Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions glass-config-init/glass_config_init/components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ components:
glass-animator: {"command": ["glass-animator"]}
glass-renderer: {"command": ["glass-renderer-wrapper.sh"], requires: [IG_WORLD_ALPHA]}
glass-islands: {"command": ["glass-islands"]}
glass-lock: {"command": ["glass-lock"]}
xkb: {"command": ["setxkbmap", "-model", "pc101", "-layout", "us"]}
root-cursor: {"command": ["xsetroot", "-cursor_name", "arrow"]}
panelterm:
Expand Down
6 changes: 4 additions & 2 deletions glass-config-init/glass_config_init/input.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ modes:

"KeyPress,XK_R": reload

"KeyPress,ItemKey,XK_U": {splash_unlock: {timeframe: 2.}}
"KeyPress,ItemKey,XK_L": {splash_lock: {timeframe: 2.}}
"KeyPress,ItemKey,XK_L": screen_lock

"KeyPress,ItemKey,XK_I": {splash_unlock: {timeframe: 2.}}
"KeyPress,ItemKey,XK_O": {splash_lock: {timeframe: 2.}}
"KeyPress,XK_space": rofi_mode

"KeyPress,XK_Escape": toggle_overlay
Expand Down
36 changes: 36 additions & 0 deletions glass-config-init/glass_config_init/lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
locker:
# Example configurations. Only one of these can be used at a time.
# All parameters are optional and here the default values are shown.
#
# i3:
# cmd: ["i3lock"]
# xscreensaver:
# cmd_daemon: ["xscreensaver", "-no-splash"]
# cmd_watch: ["xscreensaver-command", "--watch"]
# cmd_lock: ["xscreensaver-command", "-lock"]
# gnome:
# cmd: ["gnome-screensaver"]
# bus_name: "org.gnome.ScreenSaver"
# obj_path: "/org/gnome/ScreenSaver"
# mate:
# cmd: ["mate-screensaver"]
# bus_name: "org.gnome.ScreenSaver"
# obj_path: "/org/gnome/ScreenSaver"
# xfce:
# cmd: ["xfce4-screensaver"]
# bus_name: "org.xfce.ScreenSaver"
# obj_path: "/org/xfce/ScreenSaver"
# light:
# cmd: ["gnome-screensaver"]
# bus_name: "org.freedesktop.ScreenSaver"
# obj_path: "/org/freedesktop/ScreenSaver"

xscreensaver:

animation:
lock:
splash_lock:
timeframe: 2.
unlock:
splash_unlock:
timeframe: 2.
5 changes: 4 additions & 1 deletion glass-ghosts/glass_ghosts/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def __new__(cls, manager, window):
self.override_redirect = self.window.get_attributes().override_redirect

for name in self.window.keys():
self.properties.update(glass_ghosts.helpers.expand_property(self.window, name))
try:
self.properties.update(glass_ghosts.helpers.expand_property(self.window, name))
except Exception as e:
InfiniteGlass.DEBUG("property-disappeared", "Property disappeared: %s" % name)

self.under_deletion = False

Expand Down
2 changes: 1 addition & 1 deletion glass-lib/InfiniteGlass/mainloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def reader(_):
break
line = buffer[:nl+1]
buffer = buffer[nl+1:]
handler(fileobj, line.decode(errors="replace"))
handler(fd, line.decode(errors="replace"))
return reader

def add_process(self, pid, handler=None):
Expand Down
41 changes: 41 additions & 0 deletions glass-lock/glass_lock/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import InfiniteGlass

class Locker(object):
def __init__(self, display, config, **kw):
self.display = display
self.config = config
for k, v in kw.items():
setattr(self, k, v)

self.action_runner = InfiniteGlass.action.ActionRunner(
self.display)

@display.root.on(mask="StructureNotifyMask", client_type="IG_SCREEN_LOCK")
def ClientMessage(win, ev):
print("Received screen lock message")
self.lock_with_animation()

def lock_with_animation(self):
animation = self.config.get("animation", {}).get("lock")
if animation is not None:
self.action_runner.run(animation)
args = next(iter(animation.values()))
if args and "timeframe" in args:
self.display.mainloop.add_timeout(
args["timeframe"],
lambda timestamp: self.lock())
return
self.lock()

def lock(self):
raise NotImplemented

def unlocked(self):
self.display.root.send(
self.display.root,
"IG_SCREEN_UNLOCKED",
0)
self.display.flush()
animation = self.config.get("animation", {}).get("unlock")
if animation is not None:
self.action_runner.run(animation)
47 changes: 47 additions & 0 deletions glass-lock/glass_lock/base_dbus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from . import base
import time

try:
import dbus
except ImportError:
dbus = None

class LockerDBUS(base.Locker):
cmd = ["gnome-screensaver"]
bus_name = "org.gnome.ScreenSaver"
obj_path = "/org/gnome/ScreenSaver"

def __init__(self, *arg, **kw):
base.Locker.__init__(self, *arg, **kw)
self.session = dbus.SessionBus()
self.ensure_dbus_locker_running()

def ensure_dbus_locker_running(self):
dbus_iface = dbus.Interface(
self.session.get_object(
"org.freedesktop.DBus",
"/org/freedesktop/DBus"),
"org.freedesktop.DBus")

if not dbus_iface.NameHasOwner(self.bus_name):
subprocess.Popen(self.cmd)
for _ in range(20):
if dbus_iface.NameHasOwner(self.bus_name):
return
time.sleep(0.1)
raise Exception("Unable to start locker %s" % self)

def active_changed(self, active):
if not active:
self.unlocked()

def lock(self):
iface = dbus.Interface(
self.session.get_object(self.bus_name, self.obj_path),
"org.freedesktop.ScreenSaver")
session.add_signal_receiver(
self.active_changed,
signal_name="ActiveChanged",
dbus_interface="org.freedesktop.ScreenSaver"
)
iface.Lock()
39 changes: 39 additions & 0 deletions glass-lock/glass_lock/cmdlockers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from . import base
import subprocess


class LockerI3(base.Locker):
cmd = ["i3lock"]

def lock(self):
proc = subprocess.Popen(self.cmd)
@self.display.mainloop.add_process(pid=proc.pid)
def child_exit(retcode):
self.unlocked()


class LockerXScreensaver(base.Locker):
cmd_daemon = ["xscreensaver", "-no-splash"]
cmd_watch = ["xscreensaver-command", "--watch"]
cmd_lock = ["xscreensaver-command", "-lock"]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.daemon = subprocess.Popen(
self.cmd_daemon)

self.watch = subprocess.Popen(
self.cmd_watch,
stdout=subprocess.PIPE,
text=True,
)

@self.display.mainloop.add_lines(self.watch.stdout.fileno())
def xscreensaver_watch(fd, line):
if "UNBLANK" in line:
self.unlocked()

def lock(self):
subprocess.run(self.cmd_lock)

21 changes: 21 additions & 0 deletions glass-lock/glass_lock/dbus_lockers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from . import base_dbus

class LockerGnome(base_dbus.LockerDBUS):
cmd = ["gnome-screensaver"]
bus_name = "org.gnome.ScreenSaver"
obj_path = "/org/gnome/ScreenSaver"

class LockerMate(base_dbus.LockerDBUS):
cmd = ["mate-screensaver"]
bus_name = "org.gnome.ScreenSaver"
obj_path = "/org/gnome/ScreenSaver"

class LockerXfce4(base_dbus.LockerDBUS):
cmd = ["xfce4-screensaver"]
bus_name = "org.xfce.ScreenSaver"
obj_path = "/org/xfce/ScreenSaver"

class LockerLight(base_dbus.LockerDBUS):
cmd = ["gnome-screensaver"]
bus_name = "org.freedesktop.ScreenSaver"
obj_path = "/org/freedesktop/ScreenSaver"
36 changes: 36 additions & 0 deletions glass-lock/glass_lock/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3
import os
import subprocess
import sys
import importlib.metadata
import InfiniteGlass
import Xlib

def screen_lock(self, **kw):
print("Sending screen lock message")
self.display.root.send(
self.display.root, "IG_SCREEN_LOCK", 0,
event_mask=Xlib.X.StructureNotifyMask)

@InfiniteGlass.profilable
def main(*arg, **kw):

with InfiniteGlass.Display() as display:
configpath = os.path.expanduser(
os.environ.get("GLASS_WIDGET_CONFIG", "~/.config/glass/lock.yml")
)

with open(configpath) as f:
config = InfiniteGlass.load_yaml(f, display)

locker_name, locker_args = next(iter(config["locker"].items()))
locker_args = locker_args or {}
LockerCls = importlib.metadata.entry_points(
group="InfiniteGlass.lockers")[locker_name].load()

LockerCls(
display, config, **locker_args)


if __name__ == "__main__":
main()
33 changes: 33 additions & 0 deletions glass-lock/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python

import setuptools

setuptools.setup(name='glass-lock',
version='0.1',
description='Screen locker controller for InfiniteGlass',
long_description='Wraps various types of screen lockers in a standard protocol for lock/unlock.',
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",
],
entry_points={
'console_scripts': [
'glass-lock = glass_lock.main:main',
],
'InfiniteGlass.actions': [
"screen_lock = glass_lock.main:screen_lock",
],
'InfiniteGlass.lockers': [
"i3 = glass_lock.cmdlockers:LockerI3",
"xscreensaver = glass_lock.cmdlockers:LockerXScreensaver",
"gnome = glass_lock.dbus_lockers:LockerGnome",
"mate = glass_lock.dbus_lockers:LockerMate",
"xfce = glass_lock.dbus_lockers:LockerXfce4",
"light = glass_lock.dbus_lockers:LockerLight",
]
}
)
4 changes: 2 additions & 2 deletions glass-theme/glass_theme/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def activate(self):
root_IG_VIEWS = ["IG_VIEW_ROOT",
"IG_VIEW_DESKTOP",
"IG_VIEW_OVERLAY",
"IG_VIEW_MENU",
"IG_VIEW_SPLASH_BACKGROUND",
"IG_VIEW_SPLASH"]
"IG_VIEW_SPLASH",
"IG_VIEW_MENU"]

root_IG_COLOR_TRANSFORM = 1

Expand Down
Loading