perf(ags overview): fix huge lag issues by limiting hyprctl calls to when overview is open

This commit is contained in:
matt1432 2023-10-12 17:36:09 -04:00
parent 3e20de0578
commit f934a2cac2

View file

@ -8,10 +8,12 @@ import * as VARS from './variables.js';
Array.prototype.remove = function (el) { this.splice(this.indexOf(el), 1) }; Array.prototype.remove = function (el) { this.splice(this.indexOf(el), 1) };
const IconStyle = app => `min-width: ${app.size[0] * VARS.SCALE - VARS.MARGIN}px; const scale = size => size * VARS.SCALE - VARS.MARGIN;
min-height: ${app.size[1] * VARS.SCALE - VARS.MARGIN}px; const getFontSize = client => Math.min(scale(client.size[0]), scale(client.size[1])) * VARS.ICON_SCALE;
font-size: ${Math.min(app.size[0] * VARS.SCALE - VARS.MARGIN,
app.size[1] * VARS.SCALE - VARS.MARGIN) * VARS.ICON_SCALE}px;`; const IconStyle = client => `min-width: ${scale(client.size[0])}px;
min-height: ${scale(client.size[1])}px;
font-size: ${getFontSize(client)}px;`;
const Client = (client, active, clients) => Revealer({ const Client = (client, active, clients) => Revealer({
@ -25,24 +27,24 @@ const Client = (client, active, clients) => Revealer({
], ],
child: WindowButton({ child: WindowButton({
address: client.address, address: client.address,
onSecondaryClickRelease: () => { onSecondaryClickRelease: () => execAsync(`hyprctl dispatch closewindow address:${client.address}`).catch(print),
execAsync(`hyprctl dispatch closewindow address:${client.address}`)
.catch(print)
},
onPrimaryClickRelease: () => { onPrimaryClickRelease: () => {
if (client.workspace.id < 0) { let wsName = String(client.workspace.name).replace('special:', '');
let wsId = client.workspace.id;
let addr = `address:${client.address}`;
if (wsId < 0) {
if (client.workspace.name === 'special') { if (client.workspace.name === 'special') {
execAsync(`hyprctl dispatch movetoworkspacesilent special:${client.workspace.id},address:${client.address}`) execAsync(`hyprctl dispatch movetoworkspacesilent special:${wsId},${addr}`).then(
.then(execAsync(`hyprctl dispatch togglespecialworkspace ${client.workspace.id}`) execAsync(`hyprctl dispatch togglespecialworkspace ${wsId}`).then(
.then(() => closeWindow('overview')) () => closeWindow('overview')
.catch(print)) ).catch(print)
.catch(print); ).catch(print);
} }
else { else {
execAsync(`hyprctl dispatch togglespecialworkspace ${String(client.workspace.name) execAsync(`hyprctl dispatch togglespecialworkspace ${wsName}`).then(
.replace('special:', '')}`) () => closeWindow('overview')
.then(() => closeWindow('overview')) ).catch(print);
.catch(print);
} }
} }
else { else {
@ -50,12 +52,12 @@ const Client = (client, active, clients) => Revealer({
let activeAddress = Hyprland.active.client.address; let activeAddress = Hyprland.active.client.address;
let currentActive = clients.find(c => c.address === activeAddress) let currentActive = clients.find(c => c.address === activeAddress)
if (currentActive && currentActive.workspace.id < 0) if (currentActive && currentActive.workspace.id < 0) {
execAsync(`hyprctl dispatch togglespecialworkspace ${String(currentActive.workspace.name) execAsync(`hyprctl dispatch togglespecialworkspace ${wsName}`).catch(print);
.replace('special:', '')}`).catch(print); }
execAsync(`hyprctl dispatch focuswindow address:${client.address}`) execAsync(`hyprctl dispatch focuswindow ${addr}`).then(
.then(() => closeWindow('overview')) () => closeWindow('overview')
.catch(print); ).catch(print);
} }
}, },
child: Icon({ child: Icon({
@ -67,8 +69,11 @@ const Client = (client, active, clients) => Revealer({
}); });
export function updateClients(box) { export function updateClients(box) {
execAsync('hyprctl clients -j') if (!App.getWindow('overview').visible)
.then(result => { return;
execAsync('hyprctl clients -j').then(
result => {
let clients = JSON.parse(result).filter(client => client.class) let clients = JSON.parse(result).filter(client => client.class)
box._workspaces.forEach(workspace => { box._workspaces.forEach(workspace => {
@ -81,6 +86,9 @@ export function updateClients(box) {
active = 'active'; active = 'active';
} }
// TODO: fix multi monitor issue. this is just a temp fix
client.at[1] -= 2920;
// Special workspaces that haven't been opened yet // Special workspaces that haven't been opened yet
// return a size of 0. We need to set them to default // return a size of 0. We need to set them to default
// values to show the workspace properly // values to show the workspace properly