2023-11-21 01:29:46 -05:00
|
|
|
import App from 'resource:///com/github/Aylur/ags/app.js';
|
2023-10-31 08:32:40 -04:00
|
|
|
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-31 08:32:40 -04:00
|
|
|
import { Icon, Revealer } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-11-13 13:19:14 -05:00
|
|
|
import { timeout } from 'resource:///com/github/Aylur/ags/utils.js';
|
2023-09-23 18:41:05 -04:00
|
|
|
|
|
|
|
import { WindowButton } from './dragndrop.js';
|
|
|
|
import * as VARS from './variables.js';
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
const scale = (size) => (size * VARS.SCALE) - VARS.MARGIN;
|
|
|
|
const getFontSize = (client) => {
|
2023-10-30 20:27:18 -04:00
|
|
|
const valX = scale(client.size[0]) * VARS.ICON_SCALE;
|
|
|
|
const valY = scale(client.size[1]) * VARS.ICON_SCALE;
|
2023-10-12 17:36:09 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
const size = Math.min(valX, valY);
|
|
|
|
|
2023-10-30 20:27:18 -04:00
|
|
|
return size <= 0 ? 0.1 : size;
|
|
|
|
};
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
const IconStyle = (client) => `
|
2023-10-30 20:27:18 -04:00
|
|
|
min-width: ${scale(client.size[0])}px;
|
|
|
|
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-11-07 13:00:29 -05:00
|
|
|
const Client = (client, active, clients, box) => {
|
2023-10-20 23:11:21 -04:00
|
|
|
const wsName = String(client.workspace.name).replace('special:', '');
|
|
|
|
const wsId = client.workspace.id;
|
|
|
|
const addr = `address:${client.address}`;
|
|
|
|
|
|
|
|
return Revealer({
|
|
|
|
transition: 'crossfade',
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
setup: (rev) => {
|
|
|
|
rev.revealChild = true;
|
|
|
|
},
|
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
properties: [
|
|
|
|
['address', client.address],
|
|
|
|
['toDestroy', false],
|
|
|
|
],
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
child: WindowButton({
|
2023-11-07 13:00:29 -05:00
|
|
|
mainBox: box,
|
2023-10-20 23:11:21 -04:00
|
|
|
address: client.address,
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
onSecondaryClickRelease: () => {
|
|
|
|
Hyprland.sendMessage(`dispatch closewindow ${addr}`);
|
|
|
|
},
|
2023-10-20 23:11:21 -04:00
|
|
|
|
|
|
|
onPrimaryClickRelease: () => {
|
|
|
|
if (wsId < 0) {
|
|
|
|
if (client.workspace.name === 'special') {
|
2023-11-21 01:29:46 -05:00
|
|
|
Hyprland.sendMessage('dispatch ' +
|
|
|
|
`movetoworkspacesilent special:${wsId},${addr}`)
|
2023-10-20 23:11:21 -04:00
|
|
|
.then(
|
2023-11-21 01:29:46 -05:00
|
|
|
Hyprland.sendMessage('dispatch ' +
|
|
|
|
`togglespecialworkspace ${wsId}`)
|
2023-11-13 13:19:14 -05:00
|
|
|
.then(
|
|
|
|
() => App.closeWindow('overview'),
|
|
|
|
).catch(print),
|
2023-10-20 23:11:21 -04:00
|
|
|
).catch(print);
|
|
|
|
}
|
|
|
|
else {
|
2023-11-21 01:29:46 -05:00
|
|
|
Hyprland.sendMessage('dispatch ' +
|
|
|
|
`togglespecialworkspace ${wsName}`).then(
|
2023-10-20 23:11:21 -04:00
|
|
|
() => App.closeWindow('overview'),
|
|
|
|
).catch(print);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2023-11-21 01:29:46 -05:00
|
|
|
// Close special workspace if one is opened
|
2023-10-20 23:11:21 -04:00
|
|
|
const activeAddress = Hyprland.active.client.address;
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
const currentActive = clients.find((c) => {
|
|
|
|
return c.address === activeAddress;
|
|
|
|
});
|
2023-10-20 23:11:21 -04:00
|
|
|
|
|
|
|
if (currentActive && currentActive.workspace.id < 0) {
|
2023-11-21 01:29:46 -05:00
|
|
|
const currentSpecial = `${currentActive.workspace.name}`
|
|
|
|
.replace('special:', '');
|
|
|
|
|
|
|
|
Hyprland.sendMessage('dispatch ' +
|
|
|
|
`togglespecialworkspace ${currentSpecial}`)
|
2023-10-20 23:11:21 -04:00
|
|
|
.catch(print);
|
|
|
|
}
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-13 13:19:14 -05:00
|
|
|
Hyprland.sendMessage(`dispatch focuswindow ${addr}`).then(
|
2023-10-20 23:11:21 -04:00
|
|
|
() => App.closeWindow('overview'),
|
|
|
|
).catch(print);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
child: Icon({
|
|
|
|
className: `window ${active}`,
|
2023-11-21 01:29:46 -05:00
|
|
|
css: `${IconStyle(client) }font-size: 10px;`,
|
2023-10-20 23:11:21 -04:00
|
|
|
icon: client.class,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
});
|
2023-10-13 10:25:56 -04:00
|
|
|
};
|
2023-09-23 18:41:05 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
export const updateClients = (box) => {
|
|
|
|
Hyprland.sendMessage('j/clients').then((out) => {
|
|
|
|
const clients = JSON.parse(out).filter((client) => client.class);
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
box._workspaces.forEach((workspace) => {
|
2023-10-20 23:11:21 -04:00
|
|
|
const fixed = workspace.getFixed();
|
|
|
|
const toRemove = fixed.get_children();
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
clients.filter((client) => client.workspace.id === workspace._id)
|
|
|
|
.forEach((client) => {
|
2023-10-20 23:11:21 -04:00
|
|
|
let active = '';
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
if (client.address === Hyprland.active.client.address) {
|
2023-10-20 23:11:21 -04:00
|
|
|
active = 'active';
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
|
|
|
|
// TODO: fix multi monitor issue. this is just a temp fix
|
|
|
|
client.at[1] -= 2920;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
const newClient = [
|
2023-11-21 01:29:46 -05:00
|
|
|
fixed.get_children()
|
|
|
|
.find((ch) => ch._address === client.address),
|
2023-10-20 23:11:21 -04:00
|
|
|
client.at[0] * VARS.SCALE,
|
|
|
|
client.at[1] * VARS.SCALE,
|
|
|
|
];
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
// If it exists already
|
|
|
|
if (newClient[0]) {
|
2023-11-07 10:56:12 -05:00
|
|
|
toRemove.splice(toRemove.indexOf(newClient[0]), 1);
|
|
|
|
fixed.move(...newClient);
|
|
|
|
}
|
2023-11-21 01:29:46 -05:00
|
|
|
else {
|
|
|
|
newClient[0] = Client(client, active, clients, box);
|
|
|
|
fixed.put(...newClient);
|
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
|
|
|
|
// Set a timeout here to have an animation when the icon first appears
|
2023-10-31 09:31:12 -04:00
|
|
|
timeout(1, () => {
|
2023-10-20 23:11:21 -04:00
|
|
|
newClient[0].child.child.className = `window ${active}`;
|
2023-11-07 10:56:12 -05:00
|
|
|
newClient[0].child.child.setCss(IconStyle(client));
|
2023-10-20 23:11:21 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
fixed.show_all();
|
2023-11-21 01:29:46 -05:00
|
|
|
toRemove.forEach((ch) => {
|
2023-10-20 23:11:21 -04:00
|
|
|
if (ch._toDestroy) {
|
|
|
|
ch.destroy();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ch.revealChild = false;
|
|
|
|
ch._toDestroy = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}).catch(print);
|
2023-11-21 01:29:46 -05:00
|
|
|
};
|