2023-09-20 14:20:05 -04:00
|
|
|
const { Window, Box, CenterBox, Icon, Revealer } = ags.Widget;
|
2023-09-19 23:24:46 -04:00
|
|
|
const { Hyprland, Applications } = ags.Service;
|
|
|
|
const { Gtk } = imports.gi;
|
|
|
|
|
|
|
|
import { EventBox } from '../misc/cursorbox.js';
|
|
|
|
|
|
|
|
const SCALE = 0.11;
|
|
|
|
const MARGIN = 8;
|
2023-09-20 21:52:04 -04:00
|
|
|
const SCREEN = {
|
|
|
|
X: 1920,
|
|
|
|
Y: 1200,
|
|
|
|
}
|
2023-09-20 14:20:05 -04:00
|
|
|
const DEFAULT_SPECIAL = {
|
|
|
|
SIZE_X: 1524,
|
|
|
|
SIZE_Y: 908,
|
|
|
|
POS_X: 197,
|
|
|
|
POS_Y: 170,
|
|
|
|
};
|
2023-09-19 23:24:46 -04:00
|
|
|
|
|
|
|
export const Overview = Window({
|
|
|
|
name: 'overview',
|
|
|
|
layer: 'overlay',
|
2023-09-20 20:25:52 -04:00
|
|
|
popup: true,
|
2023-09-19 23:24:46 -04:00
|
|
|
anchor: 'top',
|
|
|
|
margin: [ 0, 0, 0, 0 ],
|
|
|
|
child: Box({
|
|
|
|
className: 'overview',
|
|
|
|
vertical: true,
|
|
|
|
children: [
|
|
|
|
CenterBox({
|
|
|
|
children: [
|
|
|
|
null,
|
|
|
|
Box({
|
|
|
|
className: 'normal',
|
|
|
|
}),
|
|
|
|
null,
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
CenterBox({
|
|
|
|
children: [
|
|
|
|
null,
|
|
|
|
Box({
|
|
|
|
className: 'special',
|
|
|
|
}),
|
|
|
|
null,
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
connections: [
|
|
|
|
[Hyprland, box => {
|
2023-09-20 14:20:05 -04:00
|
|
|
let childI = 0;
|
2023-09-20 20:25:52 -04:00
|
|
|
box._workspaces = [].concat(box.children[childI++].centerWidget.children,
|
|
|
|
box.children[childI].centerWidget.children)
|
|
|
|
.sort((a, b) => a._id - b._id);
|
2023-09-19 23:24:46 -04:00
|
|
|
|
2023-09-20 16:02:04 -04:00
|
|
|
box._updateWs(box);
|
|
|
|
box._updateApps(box);
|
2023-09-19 23:24:46 -04:00
|
|
|
}],
|
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
['workspaces'],
|
|
|
|
|
|
|
|
['updateApps', box => {
|
|
|
|
ags.Utils.execAsync('hyprctl clients -j')
|
|
|
|
.then(result => {
|
2023-09-20 21:52:04 -04:00
|
|
|
let clients = JSON.parse(result).filter(client => client.class)
|
2023-09-19 23:24:46 -04:00
|
|
|
|
|
|
|
box._workspaces.forEach(workspace => {
|
2023-09-20 22:17:33 -04:00
|
|
|
let fixed = workspace.child.child.children[0];
|
2023-09-20 14:20:05 -04:00
|
|
|
let toRemove = fixed.get_children();
|
2023-09-19 23:24:46 -04:00
|
|
|
|
2023-09-20 21:52:04 -04:00
|
|
|
clients.filter(app => app.workspace.id == workspace._id).forEach(app => {
|
2023-09-19 23:24:46 -04:00
|
|
|
let active = '';
|
|
|
|
if (app.address == Hyprland.active.client.address) {
|
|
|
|
active = 'active';
|
|
|
|
}
|
|
|
|
|
2023-09-20 14:20:05 -04:00
|
|
|
// Special workspaces that haven't been opened yet
|
2023-09-20 14:46:39 -04:00
|
|
|
// return a size of 0. We need to set them to default
|
|
|
|
// values to show the workspace properly
|
2023-09-19 23:24:46 -04:00
|
|
|
if (app.size[0] === 0) {
|
2023-09-20 14:20:05 -04:00
|
|
|
app.size[0] = DEFAULT_SPECIAL.SIZE_X;
|
|
|
|
app.size[1] = DEFAULT_SPECIAL.SIZE_Y;
|
|
|
|
app.at[0] = DEFAULT_SPECIAL.POS_X;
|
|
|
|
app.at[1] = DEFAULT_SPECIAL.POS_Y;
|
2023-09-19 23:24:46 -04:00
|
|
|
}
|
|
|
|
|
2023-09-20 14:20:05 -04:00
|
|
|
let existingApp = fixed.get_children().find(ch => ch._address == app.address);
|
|
|
|
toRemove.splice(toRemove.indexOf(existingApp), 1);
|
|
|
|
|
|
|
|
if (existingApp) {
|
|
|
|
fixed.move(
|
|
|
|
existingApp,
|
|
|
|
app.at[0] * SCALE,
|
|
|
|
app.at[1] * SCALE,
|
|
|
|
);
|
|
|
|
existingApp.child.className = `window ${active}`;
|
|
|
|
existingApp.child.style = `min-width: ${app.size[0] * SCALE - MARGIN}px;
|
2023-09-20 14:46:39 -04:00
|
|
|
min-height: ${app.size[1] * SCALE - MARGIN}px;`;
|
2023-09-20 14:20:05 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
fixed.put(
|
|
|
|
Revealer({
|
|
|
|
transition: 'slide_right',
|
|
|
|
connections: [[Hyprland, rev => {
|
|
|
|
rev.revealChild = true;
|
|
|
|
}]],
|
|
|
|
properties: [
|
|
|
|
['address', app.address],
|
|
|
|
['toDestroy', false]
|
|
|
|
],
|
|
|
|
child: Icon({
|
|
|
|
className: `window ${active}`,
|
|
|
|
style: `min-width: ${app.size[0] * SCALE - MARGIN}px;
|
2023-09-20 14:46:39 -04:00
|
|
|
min-height: ${app.size[1] * SCALE - MARGIN}px;`,
|
2023-09-20 14:20:05 -04:00
|
|
|
icon: app.class,
|
|
|
|
size: 40,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
app.at[0] * SCALE,
|
|
|
|
app.at[1] * SCALE,
|
|
|
|
);
|
|
|
|
}
|
2023-09-19 23:24:46 -04:00
|
|
|
});
|
|
|
|
fixed.show_all();
|
2023-09-20 14:20:05 -04:00
|
|
|
toRemove.forEach(ch => {
|
|
|
|
if (ch._toDestroy) {
|
|
|
|
ch.destroy();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ch.revealChild = false;
|
|
|
|
ch._toDestroy = true;
|
|
|
|
}
|
|
|
|
});
|
2023-09-19 23:24:46 -04:00
|
|
|
});
|
|
|
|
}).catch(print);
|
|
|
|
}],
|
|
|
|
|
|
|
|
['updateWs', box => {
|
2023-09-20 16:02:04 -04:00
|
|
|
Hyprland.workspaces.forEach(ws => {
|
|
|
|
let currentWs = box._workspaces.find(ch => ch._id == ws.id)
|
2023-09-20 20:25:52 -04:00
|
|
|
if (!currentWs) {
|
2023-09-19 23:24:46 -04:00
|
|
|
var childI = 0;
|
|
|
|
if (ws.id < 0) {
|
|
|
|
childI = 1;
|
|
|
|
}
|
|
|
|
|
2023-09-20 22:17:33 -04:00
|
|
|
currentWs = Revealer({
|
|
|
|
transition: 'slide_right',
|
2023-09-20 16:02:04 -04:00
|
|
|
properties: [
|
|
|
|
['id', ws.id],
|
|
|
|
],
|
2023-09-20 21:52:04 -04:00
|
|
|
connections: [[Hyprland, box => {
|
|
|
|
let active = Hyprland.active.workspace.id === box._id;
|
2023-09-20 22:17:33 -04:00
|
|
|
box.child.child.toggleClassName('active', active);
|
|
|
|
box.revealChild = Hyprland.getWorkspace(box._id)?.windows > 0 || active;
|
2023-09-20 21:52:04 -04:00
|
|
|
}]],
|
2023-09-20 16:02:04 -04:00
|
|
|
child: EventBox({
|
|
|
|
tooltipText: `Workspace: ${ws.id}`,
|
2023-09-20 22:17:33 -04:00
|
|
|
child: Box({
|
|
|
|
className: 'workspace',
|
|
|
|
style: `min-width: ${SCREEN.X * SCALE}px;
|
|
|
|
min-height: ${SCREEN.Y * SCALE}px;`,
|
|
|
|
child: ags.Widget({
|
|
|
|
type: Gtk.Fixed,
|
|
|
|
}),
|
2023-09-19 23:24:46 -04:00
|
|
|
}),
|
2023-09-20 16:02:04 -04:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
box.children[childI].centerWidget.add(currentWs);
|
2023-09-19 23:24:46 -04:00
|
|
|
}
|
|
|
|
});
|
2023-09-20 16:02:04 -04:00
|
|
|
box.show_all();
|
2023-09-20 20:25:52 -04:00
|
|
|
|
|
|
|
// Make sure the order is correct
|
|
|
|
box._workspaces.forEach((workspace, i) => {
|
|
|
|
workspace.get_parent().reorder_child(workspace, i)
|
|
|
|
});
|
2023-09-19 23:24:46 -04:00
|
|
|
}],
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
});
|