From 79bf05d9c99d04f4e93395de8d6477c8473eacaa Mon Sep 17 00:00:00 2001 From: Jas Singh Date: Sun, 11 Aug 2024 20:38:50 -0700 Subject: [PATCH] Hyprland scaling updates are now properly reflected without having to restart ags. (#113) --- modules/menus/DropdownMenu.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/menus/DropdownMenu.ts b/modules/menus/DropdownMenu.ts index ef3481b..411f3fe 100644 --- a/modules/menus/DropdownMenu.ts +++ b/modules/menus/DropdownMenu.ts @@ -1,6 +1,8 @@ const hyprland = await Service.import("hyprland"); import { globalMousePos } from "globals"; import { Exclusivity } from "lib/types/widget"; +import { bash } from "lib/utils"; +import { Monitor } from "types/service/hyprland"; export const Padding = (name: string) => Widget.EventBox({ @@ -16,11 +18,23 @@ const moveBoxToCursor = (self: any, fixed: boolean) => { return; } - globalMousePos.connect("changed", ({ value }) => { + globalMousePos.connect("changed", async ({ value }) => { const curHyprlandMonitor = hyprland.monitors.find(m => m.id === hyprland.active.monitor.id); const dropdownWidth = self.child.get_allocation().width; - const hyprScaling = curHyprlandMonitor?.scale; + let hyprScaling = 1; + try { + const monitorInfo = await bash('hyprctl monitors -j'); + const parsedMonitorInfo = JSON.parse(monitorInfo); + + const foundMonitor = parsedMonitorInfo.find((monitor: Monitor) => + monitor.id === hyprland.active.monitor.id + ); + hyprScaling = foundMonitor?.scale || 1; + } catch (error) { + console.error(`Error parsing hyprland monitors: ${error}`); + } + let monWidth = curHyprlandMonitor?.width; let monHeight = curHyprlandMonitor?.height;