Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ags & hypr: toggleable session screen & power button keybind #822

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions .config/ags/modules/session/sessionscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,22 @@ 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 cancelButton = SessionButton('Cancel', 'close', () => closeWindowOnAllMonitors('session'), { className: 'session-button-cancel' }, 7);
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) {
closeEverything();
Utils.timeout(1, () => openWindowOnAllMonitors("session"));
} else {
closeWindowOnAllMonitors("session");
}
}, { className: 'session-button-cancel' }, 7);

const sessionDescription = Widget.Box({
vertical: true,
Expand Down Expand Up @@ -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;
}
});
},
});
}
12 changes: 10 additions & 2 deletions .config/ags/modules/sideright/quicktoggles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
})
3 changes: 3 additions & 0 deletions .config/ags/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion .config/hypr/hyprland/keybinds.conf
Original file line number Diff line number Diff line change
@@ -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]
Expand Down