2023-10-02 12:06:35 -04:00
|
|
|
import { App, Hyprland, Utils, Widget } from '../../imports.js';
|
|
|
|
const { Icon, Revealer } = Widget;
|
|
|
|
const { execAsync } = Utils;
|
2023-09-23 18:41:05 -04:00
|
|
|
|
|
|
|
import { WindowButton } from './dragndrop.js';
|
|
|
|
import * as VARS from './variables.js';
|
|
|
|
|
|
|
|
Array.prototype.remove = function (el) { this.splice(this.indexOf(el), 1) };
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-10-12 17:36:09 -04:00
|
|
|
const scale = size => size * VARS.SCALE - VARS.MARGIN;
|
|
|
|
const getFontSize = client => Math.min(scale(client.size[0]), scale(client.size[1])) * VARS.ICON_SCALE;
|
|
|
|
|
2023-10-12 18:10:39 -04:00
|
|
|
const IconStyle = client => `transition: font-size 0.2s linear;
|
|
|
|
min-width: ${scale(client.size[0])}px;
|
2023-10-12 17:36:09 -04:00
|
|
|
min-height: ${scale(client.size[1])}px;
|
|
|
|
font-size: ${getFontSize(client)}px;`;
|
2023-09-23 18:41:05 -04:00
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-10-13 10:25:56 -04:00
|
|
|
const Client = (client, active, clients) => {
|
|
|
|
let wsName = String(client.workspace.name).replace('special:', '');
|
|
|
|
let wsId = client.workspace.id;
|
|
|
|
let addr = `address:${client.address}`;
|
2023-10-12 17:36:09 -04:00
|
|
|
|
2023-10-14 13:54:45 -04:00
|
|
|
// FIXME: special workspaces not closing when in one and clicking on normal client
|
2023-10-13 10:25:56 -04:00
|
|
|
return Revealer({
|
|
|
|
transition: 'crossfade',
|
|
|
|
setup: rev => rev.revealChild = true,
|
|
|
|
properties: [
|
|
|
|
['address', client.address],
|
|
|
|
['toDestroy', false]
|
|
|
|
],
|
|
|
|
child: WindowButton({
|
|
|
|
address: client.address,
|
|
|
|
onSecondaryClickRelease: () => execAsync(`hyprctl dispatch closewindow ${addr}`).catch(print),
|
|
|
|
onPrimaryClickRelease: () => {
|
|
|
|
if (wsId < 0) {
|
|
|
|
if (client.workspace.name === 'special') {
|
|
|
|
execAsync(`hyprctl dispatch movetoworkspacesilent special:${wsId},${addr}`).then(
|
|
|
|
execAsync(`hyprctl dispatch togglespecialworkspace ${wsId}`).then(
|
2023-10-14 13:54:45 -04:00
|
|
|
() => App.closeWindow('overview')
|
2023-10-13 10:25:56 -04:00
|
|
|
).catch(print)
|
|
|
|
).catch(print);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
execAsync(`hyprctl dispatch togglespecialworkspace ${wsName}`).then(
|
2023-10-14 13:54:45 -04:00
|
|
|
() => App.closeWindow('overview')
|
2023-10-13 10:25:56 -04:00
|
|
|
).catch(print);
|
|
|
|
}
|
2023-09-23 21:34:49 -04:00
|
|
|
}
|
|
|
|
else {
|
2023-10-13 10:25:56 -04:00
|
|
|
// close special workspace if one is opened
|
|
|
|
let activeAddress = Hyprland.active.client.address;
|
|
|
|
let currentActive = clients.find(c => c.address === activeAddress)
|
|
|
|
|
|
|
|
if (currentActive && currentActive.workspace.id < 0) {
|
|
|
|
execAsync(`hyprctl dispatch togglespecialworkspace ${wsName}`).catch(print);
|
|
|
|
}
|
|
|
|
execAsync(`hyprctl dispatch focuswindow ${addr}`).then(
|
2023-10-14 13:54:45 -04:00
|
|
|
() => App.closeWindow('overview')
|
2023-10-12 17:36:09 -04:00
|
|
|
).catch(print);
|
2023-09-23 21:34:49 -04:00
|
|
|
}
|
2023-10-13 10:25:56 -04:00
|
|
|
},
|
|
|
|
child: Icon({
|
|
|
|
className: `window ${active}`,
|
|
|
|
style: IconStyle(client) + 'font-size: 10px;',
|
|
|
|
icon: client.class,
|
|
|
|
}),
|
2023-09-23 18:41:05 -04:00
|
|
|
}),
|
2023-10-13 10:25:56 -04:00
|
|
|
});
|
|
|
|
};
|
2023-09-23 18:41:05 -04:00
|
|
|
|
|
|
|
export function updateClients(box) {
|
2023-10-12 17:36:09 -04:00
|
|
|
execAsync('hyprctl clients -j').then(
|
|
|
|
result => {
|
2023-09-23 18:41:05 -04:00
|
|
|
let clients = JSON.parse(result).filter(client => client.class)
|
|
|
|
|
|
|
|
box._workspaces.forEach(workspace => {
|
2023-10-07 20:37:46 -04:00
|
|
|
let fixed = workspace.child.child.get_children()[2].children[0];
|
2023-09-23 18:41:05 -04:00
|
|
|
let toRemove = fixed.get_children();
|
|
|
|
|
|
|
|
clients.filter(client => client.workspace.id == workspace._id).forEach(client => {
|
|
|
|
let active = '';
|
|
|
|
if (client.address == Hyprland.active.client.address) {
|
|
|
|
active = 'active';
|
|
|
|
}
|
|
|
|
|
2023-10-12 17:36:09 -04:00
|
|
|
// TODO: fix multi monitor issue. this is just a temp fix
|
|
|
|
client.at[1] -= 2920;
|
|
|
|
|
2023-09-23 18:41:05 -04:00
|
|
|
// Special workspaces that haven't been opened yet
|
|
|
|
// return a size of 0. We need to set them to default
|
|
|
|
// values to show the workspace properly
|
|
|
|
if (client.size[0] === 0) {
|
|
|
|
client.size[0] = VARS.DEFAULT_SPECIAL.SIZE_X;
|
|
|
|
client.size[1] = VARS.DEFAULT_SPECIAL.SIZE_Y;
|
|
|
|
client.at[0] = VARS.DEFAULT_SPECIAL.POS_X;
|
|
|
|
client.at[1] = VARS.DEFAULT_SPECIAL.POS_Y;
|
|
|
|
}
|
|
|
|
|
2023-10-12 18:10:39 -04:00
|
|
|
let newClient = [
|
|
|
|
fixed.get_children().find(ch => ch._address == client.address),
|
|
|
|
client.at[0] * VARS.SCALE,
|
|
|
|
client.at[1] * VARS.SCALE,
|
|
|
|
];
|
|
|
|
|
|
|
|
if (newClient[0]) {
|
|
|
|
toRemove.remove(newClient[0]);
|
|
|
|
fixed.move(...newClient);
|
2023-09-23 18:41:05 -04:00
|
|
|
}
|
|
|
|
else {
|
2023-10-12 18:10:39 -04:00
|
|
|
newClient[0] = Client(client, active, clients);
|
|
|
|
fixed.put(...newClient);
|
2023-09-23 18:41:05 -04:00
|
|
|
}
|
2023-10-12 18:10:39 -04:00
|
|
|
|
|
|
|
// Set a timeout here to have an animation when the icon first appears
|
|
|
|
setTimeout(() => {
|
|
|
|
newClient[0].child.child.className = `window ${active}`;
|
|
|
|
newClient[0].child.child.style = IconStyle(client);
|
|
|
|
}, 1);
|
2023-09-23 18:41:05 -04:00
|
|
|
});
|
|
|
|
fixed.show_all();
|
|
|
|
toRemove.forEach(ch => {
|
|
|
|
if (ch._toDestroy) {
|
|
|
|
ch.destroy();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ch.revealChild = false;
|
|
|
|
ch._toDestroy = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}).catch(print);
|
|
|
|
};
|