refactor(ags overview): restructure window func to have easy refs

This commit is contained in:
matt1432 2023-11-07 12:31:39 -05:00
parent 3b65abac7e
commit 8307198659
2 changed files with 47 additions and 41 deletions

View file

@ -16,18 +16,17 @@ export const Highlighter = () => Box({
css: DEFAULT_STYLE, css: DEFAULT_STYLE,
}); });
export const updateCurrentWorkspace = self => { export const updateCurrentWorkspace = (main, highlighter) => {
self = self.get_parent().get_children()[1];
const currentId = Hyprland.active.workspace.id; const currentId = Hyprland.active.workspace.id;
const row = Math.floor((currentId - 1) / VARS.WORKSPACE_PER_ROW); const row = Math.floor((currentId - 1) / VARS.WORKSPACE_PER_ROW);
const rowObject = self.get_parent().get_children()[0].children[0].children[row]; const rowObject = main.children[0].children[row];
const workspaces = rowObject.child.centerWidget.child.get_children().filter(w => w.revealChild); const workspaces = rowObject.child.centerWidget.child.get_children().filter(w => w.revealChild);
const height = row * (VARS.SCREEN.Y * VARS.SCALE + 17); const height = row * (VARS.SCREEN.Y * VARS.SCALE + 17);
const currentIndex = workspaces.findIndex(w => w._id == currentId); const currentIndex = workspaces.findIndex(w => w._id == currentId);
self.setCss(` highlighter.setCss(`
${DEFAULT_STYLE} ${DEFAULT_STYLE}
margin-left: ${9 + currentIndex * (VARS.SCREEN.X * VARS.SCALE + 34)}px; margin-left: ${9 + currentIndex * (VARS.SCREEN.X * VARS.SCALE + 34)}px;
margin-top: ${9 + height}px; margin-top: ${9 + height}px;

View file

@ -9,26 +9,19 @@ import { Highlighter, updateCurrentWorkspace } from './current-workspace.js';
import { updateClients } from './clients.js'; import { updateClients } from './clients.js';
function update(box) { function update(box, highlight) {
getWorkspaces(box); getWorkspaces(box);
updateWorkspaces(box); updateWorkspaces(box);
updateClients(box); updateClients(box);
updateCurrentWorkspace(box); updateCurrentWorkspace(box, highlight);
} }
// FIXME: can't drag in workspaces that are before the highlight // FIXME: can't drag in workspaces that are before the highlight
// TODO: have a 'page' for each monitor, arrows on both sides to loop through // TODO: have a 'page' for each monitor, arrows on both sides to loop through
export default () => PopupWindow({ export default () => {
name: 'overview', const highlighter = Highlighter();
closeOnUnfocus: 'none',
onOpen: child => update(child.child),
child: Overlay({ const mainBox = Box({
// FIXME: see if we can get rid of this timeout
setup: self => timeout(1, () => self.pass_through = true),
overlays: [Highlighter()],
child: Box({
className: 'overview', className: 'overview',
vertical: true, vertical: true,
children: [ children: [
@ -49,12 +42,26 @@ export default () => PopupWindow({
if (!App.getWindow('overview').visible) if (!App.getWindow('overview').visible)
return; return;
update(self); update(self, highlighter);
}]], }]],
properties: [ properties: [
['workspaces'], ['workspaces'],
], ],
}), });
const window = PopupWindow({
name: 'overview',
closeOnUnfocus: 'none',
onOpen: () => update(mainBox, highlighter),
child: Overlay({
// FIXME: see if we can get rid of this timeout
setup: self => timeout(1, () => self.pass_through = true),
overlays: [highlighter],
child: mainBox,
}), }),
}); });
return window;
};