fix keybind cheatsheet

This commit is contained in:
end-4
2026-05-12 09:28:07 +02:00
parent 807c761ed0
commit ae7f6bd165
2 changed files with 99 additions and 170 deletions
@@ -2,18 +2,22 @@ pragma ComponentBehavior: Bound
import qs.services import qs.services
import qs.modules.common import qs.modules.common
import qs.modules.common.functions
import qs.modules.common.widgets import qs.modules.common.widgets
import QtQuick import QtQuick
import QtQuick.Layouts import QtQuick.Layouts
import Quickshell
Item { Item {
id: root id: root
readonly property var keybinds: HyprlandKeybinds.keybinds readonly property var keybinds: HyprlandKeybinds.keybinds.filter(function(keybind) {
property real spacing: 20 return keybind.has_description;
})
property real columnSpacing: 40
property real titleSpacing: 7 property real titleSpacing: 7
property real padding: 4 property real padding: 4
implicitWidth: row.implicitWidth + padding * 2 implicitWidth: QsWindow.window.screen.width * 0.7
implicitHeight: row.implicitHeight + padding * 2 implicitHeight: QsWindow.window.screen.height * 0.7
// Excellent symbol explaination and source : // Excellent symbol explaination and source :
// http://xahlee.info/comp/unicode_computing_symbols.html // http://xahlee.info/comp/unicode_computing_symbols.html
// https://www.nerdfonts.com/cheat-sheet // https://www.nerdfonts.com/cheat-sheet
@@ -56,7 +60,7 @@ Item {
"Page_↑/↓": "⇞/⇟", "Page_↑/↓": "⇞/⇟",
}) })
property var keyBlacklist: ["Super_L"] property var keyBlacklist: ["SUPER_L", "SUPER_R"]
property var keySubstitutions: Object.assign({ property var keySubstitutions: Object.assign({
"Super": "", "Super": "",
"mouse_up": "Scroll ↓", // ikr, weird "mouse_up": "Scroll ↓", // ikr, weird
@@ -77,139 +81,91 @@ Item {
Config.options.cheatsheet.useMouseSymbol ? mouseSymbolMap : {}, Config.options.cheatsheet.useMouseSymbol ? mouseSymbolMap : {},
) )
Row { // Keybind columns StyledFlickable {
id: row id: flickable
spacing: root.spacing anchors.fill: parent
anchors.margins: Appearance.rounding.small
Repeater { contentHeight: height
model: keybinds.children contentWidth: flow.implicitWidth
Flow {
delegate: Column { // Keybind sections id: flow
spacing: root.spacing height: flickable.height
required property var modelData flow: Flow.TopToBottom
anchors.top: row.top spacing: 4
Repeater {
Repeater { model: root.keybinds
model: modelData.children delegate: BindLine {
required property var modelData
delegate: Item { // Section with real keybinds keyData: modelData
id: keybindSection }
required property var modelData }
implicitWidth: sectionColumn.implicitWidth }
implicitHeight: sectionColumn.implicitHeight }
Column { function modMaskToStringList(modMask: int): list<string> {
id: sectionColumn var list = [];
anchors.centerIn: parent if (modMask & (1 << 0)) { list.push("Shift"); }
spacing: root.titleSpacing if (modMask & (1 << 1)) { list.push("Caps"); }
if (modMask & (1 << 2)) { list.push("Ctrl"); }
StyledText { if (modMask & (1 << 3)) { list.push("Alt"); }
id: sectionTitle if (modMask & (1 << 4)) { list.push("Mod2"); }
font { if (modMask & (1 << 5)) { list.push("Mod3"); }
family: Appearance.font.family.title if (modMask & (1 << 6)) { list.push("Super"); }
pixelSize: Appearance.font.pixelSize.title if (modMask & (1 << 7)) { list.push("Mod5"); }
variableAxes: Appearance.font.variableAxes.title return list;
} }
color: Appearance.colors.colOnLayer0
text: keybindSection.modelData.name property int maxBindWidth: 0
}
component BindLine: Row {
GridLayout { required property var keyData
id: keybindGrid Row {
columns: 2 spacing: 16
columnSpacing: 4 Row {
rowSpacing: 4 id: modRow
Component.onCompleted: root.maxBindWidth = Math.max(root.maxBindWidth, implicitWidth)
Repeater { width: root.maxBindWidth
model: { spacing: 4
var result = []; Repeater {
for (var i = 0; i < keybindSection.modelData.keybinds.length; i++) { model: {
const keybind = keybindSection.modelData.keybinds[i]; const modList = root.modMaskToStringList(keyData.modmask)
if (modList.length == 0) return []
if (!Config.options.cheatsheet.splitButtons) { if (Config.options.cheatsheet.splitButtons) return modList;
for (var j = 0; j < keybind.mods.length; j++) { return [modList.join(" ")]
keybind.mods[j] = keySubstitutions[keybind.mods[j]] || keybind.mods[j]; }
} delegate: KeyboardKey {
keybind.mods = [keybind.mods.join(' ') ] required property var modelData
keybind.mods[0] += !keyBlacklist.includes(keybind.key) && keybind.mods[0].length ? ' ' : '' key: root.keySubstitutions[modelData] || modelData
keybind.mods[0] += !keyBlacklist.includes(keybind.key) ? (keySubstitutions[keybind.key] || keybind.key) : '' pixelSize: Config.options.cheatsheet.fontSize.key
} }
}
result.push({ StyledText {
"type": "keys", id: keybindPlus
"mods": keybind.mods, anchors.verticalCenter: parent.verticalCenter
"key": keybind.key, visible: !keyBlacklist.includes(keyData.key) && keyData.modmask > 0
}); text: "+"
result.push({ }
"type": "comment", KeyboardKey {
"comment": keybind.comment, id: keybindKey
}); anchors.verticalCenter: parent.verticalCenter
} visible: !keyBlacklist.includes(keyData.key)
return result; key: StringUtils.toTitleCase(root.keySubstitutions[keyData.key] || keyData.key)
} pixelSize: Config.options.cheatsheet.fontSize.key
delegate: Item { color: Appearance.colors.colOnLayer0
required property var modelData }
implicitWidth: keybindLoader.implicitWidth }
implicitHeight: keybindLoader.implicitHeight Item {
anchors.verticalCenter: parent.verticalCenter
Loader { implicitWidth: commentText.implicitWidth + root.columnSpacing
id: keybindLoader implicitHeight: commentText.implicitHeight
sourceComponent: (modelData.type === "keys") ? keysComponent : commentComponent StyledText {
} id: commentText
anchors.verticalCenter: parent.verticalCenter
Component { anchors.left: parent.left
id: keysComponent font.pixelSize: Config.options.cheatsheet.fontSize.comment || Appearance.font.pixelSize.smaller
Row { text: keyData.description
spacing: 4
Repeater {
model: modelData.mods
delegate: KeyboardKey {
required property var modelData
key: keySubstitutions[modelData] || modelData
pixelSize: Config.options.cheatsheet.fontSize.key
}
}
StyledText {
id: keybindPlus
visible: Config.options.cheatsheet.splitButtons && !keyBlacklist.includes(modelData.key) && modelData.mods.length > 0
text: "+"
}
KeyboardKey {
id: keybindKey
visible: Config.options.cheatsheet.splitButtons && !keyBlacklist.includes(modelData.key)
key: keySubstitutions[modelData.key] || modelData.key
pixelSize: Config.options.cheatsheet.fontSize.key
color: Appearance.colors.colOnLayer0
}
}
}
Component {
id: commentComponent
Item {
id: commentItem
implicitWidth: commentText.implicitWidth + 8 * 2
implicitHeight: commentText.implicitHeight
StyledText {
id: commentText
anchors.centerIn: parent
font.pixelSize: Config.options.cheatsheet.fontSize.comment || Appearance.font.pixelSize.smaller
text: modelData.comment
}
}
}
}
}
}
}
}
} }
} }
} }
} }
} }
@@ -14,54 +14,27 @@ import Quickshell.Hyprland
*/ */
Singleton { Singleton {
id: root id: root
property string keybindParserPath: FileUtils.trimFileProtocol(`${Directories.scriptPath}/hyprland/get_keybinds.py`) property var keybinds: []
property string defaultKeybindConfigPath: FileUtils.trimFileProtocol(`${Directories.config}/hypr/hyprland/keybinds.conf`)
property string userKeybindConfigPath: FileUtils.trimFileProtocol(`${Directories.config}/hypr/custom/keybinds.conf`)
property var defaultKeybinds: {"children": []}
property var userKeybinds: {"children": []}
property var keybinds: ({
children: [
...(defaultKeybinds.children ?? []),
...(userKeybinds.children ?? []),
]
})
Connections { Connections {
target: Hyprland target: Hyprland
function onRawEvent(event) { function onRawEvent(event) {
if (event.name == "configreloaded") { if (event.name == "configreloaded") {
getDefaultKeybinds.running = true getKeybinds.running = true
getUserKeybinds.running = true
} }
} }
} }
Process { Process {
id: getDefaultKeybinds id: getKeybinds
running: true running: true
command: [root.keybindParserPath, "--path", root.defaultKeybindConfigPath] command: ["hyprctl", "binds", "-j"]
stdout: SplitParser { stdout: StdioCollector {
onRead: data => { onStreamFinished: {
try { try {
root.defaultKeybinds = JSON.parse(data) root.keybinds = JSON.parse(text)
} catch (e) {
console.error("[CheatsheetKeybinds] Error parsing keybinds:", e)
}
}
}
}
Process {
id: getUserKeybinds
running: true
command: [root.keybindParserPath, "--path", root.userKeybindConfigPath]
stdout: SplitParser {
onRead: data => {
try {
root.userKeybinds = JSON.parse(data)
} catch (e) { } catch (e) {
console.error("[CheatsheetKeybinds] Error parsing keybinds:", e) console.error("[CheatsheetKeybinds] Error parsing keybinds:", e)
} }