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.
pull/168/head
whitequark 2017-01-17 13:11:09 +00:00
parent 8749a175a6
commit 068191bf28
1 changed files with 20 additions and 18 deletions

View File

@ -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,13 +283,26 @@ public:
protected:
bool on_key_press_event(GdkEventKey *event) override {
if(is_editing()) {
if(event->keyval == GDK_KEY_Escape) {
stop_editing();
} else {
_entry.event((GdkEvent *)event);
}
return true;
} else {
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 {
Gtk::Fixed::on_size_allocate(allocation);
@ -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);