Add ags workspaces
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
17
users/configs/ags/config/src/index.ts
Normal file
17
users/configs/ags/config/src/index.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import gtk from 'gi://Gtk?version=3.0';
|
||||
import gdk from 'gi://Gdk';
|
||||
import { range } from 'lib';
|
||||
import themeInit from 'theme';
|
||||
import bar from 'widgets/bar/bar';
|
||||
|
||||
const forMonitors = (widget: (monitor: number) => gtk.Window) => {
|
||||
const n = gdk.Display.get_default()?.get_n_monitors() || 1;
|
||||
return range(n, 0).flatMap(widget);
|
||||
};
|
||||
|
||||
App.config({
|
||||
style: themeInit(),
|
||||
windows: [
|
||||
...forMonitors(bar),
|
||||
]
|
||||
});
|
3
users/configs/ags/config/src/lib.ts
Normal file
3
users/configs/ags/config/src/lib.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const range = (length: number, start = 1) => {
|
||||
return Array.from({ length }, (n, i) => i + start);
|
||||
};
|
25
users/configs/ags/config/src/theme.ts
Normal file
25
users/configs/ags/config/src/theme.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
export default () => {
|
||||
const css = `${App.configDir}/theme.css`;
|
||||
const scss = `${App.configDir}/theme.sass`;
|
||||
|
||||
let themeExists = true;
|
||||
|
||||
try {
|
||||
Utils.readFile(scss);
|
||||
Utils.exec(`sassc ${scss} ${css}`);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
themeExists = false;
|
||||
}
|
||||
|
||||
Utils.monitorFile(
|
||||
`${App.configDir}/theme.sass`,
|
||||
function () {
|
||||
Utils.exec(`sassc ${scss} ${css}`);
|
||||
App.resetCss();
|
||||
App.applyCss(css);
|
||||
},
|
||||
);
|
||||
|
||||
return themeExists ? css : undefined;
|
||||
};
|
32
users/configs/ags/config/src/widgets/bar/bar.ts
Normal file
32
users/configs/ags/config/src/widgets/bar/bar.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import date from './date/date';
|
||||
import workspace from './workspace/workspace';
|
||||
|
||||
export default (monitor: number) => Widget.Window({
|
||||
monitor,
|
||||
class_name: 'bar',
|
||||
name: `bar${monitor}`,
|
||||
exclusivity: 'exclusive',
|
||||
anchor: ['top', 'right', 'left'],
|
||||
child: Widget.CenterBox({
|
||||
css: 'min-width: 2px; min-height: 2px; padding-top: 2px; padding-bottom: 2px;',
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
startWidget: Widget.Box({
|
||||
hexpand: true,
|
||||
children: [
|
||||
workspace(),
|
||||
],
|
||||
}),
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
centerWidget: Widget.Box({
|
||||
hpack: 'center',
|
||||
children: [
|
||||
date(),
|
||||
],
|
||||
}),
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
endWidget: Widget.Box({
|
||||
hexpand: true,
|
||||
children: [],
|
||||
}),
|
||||
}),
|
||||
});
|
13
users/configs/ags/config/src/widgets/bar/date/date.ts
Normal file
13
users/configs/ags/config/src/widgets/bar/date/date.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import glib from 'gi://GLib';
|
||||
|
||||
const clock = Variable(glib.DateTime.new_now_local(), {
|
||||
poll: [1000, () => glib.DateTime.new_now_local()]
|
||||
});
|
||||
|
||||
const time = Utils.derive([clock], (c) => c.format('%H:%M - %A, %d %B %Y') || '');
|
||||
|
||||
export default () => Widget.Label({
|
||||
class_name: 'label',
|
||||
justification: 'center',
|
||||
label: time.bind(),
|
||||
});
|
@@ -0,0 +1,23 @@
|
||||
import { range } from 'lib';
|
||||
|
||||
const hyprland = await Service.import('hyprland');
|
||||
const dispatch = ws => hyprland.messageAsync(`dispatch workspace ${ws}`);
|
||||
|
||||
const workspaceButton = (i: number) => Widget.Label({
|
||||
class_name: 'button',
|
||||
attribute: i,
|
||||
vpack: "center",
|
||||
setup: self => self.hook(hyprland, () => {
|
||||
self.toggleClassName('active', hyprland.active.workspace.id === i);
|
||||
self.toggleClassName('occupied', (hyprland.getWorkspace(i)?.windows || 0) > 0);
|
||||
}),
|
||||
});
|
||||
|
||||
export default () => Widget.EventBox({
|
||||
class_name: 'workspace',
|
||||
onScrollUp: () => dispatch('e-1'),
|
||||
onScrollDown: () => dispatch('e+1'),
|
||||
child: Widget.Box({
|
||||
children: range(10).map(workspaceButton),
|
||||
}),
|
||||
});
|
Reference in New Issue
Block a user