From 068191bf28fd423c76fc6d4ba30121d8c0389f5a Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 17 Jan 2017 13:11:09 +0000 Subject: [PATCH] GTK: unbreak the color chooser. We want to suppress accelerators but still get input to (at least) the window where the editor is opened. It's no harm to permit input to other windows, but it is bad to route all of it to the editor, since color chooser depends on being able to receive input. So, what we do is add modal grab to the *overlay*, which has the editor and the underlay widget, route all events as usual to children, and just force the key events to go to the editor, since otherwise they would still propagate up for some reason. --- src/platform/gtkmain.cpp | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/platform/gtkmain.cpp b/src/platform/gtkmain.cpp index 2ba3c8f..fe0c4a3 100644 --- a/src/platform/gtkmain.cpp +++ b/src/platform/gtkmain.cpp @@ -258,13 +258,14 @@ public: if(!_entry.is_visible()) { _entry.show(); _entry.grab_focus(); - _entry.add_modal_grab(); + add_modal_grab(); } } void stop_editing() { - if(_entry.is_visible()) - _entry.remove_modal_grab(); + if(_entry.is_visible()) { + remove_modal_grab(); + } _entry.hide(); } @@ -282,12 +283,25 @@ public: protected: bool on_key_press_event(GdkEventKey *event) override { - if(event->keyval == GDK_KEY_Escape) { - stop_editing(); + if(is_editing()) { + if(event->keyval == GDK_KEY_Escape) { + stop_editing(); + } else { + _entry.event((GdkEvent *)event); + } return true; + } else { + return false; } + } - return false; + bool on_key_release_event(GdkEventKey *event) override { + if(is_editing()) { + _entry.event((GdkEvent *)event); + return true; + } else { + return false; + } } void on_size_allocate(Gtk::Allocation& allocation) override { @@ -464,10 +478,6 @@ public: return _is_fullscreen; } - bool emulate_key_press(GdkEventKey *event) { - return on_key_press_event(event); - } - protected: void on_show() override { Gtk::Window::on_show(); @@ -1220,14 +1230,6 @@ protected: Gtk::Window::on_hide(); } - bool on_key_press_event(GdkEventKey *event) override { - if(GW->emulate_key_press(event)) { - return true; - } - - return Gtk::Window::on_key_press_event(event); - } - bool on_delete_event(GdkEventAny *) override { /* trigger the action and ignore the request */ GraphicsWindow::MenuView(Command::SHOW_TEXT_WND);