refactor(ags overview): try to make code cleaner

This commit is contained in:
matt1432 2023-10-13 10:25:56 -04:00
parent 1bd135057a
commit 2b0c55584f
3 changed files with 48 additions and 51 deletions

View file

@ -17,23 +17,22 @@ const IconStyle = client => `transition: font-size 0.2s linear;
font-size: ${getFontSize(client)}px;`; font-size: ${getFontSize(client)}px;`;
const Client = (client, active, clients) => Revealer({ const Client = (client, active, clients) => {
let wsName = String(client.workspace.name).replace('special:', '');
let wsId = client.workspace.id;
let addr = `address:${client.address}`;
return Revealer({
transition: 'crossfade', transition: 'crossfade',
setup: rev => { setup: rev => rev.revealChild = true,
rev.revealChild = true;
},
properties: [ properties: [
['address', client.address], ['address', client.address],
['toDestroy', false] ['toDestroy', false]
], ],
child: WindowButton({ child: WindowButton({
address: client.address, address: client.address,
onSecondaryClickRelease: () => execAsync(`hyprctl dispatch closewindow address:${client.address}`).catch(print), onSecondaryClickRelease: () => execAsync(`hyprctl dispatch closewindow ${addr}`).catch(print),
onPrimaryClickRelease: () => { onPrimaryClickRelease: () => {
let wsName = String(client.workspace.name).replace('special:', '');
let wsId = client.workspace.id;
let addr = `address:${client.address}`;
if (wsId < 0) { if (wsId < 0) {
if (client.workspace.name === 'special') { if (client.workspace.name === 'special') {
execAsync(`hyprctl dispatch movetoworkspacesilent special:${wsId},${addr}`).then( execAsync(`hyprctl dispatch movetoworkspacesilent special:${wsId},${addr}`).then(
@ -67,7 +66,8 @@ const Client = (client, active, clients) => Revealer({
icon: client.class, icon: client.class,
}), }),
}), }),
}); });
};
export function updateClients(box) { export function updateClients(box) {
execAsync('hyprctl clients -j').then( execAsync('hyprctl clients -j').then(

View file

@ -8,6 +8,7 @@ import Gdk from 'gi://Gdk';
import Cairo from 'cairo'; import Cairo from 'cairo';
import { Button } from '../misc/cursorbox.js'; import { Button } from '../misc/cursorbox.js';
import { updateClients } from './clients.js';
const TARGET = [Gtk.TargetEntry.new('text/plain', Gtk.TargetFlags.SAME_APP, 0)]; const TARGET = [Gtk.TargetEntry.new('text/plain', Gtk.TargetFlags.SAME_APP, 0)];
@ -66,7 +67,7 @@ export const WindowButton = ({address, ...params} = {}) => Button({
button.get_parent().destroy(); button.get_parent().destroy();
let mainBox = getWindow('overview').child.children[0].child; let mainBox = getWindow('overview').child.children[0].child;
mainBox._updateClients(mainBox); updateClients(mainBox);
}); });
}, },
}); });

View file

@ -6,9 +6,9 @@ import { WorkspaceRow, getWorkspaces, updateWorkspaces } from './workspaces.js';
import { updateClients } from './clients.js'; import { updateClients } from './clients.js';
function update(box) { function update(box) {
box._getWorkspaces(box); getWorkspaces(box);
box._updateWorkspaces(box); updateWorkspaces(box);
box._updateClients(box); updateClients(box);
} }
export default PopupWindow({ export default PopupWindow({
@ -45,10 +45,6 @@ export default PopupWindow({
], ],
properties: [ properties: [
['workspaces'], ['workspaces'],
['getWorkspaces', getWorkspaces],
['updateWorkspaces', updateWorkspaces],
['updateClients', updateClients],
], ],
}), }),