]> git.tdb.fi Git - libs/gltk.git/commitdiff
Improve pointer grab handling
authorMikko Rasa <tdb@tdb.fi>
Mon, 23 Sep 2019 18:23:08 +0000 (21:23 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 23 Sep 2019 18:23:08 +0000 (21:23 +0300)
This fixes a bug where hiding a widget with active pointer grab would
leave the grab flag set, preventing pointer events from being sent
anywere.

source/container.cpp
source/container.h

index 03dff1137bfdf6416f6d755c61bae65604f8733b..53eeaa7e440b7f6489bf507d59cbb08681bb218b 100644 (file)
@@ -130,7 +130,7 @@ void Container::raise(Widget &wdg)
        throw hierarchy_error("widget not in container");
 }
 
-void Container::set_pointer_focus(Widget *wdg)
+void Container::set_pointer_focus(Widget *wdg, bool grab)
 {
        if(wdg!=pointer_focus)
        {
@@ -138,10 +138,13 @@ void Container::set_pointer_focus(Widget *wdg)
                        pointer_focus->pointer_leave();
 
                pointer_focus = wdg;
+               pointer_grabbed = grab;
 
                if(pointer_focus)
                        pointer_focus->pointer_enter();
        }
+       else
+               pointer_grabbed = grab;
 }
 
 void Container::set_input_focus(Widget *wdg)
@@ -411,8 +414,7 @@ void Container::Child::grab_pointer()
 {
        if(!container.pointer_grabbed)
        {
-               container.set_pointer_focus(widget);
-               container.pointer_grabbed = true;
+               container.set_pointer_focus(widget, true);
                container.signal_grab_pointer.emit();
        }
 }
@@ -423,7 +425,6 @@ void Container::Child::ungrab_pointer()
        {
                // XXX Should set to the widget under pointer
                container.set_pointer_focus(0);
-               container.pointer_grabbed = false;
                container.signal_ungrab_pointer.emit();
        }
 }
index f16a9ba5d814b1e21841bdf0b18c4e49cc8a2a79..d98ce394c0506d9ad522c153aad1f875d10efd81 100644 (file)
@@ -63,7 +63,7 @@ public:
        void raise(Widget &);
 
 protected:
-       void set_pointer_focus(Widget *);
+       void set_pointer_focus(Widget *, bool = false);
        void set_input_focus(Widget *);
 public:
        Widget *get_input_focus() const { return input_focus; }