From e1e38fc18ff5e097e3f5e1a2eaaa8a98adc63e6a Mon Sep 17 00:00:00 2001 From: matt1432 Date: Mon, 18 Dec 2023 23:20:32 -0500 Subject: [PATCH] refactor(ags): typecheck popupwins and make cursorbox its own thing --- .../wim/config/ags/js/applauncher/app-item.js | 7 +- devices/wim/config/ags/js/applauncher/main.js | 3 +- .../wim/config/ags/js/bar/buttons/clock.js | 8 +- .../wim/config/ags/js/bar/buttons/heart.js | 6 +- .../config/ags/js/bar/buttons/notif-button.js | 10 +- .../config/ags/js/bar/buttons/osk-toggle.js | 8 +- .../ags/js/bar/buttons/quick-settings.js | 12 +- .../ags/js/bar/buttons/tablet-toggle.js | 6 +- .../config/ags/js/bar/buttons/workspaces.js | 10 +- .../wim/config/ags/js/media-player/gesture.js | 5 +- .../wim/config/ags/js/media-player/mpris.js | 14 ++- devices/wim/config/ags/js/misc/audio-icons.js | 8 +- devices/wim/config/ags/js/misc/closer.js | 5 +- devices/wim/config/ags/js/misc/cursorbox.js | 63 ++++++----- devices/wim/config/ags/js/misc/popup.js | 105 ++++++++++-------- devices/wim/config/ags/js/misc/separator.js | 8 ++ .../wim/config/ags/js/notifications/base.js | 12 +- .../wim/config/ags/js/notifications/center.js | 4 +- .../wim/config/ags/js/notifications/main.js | 2 +- devices/wim/config/ags/js/osd/main.js | 4 +- .../wim/config/ags/js/overview/dragndrop.js | 15 ++- devices/wim/config/ags/js/overview/main.js | 12 +- devices/wim/config/ags/js/powermenu.js | 26 ++--- .../config/ags/js/quick-settings/bluetooth.js | 6 +- .../ags/js/quick-settings/button-grid.js | 10 +- .../config/ags/js/quick-settings/network.js | 6 +- devices/wim/config/ags/services/pointers.js | 16 +-- 27 files changed, 215 insertions(+), 176 deletions(-) diff --git a/devices/wim/config/ags/js/applauncher/app-item.js b/devices/wim/config/ags/js/applauncher/app-item.js index 63c6a5a..8f14659 100644 --- a/devices/wim/config/ags/js/applauncher/app-item.js +++ b/devices/wim/config/ags/js/applauncher/app-item.js @@ -4,7 +4,7 @@ import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; import { Box, Icon, Label } from 'resource:///com/github/Aylur/ags/widget.js'; import { lookUpIcon } from 'resource:///com/github/Aylur/ags/utils.js'; -import EventBox from '../misc/cursorbox.js'; +import CursorBox from '../misc/cursorbox.js'; /** @@ -50,14 +50,13 @@ export default (app) => { ], }); - - return EventBox({ + return CursorBox({ hexpand: true, class_name: 'app', attribute: { app }, - onPrimaryClickRelease: (self) => { + on_primary_click_release: (self) => { App.closeWindow('applauncher'); Hyprland.sendMessage(`dispatch exec sh -c ${self.attribute.app.executable}`); diff --git a/devices/wim/config/ags/js/applauncher/main.js b/devices/wim/config/ags/js/applauncher/main.js index 3fa0ace..46f3f97 100644 --- a/devices/wim/config/ags/js/applauncher/main.js +++ b/devices/wim/config/ags/js/applauncher/main.js @@ -78,10 +78,9 @@ const Applauncher = ({ window_name = 'applauncher' } = {}) => { }, on_change: ({ text }) => { - if (!text) { + if (text === null) { return; } - setSort(text); let visibleApps = 0; diff --git a/devices/wim/config/ags/js/bar/buttons/clock.js b/devices/wim/config/ags/js/bar/buttons/clock.js index da6ca24..adaecfa 100644 --- a/devices/wim/config/ags/js/bar/buttons/clock.js +++ b/devices/wim/config/ags/js/bar/buttons/clock.js @@ -4,13 +4,13 @@ import { Label } from 'resource:///com/github/Aylur/ags/widget.js'; const { DateTime } = imports.gi.GLib; -import EventBox from '../../misc/cursorbox.js'; +import CursorBox from '../../misc/cursorbox.js'; -export default () => EventBox({ - className: 'toggle-off', +export default () => CursorBox({ + class_name: 'toggle-off', - onPrimaryClickRelease: () => App.toggleWindow('calendar'), + on_primary_click_release: () => App.toggleWindow('calendar'), setup: (self) => { self.hook(App, (_, windowName, visible) => { diff --git a/devices/wim/config/ags/js/bar/buttons/heart.js b/devices/wim/config/ags/js/bar/buttons/heart.js index c72b53e..de01a85 100644 --- a/devices/wim/config/ags/js/bar/buttons/heart.js +++ b/devices/wim/config/ags/js/bar/buttons/heart.js @@ -2,7 +2,7 @@ import { Label } from 'resource:///com/github/Aylur/ags/widget.js'; import Variable from 'resource:///com/github/Aylur/ags/variable.js'; -import EventBox from '../../misc/cursorbox.js'; +import CursorBox from '../../misc/cursorbox.js'; import Persist from '../../misc/persist.js'; const HeartState = Variable(''); @@ -16,8 +16,8 @@ Persist({ }); -export default () => EventBox({ - onPrimaryClickRelease: () => { +export default () => CursorBox({ + on_primary_click_release: () => { HeartState.value = HeartState.value === '' ? '󰣐' : ''; }, diff --git a/devices/wim/config/ags/js/bar/buttons/notif-button.js b/devices/wim/config/ags/js/bar/buttons/notif-button.js index 3a4dfd9..dc5d9eb 100644 --- a/devices/wim/config/ags/js/bar/buttons/notif-button.js +++ b/devices/wim/config/ags/js/bar/buttons/notif-button.js @@ -3,18 +3,18 @@ import Notifications from 'resource:///com/github/Aylur/ags/service/notification import { Box, CenterBox, Icon, Label } from 'resource:///com/github/Aylur/ags/widget.js'; -import EventBox from '../../misc/cursorbox.js'; +import CursorBox from '../../misc/cursorbox.js'; import Separator from '../../misc/separator.js'; const SPACING = 4; -export default () => EventBox({ - className: 'toggle-off', +export default () => CursorBox({ + class_name: 'toggle-off', - onPrimaryClickRelease: (self) => { + on_primary_click_release: (self) => { // @ts-expect-error - App.getWindow('notification-center')?.setXPos( + App.getWindow('notification-center')?.attribute.set_x_pos( self.get_allocation(), 'right', ); diff --git a/devices/wim/config/ags/js/bar/buttons/osk-toggle.js b/devices/wim/config/ags/js/bar/buttons/osk-toggle.js index 58d29db..2fe6e34 100644 --- a/devices/wim/config/ags/js/bar/buttons/osk-toggle.js +++ b/devices/wim/config/ags/js/bar/buttons/osk-toggle.js @@ -1,13 +1,13 @@ import { Label } from 'resource:///com/github/Aylur/ags/widget.js'; import Tablet from '../../../services/tablet.js'; -import EventBox from '../../misc/cursorbox.js'; +import CursorBox from '../../misc/cursorbox.js'; -export default () => EventBox({ - className: 'toggle-off', +export default () => CursorBox({ + class_name: 'toggle-off', - onPrimaryClickRelease: () => Tablet.toggleOsk(), + on_primary_click_release: () => Tablet.toggleOsk(), child: Label({ class_name: 'osk-toggle', diff --git a/devices/wim/config/ags/js/bar/buttons/quick-settings.js b/devices/wim/config/ags/js/bar/buttons/quick-settings.js index dab23e2..a550967 100644 --- a/devices/wim/config/ags/js/bar/buttons/quick-settings.js +++ b/devices/wim/config/ags/js/bar/buttons/quick-settings.js @@ -8,20 +8,18 @@ import Brightness from './brightness.js'; import KeyboardLayout from './keyboard-layout.js'; import Network from './network.js'; -import EventBox from '../../misc/cursorbox.js'; +import CursorBox from '../../misc/cursorbox.js'; import Separator from '../../misc/separator.js'; const SPACING = 4; -export default () => EventBox({ - className: 'toggle-off', +export default () => CursorBox({ + class_name: 'toggle-off', - onHoverLost: () => { /**/ }, - - onPrimaryClickRelease: (self) => { + on_primary_click_release: (self) => { // @ts-expect-error - App.getWindow('notification-center').setXPos( + App.getWindow('notification-center').attribute.set_x_pos( self.get_allocation(), 'right', ); diff --git a/devices/wim/config/ags/js/bar/buttons/tablet-toggle.js b/devices/wim/config/ags/js/bar/buttons/tablet-toggle.js index b939e35..069cabb 100644 --- a/devices/wim/config/ags/js/bar/buttons/tablet-toggle.js +++ b/devices/wim/config/ags/js/bar/buttons/tablet-toggle.js @@ -1,13 +1,13 @@ import { Box, Label } from 'resource:///com/github/Aylur/ags/widget.js'; import Tablet from '../../../services/tablet.js'; -import EventBox from '../../misc/cursorbox.js'; +import CursorBox from '../../misc/cursorbox.js'; -export default () => EventBox({ +export default () => CursorBox({ class_name: 'toggle-off', - onPrimaryClickRelease: () => Tablet.toggleMode(), + on_primary_click_release: () => Tablet.toggleMode(), child: Box({ class_name: 'tablet-toggle', diff --git a/devices/wim/config/ags/js/bar/buttons/workspaces.js b/devices/wim/config/ags/js/bar/buttons/workspaces.js index d4522a5..5f664ee 100644 --- a/devices/wim/config/ags/js/bar/buttons/workspaces.js +++ b/devices/wim/config/ags/js/bar/buttons/workspaces.js @@ -3,7 +3,7 @@ import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.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'; +import CursorBox from '../../misc/cursorbox.js'; const URGENT_DURATION = 1000; @@ -16,10 +16,10 @@ const Workspace = ({ id }) => { transition: 'slide_right', attribute: { id }, - child: EventBox({ + child: CursorBox({ tooltipText: `${id}`, - onPrimaryClickRelease: () => { + on_primary_click_release: () => { Hyprland.sendMessage(`dispatch workspace ${id}`); }, @@ -84,7 +84,7 @@ export default () => { const updateHighlight = (self) => { const currentId = Hyprland.active.workspace.id; // @ts-expect-error - const indicators = self.get_parent().get_children()[0].child.children; + const indicators = self.get_parent().get_children()[0].child.child.children; const currentIndex = Array.from(indicators) .findIndex((w) => w.attribute.id === currentId); @@ -105,7 +105,7 @@ export default () => { const widget = Overlay({ pass_through: true, overlays: [highlight], - child: EventBox({ + child: CursorBox({ child: Box({ class_name: 'workspaces', diff --git a/devices/wim/config/ags/js/media-player/gesture.js b/devices/wim/config/ags/js/media-player/gesture.js index 60465f4..38a553c 100644 --- a/devices/wim/config/ags/js/media-player/gesture.js +++ b/devices/wim/config/ags/js/media-player/gesture.js @@ -1,7 +1,7 @@ import { timeout } from 'resource:///com/github/Aylur/ags/utils.js'; import { Box, EventBox, Overlay } from 'resource:///com/github/Aylur/ags/widget.js'; -import Gtk from 'gi://Gtk'; +const { Gtk } = imports.gi; const MAX_OFFSET = 200; const OFFSCREEN = 500; @@ -61,10 +61,9 @@ export default ({ setup(self); self - // @ts-expect-error .hook(gesture, (overlay, realGesture) => { if (realGesture) { - overlay.attribute.list().forEach((over) => { + Array.from(overlay.attribute.list()).forEach((over) => { over.visible = true; }); } diff --git a/devices/wim/config/ags/js/media-player/mpris.js b/devices/wim/config/ags/js/media-player/mpris.js index 2ad5daa..8913b4a 100644 --- a/devices/wim/config/ags/js/media-player/mpris.js +++ b/devices/wim/config/ags/js/media-player/mpris.js @@ -4,7 +4,7 @@ import { Button, Icon, Label, Stack, Slider, CenterBox, Box } from 'resource:/// import { execAsync, lookUpIcon, readFileAsync } from 'resource:///com/github/Aylur/ags/utils.js'; import Separator from '../misc/separator.js'; -import EventBox from '../misc/cursorbox.js'; +import CursorBox from '../misc/cursorbox.js'; /** * @typedef {import('types/service/mpris').MprisPlayer} Player @@ -137,10 +137,10 @@ export const PlayerIcon = (player, overlay) => { * @param {Overlay=} widget * @param {Overlay=} over */ - const playerIcon = (p, widget, over) => EventBox({ + const playerIcon = (p, widget, over) => CursorBox({ tooltip_text: p.identity || '', - onPrimaryClickRelease: () => { + on_primary_click_release: () => { widget?.attribute.moveToTop(over); }, @@ -223,7 +223,13 @@ export const PositionSlider = (player, colors) => Slider({ }, }); -const PlayerButton = ({ player, colors, items, onClick, prop }) => EventBox({ +const PlayerButton = ({ + player, + colors, + items, + onClick, + prop, +}) => CursorBox({ child: Button({ attribute: { hovered: false }, child: Stack({ items }), diff --git a/devices/wim/config/ags/js/misc/audio-icons.js b/devices/wim/config/ags/js/misc/audio-icons.js index ea416e7..561157f 100644 --- a/devices/wim/config/ags/js/misc/audio-icons.js +++ b/devices/wim/config/ags/js/misc/audio-icons.js @@ -17,13 +17,13 @@ const micIcons = { }; -export const SpeakerIcon = Variable(); +export const SpeakerIcon = Variable(''); Audio.connect('speaker-changed', () => { if (!Audio.speaker) { return; } - if (Audio.speaker.stream.isMuted) { + if (Audio.speaker.stream.is_muted) { SpeakerIcon.value = speakerIcons[0]; } else { @@ -37,13 +37,13 @@ Audio.connect('speaker-changed', () => { } }); -export const MicIcon = Variable(); +export const MicIcon = Variable(''); Audio.connect('microphone-changed', () => { if (!Audio.microphone) { return; } - if (Audio.microphone.stream.isMuted) { + if (Audio.microphone.stream.is_muted) { MicIcon.value = micIcons[0]; } else { diff --git a/devices/wim/config/ags/js/misc/closer.js b/devices/wim/config/ags/js/misc/closer.js index 39dc55f..e3de2c1 100644 --- a/devices/wim/config/ags/js/misc/closer.js +++ b/devices/wim/config/ags/js/misc/closer.js @@ -3,7 +3,10 @@ import App from 'resource:///com/github/Aylur/ags/app.js'; export default () => { Array.from(App.windows) - .filter((w) => w[1].closeOnUnfocus && w[1].closeOnUnfocus !== 'stay') + // @ts-expect-error + .filter((w) => w[1].attribute?.close_on_unfocus && + // @ts-expect-error + w[1].attribute?.close_on_unfocus !== 'stay') .forEach((w) => { App.closeWindow(w[0]); }); diff --git a/devices/wim/config/ags/js/misc/cursorbox.js b/devices/wim/config/ags/js/misc/cursorbox.js index d6643cb..511a74e 100644 --- a/devices/wim/config/ags/js/misc/cursorbox.js +++ b/devices/wim/config/ags/js/misc/cursorbox.js @@ -1,49 +1,38 @@ import Variable from 'resource:///com/github/Aylur/ags/variable.js'; -import { Button, EventBox } from 'resource:///com/github/Aylur/ags/widget.js'; +import { EventBox } from 'resource:///com/github/Aylur/ags/widget.js'; -import Gtk from 'gi://Gtk'; +const { Gtk } = imports.gi; // TODO: wrap in another EventBox for disabled cursor /** - * @typedef {import('types/widget.js').Widget} Widget - * @typedef {Widget & Object} CursorProps - * @property {boolean=} isButton - * @property {function(Widget):void=} onPrimaryClickRelease + * @typedef {import('types/widgets/eventbox').EventBoxProps} EventBox * - * @param {CursorProps} obj + * @param {EventBox & { + * on_primary_click_release?: function(EventBox):void + * }} o */ export default ({ - isButton = false, - - onPrimaryClickRelease = (self) => { - self; - }, + attribute, + on_primary_click_release = () => {/**/}, ...props }) => { // Make this variable to know if the function should // be executed depending on where the click is released const CanRun = Variable(true); + const Disabled = Variable(false); - let widgetFunc; - - if (isButton) { - widgetFunc = Button; - } - else { - widgetFunc = EventBox; - } - - const widget = widgetFunc({ + const widget = EventBox({ ...props, - cursor: 'pointer', + sensitive: Disabled.bind().transform((v) => !v), + on_primary_click_release: (self) => { // Every click, do a one shot connect to // CanRun to wait for location of click const id = CanRun.connect('changed', () => { if (CanRun.value) { - onPrimaryClickRelease(self); + on_primary_click_release(self); } CanRun.disconnect(id); @@ -51,9 +40,31 @@ export default ({ }, }); + const wrapper = EventBox({ + cursor: 'pointer', + + attribute: { + ...attribute, + + disabled: Disabled, + + get_child: () => widget.child, + + set_child: (new_child) => { + widget.child = new_child; + }, + }, + + child: widget, + + }).hook(Disabled, (self) => { + self.cursor = Disabled.value ? + 'not-allowed' : + 'pointer'; + }); + const gesture = Gtk.GestureLongPress.new(widget); - // @ts-expect-error widget.hook(gesture, () => { const pointer = gesture.get_point(null); const x = pointer[1]; @@ -69,5 +80,5 @@ export default ({ ); }, 'end'); - return widget; + return wrapper; }; diff --git a/devices/wim/config/ags/js/misc/popup.js b/devices/wim/config/ags/js/misc/popup.js index 85f3166..c2a5f48 100644 --- a/devices/wim/config/ags/js/misc/popup.js +++ b/devices/wim/config/ags/js/misc/popup.js @@ -4,24 +4,35 @@ import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; import { Revealer, Box, Window } from 'resource:///com/github/Aylur/ags/widget.js'; import { timeout } from 'resource:///com/github/Aylur/ags/utils.js'; +/** + * @typedef {import('types/widgets/revealer').RevealerProps} RevProp + * @typedef {import('types/widgets/window').WindowProps} WinProp + */ + +/** + * @param {WinProp & { + * transition?: RevProp['transition'] + * transition_duration?: RevProp['transition_duration'] + * onOpen?: function + * onClose?: function + * blur?: boolean + * close_on_unfocus?: 'none'|'stay'|'released'|'clicked' + * }} o + */ export default ({ - // Revealer props transition = 'slide_down', - transitionDuration = 500, - - // Optional: execute a function whenever - // the window pops up or goes away + transition_duration = 500, onOpen = () => { /**/ }, onClose = () => { /**/ }, // Window props name, child, - blur = false, - closeOnUnfocus = 'released', visible = false, layer = 'overlay', + blur = false, + close_on_unfocus = 'released', ...props }) => { const window = Window({ @@ -30,11 +41,49 @@ export default ({ visible: false, ...props, + attribute: { + set_x_pos: ( + alloc = {}, + side = 'right', + ) => { + const width = window.get_display() + .get_monitor_at_point(alloc.x, alloc.y) + .get_geometry().width; + + window.margins = [ + window.margins[0], + + side === 'right' ? + (width - alloc.x - alloc.width) : + window.margins[1], + + window.margins[2], + + side === 'right' ? + window.margins[3] : + (alloc.x - alloc.width), + ]; + }, + + // @ts-expect-error + get_child: () => window.child.children[0].child, + + set_child: (newChild) => { + // @ts-expect-error + window.child.children[0].child = newChild; + // @ts-expect-error + window.child.children[0].show_all(); + }, + + // This is for my custom pointers.js + close_on_unfocus, + }, + setup: () => { // Add way to make window open on startup const id = App.connect('config-parsed', () => { if (visible) { - App.openWindow(name); + App.openWindow(String(name)); } App.disconnect(id); }); @@ -56,18 +105,18 @@ export default ({ `, child: Revealer({ transition, - transitionDuration, + transition_duration, setup: (self) => { self.hook(App, (_, currentName, isOpen) => { if (currentName === name) { - self.revealChild = isOpen; + self.reveal_child = isOpen; if (isOpen) { onOpen(window); } else { - timeout(transitionDuration, () => { + timeout(Number(transition_duration), () => { onClose(window); }); } @@ -80,39 +129,5 @@ export default ({ }), }); - window.setXPos = ( - alloc, - side = 'right', - ) => { - const width = window.get_display() - .get_monitor_at_point(alloc.x, alloc.y) - .get_geometry().width; - - window.margins = [ - window.margins[0], - - side === 'right' ? - (width - alloc.x - alloc.width) : - window.margins[1], - - window.margins[2], - - side === 'right' ? - window.margins[3] : - (alloc.x - alloc.width), - ]; - }; - - // Make getting the original child passed in this - // function easier when making more code for the widget - window.getChild = () => window.child.children[0].child; - window.setChild = (newChild) => { - window.child.children[0].child = newChild; - window.child.children[0].show_all(); - }; - - // This is for my custom pointers.js - window.closeOnUnfocus = closeOnUnfocus; - return window; }; diff --git a/devices/wim/config/ags/js/misc/separator.js b/devices/wim/config/ags/js/misc/separator.js index 5cc17ed..9b194c2 100644 --- a/devices/wim/config/ags/js/misc/separator.js +++ b/devices/wim/config/ags/js/misc/separator.js @@ -1,6 +1,14 @@ import { Box } from 'resource:///com/github/Aylur/ags/widget.js'; +/** + * @param {number} size + * @param {{ + * vertical?: boolean + * css?: string + * props?: import('types/widgets/box').BoxProps + * }} o + */ export default (size, { vertical = false, css = '', diff --git a/devices/wim/config/ags/js/notifications/base.js b/devices/wim/config/ags/js/notifications/base.js index ff9f06b..3c1a1ce 100644 --- a/devices/wim/config/ags/js/notifications/base.js +++ b/devices/wim/config/ags/js/notifications/base.js @@ -18,7 +18,7 @@ const getDragState = (box) => box.get_parent().get_parent() .get_parent().get_parent().get_parent()._dragging; import Gesture from './gesture.js'; -import EventBox from '../misc/cursorbox.js'; +import CursorBox from '../misc/cursorbox.js'; const NotificationIcon = (notif) => { @@ -75,8 +75,8 @@ const NotificationIcon = (notif) => { } if (notif.image) { - return EventBox({ - onPrimaryClickRelease: iconCmd, + return CursorBox({ + on_primary_click_release: iconCmd, child: Box({ vpack: 'start', @@ -106,8 +106,8 @@ const NotificationIcon = (notif) => { } - return EventBox({ - onPrimaryClickRelease: iconCmd, + return CursorBox({ + on_primary_click_release: iconCmd, child: Box({ vpack: 'start', @@ -205,7 +205,7 @@ export const Notification = ({ }), // Close button - EventBox({ + CursorBox({ child: Button({ className: 'close-button', vpack: 'start', diff --git a/devices/wim/config/ags/js/notifications/center.js b/devices/wim/config/ags/js/notifications/center.js index e9288f7..e70be8f 100644 --- a/devices/wim/config/ags/js/notifications/center.js +++ b/devices/wim/config/ags/js/notifications/center.js @@ -5,7 +5,7 @@ import { Button, Label, Box, Icon, Scrollable, Revealer } from 'resource:///com/ import { timeout } from 'resource:///com/github/Aylur/ags/utils.js'; import { Notification, HasNotifs } from './base.js'; -import EventBox from '../misc/cursorbox.js'; +import CursorBox from '../misc/cursorbox.js'; const addNotif = (box, notif) => { @@ -55,7 +55,7 @@ const NotificationList = () => Box({ }); // Needs to be wrapped to still have onHover when disabled -const ClearButton = () => EventBox({ +const ClearButton = () => CursorBox({ child: Button({ onPrimaryClickRelease: () => { Notifications.clear(); diff --git a/devices/wim/config/ags/js/notifications/main.js b/devices/wim/config/ags/js/notifications/main.js index 29f343f..1528c4b 100644 --- a/devices/wim/config/ags/js/notifications/main.js +++ b/devices/wim/config/ags/js/notifications/main.js @@ -8,7 +8,7 @@ export const NotifPopups = () => PopupWindow({ anchor: ['top', 'left'], visible: true, transition: 'none', - closeOnUnfocus: 'stay', + close_on_unfocus: 'stay', child: PopUpsWidget(), }); diff --git a/devices/wim/config/ags/js/osd/main.js b/devices/wim/config/ags/js/osd/main.js index cc0edb6..3e0efe7 100644 --- a/devices/wim/config/ags/js/osd/main.js +++ b/devices/wim/config/ags/js/osd/main.js @@ -53,8 +53,8 @@ export default () => PopupWindow({ name: 'osd', anchor: ['bottom'], exclusivity: 'ignore', - closeOnUnfocus: 'stay', + close_on_unfocus: 'stay', transition: 'slide_up', - transitionDuration: 200, + transition_duration: 200, child: OSDs(), }); diff --git a/devices/wim/config/ags/js/overview/dragndrop.js b/devices/wim/config/ags/js/overview/dragndrop.js index 3240a61..73b0841 100644 --- a/devices/wim/config/ags/js/overview/dragndrop.js +++ b/devices/wim/config/ags/js/overview/dragndrop.js @@ -1,12 +1,10 @@ import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; -import { EventBox } from 'resource:///com/github/Aylur/ags/widget.js'; +import { Button, EventBox } from 'resource:///com/github/Aylur/ags/widget.js'; -import Gtk from 'gi://Gtk'; -import Gdk from 'gi://Gdk'; import Cairo from 'cairo'; +const { Gtk, Gdk } = imports.gi; -import Button from '../misc/cursorbox.js'; import { updateClients } from './clients.js'; const TARGET = [Gtk.TargetEntry.new('text/plain', Gtk.TargetFlags.SAME_APP, 0)]; @@ -58,10 +56,15 @@ export const WorkspaceDrop = (props) => EventBox({ }, }); -export const WindowButton = ({ address, mainBox, ...props } = {}) => Button({ - isButton: true, +export const WindowButton = ({ + address, + mainBox, + ...props +} = {}) => Button({ ...props, + cursor: 'pointer', + setup: (self) => { self.drag_source_set( Gdk.ModifierType.BUTTON1_MASK, diff --git a/devices/wim/config/ags/js/overview/main.js b/devices/wim/config/ags/js/overview/main.js index 6603cc3..1047599 100644 --- a/devices/wim/config/ags/js/overview/main.js +++ b/devices/wim/config/ags/js/overview/main.js @@ -93,15 +93,15 @@ export const Overview = () => { }; export default () => { - const window = PopupWindow({ + const win = PopupWindow({ name: 'overview', blur: true, - closeOnUnfocus: 'none', - onOpen: (win) => { - win.setChild(Overview()); - win.getChild().getChild().update(); + close_on_unfocus: 'none', + onOpen: () => { + win.attribute.set_child(Overview()); + win.attribute.get_child().getChild().update(); }, }); - return window; + return win; }; diff --git a/devices/wim/config/ags/js/powermenu.js b/devices/wim/config/ags/js/powermenu.js index bc1b6a4..520d1d1 100644 --- a/devices/wim/config/ags/js/powermenu.js +++ b/devices/wim/config/ags/js/powermenu.js @@ -4,17 +4,17 @@ import { CenterBox, Label } from 'resource:///com/github/Aylur/ags/widget.js'; import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js'; import PopupWindow from './misc/popup.js'; -import Button from './misc/cursorbox.js'; +import CursorBox from './misc/cursorbox.js'; const PowermenuWidget = () => CenterBox({ - className: 'powermenu', + class_name: 'powermenu', + // @ts-expect-error vertical: false, - startWidget: Button({ - isButton: true, - className: 'shutdown', - onPrimaryClickRelease: () => execAsync(['systemctl', 'poweroff']) + startWidget: CursorBox({ + class_name: 'shutdown', + on_primary_click_release: () => execAsync(['systemctl', 'poweroff']) .catch(print), child: Label({ @@ -22,10 +22,9 @@ const PowermenuWidget = () => CenterBox({ }), }), - centerWidget: Button({ - isButton: true, - className: 'reboot', - onPrimaryClickRelease: () => execAsync(['systemctl', 'reboot']) + centerWidget: CursorBox({ + class_name: 'reboot', + on_primary_click_release: () => execAsync(['systemctl', 'reboot']) .catch(print), child: Label({ @@ -33,10 +32,9 @@ const PowermenuWidget = () => CenterBox({ }), }), - endWidget: Button({ - isButton: true, - className: 'logout', - onPrimaryClickRelease: () => Hyprland.sendMessage('dispatch exit') + endWidget: CursorBox({ + class_name: 'logout', + on_primary_click_release: () => Hyprland.sendMessage('dispatch exit') .catch(print), child: Label({ diff --git a/devices/wim/config/ags/js/quick-settings/bluetooth.js b/devices/wim/config/ags/js/quick-settings/bluetooth.js index dbff22a..8785ef6 100644 --- a/devices/wim/config/ags/js/quick-settings/bluetooth.js +++ b/devices/wim/config/ags/js/quick-settings/bluetooth.js @@ -3,7 +3,7 @@ import Bluetooth from 'resource:///com/github/Aylur/ags/service/bluetooth.js'; import { Box, Icon, Label, ListBox, Overlay, Revealer, Scrollable } from 'resource:///com/github/Aylur/ags/widget.js'; -import EventBox from '../misc/cursorbox.js'; +import CursorBox from '../misc/cursorbox.js'; const SCROLL_THRESH_H = 200; const SCROLL_THRESH_N = 7; @@ -42,8 +42,8 @@ const BluetoothDevice = (dev) => { widget.add(Revealer({ revealChild: true, transition: 'slide_down', - child: EventBox({ - onPrimaryClickRelease: () => dev.setConnection(true), + child: CursorBox({ + on_primary_click_release: () => dev.setConnection(true), child, }), })); diff --git a/devices/wim/config/ags/js/quick-settings/button-grid.js b/devices/wim/config/ags/js/quick-settings/button-grid.js index 9d60194..b303973 100644 --- a/devices/wim/config/ags/js/quick-settings/button-grid.js +++ b/devices/wim/config/ags/js/quick-settings/button-grid.js @@ -7,7 +7,7 @@ import { Box, Icon, Label, Revealer } from 'resource:///com/github/Aylur/ags/wid import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js'; import { SpeakerIcon, MicIcon } from '../misc/audio-icons.js'; -import EventBox from '../misc/cursorbox.js'; +import CursorBox from '../misc/cursorbox.js'; import Separator from '../misc/separator.js'; import { NetworkMenu } from './network.js'; @@ -85,10 +85,10 @@ const GridButton = ({ className: 'grid-button', children: [ - EventBox({ + CursorBox({ className: 'left-part', - onPrimaryClickRelease: () => { + on_primary_click_release: () => { if (Activated.value) { secondaryCommand(); } @@ -100,10 +100,10 @@ const GridButton = ({ child: icon, }), - EventBox({ + CursorBox({ className: 'right-part', - onPrimaryClickRelease: () => { + on_primary_click_release: () => { ButtonStates.forEach((state) => { if (state !== Activated) { state.value = false; diff --git a/devices/wim/config/ags/js/quick-settings/network.js b/devices/wim/config/ags/js/quick-settings/network.js index 5d5182e..2895420 100644 --- a/devices/wim/config/ags/js/quick-settings/network.js +++ b/devices/wim/config/ags/js/quick-settings/network.js @@ -5,7 +5,7 @@ import Variable from 'resource:///com/github/Aylur/ags/variable.js'; import { Box, Icon, Label, ListBox, Overlay, Revealer, Scrollable } from 'resource:///com/github/Aylur/ags/widget.js'; import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js'; -import EventBox from '../misc/cursorbox.js'; +import CursorBox from '../misc/cursorbox.js'; const SCROLL_THRESH_H = 200; const SCROLL_THRESH_N = 7; @@ -60,8 +60,8 @@ const AccessPoint = (ap) => { widget.add(Revealer({ revealChild: true, transition: 'slide_down', - child: EventBox({ - onPrimaryClickRelease: () => { + child: CursorBox({ + on_primary_click_release: () => { execAsync(`nmcli device wifi connect ${widget.ap.value.bssid}`).catch(print); }, diff --git a/devices/wim/config/ags/services/pointers.js b/devices/wim/config/ags/services/pointers.js index c6911ba..62d3221 100644 --- a/devices/wim/config/ags/services/pointers.js +++ b/devices/wim/config/ags/services/pointers.js @@ -62,7 +62,7 @@ class Pointers extends Service { this.#getDevices(); this.#udevClient.connect('uevent', (_, action) => { if (action === 'add' || action === 'remove') { - this.getDevices(); + this.#getDevices(); if (this.#process) { this.killProc(); this.startProc(); @@ -139,9 +139,9 @@ class Pointers extends Service { #initAppConnection() { App.connect('window-toggled', () => { const anyVisibleAndClosable = Array.from(App.windows).some((w) => { - const closable = w[1].closeOnUnfocus && - !(w[1].closeOnUnfocus === 'none' || - w[1].closeOnUnfocus === 'stay'); + const closable = w[1].attribute?.close_on_unfocus && + !(w[1].attribute?.close_on_unfocus === 'none' || + w[1].attribute?.close_on_unfocus === 'stay'); return w[1].visible && closable; }); @@ -158,8 +158,8 @@ class Pointers extends Service { static detectClickedOutside(clickStage) { const toClose = Array.from(App.windows).some((w) => { - const closable = (w[1].closeOnUnfocus && - w[1].closeOnUnfocus === clickStage); + const closable = (w[1].attribute?.close_on_unfocus && + w[1].attribute?.close_on_unfocus === clickStage); return w[1].visible && closable; }); @@ -181,8 +181,8 @@ class Pointers extends Service { const widgets = key.levels['3'].filter((n) => { const window = App.getWindow(n.namespace); - return window?.closeOnUnfocus && - window?.closeOnUnfocus === clickStage; + return window?.attribute?.close_on_unfocus && + window?.attribute?.close_on_unfocus === clickStage; }); if (pos.x > bar?.x && pos.x < bar?.x + bar?.w &&