]> source.dussan.org Git - tigervnc.git/commitdiff
Add focus test helper for Viewport
authorPierre Ossman <ossman@cendio.se>
Mon, 26 Mar 2018 12:16:43 +0000 (14:16 +0200)
committerPierre Ossman <ossman@cendio.se>
Mon, 26 Mar 2018 12:16:43 +0000 (14:16 +0200)
vncviewer/Viewport.cxx
vncviewer/Viewport.h

index be38b929a49f31b713240c6939104f000bcafc76..3b56fce558d42d9be4bd70365e09c2779ba34897 100644 (file)
@@ -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);
index 14ef4ab1fdffff6df512ee5a453d04f086409a31..170be0d7b70da6f43ce1bd128867ef661d046747 100644 (file)
@@ -64,6 +64,7 @@ public:
   int handle(int event);
 
 private:
+  bool hasFocus();
 
   unsigned int getModifierMask(unsigned int keysym);