diff --git a/nixosModules/ags/v2/lib.ts b/nixosModules/ags/v2/lib.ts index b7e4cd94..927bb0b8 100644 --- a/nixosModules/ags/v2/lib.ts +++ b/nixosModules/ags/v2/lib.ts @@ -37,3 +37,11 @@ export const get_gdkmonitor_from_desc = (desc: string): Gdk.Monitor => { export const get_monitor_desc = (mon: AstalHyprland.Monitor): string => { return `desc:${mon.description}`; }; + +export const hyprMessage = (message: string) => new Promise((resolution = () => { /**/ }) => { + Hyprland.message_async(message, (_, asyncResult) => { + const result = Hyprland.message_finish(asyncResult); + + resolution(result); + }); +}); diff --git a/nixosModules/ags/v2/widgets/bar/fullscreen.tsx b/nixosModules/ags/v2/widgets/bar/fullscreen.tsx index 41a3b5b4..e7f5396b 100644 --- a/nixosModules/ags/v2/widgets/bar/fullscreen.tsx +++ b/nixosModules/ags/v2/widgets/bar/fullscreen.tsx @@ -4,7 +4,7 @@ import { bind, Variable } from 'astal'; import AstalHyprland from 'gi://AstalHyprland?version=0.1'; const Hyprland = AstalHyprland.get_default(); -import { get_hyprland_monitor_desc, get_monitor_desc } from '../../lib'; +import { get_hyprland_monitor_desc, get_monitor_desc, hyprMessage } from '../../lib'; const FullscreenState = Variable({ @@ -12,7 +12,7 @@ const FullscreenState = Variable({ clientAddrs: new Map() as Map, }); -Hyprland.connect('event', () => { +Hyprland.connect('event', async() => { const arrayEquals = (a1: unknown[], a2: unknown[]) => a1.sort().toString() === a2.sort().toString(); @@ -20,7 +20,7 @@ Hyprland.connect('event', () => { m1.size === m2.size && Array.from(m1.keys()).every((key) => m1.get(key) === m2.get(key)); - const newMonitors = JSON.parse(Hyprland.message('j/monitors')) as AstalHyprland.Monitor[]; + const newMonitors = JSON.parse(await hyprMessage('j/monitors')) as AstalHyprland.Monitor[]; const fs = FullscreenState.get(); const fsClients = Hyprland.get_clients().filter((c) => { diff --git a/nixosModules/ags/v2/widgets/bar/items/current-client.tsx b/nixosModules/ags/v2/widgets/bar/items/current-client.tsx index 751dd1f3..163ea6f6 100644 --- a/nixosModules/ags/v2/widgets/bar/items/current-client.tsx +++ b/nixosModules/ags/v2/widgets/bar/items/current-client.tsx @@ -7,6 +7,7 @@ import AstalHyprland from 'gi://AstalHyprland?version=0.1'; const Hyprland = AstalHyprland.get_default(); import Separator from '../../misc/separator'; +import { hyprMessage } from '../../../lib'; export default () => { @@ -37,8 +38,8 @@ export default () => { updateVars(); Hyprland.connect('notify::focused-client', () => updateVars()); Hyprland.connect('client-removed', () => updateVars()); - Hyprland.connect('client-added', () => { - updateVars(Hyprland.get_client(JSON.parse(Hyprland.message('j/activewindow')).address)); + Hyprland.connect('client-added', async() => { + updateVars(Hyprland.get_client(JSON.parse(await hyprMessage('j/activewindow')).address)); }); return ( diff --git a/nixosModules/ags/v2/widgets/bar/items/workspaces.tsx b/nixosModules/ags/v2/widgets/bar/items/workspaces.tsx index 23ba8cfd..2c6d64ea 100644 --- a/nixosModules/ags/v2/widgets/bar/items/workspaces.tsx +++ b/nixosModules/ags/v2/widgets/bar/items/workspaces.tsx @@ -4,6 +4,8 @@ import { timeout } from 'astal'; import AstalHyprland from 'gi://AstalHyprland?version=0.1'; const Hyprland = AstalHyprland.get_default(); +import { hyprMessage } from '../../../lib'; + const URGENT_DURATION = 1000; @@ -17,7 +19,7 @@ const Workspace = ({ id = 0 }) => ( tooltip_text={id.toString()} onClickRelease={() => { - Hyprland.message_async(`dispatch workspace ${id}`, () => { /**/ }); + hyprMessage(`dispatch workspace ${id}`); }} > ) => { - Hyprland.message_async( - `keyword layerrule animation ${t}, ${this.name}`, - () => { /**/ }, - ); + hyprMessage(`keyword layerrule animation ${t}, ${this.name}`); }; this.connect('notify::transition', setTransition); diff --git a/nixosModules/ags/v2/widgets/notifs/gesture.tsx b/nixosModules/ags/v2/widgets/notifs/gesture.tsx index bec34a90..272762d3 100644 --- a/nixosModules/ags/v2/widgets/notifs/gesture.tsx +++ b/nixosModules/ags/v2/widgets/notifs/gesture.tsx @@ -7,8 +7,7 @@ import AstalIO from 'gi://AstalIO?version=0.1'; import AstalNotifd from 'gi://AstalNotifd?version=0.1'; const Notifications = AstalNotifd.get_default(); -import AstalHyprland from 'gi://AstalHyprland?version=0.1'; -const Hyprland = AstalHyprland.get_default(); +import { hyprMessage } from '../../lib'; import { HasNotifs } from './notification'; import { get_hyprland_monitor } from '../../lib'; @@ -83,9 +82,9 @@ export class NotifGestureWrapper extends Widget.EventBox { @property(Boolean) declare dragging: boolean; - get hovered(): boolean { - const layers = JSON.parse(Hyprland.message('j/layers')) as LayerResult; - const cursorPos = JSON.parse(Hyprland.message('j/cursorpos')) as CursorPos; + private async get_hovered(): Promise { + const layers = JSON.parse(await hyprMessage('j/layers')) as LayerResult; + const cursorPos = JSON.parse(await hyprMessage('j/cursorpos')) as CursorPos; const window = this.get_window(); @@ -214,8 +213,8 @@ export class NotifGestureWrapper extends Widget.EventBox { // Handle timeout before sliding away if it is a popup if (this.popup_timer !== 0) { - this.timer_object = interval(1000, () => { - if (!this.hovered) { + this.timer_object = interval(1000, async() => { + if (!(await this.get_hovered())) { if (this.popup_timer === 0) { this.slideAway('Left'); }