From 723d8caa9d2a5acd423a354332f652ddfefb7d6e Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Sun, 16 Oct 2022 23:23:04 +0200 Subject: Fix "Fl::focus() changes Fl_Group::current() to null" (#515) This issue is caused by setting `Fl_Group::current(0);` in Fl_Window::show(), i.e. in Fl_X::make_xid(..) in an attempt to fix a "very common user bug: forgot end()". As long as this is done, this commit fixes the issue. For details see GitHub issue #515. --- src/drivers/X11/Fl_X11_Window_Driver.cxx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/drivers/X11/Fl_X11_Window_Driver.cxx b/src/drivers/X11/Fl_X11_Window_Driver.cxx index 3fb10cb74..5b44bedec 100644 --- a/src/drivers/X11/Fl_X11_Window_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Window_Driver.cxx @@ -127,10 +127,18 @@ int Fl_X11_Window_Driver::decorated_w() void Fl_X11_Window_Driver::take_focus() { Fl_X *i = Fl_X::i(pWindow); - if (!Fl_X11_Screen_Driver::ewmh_supported()) - pWindow->show(); // Old WMs, XMapRaised - else if (i) // New WMs use the NETWM attribute: + if (!Fl_X11_Screen_Driver::ewmh_supported()) { + + // Save and restore the current group because 'show()' sets it to NULL. + // See issue #515: Fl::focus() changes Fl_Group::current() to null. + + Fl_Group *cg = Fl_Group::current(); // save current group + pWindow->show(); // old WMs, XMapRaised + Fl_Group::current(cg); // restore current group + } + else if (i) { // New WMs use the NETWM attribute: activate_window(); + } } -- cgit v1.2.3