feat(ags): use Hyprland.sendMessage instead of hyprctl

This commit is contained in:
matt1432 2023-11-13 13:19:14 -05:00
parent 1e4fe115ad
commit c0a97e044c
13 changed files with 79 additions and 71 deletions

View file

@ -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

View file

@ -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;
}]],

View file

@ -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']],
}),

View file

@ -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(),

View file

@ -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',

View file

@ -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();
}

View file

@ -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 => {

View file

@ -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 => {

View file

@ -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: '',

View file

@ -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'),
});
};

View file

@ -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);

View file

@ -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 => {

View file

@ -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();