[Feature] Change shell mode per monitor (#736)

This commit is contained in:
end-4
2024-08-15 20:54:50 +07:00
committed by GitHub
3 changed files with 38 additions and 11 deletions
@@ -221,6 +221,12 @@ let configOptions = {
'cycleTab': "Ctrl+Tab", 'cycleTab': "Ctrl+Tab",
} }
}, },
'bar': {
// Array of bar modes for each monitor. Hit Ctrl+Alt+Slash to cycle.
// Modes: "normal", "focus" (workspace indicator only), "nothing"
// Example for four monitors: ["normal", "focus", "normal", "nothing"]
'modes': ["normal"]
},
} }
// Override defaults with user's options // Override defaults with user's options
+1 -2
View File
@@ -101,8 +101,7 @@ export const Bar = async (monitor = 0) => {
'nothing': nothingContent, 'nothing': nothingContent,
}, },
setup: (self) => self.hook(currentShellMode, (self) => { setup: (self) => self.hook(currentShellMode, (self) => {
self.shown = currentShellMode.value; self.shown = currentShellMode.value[monitor];
}) })
}), }),
}); });
+31 -9
View File
@@ -1,8 +1,8 @@
const { Gdk, Gtk } = imports.gi; const { Gdk, Gtk } = imports.gi;
import App from 'resource:///com/github/Aylur/ags/app.js' import App from 'resource:///com/github/Aylur/ags/app.js'
import Variable from 'resource:///com/github/Aylur/ags/variable.js'; import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
import Mpris from 'resource:///com/github/Aylur/ags/service/mpris.js'; import Mpris from 'resource:///com/github/Aylur/ags/service/mpris.js';
import Variable from 'resource:///com/github/Aylur/ags/variable.js';
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js'; import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
const { exec, execAsync } = Utils; const { exec, execAsync } = Utils;
@@ -15,18 +15,40 @@ globalThis['openMusicControls'] = showMusicControls;
globalThis['openColorScheme'] = showColorScheme; globalThis['openColorScheme'] = showColorScheme;
globalThis['mpris'] = Mpris; globalThis['mpris'] = Mpris;
// load monitor shell modes from userOptions
const initialMonitorShellModes = () => {
const numberOfMonitors = Gdk.Display.get_default()?.get_n_monitors() || 1;
const monitorBarConfigs = [];
for (let i = 0; i < numberOfMonitors; i++) {
if (userOptions.bar.modes[i]) {
monitorBarConfigs.push(userOptions.bar.modes[i])
} else {
monitorBarConfigs.push('normal')
}
}
return monitorBarConfigs;
}
export const currentShellMode = Variable(initialMonitorShellModes(), {}) // normal, focus
// Mode switching // Mode switching
export const currentShellMode = Variable('normal', {}) // normal, focus const updateMonitorShellMode = (monitorShellModes, monitor, mode) => {
const newValue = [...monitorShellModes.value];
newValue[monitor] = mode;
monitorShellModes.value = newValue;
}
globalThis['currentMode'] = currentShellMode; globalThis['currentMode'] = currentShellMode;
globalThis['cycleMode'] = () => { globalThis['cycleMode'] = () => {
if (currentShellMode.value === 'normal') { const monitor = Hyprland.active.monitor.id || 0;
currentShellMode.value = 'focus';
} if (currentShellMode.value[monitor] === 'normal') {
else if (currentShellMode.value === 'focus') { updateMonitorShellMode(currentShellMode, monitor, 'focus')
currentShellMode.value = 'nothing'; }
else if (currentShellMode.value[monitor] === 'focus') {
updateMonitorShellMode(currentShellMode, monitor, 'nothing')
} }
else { else {
currentShellMode.value = 'normal'; updateMonitorShellMode(currentShellMode, monitor, 'normal')
} }
} }