2023-09-23 21:34:49 -04:00
|
|
|
const { Revealer, CenterBox, Box, EventBox, Label } = ags.Widget;
|
2023-09-23 18:41:05 -04:00
|
|
|
const { Hyprland } = ags.Service;
|
|
|
|
const { Gtk } = imports.gi;
|
|
|
|
|
|
|
|
import { WorkspaceDrop } from './dragndrop.js';
|
|
|
|
import * as VARS from './variables.js';
|
|
|
|
|
|
|
|
export function getWorkspaces(box) {
|
|
|
|
let children = [];
|
|
|
|
box.children.forEach(type => {
|
|
|
|
type.children.forEach(row => {
|
2023-09-23 21:34:49 -04:00
|
|
|
row.child.centerWidget.child.children.forEach(ch => {
|
2023-09-23 18:41:05 -04:00
|
|
|
children.push(ch);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
box._workspaces = children.sort((a, b) => a._id - b._id);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const WorkspaceRow = (className, i) => Revealer({
|
|
|
|
transition: 'slide_down',
|
|
|
|
connections: [[Hyprland, rev => {
|
|
|
|
rev.revealChild = Hyprland.workspaces.some(ws => ws.id > i * VARS.WORKSPACE_PER_ROW &&
|
|
|
|
(ws.windows > 0 ||
|
|
|
|
ws.id === Hyprland.active.workspace.id));
|
|
|
|
}]],
|
|
|
|
child: CenterBox({
|
2023-09-23 21:34:49 -04:00
|
|
|
children: [null, EventBox({
|
|
|
|
properties: [['box']],
|
|
|
|
setup: eventbox => eventbox._box = eventbox.child.children[0],
|
2023-09-23 22:08:29 -04:00
|
|
|
connections: [[Hyprland, eventbox => {
|
|
|
|
eventbox._box.revealChild = className === 'special' ||
|
|
|
|
!Hyprland.workspaces.some(ws => ws.id > i * VARS.WORKSPACE_PER_ROW + VARS.WORKSPACE_PER_ROW && (ws.windows > 0 || ws.id === Hyprland.active.workspace.id));
|
|
|
|
}]],
|
2023-09-23 21:34:49 -04:00
|
|
|
child: Box({
|
|
|
|
className: className,
|
|
|
|
children: [
|
|
|
|
Revealer({
|
|
|
|
transition: 'slide_right',
|
|
|
|
properties: [
|
|
|
|
['id', className === 'special' ? -1 : 1000],
|
|
|
|
['name', className === 'special' ? 'special' : ''],
|
|
|
|
],
|
|
|
|
child: WorkspaceDrop({
|
|
|
|
child: Box({
|
|
|
|
className: 'workspace',
|
|
|
|
style: `min-width: ${VARS.SCREEN.X * VARS.SCALE}px;
|
|
|
|
min-height: ${VARS.SCREEN.Y * VARS.SCALE}px;`,
|
|
|
|
children: [
|
|
|
|
ags.Widget({
|
|
|
|
type: Gtk.Fixed,
|
|
|
|
}),
|
|
|
|
Label({
|
|
|
|
label: ' +',
|
|
|
|
style: 'font-size: 40px;',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
2023-09-23 18:41:05 -04:00
|
|
|
}), null],
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
2023-09-23 21:34:49 -04:00
|
|
|
const Workspace = (id, name) => Revealer({
|
2023-09-23 18:41:05 -04:00
|
|
|
transition: 'slide_right',
|
|
|
|
properties: [
|
|
|
|
['id', id],
|
2023-09-23 21:34:49 -04:00
|
|
|
['name', name],
|
2023-09-23 18:41:05 -04:00
|
|
|
],
|
|
|
|
connections: [[Hyprland, box => {
|
|
|
|
let active = Hyprland.active.workspace.id === box._id;
|
|
|
|
box.child.child.toggleClassName('active', active);
|
|
|
|
box.revealChild = Hyprland.getWorkspace(box._id)?.windows > 0 || active;
|
|
|
|
}]],
|
|
|
|
child: WorkspaceDrop({
|
|
|
|
child: Box({
|
|
|
|
className: 'workspace',
|
|
|
|
style: `min-width: ${VARS.SCREEN.X * VARS.SCALE}px;
|
|
|
|
min-height: ${VARS.SCREEN.Y * VARS.SCALE}px;`,
|
|
|
|
child: ags.Widget({
|
|
|
|
type: Gtk.Fixed,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
export function updateWorkspaces(box) {
|
|
|
|
Hyprland.workspaces.forEach(ws => {
|
|
|
|
let currentWs = box._workspaces.find(ch => ch._id == ws.id);
|
|
|
|
if (!currentWs) {
|
|
|
|
var type = 0;
|
|
|
|
var rowNo = 0;
|
|
|
|
|
|
|
|
if (ws.id < 0) {
|
|
|
|
// This means it's a special workspace
|
|
|
|
type = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rowNo = Math.floor((ws.id - 1) / VARS.WORKSPACE_PER_ROW);
|
|
|
|
if (rowNo >= box.children[type].children.length) {
|
|
|
|
for (let i = box.children[type].children.length; i <= rowNo; ++i) {
|
2023-09-23 21:34:49 -04:00
|
|
|
box.children[type].add(WorkspaceRow(type ? 'special' : 'normal', i));
|
2023-09-23 18:41:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-23 21:34:49 -04:00
|
|
|
var row = box.children[type].children[rowNo].child.centerWidget.child;
|
|
|
|
row.add(Workspace(ws.id, type ? ws.name : ''));
|
2023-09-23 18:41:05 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
box.show_all();
|
|
|
|
|
|
|
|
// Make sure the order is correct
|
|
|
|
box._workspaces.forEach((workspace, i) => {
|
|
|
|
workspace.get_parent().reorder_child(workspace, i)
|
|
|
|
});
|
|
|
|
}
|