Skip to content

Commit f92d408

Browse files
committed
compute geometry separately for each monitor
This commit was sponsored by Brian Grohe, tdsmith, and my other patrons. If you want to join them, you can support my work at https://glyph.im/patrons/.
1 parent fb2ee58 commit f92d408

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

src/pomodouroboros/linux/gtk_progress_bar.py

+29-24
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@
3333

3434
css.load_from_data(
3535
"""
36-
progressbar text {
36+
progressbar.overlay text {
3737
color: yellow;
3838
font-weight: bold;
3939
}
40-
progressbar trough, progress {
40+
progressbar.overlay trough, progress {
4141
min-height: 100px;
4242
}
43-
progressbar progress {
43+
progressbar.pomodoro progress {
4444
background-image: none;
45-
background-color: #f00;
45+
background-color: #0f0;
4646
}
47-
progressbar trough {
47+
progressbar.pomodoro trough {
4848
background-image: none;
49-
background-color: #0f0;
49+
background-color: #00f;
5050
}
5151
"""
5252
)
@@ -57,16 +57,16 @@
5757
from cairo import Region # type:ignore
5858

5959

60-
# When the application is launched…
61-
def on_activate(app: Gtk.Application) -> None:
62-
# … create a new window…
60+
def makeOneProgressBar(display: Gdk.Display, monitor: Gdk.Monitor, ewmh: EWMH) -> None:
6361
win = Gtk.ApplicationWindow(application=app, title="Should Never Focus")
6462
win.set_opacity(0.25)
6563
win.set_decorated(False)
66-
win.set_default_size(2000, 100)
67-
# … with a button in it…
68-
# btn = Gtk.Button(label="Hello, World!")
64+
monitor_geom = monitor.get_geometry()
65+
win.set_default_size(monitor_geom.width, 100)
66+
6967
prog = Gtk.ProgressBar()
68+
prog.add_css_class("pomodoro")
69+
prog.add_css_class("overlay")
7070
frac = 0.7
7171

7272
def refraction() -> bool:
@@ -75,17 +75,9 @@ def refraction() -> bool:
7575
frac %= 1.0
7676
prog.set_fraction(frac)
7777
return True
78-
7978
to = GLib.timeout_add((1000 // 10), refraction)
80-
8179
prog.set_fraction(0.7)
82-
8380
win.set_child(prog)
84-
gdisplay = prog.get_display()
85-
86-
Gtk.StyleContext.add_provider_for_display(
87-
gdisplay, css, Gtk.STYLE_PROVIDER_PRIORITY_USER
88-
)
8981

9082
# we can't actually avoid getting focus, but in case the compositors ever
9183
# fix themselves, let's give it our best try
@@ -101,12 +93,11 @@ def refraction() -> bool:
10193
win.get_surface().set_input_region(Region())
10294
gdk_x11_win = win.get_native().get_surface()
10395
xid = gdk_x11_win.get_xid()
104-
display = XOpenDisplay()
10596
xlibwin = display.create_resource_object("window", xid)
106-
screen = display.screen()
107-
ewmh = EWMH(display, screen.root)
97+
10898
# Always on top
109-
ewmh.setMoveResizeWindow(xlibwin, x=300, y=800, w=2000, h=150)
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)
110101
ewmh.setWmState(xlibwin, 1, "_NET_WM_STATE_ABOVE")
111102

112103
# Draw even over the task bar (this breaks stuff)
@@ -117,6 +108,20 @@ def refraction() -> bool:
117108
ewmh.setWmState(xlibwin, 1, "_NET_WM_STATE_SKIP_PAGER")
118109
display.flush()
119110

111+
# When the application is launched…
112+
def on_activate(app: Gtk.Application) -> None:
113+
# … create a new window…
114+
gdisplay = Gdk.Display.get_default()
115+
Gtk.StyleContext.add_provider_for_display(
116+
gdisplay, css, Gtk.STYLE_PROVIDER_PRIORITY_USER
117+
)
118+
119+
display = XOpenDisplay()
120+
screen = display.screen()
121+
ewmh = EWMH(display, screen.root)
122+
for monitor in gdisplay.get_monitors():
123+
makeOneProgressBar(display, monitor, ewmh)
124+
120125

121126
if __name__ == "__main__":
122127
# Create a new application

0 commit comments

Comments
 (0)