]> source.dussan.org Git - tigervnc.git/commitdiff
Handle pointer events.
authorPierre Ossman <ossman@cendio.se>
Wed, 9 Mar 2011 10:24:12 +0000 (10:24 +0000)
committerPierre Ossman <ossman@cendio.se>
Wed, 9 Mar 2011 10:24:12 +0000 (10:24 +0000)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4346 3789f03b-4d11-0410-bbf8-ca57d06f2519

vncviewer/DesktopWindow.cxx
vncviewer/DesktopWindow.h

index 28f6c09add52df5320d48a776ab70794fc9965a5..5daac0a2706a604837d9438d4656bd8c5a95fc58 100644 (file)
@@ -40,7 +40,8 @@ static rfb::LogWriter vlog("DesktopWindow");
 DesktopWindow::DesktopWindow(int w, int h, const char *name,
                              const rfb::PixelFormat& serverPF,
                              CConn* cc_)
-  : Fl_Window(w, h), cc(cc_), frameBuffer(NULL), pixelTrans(NULL)
+  : Fl_Window(w, h), cc(cc_), frameBuffer(NULL), pixelTrans(NULL),
+    lastPointerPos(0, 0), lastButtonMask(0)
 {
   callback(handleClose, this);
 
@@ -158,6 +159,44 @@ void DesktopWindow::draw()
 }
 
 
+int DesktopWindow::handle(int event)
+{
+  int buttonMask, wheelMask;
+
+  switch (event) {
+  case FL_PUSH:
+  case FL_RELEASE:
+  case FL_DRAG:
+  case FL_MOVE:
+  case FL_MOUSEWHEEL:
+    buttonMask = 0;
+    if (Fl::event_button1())
+      buttonMask |= 1;
+    if (Fl::event_button2())
+      buttonMask |= 2;
+    if (Fl::event_button3())
+      buttonMask |= 4;
+
+    if (event == FL_MOUSEWHEEL) {
+      if (Fl::event_dy() < 0)
+        wheelMask = 8;
+      else
+        wheelMask = 16;
+
+      // A quick press of the wheel "button", followed by a immediate
+      // release below
+      handlePointerEvent(Point(Fl::event_x(), Fl::event_y()),
+                         buttonMask | wheelMask);
+    } 
+
+    handlePointerEvent(Point(Fl::event_x(), Fl::event_y()), buttonMask);
+    return 1;
+  }
+
+  return Fl_Window::handle(event);
+}
+
+
 void DesktopWindow::handleUpdateTimeout(void *data)
 {
   DesktopWindow *self = (DesktopWindow *)data;
@@ -184,3 +223,28 @@ void DesktopWindow::handleClose(Fl_Widget *wnd, void *data)
 {
   exit_vncviewer();
 }
+
+
+void DesktopWindow::handlePointerEvent(const rfb::Point& pos, int buttonMask)
+{
+  if (!viewOnly) {
+    if (pointerEventInterval == 0 || buttonMask != lastButtonMask) {
+      cc->writer()->pointerEvent(pos, buttonMask);
+    } else {
+      if (!Fl::has_timeout(handlePointerTimeout, this))
+        Fl::add_timeout((double)pointerEventInterval/1000.0,
+                        handlePointerTimeout, this);
+    }
+    lastPointerPos = pos;
+    lastButtonMask = buttonMask;
+  }
+}
+
+
+void DesktopWindow::handlePointerTimeout(void *data)
+{
+  DesktopWindow *self = (DesktopWindow *)data;
+
+  assert(self);
+
+}
index de85adde3234a87e8cdf1b17c63686af1dc6399c..ba308c0559296d6d5ac19577187ac2ad1c9fd65f 100644 (file)
@@ -82,6 +82,7 @@ public:
 
   // Fl_Window callback methods
   void draw();
+  int handle(int event);
 
 private:
 
@@ -96,6 +97,9 @@ private:
 
   static void handleClose(Fl_Widget *wnd, void *data);
 
+  void handlePointerEvent(const rfb::Point& pos, int buttonMask);
+  static void handlePointerTimeout(void *data);
+
 private:
   CConn* cc;
 
@@ -105,6 +109,9 @@ private:
   rfb::SimpleColourMap colourMap;
 
   rfb::Region damage;
+
+  rfb::Point lastPointerPos;
+  int lastButtonMask;
 };
 
 #endif