Skip to content

Commit

Permalink
[Feature] Change shell mode per monitor (end-4#736)
Browse files Browse the repository at this point in the history
  • Loading branch information
end-4 authored Aug 15, 2024
2 parents 6f5494f + db004ee commit d88ba98
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
6 changes: 6 additions & 0 deletions .config/ags/modules/.configuration/user_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions .config/ags/modules/bar/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
})
}),
});
Expand Down
40 changes: 31 additions & 9 deletions .config/ags/variables.js
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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')
}
}

Expand Down

0 comments on commit d88ba98

Please sign in to comment.