style(ags workspaces): clarify code a bit

This commit is contained in:
matt1432 2023-09-05 13:27:29 -04:00
parent a9e4951e3a
commit ca4e1be045

View file

@ -1,22 +1,14 @@
// https://github.com/Aylur/dotfiles/blob/f03e58ba0d3b56f1144631c179ab27357e466753/.config/ags/modules/hyprland.js#L4
import Gdk from 'gi://Gdk';
const display = Gdk.Display.get_default();
const { App } = ags;
const { Hyprland, Applications } = ags.Service; const { Hyprland, Applications } = ags.Service;
const { execAsync, lookUpIcon } = ags.Utils; const { execAsync } = ags.Utils;
const { Box, Button, EventBox, Label, Icon } = ags.Widget; const { Box, Button, Label, Revealer } = ags.Widget;
export const Workspace = ({ i, } = {}) => import { EventBox } from '../common.js';
ags.Widget.Revealer({
const Workspace = ({ i } = {}) =>
Revealer({
transition: "slide_right", transition: "slide_right",
child: EventBox({ child: EventBox({
onPrimaryClickRelease: () => execAsync(`hyprctl dispatch workspace ${i}`).catch(print), onPrimaryClickRelease: () => execAsync(`hyprctl dispatch workspace ${i}`).catch(print),
onHover: box => {
box.window.set_cursor(Gdk.Cursor.new_from_name(display, 'pointer'));
},
onHoverLost: box => {
box.window.set_cursor(null);
},
child: Box({ child: Box({
className: 'button', className: 'button',
child: Label(`${i}`), child: Label(`${i}`),
@ -33,32 +25,22 @@ ags.Widget.Revealer({
}), }),
}); });
var prev = Hyprland.active.workspace.id;
export const Workspaces = props => Box({ export const Workspaces = props => Box({
className: 'workspaces panel-button', className: 'workspaces',
children: [EventBox({ children: [EventBox({
child: Box({ child: Box({
children: Array.from({ length: 15 }, (_, i) => i + 1).map(i => Workspace({ i: i})),
connections: [[Hyprland, box => { connections: [[Hyprland, box => {
let workspaces = []; let workspaces = [];
Hyprland.workspaces.forEach(ws => {
if (ws.id > 0) workspaces.push(ws);
});
new Promise(resolve => { box.children.forEach(rev => rev.reveal_child = false);
workspaces.forEach(ws => {
Hyprland.workspaces.forEach(ws => { box.children[ws.id - 1].reveal_child = true;
if (ws.id > 0) workspaces.push(ws);
});
resolve();
}).then(value => {
box.children.forEach(rev => rev.reveal_child = false);
workspaces.forEach(ws => {
box.children[ws.id - 1].reveal_child = true;
});
}); });
}]], }]],
children: Array.from({ length: 15 }, (_, i) => i + 1).map(i => Workspace({ i: i})),
}), }),
})], })],
}); });