[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",
}
},
'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
+1 -2
View File
@@ -101,8 +101,7 @@ export const Bar = async (monitor = 0) => {
'nothing': nothingContent,
},
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;
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 Variable from 'resource:///com/github/Aylur/ags/variable.js';
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
const { exec, execAsync } = Utils;
@@ -15,18 +15,40 @@ globalThis['openMusicControls'] = showMusicControls;
globalThis['openColorScheme'] = showColorScheme;
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
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['cycleMode'] = () => {
if (currentShellMode.value === 'normal') {
currentShellMode.value = 'focus';
}
else if (currentShellMode.value === 'focus') {
currentShellMode.value = 'nothing';
const monitor = Hyprland.active.monitor.id || 0;
if (currentShellMode.value[monitor] === 'normal') {
updateMonitorShellMode(currentShellMode, monitor, 'focus')
}
else if (currentShellMode.value[monitor] === 'focus') {
updateMonitorShellMode(currentShellMode, monitor, 'nothing')
}
else {
currentShellMode.value = 'normal';
updateMonitorShellMode(currentShellMode, monitor, 'normal')
}
}