diff --git a/devices/wim/config/ags/bin/launch-app.sh b/devices/wim/config/ags/bin/launch-app.sh deleted file mode 100755 index ef79c6dd..00000000 --- a/devices/wim/config/ags/bin/launch-app.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash - -APP="$1" -EXEC="$2" - -if [[ "$APP" == "thunderbird" ]]; then - hyprctl dispatch togglespecialworkspace thunder -elif [[ "$APP" == "Spotify" ]]; then - hyprctl dispatch togglespecialworkspace spot -elif [[ $(hyprctl clients | grep "$APP") != "" ]]; then - hyprctl dispatch focuswindow "^($APP)$" -else - hyprctl dispatch workspace empty - hyprctl dispatch exec "$EXEC" -fi diff --git a/devices/wim/config/ags/js/applauncher/main.js b/devices/wim/config/ags/js/applauncher/main.js index 2e78cc1b..f9634ec6 100644 --- a/devices/wim/config/ags/js/applauncher/main.js +++ b/devices/wim/config/ags/js/applauncher/main.js @@ -1,8 +1,8 @@ import App from 'resource:///com/github/Aylur/ags/app.js'; import Applications from 'resource:///com/github/Aylur/ags/service/applications.js'; +import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; import { Label, Box, Icon, Button, Scrollable, Entry } from 'resource:///com/github/Aylur/ags/widget.js'; -import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js'; import Separator from '../misc/separator.js'; import PopupWindow from '../misc/popup.js'; @@ -23,7 +23,7 @@ const AppItem = (app, window) => { className: 'app', connections: [['clicked', () => { App.closeWindow(window); - execAsync(['hyprctl', 'dispatch', 'exec', `sh -c ${app.executable}`]); + Hyprland.sendMessage(`dispatch exec sh -c ${app.executable}`); // TODO: focus on new client. Is this only needed after launch? ++app.frequency; }]], diff --git a/devices/wim/config/ags/js/bar/keyboard-layout.js b/devices/wim/config/ags/js/bar/keyboard-layout.js index aa9d7b40..8182b6a0 100644 --- a/devices/wim/config/ags/js/bar/keyboard-layout.js +++ b/devices/wim/config/ags/js/bar/keyboard-layout.js @@ -1,11 +1,11 @@ import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; -import { exec } from 'resource:///com/github/Aylur/ags/utils.js'; import { Box, Icon, Label } from 'resource:///com/github/Aylur/ags/widget.js'; const DEFAULT_KB = 'at-translated-set-2-keyboard'; export default () => Box({ className: 'toggle-off', + css: 'padding: 0 10px;', children: [ Icon({ icon: 'input-keyboard-symbolic', @@ -14,16 +14,24 @@ export default () => Box({ Label({ connections: [[Hyprland, (self, _n, layout) => { if (!layout) { - const obj = exec('hyprctl devices -j'); - const keyboards = JSON.parse(obj)['keyboards']; - const kb = keyboards.find(val => val.name === DEFAULT_KB); + Hyprland.sendMessage('j/devices').then(obj => { + const kb = JSON.parse(obj)['keyboards'] + .find(val => val.name === DEFAULT_KB); - layout = kb['active_keymap']; + layout = kb['active_keymap']; - self.label = layout; + const shortName = layout.match(/\(([A-Za-z]+)\)/); + + self.label = shortName ? shortName[1] : layout; + }).catch(print); } else { - self.label = layout; + if (layout === 'error') + return; + + const shortName = layout.match(/\(([A-Za-z]+)\)/); + + self.label = shortName ? shortName[1] : layout; } }, 'keyboard-layout']], }), diff --git a/devices/wim/config/ags/js/bar/main.js b/devices/wim/config/ags/js/bar/main.js index 2101e4b6..d4ea30c0 100644 --- a/devices/wim/config/ags/js/bar/main.js +++ b/devices/wim/config/ags/js/bar/main.js @@ -13,7 +13,7 @@ import Battery from './battery.js'; import Brightness from './brightness.js'; import Audio from './audio.js'; import Revealer from './fullscreen.js'; -//import KeyboardLayout from './keyboard-layout.js'; +import KeyboardLayout from './keyboard-layout.js'; export const BgGradient = () => Window({ @@ -82,9 +82,9 @@ export const Bar = () => Window({ Separator(12), - //KeyboardLayout(), + KeyboardLayout(), - //Separator(12), + Separator(12), Clock(), diff --git a/devices/wim/config/ags/js/bar/workspaces.js b/devices/wim/config/ags/js/bar/workspaces.js index 4dd2985e..17175faf 100644 --- a/devices/wim/config/ags/js/bar/workspaces.js +++ b/devices/wim/config/ags/js/bar/workspaces.js @@ -1,5 +1,5 @@ import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; -import { execAsync, timeout } from 'resource:///com/github/Aylur/ags/utils.js'; +import { timeout } from 'resource:///com/github/Aylur/ags/utils.js'; import { Box, Overlay, Revealer } from 'resource:///com/github/Aylur/ags/widget.js'; import EventBox from '../misc/cursorbox.js'; @@ -12,10 +12,7 @@ const Workspace = ({ i } = {}) => child: EventBox({ tooltipText: `${i}`, - onPrimaryClickRelease: () => { - execAsync(`hyprctl dispatch workspace ${i}`) - .catch(print); - }, + onPrimaryClickRelease: () => Hyprland.sendMessage(`dispatch workspace ${i}`), child: Box({ vpack: 'center', className: 'button', diff --git a/devices/wim/config/ags/js/notifications/base.js b/devices/wim/config/ags/js/notifications/base.js index 5a81dabe..dd85df0f 100644 --- a/devices/wim/config/ags/js/notifications/base.js +++ b/devices/wim/config/ags/js/notifications/base.js @@ -1,8 +1,9 @@ import Applications from 'resource:///com/github/Aylur/ags/service/applications.js'; +import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js'; import Variable from 'resource:///com/github/Aylur/ags/variable.js'; import { Box, Icon, Label, Button } from 'resource:///com/github/Aylur/ags/widget.js'; -import { lookUpIcon, execAsync } from 'resource:///com/github/Aylur/ags/utils.js'; +import { lookUpIcon } from 'resource:///com/github/Aylur/ags/utils.js'; import GLib from 'gi://GLib'; @@ -32,11 +33,32 @@ const NotificationIcon = notif => { if (wmClass != null) { iconCmd = box => { if (!getDragState(box)) { - execAsync(['bash', '-c', - `$AGS_PATH/launch-app.sh - ${wmClass} - ${app.app.get_string('Exec')}`, - ]).catch(print); + if (wmClass === 'thunderbird') { + Hyprland.sendMessage('dispatch togglespecialworkspace thunder'); + } + else if (wmClass === 'Spotify') { + Hyprland.sendMessage('dispatch togglespecialworkspace spot'); + } + else { + Hyprland.sendMessage('j/clients').then(out => { + out = JSON.parse(out); + const classes = []; + for (const key of out) { + if (key.class) + classes.push(key.class); + } + + if (classes.includes(wmClass)) { + Hyprland.sendMessage(`dispatch focuswindow ^(${wmClass})`); + } + else { + Hyprland.sendMessage('[[BATCH]] ' + + 'dispatch workspace empty; ' + + `dispatch exec sh -c ${app.executable} + `); + } + }); + } globalThis.closeAll(); } diff --git a/devices/wim/config/ags/js/overview/clients.js b/devices/wim/config/ags/js/overview/clients.js index d8510103..480c7cd7 100644 --- a/devices/wim/config/ags/js/overview/clients.js +++ b/devices/wim/config/ags/js/overview/clients.js @@ -1,7 +1,7 @@ import App from 'resource:///com/github/Aylur/ags/app.js'; import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; import { Icon, Revealer } from 'resource:///com/github/Aylur/ags/widget.js'; -import { execAsync, timeout } from 'resource:///com/github/Aylur/ags/utils.js'; +import { timeout } from 'resource:///com/github/Aylur/ags/utils.js'; import { WindowButton } from './dragndrop.js'; import * as VARS from './variables.js'; @@ -37,26 +37,21 @@ const Client = (client, active, clients, box) => { child: WindowButton({ mainBox: box, address: client.address, - onSecondaryClickRelease: () => { - execAsync(`hyprctl dispatch closewindow ${addr}`) - .catch(print); - }, + onSecondaryClickRelease: () => Hyprland.sendMessage(`dispatch closewindow ${addr}`), onPrimaryClickRelease: () => { if (wsId < 0) { if (client.workspace.name === 'special') { - execAsync(`hyprctl dispatch - movetoworkspacesilent special:${wsId},${addr}`) + Hyprland.sendMessage(`dispatch movetoworkspacesilent special:${wsId},${addr}`) .then( - - execAsync(`hyprctl dispatch togglespecialworkspace ${wsId}`).then( - () => App.closeWindow('overview'), - ).catch(print), - + Hyprland.sendMessage(`dispatch togglespecialworkspace ${wsId}`) + .then( + () => App.closeWindow('overview'), + ).catch(print), ).catch(print); } else { - execAsync(`hyprctl dispatch togglespecialworkspace ${wsName}`).then( + Hyprland.sendMessage(`dispatch togglespecialworkspace ${wsName}`).then( () => App.closeWindow('overview'), ).catch(print); } @@ -68,10 +63,10 @@ const Client = (client, active, clients, box) => { const currentSpecial = String(currentActive.workspace.name).replace('special:', ''); if (currentActive && currentActive.workspace.id < 0) { - execAsync(`hyprctl dispatch togglespecialworkspace ${currentSpecial}`) + Hyprland.sendMessage(`dispatch togglespecialworkspace ${currentSpecial}`) .catch(print); } - execAsync(`hyprctl dispatch focuswindow ${addr}`).then( + Hyprland.sendMessage(`dispatch focuswindow ${addr}`).then( () => App.closeWindow('overview'), ).catch(print); } @@ -87,7 +82,7 @@ const Client = (client, active, clients, box) => { }; export function updateClients(box) { - execAsync('hyprctl clients -j').then(out => { + Hyprland.sendMessage('j/clients').then(out => { const clients = JSON.parse(out).filter(client => client.class); box._workspaces.forEach(workspace => { diff --git a/devices/wim/config/ags/js/overview/dragndrop.js b/devices/wim/config/ags/js/overview/dragndrop.js index 2cdebc4c..1e0fb0a5 100644 --- a/devices/wim/config/ags/js/overview/dragndrop.js +++ b/devices/wim/config/ags/js/overview/dragndrop.js @@ -1,5 +1,5 @@ +import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; import { EventBox } from 'resource:///com/github/Aylur/ags/widget.js'; -import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js'; import Gtk from 'gi://Gtk'; import Gdk from 'gi://Gdk'; @@ -42,7 +42,7 @@ export const WorkspaceDrop = props => EventBox({ else if (id === 1000) id = 'empty'; - execAsync(`hyprctl dispatch movetoworkspacesilent ${id},address:${data.get_text()}`) + Hyprland.sendMessage(`dispatch movetoworkspacesilent ${id},address:${data.get_text()}`) .catch(print); }]], setup: self => { diff --git a/devices/wim/config/ags/js/powermenu.js b/devices/wim/config/ags/js/powermenu.js index fa68fe42..7e0677a4 100644 --- a/devices/wim/config/ags/js/powermenu.js +++ b/devices/wim/config/ags/js/powermenu.js @@ -1,3 +1,4 @@ +import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; import { CenterBox, Label } from 'resource:///com/github/Aylur/ags/widget.js'; import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js'; @@ -32,7 +33,7 @@ const PowermenuWidget = () => CenterBox({ endWidget: Button({ isButton: true, className: 'logout', - onPrimaryClickRelease: () => execAsync(['hyprctl', 'dispatch', 'exit']).catch(print), + onPrimaryClickRelease: () => Hyprland.sendMessage('dispatch exit').catch(print), child: Label({ label: '', diff --git a/devices/wim/config/ags/js/setup.js b/devices/wim/config/ags/js/setup.js index 02fef87b..d9c90a1a 100644 --- a/devices/wim/config/ags/js/setup.js +++ b/devices/wim/config/ags/js/setup.js @@ -1,4 +1,5 @@ import App from 'resource:///com/github/Aylur/ags/app.js'; +import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js'; import Brightness from '../services/brightness.js'; @@ -41,13 +42,13 @@ export default () => { name: 'swipeSpotify1', gesture: 'LR', edge: 'L', - command: 'hyprctl dispatch togglespecialworkspace spot', + command: () => Hyprland.sendMessage('dispatch togglespecialworkspace spot'), }); TouchGestures.addGesture({ name: 'swipeSpotify2', gesture: 'RL', edge: 'L', - command: 'hyprctl dispatch togglespecialworkspace spot', + command: () => Hyprland.sendMessage('dispatch togglespecialworkspace spot'), }); }; diff --git a/devices/wim/config/ags/services/brightness.js b/devices/wim/config/ags/services/brightness.js index 8d0c651b..91fb5278 100644 --- a/devices/wim/config/ags/services/brightness.js +++ b/devices/wim/config/ags/services/brightness.js @@ -63,7 +63,7 @@ class Brightness extends Service { monitorKbdState() { Variable(0, { - poll: [1000, `brightnessctl -d ${KBD} g`, out => { + poll: [500, `brightnessctl -d ${KBD} g`, out => { if (out !== this._kbd) { this._kbd = out; this.emit('kbd', this._kbd); diff --git a/devices/wim/config/ags/services/pointers.js b/devices/wim/config/ags/services/pointers.js index 006816db..74617be1 100644 --- a/devices/wim/config/ags/services/pointers.js +++ b/devices/wim/config/ags/services/pointers.js @@ -1,6 +1,7 @@ import App from 'resource:///com/github/Aylur/ags/app.js'; +import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; import Service from 'resource:///com/github/Aylur/ags/service.js'; -import { execAsync, subprocess } from 'resource:///com/github/Aylur/ags/utils.js'; +import { subprocess } from 'resource:///com/github/Aylur/ags/utils.js'; import GUdev from 'gi://GUdev'; const UDEV_POINTERS = [ @@ -148,10 +149,10 @@ class Pointers extends Service { if (!toClose) return; - execAsync('hyprctl layers -j').then(layers => { + Hyprland.sendMessage('j/layers').then(layers => { layers = JSON.parse(layers); - execAsync('hyprctl cursorpos -j').then(pos => { + Hyprland.sendMessage('j/cursorpos').then(pos => { pos = JSON.parse(pos); Object.values(layers).forEach(key => { diff --git a/devices/wim/config/ags/services/tablet.js b/devices/wim/config/ags/services/tablet.js index 31828778..70adb63a 100644 --- a/devices/wim/config/ags/services/tablet.js +++ b/devices/wim/config/ags/services/tablet.js @@ -1,3 +1,4 @@ +import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; import Service from 'resource:///com/github/Aylur/ags/service.js'; import TouchGestures from './touch-gestures.js'; import { execAsync, subprocess } from 'resource:///com/github/Aylur/ags/utils.js'; @@ -116,7 +117,7 @@ class Tablet extends Service { getDevices() { this.devices = []; - execAsync(['hyprctl', 'devices', '-j']).then(out => { + Hyprland.sendMessage('j/devices').then(out => { const devices = JSON.parse(out); devices['touch'].forEach(dev => { this.devices.push(dev.name); @@ -139,15 +140,12 @@ class Tablet extends Service { if (output.includes('orientation changed')) { const orientation = ROTATION_MAPPING[output.split(' ').at(-1)]; - execAsync(['hyprctl', 'keyword', 'monitor', - `${SCREEN},transform,${orientation}`]) + Hyprland.sendMessage(`keyword monitor ${SCREEN},transform,${orientation}`) .catch(print); - this.devices.forEach(dev => { - execAsync(['hyprctl', 'keyword', - `device:${dev}:transform`, String(orientation)]) - .catch(print); - }); + const batchRotate = this.devices.map(dev => + `keyword device:${dev}:transform ${orientation}; `); + Hyprland.sendMessage(`[[BATCH]] ${batchRotate.flat()}`); if (TouchGestures.gestureDaemon) { TouchGestures.killDaemon();