mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-06-24 18:58:33 +02:00
xsecurelock: only display clock and weather on one screen
Relying on position is weak. Use an abstract Unix socket to take some kind of lock and declare a leader.
This commit is contained in:
parent
943445d31f
commit
8fbc2560df
1 changed files with 16 additions and 2 deletions
|
@ -22,6 +22,7 @@ import types
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
import re
|
||||||
import gi
|
import gi
|
||||||
|
import socket
|
||||||
|
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
from gi.repository import Gtk, Gdk, GdkX11, GLib, GdkPixbuf, Gio
|
from gi.repository import Gtk, Gdk, GdkX11, GLib, GdkPixbuf, Gio
|
||||||
|
@ -68,6 +69,8 @@ def on_win_draw(widget, cctx, ctx):
|
||||||
|
|
||||||
def on_overlay_draw(widget, cctx, ctx):
|
def on_overlay_draw(widget, cctx, ctx):
|
||||||
"""Draw overlay (clock and weather)."""
|
"""Draw overlay (clock and weather)."""
|
||||||
|
if not ctx.leader:
|
||||||
|
return
|
||||||
wwidth, wheight = widget.get_parent().get_size()
|
wwidth, wheight = widget.get_parent().get_size()
|
||||||
cctx.set_operator(cairo.OPERATOR_OVER)
|
cctx.set_operator(cairo.OPERATOR_OVER)
|
||||||
|
|
||||||
|
@ -106,7 +109,7 @@ def on_overlay_draw(widget, cctx, ctx):
|
||||||
# We can have polybar markups in it. We assume %{Tx} means to use
|
# We can have polybar markups in it. We assume %{Tx} means to use
|
||||||
# Font Awesome 6 and we ignore font color change. The parsing is
|
# Font Awesome 6 and we ignore font color change. The parsing is
|
||||||
# quite basic.
|
# quite basic.
|
||||||
if ctx.weather and ctx.position == (0, 0):
|
if ctx.weather:
|
||||||
data = re.sub(r"%{F[#\d+-]+?}", "", ctx.weather)
|
data = re.sub(r"%{F[#\d+-]+?}", "", ctx.weather)
|
||||||
data = re.split(r"(%{T[1-9-]})", data)
|
data = re.split(r"(%{T[1-9-]})", data)
|
||||||
font = ctx.font_family
|
font = ctx.font_family
|
||||||
|
@ -156,7 +159,17 @@ def on_clock_change(ctx):
|
||||||
if new_clock != ctx.clock:
|
if new_clock != ctx.clock:
|
||||||
ctx.clock = (new_clock, now.strftime("%A %-d %B"))
|
ctx.clock = (new_clock, now.strftime("%A %-d %B"))
|
||||||
ctx.overlay.queue_draw()
|
ctx.overlay.queue_draw()
|
||||||
GLib.timeout_add(min(60 - now.second, 3) * 1000, on_clock_change, ctx)
|
if ctx.leader is None:
|
||||||
|
# Do leader "election"
|
||||||
|
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
|
try:
|
||||||
|
s.bind("\0xsecurelock-saver")
|
||||||
|
except OSError:
|
||||||
|
ctx.leader = False
|
||||||
|
else:
|
||||||
|
ctx.leader = s
|
||||||
|
if ctx.leader:
|
||||||
|
GLib.timeout_add(min(60 - now.second, 3) * 1000, on_clock_change, ctx)
|
||||||
|
|
||||||
|
|
||||||
def on_weather_change(monitor, f1, f2, event, ctx):
|
def on_weather_change(monitor, f1, f2, event, ctx):
|
||||||
|
@ -185,6 +198,7 @@ if __name__ == "__main__":
|
||||||
ctx.weather = None
|
ctx.weather = None
|
||||||
ctx.clock = None
|
ctx.clock = None
|
||||||
ctx.position = (0, 0)
|
ctx.position = (0, 0)
|
||||||
|
ctx.leader = None
|
||||||
|
|
||||||
ctx.window = Gtk.Window()
|
ctx.window = Gtk.Window()
|
||||||
ctx.window.set_app_paintable(True)
|
ctx.window.set_app_paintable(True)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue