animate overview wooooooooo

This commit is contained in:
end-4
2024-02-08 20:22:55 +07:00
parent 58b66959b7
commit 9f5a663d2d
+120 -58
View File
@@ -90,15 +90,32 @@ export default () => {
if (x + w > SCREEN_WIDTH) w = SCREEN_WIDTH - x; if (x + w > SCREEN_WIDTH) w = SCREEN_WIDTH - x;
if (y + h > SCREEN_HEIGHT) h = SCREEN_HEIGHT - y; if (y + h > SCREEN_HEIGHT) h = SCREEN_HEIGHT - y;
// title = truncateTitle(title); const appIcon = Widget.Icon({
icon: substitute(c),
size: Math.min(w, h) * OVERVIEW_SCALE / 2.5,
});
return Widget.Button({ return Widget.Button({
attribute: { address, x, y, ws: id }, attribute: {
address, x, y, w, h, ws: id,
updateIconSize: (self) => {
appIcon.size = Math.min(self.attribute.w, self.attribute.h) * OVERVIEW_SCALE / 2.5;
},
},
className: 'overview-tasks-window', className: 'overview-tasks-window',
hpack: 'center', // hpack: 'center',
vpack: 'center', // vpack: 'center',
onClicked: () => { hpack: 'start',
Hyprland.sendMessage(`dispatch focuswindow address:${address}`); vpack: 'start',
App.closeWindow('overview'); css: `
margin-left: ${Math.round(x * OVERVIEW_SCALE)}px;
margin-top: ${Math.round(y * OVERVIEW_SCALE)}px;
margin-right: -${Math.round((x + w) * OVERVIEW_SCALE)}px;
margin-bottom: -${Math.round((y + h) * OVERVIEW_SCALE)}px;
`,
onClicked: (self) => {
// Hyprland.sendMessage(`dispatch focuswindow address:${address}`);
// App.closeWindow('overview');
console.log(x, y, w, h, '\n\n', self.css);
}, },
onMiddleClickRelease: () => Hyprland.sendMessage(`dispatch closewindow address:${address}`), onMiddleClickRelease: () => Hyprland.sendMessage(`dispatch closewindow address:${address}`),
onSecondaryClick: (button) => { onSecondaryClick: (button) => {
@@ -136,35 +153,32 @@ export default () => {
button.connect("destroy", () => menu.destroy()); button.connect("destroy", () => menu.destroy());
}, },
child: Widget.Box({ child: Widget.Box({
css: ` // css: `
min-width: ${Math.max(w * OVERVIEW_SCALE - 4, 1)}px; // min-width: ${Math.max(w * OVERVIEW_SCALE - 4, 1)}px;
min-height: ${Math.max(h * 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,
vpack: 'center', vpack: 'center',
className: 'spacing-v-5', className: 'spacing-v-5',
children: [ children: [
Widget.Icon({ appIcon,
icon: substitute(c),
size: Math.min(w, h) * OVERVIEW_SCALE / 2.5,
}),
// TODO: Add xwayland tag instead of just having italics // TODO: Add xwayland tag instead of just having italics
Widget.Revealer({ // Widget.Revealer({
transition: 'slide_down', // transition: 'slide_down',
revealChild: revealInfoCondition, // revealChild: revealInfoCondition,
child: Widget.Label({ // child: Widget.Label({
truncate: 'end', // truncate: 'end',
className: `${xwayland ? 'txt txt-italic' : 'txt'}`, // className: `${xwayland ? 'txt txt-italic' : 'txt'}`,
css: ` // css: `
font-size: ${Math.min(SCREEN_WIDTH, SCREEN_HEIGHT) * OVERVIEW_SCALE / 14.6}px; // font-size: ${Math.min(SCREEN_WIDTH, SCREEN_HEIGHT) * OVERVIEW_SCALE / 14.6}px;
margin: 0px ${Math.min(SCREEN_WIDTH, SCREEN_HEIGHT) * OVERVIEW_SCALE / 10}px; // margin: 0px ${Math.min(SCREEN_WIDTH, SCREEN_HEIGHT) * OVERVIEW_SCALE / 10}px;
`, // `,
// If the title is too short, include the class // // If the title is too short, include the class
label: (title.length <= 1 ? `${c}: ${title}` : title), // label: (title.length <= 1 ? `${c}: ${title}` : title),
}) // })
}) // })
] ]
}) })
}), }),
@@ -188,22 +202,59 @@ export default () => {
} }
const Workspace = (index) => { const Workspace = (index) => {
const fixed = Gtk.Fixed.new(); // const fixed = Widget.Fixed({
// attribute: {
// put: (widget, x, y) => {
// fixed.put(widget, x, y);
// },
// move: (widget, x, y) => {
// fixed.move(widget, x, y);
// },
// }
// });
const fixed = Widget.Box({
attribute: {
put: (widget, x, y) => {
if (!widget.attribute) return;
// Note: x and y are already multiplied by OVERVIEW_SCALE
const newCss = `
margin-left: ${Math.round(x)}px;
margin-top: ${Math.round(y)}px;
margin-right: -${Math.round(x + (widget.attribute.w * OVERVIEW_SCALE))}px;
margin-bottom: -${Math.round(y + (widget.attribute.h * OVERVIEW_SCALE))}px;
`;
widget.css = newCss;
fixed.pack_start(widget, false, false, 0);
},
move: (widget, x, y) => {
if (!widget) return;
if (!widget.attribute) return;
// Note: x and y are already multiplied by OVERVIEW_SCALE
const newCss = `
margin-left: ${Math.round(x)}px;
margin-top: ${Math.round(y)}px;
margin-right: -${Math.round(x + (widget.attribute.w * OVERVIEW_SCALE))}px;
margin-bottom: -${Math.round(y + (widget.attribute.h * OVERVIEW_SCALE))}px;
`;
widget.css = newCss;
},
}
})
const WorkspaceNumber = (index) => Widget.Label({ const WorkspaceNumber = (index) => Widget.Label({
className: 'overview-tasks-workspace-number', className: 'overview-tasks-workspace-number',
label: `${index}`, label: `${index}`,
css: ` css: `
margin: ${Math.min(SCREEN_WIDTH, SCREEN_HEIGHT) * OVERVIEW_SCALE * OVERVIEW_WS_NUM_MARGIN_SCALE}px; margin: ${Math.min(SCREEN_WIDTH, SCREEN_HEIGHT) * OVERVIEW_SCALE * OVERVIEW_WS_NUM_MARGIN_SCALE}px;
font-size: ${SCREEN_HEIGHT * OVERVIEW_SCALE * OVERVIEW_WS_NUM_SCALE}px; font-size: ${SCREEN_HEIGHT * OVERVIEW_SCALE * OVERVIEW_WS_NUM_SCALE}px;
`, `,
}) })
const widget = Widget.Box({ const widget = Widget.Box({
className: 'overview-tasks-workspace', className: 'overview-tasks-workspace',
vpack: 'center', vpack: 'center',
css: ` css: `
min-width: ${SCREEN_WIDTH * OVERVIEW_SCALE}px; min-width: ${SCREEN_WIDTH * OVERVIEW_SCALE}px;
min-height: ${SCREEN_HEIGHT * OVERVIEW_SCALE}px; min-height: ${SCREEN_HEIGHT * OVERVIEW_SCALE}px;
`, `,
children: [Widget.EventBox({ children: [Widget.EventBox({
hexpand: true, hexpand: true,
vexpand: true, vexpand: true,
@@ -221,51 +272,58 @@ export default () => {
child: fixed, child: fixed,
})], })],
}); });
const offset = Math.floor((Hyprland.active.workspace.id - 1) / NUM_OF_WORKSPACES_SHOWN) * NUM_OF_WORKSPACES_SHOWN;
fixed.attribute.put(WorkspaceNumber(offset + index), 0, 0);
widget.clear = () => { widget.clear = () => {
const offset = Math.floor((Hyprland.active.workspace.id - 1) / NUM_OF_WORKSPACES_SHOWN) * NUM_OF_WORKSPACES_SHOWN;
clientMap.forEach((client, address) => { clientMap.forEach((client, address) => {
if (!client || client.ws !== index) return; if (!client || client.ws !== offset + index) return;
client.destroy(); client.destroy();
client = null; client = null;
clientMap.delete(address); clientMap.delete(address);
}); });
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, screenCoords) => { widget.set = (clientJson, screenCoords) => {
let c = clientMap.get(clientJson.address); let c = clientMap.get(clientJson.address);
if (c) { if (c) {
if (c.ws !== clientJson.workspace.id) { if (c.attribute?.ws !== clientJson.workspace.id) {
console.log('set: del')
c.destroy(); c.destroy();
c = null; c = null;
clientMap.delete(clientJson.address); clientMap.delete(clientJson.address);
} }
else { else if (c) {
fixed.move(c, console.log('set: move')
Math.max(0, (c.attribute.x + clientJson.x) / 2 * OVERVIEW_SCALE), c.attribute.w = clientJson.size[0];
Math.max(0, (c.attribute.y + clientJson.y) / 2 * OVERVIEW_SCALE) c.attribute.h = clientJson.size[1];
c.attribute.updateIconSize(c);
fixed.attribute.move(c,
Math.max(0, clientJson.at[0] * OVERVIEW_SCALE),
Math.max(0, clientJson.at[1] * OVERVIEW_SCALE)
); );
Utils.timeout(1000, () => fixed.move(c,
Math.max(0, clientJson.x * OVERVIEW_SCALE),
Math.max(0, clientJson.y * OVERVIEW_SCALE)
));
return; 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);
fixed.put(newWindow, fixed.attribute.put(newWindow,
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); clientMap.set(clientJson.address, newWindow);
}; };
// widget.unset = (clientAddress) => { widget.unset = (clientAddress) => {
// if(clientMap.get(clientAddress)) { const offset = Math.floor((Hyprland.active.workspace.id - 1) / NUM_OF_WORKSPACES_SHOWN) * NUM_OF_WORKSPACES_SHOWN;
// clientMap.get(clientAddress).destroy(); let c = clientMap.get(clientAddress);
// clientMap.delete(clientAddress); if (!c) return;
// } if (c.attribute?.ws === offset + index) {
// }; console.log('unset: del')
c.destroy();
c = null;
clientMap.delete(clientAddress);
}
};
widget.show = () => { widget.show = () => {
fixed.show_all(); fixed.show_all();
} }
@@ -318,7 +376,7 @@ export default () => {
offset + startWorkspace <= id && offset + startWorkspace <= id &&
id <= offset + startWorkspace + workspaces id <= offset + startWorkspace + workspaces
)) return; )) return;
if (!App.getWindow(windowName).visible) return; // if (!App.getWindow(windowName).visible) return;
Hyprland.sendMessage('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();
@@ -337,10 +395,14 @@ export default () => {
box box
.hook(overviewTick, (box) => box.attribute.update(box)) .hook(overviewTick, (box) => box.attribute.update(box))
.hook(Hyprland, (box, clientAddress) => { .hook(Hyprland, (box, clientAddress) => {
const offset = Math.floor((Hyprland.active.workspace.id - 1) / NUM_OF_WORKSPACES_SHOWN) * NUM_OF_WORKSPACES_SHOWN;
const kids = box.get_children();
const client = Hyprland.getClient(clientAddress); const client = Hyprland.getClient(clientAddress);
if (!client) return; if (!client) return;
box.attribute.updateWorkspace(box, client.workspace.id); const id = client.workspace.id;
// box.attribute.update(box)
box.attribute.updateWorkspace(box, id);
kids[id - (offset + startWorkspace)]?.unset(clientAddress);
}, 'client-removed') }, 'client-removed')
.hook(Hyprland, (box, clientAddress) => { .hook(Hyprland, (box, clientAddress) => {
const client = Hyprland.getClient(clientAddress); const client = Hyprland.getClient(clientAddress);