diff --git a/flake.lock b/flake.lock index ca7f6192..7e941c05 100644 Binary files a/flake.lock and b/flake.lock differ diff --git a/nixosModules/ags/v2/app.ts b/nixosModules/ags/v2/app.ts index c52785ab..89a525e5 100644 --- a/nixosModules/ags/v2/app.ts +++ b/nixosModules/ags/v2/app.ts @@ -1,6 +1,6 @@ import { App } from 'astal/gtk3'; -import GLib from 'gi://GLib?version=2.0'; +import GLib from 'gi://GLib'; import style from './style.scss'; diff --git a/nixosModules/ags/v2/lib.ts b/nixosModules/ags/v2/lib.ts index b4124dfe..c5a54c71 100644 --- a/nixosModules/ags/v2/lib.ts +++ b/nixosModules/ags/v2/lib.ts @@ -1,6 +1,6 @@ import { Gdk } from 'astal/gtk3'; -import AstalHyprland from 'gi://AstalHyprland?version=0.1'; +import AstalHyprland from 'gi://AstalHyprland'; const Hyprland = AstalHyprland.get_default(); /* Types */ diff --git a/nixosModules/ags/v2/services/monitor-clicks.ts b/nixosModules/ags/v2/services/monitor-clicks.ts index de74876f..f4b2850f 100644 --- a/nixosModules/ags/v2/services/monitor-clicks.ts +++ b/nixosModules/ags/v2/services/monitor-clicks.ts @@ -2,7 +2,7 @@ import { subprocess } from 'astal'; import { App } from 'astal/gtk3'; import GObject, { register, signal } from 'astal/gobject'; -import AstalIO from 'gi://AstalIO?version=0.1'; +import AstalIO from 'gi://AstalIO'; import { hyprMessage } from '../lib'; diff --git a/nixosModules/ags/v2/widgets/applauncher/app-item.tsx b/nixosModules/ags/v2/widgets/applauncher/app-item.tsx index 8f5fb6dc..e21141e3 100644 --- a/nixosModules/ags/v2/widgets/applauncher/app-item.tsx +++ b/nixosModules/ags/v2/widgets/applauncher/app-item.tsx @@ -2,7 +2,7 @@ import { App, Gtk, Widget } from 'astal/gtk3'; import { register } from 'astal/gobject'; /* Types */ -import AstalApps from 'gi://AstalApps?version=0.1'; +import AstalApps from 'gi://AstalApps'; type AppItemProps = Widget.BoxProps & { app: AstalApps.Application }; diff --git a/nixosModules/ags/v2/widgets/applauncher/launch.ts b/nixosModules/ags/v2/widgets/applauncher/launch.ts index 956d9d08..c519c9b4 100644 --- a/nixosModules/ags/v2/widgets/applauncher/launch.ts +++ b/nixosModules/ags/v2/widgets/applauncher/launch.ts @@ -1,6 +1,6 @@ import { execAsync } from 'astal'; -import AstalApps from 'gi://AstalApps?version=0.1'; +import AstalApps from 'gi://AstalApps'; const bash = async(strings: TemplateStringsArray | string, ...values: unknown[]) => { diff --git a/nixosModules/ags/v2/widgets/applauncher/main.tsx b/nixosModules/ags/v2/widgets/applauncher/main.tsx index 58b0eb81..60027951 100644 --- a/nixosModules/ags/v2/widgets/applauncher/main.tsx +++ b/nixosModules/ags/v2/widgets/applauncher/main.tsx @@ -1,7 +1,7 @@ import { App, Astal, Gtk, Widget } from 'astal/gtk3'; import { idle } from 'astal'; -import AstalApps from 'gi://AstalApps?version=0.1'; +import AstalApps from 'gi://AstalApps'; import { Fzf, FzfResultItem } from 'fzf'; diff --git a/nixosModules/ags/v2/widgets/bar/fullscreen.tsx b/nixosModules/ags/v2/widgets/bar/fullscreen.tsx index 45c28ebb..d9c52d89 100644 --- a/nixosModules/ags/v2/widgets/bar/fullscreen.tsx +++ b/nixosModules/ags/v2/widgets/bar/fullscreen.tsx @@ -1,7 +1,7 @@ import { App, Astal, Gdk, Gtk, Widget } from 'astal/gtk3'; import { bind, Variable } from 'astal'; -import AstalHyprland from 'gi://AstalHyprland?version=0.1'; +import AstalHyprland from 'gi://AstalHyprland'; const Hyprland = AstalHyprland.get_default(); import { get_hyprland_monitor_desc, get_monitor_desc, hyprMessage } from '../../lib'; diff --git a/nixosModules/ags/v2/widgets/bar/items/clock.tsx b/nixosModules/ags/v2/widgets/bar/items/clock.tsx index e7968ad4..4e528601 100644 --- a/nixosModules/ags/v2/widgets/bar/items/clock.tsx +++ b/nixosModules/ags/v2/widgets/bar/items/clock.tsx @@ -1,7 +1,7 @@ import { bind, Variable } from 'astal'; import { App } from 'astal/gtk3'; -import GLib from 'gi://GLib?version=2.0'; +import GLib from 'gi://GLib'; import { PopupWindow } from '../../misc/popup-window'; diff --git a/nixosModules/ags/v2/widgets/bar/items/current-client.tsx b/nixosModules/ags/v2/widgets/bar/items/current-client.tsx index cf985302..25760293 100644 --- a/nixosModules/ags/v2/widgets/bar/items/current-client.tsx +++ b/nixosModules/ags/v2/widgets/bar/items/current-client.tsx @@ -1,9 +1,9 @@ import { bind, Variable } from 'astal'; -import AstalApps from 'gi://AstalApps?version=0.1'; +import AstalApps from 'gi://AstalApps'; const Applications = AstalApps.Apps.new(); -import AstalHyprland from 'gi://AstalHyprland?version=0.1'; +import AstalHyprland from 'gi://AstalHyprland'; const Hyprland = AstalHyprland.get_default(); import Separator from '../../misc/separator'; diff --git a/nixosModules/ags/v2/widgets/bar/items/notif-button.tsx b/nixosModules/ags/v2/widgets/bar/items/notif-button.tsx index 09f97acc..3b76dde6 100644 --- a/nixosModules/ags/v2/widgets/bar/items/notif-button.tsx +++ b/nixosModules/ags/v2/widgets/bar/items/notif-button.tsx @@ -1,7 +1,7 @@ import { bind } from 'astal'; import { App } from 'astal/gtk3'; -import AstalNotifd from 'gi://AstalNotifd?version=0.1'; +import AstalNotifd from 'gi://AstalNotifd'; const Notifications = AstalNotifd.get_default(); import Separator from '../../misc/separator'; diff --git a/nixosModules/ags/v2/widgets/bar/items/workspaces.tsx b/nixosModules/ags/v2/widgets/bar/items/workspaces.tsx index 29151f3f..b5722f03 100644 --- a/nixosModules/ags/v2/widgets/bar/items/workspaces.tsx +++ b/nixosModules/ags/v2/widgets/bar/items/workspaces.tsx @@ -1,7 +1,7 @@ import { Gtk, Widget } from 'astal/gtk3'; import { timeout } from 'astal'; -import AstalHyprland from 'gi://AstalHyprland?version=0.1'; +import AstalHyprland from 'gi://AstalHyprland'; const Hyprland = AstalHyprland.get_default(); import { hyprMessage } from '../../../lib'; diff --git a/nixosModules/ags/v2/widgets/date/main.tsx b/nixosModules/ags/v2/widgets/date/main.tsx index db7d699c..4cb4d583 100644 --- a/nixosModules/ags/v2/widgets/date/main.tsx +++ b/nixosModules/ags/v2/widgets/date/main.tsx @@ -1,7 +1,7 @@ import { bind, Variable } from 'astal'; import { Astal, Gtk } from 'astal/gtk3'; -import GLib from 'gi://GLib?version=2.0'; +import GLib from 'gi://GLib'; import PopupWindow from '../misc/popup-window'; diff --git a/nixosModules/ags/v2/widgets/lockscreen/main.tsx b/nixosModules/ags/v2/widgets/lockscreen/main.tsx index 93bb8732..f985dcda 100644 --- a/nixosModules/ags/v2/widgets/lockscreen/main.tsx +++ b/nixosModules/ags/v2/widgets/lockscreen/main.tsx @@ -3,7 +3,7 @@ import { App, Astal, Gdk, Gtk, Widget } from 'astal/gtk3'; import { register } from 'astal/gobject'; import AstalAuth from 'gi://AstalAuth'; -import Lock from 'gi://GtkSessionLock?version=0.1'; +import Lock from 'gi://GtkSessionLock'; import Separator from '../misc/separator'; import { get_hyprland_monitor_desc } from '../../lib'; diff --git a/nixosModules/ags/v2/widgets/misc/popup-window.tsx b/nixosModules/ags/v2/widgets/misc/popup-window.tsx index 5e060deb..dd1b4f7e 100644 --- a/nixosModules/ags/v2/widgets/misc/popup-window.tsx +++ b/nixosModules/ags/v2/widgets/misc/popup-window.tsx @@ -1,5 +1,5 @@ import { App, Astal, Gtk, Widget } from 'astal/gtk3'; -import { register } from 'astal/gobject'; +import { property, register } from 'astal/gobject'; import { Binding, idle } from 'astal'; import { get_hyprland_monitor, hyprMessage } from '../../lib'; @@ -20,8 +20,12 @@ type PopupWindowProps = Widget.WindowProps & { @register() export class PopupWindow extends Widget.Window { - transition: HyprTransition | Binding; - close_on_unfocus: CloseType | Binding; + @property(String) + declare transition: HyprTransition | Binding; + + @property(String) + declare close_on_unfocus: CloseType | Binding; + on_open: PopupCallback; on_close: PopupCallback; diff --git a/nixosModules/ags/v2/widgets/notifs/center.tsx b/nixosModules/ags/v2/widgets/notifs/center.tsx index 81b1986e..1bb4e160 100644 --- a/nixosModules/ags/v2/widgets/notifs/center.tsx +++ b/nixosModules/ags/v2/widgets/notifs/center.tsx @@ -1,7 +1,7 @@ import { bind, timeout } from 'astal'; import { App, Gtk, Widget } from 'astal/gtk3'; -import AstalNotifd from 'gi://AstalNotifd?version=0.1'; +import AstalNotifd from 'gi://AstalNotifd'; const Notifications = AstalNotifd.get_default(); import { Notification, HasNotifs } from './notification'; diff --git a/nixosModules/ags/v2/widgets/notifs/gesture.tsx b/nixosModules/ags/v2/widgets/notifs/gesture.tsx index b5f3793b..b52560df 100644 --- a/nixosModules/ags/v2/widgets/notifs/gesture.tsx +++ b/nixosModules/ags/v2/widgets/notifs/gesture.tsx @@ -1,10 +1,10 @@ import { Gdk, Gtk, Widget } from 'astal/gtk3'; -import { register, signal } from 'astal/gobject'; +import { property, register } from 'astal/gobject'; import { idle, interval } from 'astal'; -import AstalIO from 'gi://AstalIO?version=0.1'; +import AstalIO from 'gi://AstalIO'; -import AstalNotifd from 'gi://AstalNotifd?version=0.1'; +import AstalNotifd from 'gi://AstalNotifd'; const Notifications = AstalNotifd.get_default(); import { hyprMessage } from '../../lib'; @@ -47,68 +47,80 @@ type NotifGestureWrapperProps = Widget.BoxProps & { @register() export class NotifGestureWrapper extends Widget.EventBox { - static popups = new Map(); + public static popups = new Map(); + public static sliding_in = 0; + public static on_sliding_in: (amount: number) => void; readonly id: number; - readonly slide_in_from: 'Left' | 'Right'; - readonly is_popup: boolean; private timer_object: AstalIO.Time | undefined; - public popup_timer: number; + @property(Number) + declare popup_timer: number; - @signal(Number) - declare timer_update: (popup_timer: number) => void; - - public static sliding_in = 0; - public static on_sliding_in: (amount: number) => void; - - public dragging: boolean; + @property(Boolean) + declare dragging: boolean; private async get_hovered(): Promise { - try { - const layers = JSON.parse(await hyprMessage('j/layers')) as LayerResult; - const cursorPos = JSON.parse(await hyprMessage('j/cursorpos')) as CursorPos; + const layers = JSON.parse(await hyprMessage('j/layers')) as LayerResult; + const cursorPos = JSON.parse(await hyprMessage('j/cursorpos')) as CursorPos; - const monitor = display?.get_monitor_at_window(this.get_window()!); - const plugName = get_hyprland_monitor(monitor!)?.name; + const win = this.get_window(); - const notifLayer = layers[plugName ?? '']?.levels['3'] - ?.find((n) => n.namespace === 'notifications'); - - if (!notifLayer) { - return false; - } - - const index = [...NotifGestureWrapper.popups.keys()] - .sort((a, b) => b - a) - .indexOf(this.id); - - const popups = [...NotifGestureWrapper.popups.entries()] - .sort((a, b) => b[0] - a[0]) - .map(([key, val]) => [key, val.get_allocated_height()]); - - const thisY = notifLayer.y + popups - .map((v) => v[1]) - .slice(0, index) - .reduce((prev, curr) => prev + curr, 0); - - if (cursorPos.y >= thisY && cursorPos.y <= thisY + (popups[index][1] ?? 0)) { - if (cursorPos.x >= notifLayer.x && - cursorPos.x <= notifLayer.x + notifLayer.w) { - return true; - } - } + if (!win) { + return false; } - catch (e) { - console.log(e); + + const monitor = display?.get_monitor_at_window(win); + + if (!monitor) { + return false; + } + + const plugName = get_hyprland_monitor(monitor)?.name; + + const notifLayer = layers[plugName ?? '']?.levels['3'] + ?.find((n) => n.namespace === 'notifications'); + + if (!notifLayer) { + return false; + } + + const index = [...NotifGestureWrapper.popups.keys()] + .sort((a, b) => b - a) + .indexOf(this.id); + + const popups = [...NotifGestureWrapper.popups.entries()] + .sort((a, b) => b[0] - a[0]) + .map(([key, val]) => [key, val.get_allocated_height()]); + + const thisY = notifLayer.y + popups + .map((v) => v[1]) + .slice(0, index) + .reduce((prev, curr) => prev + curr, 0); + + if (cursorPos.y >= thisY && cursorPos.y <= thisY + (popups[index][1] ?? 0)) { + if (cursorPos.x >= notifLayer.x && + cursorPos.x <= notifLayer.x + notifLayer.w) { + return true; + } } return false; } + private setCursor(cursor: string) { + if (!display) { + return; + } + this.window.set_cursor(Gdk.Cursor.new_from_name( + display, + cursor, + )); + } + public slideAway(side: 'Left' | 'Right') { if (!this.sensitive) { return; @@ -158,50 +170,25 @@ export class NotifGestureWrapper extends Widget.EventBox { this.popup_timer = popup_timer; this.is_popup = this.popup_timer !== 0; - this.timer_update(this.popup_timer); // OnClick this.connect('button-press-event', () => { - if (!display) { - return; - } - this.window.set_cursor(Gdk.Cursor.new_from_name( - display, - 'grabbing', - )); + this.setCursor('grabbing'); }); // OnRelease this.connect('button-release-event', () => { - if (!display) { - return; - } - this.window.set_cursor(Gdk.Cursor.new_from_name( - display, - 'grab', - )); + this.setCursor('grab'); }); // OnHover this.connect('enter-notify-event', () => { - if (!display) { - return; - } - this.window.set_cursor(Gdk.Cursor.new_from_name( - display, - 'grab', - )); + this.setCursor('grab'); }); // OnHoverLost this.connect('leave-notify-event', () => { - if (!display) { - return; - } - this.window.set_cursor(Gdk.Cursor.new_from_name( - display, - 'grab', - )); + this.setCursor('grab'); }); // Handle timeout before sliding away if it is a popup @@ -212,7 +199,7 @@ export class NotifGestureWrapper extends Widget.EventBox { this.slideAway('Left'); } else { - this.timer_update(--this.popup_timer); + --this.popup_timer; } } }); @@ -260,13 +247,7 @@ export class NotifGestureWrapper extends Widget.EventBox { // Put a threshold on if a click is actually dragging this.dragging = Math.abs(offset) > SLIDE_MIN_THRESHOLD; - if (!display) { - return; - } - this.window.set_cursor(Gdk.Cursor.new_from_name( - display, - 'grabbing', - )); + this.setCursor('grabbing'); }) // On drag end @@ -279,24 +260,13 @@ export class NotifGestureWrapper extends Widget.EventBox { // If crosses threshold after letting go, slide away if (Math.abs(offset) > MAX_OFFSET) { - if (offset > 0) { - this.slideAway('Right'); - } - else { - this.slideAway('Left'); - } + this.slideAway(offset > 0 ? 'Right' : 'Left'); } else { self.css = defaultStyle; this.dragging = false; - if (!display) { - return; - } - this.window.set_cursor(Gdk.Cursor.new_from_name( - display, - 'grab', - )); + this.setCursor('grab'); } }); diff --git a/nixosModules/ags/v2/widgets/notifs/notification.tsx b/nixosModules/ags/v2/widgets/notifs/notification.tsx index 25edf810..cfc9eeee 100644 --- a/nixosModules/ags/v2/widgets/notifs/notification.tsx +++ b/nixosModules/ags/v2/widgets/notifs/notification.tsx @@ -1,12 +1,12 @@ import { App, Gtk, Gdk, Widget } from 'astal/gtk3'; import { Variable } from 'astal'; -import GLib from 'gi://GLib?version=2.0'; +import GLib from 'gi://GLib'; -import AstalApps from 'gi://AstalApps?version=0.1'; +import AstalApps from 'gi://AstalApps'; const Applications = AstalApps.Apps.new(); -import AstalNotifd from 'gi://AstalNotifd?version=0.1'; +import AstalNotifd from 'gi://AstalNotifd'; const Notifications = AstalNotifd.get_default(); import NotifGestureWrapper from './gesture'; @@ -115,7 +115,7 @@ export const Notification = ({ slide_in_from={slide_in_from} setup_notif={(self) => { if (self.is_popup) { - self.connect('timer-update', () => { + self.connect('notify::popup-timer', () => { progress.fraction = self.popup_timer / 5; }); } diff --git a/nixosModules/ags/v2/widgets/notifs/popups.tsx b/nixosModules/ags/v2/widgets/notifs/popups.tsx index f7aaf78b..b564a351 100644 --- a/nixosModules/ags/v2/widgets/notifs/popups.tsx +++ b/nixosModules/ags/v2/widgets/notifs/popups.tsx @@ -1,4 +1,4 @@ -import AstalNotifd from 'gi://AstalNotifd?version=0.1'; +import AstalNotifd from 'gi://AstalNotifd'; const Notifications = AstalNotifd.get_default(); import { NotifGestureWrapper } from './gesture';