Skip to content

Commit

Permalink
Merge pull request #23 from nwg-piotr/mouse-event
Browse files Browse the repository at this point in the history
Emulate mouse button release event on startup
  • Loading branch information
nwg-piotr authored Sep 19, 2024
2 parents 3a6ff10 + 29a2f95 commit 5ab84d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion nwg_hello/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,29 @@
eprint(f"X11 sessions: {x_sessions}", log=args.log)


def set_clock():
_now = datetime.now()
for win in windows:
win.update_time(_now)
return False


def move_clock():
_now = datetime.now()
for win in windows:
win.update_time(_now)
return True


def emulate_mouse_event():
# In order to focus the window -> password form entry, we need to perform some mouse event.
# Although I tried hard, nothing worked well on Hyprland 0.43.0, so we'll only do it for sway.
if os.getenv('SWAYSOCK'):
subprocess.Popen("swaymsg seat - cursor release button1", shell=True)

return False


def main():
# Some monitors take longer to startup; we can just time.sleep() here, as we're not yet on the GTK loop.
if settings["delay_secs"] > 0:
Expand Down Expand Up @@ -178,7 +194,11 @@ def main():
else:
win = EmptyWindow(monitor, args.log, args.test)

GLib.timeout_add(1, move_clock)
GLib.timeout_add(0, set_clock)
GLib.timeout_add(500, move_clock)

GLib.timeout_add(1000, emulate_mouse_event)

Gtk.main()


Expand Down
2 changes: 1 addition & 1 deletion nwg_hello/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def __init__(self, client, settings, sessions, x_sessions, users, monitor, voc,
GtkLayerShell.init_for_window(self.window)
GtkLayerShell.set_monitor(self.window, monitor)
GtkLayerShell.set_layer(self.window, GtkLayerShell.Layer.OVERLAY)
GtkLayerShell.set_keyboard_mode(self.window, GtkLayerShell.KeyboardMode.ON_DEMAND)
GtkLayerShell.set_keyboard_mode(self.window, GtkLayerShell.KeyboardMode.EXCLUSIVE)
GtkLayerShell.set_anchor(self.window, GtkLayerShell.Edge.TOP, True)
GtkLayerShell.set_anchor(self.window, GtkLayerShell.Edge.BOTTOM, True)
GtkLayerShell.set_anchor(self.window, GtkLayerShell.Edge.LEFT, True)
Expand Down

0 comments on commit 5ab84d0

Please sign in to comment.