Revision: 5184
          http://sourceforge.net/p/tigervnc/code/5184
Author:   ossman_
Date:     2014-06-13 10:52:11 +0000 (Fri, 13 Jun 2014)
Log Message:
-----------
Add a global event handler so that we can intercept custom events
that aren't for a specific window.

Modified Paths:
--------------
    trunk/unix/tx/TXWindow.cxx
    trunk/unix/tx/TXWindow.h

Modified: trunk/unix/tx/TXWindow.cxx
===================================================================
--- trunk/unix/tx/TXWindow.cxx  2014-05-21 10:54:17 UTC (rev 5183)
+++ trunk/unix/tx/TXWindow.cxx  2014-06-13 10:52:11 UTC (rev 5184)
@@ -46,6 +46,8 @@
 const int TXWindow::dotSize = 4, TXWindow::tickSize = 8;
 char* TXWindow::defaultWindowClass;
 
+TXGlobalEventHandler* TXWindow::globalEventHandler = NULL;
+
 void TXWindow::init(Display* dpy, const char* defaultWindowClass_)
 {
   cmap = DefaultColormap(dpy,DefaultScreen(dpy));
@@ -101,6 +103,10 @@
   while (XPending(dpy)) {
     XEvent ev;
     XNextEvent(dpy, &ev);
+    if (globalEventHandler) {
+      if (globalEventHandler->handleGlobalEvent(&ev))
+        continue;
+    }
     if (ev.type == MappingNotify) {
       XRefreshKeyboardMapping(&ev.xmapping);
     } else if (ev.type == PropertyNotify &&
@@ -117,6 +123,13 @@
   }
 }
 
+TXGlobalEventHandler* TXWindow::setGlobalEventHandler(TXGlobalEventHandler* h)
+{
+  TXGlobalEventHandler* old = globalEventHandler;
+  globalEventHandler = h;
+  return old;
+}
+
 void TXWindow::getColours(Display* dpy, XColor* cols, int nCols)
 {
   bool* got = new bool[nCols];

Modified: trunk/unix/tx/TXWindow.h
===================================================================
--- trunk/unix/tx/TXWindow.h    2014-05-21 10:54:17 UTC (rev 5183)
+++ trunk/unix/tx/TXWindow.h    2014-06-13 10:52:11 UTC (rev 5184)
@@ -51,6 +51,14 @@
   virtual void handleEvent(TXWindow* w, XEvent* ev) = 0;
 };
 
+// TXGlobalEventHandler is similar to TXEventHandler but will be called early 
and
+// for every X event. The handler should return true to indicate that the
+// event was swallowed and shouldn't be processed further.
+class TXGlobalEventHandler {
+public:
+  virtual bool handleGlobalEvent(XEvent* ev) = 0;
+};
+
 class TXWindow {
 public:
 
@@ -162,6 +170,11 @@
   // returns when there are no more events to process.
   static void handleXEvents(Display* dpy);
 
+  // setGlobalEventHandler() sets the TXGlobalEventHandler to intercept all
+  // X events. It returns the previous events handler, so that handlers can
+  // chain themselves.
+  static TXGlobalEventHandler* setGlobalEventHandler(TXGlobalEventHandler* h);
+
   // windowWithName() locates a window with a given name on a display.
   static Window windowWithName(Display* dpy, Window top, const char* name);
 
@@ -204,6 +217,8 @@
   std::map<Atom,Time> selectionOwnTime;
   std::map<Atom,bool> selectionOwner_;
   bool toplevel_;
+
+  static TXGlobalEventHandler* globalEventHandler;
 };
 
 extern Atom wmProtocols, wmDeleteWindow, wmTakeFocus;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems
_______________________________________________
Tigervnc-commits mailing list
Tigervnc-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tigervnc-commits

Reply via email to