From: Pierre Ossman Date: Mon, 26 Mar 2018 12:16:43 +0000 (+0200) Subject: Add focus test helper for Viewport X-Git-Tag: v1.8.90~22^2~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9a74732b5cbb1a11b950cd09ff5e764ddffc3897;p=tigervnc.git Add focus test helper for Viewport --- diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx index be38b929..3b56fce5 100644 --- a/vncviewer/Viewport.cxx +++ b/vncviewer/Viewport.cxx @@ -309,17 +309,9 @@ void Viewport::setCursor(int width, int height, const Point& hotspot, void Viewport::setLEDState(unsigned int state) { - Fl_Widget *focus; - vlog.debug("Got server LED state: 0x%08x", state); - focus = Fl::grab(); - if (!focus) - focus = Fl::focus(); - if (!focus) - return; - - if (focus != this) + if (!hasFocus()) return; #if defined(WIN32) @@ -635,6 +627,17 @@ int Viewport::handle(int event) } +bool Viewport::hasFocus() +{ + Fl_Widget* focus; + + focus = Fl::grab(); + if (!focus) + focus = Fl::focus(); + + return focus == this; +} + #if ! (defined(WIN32) || defined(__APPLE__)) unsigned int Viewport::getModifierMask(unsigned int keysym) { @@ -845,17 +848,10 @@ void Viewport::handleKeyRelease(int keyCode) int Viewport::handleSystemEvent(void *event, void *data) { Viewport *self = (Viewport *)data; - Fl_Widget *focus; assert(self); - focus = Fl::grab(); - if (!focus) - focus = Fl::focus(); - if (!focus) - return 0; - - if (focus != self) + if (!self->hasFocus()) return 0; assert(event); diff --git a/vncviewer/Viewport.h b/vncviewer/Viewport.h index 14ef4ab1..170be0d7 100644 --- a/vncviewer/Viewport.h +++ b/vncviewer/Viewport.h @@ -64,6 +64,7 @@ public: int handle(int event); private: + bool hasFocus(); unsigned int getModifierMask(unsigned int keysym);