Skip to content

Commit 8e8ed0a

Browse files
committed
oh hey it's that thing I said in my patreon update
This commit was sponsored by Seth Larson, Quentin Pradet, zts, and my other patrons. If you want to join them, you can support my work at https://glyph.im/patrons/.
1 parent dbee759 commit 8e8ed0a

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

src/pomodouroboros/linux/gtk_progress_bar.py

+44-5
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757
from cairo import Region # type:ignore
5858

5959

60-
def makeOneProgressBar(display: Gdk.Display, monitor: Gdk.Monitor, ewmh: EWMH) -> None:
60+
def makeOneProgressBar(
61+
display: Gdk.Display, monitor: Gdk.Monitor, ewmh: EWMH
62+
) -> Gtk.ApplicationWindow:
6163
win = Gtk.ApplicationWindow(application=app, title="Should Never Focus")
6264
win.set_opacity(0.25)
6365
win.set_decorated(False)
@@ -75,6 +77,7 @@ def refraction() -> bool:
7577
frac %= 1.0
7678
prog.set_fraction(frac)
7779
return True
80+
7881
to = GLib.timeout_add((1000 // 10), refraction)
7982
prog.set_fraction(0.7)
8083
win.set_child(prog)
@@ -96,8 +99,14 @@ def refraction() -> bool:
9699
xlibwin = display.create_resource_object("window", xid)
97100

98101
# Always on top
99-
print(f'moving to {monitor_geom.x} {monitor_geom.y} {monitor_geom.width}')
100-
ewmh.setMoveResizeWindow(xlibwin, x=monitor_geom.x, y=monitor_geom.y + (monitor_geom.height - 150), w=monitor_geom.width, h=150)
102+
print(f"moving to {monitor_geom.x} {monitor_geom.y} {monitor_geom.width}")
103+
ewmh.setMoveResizeWindow(
104+
xlibwin,
105+
x=monitor_geom.x,
106+
y=monitor_geom.y + (monitor_geom.height - 150),
107+
w=monitor_geom.width,
108+
h=150,
109+
)
101110
ewmh.setWmState(xlibwin, 1, "_NET_WM_STATE_ABOVE")
102111

103112
# Draw even over the task bar (this breaks stuff)
@@ -107,6 +116,8 @@ def refraction() -> bool:
107116
ewmh.setWmState(xlibwin, 1, "_NET_WM_STATE_SKIP_TASKBAR")
108117
ewmh.setWmState(xlibwin, 1, "_NET_WM_STATE_SKIP_PAGER")
109118
display.flush()
119+
return win
120+
110121

111122
# When the application is launched…
112123
def on_activate(app: Gtk.Application) -> None:
@@ -119,8 +130,36 @@ def on_activate(app: Gtk.Application) -> None:
119130
display = XOpenDisplay()
120131
screen = display.screen()
121132
ewmh = EWMH(display, screen.root)
122-
for monitor in gdisplay.get_monitors():
123-
makeOneProgressBar(display, monitor, ewmh)
133+
bars: list[Gtk.ApplicationWindow] = []
134+
135+
def remonitor() -> bool:
136+
print("remonitoring")
137+
prevbars = bars[:]
138+
for monitor in gdisplay.get_monitors():
139+
bars.append(makeOneProgressBar(display, monitor, ewmh))
140+
for prevbar in prevbars:
141+
prevbar.close()
142+
return False
143+
144+
def remonitor_later(
145+
display: str,
146+
path: str,
147+
iface: str,
148+
signal: str,
149+
args: tuple[object, ...],
150+
) -> None:
151+
print("remonitoring...", display)
152+
GLib.timeout_add(1000, remonitor)
153+
154+
from pydbus import SessionBus
155+
156+
bus = SessionBus()
157+
bus.subscribe(
158+
iface="org.gnome.Mutter.DisplayConfig",
159+
signal="MonitorsChanged",
160+
signal_fired=remonitor_later,
161+
)
162+
remonitor()
124163

125164

126165
if __name__ == "__main__":

0 commit comments

Comments
 (0)