refactor(globalmenu): reuse active-window service
This commit is contained in:
1 file changed
+7
-12
@@ -1,6 +1,5 @@
|
|||||||
"""Global Menu Service — event-driven, persistent importer architecture."""
|
"""Global Menu Service — event-driven, persistent importer architecture."""
|
||||||
|
|
||||||
import json
|
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
@@ -11,12 +10,12 @@ from fabric.core.service import Property, Service, Signal
|
|||||||
from fabric.utils import (
|
from fabric.utils import (
|
||||||
Gio,
|
Gio,
|
||||||
GLib,
|
GLib,
|
||||||
exec_shell_command,
|
|
||||||
idle_add,
|
idle_add,
|
||||||
logger,
|
logger,
|
||||||
os,
|
os,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from services.modus import get_active_window
|
||||||
from window.globalmenu.dbusmenu import DBusMenuClient, DBusMenuItem, _get_bus
|
from window.globalmenu.dbusmenu import DBusMenuClient, DBusMenuItem, _get_bus
|
||||||
from window.globalmenu.environment import setup_global_menu_environment
|
from window.globalmenu.environment import setup_global_menu_environment
|
||||||
from window.globalmenu.gtkmenu import ActionMenuClient, GtkMenuClient
|
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):
|
def update_active_window(self, app_name: str, wm_class: str):
|
||||||
target_pid = 0
|
target_pid = 0
|
||||||
try:
|
try:
|
||||||
out = exec_shell_command("hyprctl activewindow -j")
|
data = get_active_window()
|
||||||
if out:
|
target_pid = data.get("pid", 0) if data else 0
|
||||||
data = json.loads(out)
|
|
||||||
target_pid = data.get("pid", 0)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(
|
logger.warning(f"[service] get_active_window() failed: {e}")
|
||||||
f"[service] out = exec_shell_command('hyprctl activewindow -j') failed: {e}"
|
|
||||||
)
|
|
||||||
|
|
||||||
with self._state_lock:
|
with self._state_lock:
|
||||||
same_class = wm_class == self._current_wm_class
|
same_class = wm_class == self._current_wm_class
|
||||||
@@ -543,10 +538,10 @@ class GlobalMenuService(Service):
|
|||||||
) -> Optional[_MenuClient]:
|
) -> Optional[_MenuClient]:
|
||||||
try:
|
try:
|
||||||
if target_pid <= 0:
|
if target_pid <= 0:
|
||||||
out = exec_shell_command("hyprctl activewindow -j")
|
data = get_active_window()
|
||||||
if not out:
|
if not data:
|
||||||
return None
|
return None
|
||||||
target_pid = json.loads(out).get("pid", 0)
|
target_pid = data.get("pid", 0)
|
||||||
if target_pid <= 0:
|
if target_pid <= 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user