1 /****************************************************************************
3 ** Copyright (C) 2007-2008 Urs Wolfer <uwolfer @ kde.org>
5 ** This file is part of KDE.
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation; either version 2 of the License, or
10 ** (at your option) any later version.
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; see the file COPYING. If not, write to
19 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ** Boston, MA 02110-1301, USA.
22 ****************************************************************************/
26 #include <QMessageBox>
27 #include <QInputDialog>
28 #define KMessageBox QMessageBox
29 #define error(parent, message, caption) \
30 critical(parent, caption, message)
32 #include <QApplication>
37 #include <QHBoxLayout>
38 #include <QVBoxLayout>
40 #include <QMouseEvent>
41 #include <QPushButton>
48 // Definition of key modifier mask constants
49 #define KMOD_Alt_R 0x01
50 #define KMOD_Alt_L 0x02
51 #define KMOD_Meta_L 0x04
52 #define KMOD_Control_L 0x08
53 #define KMOD_Shift_L 0x10
55 //local cursor width/height in px, should be an odd number
56 const int cursor_size = 7;
58 VncView::VncView(QWidget *parent, const KUrl &url, RemoteView::Quality quality)
66 m_firstPasswordTry(true),
67 m_dontSendClipboard(false),
68 m_horizontalFactor(1.0),
69 m_verticalFactor(1.0),
70 m_forceLocalCursor(false),
71 force_full_repaint(false),
78 connect(&vncThread, SIGNAL(imageUpdated(int, int, int, int)), this, SLOT(updateImage(int, int, int, int)), Qt::BlockingQueuedConnection);
79 connect(&vncThread, SIGNAL(gotCut(const QString&)), this, SLOT(setCut(const QString&)), Qt::BlockingQueuedConnection);
80 connect(&vncThread, SIGNAL(passwordRequest()), this, SLOT(requestPassword()), Qt::BlockingQueuedConnection);
81 connect(&vncThread, SIGNAL(outputErrorMessage(QString)), this, SLOT(outputErrorMessage(QString)));
83 m_clipboard = QApplication::clipboard();
84 connect(m_clipboard, SIGNAL(selectionChanged()), this, SLOT(clipboardSelectionChanged()));
85 connect(m_clipboard, SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
94 // Disconnect all signals so that we don't get any more callbacks from the client thread
95 vncThread.disconnect();
100 void VncView::forceFullRepaint()
102 force_full_repaint = true;
106 bool VncView::eventFilter(QObject *obj, QEvent *event)
109 if (event->type() == QEvent::KeyPress ||
110 event->type() == QEvent::KeyRelease ||
111 event->type() == QEvent::MouseButtonDblClick ||
112 event->type() == QEvent::MouseButtonPress ||
113 event->type() == QEvent::MouseButtonRelease ||
114 event->type() == QEvent::Wheel ||
115 event->type() == QEvent::MouseMove)
118 return RemoteView::eventFilter(obj, event);
121 QSize VncView::framebufferSize()
123 return m_frame.size();
126 QSize VncView::sizeHint() const
131 QSize VncView::minimumSizeHint() const
136 void VncView::scaleResize(int w, int h)
138 RemoteView::scaleResize(w, h);
140 kDebug(5011) << "scaleResize(): " <<w << h;
142 m_verticalFactor = (qreal) h / m_frame.height();
143 m_horizontalFactor = (qreal) w / m_frame.width();
145 m_verticalFactor = m_horizontalFactor = qMin(m_verticalFactor, m_horizontalFactor);
147 const qreal newW = m_frame.width() * m_horizontalFactor;
148 const qreal newH = m_frame.height() * m_verticalFactor;
150 setMaximumSize(newW, newH); //This is a hack to force Qt to center the view in the scroll area
151 //also causes the widget's size to flicker
158 void VncView::startQuitting()
160 kDebug(5011) << "about to quit";
162 const bool connected = status() == RemoteView::Connected;
164 setStatus(Disconnecting);
174 const bool quitSuccess = vncThread.wait(500);
176 kDebug(5011) << "startQuitting(): Quit VNC thread success:" << quitSuccess;
178 setStatus(Disconnected);
181 bool VncView::isQuitting()
186 bool VncView::start()
188 vncThread.setHost(m_host);
189 vncThread.setPort(m_port);
191 vncThread.setQuality(quality);
193 // set local cursor on by default because low quality mostly means slow internet connection
194 if (quality == RemoteView::Low) {
195 showDotCursor(RemoteView::CursorOn);
198 setStatus(Connecting);
204 bool VncView::supportsScaling() const
209 bool VncView::supportsLocalCursor() const
214 void VncView::requestPassword()
216 kDebug(5011) << "request password";
218 setStatus(Authenticating);
220 if (!m_url.password().isNull()) {
221 vncThread.setPassword(m_url.password());
226 settings.beginGroup("hosts");
227 QString password = settings.value(QString("%1/password").arg(m_host), "").toString();
228 //check for saved password
229 if(m_firstPasswordTry and !password.isEmpty()) {
230 kDebug(5011) << "Trying saved password";
231 m_firstPasswordTry = false;
232 vncThread.setPassword(password);
235 m_firstPasswordTry = false;
238 QDialog dialog(this);
239 dialog.setWindowTitle(tr("Password required"));
241 QLineEdit passwordbox;
242 passwordbox.setEchoMode(QLineEdit::Password);
243 passwordbox.setText(password);
244 QCheckBox save_password(tr("Save Password"));
245 save_password.setChecked(!password.isEmpty()); //offer to overwrite saved password
246 QPushButton ok_button(tr("Done"));
247 ok_button.setMaximumWidth(100);
248 connect(&ok_button, SIGNAL(clicked()),
249 &dialog, SLOT(accept()));
253 layout2.addWidget(&passwordbox);
254 layout2.addWidget(&save_password);
255 layout1.addLayout(&layout2);
256 layout1.addWidget(&ok_button);
257 dialog.setLayout(&layout1);
259 if(dialog.exec()) { //dialog accepted
260 password = passwordbox.text();
262 if(save_password.isChecked()) {
263 kDebug(5011) << "Saving password for host '" << m_host << "'";
265 settings.setValue(QString("%1/password").arg(m_host), password);
269 vncThread.setPassword(password);
275 void VncView::outputErrorMessage(const QString &message)
277 kDebug(5011) << message;
279 if (message == "INTERNAL:APPLE_VNC_COMPATIBILTY") {
280 setCursor(localDotCursor());
281 m_forceLocalCursor = true;
287 emit errorMessage(i18n("VNC failure"), message);
290 void VncView::updateImage(int x, int y, int w, int h)
292 if(!QApplication::focusWidget()) { //no focus, we're probably minimized
295 //kDebug(5011) << "got update" << width() << height();
298 static unsigned int frames = 0;
299 static unsigned int updates = 0;
300 static QTime time = QTime::currentTime();
302 if(updates % 100 == 0)
303 kDebug(5011) << "u/s: " << updates/double(time.elapsed()) * 1000.0;
304 if(x == 0 and y == 0) {
306 if(frames % 100 == 0)
307 kDebug(5011) << "f/s: " << frames/double(time.elapsed()) * 1000.0;
317 //with scaled view, artefacts occur because of rounding errors
318 //we'll try to only update chunks of screen space that correspond to integer pixel sizes in m_frame
320 int frame_x = x/m_horizontalFactor;
321 int frame_w = w/m_horizontalFactor;
322 int frame_y = y/m_verticalFactor;
323 int frame_h = h/m_verticalFactor;
325 m_x = frame_x*m_horizontalFactor;
326 m_y = frame_y*m_verticalFactor;
328 m_w = (frame_w+2)*m_horizontalFactor;
329 m_h = (frame_h+2)*m_verticalFactor;
330 kDebug(5011)<< "update);
334 if (m_horizontalFactor != 1.0 || m_verticalFactor != 1.0) {
335 // If the view is scaled, grow the update rectangle to avoid artifacts
336 int x_extrapixels = 1.0/m_horizontalFactor + 1;
337 int y_extrapixels = 1.0/m_verticalFactor + 1;
341 m_w+=2*x_extrapixels;
342 m_h+=2*y_extrapixels;
345 m_frame = vncThread.image();
348 setAttribute(Qt::WA_StaticContents);
349 setAttribute(Qt::WA_OpaquePaintEvent);
350 installEventFilter(this);
352 setCursor(((m_dotCursorState == CursorOn) || m_forceLocalCursor) ? localDotCursor() : Qt::BlankCursor);
354 setMouseTracking(true); // get mouse events even when there is no mousebutton pressed
355 setFocusPolicy(Qt::WheelFocus);
356 setStatus(Connected);
357 // emit framebufferSizeChanged(m_frame.width(), m_frame.height());
362 scaleResize(parentWidget()->width(), parentWidget()->height());
364 scaleResize(width(), height());
371 static QSize old_frame_size = QSize();
372 if ((y == 0 && x == 0) && (m_frame.size() != old_frame_size)) {
373 old_frame_size = m_frame.size();
374 kDebug(5011) << "Updating framebuffer size";
376 //setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
378 scaleResize(parentWidget()->width(), parentWidget()->height());
380 kDebug(5011) << "Resizing: " << m_frame.width() << m_frame.height();
381 resize(m_frame.width(), m_frame.height());
382 //setMaximumSize(m_frame.width(), m_frame.height()); //This is a hack to force Qt to center the view in the scroll area
383 //setMinimumSize(m_frame.width(), m_frame.height());
385 emit framebufferSizeChanged(m_frame.width(), m_frame.height());
389 repaint(qRound(m_x * m_horizontalFactor), qRound(m_y * m_verticalFactor), qRound(m_w * m_horizontalFactor), qRound(m_h * m_verticalFactor));
393 void VncView::setViewOnly(bool viewOnly)
395 RemoteView::setViewOnly(viewOnly);
397 m_dontSendClipboard = viewOnly;
400 setCursor(Qt::ArrowCursor);
402 setCursor(m_dotCursorState == CursorOn ? localDotCursor() : Qt::BlankCursor);
405 void VncView::showDotCursor(DotCursorState state)
407 RemoteView::showDotCursor(state);
409 setCursor(state == CursorOn ? localDotCursor() : Qt::BlankCursor);
412 void VncView::enableScaling(bool scale)
414 RemoteView::enableScaling(scale);
417 //setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
418 //setMinimumSize(1, 1);
420 scaleResize(parentWidget()->width(), parentWidget()->height());
422 scaleResize(width(), height());
424 m_verticalFactor = 1.0;
425 m_horizontalFactor = 1.0;
427 //setMaximumSize(m_frame.width(), m_frame.height()); //This is a hack to force Qt to center the view in the scroll area
428 //setMinimumSize(m_frame.width(), m_frame.height());
429 resize(m_frame.width(), m_frame.height());
433 //level should be in [0, 100]
434 void VncView::setZoomLevel(int level)
436 Q_ASSERT(parentWidget() != 0);
439 double factor; //actual magnification
442 } else if(level > 90) {
445 const double min_horiz_factor = double(parentWidget()->width())/m_frame.width();
446 const double min_vert_factor = double(parentWidget()->height())/m_frame.height();
447 const double fit_screen_factor = qMin(min_horiz_factor, min_vert_factor);
449 //level=900 => factor=1.0, level=0 => factor=fit_screen_factor
450 factor = (level)/90.0*(1.0 - fit_screen_factor) + fit_screen_factor;
454 //remote display smaller than local?
455 kDebug(5011) << "remote display smaller than local?";
459 m_verticalFactor = m_horizontalFactor = factor;
460 resize(m_frame.width()*factor, m_frame.height()*factor);
463 void VncView::setCut(const QString &text)
465 m_dontSendClipboard = true;
466 m_clipboard->setText(text, QClipboard::Clipboard);
467 m_clipboard->setText(text, QClipboard::Selection);
468 m_dontSendClipboard = false;
471 void VncView::paintEvent(QPaintEvent *event)
473 //kDebug(5011) << "paint event: x: " << m_x << ", y: " << m_y << ", w: " << m_w << ", h: " << m_h;
474 if (m_frame.isNull() || m_frame.format() == QImage::Format_Invalid) {
475 kDebug(5011) << "no valid image to paint";
476 RemoteView::paintEvent(event);
482 QPainter painter(this);
484 Qt::TransformationMode transformation_mode = Qt::SmoothTransformation;
485 if( m_horizontalFactor >= 1.0 )
486 transformation_mode = Qt::FastTransformation;
488 if (m_repaint and !force_full_repaint) {
489 // kDebug(5011) << "normal repaint";
490 painter.drawImage(QRect(qRound(m_x*m_horizontalFactor), qRound(m_y*m_verticalFactor),
491 qRound(m_w*m_horizontalFactor), qRound(m_h*m_verticalFactor)),
492 m_frame.copy(m_x, m_y, m_w, m_h).scaled(qRound(m_w*m_horizontalFactor),
493 qRound(m_h*m_verticalFactor),
494 Qt::IgnoreAspectRatio, transformation_mode));
496 //kDebug(5011) << "resize repaint";
497 QRect rect = event->rect();
498 if (!force_full_repaint and (rect.width() != width() || rect.height() != height())) {
499 // kDebug(5011) << "Partial repaint";
500 const int sx = rect.x()/m_horizontalFactor;
501 const int sy = rect.y()/m_verticalFactor;
502 const int sw = rect.width()/m_horizontalFactor;
503 const int sh = rect.height()/m_verticalFactor;
504 painter.drawImage(rect,
505 m_frame.copy(sx, sy, sw, sh).scaled(rect.width(), rect.height(),
506 Qt::IgnoreAspectRatio, transformation_mode));
508 kDebug(5011) << "Full repaint" << width() << height() << m_frame.width() << m_frame.height();
509 painter.drawImage(QRect(0, 0, width(), height()),
510 m_frame.scaled(m_frame.width() * m_horizontalFactor, m_frame.height() * m_verticalFactor,
511 Qt::IgnoreAspectRatio, transformation_mode));
512 force_full_repaint = false;
516 //draw local cursor ourselves, normal mouse pointer doesn't deal with scrolling
517 if((m_dotCursorState == CursorOn) || m_forceLocalCursor) {
518 #if QT_VERSION >= 0x040500
519 painter.setCompositionMode(QPainter::RasterOp_SourceXorDestination);
521 //rectangle size includes 1px pen width
522 painter.drawRect(cursor_x*m_horizontalFactor - cursor_size/2, cursor_y*m_verticalFactor - cursor_size/2, cursor_size-1, cursor_size-1);
525 RemoteView::paintEvent(event);
528 void VncView::resizeEvent(QResizeEvent *event)
530 RemoteView::resizeEvent(event);
532 scaleResize(event->size().width(), event->size().height());
537 bool VncView::event(QEvent *event)
539 switch (event->type()) {
540 case QEvent::KeyPress:
541 case QEvent::KeyRelease:
542 // kDebug(5011) << "keyEvent";
543 keyEventHandler(static_cast<QKeyEvent*>(event));
546 case QEvent::MouseButtonDblClick:
547 case QEvent::MouseButtonPress:
548 case QEvent::MouseButtonRelease:
549 case QEvent::MouseMove:
550 // kDebug(5011) << "mouseEvent";
551 mouseEventHandler(static_cast<QMouseEvent*>(event));
555 // kDebug(5011) << "wheelEvent";
556 wheelEventHandler(static_cast<QWheelEvent*>(event));
559 case QEvent::WindowActivate: //input panel may have been closed, prevent IM from interfering with hardware keyboard
560 setAttribute(Qt::WA_InputMethodEnabled, false);
563 return RemoteView::event(event);
567 //call with e == 0 to flush held events
568 void VncView::mouseEventHandler(QMouseEvent *e)
570 static bool tap_detected = false;
571 static bool double_tap_detected = false;
572 static bool tap_drag_detected = false;
573 static QTime press_time;
574 static QTime up_time; //used for double clicks/tap&drag, for time after first tap
576 const int TAP_PRESS_TIME = 180;
577 const int DOUBLE_TAP_UP_TIME = 500;
579 if(!e) { //flush held taps
581 m_buttonMask |= 0x01;
582 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
583 m_buttonMask &= 0xfe;
584 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
585 tap_detected = false;
586 } else if(double_tap_detected and press_time.elapsed() > TAP_PRESS_TIME) { //got tap + another press -> tap & drag
587 m_buttonMask |= 0x01;
588 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
589 double_tap_detected = false;
590 tap_drag_detected = true;
596 if(e->x() < 0 or e->y() < 0) { //QScrollArea tends to send invalid events sometimes...
601 cursor_x = qRound(e->x()/m_horizontalFactor);
602 cursor_y = qRound(e->y()/m_verticalFactor);
603 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); // plain move event
605 if(!disable_tapping and e->button() == Qt::LeftButton) { //implement touchpad-like input for left button
606 if(e->type() == QEvent::MouseButtonPress or e->type() == QEvent::MouseButtonDblClick) {
608 if(tap_detected and up_time.elapsed() < DOUBLE_TAP_UP_TIME) {
609 tap_detected = false;
610 double_tap_detected = true;
612 QTimer::singleShot(TAP_PRESS_TIME, this, SLOT(mouseEventHandler()));
614 } else if(e->type() == QEvent::MouseButtonRelease) {
615 if(tap_drag_detected) {
616 m_buttonMask &= 0xfe;
617 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
618 tap_drag_detected = false;
619 } else if(double_tap_detected) { //double click
620 double_tap_detected = false;
622 m_buttonMask |= 0x01;
623 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
624 m_buttonMask &= 0xfe;
625 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
626 m_buttonMask |= 0x01;
627 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
628 m_buttonMask &= 0xfe;
629 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
630 } else if(press_time.elapsed() < TAP_PRESS_TIME) { //tap
633 QTimer::singleShot(DOUBLE_TAP_UP_TIME, this, SLOT(mouseEventHandler()));
637 } else { //middle or right button, send directly
638 if ((e->type() == QEvent::MouseButtonPress)) {
639 if (e->button() & Qt::MidButton)
640 m_buttonMask |= 0x02;
641 if (e->button() & Qt::RightButton)
642 m_buttonMask |= 0x04;
643 } else if (e->type() == QEvent::MouseButtonRelease) {
644 if (e->button() & Qt::MidButton)
645 m_buttonMask &= 0xfd;
646 if (e->button() & Qt::RightButton)
647 m_buttonMask &= 0xfb;
649 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
652 //prevent local cursor artifacts
653 static int old_cursor_x = cursor_x;
654 static int old_cursor_y = cursor_y;
655 if(((m_dotCursorState == CursorOn) || m_forceLocalCursor)
656 and (cursor_x != old_cursor_x or cursor_y != old_cursor_y)) {
657 //clear last position
658 repaint(old_cursor_x*m_horizontalFactor - cursor_size/2, old_cursor_y*m_verticalFactor - cursor_size/2, cursor_size, cursor_size);
659 //and refresh new one
660 repaint(cursor_x*m_horizontalFactor - cursor_size/2, cursor_y*m_verticalFactor - cursor_size/2, cursor_size, cursor_size);
662 old_cursor_x = cursor_x; old_cursor_y = cursor_y;
666 void VncView::wheelEventHandler(QWheelEvent *event)
669 if (event->delta() < 0)
674 const int x = qRound(event->x() / m_horizontalFactor);
675 const int y = qRound(event->y() / m_verticalFactor);
677 vncThread.mouseEvent(x, y, eb | m_buttonMask);
678 vncThread.mouseEvent(x, y, m_buttonMask);
681 void VncView::keyEventHandler(QKeyEvent *e)
683 // strip away autorepeating KeyRelease; see bug #206598
684 if (e->isAutoRepeat() && (e->type() == QEvent::KeyRelease)) {
688 // parts of this code are based on http://italc.sourcearchive.com/documentation/1.0.9.1/vncview_8cpp-source.html
689 rfbKeySym k = e->nativeVirtualKey();
691 // we do not handle Key_Backtab separately as the Shift-modifier
692 // is already enabled
693 if (e->key() == Qt::Key_Backtab) {
697 const bool pressed = (e->type() == QEvent::KeyPress);
700 //don't send ISO_Level3_Shift (would break things like Win+0-9)
701 //also enable IM so symbol key works
703 setAttribute(Qt::WA_InputMethodEnabled, pressed);
710 if (k == XK_Shift_L || k == XK_Control_L || k == XK_Meta_L || k == XK_Alt_L) {
713 } else if (m_mods.contains(k)) {
721 int current_zoom = -1;
722 if(e->key() == Qt::Key_F8)
723 current_zoom = left_zoom;
724 else if(e->key() == Qt::Key_F7)
725 current_zoom = right_zoom;
727 // kDebug(5011) << "got '" << e->text() << "'.";
728 vncThread.keyEvent(k, pressed);
730 kDebug(5011) << "nativeVirtualKey() for '" << e->text() << "' failed.";
734 if(current_zoom == -1)
737 //handle zoom buttons
738 if(current_zoom == 0) { //left click
740 m_buttonMask |= 0x01;
742 m_buttonMask &= 0xfe;
743 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
744 } else if(current_zoom == 1) { //right click
746 m_buttonMask |= 0x04;
748 m_buttonMask &= 0xfb;
749 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
750 } else if(current_zoom == 2) { //middle click
752 m_buttonMask |= 0x02;
754 m_buttonMask &= 0xfd;
755 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
756 } else if(current_zoom == 3 and pressed) { //wheel up
758 vncThread.mouseEvent(cursor_x, cursor_y, eb | m_buttonMask);
759 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
760 } else if(current_zoom == 4 and pressed) { //wheel down
762 vncThread.mouseEvent(cursor_x, cursor_y, eb | m_buttonMask);
763 vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
764 } else if(current_zoom == 5) { //page up
765 vncThread.keyEvent(0xff55, pressed);
766 } else if(current_zoom == 6) { //page down
767 vncThread.keyEvent(0xff56, pressed);
771 void VncView::unpressModifiers()
773 const QList<unsigned int> keys = m_mods.keys();
774 QList<unsigned int>::const_iterator it = keys.constBegin();
775 while (it != keys.end()) {
776 vncThread.keyEvent(*it, false);
782 void VncView::clipboardSelectionChanged()
784 if (m_status != Connected)
787 if (m_clipboard->ownsSelection() || m_dontSendClipboard)
790 const QString text = m_clipboard->text(QClipboard::Selection);
792 vncThread.clientCut(text);
795 void VncView::clipboardDataChanged()
797 if (m_status != Connected)
800 if (m_clipboard->ownsClipboard() || m_dontSendClipboard)
803 const QString text = m_clipboard->text(QClipboard::Clipboard);
805 vncThread.clientCut(text);
809 void VncView::sendKey(Qt::Key key)
811 //convert Qt::Key into x11 keysym
823 case Qt::Key_PageDown:
841 case Qt::Key_Backspace:
856 k = 0xffbe + int(key - Qt::Key_F1);
868 case Qt::MetaModifier:
872 case Qt::AltModifier:
875 case Qt::Key_Control:
876 case Qt::ControlModifier:
880 kDebug(5011) << "sendKey(): Unhandled Qt::Key value " << key;
884 if (k == XK_Shift_L || k == XK_Control_L || k == XK_Meta_L || k == XK_Alt_L || k == XK_Super_L) {
885 if (m_mods.contains(k)) { //release
887 vncThread.keyEvent(k, false);
890 vncThread.keyEvent(k, true);
892 } else { //normal key
893 vncThread.keyEvent(k, true);
894 vncThread.keyEvent(k, false);
898 void VncView::sendKeySequence(QKeySequence keys)
900 Q_ASSERT(keys.count() <= 1); //we can only handle a single combination
902 //to get at individual key presses, we split 'keys' into its components
904 for(int i = 0; ; i++) {
905 QString k = keys.toString().section('+', i, i);
908 //kDebug(5011) << "found key: " << k;
910 key_list.append(Qt::Key_Alt);
911 } else if(k == "Ctrl") {
912 key_list.append(Qt::Key_Control);
913 } else if(k == "Meta") {
914 key_list.append(Qt::Key_Meta);
916 key_list.append(QKeySequence(k)[0]);
920 for(int i = 0; i < key_list.count(); i++)
921 sendKey(Qt::Key(key_list.at(i)));
923 //release modifiers (everything before final key)
924 for(int i = key_list.count()-2; i >= 0; i--)
925 sendKey(Qt::Key(key_list.at(i)));
928 void VncView::reloadSettings()
931 left_zoom = settings.value("left_zoom", 0).toInt();
932 right_zoom = settings.value("right_zoom", 1).toInt();
933 disable_tapping = settings.value("disable_tapping", false).toBool();
935 bool always_show_local_cursor = settings.value("always_show_local_cursor", false).toBool();
936 if(always_show_local_cursor)
937 showDotCursor(CursorOn);
940 //convert commitString into keyevents
941 void VncView::inputMethodEvent(QInputMethodEvent *event)
943 //TODO handle replacements
944 //NOTE for the return key to work Qt needs to enable multiline input, which only works for Q(Plain)TextEdit
946 //kDebug(5011) << event->commitString() << "|" << event->preeditString() << "|" << event->replacementLength() << "|" << event->replacementStart();
947 QString letters = event->commitString();
948 for(int i = 0; i < letters.length(); i++) {
949 char k = letters.at(i).toLatin1(); //works with all 'normal' keys, not umlauts.
951 kDebug(5011) << "unhandled key";
954 vncThread.keyEvent(k, true);
955 vncThread.keyEvent(k, false);
960 #include "moc_vncview.cpp"