cursor rectangle was 1px too big
[presencevnc] / src / vncview.cpp
index afe6f5f..9b7c91a 100644 (file)
@@ -290,6 +290,8 @@ void VncView::updateImage(int x, int y, int w, int h)
                return;
        }
      //kDebug(5011) << "got update" << width() << height();
+
+     /*
      static unsigned int frames = 0;
      static unsigned int updates = 0;
      static QTime time = QTime::currentTime();
@@ -301,6 +303,7 @@ if(x == 0 and y == 0) {
      if(frames % 100 == 0)
             kDebug(5011) << "f/s: " << frames/double(time.elapsed()) * 1000.0;
 }
+*/
 
     m_x = x;
     m_y = y;
@@ -457,13 +460,11 @@ void VncView::paintEvent(QPaintEvent *event)
 
        //draw local cursor ourselves, normal mouse pointer doesn't deal with scrolling
        if((m_dotCursorState == CursorOn) || m_forceLocalCursor) {
-               const uchar bits[] = { 0xff, 0x8e, 0x8e, 0x8e, 0xff };
-               const bool little_endian = (Q_BYTE_ORDER == Q_LITTLE_ENDIAN);
-               const QBitmap cursorBitmap = QBitmap::fromData(QSize(5,5), bits , little_endian?QImage::Format_Mono:QImage::Format_MonoLSB);
-
+#if QT_VERSION >= 0x040500
                painter.setCompositionMode(QPainter::RasterOp_SourceXorDestination);
-               painter.drawPixmap(cursor_x-2, cursor_y-2, cursorBitmap);
-               //TODO update position of last cursor_x/y to avoid artifacts
+#endif
+               //rectangle size is 5px = 4px + 1px pen width
+               painter.drawRect(cursor_x*m_horizontalFactor - 2, cursor_y*m_verticalFactor - 2, 4, 4);
        }
 
     RemoteView::paintEvent(event);
@@ -544,60 +545,65 @@ void VncView::mouseEventHandler(QMouseEvent *e)
        cursor_y = qRound(e->y()/m_verticalFactor);
        vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); // plain move event
 
-       if(disable_tapping) { //only move cursor
-               e->ignore();
-               return;
-       }
-
-       if(e->type() == QEvent::MouseButtonPress or e->type() == QEvent::MouseButtonDblClick) {
-               press_time.start();
-               if(tap_detected and up_time.elapsed() < DOUBLE_TAP_UP_TIME) {
-                       tap_detected = false;
-                       double_tap_detected = true;
+       if(!disable_tapping and e->button() == Qt::LeftButton) { //implement touchpad-like input for left button
+               if(e->type() == QEvent::MouseButtonPress or e->type() == QEvent::MouseButtonDblClick) {
+                       press_time.start();
+                       if(tap_detected and up_time.elapsed() < DOUBLE_TAP_UP_TIME) {
+                               tap_detected = false;
+                               double_tap_detected = true;
+
+                               QTimer::singleShot(TAP_PRESS_TIME, this, SLOT(mouseEventHandler()));
+                       }
+               } else if(e->type() == QEvent::MouseButtonRelease) {
+                       if(tap_drag_detected) {
+                               m_buttonMask &= 0xfe;
+                               vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
+                               tap_drag_detected = false;
+                       } else if(double_tap_detected) { //double click
+                               double_tap_detected = false;
+
+                               m_buttonMask |= 0x01;
+                               vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
+                               m_buttonMask &= 0xfe;
+                               vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
+                               m_buttonMask |= 0x01;
+                               vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
+                               m_buttonMask &= 0xfe;
+                               vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
+                       } else if(press_time.elapsed() < TAP_PRESS_TIME) { //tap
+                               up_time.start();
+                               tap_detected = true;
+                               QTimer::singleShot(DOUBLE_TAP_UP_TIME, this, SLOT(mouseEventHandler()));
+                       }
 
-                       QTimer::singleShot(TAP_PRESS_TIME, this, SLOT(mouseEventHandler()));
                }
-       } else if(e->type() == QEvent::MouseButtonRelease) {
-               if(tap_drag_detected) {
-                       m_buttonMask &= 0xfe;
-                       vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
-                       tap_drag_detected = false;
-               } else if(double_tap_detected) { //double click
-                       double_tap_detected = false;
-
-                       m_buttonMask |= 0x01;
-                       vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
-                       m_buttonMask &= 0xfe;
-                       vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
-                       m_buttonMask |= 0x01;
-                       vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
-                       m_buttonMask &= 0xfe;
-                       vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
-               } else if(press_time.elapsed() < TAP_PRESS_TIME) { //tap
-                       up_time.start();
-                       tap_detected = true;
-                       QTimer::singleShot(DOUBLE_TAP_UP_TIME, this, SLOT(mouseEventHandler()));
+       } else { //middle or right button, send directly
+               if ((e->type() == QEvent::MouseButtonPress)) {
+                   if (e->button() & Qt::MidButton)
+                       m_buttonMask |= 0x02;
+                   if (e->button() & Qt::RightButton)
+                       m_buttonMask |= 0x04;
+               } else if (e->type() == QEvent::MouseButtonRelease) {
+                   if (e->button() & Qt::MidButton)
+                       m_buttonMask &= 0xfd;
+                   if (e->button() & Qt::RightButton)
+                       m_buttonMask &= 0xfb;
                }
-
+               vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
        }
 
-/* for reference:
-    if (e->type() != QEvent::MouseMove) {
-        if ((e->type() == QEvent::MouseButtonPress)) {
-            if (e->button() & Qt::LeftButton)
-                m_buttonMask |= 0x01;
-            if (e->button() & Qt::MidButton)
-                m_buttonMask |= 0x02;
-            if (e->button() & Qt::RightButton)
-                m_buttonMask |= 0x04;
-        } else if (e->type() == QEvent::MouseButtonRelease) {
-            if (e->button() & Qt::LeftButton)
-                m_buttonMask &= 0xfe;
-            if (e->button() & Qt::MidButton)
-                m_buttonMask &= 0xfd;
-            if (e->button() & Qt::RightButton)
-                m_buttonMask &= 0xfb;
-       */
+       //prevent local cursor artifacts
+       static int old_cursor_x = cursor_x;
+       static int old_cursor_y = cursor_y;
+       if(((m_dotCursorState == CursorOn) || m_forceLocalCursor)
+       and (cursor_x != old_cursor_x or cursor_y != old_cursor_y)) {
+               //clear last position (plus a few extra pixels)
+               repaint(old_cursor_x*m_horizontalFactor - 3, old_cursor_y*m_verticalFactor - 3, 7, 7);
+               //and refresh new one
+               repaint(cursor_x*m_horizontalFactor - 3, cursor_y*m_verticalFactor - 3, 7, 7);
+
+               old_cursor_x = cursor_x; old_cursor_y = cursor_y;
+       }
 }
 
 void VncView::wheelEventHandler(QWheelEvent *event)
@@ -633,6 +639,16 @@ void VncView::keyEventHandler(QKeyEvent *e)
 
     const bool pressed = (e->type() == QEvent::KeyPress);
 
+#ifdef Q_WS_MAEMO_5
+    //don't send ISO_Level3_Shift (would break things like Win+0-9)
+    //also enable IM so symbol key works
+    if(k == 0xfe03) {
+           setAttribute(Qt::WA_InputMethodEnabled, pressed);
+           e->ignore();
+           return;
+    }
+#endif
+
     // handle modifiers
     if (k == XK_Shift_L || k == XK_Control_L || k == XK_Meta_L || k == XK_Alt_L) {
         if (pressed) {
@@ -708,8 +724,6 @@ void VncView::unpressModifiers()
 
 void VncView::clipboardSelectionChanged()
 {
-    //kDebug(5011);
-
     if (m_status != Connected)
         return;
 
@@ -723,8 +737,6 @@ void VncView::clipboardSelectionChanged()
 
 void VncView::clipboardDataChanged()
 {
-    //kDebug(5011);
-
     if (m_status != Connected)
         return;
 
@@ -853,6 +865,10 @@ void VncView::reloadSettings()
        left_zoom = settings.value("left_zoom", 0).toInt();
        right_zoom = settings.value("right_zoom", 1).toInt();
        disable_tapping = settings.value("disable_tapping", false).toBool();
+
+       bool always_show_local_cursor = settings.value("always_show_local_cursor", false).toBool();
+       if(always_show_local_cursor)
+               showDotCursor(CursorOn);
 }
 
 //convert commitString into keyevents