mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-06-25 03:08:34 +02:00
dimmer: integration into main loop
Just for fun.
This commit is contained in:
parent
3aa4d9686c
commit
bfda96a86c
1 changed files with 23 additions and 10 deletions
33
bin/dimmer
33
bin/dimmer
|
@ -21,11 +21,8 @@ from Xlib.error import BadWindow
|
||||||
from Xlib.protocol.event import MapNotify
|
from Xlib.protocol.event import MapNotify
|
||||||
|
|
||||||
|
|
||||||
def watch_for_locker(locker):
|
def on_xevent(source, condition, xdisplay, locker):
|
||||||
xdisplay = display.Display()
|
while xdisplay.pending_events():
|
||||||
root = xdisplay.screen().root
|
|
||||||
root.change_attributes(event_mask=X.SubstructureNotifyMask)
|
|
||||||
while True:
|
|
||||||
event = xdisplay.next_event()
|
event = xdisplay.next_event()
|
||||||
if event.type != X.MapNotify:
|
if event.type != X.MapNotify:
|
||||||
continue
|
continue
|
||||||
|
@ -34,8 +31,9 @@ def watch_for_locker(locker):
|
||||||
except error.BadWindow:
|
except error.BadWindow:
|
||||||
continue
|
continue
|
||||||
if wmclass and wmclass[1] == locker:
|
if wmclass and wmclass[1] == locker:
|
||||||
GLib.idle_add(Gtk.main_quit)
|
Gtk.main_quit()
|
||||||
return
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def on_realize(widget):
|
def on_realize(widget):
|
||||||
|
@ -94,6 +92,7 @@ if __name__ == "__main__":
|
||||||
add("--locker", default="i3lock", help="quit if window class detected")
|
add("--locker", default="i3lock", help="quit if window class detected")
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
|
|
||||||
|
# Setup dimmer windows on each monitor
|
||||||
gdisplay = Gdk.Display.get_default()
|
gdisplay = Gdk.Display.get_default()
|
||||||
for i in range(gdisplay.get_n_monitors()):
|
for i in range(gdisplay.get_n_monitors()):
|
||||||
geom = gdisplay.get_monitor(i).get_geometry()
|
geom = gdisplay.get_monitor(i).get_geometry()
|
||||||
|
@ -114,8 +113,22 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
window.show_all()
|
window.show_all()
|
||||||
|
|
||||||
watcher = threading.Thread(
|
# Watch for locker window
|
||||||
target=watch_for_locker, args=(options.locker,), daemon=True
|
xdisplay = display.Display()
|
||||||
|
root = xdisplay.screen().root
|
||||||
|
root.change_attributes(event_mask=X.SubstructureNotifyMask)
|
||||||
|
channel = GLib.IOChannel.unix_new(xdisplay.fileno())
|
||||||
|
channel.set_encoding(None)
|
||||||
|
channel.set_buffered(False)
|
||||||
|
GLib.io_add_watch(
|
||||||
|
channel,
|
||||||
|
GLib.PRIORITY_DEFAULT,
|
||||||
|
GLib.IOCondition.IN,
|
||||||
|
on_xevent,
|
||||||
|
xdisplay,
|
||||||
|
options.locker,
|
||||||
)
|
)
|
||||||
watcher.start()
|
xdisplay.pending_events() # otherwise, socket is inactive
|
||||||
|
|
||||||
|
# Main loop
|
||||||
Gtk.main()
|
Gtk.main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue