ags: fix multi-monitor widgets

This commit is contained in:
MoetaYuko
2024-05-01 20:12:58 +08:00
parent 8041153434
commit d696089c78
6 changed files with 40 additions and 37 deletions
+21 -17
View File
@@ -10,12 +10,12 @@ const cheatsheets = [
{ {
name: 'Keybinds', name: 'Keybinds',
materialIcon: 'keyboard', materialIcon: 'keyboard',
contentWidget: Keybinds(), contentWidget: Keybinds,
}, },
{ {
name: 'Periodic table', name: 'Periodic table',
materialIcon: 'experiment', materialIcon: 'experiment',
contentWidget: PeriodicTable(), contentWidget: PeriodicTable,
}, },
]; ];
@@ -70,20 +70,24 @@ const CheatsheetHeader = () => Widget.CenterBox({
}), }),
}); });
export const sheetContent = ExpandingIconTabContainer({ const sheetContents = {};
tabsHpack: 'center', const SheetContent = (id) => {
tabSwitcherClassName: 'sidebar-icontabswitcher', sheetContents[id] = ExpandingIconTabContainer({
transitionDuration: userOptions.animations.durationLarge * 1.4, tabsHpack: 'center',
icons: cheatsheets.map((api) => api.materialIcon), tabSwitcherClassName: 'sidebar-icontabswitcher',
names: cheatsheets.map((api) => api.name), transitionDuration: userOptions.animations.durationLarge * 1.4,
children: cheatsheets.map((api) => api.contentWidget), icons: cheatsheets.map((api) => api.materialIcon),
onChange: (self, id) => { names: cheatsheets.map((api) => api.name),
self.shown = cheatsheets[id].name; children: cheatsheets.map((api) => api.contentWidget()),
if (cheatsheets[id].onFocus) cheatsheets[id].onFocus(); onChange: (self, id) => {
} self.shown = cheatsheets[id].name;
}); }
});
return sheetContents[id];
}
export default (id) => PopupWindow({ export default (id) => PopupWindow({
monitor: id,
name: `cheatsheet${id}`, name: `cheatsheet${id}`,
layer: 'overlay', layer: 'overlay',
keymode: 'on-demand', keymode: 'on-demand',
@@ -96,15 +100,15 @@ export default (id) => PopupWindow({
className: "cheatsheet-bg spacing-v-5", className: "cheatsheet-bg spacing-v-5",
children: [ children: [
CheatsheetHeader(), CheatsheetHeader(),
sheetContent, SheetContent(id),
] ]
}), }),
], ],
setup: (self) => self.on('key-press-event', (widget, event) => { // Typing setup: (self) => self.on('key-press-event', (widget, event) => { // Typing
if (checkKeybind(event, userOptions.keybinds.cheatsheet.nextTab)) if (checkKeybind(event, userOptions.keybinds.cheatsheet.nextTab))
sheetContent.nextTab(); sheetContents[id].nextTab();
else if (checkKeybind(event, userOptions.keybinds.cheatsheet.prevTab)) else if (checkKeybind(event, userOptions.keybinds.cheatsheet.prevTab))
sheetContent.prevTab(); sheetContents[id].prevTab();
}) })
}) })
}); });
@@ -2,6 +2,7 @@ import PopupWindow from '../.widgethacks/popupwindow.js';
import OnScreenKeyboard from "./onscreenkeyboard.js"; import OnScreenKeyboard from "./onscreenkeyboard.js";
export default (id) => PopupWindow({ export default (id) => PopupWindow({
monitor: id,
anchor: ['bottom'], anchor: ['bottom'],
name: `osk${id}`, name: `osk${id}`,
showClassName: 'osk-show', showClassName: 'osk-show',
@@ -14,7 +14,7 @@ const keyboardJson = oskLayouts[keyboardLayout];
async function startYdotoolIfNeeded() { async function startYdotoolIfNeeded() {
const running = exec('pidof ydotool') const running = exec('pidof ydotool')
if(!running) execAsync(['ydotoold']).catch(print); if (!running) execAsync(['ydotoold']).catch(print);
} }
function releaseAllKeys() { function releaseAllKeys() {
@@ -72,7 +72,7 @@ const KeyboardControls = () => Box({
className: 'osk-control-button txt-norm icon-material', className: 'osk-control-button txt-norm icon-material',
onClicked: () => { onClicked: () => {
releaseAllKeys(); releaseAllKeys();
App.toggleWindowOnAllMonitors('osk'); toggleWindowOnAllMonitors('osk');
}, },
label: 'keyboard_hide', label: 'keyboard_hide',
}), }),
@@ -213,7 +213,7 @@ const KeyboardWindow = () => Box({
}) })
], ],
setup: (self) => self.hook(App, (self, name, visible) => { // Update on open setup: (self) => self.hook(App, (self, name, visible) => { // Update on open
if(!name) return; if (!name) return;
if (name.startsWith('osk') && visible) { if (name.startsWith('osk') && visible) {
self.setCss(`margin-bottom: -0px;`); self.setCss(`margin-bottom: -0px;`);
} }
+2 -1
View File
@@ -3,6 +3,7 @@ import SessionScreen from "./sessionscreen.js";
import PopupWindow from '../.widgethacks/popupwindow.js'; import PopupWindow from '../.widgethacks/popupwindow.js';
export default (id = 0) => PopupWindow({ // On-screen keyboard export default (id = 0) => PopupWindow({ // On-screen keyboard
monitor: id,
name: `session${id}`, name: `session${id}`,
visible: false, visible: false,
keymode: 'on-demand', keymode: 'on-demand',
@@ -10,4 +11,4 @@ export default (id = 0) => PopupWindow({ // On-screen keyboard
exclusivity: 'ignore', exclusivity: 'ignore',
anchor: ['top', 'bottom', 'left', 'right'], anchor: ['top', 'bottom', 'left', 'right'],
child: SessionScreen({ id: id }), child: SessionScreen({ id: id }),
}) })
+10 -10
View File
@@ -61,14 +61,14 @@ const SessionButton = (name, icon, command, props = {}, colorid = 0) => {
export default ({ id = 0 }) => { export default ({ id = 0 }) => {
// lock, logout, sleep // lock, logout, sleep
const lockButton = SessionButton('Lock', 'lock', () => { App.closeWindow(`session${id}`); execAsync(['loginctl', 'lock-session']).catch(print) }, {}, 1); const lockButton = SessionButton('Lock', 'lock', () => { closeWindowOnAllMonitors('session'); execAsync(['loginctl', 'lock-session']).catch(print) }, {}, 1);
const logoutButton = SessionButton('Logout', 'logout', () => { App.closeWindow(`session${id}`); execAsync(['bash', '-c', 'pkill Hyprland || pkill sway || pkill niri || loginctl terminate-user $USER']).catch(print) }, {}, 2); 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', () => { App.closeWindow(`session${id}`); execAsync(['bash', '-c', 'systemctl suspend || loginctl suspend']).catch(print) }, {}, 3); const sleepButton = SessionButton('Sleep', 'sleep', () => { closeWindowOnAllMonitors('session'); execAsync(['bash', '-c', 'systemctl suspend || loginctl suspend']).catch(print) }, {}, 3);
// hibernate, shutdown, reboot // hibernate, shutdown, reboot
const hibernateButton = SessionButton('Hibernate', 'downloading', () => { App.closeWindow(`session${id}`); execAsync(['bash', '-c', 'systemctl hibernate || loginctl hibernate']).catch(print) }, {}, 4); const hibernateButton = SessionButton('Hibernate', 'downloading', () => { closeWindowOnAllMonitors('session'); execAsync(['bash', '-c', 'systemctl hibernate || loginctl hibernate']).catch(print) }, {}, 4);
const shutdownButton = SessionButton('Shutdown', 'power_settings_new', () => { App.closeWindow(`session${id}`); execAsync(['bash', '-c', 'systemctl poweroff || loginctl poweroff']).catch(print) }, {}, 5); 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', () => { App.closeWindow(`session${id}`); execAsync(['bash', '-c', 'systemctl reboot || loginctl reboot']).catch(print) }, {}, 6); const rebootButton = SessionButton('Reboot', 'restart_alt', () => { closeWindowOnAllMonitors('session'); execAsync(['bash', '-c', 'systemctl reboot || loginctl reboot']).catch(print) }, {}, 6);
const cancelButton = SessionButton('Cancel', 'close', () => App.closeWindow(`session${id}`), { className: 'session-button-cancel' }, 7); const cancelButton = SessionButton('Cancel', 'close', () => closeWindowOnAllMonitors('session'), { className: 'session-button-cancel' }, 7);
const sessionDescription = Widget.Box({ const sessionDescription = Widget.Box({
vertical: true, vertical: true,
@@ -104,9 +104,9 @@ export default ({ id = 0 }) => {
vertical: true, vertical: true,
children: [ children: [
Widget.EventBox({ Widget.EventBox({
onPrimaryClick: () => App.closeWindow(`session${id}`), onPrimaryClick: () => closeWindowOnAllMonitors('session'),
onSecondaryClick: () => App.closeWindow(`session${id}`), onSecondaryClick: () => closeWindowOnAllMonitors('session'),
onMiddleClick: () => App.closeWindow(`session${id}`), onMiddleClick: () => closeWindowOnAllMonitors('session'),
}), }),
Widget.Box({ Widget.Box({
hpack: 'center', hpack: 'center',
+3 -6
View File
@@ -81,15 +81,15 @@ bind = Control+Super, T, exec, ~/.config/ags/scripts/color_generation/switchwall
bind = Control+Alt, Slash, exec, ags run-js 'cycleMode();' bind = Control+Alt, Slash, exec, ags run-js 'cycleMode();'
bindir = Super, Super_L, exec, ags -t 'overview' bindir = Super, Super_L, exec, ags -t 'overview'
bind = Super, Tab, exec, ags -t 'overview' bind = Super, Tab, exec, ags -t 'overview'
bind = Super, Slash, exec, for ((i=0; i<$(xrandr --listmonitors | grep -c 'Monitor'); i++)); do ags -t "cheatsheet""$i"; done bind = Super, Slash, exec, for ((i=0; i<$(hyprctl monitors -j | jq length); i++)); do ags -t "cheatsheet""$i"; done
bind = Super, B, exec, ags -t 'sideleft' bind = Super, B, exec, ags -t 'sideleft'
bind = Super, A, exec, ags -t 'sideleft' bind = Super, A, exec, ags -t 'sideleft'
bind = Super, O, exec, ags -t 'sideleft' bind = Super, O, exec, ags -t 'sideleft'
bind = Super, N, exec, ags -t 'sideright' bind = Super, N, exec, ags -t 'sideright'
bind = Super, M, exec, ags run-js 'openMusicControls.value = (!mpris.getPlayer() ? false : !openMusicControls.value);' bind = Super, M, exec, ags run-js 'openMusicControls.value = (!mpris.getPlayer() ? false : !openMusicControls.value);'
bind = Super, Comma, exec, ags run-js 'openColorScheme.value = true; Utils.timeout(2000, () => openColorScheme.value = false);' bind = Super, Comma, exec, ags run-js 'openColorScheme.value = true; Utils.timeout(2000, () => openColorScheme.value = false);'
bind = Super, K, exec, for ((i=0; i<$(xrandr --listmonitors | grep -c 'Monitor'); i++)); do ags -t "osk""$i"; done bind = Super, K, exec, for ((i=0; i<$(hyprctl monitors -j | jq length); i++)); do ags -t "osk""$i"; done
bind = Control+Alt, Delete, exec, for ((i=0; i<$(xrandr --listmonitors | grep -c 'Monitor'); i++)); do ags -t "session""$i"; done bind = Control+Alt, Delete, exec, for ((i=0; i<$(hyprctl monitors -j | jq length); i++)); do ags -t "session""$i"; done
bindle = , XF86AudioRaiseVolume, exec, ags run-js 'indicator.popup(1);' bindle = , XF86AudioRaiseVolume, exec, ags run-js 'indicator.popup(1);'
bindle = , XF86AudioLowerVolume, exec, ags run-js 'indicator.popup(1);' bindle = , XF86AudioLowerVolume, exec, ags run-js 'indicator.popup(1);'
bindle=, XF86MonBrightnessUp, exec, ags run-js 'brightness.screen_value += 0.05; indicator.popup(1);' bindle=, XF86MonBrightnessUp, exec, ags run-js 'brightness.screen_value += 0.05; indicator.popup(1);'
@@ -206,6 +206,3 @@ bindle = Alt, L, exec, ydotool key 106:1 106:0
# Control + Side mouse btn for switching tabs (Ctrl+PgUp/PgDn) # Control + Side mouse btn for switching tabs (Ctrl+PgUp/PgDn)
# bind = Control, mouse:275, exec, ydotool key 29:1 104:1 104:0 29:0 # bind = Control, mouse:275, exec, ydotool key 29:1 104:1 104:0 29:0
# bind = Control, mouse:276, exec, ydotool key 29:1 109:1 109:0 29:0 # bind = Control, mouse:276, exec, ydotool key 29:1 109:1 109:0 29:0