Pressing any global keyboard shortcut causes temporary loss of focus (continue)

continuation from Pressing any global keyboard shortcut causes temporary loss of focus
I’ve tried to devise a workaround. If toplevel window lost focus then run timer of 1s to check if keyboard switch is in process. It replicates original behavior:

  • commit change if focus stays on TreeView
  • discard if focus changes to different widget/window

What are downsides of this approach?
Could it be the case that GTK devs are interested in implementing it (or similar)?

workaround in python
 class CellRendererTextMy(Gtk.CellRendererText):
    def __init__(self):
        def on_editing_started(self,editable,path):
            if isinstance(editable,Gtk.Entry):
                ttag = None
                def stop_edit():
                    nonlocal ttag
                    ttag = None
                    #gtk_cell_renderer_text_focus_out_event() in gtkcellrenderertext.c
                    editable.set_property("editing-canceled", True)
                    return False
                def on_focus_in(widget,event):
                    nonlocal ttag
                    if ttag:
                        ttag = None
                    return False
                def editable_workaround(widget, event):
                    if widget.get_realized():
                        toplevel = widget
                        while toplevel.get_parent():
                            toplevel = toplevel.get_parent()
                        if not toplevel.get_property("has_toplevel_focus"):
                            nonlocal ttag
                            ttag = GLib.timeout_add(1000, stop_edit)
                            return True                    
                editable.connect("focus-out-event", editable_workaround)
                editable.connect("focus-in-event", on_focus_in)
        self.connect("editing_started", on_editing_started)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.