2023-10-02 12:06:35 -04:00
|
|
|
import { Hyprland, Widget } from '../../imports.js';
|
|
|
|
const { Revealer, CenterBox, Box, EventBox, Label, Overlay } = Widget;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
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 => {
|
2023-09-28 22:45:23 -04:00
|
|
|
let minId = i * VARS.WORKSPACE_PER_ROW;
|
|
|
|
let activeId = Hyprland.active.workspace.id;
|
|
|
|
|
|
|
|
rev.revealChild = Hyprland.workspaces.some(ws => ws.id > minId &&
|
2023-09-23 18:41:05 -04:00
|
|
|
(ws.windows > 0 ||
|
2023-09-28 22:45:23 -04:00
|
|
|
ws.id === activeId));
|
2023-09-23 18:41:05 -04:00
|
|
|
}]],
|
|
|
|
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 => {
|
2023-09-28 22:45:23 -04:00
|
|
|
let maxId = i * VARS.WORKSPACE_PER_ROW + VARS.WORKSPACE_PER_ROW;
|
|
|
|
let activeId = Hyprland.active.workspace.id;
|
|
|
|
|
2023-09-23 22:08:29 -04:00
|
|
|
eventbox._box.revealChild = className === 'special' ||
|
2023-09-28 22:45:23 -04:00
|
|
|
!Hyprland.workspaces.some(ws => ws.id > maxId &&
|
|
|
|
(ws.windows > 0 ||
|
|
|
|
ws.id === activeId));
|
2023-09-23 22:08:29 -04:00
|
|
|
}]],
|
2023-09-23 21:34:49 -04:00
|
|
|
child: Box({
|
|
|
|
className: className,
|
|
|
|
children: [
|
2023-10-17 13:47:02 -04:00
|
|
|
Workspace(className === 'special' ? -1 : 1000,
|
|
|
|
className === 'special' ? 'special' : '',
|
|
|
|
true),
|
2023-09-23 21:34:49 -04:00
|
|
|
],
|
|
|
|
}),
|
2023-09-23 18:41:05 -04:00
|
|
|
}), null],
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
// TODO: please make this readable for the love of god
|
|
|
|
const Workspace = (id, name, extra = false) => {
|
|
|
|
let workspace;
|
2023-10-18 11:53:49 -04:00
|
|
|
let fixed = Gtk.Fixed.new();
|
2023-09-28 22:45:23 -04:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
if (!extra) {
|
|
|
|
workspace = Revealer({
|
|
|
|
transition: 'slide_right',
|
|
|
|
transitionDuration: 500,
|
|
|
|
properties: [
|
|
|
|
['id', id],
|
|
|
|
['name', name],
|
|
|
|
['timeouts', []],
|
|
|
|
['wasActive', false],
|
|
|
|
],
|
|
|
|
connections: [[Hyprland, box => {
|
|
|
|
box._timeouts.forEach(timer => timer.destroy());
|
2023-09-28 22:45:23 -04:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
let activeId = Hyprland.active.workspace.id;
|
|
|
|
let active = activeId === box._id;
|
2023-09-28 22:45:23 -04:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
let rev = box.child.child.get_children()[1];
|
|
|
|
let n = activeId > box._id;
|
2023-09-28 22:45:23 -04:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
if (Hyprland.getWorkspace(box._id)?.windows > 0 || active) {
|
|
|
|
rev.setStyle(DEFAULT_STYLE);
|
|
|
|
box._timeouts.push(setTimeout(() => {
|
|
|
|
box.revealChild = true;
|
|
|
|
}, 100));
|
2023-09-28 22:45:23 -04:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
}
|
|
|
|
else if (!Hyprland.getWorkspace(box._id)?.windows > 0) {
|
|
|
|
rev.setStyle(DEFAULT_STYLE);
|
|
|
|
box._timeouts.push(setTimeout(() => {
|
|
|
|
box.revealChild = false;
|
|
|
|
}, 100));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (active) {
|
|
|
|
rev.setStyle(`${DEFAULT_STYLE}
|
2023-09-28 22:45:23 -04:00
|
|
|
transition: margin 0.5s ease-in-out;
|
|
|
|
opacity: 1;`);
|
2023-10-17 13:47:02 -04:00
|
|
|
box._wasActive = true;
|
|
|
|
}
|
|
|
|
else if (box._wasActive) {
|
|
|
|
box._timeouts.push(setTimeout(() => {
|
|
|
|
rev.setStyle(`${DEFAULT_STYLE}
|
2023-09-28 22:45:23 -04:00
|
|
|
transition: margin 0.5s ease-in-out;
|
|
|
|
opacity: 1; margin-left: ${n ? '' : '-'}300px;
|
|
|
|
margin-right: ${n ? '-' : ''}300px;`);
|
2023-10-17 13:47:02 -04:00
|
|
|
box._wasActive = false;
|
|
|
|
}, 120));
|
|
|
|
box._timeouts.push(setTimeout(() => {
|
|
|
|
rev.setStyle(`${DEFAULT_STYLE} opacity: 0;
|
2023-09-28 22:45:23 -04:00
|
|
|
margin-left: ${n ? '' : '-'}300px;
|
|
|
|
margin-right: ${n ? '-' : ''}300px;`);
|
2023-10-17 13:47:02 -04:00
|
|
|
}, 500));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rev.setStyle(`${DEFAULT_STYLE} opacity: 0;
|
2023-09-28 22:45:23 -04:00
|
|
|
margin-left: ${n ? '' : '-'}300px;
|
|
|
|
margin-right: ${n ? '-' : ''}300px;`);
|
2023-10-17 13:47:02 -04:00
|
|
|
}
|
|
|
|
}]],
|
|
|
|
child: WorkspaceDrop({
|
|
|
|
child: Overlay({
|
|
|
|
child: Box({
|
|
|
|
className: 'workspace active',
|
|
|
|
style: `${DEFAULT_STYLE} opacity: 0;`,
|
2023-10-02 14:17:48 -04:00
|
|
|
}),
|
2023-10-17 13:47:02 -04:00
|
|
|
overlays: [
|
|
|
|
Box({
|
|
|
|
className: 'workspace active',
|
|
|
|
style: `${DEFAULT_STYLE} opacity: 0;`,
|
|
|
|
}),
|
|
|
|
Box({
|
|
|
|
className: 'workspace',
|
|
|
|
style: DEFAULT_STYLE,
|
|
|
|
child: fixed,
|
|
|
|
})
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
workspace = Revealer({
|
|
|
|
transition: 'slide_right',
|
|
|
|
properties: [
|
|
|
|
['id', id],
|
|
|
|
['name', name],
|
2023-10-02 14:17:48 -04:00
|
|
|
],
|
2023-10-17 13:47:02 -04:00
|
|
|
child: WorkspaceDrop({
|
|
|
|
child: Overlay({
|
|
|
|
child: Box({
|
|
|
|
className: 'workspace',
|
|
|
|
style: DEFAULT_STYLE,
|
|
|
|
}),
|
|
|
|
overlays: [
|
|
|
|
Box({
|
|
|
|
className: 'workspace active',
|
|
|
|
style: `${DEFAULT_STYLE} opacity: 0;`,
|
|
|
|
}),
|
|
|
|
Box({
|
|
|
|
style: DEFAULT_STYLE,
|
|
|
|
children: [
|
|
|
|
fixed,
|
|
|
|
Label({
|
|
|
|
label: ' +',
|
|
|
|
style: 'font-size: 40px;',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
})
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
workspace.getFixed = () => fixed;
|
|
|
|
return workspace;
|
|
|
|
};
|
2023-09-23 18:41:05 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
});
|
|
|
|
}
|