forked from Shinonome/dots-hyprland
overview: fewer destroy/create
This commit is contained in:
@@ -49,8 +49,9 @@ function substitute(str) {
|
|||||||
if (!iconExists(str)) str = str.toLowerCase().replace(/\s+/g, '-'); // Turn into kebab-case
|
if (!iconExists(str)) str = str.toLowerCase().replace(/\s+/g, '-'); // Turn into kebab-case
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
export default () => {
|
||||||
const ContextMenuWorkspaceArray = ({ label, actionFunc, thisWorkspace }) => Widget.MenuItem({
|
const clientMap = new Map();
|
||||||
|
const ContextMenuWorkspaceArray = ({ label, actionFunc, thisWorkspace }) => Widget.MenuItem({
|
||||||
label: `${label}`,
|
label: `${label}`,
|
||||||
setup: (menuItem) => {
|
setup: (menuItem) => {
|
||||||
let submenu = new Gtk.Menu();
|
let submenu = new Gtk.Menu();
|
||||||
@@ -72,9 +73,9 @@ const ContextMenuWorkspaceArray = ({ label, actionFunc, thisWorkspace }) => Widg
|
|||||||
menuItem.set_reserve_indicator(true);
|
menuItem.set_reserve_indicator(true);
|
||||||
menuItem.set_submenu(submenu);
|
menuItem.set_submenu(submenu);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const Window = ({ address, at: [x, y], size: [w, h], workspace: { id, name }, class: c, title, xwayland }, screenCoords) => {
|
const Window = ({ address, at: [x, y], size: [w, h], workspace: { id, name }, class: c, title, xwayland }, screenCoords) => {
|
||||||
const revealInfoCondition = (Math.min(w, h) * OVERVIEW_SCALE > 70);
|
const revealInfoCondition = (Math.min(w, h) * OVERVIEW_SCALE > 70);
|
||||||
if (w <= 0 || h <= 0 || (c === '' && title === '')) return null;
|
if (w <= 0 || h <= 0 || (c === '' && title === '')) return null;
|
||||||
// Non-primary monitors
|
// Non-primary monitors
|
||||||
@@ -91,7 +92,7 @@ const Window = ({ address, at: [x, y], size: [w, h], workspace: { id, name }, cl
|
|||||||
|
|
||||||
// title = truncateTitle(title);
|
// title = truncateTitle(title);
|
||||||
return Widget.Button({
|
return Widget.Button({
|
||||||
attribute: { x, y },
|
attribute: { address, x, y, ws: id },
|
||||||
className: 'overview-tasks-window',
|
className: 'overview-tasks-window',
|
||||||
hpack: 'center',
|
hpack: 'center',
|
||||||
vpack: 'center',
|
vpack: 'center',
|
||||||
@@ -184,11 +185,10 @@ const Window = ({ address, at: [x, y], size: [w, h], workspace: { id, name }, cl
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const Workspace = (index) => {
|
const Workspace = (index) => {
|
||||||
const fixed = Gtk.Fixed.new();
|
const fixed = Gtk.Fixed.new();
|
||||||
// const clientMap = new Map();
|
|
||||||
const WorkspaceNumber = (index) => Widget.Label({
|
const WorkspaceNumber = (index) => Widget.Label({
|
||||||
className: 'overview-tasks-workspace-number',
|
className: 'overview-tasks-workspace-number',
|
||||||
label: `${index}`,
|
label: `${index}`,
|
||||||
@@ -222,12 +222,35 @@ const Workspace = (index) => {
|
|||||||
})],
|
})],
|
||||||
});
|
});
|
||||||
widget.clear = () => {
|
widget.clear = () => {
|
||||||
fixed.get_children().forEach(ch => ch.destroy());
|
clientMap.forEach((client, address) => {
|
||||||
|
if (!client || client.ws !== index) return;
|
||||||
|
client.destroy();
|
||||||
|
client = null;
|
||||||
|
clientMap.delete(address);
|
||||||
|
});
|
||||||
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;
|
||||||
fixed.put(WorkspaceNumber(offset + index), 0, 0);
|
fixed.put(WorkspaceNumber(offset + index), 0, 0);
|
||||||
}
|
}
|
||||||
widget.set = (clientJson, screenCoords) => {
|
widget.set = (clientJson, screenCoords) => {
|
||||||
// if(clientMap.get(clientJson.address)) clientMap.get(clientJson.address).destroy();
|
let c = clientMap.get(clientJson.address);
|
||||||
|
if (c) {
|
||||||
|
if (c.ws !== clientJson.workspace.id) {
|
||||||
|
c.destroy();
|
||||||
|
c = null;
|
||||||
|
clientMap.delete(clientJson.address);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fixed.move(c,
|
||||||
|
Math.max(0, (c.attribute.x + clientJson.x) / 2 * OVERVIEW_SCALE),
|
||||||
|
Math.max(0, (c.attribute.y + clientJson.y) / 2 * OVERVIEW_SCALE)
|
||||||
|
);
|
||||||
|
Utils.timeout(1000, () => fixed.move(c,
|
||||||
|
Math.max(0, clientJson.x * OVERVIEW_SCALE),
|
||||||
|
Math.max(0, clientJson.y * OVERVIEW_SCALE)
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
const newWindow = Window(clientJson, screenCoords);
|
const newWindow = Window(clientJson, screenCoords);
|
||||||
if (newWindow === null) return;
|
if (newWindow === null) return;
|
||||||
// clientMap.set(clientJson.address, newWindow);
|
// clientMap.set(clientJson.address, newWindow);
|
||||||
@@ -235,6 +258,7 @@ const Workspace = (index) => {
|
|||||||
Math.max(0, newWindow.attribute.x * OVERVIEW_SCALE),
|
Math.max(0, newWindow.attribute.x * OVERVIEW_SCALE),
|
||||||
Math.max(0, newWindow.attribute.y * OVERVIEW_SCALE)
|
Math.max(0, newWindow.attribute.y * OVERVIEW_SCALE)
|
||||||
);
|
);
|
||||||
|
clientMap.set(clientJson.address, newWindow);
|
||||||
};
|
};
|
||||||
// widget.unset = (clientAddress) => {
|
// widget.unset = (clientAddress) => {
|
||||||
// if(clientMap.get(clientAddress)) {
|
// if(clientMap.get(clientAddress)) {
|
||||||
@@ -246,17 +270,17 @@ const Workspace = (index) => {
|
|||||||
fixed.show_all();
|
fixed.show_all();
|
||||||
}
|
}
|
||||||
return widget;
|
return widget;
|
||||||
};
|
};
|
||||||
|
|
||||||
const arr = (s, n) => {
|
const arr = (s, n) => {
|
||||||
const array = [];
|
const array = [];
|
||||||
for (let i = 0; i < n; i++)
|
for (let i = 0; i < n; i++)
|
||||||
array.push(s + i);
|
array.push(s + i);
|
||||||
|
|
||||||
return array;
|
return array;
|
||||||
};
|
};
|
||||||
|
|
||||||
const OverviewRow = ({ startWorkspace, workspaces, windowName = 'overview' }) => Widget.Box({
|
const OverviewRow = ({ startWorkspace, workspaces, windowName = 'overview' }) => Widget.Box({
|
||||||
children: arr(startWorkspace, workspaces).map(Workspace),
|
children: arr(startWorkspace, workspaces).map(Workspace),
|
||||||
attribute: {
|
attribute: {
|
||||||
monitorMap: [],
|
monitorMap: [],
|
||||||
@@ -271,7 +295,7 @@ const OverviewRow = ({ startWorkspace, workspaces, windowName = 'overview' }) =>
|
|||||||
update: (box) => {
|
update: (box) => {
|
||||||
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;
|
||||||
if (!App.getWindow(windowName).visible) return;
|
if (!App.getWindow(windowName).visible) return;
|
||||||
execAsync('hyprctl -j clients').then(clients => {
|
Hyprland.sendMessage('j/clients').then(clients => {
|
||||||
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());
|
||||||
@@ -287,7 +311,26 @@ const OverviewRow = ({ startWorkspace, workspaces, windowName = 'overview' }) =>
|
|||||||
kids.forEach(kid => kid.show());
|
kids.forEach(kid => kid.show());
|
||||||
|
|
||||||
}).catch(print);
|
}).catch(print);
|
||||||
|
},
|
||||||
|
updateWorkspace: (box, id) => {
|
||||||
|
const offset = Math.floor((Hyprland.active.workspace.id - 1) / NUM_OF_WORKSPACES_SHOWN) * NUM_OF_WORKSPACES_SHOWN;
|
||||||
|
if (!( // Not in range, ignore
|
||||||
|
offset + startWorkspace <= id &&
|
||||||
|
id <= offset + startWorkspace + workspaces
|
||||||
|
)) return;
|
||||||
|
if (!App.getWindow(windowName).visible) return;
|
||||||
|
Hyprland.sendMessage('j/clients').then(clients => {
|
||||||
|
const allClients = JSON.parse(clients);
|
||||||
|
const kids = box.get_children();
|
||||||
|
for (let i = 0; i < allClients.length; i++) {
|
||||||
|
const client = allClients[i];
|
||||||
|
if (client.workspace.id != id) continue;
|
||||||
|
const screenCoords = box.attribute.monitorMap[client.monitor];
|
||||||
|
kids[id - (offset + startWorkspace)]?.set(client, screenCoords);
|
||||||
}
|
}
|
||||||
|
kids[id - (offset + startWorkspace)]?.show();
|
||||||
|
}).catch(print);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
setup: (box) => {
|
setup: (box) => {
|
||||||
box.attribute.getMonitorMap(box);
|
box.attribute.getMonitorMap(box);
|
||||||
@@ -295,21 +338,23 @@ const OverviewRow = ({ startWorkspace, workspaces, windowName = 'overview' }) =>
|
|||||||
.hook(overviewTick, (box) => box.attribute.update(box))
|
.hook(overviewTick, (box) => box.attribute.update(box))
|
||||||
.hook(Hyprland, (box, clientAddress) => {
|
.hook(Hyprland, (box, clientAddress) => {
|
||||||
const client = Hyprland.getClient(clientAddress);
|
const client = Hyprland.getClient(clientAddress);
|
||||||
box.attribute.updateWorkspace(client.workspace.id);
|
if (!client) return;
|
||||||
|
box.attribute.updateWorkspace(box, client.workspace.id);
|
||||||
// box.attribute.update(box)
|
// box.attribute.update(box)
|
||||||
}, 'client-removed')
|
}, 'client-removed')
|
||||||
.hook(Hyprland, (box, clientAddress) => {
|
.hook(Hyprland, (box, clientAddress) => {
|
||||||
box.attribute.update(box);
|
const client = Hyprland.getClient(clientAddress);
|
||||||
|
if (!client) return;
|
||||||
|
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) => 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);
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return Widget.Revealer({
|
||||||
export default () => Widget.Revealer({
|
|
||||||
revealChild: true,
|
revealChild: true,
|
||||||
transition: 'slide_down',
|
transition: 'slide_down',
|
||||||
transitionDuration: 200,
|
transitionDuration: 200,
|
||||||
@@ -323,4 +368,5 @@ export default () => Widget.Revealer({
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user