feat(ags): make workspace logic dynamic

This commit is contained in:
matt1432 2023-09-20 20:25:52 -04:00
parent ecd161ba8b
commit c057ebd15b
3 changed files with 46 additions and 27 deletions

View file

@ -5,6 +5,7 @@ import { NotificationCenter } from './js/notifications/center.js';
import { NotificationsPopupList } from './js/notifications/popup.js' import { NotificationsPopupList } from './js/notifications/popup.js'
import { Calendar } from './js/date.js'; import { Calendar } from './js/date.js';
import { QuickSettings } from './js/quick-settings/main.js'; import { QuickSettings } from './js/quick-settings/main.js';
import { Overview } from './js/overview/main.js';
import { Closer, closeAll } from './js/misc/closer.js'; import { Closer, closeAll } from './js/misc/closer.js';
ags.App.closeAll = () => closeAll(); ags.App.closeAll = () => closeAll();
@ -27,5 +28,6 @@ export default {
NotificationsPopupList, NotificationsPopupList,
Calendar, Calendar,
QuickSettings, QuickSettings,
Overview,
], ],
}; };

View file

@ -7,6 +7,9 @@ import { EventBox } from '../misc/cursorbox.js';
const Workspace = ({ i } = {}) => const Workspace = ({ i } = {}) =>
Revealer({ Revealer({
transition: "slide_right", transition: "slide_right",
properties: [
['id', i],
],
child: EventBox({ child: EventBox({
tooltipText: `${i}`, tooltipText: `${i}`,
onPrimaryClickRelease: () => execAsync(`hyprctl dispatch workspace ${i}`).catch(print), onPrimaryClickRelease: () => execAsync(`hyprctl dispatch workspace ${i}`).catch(print),
@ -29,17 +32,38 @@ export const Workspaces = Box({
className: 'workspaces', className: 'workspaces',
children: [EventBox({ children: [EventBox({
child: Box({ child: Box({
children: Array.from({ length: 15 }, (_, i) => i + 1).map(i => Workspace({ i: i})), properties: [
connections: [[Hyprland, box => { ['workspaces'],
let workspaces = [];
Hyprland.workspaces.forEach(ws => {
if (ws.id > 0) workspaces.push(ws);
});
['refresh', box => {
box.children.forEach(rev => rev.reveal_child = false); box.children.forEach(rev => rev.reveal_child = false);
workspaces.forEach(ws => { box._workspaces.forEach(ws => {
box.children[ws.id - 1].reveal_child = true; ws.revealChild = true;
}); });
}],
['updateWs', box => {
Hyprland.workspaces.forEach(ws => {
let currentWs = box.children.find(ch => ch._id == ws.id);
if (!currentWs && ws.id > 0) {
box.add(Workspace({ i: ws.id}));
}
});
box.show_all();
// Make sure the order is correct
box._workspaces.forEach((workspace, i) => {
workspace.get_parent().reorder_child(workspace, i);
});
}],
],
connections: [[Hyprland, box => {
box._workspaces = box.children.filter(ch => {
return Hyprland.workspaces.find(ws => ws.id == ch._id)
}).sort((a, b) => a._id - b._id);
box._updateWs(box);
box._refresh(box);
}]], }]],
}), }),
})], })],

View file

@ -16,7 +16,7 @@ const DEFAULT_SPECIAL = {
export const Overview = Window({ export const Overview = Window({
name: 'overview', name: 'overview',
layer: 'overlay', layer: 'overlay',
//popup: true, popup: true,
anchor: 'top', anchor: 'top',
margin: [ 0, 0, 0, 0 ], margin: [ 0, 0, 0, 0 ],
child: Box({ child: Box({
@ -45,17 +45,12 @@ export const Overview = Window({
connections: [ connections: [
[Hyprland, box => { [Hyprland, box => {
let childI = 0; let childI = 0;
box._workspaces = box.children[childI++].centerWidget.children.concat( box._workspaces = [].concat(box.children[childI++].centerWidget.children,
box.children[childI].centerWidget.children); box.children[childI].centerWidget.children)
.sort((a, b) => a._id - b._id);
// Make sure the order is correct
box._workspaces.forEach(workspace => {
workspace.get_parent().reorder_child(workspace, workspace._id)
});
box._updateWs(box); box._updateWs(box);
box._updateApps(box); box._updateApps(box);
}], }],
], ],
properties: [ properties: [
@ -142,13 +137,7 @@ export const Overview = Window({
['updateWs', box => { ['updateWs', box => {
Hyprland.workspaces.forEach(ws => { Hyprland.workspaces.forEach(ws => {
let currentWs = box._workspaces.find(ch => ch._id == ws.id) let currentWs = box._workspaces.find(ch => ch._id == ws.id)
if (currentWs) { if (!currentWs) {
if (!currentWs._ordered) {
currentWs.get_parent().reorder_child(currentWs, ws._id);
currentWs._ordered = true;
}
}
else {
var childI = 0; var childI = 0;
if (ws.id < 0) { if (ws.id < 0) {
childI = 1; childI = 1;
@ -157,7 +146,6 @@ export const Overview = Window({
currentWs = Box({ currentWs = Box({
properties: [ properties: [
['id', ws.id], ['id', ws.id],
['ordered', false],
], ],
className: 'workspace', className: 'workspace',
child: EventBox({ child: EventBox({
@ -171,6 +159,11 @@ export const Overview = Window({
} }
}); });
box.show_all(); box.show_all();
// Make sure the order is correct
box._workspaces.forEach((workspace, i) => {
workspace.get_parent().reorder_child(workspace, i)
});
}], }],
], ],
}), }),