import qs import qs.services import qs.modules.common import qs.modules.common.widgets import QtQuick import QtQuick.Controls import QtQuick.Layouts import Qt5Compat.GraphicalEffects import Quickshell.Io import Quickshell import Quickshell.Wayland import Quickshell.Hyprland Scope { // Scope id: root property var tabButtonList: [ { "icon": "keyboard", "name": Translation.tr("Keybinds") }, { "icon": "experiment", "name": Translation.tr("Elements") }, ] property int selectedTab: 0 Loader { id: cheatsheetLoader active: false sourceComponent: PanelWindow { // Window id: cheatsheetRoot visible: cheatsheetLoader.active anchors { top: true bottom: true left: true right: true } function hide() { cheatsheetLoader.active = false; } exclusiveZone: 0 implicitWidth: cheatsheetBackground.width + Appearance.sizes.elevationMargin * 2 implicitHeight: cheatsheetBackground.height + Appearance.sizes.elevationMargin * 2 WlrLayershell.namespace: "quickshell:cheatsheet" // Hyprland 0.49: Focus is always exclusive and setting this breaks mouse focus grab // WlrLayershell.keyboardFocus: WlrKeyboardFocus.Exclusive color: "transparent" mask: Region { item: cheatsheetBackground } HyprlandFocusGrab { // Click outside to close id: grab windows: [cheatsheetRoot] active: cheatsheetRoot.visible onCleared: () => { if (!active) cheatsheetRoot.hide(); } } // Background StyledRectangularShadow { target: cheatsheetBackground } Rectangle { id: cheatsheetBackground anchors.centerIn: parent color: Appearance.colors.colLayer0 border.width: 1 border.color: Appearance.colors.colLayer0Border radius: Appearance.rounding.windowRounding property real padding: 30 implicitWidth: cheatsheetColumnLayout.implicitWidth + padding * 2 implicitHeight: cheatsheetColumnLayout.implicitHeight + padding * 2 Keys.onPressed: event => { // Esc to close if (event.key === Qt.Key_Escape) { cheatsheetRoot.hide(); } if (event.modifiers === Qt.ControlModifier) { if (event.key === Qt.Key_PageDown) { root.selectedTab = Math.min(root.selectedTab + 1, root.tabButtonList.length - 1); event.accepted = true; } else if (event.key === Qt.Key_PageUp) { root.selectedTab = Math.max(root.selectedTab - 1, 0); event.accepted = true; } else if (event.key === Qt.Key_Tab) { root.selectedTab = (root.selectedTab + 1) % root.tabButtonList.length; event.accepted = true; } else if (event.key === Qt.Key_Backtab) { root.selectedTab = (root.selectedTab - 1 + root.tabButtonList.length) % root.tabButtonList.length; event.accepted = true; } } } RippleButton { // Close button id: closeButton focus: cheatsheetRoot.visible implicitWidth: 40 implicitHeight: 40 buttonRadius: Appearance.rounding.full anchors { top: parent.top right: parent.right topMargin: 20 rightMargin: 20 } onClicked: { cheatsheetRoot.hide(); } contentItem: MaterialSymbol { anchors.centerIn: parent horizontalAlignment: Text.AlignHCenter font.pixelSize: Appearance.font.pixelSize.title text: "close" } } ColumnLayout { // Real content id: cheatsheetColumnLayout anchors.centerIn: parent spacing: 20 StyledText { id: cheatsheetTitle Layout.alignment: Qt.AlignHCenter font.family: Appearance.font.family.title font.pixelSize: Appearance.font.pixelSize.title text: Translation.tr("Cheat sheet") } PrimaryTabBar { // Tab strip id: tabBar tabButtonList: root.tabButtonList externalTrackedTab: root.selectedTab function onCurrentIndexChanged(currentIndex) { root.selectedTab = currentIndex; } } SwipeView { // Content pages id: swipeView Layout.topMargin: 5 Layout.fillWidth: true Layout.fillHeight: true spacing: 10 Behavior on implicitWidth { id: contentWidthBehavior enabled: false animation: Appearance.animation.elementMoveFast.numberAnimation.createObject(this) } Behavior on implicitHeight { id: contentHeightBehavior enabled: false animation: Appearance.animation.elementMoveFast.numberAnimation.createObject(this) } currentIndex: tabBar.externalTrackedTab onCurrentIndexChanged: { contentWidthBehavior.enabled = true; contentHeightBehavior.enabled = true; tabBar.enableIndicatorAnimation = true; root.selectedTab = currentIndex; } clip: true layer.enabled: true layer.effect: OpacityMask { maskSource: Rectangle { width: swipeView.width height: swipeView.height radius: Appearance.rounding.small } } CheatsheetKeybinds {} CheatsheetPeriodicTable {} } } } } } IpcHandler { target: "cheatsheet" function toggle(): void { cheatsheetLoader.active = !cheatsheetLoader.active; } function close(): void { cheatsheetLoader.active = false; } function open(): void { cheatsheetLoader.active = true; } } GlobalShortcut { name: "cheatsheetToggle" description: "Toggles cheatsheet on press" onPressed: { cheatsheetLoader.active = !cheatsheetLoader.active; } } GlobalShortcut { name: "cheatsheetOpen" description: "Opens cheatsheet on press" onPressed: { cheatsheetLoader.active = true; } } GlobalShortcut { name: "cheatsheetClose" description: "Closes cheatsheet on press" onPressed: { cheatsheetLoader.active = false; } } }