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,57 +17,57 @@ 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) => {
transition: 'crossfade', let wsName = String(client.workspace.name).replace('special:', '');
setup: rev => { let wsId = client.workspace.id;
rev.revealChild = true; let addr = `address:${client.address}`;
},
properties: [
['address', client.address],
['toDestroy', false]
],
child: WindowButton({
address: client.address,
onSecondaryClickRelease: () => execAsync(`hyprctl dispatch closewindow address:${client.address}`).catch(print),
onPrimaryClickRelease: () => {
let wsName = String(client.workspace.name).replace('special:', '');
let wsId = client.workspace.id;
let addr = `address:${client.address}`;
if (wsId < 0) { return Revealer({
if (client.workspace.name === 'special') { transition: 'crossfade',
execAsync(`hyprctl dispatch movetoworkspacesilent special:${wsId},${addr}`).then( setup: rev => rev.revealChild = true,
execAsync(`hyprctl dispatch togglespecialworkspace ${wsId}`).then( 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(
() => closeWindow('overview')
).catch(print)
).catch(print);
}
else {
execAsync(`hyprctl dispatch togglespecialworkspace ${wsName}`).then(
() => closeWindow('overview') () => closeWindow('overview')
).catch(print) ).catch(print);
).catch(print); }
} }
else { else {
execAsync(`hyprctl dispatch togglespecialworkspace ${wsName}`).then( // 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(
() => closeWindow('overview') () => closeWindow('overview')
).catch(print); ).catch(print);
} }
} },
else { child: Icon({
// close special workspace if one is opened className: `window ${active}`,
let activeAddress = Hyprland.active.client.address; style: IconStyle(client) + 'font-size: 10px;',
let currentActive = clients.find(c => c.address === activeAddress) icon: client.class,
}),
if (currentActive && currentActive.workspace.id < 0) {
execAsync(`hyprctl dispatch togglespecialworkspace ${wsName}`).catch(print);
}
execAsync(`hyprctl dispatch focuswindow ${addr}`).then(
() => closeWindow('overview')
).catch(print);
}
},
child: Icon({
className: `window ${active}`,
style: IconStyle(client) + 'font-size: 10px;',
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],
], ],
}), }),