From 0cb94fa0a5d960a1c2787a25d0408d0384c316bb Mon Sep 17 00:00:00 2001 From: verysillycat Date: Mon, 16 Sep 2024 11:03:54 -0600 Subject: [PATCH 1/3] ags & hypr: make session manager toggleable & add power button keybind --- .config/ags/modules/sideright/quicktoggles.js | 12 ++++++++++-- .config/ags/variables.js | 3 +++ .config/hypr/hyprland/keybinds.conf | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.config/ags/modules/sideright/quicktoggles.js b/.config/ags/modules/sideright/quicktoggles.js index e37b79b790..63142b2f2e 100644 --- a/.config/ags/modules/sideright/quicktoggles.js +++ b/.config/ags/modules/sideright/quicktoggles.js @@ -257,11 +257,19 @@ export const ModulePowerIcon = (props = {}) => Widget.Button({ className: 'txt-small sidebar-iconbutton', tooltipText: 'Session', onClicked: () => { - closeEverything(); - Utils.timeout(1, () => openWindowOnAllMonitors('session')); + showSessionWindow.value = !showSessionWindow.value; + if (showSessionWindow.value) { + closeEverything(); + Utils.timeout(1, () => openWindowOnAllMonitors('session')); + } else { + closeWindowOnAllMonitors('session'); + } }, child: MaterialIcon('power_settings_new', 'norm'), setup: button => { setupCursorHover(button); + button.hook(showSessionWindow, (btn) => { + btn.toggleClassName('sidebar-button-active', showSessionWindow.value); + }); } }) diff --git a/.config/ags/variables.js b/.config/ags/variables.js index bf6a9ff6f7..b203e56dd3 100644 --- a/.config/ags/variables.js +++ b/.config/ags/variables.js @@ -70,6 +70,9 @@ globalThis['openWindowOnAllMonitors'] = (name) => { }); } +export const showSessionWindow = Variable(false, {}); +globalThis['showSessionWindow'] = showSessionWindow; + globalThis['closeEverything'] = () => { const numMonitors = Gdk.Display.get_default()?.get_n_monitors() || 1; for (let i = 0; i < numMonitors; i++) { diff --git a/.config/hypr/hyprland/keybinds.conf b/.config/hypr/hyprland/keybinds.conf index 5203867c23..e531533b8c 100644 --- a/.config/hypr/hyprland/keybinds.conf +++ b/.config/hypr/hyprland/keybinds.conf @@ -1,6 +1,6 @@ # Lines ending with `# [hidden]` won't be shown on cheatsheet # Lines starting with #! are section headings - +bindle =, XF86PowerOff , exec, ags run-js 'showSessionWindow.value = !showSessionWindow.value; if (showSessionWindow.value) { closeEverything(); Utils.timeout(1, () => openWindowOnAllMonitors("session"));} else { closeWindowOnAllMonitors("session");}' bindl = Alt ,XF86AudioMute, exec, wpctl set-mute @DEFAULT_SOURCE@ toggle # [hidden] bindl = Super ,XF86AudioMute, exec, wpctl set-mute @DEFAULT_SOURCE@ toggle # [hidden] bindl = ,XF86AudioMute, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 0% # [hidden] From ff9a47c206be5063bb8938bbeb21aec12923144d Mon Sep 17 00:00:00 2001 From: verysillycat Date: Mon, 16 Sep 2024 22:14:51 -0600 Subject: [PATCH 2/3] ags(sessionmanager): some minor fixes --- .config/ags/modules/session/sessionscreen.js | 23 +++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/.config/ags/modules/session/sessionscreen.js b/.config/ags/modules/session/sessionscreen.js index 1160047ff2..171041ff32 100644 --- a/.config/ags/modules/session/sessionscreen.js +++ b/.config/ags/modules/session/sessionscreen.js @@ -68,7 +68,15 @@ export default ({ id = 0 }) => { const hibernateButton = SessionButton('Hibernate', 'downloading', () => { closeWindowOnAllMonitors('session'); execAsync(['bash', '-c', 'systemctl hibernate || loginctl hibernate']).catch(print) }, {}, 4); const shutdownButton = SessionButton('Shutdown', 'power_settings_new', () => { closeWindowOnAllMonitors('session'); execAsync(['bash', '-c', 'systemctl poweroff || loginctl poweroff']).catch(print) }, {}, 5); const rebootButton = SessionButton('Reboot', 'restart_alt', () => { closeWindowOnAllMonitors('session'); execAsync(['bash', '-c', 'systemctl reboot || loginctl reboot']).catch(print) }, {}, 6); - const cancelButton = SessionButton('Cancel', 'close', () => closeWindowOnAllMonitors('session'), { className: 'session-button-cancel' }, 7); + const cancelButton = SessionButton('Cancel', 'close', () => { + showSessionWindow.value = !showSessionWindow.value; + if (showSessionWindow.value) { + closeEverything(); + Utils.timeout(1, () => openWindowOnAllMonitors("session")); + } else { + closeWindowOnAllMonitors("session"); + } + }, { className: 'session-button-cancel' }, 7); const sessionDescription = Widget.Box({ vertical: true, @@ -125,10 +133,15 @@ export default ({ id = 0 }) => { ] }) ], - setup: (self) => self - .hook(App, (_b, name, visible) => { + setup: (self) => { + self.hook(App, (_b, name, visible) => { if (visible) lockButton.grab_focus(); // Lock is the default option - }) - , + }); + self.on('key-press-event', (widget, event) => { + if (event.get_keyval()[1] === Gdk.KEY_Escape) { + showSessionWindow.value = false; + } + }); + }, }); } From 44ae2affecbdcfce1f0df6ea094b7b07c0574817 Mon Sep 17 00:00:00 2001 From: verysillycat Date: Mon, 16 Sep 2024 22:55:02 -0600 Subject: [PATCH 3/3] ags(sessionmanager): another minor fix im done now --- .config/ags/modules/session/sessionscreen.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.config/ags/modules/session/sessionscreen.js b/.config/ags/modules/session/sessionscreen.js index 171041ff32..d4c9a82f66 100644 --- a/.config/ags/modules/session/sessionscreen.js +++ b/.config/ags/modules/session/sessionscreen.js @@ -61,13 +61,13 @@ const SessionButton = (name, icon, command, props = {}, colorid = 0) => { export default ({ id = 0 }) => { // lock, logout, sleep - const lockButton = SessionButton('Lock', 'lock', () => { closeWindowOnAllMonitors('session'); execAsync(['loginctl', 'lock-session']).catch(print) }, {}, 1); - const logoutButton = SessionButton('Logout', 'logout', () => { closeWindowOnAllMonitors('session'); execAsync(['bash', '-c', 'pkill Hyprland || pkill sway || pkill niri || loginctl terminate-user $USER']).catch(print) }, {}, 2); - const sleepButton = SessionButton('Sleep', 'sleep', () => { closeWindowOnAllMonitors('session'); execAsync(['bash', '-c', 'systemctl suspend || loginctl suspend']).catch(print) }, {}, 3); + const lockButton = SessionButton('Lock', 'lock', () => { closeWindowOnAllMonitors('session'); execAsync(['loginctl', 'lock-session']).catch(print); showSessionWindow.value = false; }, {}, 1); + const logoutButton = SessionButton('Logout', 'logout', () => { closeWindowOnAllMonitors('session'); execAsync(['bash', '-c', 'pkill Hyprland || pkill sway || pkill niri || loginctl terminate-user $USER']).catch(print); showSessionWindow.value = false; }, {}, 2); + const sleepButton = SessionButton('Sleep', 'sleep', () => { closeWindowOnAllMonitors('session'); execAsync(['bash', '-c', 'systemctl suspend || loginctl suspend']).catch(print); showSessionWindow.value = false; }, {}, 3); // hibernate, shutdown, reboot - const hibernateButton = SessionButton('Hibernate', 'downloading', () => { closeWindowOnAllMonitors('session'); execAsync(['bash', '-c', 'systemctl hibernate || loginctl hibernate']).catch(print) }, {}, 4); - const shutdownButton = SessionButton('Shutdown', 'power_settings_new', () => { closeWindowOnAllMonitors('session'); execAsync(['bash', '-c', 'systemctl poweroff || loginctl poweroff']).catch(print) }, {}, 5); - const rebootButton = SessionButton('Reboot', 'restart_alt', () => { closeWindowOnAllMonitors('session'); execAsync(['bash', '-c', 'systemctl reboot || loginctl reboot']).catch(print) }, {}, 6); + const hibernateButton = SessionButton('Hibernate', 'downloading', () => { closeWindowOnAllMonitors('session'); execAsync(['bash', '-c', 'systemctl hibernate || loginctl hibernate']).catch(print); showSessionWindow.value = false; }, {}, 4); + const shutdownButton = SessionButton('Shutdown', 'power_settings_new', () => { closeWindowOnAllMonitors('session'); execAsync(['bash', '-c', 'systemctl poweroff || loginctl poweroff']).catch(print); showSessionWindow.value = false; }, {}, 5); + const rebootButton = SessionButton('Reboot', 'restart_alt', () => { closeWindowOnAllMonitors('session'); execAsync(['bash', '-c', 'systemctl reboot || loginctl reboot']).catch(print); showSessionWindow.value = false; }, {}, 6); const cancelButton = SessionButton('Cancel', 'close', () => { showSessionWindow.value = !showSessionWindow.value; if (showSessionWindow.value) {