overview: only fully update when switching group

This commit is contained in:
end-4
2024-02-13 21:20:22 +07:00
parent bec26cba7d
commit 1577287624
@@ -51,6 +51,7 @@ function substitute(str) {
} }
export default () => { export default () => {
const clientMap = new Map(); const clientMap = new Map();
let workspaceGroup = 0;
const ContextMenuWorkspaceArray = ({ label, actionFunc, thisWorkspace }) => Widget.MenuItem({ const ContextMenuWorkspaceArray = ({ label, actionFunc, thisWorkspace }) => Widget.MenuItem({
label: `${label}`, label: `${label}`,
setup: (menuItem) => { setup: (menuItem) => {
@@ -102,8 +103,6 @@ export default () => {
}, },
}, },
className: 'overview-tasks-window', className: 'overview-tasks-window',
// hpack: 'center',
// vpack: 'center',
hpack: 'start', hpack: 'start',
vpack: 'start', vpack: 'start',
css: ` css: `
@@ -147,15 +146,10 @@ export default () => {
menu.connect("selection-done", () => { menu.connect("selection-done", () => {
button.toggleClassName('overview-tasks-window-selected', false); button.toggleClassName('overview-tasks-window-selected', false);
}) })
// menu.popup_at_pointer(null); // Show the menu at the pointer's position
menu.popup_at_widget(button.get_parent(), Gravity.SOUTH, Gravity.NORTH, null); // Show menu below the button menu.popup_at_widget(button.get_parent(), Gravity.SOUTH, Gravity.NORTH, null); // Show menu below the button
button.connect("destroy", () => menu.destroy()); button.connect("destroy", () => menu.destroy());
}, },
child: Widget.Box({ child: Widget.Box({
// css: `
// min-width: ${Math.max(w * OVERVIEW_SCALE - 4, 1)}px;
// min-height: ${Math.max(h * OVERVIEW_SCALE - 4, 1)}px;
// `,
homogeneous: true, homogeneous: true,
child: Widget.Box({ child: Widget.Box({
vertical: true, vertical: true,
@@ -314,11 +308,9 @@ export default () => {
const offset = Math.floor((Hyprland.active.workspace.id - 1) / NUM_OF_WORKSPACES_SHOWN) * NUM_OF_WORKSPACES_SHOWN; const offset = Math.floor((Hyprland.active.workspace.id - 1) / NUM_OF_WORKSPACES_SHOWN) * NUM_OF_WORKSPACES_SHOWN;
let c = clientMap.get(clientAddress); let c = clientMap.get(clientAddress);
if (!c) return; if (!c) return;
if (c.attribute?.ws === offset + index) { c.destroy();
c.destroy(); c = null;
c = null; clientMap.delete(clientAddress);
clientMap.delete(clientAddress);
}
}; };
widget.show = () => { widget.show = () => {
fixed.show_all(); fixed.show_all();
@@ -353,17 +345,32 @@ export default () => {
const allClients = JSON.parse(clients); const allClients = JSON.parse(clients);
const kids = box.get_children(); const kids = box.get_children();
kids.forEach(kid => kid.clear()); kids.forEach(kid => kid.clear());
// console.log('----------------------------');
for (let i = 0; i < allClients.length; i++) { for (let i = 0; i < allClients.length; i++) {
const client = allClients[i]; const client = allClients[i];
const childID = client.workspace.id - (offset + startWorkspace);
if (offset + startWorkspace <= client.workspace.id && if (offset + startWorkspace <= client.workspace.id &&
client.workspace.id <= offset + startWorkspace + workspaces) { client.workspace.id <= offset + startWorkspace + workspaces) {
const screenCoords = box.attribute.monitorMap[client.monitor]; const screenCoords = box.attribute.monitorMap[client.monitor];
kids[client.workspace.id - (offset + startWorkspace)] if (kids[childID]) {
?.set(client, screenCoords); kids[childID].set(client, screenCoords);
}
continue;
} }
// const modID = client.workspace.id % NUM_OF_WORKSPACES_SHOWN;
// console.log(`[${startWorkspace} -> ${startWorkspace + workspaces - 1}] ? (${client.workspace.id} == ${modID})`);
// // console.log(`[${startWorkspace} -> ${startWorkspace + workspaces}] ? (${modID})`);
// if (startWorkspace <= modID && modID < startWorkspace + workspaces) {
// console.log('i care');
// const clientWidget = clientMap.get(client.address);
// console.log(childID, kids[childID], clientWidget);
// if (kids[childID] && clientWidget) {
// console.log('hmm remove', clientWidget.attribute)
// kids[childID].remove(clientWidget);
// }
// }
} }
kids.forEach(kid => kid.show()); kids.forEach(kid => kid.show());
}).catch(print); }).catch(print);
}, },
updateWorkspace: (box, id) => { updateWorkspace: (box, id) => {
@@ -405,7 +412,15 @@ export default () => {
if (!client) return; if (!client) return;
box.attribute.updateWorkspace(box, client.workspace.id); box.attribute.updateWorkspace(box, client.workspace.id);
}, 'client-added') }, 'client-added')
.hook(Hyprland.active.workspace, (box) => box.attribute.update(box)) .hook(Hyprland.active.workspace, (box) => {
const previousGroup = box.attribute.workspaceGroup;
const currentGroup = Math.floor((Hyprland.active.workspace.id - 1) / NUM_OF_WORKSPACES_SHOWN);
if (currentGroup !== previousGroup) {
box.attribute.update(box);
workspaceGroup = currentGroup;
}
// box.attribute.update(box);
})
.hook(App, (box, name, visible) => { // Update on open .hook(App, (box, name, visible) => { // Update on open
if (name == 'overview' && visible) box.attribute.update(box); if (name == 'overview' && visible) box.attribute.update(box);
}) })