refactor(ags overview): try to make code cleaner
This commit is contained in:
parent
1bd135057a
commit
2b0c55584f
3 changed files with 48 additions and 51 deletions
|
@ -17,57 +17,57 @@ const IconStyle = client => `transition: font-size 0.2s linear;
|
|||
font-size: ${getFontSize(client)}px;`;
|
||||
|
||||
|
||||
const Client = (client, active, clients) => Revealer({
|
||||
transition: 'crossfade',
|
||||
setup: rev => {
|
||||
rev.revealChild = true;
|
||||
},
|
||||
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}`;
|
||||
const Client = (client, active, clients) => {
|
||||
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') {
|
||||
execAsync(`hyprctl dispatch movetoworkspacesilent special:${wsId},${addr}`).then(
|
||||
execAsync(`hyprctl dispatch togglespecialworkspace ${wsId}`).then(
|
||||
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(
|
||||
() => closeWindow('overview')
|
||||
).catch(print)
|
||||
).catch(print);
|
||||
}
|
||||
else {
|
||||
execAsync(`hyprctl dispatch togglespecialworkspace ${wsName}`).then(
|
||||
() => closeWindow('overview')
|
||||
).catch(print)
|
||||
).catch(print);
|
||||
).catch(print);
|
||||
}
|
||||
}
|
||||
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')
|
||||
).catch(print);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 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')
|
||||
).catch(print);
|
||||
}
|
||||
},
|
||||
child: Icon({
|
||||
className: `window ${active}`,
|
||||
style: IconStyle(client) + 'font-size: 10px;',
|
||||
icon: client.class,
|
||||
},
|
||||
child: Icon({
|
||||
className: `window ${active}`,
|
||||
style: IconStyle(client) + 'font-size: 10px;',
|
||||
icon: client.class,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export function updateClients(box) {
|
||||
execAsync('hyprctl clients -j').then(
|
||||
|
|
|
@ -8,6 +8,7 @@ import Gdk from 'gi://Gdk';
|
|||
import Cairo from 'cairo';
|
||||
|
||||
import { Button } from '../misc/cursorbox.js';
|
||||
import { updateClients } from './clients.js';
|
||||
|
||||
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();
|
||||
|
||||
let mainBox = getWindow('overview').child.children[0].child;
|
||||
mainBox._updateClients(mainBox);
|
||||
updateClients(mainBox);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
|
@ -6,9 +6,9 @@ import { WorkspaceRow, getWorkspaces, updateWorkspaces } from './workspaces.js';
|
|||
import { updateClients } from './clients.js';
|
||||
|
||||
function update(box) {
|
||||
box._getWorkspaces(box);
|
||||
box._updateWorkspaces(box);
|
||||
box._updateClients(box);
|
||||
getWorkspaces(box);
|
||||
updateWorkspaces(box);
|
||||
updateClients(box);
|
||||
}
|
||||
|
||||
export default PopupWindow({
|
||||
|
@ -45,10 +45,6 @@ export default PopupWindow({
|
|||
],
|
||||
properties: [
|
||||
['workspaces'],
|
||||
|
||||
['getWorkspaces', getWorkspaces],
|
||||
['updateWorkspaces', updateWorkspaces],
|
||||
['updateClients', updateClients],
|
||||
],
|
||||
}),
|
||||
|
||||
|
|
Loading…
Reference in a new issue