2023-10-31 08:32:40 -04:00
|
|
|
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
|
|
|
import { Revealer, CenterBox, Box, EventBox, Label } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
import Gtk from 'gi://Gtk';
|
2023-09-23 18:41:05 -04:00
|
|
|
|
|
|
|
import { WorkspaceDrop } from './dragndrop.js';
|
|
|
|
import * as VARS from './variables.js';
|
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
const DEFAULT_STYLE = `min-width: ${VARS.SCREEN.X * VARS.SCALE}px;
|
2023-09-28 22:45:23 -04:00
|
|
|
min-height: ${VARS.SCREEN.Y * VARS.SCALE}px;`;
|
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-09-23 18:41:05 -04:00
|
|
|
export function getWorkspaces(box) {
|
2023-10-20 23:11:21 -04:00
|
|
|
const children = [];
|
|
|
|
box.children.forEach(type => {
|
|
|
|
type.children.forEach(row => {
|
|
|
|
row.child.centerWidget.child.children.forEach(ch => {
|
|
|
|
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-09-23 18:41:05 -04:00
|
|
|
|
|
|
|
export const WorkspaceRow = (className, i) => Revealer({
|
2023-10-20 23:11:21 -04:00
|
|
|
transition: 'slide_down',
|
2023-10-30 22:00:46 -04:00
|
|
|
halign: className === 'special' ? '' : 'start',
|
2023-10-20 23:11:21 -04:00
|
|
|
connections: [[Hyprland, rev => {
|
|
|
|
const minId = i * VARS.WORKSPACE_PER_ROW;
|
|
|
|
const activeId = Hyprland.active.workspace.id;
|
|
|
|
|
2023-10-30 22:00:46 -04:00
|
|
|
rev.revealChild = Hyprland.workspaces
|
|
|
|
.some(ws => ws.id > minId &&
|
|
|
|
(ws.windows > 0 || ws.id === activeId));
|
2023-10-20 23:11:21 -04:00
|
|
|
}]],
|
|
|
|
child: CenterBox({
|
|
|
|
children: [null, EventBox({
|
2023-10-30 22:00:46 -04:00
|
|
|
// save ref to the 'add' workspace
|
2023-10-20 23:11:21 -04:00
|
|
|
properties: [['box']],
|
|
|
|
setup: eventbox => eventbox._box = eventbox.child.children[0],
|
2023-10-30 22:00:46 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
connections: [[Hyprland, eventbox => {
|
|
|
|
const maxId = i * VARS.WORKSPACE_PER_ROW + VARS.WORKSPACE_PER_ROW;
|
|
|
|
const activeId = Hyprland.active.workspace.id;
|
|
|
|
|
|
|
|
eventbox._box.revealChild = className === 'special' ||
|
2023-10-30 22:00:46 -04:00
|
|
|
!Hyprland.workspaces.some(ws => ws.id > maxId &&
|
|
|
|
(ws.windows > 0 || ws.id === activeId));
|
2023-10-20 23:11:21 -04:00
|
|
|
}]],
|
|
|
|
child: Box({
|
|
|
|
className: className,
|
|
|
|
children: [
|
2023-10-30 22:00:46 -04:00
|
|
|
// the 'add' workspace
|
2023-10-20 23:11:21 -04:00
|
|
|
Workspace(className === 'special' ? -1 : 1000,
|
|
|
|
className === 'special' ? 'special' : '',
|
|
|
|
true),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
}), null],
|
|
|
|
}),
|
2023-09-23 18:41:05 -04:00
|
|
|
});
|
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
const Workspace = (id, name, extra = false) => {
|
2023-10-20 23:11:21 -04:00
|
|
|
let workspace;
|
|
|
|
const fixed = Gtk.Fixed.new();
|
|
|
|
|
|
|
|
if (!extra) {
|
|
|
|
workspace = Revealer({
|
|
|
|
transition: 'slide_right',
|
|
|
|
transitionDuration: 500,
|
|
|
|
properties: [
|
|
|
|
['id', id],
|
|
|
|
['name', name],
|
|
|
|
],
|
|
|
|
connections: [[Hyprland, box => {
|
|
|
|
const activeId = Hyprland.active.workspace.id;
|
|
|
|
const active = activeId === box._id;
|
|
|
|
|
2023-10-30 22:00:46 -04:00
|
|
|
box.revealChild = Hyprland.getWorkspace(box._id)?.windows > 0 || active;
|
2023-10-20 23:11:21 -04:00
|
|
|
}]],
|
|
|
|
child: WorkspaceDrop({
|
2023-10-30 22:00:46 -04:00
|
|
|
child: Box({
|
|
|
|
className: 'workspace',
|
|
|
|
style: DEFAULT_STYLE,
|
|
|
|
child: fixed,
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
2023-10-17 13:47:02 -04:00
|
|
|
}),
|
2023-10-20 23:11:21 -04:00
|
|
|
});
|
|
|
|
}
|
2023-10-30 22:00:46 -04:00
|
|
|
// 'add' workspace
|
2023-10-20 23:11:21 -04:00
|
|
|
else {
|
|
|
|
workspace = Revealer({
|
|
|
|
transition: 'slide_right',
|
|
|
|
properties: [
|
|
|
|
['id', id],
|
|
|
|
['name', name],
|
|
|
|
],
|
|
|
|
child: WorkspaceDrop({
|
2023-10-30 22:00:46 -04:00
|
|
|
child: Box({
|
|
|
|
style: `min-width: ${VARS.SCREEN.X * VARS.SCALE / 2}px;
|
|
|
|
min-height: ${VARS.SCREEN.Y * VARS.SCALE}px;`,
|
|
|
|
children: [
|
|
|
|
fixed,
|
|
|
|
Label({
|
|
|
|
label: ' +',
|
|
|
|
style: 'font-size: 40px;',
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
],
|
2023-10-17 13:47:02 -04:00
|
|
|
}),
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
}
|
2023-10-17 13:47:02 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
workspace.getFixed = () => fixed;
|
|
|
|
return workspace;
|
2023-10-17 13:47:02 -04:00
|
|
|
};
|
2023-09-23 18:41:05 -04:00
|
|
|
|
|
|
|
export function updateWorkspaces(box) {
|
2023-10-20 23:11:21 -04:00
|
|
|
Hyprland.workspaces.forEach(ws => {
|
|
|
|
const 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)
|
|
|
|
box.children[type].add(WorkspaceRow(type ? 'special' : 'normal', i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
});
|
|
|
|
box.show_all();
|
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-09-23 18:41:05 -04:00
|
|
|
}
|