What I want to do and why
I want my window to not focus, so the previous focused window is selected.
Why? I want to interact with a previously selected window (from other programs). My current plan is to expand my window, use libxdo
to simulate keystrokes, and then focus my window again.
My window can be mounted on top to avoid clicking. It should be good enough. It looks simple to me. But I can’t make it work.
What have i tried so far
Hiding the window with Gtk.Widget.hide()
and then re-displaying: the window flickers too much and it is slightly pushed a few pixels up (due to the stubbornness of the window manager, I suppose).
Test code example
Current code calls Gtk.Window.set_focus(None)
, that do not work. I need to replace this line with something else that does what I want it to do.
losefocus.py
:
import signal from gi import require_version require_version('Gtk', '3.0') from gi.repository import GLib, Gtk, GObject class LoseFocusHandler: def onClick(self, window): print "Losing focus yet?" window1 = builder.get_object("window1") window1.set_focus(None) if __name__ == "__main__": GObject.threads_init() builder = Gtk.Builder() builder.add_from_file("losefocus.glade") builder.connect_signals(LoseFocusHandler()) window1 = builder.get_object("window1") window1.show_all() signal.signal(signal.SIGINT, signal.SIG_DFL) Gtk.main()
losefocus.glade
:
<?xml version="1.0" encoding="UTF-8"?> <interface> <requires lib="gtk+" version="3.10"/> <object class="GtkWindow" id="window1"> <property name="can_focus">False</property> <property name="window_position">center-always</property> <property name="gravity">center</property> <child> <object class="GtkButton" id="button1"> <property name="label" translatable="yes">Lose Focus!</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <property name="relief">half</property> <signal name="clicked" handler="onClick" swapped="no"/> </object> </child> </object> </interface>
source share