Skip to content

Commit

Permalink
Separated glass-ghosts and glass-components
Browse files Browse the repository at this point in the history
  • Loading branch information
Egil committed May 16, 2024
1 parent a829296 commit cda55d6
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
59 changes: 59 additions & 0 deletions glass-components/glass_components/main.py
Original file line number Diff line number Diff line change
@@ -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")
25 changes: 25 additions & 0 deletions glass-components/setup.py
Original file line number Diff line number Diff line change
@@ -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='[email protected]',
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',
],
}
)
14 changes: 14 additions & 0 deletions glass-config-init/glass_config_init/components.yml
Original file line number Diff line number Diff line change
@@ -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" }
13 changes: 0 additions & 13 deletions glass-config-init/glass_config_init/ghosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions glass-ghosts/glass_ghosts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
2 changes: 0 additions & 2 deletions glass-ghosts/glass_ghosts/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion scripts/xinitrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ if [ -e ~/.config/glass/session.sh ]; then
fi

glass-config-init
glass-ghosts $GLASS_GHOSTS_OPTIONS
glass-components

0 comments on commit cda55d6

Please sign in to comment.