lock: make window hiding anim work with floating windows

This commit is contained in:
end-4
2025-10-30 11:07:57 +01:00
parent b484e3311c
commit dfbbe3fcca
@@ -1,4 +1,6 @@
pragma ComponentBehavior: Bound
import qs import qs
import qs.services
import qs.modules.common import qs.modules.common
import qs.modules.common.functions import qs.modules.common.functions
import qs.modules.lock import qs.modules.lock
@@ -9,9 +11,9 @@ import Quickshell.Wayland
import Quickshell.Hyprland import Quickshell.Hyprland
Scope { Scope {
id: root id: root
function unlockKeyring() { function unlockKeyring() {
Quickshell.execDetached({ Quickshell.execDetached({
environment: ({ environment: ({
UNLOCK_PASSWORD: root.currentText UNLOCK_PASSWORD: root.currentText
@@ -20,120 +22,136 @@ Scope {
}) })
} }
// This stores all the information shared between the lock surfaces on each screen. property var windowData: []
// https://github.com/quickshell-mirror/quickshell-examples/tree/master/lockscreen function saveWindowPositionAndTile() {
LockContext { root.windowData = HyprlandData.windowList.filter(w => w.floating)
id: lockContext root.windowData.forEach(w => {
Hyprland.dispatch(`settiled address:${w.address}`)
})
}
function restoreWindowPositionAndTile() {
root.windowData.forEach(w => {
Hyprland.dispatch(`setfloating address:${w.address}`)
Hyprland.dispatch(`movewindowpixel exact ${w.at[0]} ${w.at[1]}, address:${w.address}`)
})
}
Connections { // This stores all the information shared between the lock surfaces on each screen.
target: GlobalStates // https://github.com/quickshell-mirror/quickshell-examples/tree/master/lockscreen
function onScreenLockedChanged() { LockContext {
if (GlobalStates.screenLocked) { id: lockContext
lockContext.reset();
lockContext.tryFingerUnlock();
}
}
}
onUnlocked: (targetAction) => { Connections {
// Perform the target action if it's not just unlocking target: GlobalStates
if (targetAction == LockContext.ActionEnum.Poweroff) { function onScreenLockedChanged() {
Session.poweroff(); if (GlobalStates.screenLocked) {
return; lockContext.reset();
} else if (targetAction == LockContext.ActionEnum.Reboot) { lockContext.tryFingerUnlock();
Session.reboot(); }
return; }
} }
// Unlock the keyring if configured to do so onUnlocked: (targetAction) => {
if (Config.options.lock.security.unlockKeyring) root.unlockKeyring(); // Perform the target action if it's not just unlocking
if (targetAction == LockContext.ActionEnum.Poweroff) {
Session.poweroff();
return;
} else if (targetAction == LockContext.ActionEnum.Reboot) {
Session.reboot();
return;
}
// Unlock the screen before exiting, or the compositor will display a // Unlock the keyring if configured to do so
// fallback lock you can't interact with. if (Config.options.lock.security.unlockKeyring) root.unlockKeyring();
GlobalStates.screenLocked = false;
// Refocus last focused window on unlock (hack) // Unlock the screen before exiting, or the compositor will display a
Quickshell.execDetached(["bash", "-c", `sleep 0.2; hyprctl --batch "dispatch togglespecialworkspace; dispatch togglespecialworkspace"`]) // fallback lock you can't interact with.
GlobalStates.screenLocked = false;
// Refocus last focused window on unlock (hack)
Quickshell.execDetached(["bash", "-c", `sleep 0.2; hyprctl --batch "dispatch togglespecialworkspace; dispatch togglespecialworkspace"`])
// Reset // Reset
lockContext.reset(); lockContext.reset();
} }
} }
WlSessionLock { WlSessionLock {
id: lock id: lock
locked: GlobalStates.screenLocked locked: GlobalStates.screenLocked
WlSessionLockSurface { WlSessionLockSurface {
color: "transparent" color: "transparent"
Loader { Loader {
active: GlobalStates.screenLocked active: GlobalStates.screenLocked
anchors.fill: parent anchors.fill: parent
opacity: active ? 1 : 0 opacity: active ? 1 : 0
Behavior on opacity { Behavior on opacity {
animation: Appearance.animation.elementMoveFast.colorAnimation.createObject(this) animation: Appearance.animation.elementMoveFast.colorAnimation.createObject(this)
} }
sourceComponent: LockSurface { sourceComponent: LockSurface {
context: lockContext context: lockContext
} }
} }
} }
} }
// Blur layer hack // Blur layer hack
Variants { Variants {
model: Quickshell.screens model: Quickshell.screens
delegate: Scope { delegate: Scope {
required property ShellScreen modelData required property ShellScreen modelData
property bool shouldPush: GlobalStates.screenLocked property bool shouldPush: GlobalStates.screenLocked
property string targetMonitorName: modelData.name property string targetMonitorName: modelData.name
property int verticalMovementDistance: modelData.height property int verticalMovementDistance: modelData.height
property int horizontalSqueeze: modelData.width * 0.2 property int horizontalSqueeze: modelData.width * 0.2
onShouldPushChanged: { onShouldPushChanged: {
if (shouldPush) { if (shouldPush) {
Quickshell.execDetached(["bash", "-c", `hyprctl keyword monitor ${targetMonitorName}, addreserved, ${verticalMovementDistance}, ${-verticalMovementDistance}, ${horizontalSqueeze}, ${horizontalSqueeze}`]) root.saveWindowPositionAndTile();
} else { Quickshell.execDetached(["bash", "-c", `hyprctl keyword monitor ${targetMonitorName}, addreserved, ${verticalMovementDistance}, ${-verticalMovementDistance}, ${horizontalSqueeze}, ${horizontalSqueeze}`])
Quickshell.execDetached(["bash", "-c", `hyprctl keyword monitor ${targetMonitorName}, addreserved, 0, 0, 0, 0`]) } else {
} Quickshell.execDetached(["bash", "-c", `hyprctl keyword monitor ${targetMonitorName}, addreserved, 0, 0, 0, 0`])
} root.restoreWindowPositionAndTile();
} }
} }
}
}
IpcHandler { IpcHandler {
target: "lock" target: "lock"
function activate(): void { function activate(): void {
GlobalStates.screenLocked = true; GlobalStates.screenLocked = true;
} }
function focus(): void { function focus(): void {
lockContext.shouldReFocus(); lockContext.shouldReFocus();
} }
} }
GlobalShortcut { GlobalShortcut {
name: "lock" name: "lock"
description: "Locks the screen" description: "Locks the screen"
onPressed: { onPressed: {
if (Config.options.lock.useHyprlock) { if (Config.options.lock.useHyprlock) {
Quickshell.execDetached(["bash", "-c", "pidof hyprlock || hyprlock"]); Quickshell.execDetached(["bash", "-c", "pidof hyprlock || hyprlock"]);
return; return;
} }
GlobalStates.screenLocked = true; GlobalStates.screenLocked = true;
} }
} }
GlobalShortcut { GlobalShortcut {
name: "lockFocus" name: "lockFocus"
description: "Re-focuses the lock screen. This is because Hyprland after waking up for whatever reason" description: "Re-focuses the lock screen. This is because Hyprland after waking up for whatever reason"
+ "decides to keyboard-unfocus the lock screen" + "decides to keyboard-unfocus the lock screen"
onPressed: { onPressed: {
lockContext.shouldReFocus(); lockContext.shouldReFocus();
} }
} }
Connections { Connections {
target: Config target: Config
function onReadyChanged() { function onReadyChanged() {
if (Config.options.lock.launchOnStartup && Config.ready && Persistent.ready && Persistent.isNewHyprlandInstance) { if (Config.options.lock.launchOnStartup && Config.ready && Persistent.ready && Persistent.isNewHyprlandInstance) {