From cda55d6d489b689a3462919bfb702c01ebb0375e Mon Sep 17 00:00:00 2001 From: Egil Date: Fri, 17 May 2024 00:18:45 +0200 Subject: [PATCH] Separated glass-ghosts and glass-components --- .../glass_components}/components.py | 15 +++-- glass-components/glass_components/main.py | 59 +++++++++++++++++++ glass-components/setup.py | 25 ++++++++ .../glass_config_init/components.yml | 14 +++++ .../glass_config_init/ghosts.yml | 13 ---- glass-ghosts/glass_ghosts/main.py | 9 --- glass-ghosts/glass_ghosts/manager.py | 2 - scripts/xinitrc | 2 +- 8 files changed, 109 insertions(+), 30 deletions(-) rename {glass-ghosts/glass_ghosts => glass-components/glass_components}/components.py (89%) create mode 100644 glass-components/glass_components/main.py create mode 100644 glass-components/setup.py create mode 100644 glass-config-init/glass_config_init/components.yml diff --git a/glass-ghosts/glass_ghosts/components.py b/glass-components/glass_components/components.py similarity index 89% rename from glass-ghosts/glass_ghosts/components.py rename to glass-components/glass_components/components.py index 2aa0e87..d1e67a6 100644 --- a/glass-ghosts/glass_ghosts/components.py +++ b/glass-components/glass_components/components.py @@ -3,29 +3,34 @@ import glass_ghosts.ghost import glass_ghosts.window import json +import yaml import os import signal import traceback import time class Components(object): - def __init__(self, manager, display, restart_components=True, **kw): - self.manager = manager + def __init__(self, display, **kw): self.display = display + + configpath = os.path.expanduser(os.environ.get("GLASS_GHOSTS_CONFIG", "~/.config/glass/components.yml")) + with open(configpath) as f: + self.config = json.loads(json.dumps(yaml.load(f, Loader=yaml.SafeLoader)), object_hook=InfiniteGlass.fromjson(self.display)) + self.components = {} self.components_by_pid = {} - self.restart_components = restart_components + self.restart_components = self.config.get("restart_components", True) self.old_sigchld = signal.signal(signal.SIGCHLD, self.sigchild) @display.root.on() def PropertyNotify(win, event): - name = self.manager.display.get_atom_name(event.atom) + name = self.display.get_atom_name(event.atom) if name.startswith("IG_COMPONENT_"): spec = json.loads(display.root[name].decode("utf-8")) self.start_component(spec) - for name, spec in self.manager.config.get("components", {}).items(): + for name, spec in self.config.get("components", {}).items(): spec["name"] = name display.root["IG_COMPONENT_" + name] = json.dumps(spec).encode("utf-8") diff --git a/glass-components/glass_components/main.py b/glass-components/glass_components/main.py new file mode 100644 index 0000000..5d0cd51 --- /dev/null +++ b/glass-components/glass_components/main.py @@ -0,0 +1,59 @@ +import InfiniteGlass +import glass_components.components +import distutils.spawn +import sys +import traceback +import signal +import os +import time +import click + +if os.environ.get("GLASS_DEBUGGER", "") == "rpdb": + import rpdb + rpdb.handle_trap() + rpdb.handle_trap() + +def substring_in_list(s, lst): + for item in lst: + if s in item: + return True + return False + +def setup_annotator(): + preloads = [] + if "LD_PRELOAD" in os.environ: + preloads = os.environ["LD_PRELOAD"].split(" ") + if not substring_in_list('glass-annotator', preloads): + preloads.append(distutils.spawn.find_executable('glass-annotator')) + os.environ["LD_PRELOAD"] = " ".join(preloads) + +@click.command() +@InfiniteGlass.profilable +def main(**kw): + setup_annotator() + manager = None + try: + with InfiniteGlass.Display() as display: + overlay = display.root.composite_get_overlay_window().overlay_window + overlay_geom = overlay.get_geometry() + + gc = overlay.create_gc( + foreground = display.screen().black_pixel, + background = display.screen().white_pixel) + overlay.rectangle(gc, 0, 0, overlay_geom.width, overlay_geom.height, onerror = None) + + components = glass_components.components.Components(display, **kw) + + manager.components.shutdown() + except Exception as e: + print("Components manager systemic failure, restarting: %s" % (e,)) + traceback.print_exc() + try: + if manager is not None and hasattr(manager, "components") and hasattr(manager.components, "components_by_pid"): + for pid in manager.components.components_by_pid.keys(): + os.kill(pid, signal.SIGINT) + except Exception as e: + print(e) + traceback.print_exc() + os.execlp(sys.argv[0], *sys.argv) + print("END") diff --git a/glass-components/setup.py b/glass-components/setup.py new file mode 100644 index 0000000..98c8a24 --- /dev/null +++ b/glass-components/setup.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +import setuptools + +setuptools.setup(name='glass-components', + version='0.1', + description='Components manager for InfiniteGlass', + long_description='Components manager for InfiniteGlass', + long_description_content_type="text/markdown", + author='Egil Moeller', + author_email='redhog@redhog.org', + url='https://github.com/redhog/InfiniteGlass', + packages=setuptools.find_packages(), + install_requires=[ + "click", + "pyyaml", + "python-slugify", + "rpdb" + ], + entry_points={ + 'console_scripts': [ + 'glass-components = glass_components.main:main', + ], + } + ) diff --git a/glass-config-init/glass_config_init/components.yml b/glass-config-init/glass_config_init/components.yml new file mode 100644 index 0000000..1276ce6 --- /dev/null +++ b/glass-config-init/glass_config_init/components.yml @@ -0,0 +1,14 @@ +restart_components: true + +components: + glass-input: {"command": ["glass-input"]} + glass-theme: {"command": ["glass-theme"]} + glass-widgets: {"command": ["glass-widgets"]} + glass-animator: {"command": ["glass-animator"]} + glass-renderer: {"command": ["glass-renderer-wrapper.sh"]} + glass-islands: {"command": ["glass-islands"]} + xkb: {"command": ["setxkbmap", "-model", "pc101", "-layout", "us"]} + root-cursor: {"command": ["xsetroot", "-cursor_name", "arrow"]} + panelterm: + command: ["xterm", "-title", "panelterm", "-xrm", "XTerm.vt100.allowTitleOps: false"] + environment: { "IG_APP_ID": "panelterm" } diff --git a/glass-config-init/glass_config_init/ghosts.yml b/glass-config-init/glass_config_init/ghosts.yml index d783722..62d108a 100644 --- a/glass-config-init/glass_config_init/ghosts.yml +++ b/glass-config-init/glass_config_init/ghosts.yml @@ -60,19 +60,6 @@ ghost_update: - IG_COORDS - IG_SIZE -components: - glass-input: {"command": ["glass-input"]} - glass-theme: {"command": ["glass-theme"]} - glass-widgets: {"command": ["glass-widgets"]} - glass-animator: {"command": ["glass-animator"]} - glass-renderer: {"command": ["glass-renderer-wrapper.sh"]} - glass-islands: {"command": ["glass-islands"]} - xkb: {"command": ["setxkbmap", "-model", "pc101", "-layout", "us"]} - root-cursor: {"command": ["xsetroot", "-cursor_name", "arrow"]} - panelterm: - command: ["xterm", "-title", "panelterm", "-xrm", "XTerm.vt100.allowTitleOps: false"] - environment: { "IG_APP_ID": "panelterm" } - # Match windows against these templates (using regexps against their # keys) and set the templated properties on them when they first # appear. This is particularly useful to set WM_COMMAND to be able to diff --git a/glass-ghosts/glass_ghosts/main.py b/glass-ghosts/glass_ghosts/main.py index b7d6a16..0efc203 100644 --- a/glass-ghosts/glass_ghosts/main.py +++ b/glass-ghosts/glass_ghosts/main.py @@ -29,7 +29,6 @@ def setup_annotator(): os.environ["LD_PRELOAD"] = " ".join(preloads) @click.command() -@click.option('--restart-components/--no-restart-components', default=True) @InfiniteGlass.profilable def main(**kw): setup_annotator() @@ -48,16 +47,8 @@ def main(**kw): sys.stdout.write("%s\n" % manager.session.listen_address()) sys.stdout.flush() InfiniteGlass.DEBUG("init", "Session manager listening to %s\n" % manager.session.listen_address()) - manager.components.shutdown() except Exception as e: print("Ghost manager systemic failure, restarting: %s" % (e,)) traceback.print_exc() - try: - if manager is not None and hasattr(manager, "components") and hasattr(manager.components, "components_by_pid"): - for pid in manager.components.components_by_pid.keys(): - os.kill(pid, signal.SIGINT) - except Exception as e: - print(e) - traceback.print_exc() os.execlp(sys.argv[0], *sys.argv) print("END") diff --git a/glass-ghosts/glass_ghosts/manager.py b/glass-ghosts/glass_ghosts/manager.py index dba1f6d..bffeadd 100644 --- a/glass-ghosts/glass_ghosts/manager.py +++ b/glass-ghosts/glass_ghosts/manager.py @@ -8,7 +8,6 @@ import glass_ghosts.ghost import glass_ghosts.window import glass_ghosts.rootwindow -import glass_ghosts.components import glass_ghosts.session import pkg_resources import sys @@ -44,7 +43,6 @@ def __init__(self, display, **kw): self.session = glass_ghosts.session.Server(self, display, **kw) self.rootwindow = glass_ghosts.rootwindow.RootWindow(self, display, **kw) - self.components = glass_ghosts.components.Components(self, display, **kw) display.mainloop.add_interval(0.5)(self.save_ghosts) diff --git a/scripts/xinitrc b/scripts/xinitrc index 3b98954..41fb209 100644 --- a/scripts/xinitrc +++ b/scripts/xinitrc @@ -16,4 +16,4 @@ if [ -e ~/.config/glass/session.sh ]; then fi glass-config-init -glass-ghosts $GLASS_GHOSTS_OPTIONS +glass-components