Fix Overview in multi-monitor setup for floating windows at corners (#232)

This commit is contained in:
end-4
2024-02-05 23:34:57 +07:00
committed by GitHub
@@ -74,18 +74,20 @@ const ContextMenuWorkspaceArray = ({ label, actionFunc, thisWorkspace }) => Widg
}
})
const Window = ({ address, at: [x, y], size: [w, h], workspace: { id, name }, class: c, title, xwayland }) => {
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);
if (w <= 0 || h <= 0 || (c === '' && title === '')) return null;
if (x + w <= 0) x += (Math.floor(x / SCREEN_WIDTH) * SCREEN_WIDTH);
else if (x < 0) { x = 0; w = x + w; }
if (y + h <= 0) x += (Math.floor(y / SCREEN_HEIGHT) * SCREEN_HEIGHT);
else if (y < 0) { y = 0; h = y + h; }
if (x >= SCREEN_WIDTH) x %= SCREEN_WIDTH;
else if (x + w > SCREEN_WIDTH) w = SCREEN_WIDTH - x;
if (y >= SCREEN_HEIGHT) y %= SCREEN_HEIGHT;
else if (y + h > SCREEN_HEIGHT) h = SCREEN_HEIGHT - y;
if (screenCoords.x != 0) x -= screenCoords.x;
if (screenCoords.y != 0) y -= screenCoords.y;
if (x + w <= 0) x += (Math.floor(x / SCREEN_WIDTH) * SCREEN_WIDTH);
else if (x < 0) { w = x + w; x = 0;}
if (y + h <= 0) x += (Math.floor(y / SCREEN_HEIGHT) * SCREEN_HEIGHT);
else if (y < 0) { h = y + h; y = 0;}
if (x + w > SCREEN_WIDTH) w = SCREEN_WIDTH - x;
if (y + h > SCREEN_HEIGHT) h = SCREEN_HEIGHT - y;
// title = truncateTitle(title);
return Widget.Button({
@@ -224,9 +226,9 @@ const Workspace = (index) => {
const offset = Math.floor((Hyprland.active.workspace.id - 1) / NUM_OF_WORKSPACES_SHOWN) * NUM_OF_WORKSPACES_SHOWN;
fixed.put(WorkspaceNumber(offset + index), 0, 0);
}
widget.set = (clientJson) => {
widget.set = (clientJson, screenCoords) => {
// if(clientMap.get(clientJson.address)) clientMap.get(clientJson.address).destroy();
const newWindow = Window(clientJson);
const newWindow = Window(clientJson, screenCoords);
if (newWindow === null) return;
// clientMap.set(clientJson.address, newWindow);
fixed.put(newWindow,
@@ -257,6 +259,14 @@ const arr = (s, n) => {
const OverviewRow = ({ startWorkspace, workspaces, windowName = 'overview' }) => Widget.Box({
children: arr(startWorkspace, workspaces).map(Workspace),
attribute: {
monitorMap: [],
getMonitorMap: (box) => {execAsync('hyprctl -j monitors').then(monitors => {
box.attribute.monitorMap = JSON.parse(monitors).reduce((acc, item) => {
acc[item.id] = { x: item.x, y: item.y };
return acc;
}, {});
});
},
update: (box) => {
const offset = Math.floor((Hyprland.active.workspace.id - 1) / NUM_OF_WORKSPACES_SHOWN) * NUM_OF_WORKSPACES_SHOWN;
if (!App.getWindow(windowName).visible) return;
@@ -268,8 +278,10 @@ const OverviewRow = ({ startWorkspace, workspaces, windowName = 'overview' }) =>
const client = allClients[i];
if (offset + startWorkspace <= client.workspace.id &&
client.workspace.id <= offset + startWorkspace + workspaces) {
const screenCoords = box.attribute.monitorMap[client.monitor];
kids[client.workspace.id - (offset + startWorkspace)]
?.set(client);
?.set(client, screenCoords);
}
}
kids.forEach(kid => kid.show());
@@ -277,7 +289,9 @@ const OverviewRow = ({ startWorkspace, workspaces, windowName = 'overview' }) =>
}).catch(print);
}
},
setup: (box) => box
setup: (box) => {
box.attribute.getMonitorMap(box)
box
.hook(overviewTick, (box) => box.attribute.update(box))
.hook(Hyprland, (box, clientAddress) => {
box.attribute.update(box)
@@ -289,7 +303,7 @@ const OverviewRow = ({ startWorkspace, workspaces, windowName = 'overview' }) =>
.hook(App, (box, name, visible) => { // Update on open
if (name == 'overview' && visible) box.attribute.update(box);
})
,
},
});