From 005bfa42940f69d4bad9d4fc22dc64a694869137 Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Fri, 5 Sep 2014 12:33:35 +0000 Subject: [PATCH] Fix cross-window focus throwing on X11, similar to the Mac case. STR #3129 git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10276 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/x.H | 1 + src/Fl.cxx | 11 +++++++++-- src/Fl_x.cxx | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/FL/x.H b/FL/x.H index 37e361ffc..012b56405 100644 --- a/FL/x.H +++ b/FL/x.H @@ -160,6 +160,7 @@ public: static void x(Fl_Window* wi, int X) {wi->x(X);} static void y(Fl_Window* wi, int Y) {wi->y(Y);} static int ewmh_supported(); + static void activate_window(Window w); }; extern FL_EXPORT char fl_override_redirect; // hack into Fl_X::make_xid() diff --git a/src/Fl.cxx b/src/Fl.cxx index 714c8deee..61263b44d 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -922,10 +922,17 @@ void Fl::focus(Fl_Widget *o) { if (fl_xfocus != win) { Fl_X *x = Fl_X::i(win); if (x) x->set_key_window(); - } + } +#elif defined(USE_X11) + if (fl_xfocus != win) { + Fl_X *x = Fl_X::i(win); + win->show(); // Old WMs, XMapRaised + // New WMs use the NETWM attribute: + if (x) Fl_X::activate_window(x->xid); + } #endif fl_xfocus = win; - } + } } // take focus from the old focused window fl_oldfocus = 0; diff --git a/src/Fl_x.cxx b/src/Fl_x.cxx index 67971b453..7869791d7 100644 --- a/src/Fl_x.cxx +++ b/src/Fl_x.cxx @@ -356,6 +356,7 @@ static Atom fl_NET_WM_STATE_FULLSCREEN; static Atom fl_NET_WM_FULLSCREEN_MONITORS; static Atom fl_NET_WORKAREA; static Atom fl_NET_WM_ICON; +static Atom fl_NET_ACTIVE_WINDOW; /* X defines 32-bit-entities to have a format value of max. 32, @@ -667,6 +668,7 @@ void fl_open_display(Display* d) { fl_NET_WM_FULLSCREEN_MONITORS = XInternAtom(d, "_NET_WM_FULLSCREEN_MONITORS", 0); fl_NET_WORKAREA = XInternAtom(d, "_NET_WORKAREA", 0); fl_NET_WM_ICON = XInternAtom(d, "_NET_WM_ICON", 0); + fl_NET_ACTIVE_WINDOW = XInternAtom(d, "_NET_ACTIVE_WINDOW", 0); if (sizeof(Atom) < 4) atom_bits = sizeof(Atom) * 8; @@ -2205,6 +2207,20 @@ int Fl_X::ewmh_supported() { return result; } +extern Fl_Window *fl_xfocus; + +void Fl_X::activate_window(Window w) { + if (!ewmh_supported()) + return; + + Fl_X *x = Fl_X::i(fl_xfocus); + if (!x) + return; + + send_wm_event(w, fl_NET_ACTIVE_WINDOW, 1 /* application */, + 0 /* timestamp */, x->xid /* previously active window */); +} + /* Change an existing window to fullscreen */ void Fl_Window::fullscreen_x() { if (Fl_X::ewmh_supported()) {