From 75d59aa06d5ad1d217f51856ffd34dd3ea8a8271 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Sun, 2 Aug 2026 13:37:10 +0545 Subject: [PATCH] refactor(globalmenu): reuse active-window service --- src/window/globalmenu/service.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/window/globalmenu/service.py b/src/window/globalmenu/service.py index a8770c8..1728040 100644 --- a/src/window/globalmenu/service.py +++ b/src/window/globalmenu/service.py @@ -1,6 +1,5 @@ """Global Menu Service — event-driven, persistent importer architecture.""" -import json import re import threading import time @@ -11,12 +10,12 @@ from fabric.core.service import Property, Service, Signal from fabric.utils import ( Gio, GLib, - exec_shell_command, idle_add, logger, os, ) +from services.modus import get_active_window from window.globalmenu.dbusmenu import DBusMenuClient, DBusMenuItem, _get_bus from window.globalmenu.environment import setup_global_menu_environment from window.globalmenu.gtkmenu import ActionMenuClient, GtkMenuClient @@ -319,14 +318,10 @@ class GlobalMenuService(Service): def update_active_window(self, app_name: str, wm_class: str): target_pid = 0 try: - out = exec_shell_command("hyprctl activewindow -j") - if out: - data = json.loads(out) - target_pid = data.get("pid", 0) + data = get_active_window() + target_pid = data.get("pid", 0) if data else 0 except Exception as e: - logger.warning( - f"[service] out = exec_shell_command('hyprctl activewindow -j') failed: {e}" - ) + logger.warning(f"[service] get_active_window() failed: {e}") with self._state_lock: same_class = wm_class == self._current_wm_class @@ -543,10 +538,10 @@ class GlobalMenuService(Service): ) -> Optional[_MenuClient]: try: if target_pid <= 0: - out = exec_shell_command("hyprctl activewindow -j") - if not out: + data = get_active_window() + if not data: return None - target_pid = json.loads(out).get("pid", 0) + target_pid = data.get("pid", 0) if target_pid <= 0: return None