Install Wnck session support helpers
This commit is contained in:
@@ -108,6 +108,7 @@ cthulhu_python_sources = files([
|
||||
'translation_manager.py',
|
||||
'tutorialgenerator.py',
|
||||
'typing_echo_presenter.py',
|
||||
'wnck_support.py',
|
||||
'where_am_i_presenter.py',
|
||||
])
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ from gi.repository import Atspi
|
||||
from cthulhu.plugin import Plugin, cthulhu_hookimpl
|
||||
from cthulhu import debug
|
||||
from cthulhu import settings_manager
|
||||
from cthulhu.wnck_support import load_wnck
|
||||
|
||||
# Note: Removed complex beep system - simple announcements work perfectly!
|
||||
|
||||
@@ -68,17 +69,18 @@ try:
|
||||
except ImportError:
|
||||
WEBCOLORS_AVAILABLE = False
|
||||
|
||||
# GTK/GDK/Wnck
|
||||
# GTK/GDK
|
||||
try:
|
||||
import gi
|
||||
gi.require_version("Gtk", "3.0")
|
||||
gi.require_version("Gdk", "3.0")
|
||||
gi.require_version("Wnck", "3.0")
|
||||
from gi.repository import Gtk, Gdk, Wnck
|
||||
from gi.repository import Gtk, Gdk
|
||||
GTK_AVAILABLE = True
|
||||
except ImportError:
|
||||
except Exception:
|
||||
GTK_AVAILABLE = False
|
||||
|
||||
Wnck = load_wnck()
|
||||
WNCK_AVAILABLE = Wnck is not None
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class OCRDesktop(Plugin):
|
||||
@@ -151,7 +153,7 @@ class OCRDesktop(Plugin):
|
||||
if not PYTESSERACT_AVAILABLE:
|
||||
missing_deps.append("python-pytesseract")
|
||||
if not GTK_AVAILABLE:
|
||||
missing_deps.append("GTK3/GDK/Wnck")
|
||||
missing_deps.append("GTK3/GDK")
|
||||
|
||||
if missing_deps:
|
||||
debug.printMessage(debug.LEVEL_INFO,
|
||||
@@ -359,6 +361,10 @@ class OCRDesktop(Plugin):
|
||||
if not GTK_AVAILABLE:
|
||||
debug.printMessage(debug.LEVEL_INFO, "OCRDesktop: GTK not available for screenshots", True)
|
||||
return False
|
||||
|
||||
if not WNCK_AVAILABLE:
|
||||
debug.printMessage(debug.LEVEL_INFO, "OCRDesktop: Wnck not available for active window screenshots", True)
|
||||
return False
|
||||
|
||||
try:
|
||||
time.sleep(0.3) # Brief delay
|
||||
@@ -869,4 +875,4 @@ class OCRDesktop(Plugin):
|
||||
return True
|
||||
except Exception as e:
|
||||
debug.printMessage(debug.LEVEL_INFO, f"OCRDesktop: Error copying to clipboard: {e}", True)
|
||||
return False
|
||||
return False
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (c) 2026 Stormux
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
"""Helpers for loading Wnck only when the session can support it."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import os
|
||||
from types import ModuleType
|
||||
|
||||
|
||||
def get_session_type() -> str:
|
||||
sessionType = (os.environ.get("XDG_SESSION_TYPE") or "").strip().lower()
|
||||
if sessionType:
|
||||
return sessionType
|
||||
if os.environ.get("WAYLAND_DISPLAY"):
|
||||
return "wayland"
|
||||
if os.environ.get("DISPLAY"):
|
||||
return "x11"
|
||||
return "unknown"
|
||||
|
||||
|
||||
def can_use_wnck(session_type: str | None = None) -> bool:
|
||||
return (session_type or get_session_type()).strip().lower() == "x11"
|
||||
|
||||
|
||||
def load_wnck(session_type: str | None = None) -> ModuleType | None:
|
||||
if not can_use_wnck(session_type):
|
||||
return None
|
||||
|
||||
gi = importlib.import_module("gi")
|
||||
gi.require_version("Wnck", "3.0")
|
||||
return importlib.import_module("gi.repository.Wnck")
|
||||
Reference in New Issue
Block a user