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,
});
export const updateCurrentWorkspace = self => {
self = self.get_parent().get_children()[1];
export const updateCurrentWorkspace = (main, highlighter) => {
const currentId = Hyprland.active.workspace.id;
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 height = row * (VARS.SCREEN.Y * VARS.SCALE + 17);
const currentIndex = workspaces.findIndex(w => w._id == currentId);
self.setCss(`
highlighter.setCss(`
${DEFAULT_STYLE}
margin-left: ${9 + currentIndex * (VARS.SCREEN.X * VARS.SCALE + 34)}px;
margin-top: ${9 + height}px;

View file

@ -9,52 +9,59 @@ import { Highlighter, updateCurrentWorkspace } from './current-workspace.js';
import { updateClients } from './clients.js';
function update(box) {
function update(box, highlight) {
getWorkspaces(box);
updateWorkspaces(box);
updateClients(box);
updateCurrentWorkspace(box);
updateCurrentWorkspace(box, 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
export default () => PopupWindow({
name: 'overview',
closeOnUnfocus: 'none',
onOpen: child => update(child.child),
export default () => {
const highlighter = Highlighter();
child: Overlay({
// FIXME: see if we can get rid of this timeout
setup: self => timeout(1, () => self.pass_through = true),
const mainBox = Box({
className: 'overview',
vertical: true,
children: [
Box({
vertical: true,
children: [
WorkspaceRow('normal', 0),
],
}),
Box({
vertical: true,
children: [
WorkspaceRow('special', 0),
],
}),
],
connections: [[Hyprland, self => {
if (!App.getWindow('overview').visible)
return;
overlays: [Highlighter()],
child: Box({
className: 'overview',
vertical: true,
children: [
Box({
vertical: true,
children: [
WorkspaceRow('normal', 0),
],
}),
Box({
vertical: true,
children: [
WorkspaceRow('special', 0),
],
}),
],
connections: [[Hyprland, self => {
if (!App.getWindow('overview').visible)
return;
update(self, highlighter);
}]],
properties: [
['workspaces'],
],
});
update(self);
}]],
properties: [
['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;
};