feat(agsV2): switch to async hyprMessage wrapper
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-10-16 12:32:06 -04:00
parent 8ee3530330
commit 276c399f49
6 changed files with 25 additions and 19 deletions

View file

@ -37,3 +37,11 @@ export const get_gdkmonitor_from_desc = (desc: string): Gdk.Monitor => {
export const get_monitor_desc = (mon: AstalHyprland.Monitor): string => { export const get_monitor_desc = (mon: AstalHyprland.Monitor): string => {
return `desc:${mon.description}`; return `desc:${mon.description}`;
}; };
export const hyprMessage = (message: string) => new Promise<string>((resolution = () => { /**/ }) => {
Hyprland.message_async(message, (_, asyncResult) => {
const result = Hyprland.message_finish(asyncResult);
resolution(result);
});
});

View file

@ -4,7 +4,7 @@ import { bind, Variable } from 'astal';
import AstalHyprland from 'gi://AstalHyprland?version=0.1'; import AstalHyprland from 'gi://AstalHyprland?version=0.1';
const Hyprland = AstalHyprland.get_default(); 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({ const FullscreenState = Variable({
@ -12,7 +12,7 @@ const FullscreenState = Variable({
clientAddrs: new Map() as Map<string, string>, clientAddrs: new Map() as Map<string, string>,
}); });
Hyprland.connect('event', () => { Hyprland.connect('event', async() => {
const arrayEquals = (a1: unknown[], a2: unknown[]) => const arrayEquals = (a1: unknown[], a2: unknown[]) =>
a1.sort().toString() === a2.sort().toString(); a1.sort().toString() === a2.sort().toString();
@ -20,7 +20,7 @@ Hyprland.connect('event', () => {
m1.size === m2.size && m1.size === m2.size &&
Array.from(m1.keys()).every((key) => m1.get(key) === m2.get(key)); 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 fs = FullscreenState.get();
const fsClients = Hyprland.get_clients().filter((c) => { const fsClients = Hyprland.get_clients().filter((c) => {

View file

@ -7,6 +7,7 @@ import AstalHyprland from 'gi://AstalHyprland?version=0.1';
const Hyprland = AstalHyprland.get_default(); const Hyprland = AstalHyprland.get_default();
import Separator from '../../misc/separator'; import Separator from '../../misc/separator';
import { hyprMessage } from '../../../lib';
export default () => { export default () => {
@ -37,8 +38,8 @@ export default () => {
updateVars(); updateVars();
Hyprland.connect('notify::focused-client', () => updateVars()); Hyprland.connect('notify::focused-client', () => updateVars());
Hyprland.connect('client-removed', () => updateVars()); Hyprland.connect('client-removed', () => updateVars());
Hyprland.connect('client-added', () => { Hyprland.connect('client-added', async() => {
updateVars(Hyprland.get_client(JSON.parse(Hyprland.message('j/activewindow')).address)); updateVars(Hyprland.get_client(JSON.parse(await hyprMessage('j/activewindow')).address));
}); });
return ( return (

View file

@ -4,6 +4,8 @@ import { timeout } from 'astal';
import AstalHyprland from 'gi://AstalHyprland?version=0.1'; import AstalHyprland from 'gi://AstalHyprland?version=0.1';
const Hyprland = AstalHyprland.get_default(); const Hyprland = AstalHyprland.get_default();
import { hyprMessage } from '../../../lib';
const URGENT_DURATION = 1000; const URGENT_DURATION = 1000;
@ -17,7 +19,7 @@ const Workspace = ({ id = 0 }) => (
tooltip_text={id.toString()} tooltip_text={id.toString()}
onClickRelease={() => { onClickRelease={() => {
Hyprland.message_async(`dispatch workspace ${id}`, () => { /**/ }); hyprMessage(`dispatch workspace ${id}`);
}} }}
> >
<box <box

View file

@ -2,8 +2,7 @@ import { Astal, Widget } from 'astal/gtk3';
import { register, property } from 'astal/gobject'; import { register, property } from 'astal/gobject';
import { Binding, idle } from 'astal'; import { Binding, idle } from 'astal';
import AstalHyprland from 'gi://AstalHyprland?version=0.1'; import { hyprMessage } from '../../lib';
const Hyprland = AstalHyprland.get_default();
/* Types */ /* Types */
type CloseType = 'none' | 'stay' | 'released' | 'clicked'; type CloseType = 'none' | 'stay' | 'released' | 'clicked';
@ -59,10 +58,7 @@ class PopupWindow extends Widget.Window {
}); });
const setTransition = (_: PopupWindow, t: HyprTransition | Binding<HyprTransition>) => { const setTransition = (_: PopupWindow, t: HyprTransition | Binding<HyprTransition>) => {
Hyprland.message_async( hyprMessage(`keyword layerrule animation ${t}, ${this.name}`);
`keyword layerrule animation ${t}, ${this.name}`,
() => { /**/ },
);
}; };
this.connect('notify::transition', setTransition); this.connect('notify::transition', setTransition);

View file

@ -7,8 +7,7 @@ import AstalIO from 'gi://AstalIO?version=0.1';
import AstalNotifd from 'gi://AstalNotifd?version=0.1'; import AstalNotifd from 'gi://AstalNotifd?version=0.1';
const Notifications = AstalNotifd.get_default(); const Notifications = AstalNotifd.get_default();
import AstalHyprland from 'gi://AstalHyprland?version=0.1'; import { hyprMessage } from '../../lib';
const Hyprland = AstalHyprland.get_default();
import { HasNotifs } from './notification'; import { HasNotifs } from './notification';
import { get_hyprland_monitor } from '../../lib'; import { get_hyprland_monitor } from '../../lib';
@ -83,9 +82,9 @@ export class NotifGestureWrapper extends Widget.EventBox {
@property(Boolean) @property(Boolean)
declare dragging: boolean; declare dragging: boolean;
get hovered(): boolean { private async get_hovered(): Promise<boolean> {
const layers = JSON.parse(Hyprland.message('j/layers')) as LayerResult; const layers = JSON.parse(await hyprMessage('j/layers')) as LayerResult;
const cursorPos = JSON.parse(Hyprland.message('j/cursorpos')) as CursorPos; const cursorPos = JSON.parse(await hyprMessage('j/cursorpos')) as CursorPos;
const window = this.get_window(); 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 // Handle timeout before sliding away if it is a popup
if (this.popup_timer !== 0) { if (this.popup_timer !== 0) {
this.timer_object = interval(1000, () => { this.timer_object = interval(1000, async() => {
if (!this.hovered) { if (!(await this.get_hovered())) {
if (this.popup_timer === 0) { if (this.popup_timer === 0) {
this.slideAway('Left'); this.slideAway('Left');
} }