cheatsheet: put in loader

This commit is contained in:
end-4
2025-05-16 22:46:11 +02:00
parent 6dc3b7ff92
commit c695a4879c
@@ -19,137 +19,151 @@ Scope { // Scope
id: cheatsheetVariants
model: Quickshell.screens
PanelWindow { // Window
id: cheatsheetRoot
visible: false
focusable: true
Loader {
id: cheatsheetLoader
active: false
property var modelData
sourceComponent: PanelWindow { // Window
id: cheatsheetRoot
visible: cheatsheetLoader.active
focusable: true
screen: modelData
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: false
onCleared: () => {
if (!active) cheatsheetRoot.visible = false
anchors {
top: true
bottom: true
left: true
right: true
}
}
Connections {
target: cheatsheetRoot
function onVisibleChanged() {
delayedGrabTimer.start()
function hide() {
cheatsheetLoader.active = false
}
}
Timer {
id: delayedGrabTimer
interval: ConfigOptions.hacks.arbitraryRaceConditionDelay
repeat: false
onTriggered: {
grab.active = cheatsheetRoot.visible
screen: modelData
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
}
}
// Background
Rectangle {
id: cheatsheetBackground
anchors.centerIn: parent
color: Appearance.colors.colLayer0
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.visible = false
HyprlandFocusGrab { // Click outside to close
id: grab
windows: [ cheatsheetRoot ]
active: false
onCleared: () => {
if (!active) cheatsheetRoot.hide()
}
}
Button { // Close button
id: closeButton
focus: cheatsheetRoot.visible
implicitWidth: 40
implicitHeight: 40
anchors {
top: parent.top
right: parent.right
topMargin: 20
rightMargin: 20
Connections {
target: cheatsheetRoot
function onVisibleChanged() {
delayedGrabTimer.start()
}
}
Timer {
id: delayedGrabTimer
interval: ConfigOptions.hacks.arbitraryRaceConditionDelay
repeat: false
onTriggered: {
grab.active = cheatsheetRoot.visible
}
}
// Background
Rectangle {
id: cheatsheetBackground
anchors.centerIn: parent
color: Appearance.colors.colLayer0
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()
}
}
PointingHandInteraction {}
onClicked: {
cheatsheetRoot.visible = false
}
Button { // Close button
id: closeButton
focus: cheatsheetRoot.visible
implicitWidth: 40
implicitHeight: 40
anchors {
top: parent.top
right: parent.right
topMargin: 20
rightMargin: 20
}
background: Item {}
contentItem: Rectangle {
anchors.fill: parent
radius: Appearance.rounding.full
color: closeButton.pressed ? Appearance.colors.colLayer0Active :
closeButton.hovered ? Appearance.colors.colLayer0Hover :
Appearance.transparentize(Appearance.colors.colLayer0, 1)
Behavior on color {
ColorAnimation {
duration: Appearance.animation.elementMoveFast.duration
easing.type: Appearance.animation.elementMoveFast.type
easing.bezierCurve: Appearance.animation.elementMoveFast.bezierCurve
PointingHandInteraction {}
onClicked: {
cheatsheetRoot.hide()
}
background: Item {}
contentItem: Rectangle {
anchors.fill: parent
radius: Appearance.rounding.full
color: closeButton.pressed ? Appearance.colors.colLayer0Active :
closeButton.hovered ? Appearance.colors.colLayer0Hover :
Appearance.transparentize(Appearance.colors.colLayer0, 1)
Behavior on color {
ColorAnimation {
duration: Appearance.animation.elementMoveFast.duration
easing.type: Appearance.animation.elementMoveFast.type
easing.bezierCurve: Appearance.animation.elementMoveFast.bezierCurve
}
}
MaterialSymbol {
anchors.centerIn: parent
font.pixelSize: Appearance.font.pixelSize.title
text: "close"
}
}
}
MaterialSymbol {
anchors.centerIn: parent
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: "close"
text: qsTr("Cheat sheet")
}
CheatsheetKeybinds {}
}
}
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: qsTr("Cheat sheet")
}
CheatsheetKeybinds {}
// Shadow
DropShadow {
anchors.fill: cheatsheetBackground
horizontalOffset: 0
verticalOffset: 2
radius: Appearance.sizes.elevationMargin
samples: Appearance.sizes.elevationMargin * 2 + 1 // Ideally should be 2 * radius + 1, see qt docs
color: Appearance.colors.colShadow
source: cheatsheetBackground
}
}
// Shadow
DropShadow {
anchors.fill: cheatsheetBackground
horizontalOffset: 0
verticalOffset: 2
radius: Appearance.sizes.elevationMargin
samples: Appearance.sizes.elevationMargin * 2 + 1 // Ideally should be 2 * radius + 1, see qt docs
color: Appearance.colors.colShadow
source: cheatsheetBackground
}
}
}
IpcHandler {
@@ -157,30 +171,22 @@ Scope { // Scope
function toggle(): void {
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
let panelWindow = cheatsheetVariants.instances[i];
if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) {
panelWindow.visible = !panelWindow.visible;
if(panelWindow.visible) Notifications.timeoutAll();
}
const loader = cheatsheetVariants.instances[i];
loader.active = !loader.active;
}
}
function close(): void {
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
let panelWindow = cheatsheetVariants.instances[i];
if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) {
panelWindow.visible = false;
}
const loader = cheatsheetVariants.instances[i];
loader.active = false
}
}
function open(): void {
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
let panelWindow = cheatsheetVariants.instances[i];
if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) {
panelWindow.visible = true;
if(panelWindow.visible) Notifications.timeoutAll();
}
const loader = cheatsheetVariants.instances[i];
loader.active = true;
}
}
}
@@ -191,11 +197,8 @@ Scope { // Scope
onPressed: {
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
let panelWindow = cheatsheetVariants.instances[i];
if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) {
panelWindow.visible = !panelWindow.visible;
if(panelWindow.visible) Notifications.timeoutAll();
}
const loader = cheatsheetVariants.instances[i];
loader.active = !loader.active;
}
}
}
@@ -206,11 +209,8 @@ Scope { // Scope
onPressed: {
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
let panelWindow = cheatsheetVariants.instances[i];
if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) {
panelWindow.visible = true;
if(panelWindow.visible) Notifications.timeoutAll();
}
const loader = cheatsheetVariants.instances[i];
loader.active = true;
}
}
}
@@ -221,10 +221,8 @@ Scope { // Scope
onPressed: {
for (let i = 0; i < cheatsheetVariants.instances.length; i++) {
let panelWindow = cheatsheetVariants.instances[i];
if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) {
panelWindow.visible = false;
}
const loader = cheatsheetVariants.instances[i];
loader.active = false;
}
}
}