2023-10-31 08:32:40 -04:00
|
|
|
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-07 10:56:12 -05:00
|
|
|
import { Revealer, CenterBox, Box, EventBox, Fixed, Label } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-09-23 18:41:05 -04:00
|
|
|
|
|
|
|
import { WorkspaceDrop } from './dragndrop.js';
|
|
|
|
import * as VARS from './variables.js';
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
const DEFAULT_STYLE = `
|
|
|
|
min-width: ${VARS.SCREEN.X * VARS.SCALE}px;
|
|
|
|
min-height: ${VARS.SCREEN.Y * VARS.SCALE}px;
|
|
|
|
`;
|
2023-09-28 22:45:23 -04:00
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
export const getWorkspaces = (box) => {
|
2023-10-20 23:11:21 -04:00
|
|
|
const children = [];
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
box.children.forEach((type) => {
|
|
|
|
type.children.forEach((row) => {
|
|
|
|
row.child.centerWidget.child.children.forEach((ch) => {
|
2023-10-20 23:11:21 -04:00
|
|
|
children.push(ch);
|
|
|
|
});
|
|
|
|
});
|
2023-09-23 18:41:05 -04:00
|
|
|
});
|
2023-10-20 23:11:21 -04:00
|
|
|
box._workspaces = children.sort((a, b) => a._id - b._id);
|
2023-11-21 01:29:46 -05:00
|
|
|
};
|
2023-09-23 18:41:05 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
const Workspace = (id, name, normal = true) => {
|
2023-11-07 10:56:12 -05:00
|
|
|
const fixed = Fixed();
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
const workspace = Revealer({
|
|
|
|
transition: 'slide_right',
|
|
|
|
transitionDuration: 500,
|
|
|
|
|
|
|
|
connections: normal ?
|
|
|
|
|
|
|
|
[[Hyprland, (box) => {
|
2023-10-20 23:11:21 -04:00
|
|
|
const activeId = Hyprland.active.workspace.id;
|
|
|
|
const active = activeId === box._id;
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
box.revealChild = Hyprland.getWorkspace(box._id)
|
|
|
|
?.windows > 0 || active;
|
|
|
|
}]] :
|
|
|
|
|
|
|
|
[],
|
|
|
|
|
|
|
|
child: WorkspaceDrop({
|
|
|
|
child: Box({
|
|
|
|
className: 'workspace',
|
|
|
|
css: normal ?
|
|
|
|
|
|
|
|
DEFAULT_STYLE :
|
|
|
|
|
|
|
|
`
|
|
|
|
min-width: ${VARS.SCREEN.X * VARS.SCALE / 2}px;
|
|
|
|
min-height: ${VARS.SCREEN.Y * VARS.SCALE}px;
|
|
|
|
`,
|
|
|
|
|
|
|
|
children: normal ?
|
|
|
|
|
|
|
|
[fixed] :
|
|
|
|
|
|
|
|
[
|
2023-10-30 22:00:46 -04:00
|
|
|
fixed,
|
|
|
|
Label({
|
|
|
|
label: ' +',
|
2023-11-07 10:56:12 -05:00
|
|
|
css: 'font-size: 40px;',
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
2023-11-21 01:29:46 -05:00
|
|
|
}),
|
|
|
|
});
|
2023-10-17 13:47:02 -04:00
|
|
|
|
2023-11-07 10:56:12 -05:00
|
|
|
workspace._id = id;
|
|
|
|
workspace._name = name;
|
2023-10-20 23:11:21 -04:00
|
|
|
workspace.getFixed = () => fixed;
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
return workspace;
|
2023-10-17 13:47:02 -04:00
|
|
|
};
|
2023-09-23 18:41:05 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
export const WorkspaceRow = (className, i) => {
|
|
|
|
const addWorkspace = Workspace(
|
|
|
|
className === 'special' ? -1 : 1000,
|
|
|
|
className === 'special' ? 'special' : '',
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
|
|
|
|
return Revealer({
|
|
|
|
transition: 'slide_down',
|
|
|
|
hpack: className === 'special' ? '' : 'start',
|
|
|
|
|
|
|
|
connections: [[Hyprland, (rev) => {
|
|
|
|
const minId = i * VARS.WORKSPACE_PER_ROW;
|
|
|
|
const activeId = Hyprland.active.workspace.id;
|
|
|
|
|
|
|
|
const rowExists = Hyprland.workspaces.some((ws) => {
|
|
|
|
const isInRow = ws.id > minId;
|
|
|
|
const hasClients = ws.windows > 0;
|
|
|
|
const isActive = ws.id === activeId;
|
|
|
|
|
|
|
|
return isInRow && (hasClients || isActive);
|
|
|
|
});
|
|
|
|
|
|
|
|
rev.revealChild = rowExists;
|
|
|
|
}]],
|
|
|
|
|
|
|
|
child: CenterBox({
|
|
|
|
children: [null, EventBox({
|
|
|
|
connections: [[Hyprland, () => {
|
|
|
|
const maxId = (i + 1) * VARS.WORKSPACE_PER_ROW;
|
|
|
|
const activeId = Hyprland.active.workspace.id;
|
|
|
|
|
|
|
|
const isSpecial = className === 'special';
|
|
|
|
const nextRowExists = Hyprland.workspaces.some((ws) => {
|
|
|
|
const isInNextRow = ws.id > maxId;
|
|
|
|
const hasClients = ws.windows > 0;
|
|
|
|
const isActive = ws.id === activeId;
|
|
|
|
|
|
|
|
return isInNextRow && (hasClients || isActive);
|
|
|
|
});
|
|
|
|
|
|
|
|
addWorkspace.revealChild = isSpecial || !nextRowExists;
|
|
|
|
}]],
|
|
|
|
|
|
|
|
child: Box({
|
|
|
|
className,
|
|
|
|
children: [addWorkspace],
|
|
|
|
}),
|
|
|
|
}), null],
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const updateWorkspaces = (box) => {
|
|
|
|
Hyprland.workspaces.forEach((ws) => {
|
|
|
|
const currentWs = box._workspaces.find((ch) => ch._id === ws.id);
|
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
if (!currentWs) {
|
2023-11-21 01:29:46 -05:00
|
|
|
let type = 0;
|
|
|
|
let rowNo = 0;
|
2023-10-20 23:11:21 -04:00
|
|
|
|
|
|
|
if (ws.id < 0) {
|
|
|
|
// This means it's a special workspace
|
|
|
|
type = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rowNo = Math.floor((ws.id - 1) / VARS.WORKSPACE_PER_ROW);
|
2023-11-21 01:29:46 -05:00
|
|
|
const wsQty = box.children[type].children.length;
|
|
|
|
|
|
|
|
if (rowNo >= wsQty) {
|
|
|
|
for (let i = wsQty; i <= rowNo; ++i) {
|
|
|
|
box.children[type].add(WorkspaceRow(
|
|
|
|
type ? 'special' : 'normal', i,
|
|
|
|
));
|
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
}
|
|
|
|
}
|
2023-11-21 01:29:46 -05:00
|
|
|
const row = box.children[type].children[rowNo]
|
|
|
|
.child.centerWidget.child;
|
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
row.add(Workspace(ws.id, type ? ws.name : ''));
|
2023-09-23 18:41:05 -04:00
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
});
|
2023-09-23 18:41:05 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
// Make sure the order is correct
|
|
|
|
box._workspaces.forEach((workspace, i) => {
|
|
|
|
workspace.get_parent().reorder_child(workspace, i);
|
|
|
|
});
|
2023-11-07 10:56:12 -05:00
|
|
|
box.show_all();
|
2023-11-21 01:29:46 -05:00
|
|
|
};
|