release 0.5
[presencevnc] / src / vncview.cpp
index 691ad86..14f5d0a 100644 (file)
@@ -52,6 +52,9 @@ critical(parent, caption, message)
 #define KMOD_Control_L         0x08
 #define KMOD_Shift_L   0x10
 
+//local cursor width/height in px, should be an odd number
+const int cursor_size = 7;
+
 VncView::VncView(QWidget *parent, const KUrl &url, RemoteView::Quality quality)
         : RemoteView(parent),
         m_initDone(false),
@@ -290,6 +293,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 +306,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,16 +463,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);
 #endif
-
-               painter.drawPixmap(cursor_x-2, cursor_y-2, cursorBitmap);
-               //TODO update position of last cursor_x/y to avoid artifacts
+               //rectangle size includes 1px pen width
+               painter.drawRect(cursor_x*m_horizontalFactor - cursor_size/2, cursor_y*m_verticalFactor - cursor_size/2, cursor_size-1, cursor_size-1);
        }
 
     RemoteView::paintEvent(event);
@@ -547,12 +548,7 @@ 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->button() == Qt::LeftButton) { //implement touchpad-like input for left button
+       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) {
@@ -598,6 +594,19 @@ void VncView::mouseEventHandler(QMouseEvent *e)
                }
                vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
        }
+
+       //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
+               repaint(old_cursor_x*m_horizontalFactor - cursor_size/2, old_cursor_y*m_verticalFactor - cursor_size/2, cursor_size, cursor_size);
+               //and refresh new one
+               repaint(cursor_x*m_horizontalFactor - cursor_size/2, cursor_y*m_verticalFactor - cursor_size/2, cursor_size, cursor_size);
+
+               old_cursor_x = cursor_x; old_cursor_y = cursor_y;
+       }
 }
 
 void VncView::wheelEventHandler(QWheelEvent *event)
@@ -792,6 +801,15 @@ void VncView::sendKey(Qt::Key key)
        case Qt::Key_F12:
                k = 0xffbe + int(key - Qt::Key_F1);
                break;
+       case Qt::Key_Pause:
+               k = 0xff13;
+               break;
+       case Qt::Key_Print:
+               k = 0xff61;
+               break;
+       case Qt::Key_Menu:
+               k = 0xff67;
+               break;
        case Qt::Key_Meta:
        case Qt::MetaModifier:
                k = XK_Super_L;