imported project
authorchristian <christian@christian-laptop.(none)>
Tue, 6 Jul 2010 21:18:22 +0000 (23:18 +0200)
committerchristian <christian@christian-laptop.(none)>
Tue, 6 Jul 2010 21:18:22 +0000 (23:18 +0200)
17 files changed:
src/main.cpp [new file with mode: 0644]
src/mainwindow.h [new file with mode: 0644]
src/remoteview.cpp [new file with mode: 0644]
src/remoteview.h [new file with mode: 0644]
src/rfb/default8x16.h [new file with mode: 0644]
src/rfb/keysym.h [new file with mode: 0644]
src/rfb/rfb.h [new file with mode: 0644]
src/rfb/rfbclient.h [new file with mode: 0644]
src/rfb/rfbconfig.h [new file with mode: 0644]
src/rfb/rfbint.h [new file with mode: 0644]
src/rfb/rfbproto.h [new file with mode: 0644]
src/rfb/rfbregion.h [new file with mode: 0755]
src/vncclientthread.cpp [new file with mode: 0644]
src/vncclientthread.h [new file with mode: 0644]
src/vncview.cpp [new file with mode: 0644]
src/vncview.h [new file with mode: 0644]
vnc.pro [new file with mode: 0644]

diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644 (file)
index 0000000..ad5ea07
--- /dev/null
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
+**
+** This file is part of KDE.
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; see the file COPYING. If not, write to
+** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+** Boston, MA 02110-1301, USA.
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QInputDialog>
+#include <QString>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+       QApplication app(argc, argv);
+
+       QString url;
+       int quality = 2;
+       QStringList arguments = QCoreApplication::arguments();
+       if (arguments.count() > 1) {
+               //Example: vnc://:password@server:1\n"
+               //"Optionally, you can define the quality as second argument (1-3, where 1 is the best). Default is 2.");
+
+               url = arguments.at(1);
+               if(arguments.count() > 2)
+                       quality = arguments.at(2).toInt();
+       } else {
+               url = QInputDialog::getText(0, "Connect to Host", "VNC Server:");
+               if(url.isEmpty()) { //dialog dismissed or nothing entered
+                       return 1;
+               }
+               url = "vnc://" + url;
+       }
+       MainWindow main(url, quality);
+       main.show();
+       return app.exec();
+}
diff --git a/src/mainwindow.h b/src/mainwindow.h
new file mode 100644 (file)
index 0000000..1b5cdbf
--- /dev/null
@@ -0,0 +1,105 @@
+
+#include <QtGui>
+
+#include <QX11Info>
+
+#include "vncview.h"
+
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+
+#include <iostream>
+
+class MainWindow : public QScrollArea {
+       Q_OBJECT
+private:
+       VncView *vnc_view;
+       QWidget *menu;
+       QPoint swipe_start;
+
+public:
+       MainWindow(QString url, int quality) : QScrollArea(0) {
+               swipe_start = QPoint(0,0);
+               setAttribute(Qt::WA_Maemo5StackedWindow);
+
+               vnc_view = new VncView(0, url, RemoteView::Quality(quality));
+               setWidget(vnc_view);
+
+               //set up menu
+               QMenuBar *menu = new QMenuBar(this);
+               QAction *scaling = new QAction("Rescale Remote Screen", this);
+               scaling->setCheckable(true);
+               scaling->setChecked(true);
+               menu->addAction(scaling);
+               QAction *about_action = new QAction("About", this);
+               menu->addAction(about_action);
+
+               //menu->setAttribute(Qt::WA_Maemo5StackedWindow);
+               //menu->hide();
+
+               connect(scaling, SIGNAL(toggled(bool)),
+                       vnc_view, SLOT(enableScaling(bool)));
+               connect(about_action, SIGNAL(triggered()),
+                       this, SLOT(about()));
+
+               grabZoomKeys(true);
+               setAttribute(Qt::WA_Maemo5AutoOrientation, true);
+               //setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
+
+               vnc_view->start();
+       }
+
+       void grabZoomKeys(bool grab)
+       {
+               unsigned long val = (grab)?1:0;
+               Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
+               if(!atom) {
+                       qWarning("Couldn't get zoom key atom");
+                       return;
+               }
+               XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER,
+                       32, PropModeReplace, reinterpret_cast<unsigned char *>(&val), 1);
+       }
+       void closeEvent(QCloseEvent*) {
+               hide();
+               grabZoomKeys(false);
+               vnc_view->startQuitting();
+       }
+public slots:
+       void about() {
+               QMessageBox::about(this, tr("About Presence VNC"),
+                       tr("<center><h1>Presence VNC 0.1 alpha</h1>\
+A touch screen friendly VNC client\
+<small><p>&copy;2010 Christian Pulvermacher &lt;pulvermacher@gmx.de&gt</p>\
+<p>Based on KRDC, &copy; 2007-2008 Urs Wolfer</small></center>\
+<p>This program is free software; License: <a href=\"http://www.gnu.org/licenses/gpl-2.0.html\">GNU GPL 2</a> or later.</p>"));
+       }
+
+protected:
+/* swipe not used, and doesn't work without scaling anyway :/
+       virtual bool event(QEvent *event) {
+               if(event->type() == QEvent::MouseMove) {
+                       QMouseEvent *ev = dynamic_cast<QMouseEvent* >(event);
+                       if(!swipe_start.isNull()) {
+                               QPoint diff = swipe_start - ev->pos();
+                               const int swipe_dist = 60;
+                               if(diff.x() > swipe_dist and diff.y() < swipe_dist and diff.y() > -swipe_dist) { //
+                                       menu->show();
+                                       swipe_start = QPoint(0,0);
+                               }
+                       } else if((width() - ev->x()) < 10) {
+                               swipe_start = ev->pos();
+                       }
+                       std::cout << "mousex: " << width() - ev->x() << "\n";
+                       //TODO: make scrolling over border result in wheel events? i get weird (out of range) mouse events when that happens
+                       return true;
+               } else if(event->type() == QEvent::MouseButtonRelease) {
+                       swipe_start = QPoint(0,0);
+                       return true;
+               } else {
+//                     std::cout << "event " << event->type() << "\n";
+                       return QScrollArea::event(event);
+               }
+       }
+       */
+};
diff --git a/src/remoteview.cpp b/src/remoteview.cpp
new file mode 100644 (file)
index 0000000..0580a58
--- /dev/null
@@ -0,0 +1,278 @@
+/****************************************************************************
+**
+** Copyright (C) 2002-2003 Tim Jansen <tim@tjansen.de>
+** Copyright (C) 2007-2008 Urs Wolfer <uwolfer @ kde.org>
+**
+** This file is part of KDE.
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; see the file COPYING. If not, write to
+** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+** Boston, MA 02110-1301, USA.
+**
+****************************************************************************/
+
+#include "remoteview.h"
+
+#ifndef QTONLY
+    #include <KDebug>
+    #include <KStandardDirs>
+#endif
+
+#include <QBitmap>
+
+RemoteView::RemoteView(QWidget *parent)
+        : QWidget(parent),
+        m_status(Disconnected),
+        m_host(QString()),
+        m_port(0),
+        m_viewOnly(false),
+        m_grabAllKeys(false),
+        m_scale(true),
+        m_keyboardIsGrabbed(false),
+#ifndef QTONLY
+        m_wallet(0),
+#endif
+        m_dotCursorState(CursorOff)
+{
+}
+
+RemoteView::~RemoteView()
+{
+#ifndef QTONLY
+    delete m_wallet;
+#endif
+}
+
+RemoteView::RemoteStatus RemoteView::status()
+{
+    return m_status;
+}
+
+void RemoteView::setStatus(RemoteView::RemoteStatus s)
+{
+    if (m_status == s)
+        return;
+
+    if (((1+ m_status) != s) && (s != Disconnected)) {
+        // follow state transition rules
+
+        if (s == Disconnecting) {
+            if (m_status == Disconnected)
+                return;
+        } else {
+            Q_ASSERT(((int) s) >= 0);
+            if (m_status > s) {
+                m_status = Disconnected;
+                emit statusChanged(Disconnected);
+            }
+            // smooth state transition
+            RemoteStatus origState = m_status;
+            for (int i = origState; i < s; ++i) {
+                m_status = (RemoteStatus) i;
+                emit statusChanged((RemoteStatus) i);
+            }
+        }
+    }
+    m_status = s;
+    emit statusChanged(m_status);
+}
+
+bool RemoteView::supportsScaling() const
+{
+    return false;
+}
+
+bool RemoteView::supportsLocalCursor() const
+{
+    return false;
+}
+
+QString RemoteView::host()
+{
+    return m_host;
+}
+
+QSize RemoteView::framebufferSize()
+{
+    return QSize(0, 0);
+}
+
+void RemoteView::startQuitting()
+{
+}
+
+bool RemoteView::isQuitting()
+{
+    return false;
+}
+
+int RemoteView::port()
+{
+    return m_port;
+}
+
+void RemoteView::updateConfiguration()
+{
+}
+
+void RemoteView::keyEvent(QKeyEvent *)
+{
+}
+
+bool RemoteView::viewOnly()
+{
+    return m_viewOnly;
+}
+
+void RemoteView::setViewOnly(bool viewOnly)
+{
+    m_viewOnly = viewOnly;
+}
+
+bool RemoteView::grabAllKeys()
+{
+    return m_grabAllKeys;
+}
+
+void RemoteView::setGrabAllKeys(bool grabAllKeys)
+{
+    m_grabAllKeys = grabAllKeys;
+
+    if (grabAllKeys) {
+        m_keyboardIsGrabbed = true;
+        grabKeyboard();
+    } else if (m_keyboardIsGrabbed) {
+        releaseKeyboard();
+    }
+}
+
+void RemoteView::showDotCursor(DotCursorState state)
+{
+    m_dotCursorState = state;
+}
+
+RemoteView::DotCursorState RemoteView::dotCursorState() const
+{
+    return m_dotCursorState;
+}
+
+bool RemoteView::scaling() const
+{
+    return m_scale;
+}
+
+void RemoteView::enableScaling(bool scale)
+{
+    m_scale = scale;
+}
+
+void RemoteView::switchFullscreen(bool)
+{
+}
+
+void RemoteView::scaleResize(int, int)
+{
+}
+
+KUrl RemoteView::url()
+{
+    return m_url;
+}
+
+#ifndef QTONLY
+QString RemoteView::readWalletPassword(bool fromUserNameOnly)
+{
+    const QString KRDCFOLDER = "KRDC";
+
+    window()->setDisabled(true); // WORKAROUND: disable inputs so users cannot close the current tab (see #181230)
+    m_wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), window()->winId());
+    window()->setDisabled(false);
+
+    if (m_wallet) {
+        bool walletOK = m_wallet->hasFolder(KRDCFOLDER);
+        if (!walletOK) {
+            walletOK = m_wallet->createFolder(KRDCFOLDER);
+            kDebug(5010) << "Wallet folder created";
+        }
+        if (walletOK) {
+            kDebug(5010) << "Wallet OK";
+            m_wallet->setFolder(KRDCFOLDER);
+            QString password;
+            
+            QString key;
+            if (fromUserNameOnly)
+                key = m_url.userName();
+            else
+                key = m_url.prettyUrl(KUrl::RemoveTrailingSlash);
+
+            if (m_wallet->hasEntry(key) &&
+                    !m_wallet->readPassword(key, password)) {
+                kDebug(5010) << "Password read OK";
+
+                return password;
+            }
+        }
+    }
+    return QString();
+}
+
+void RemoteView::saveWalletPassword(const QString &password, bool fromUserNameOnly)
+{
+    QString key;
+    if (fromUserNameOnly)
+        key = m_url.userName();
+    else
+        key = m_url.prettyUrl(KUrl::RemoveTrailingSlash);
+
+    if (m_wallet && m_wallet->isOpen()) {
+        kDebug(5010) << "Write wallet password";
+        m_wallet->writePassword(key, password);
+    }
+}
+#endif
+
+QCursor RemoteView::localDotCursor() const
+{
+#ifdef QTONLY
+    return QCursor(); //TODO
+#else
+    QBitmap cursorBitmap(KGlobal::dirs()->findResource("appdata",
+                                                       "pics/pointcursor.png"));
+    QBitmap cursorMask(KGlobal::dirs()->findResource("appdata",
+                                                     "pics/pointcursormask.png"));
+    return QCursor(cursorBitmap, cursorMask);
+#endif
+}
+
+void RemoteView::focusInEvent(QFocusEvent *event)
+{
+    if (m_grabAllKeys) {
+        m_keyboardIsGrabbed = true;
+        grabKeyboard();
+    }
+
+    QWidget::focusInEvent(event);
+}
+
+void RemoteView::focusOutEvent(QFocusEvent *event)
+{
+    if (m_grabAllKeys || m_keyboardIsGrabbed) {
+        m_keyboardIsGrabbed = false;
+        releaseKeyboard();
+    }
+
+    QWidget::focusOutEvent(event);
+}
+
+#include "moc_remoteview.cpp"
diff --git a/src/remoteview.h b/src/remoteview.h
new file mode 100644 (file)
index 0000000..b3d734f
--- /dev/null
@@ -0,0 +1,409 @@
+/****************************************************************************
+**
+** Copyright (C) 2002-2003 Tim Jansen <tim@tjansen.de>
+** Copyright (C) 2007-2008 Urs Wolfer <uwolfer @ kde.org>
+**
+** This file is part of KDE.
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; see the file COPYING. If not, write to
+** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+** Boston, MA 02110-1301, USA.
+**
+****************************************************************************/
+
+#ifndef REMOTEVIEW_H
+#define REMOTEVIEW_H
+
+#ifdef QTONLY
+    #include <QUrl>
+    #define KUrl QUrl
+    #define KDE_EXPORT
+#else
+    #include <KUrl>
+    #include <KWallet/Wallet>
+#endif
+
+#include <QWidget>
+
+class HostPreferences;
+
+/**
+ * Generic widget that displays a remote framebuffer.
+ * Implement this if you want to add another backend.
+ *
+ * Things to take care of:
+ * @li The RemoteView is responsible for its size. In
+ *     non-scaling mode, set the fixed size of the widget
+ *     to the remote resolution. In scaling mode, set the
+ *     maximum size to the remote size and minimum size to the
+ *     smallest resolution that your scaler can handle.
+ * @li if you override mouseMoveEvent()
+ *     you must ignore the QEvent, because the KRDC widget will
+ *     need it for stuff like toolbar auto-hide and bump
+ *     scrolling. If you use x11Event(), make sure that
+ *     MotionNotify events will be forwarded.
+ *
+ */
+class KDE_EXPORT RemoteView : public QWidget
+{
+    Q_OBJECT
+
+public:
+
+    Q_ENUMS(Quality)
+
+    enum Quality {
+        Unknown,
+        High,
+        Medium,
+        Low
+    };
+
+    /**
+    * Describes the state of a local cursor, if there is such a concept in the backend.
+    * With local cursors, there are two cursors: the cursor on the local machine (client),
+    * and the cursor on the remote machine (server). Because there is usually some lag,
+    * some backends show both cursors simultanously. In the VNC backend the local cursor
+    * is a dot and the remote cursor is the 'real' cursor, usually an arrow.
+    */
+
+    Q_ENUMS(DotCursorState)
+
+    enum DotCursorState {
+        CursorOn,  ///< Always show local cursor (and the remote one).
+        CursorOff, ///< Never show local cursor, only the remote one.
+        /// Try to measure the lag and enable the local cursor if the latency is too high.
+        CursorAuto
+    };
+
+    /**
+    * State of the connection. The state of the connection is returned
+    * by @ref RemoteView::status().
+    *
+    * Not every state transition is allowed. You are only allowed to transition
+    * a state to the following state, with three exceptions:
+    * @li You can move from every state directly to Disconnected
+    * @li You can move from every state except Disconnected to
+    *     Disconnecting
+    * @li You can move from Disconnected to Connecting
+    *
+    * @ref RemoteView::setStatus() will follow this rules for you.
+    * (If you add/remove a state here, you must adapt it)
+    */
+
+    Q_ENUMS(RemoteStatus)
+
+    enum RemoteStatus {
+        Connecting     = 0,
+        Authenticating = 1,
+        Preparing      = 2,
+        Connected      = 3,
+        Disconnecting  = -1,
+        Disconnected   = -2
+    };
+
+    Q_ENUMS(ErrorCode)
+
+    enum ErrorCode {
+        None = 0,
+        Internal,
+        Connection,
+        Protocol,
+        IO,
+        Name,
+        NoServer,
+        ServerBlocked,
+        Authentication
+    };
+
+    virtual ~RemoteView();
+
+    /**
+     * Checks whether the backend supports scaling. The
+     * default implementation returns false.
+     * @return true if scaling is supported
+     * @see scaling()
+     */
+    virtual bool supportsScaling() const;
+
+    /**
+     * Checks whether the widget is in scale mode. The
+     * default implementation always returns false.
+     * @return true if scaling is activated. Must always be
+     *         false if @ref supportsScaling() returns false
+     * @see supportsScaling()
+     */
+    virtual bool scaling() const;
+
+    /**
+     * Checks whether the backend supports the concept of local cursors. The
+     * default implementation returns false.
+     * @return true if local cursors are supported/known
+     * @see DotCursorState
+     * @see showDotCursor()
+     * @see dotCursorState()
+     */
+    virtual bool supportsLocalCursor() const;
+
+    /**
+     * Sets the state of the dot cursor, if supported by the backend.
+     * The default implementation does nothing.
+     * @param state the new state (CursorOn, CursorOff or
+     *        CursorAuto)
+     * @see dotCursorState()
+     * @see supportsLocalCursor()
+     */
+    virtual void showDotCursor(DotCursorState state);
+
+    /**
+     * Returns the state of the local cursor. The default implementation returns
+     * always CursorOff.
+     * @return true if local cursors are supported/known
+     * @see showDotCursor()
+     * @see supportsLocalCursor()
+     */
+    virtual DotCursorState dotCursorState() const;
+
+    /**
+     * Checks whether the view is in view-only mode. This means
+     * that all input is ignored.
+     */
+    virtual bool viewOnly();
+
+    /**
+     * Checks whether grabbing all possible keys is enabled.
+     */
+    virtual bool grabAllKeys();
+
+    /**
+     * Returns the resolution of the remote framebuffer.
+     * It should return a null @ref QSize when the size
+     * is not known.
+     * The backend must also emit a @ref framebufferSizeChanged()
+     * when the size of the framebuffer becomes available
+     * for the first time or the size changed.
+     * @return the remote framebuffer size, a null QSize
+     *         if unknown
+     */
+    virtual QSize framebufferSize();
+
+    /**
+     * Initiate the disconnection. This doesn't need to happen
+     * immediately. The call must not block.
+     * @see isQuitting()
+     */
+    virtual void startQuitting();
+
+    /**
+     * Checks whether the view is currently quitting.
+     * @return true if it is quitting
+     * @see startQuitting()
+     * @see setStatus()
+     */
+    virtual bool isQuitting();
+
+    /**
+     * @return the host the view is connected to
+     */
+    virtual QString host();
+
+    /**
+     * @return the port the view is connected to
+     */
+    virtual int port();
+
+    /**
+     * Initialize the view (for example by showing configuration
+     * dialogs to the user) and start connecting. Should not block
+     * without running the event loop (so displaying a dialog is ok).
+     * When the view starts connecting the application must call
+     * @ref setStatus() with the status Connecting.
+     * @return true if successful (so far), false
+     *         otherwise
+     * @see connected()
+     * @see disconnected()
+     * @see disconnectedError()
+     * @see statusChanged()
+     */
+    virtual bool start() = 0;
+    
+    /**
+     * Called when the configuration is changed.
+     * The default implementation does nothing.
+     */
+    virtual void updateConfiguration();
+    
+#ifndef QTONLY
+    /**
+     * Returns the current host preferences of this view.
+     */
+    virtual HostPreferences* hostPreferences() = 0;
+#endif
+    
+    /**
+     * Returns the current status of the connection.
+     * @return the status of the connection
+     * @see setStatus()
+     */
+    RemoteStatus status();
+
+    /**
+     * @return the current url
+     */
+    KUrl url();
+
+public slots:
+    /**
+     * Called to enable or disable scaling.
+     * Ignored if @ref supportsScaling() is false.
+     * The default implementation does nothing.
+     * @param s true to enable, false to disable.
+     * @see supportsScaling()
+     * @see scaling()
+     */
+    virtual void enableScaling(bool scale);
+
+    /**
+     * Enables/disables the view-only mode.
+     * Ignored if @ref supportsScaling() is false.
+     * The default implementation does nothing.
+     * @param viewOnly true to enable, false to disable.
+     * @see supportsScaling()
+     * @see viewOnly()
+     */
+    virtual void setViewOnly(bool viewOnly);
+
+    /**
+     * Enables/disables grabbing all possible keys.
+     * @param grabAllKeys true to enable, false to disable.
+     * Default is false.
+     * @see grabAllKeys()
+     */
+    virtual void setGrabAllKeys(bool grabAllKeys);
+
+    /**
+     * Called to let the backend know it when
+     * we switch from/to fullscreen.
+     * @param on true when switching to fullscreen,
+     *           false when switching from fullscreen.
+     */
+    virtual void switchFullscreen(bool on);
+
+    /**
+     * Sends a QKeyEvent to the remote server.
+     * @param event the key to send
+     */
+    virtual void keyEvent(QKeyEvent *event);
+
+    /**
+     * Called when the visible place changed so remote
+     * view can resize itself.
+     */
+    virtual void scaleResize(int w, int h);
+
+signals:
+    /**
+     * Emitted when the size of the remote screen changes. Also
+     * called when the size is known for the first time.
+     * @param x the width of the screen
+     * @param y the height of the screen
+     */
+    void framebufferSizeChanged(int w, int h);
+
+    /**
+     * Emitted when the view connected successfully.
+     */
+    void connected();
+
+    /**
+     * Emitted when the view disconnected without error.
+     */
+    void disconnected();
+
+    /**
+     * Emitted when the view disconnected with error.
+     */
+    void disconnectedError();
+
+    /**
+     * Emitted when the view has a specific error.
+     */
+    void errorMessage(const QString &title, const QString &message);
+    /**
+     * Emitted when the status of the view changed.
+     * @param s the new status
+        */
+    void statusChanged(RemoteView::RemoteStatus s);
+
+    /**
+     * Emitted when the password dialog is shown or hidden.
+     * @param b true when the dialog is shown, false when it has been hidden
+     */
+    void showingPasswordDialog(bool b);
+
+    /**
+     * Emitted when the mouse on the remote side has been moved.
+     * @param x the new x coordinate
+     * @param y the new y coordinate
+     * @param buttonMask the mask of mouse buttons (bit 0 for first mouse
+     *                   button, 1 for second button etc)a
+     */
+    void mouseStateChanged(int x, int y, int buttonMask);
+
+protected:
+    RemoteView(QWidget *parent = 0);
+
+    void focusInEvent(QFocusEvent *event);
+    void focusOutEvent(QFocusEvent *event);
+
+    /**
+     * The status of the remote view.
+     */
+    RemoteStatus m_status;
+
+    /**
+     * Set the status of the connection.
+     * Emits a statusChanged() signal.
+     * Note that the states need to be set in a certain order,
+     * see @ref Status. setStatus() will try to do this
+     * transition automatically, so if you are in Connecting
+     * and call setStatus(Preparing), setStatus() will
+     * emit a Authenticating and then Preparing.
+     * If you transition backwards, it will emit a
+     * Disconnected before doing the transition.
+     * @param s the new status
+     */
+    virtual void setStatus(RemoteStatus s);
+
+    QCursor localDotCursor() const;
+
+    QString m_host;
+    int m_port;
+    bool m_viewOnly;
+    bool m_grabAllKeys;
+    bool m_scale;
+    bool m_keyboardIsGrabbed;
+    KUrl m_url;
+
+#ifndef QTONLY
+    QString readWalletPassword(bool fromUserNameOnly = false);
+    void saveWalletPassword(const QString &password, bool fromUserNameOnly = false);
+    KWallet::Wallet *m_wallet;
+#endif
+
+    DotCursorState m_dotCursorState;
+};
+
+#endif
diff --git a/src/rfb/default8x16.h b/src/rfb/default8x16.h
new file mode 100644 (file)
index 0000000..252f411
--- /dev/null
@@ -0,0 +1,261 @@
+static unsigned char default8x16FontData[4096+1]={
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x7e,0x81,0xa5,0x81,0x81,0xbd,0x99,0x81,0x81,0x7e,0x00,0x00,0x00,0x00,
+0x00,0x00,0x7e,0xff,0xdb,0xff,0xff,0xc3,0xe7,0xff,0xff,0x7e,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x6c,0xfe,0xfe,0xfe,0xfe,0x7c,0x38,0x10,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x10,0x38,0x7c,0xfe,0x7c,0x38,0x10,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x18,0x3c,0x3c,0xe7,0xe7,0xe7,0x18,0x18,0x3c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x18,0x3c,0x7e,0xff,0xff,0x7e,0x18,0x18,0x3c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x3c,0x3c,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
+0xff,0xff,0xff,0xff,0xff,0xff,0xe7,0xc3,0xc3,0xe7,0xff,0xff,0xff,0xff,0xff,0xff,
+0x00,0x00,0x00,0x00,0x00,0x3c,0x66,0x42,0x42,0x66,0x3c,0x00,0x00,0x00,0x00,0x00,
+0xff,0xff,0xff,0xff,0xff,0xc3,0x99,0xbd,0xbd,0x99,0xc3,0xff,0xff,0xff,0xff,0xff,
+0x00,0x00,0x1e,0x0e,0x1a,0x32,0x78,0xcc,0xcc,0xcc,0xcc,0x78,0x00,0x00,0x00,0x00,
+0x00,0x00,0x3c,0x66,0x66,0x66,0x66,0x3c,0x18,0x7e,0x18,0x18,0x00,0x00,0x00,0x00,
+0x00,0x00,0x3f,0x33,0x3f,0x30,0x30,0x30,0x30,0x70,0xf0,0xe0,0x00,0x00,0x00,0x00,
+0x00,0x00,0x7f,0x63,0x7f,0x63,0x63,0x63,0x63,0x67,0xe7,0xe6,0xc0,0x00,0x00,0x00,
+0x00,0x00,0x00,0x18,0x18,0xdb,0x3c,0xe7,0x3c,0xdb,0x18,0x18,0x00,0x00,0x00,0x00,
+0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfe,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x00,0x00,0x00,
+0x00,0x02,0x06,0x0e,0x1e,0x3e,0xfe,0x3e,0x1e,0x0e,0x06,0x02,0x00,0x00,0x00,0x00,
+0x00,0x00,0x18,0x3c,0x7e,0x18,0x18,0x18,0x7e,0x3c,0x18,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x00,0x66,0x66,0x00,0x00,0x00,0x00,
+0x00,0x00,0x7f,0xdb,0xdb,0xdb,0x7b,0x1b,0x1b,0x1b,0x1b,0x1b,0x00,0x00,0x00,0x00,
+0x00,0x7c,0xc6,0x60,0x38,0x6c,0xc6,0xc6,0x6c,0x38,0x0c,0xc6,0x7c,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0xfe,0xfe,0xfe,0x00,0x00,0x00,0x00,
+0x00,0x00,0x18,0x3c,0x7e,0x18,0x18,0x18,0x7e,0x3c,0x18,0x7e,0x00,0x00,0x00,0x00,
+0x00,0x00,0x18,0x3c,0x7e,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x00,
+0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x7e,0x3c,0x18,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x18,0x0c,0xfe,0x0c,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x30,0x60,0xfe,0x60,0x30,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0xc0,0xc0,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x24,0x66,0xff,0x66,0x24,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x10,0x38,0x38,0x7c,0x7c,0xfe,0xfe,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0xfe,0xfe,0x7c,0x7c,0x38,0x38,0x10,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x18,0x3c,0x3c,0x3c,0x18,0x18,0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00,
+0x00,0x66,0x66,0x66,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x6c,0x6c,0xfe,0x6c,0x6c,0x6c,0xfe,0x6c,0x6c,0x00,0x00,0x00,0x00,
+0x18,0x18,0x7c,0xc6,0xc2,0xc0,0x7c,0x06,0x06,0x86,0xc6,0x7c,0x18,0x18,0x00,0x00,
+0x00,0x00,0x00,0x00,0xc2,0xc6,0x0c,0x18,0x30,0x60,0xc6,0x86,0x00,0x00,0x00,0x00,
+0x00,0x00,0x38,0x6c,0x6c,0x38,0x76,0xdc,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,
+0x00,0x30,0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x0c,0x18,0x30,0x30,0x30,0x30,0x30,0x30,0x18,0x0c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x30,0x18,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x18,0x30,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x66,0x3c,0xff,0x3c,0x66,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x7e,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x18,0x30,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x02,0x06,0x0c,0x18,0x30,0x60,0xc0,0x80,0x00,0x00,0x00,0x00,
+0x00,0x00,0x7c,0xc6,0xc6,0xce,0xde,0xf6,0xe6,0xc6,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x18,0x38,0x78,0x18,0x18,0x18,0x18,0x18,0x18,0x7e,0x00,0x00,0x00,0x00,
+0x00,0x00,0x7c,0xc6,0x06,0x0c,0x18,0x30,0x60,0xc0,0xc6,0xfe,0x00,0x00,0x00,0x00,
+0x00,0x00,0x7c,0xc6,0x06,0x06,0x3c,0x06,0x06,0x06,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x0c,0x1c,0x3c,0x6c,0xcc,0xfe,0x0c,0x0c,0x0c,0x1e,0x00,0x00,0x00,0x00,
+0x00,0x00,0xfe,0xc0,0xc0,0xc0,0xfc,0x06,0x06,0x06,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x38,0x60,0xc0,0xc0,0xfc,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0xfe,0xc6,0x06,0x06,0x0c,0x18,0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00,
+0x00,0x00,0x7c,0xc6,0xc6,0xc6,0x7c,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x7c,0xc6,0xc6,0xc6,0x7e,0x06,0x06,0x06,0x0c,0x78,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x30,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x06,0x0c,0x18,0x30,0x60,0x30,0x18,0x0c,0x06,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x60,0x30,0x18,0x0c,0x06,0x0c,0x18,0x30,0x60,0x00,0x00,0x00,0x00,
+0x00,0x00,0x7c,0xc6,0xc6,0x0c,0x18,0x18,0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00,
+0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xde,0xde,0xde,0xdc,0xc0,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x10,0x38,0x6c,0xc6,0xc6,0xfe,0xc6,0xc6,0xc6,0xc6,0x00,0x00,0x00,0x00,
+0x00,0x00,0xfc,0x66,0x66,0x66,0x7c,0x66,0x66,0x66,0x66,0xfc,0x00,0x00,0x00,0x00,
+0x00,0x00,0x3c,0x66,0xc2,0xc0,0xc0,0xc0,0xc0,0xc2,0x66,0x3c,0x00,0x00,0x00,0x00,
+0x00,0x00,0xf8,0x6c,0x66,0x66,0x66,0x66,0x66,0x66,0x6c,0xf8,0x00,0x00,0x00,0x00,
+0x00,0x00,0xfe,0x66,0x62,0x68,0x78,0x68,0x60,0x62,0x66,0xfe,0x00,0x00,0x00,0x00,
+0x00,0x00,0xfe,0x66,0x62,0x68,0x78,0x68,0x60,0x60,0x60,0xf0,0x00,0x00,0x00,0x00,
+0x00,0x00,0x3c,0x66,0xc2,0xc0,0xc0,0xde,0xc6,0xc6,0x66,0x3a,0x00,0x00,0x00,0x00,
+0x00,0x00,0xc6,0xc6,0xc6,0xc6,0xfe,0xc6,0xc6,0xc6,0xc6,0xc6,0x00,0x00,0x00,0x00,
+0x00,0x00,0x3c,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x3c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x1e,0x0c,0x0c,0x0c,0x0c,0x0c,0xcc,0xcc,0xcc,0x78,0x00,0x00,0x00,0x00,
+0x00,0x00,0xe6,0x66,0x66,0x6c,0x78,0x78,0x6c,0x66,0x66,0xe6,0x00,0x00,0x00,0x00,
+0x00,0x00,0xf0,0x60,0x60,0x60,0x60,0x60,0x60,0x62,0x66,0xfe,0x00,0x00,0x00,0x00,
+0x00,0x00,0xc3,0xe7,0xff,0xff,0xdb,0xc3,0xc3,0xc3,0xc3,0xc3,0x00,0x00,0x00,0x00,
+0x00,0x00,0xc6,0xe6,0xf6,0xfe,0xde,0xce,0xc6,0xc6,0xc6,0xc6,0x00,0x00,0x00,0x00,
+0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0xfc,0x66,0x66,0x66,0x7c,0x60,0x60,0x60,0x60,0xf0,0x00,0x00,0x00,0x00,
+0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xd6,0xde,0x7c,0x0c,0x0e,0x00,0x00,
+0x00,0x00,0xfc,0x66,0x66,0x66,0x7c,0x6c,0x66,0x66,0x66,0xe6,0x00,0x00,0x00,0x00,
+0x00,0x00,0x7c,0xc6,0xc6,0x60,0x38,0x0c,0x06,0xc6,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0xff,0xdb,0x99,0x18,0x18,0x18,0x18,0x18,0x18,0x3c,0x00,0x00,0x00,0x00,
+0x00,0x00,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0xc3,0xc3,0xc3,0xc3,0xc3,0xc3,0xc3,0x66,0x3c,0x18,0x00,0x00,0x00,0x00,
+0x00,0x00,0xc3,0xc3,0xc3,0xc3,0xc3,0xdb,0xdb,0xff,0x66,0x66,0x00,0x00,0x00,0x00,
+0x00,0x00,0xc3,0xc3,0x66,0x3c,0x18,0x18,0x3c,0x66,0xc3,0xc3,0x00,0x00,0x00,0x00,
+0x00,0x00,0xc3,0xc3,0xc3,0x66,0x3c,0x18,0x18,0x18,0x18,0x3c,0x00,0x00,0x00,0x00,
+0x00,0x00,0xff,0xc3,0x86,0x0c,0x18,0x30,0x60,0xc1,0xc3,0xff,0x00,0x00,0x00,0x00,
+0x00,0x00,0x3c,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x3c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x80,0xc0,0xe0,0x70,0x38,0x1c,0x0e,0x06,0x02,0x00,0x00,0x00,0x00,
+0x00,0x00,0x3c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x3c,0x00,0x00,0x00,0x00,
+0x10,0x38,0x6c,0xc6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x00,0x00,
+0x30,0x30,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x78,0x0c,0x7c,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,
+0x00,0x00,0xe0,0x60,0x60,0x78,0x6c,0x66,0x66,0x66,0x66,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x7c,0xc6,0xc0,0xc0,0xc0,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x1c,0x0c,0x0c,0x3c,0x6c,0xcc,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x7c,0xc6,0xfe,0xc0,0xc0,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x38,0x6c,0x64,0x60,0xf0,0x60,0x60,0x60,0x60,0xf0,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0xcc,0xcc,0x7c,0x0c,0xcc,0x78,0x00,
+0x00,0x00,0xe0,0x60,0x60,0x6c,0x76,0x66,0x66,0x66,0x66,0xe6,0x00,0x00,0x00,0x00,
+0x00,0x00,0x18,0x18,0x00,0x38,0x18,0x18,0x18,0x18,0x18,0x3c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x06,0x06,0x00,0x0e,0x06,0x06,0x06,0x06,0x06,0x06,0x66,0x66,0x3c,0x00,
+0x00,0x00,0xe0,0x60,0x60,0x66,0x6c,0x78,0x78,0x6c,0x66,0xe6,0x00,0x00,0x00,0x00,
+0x00,0x00,0x38,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x3c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0xe6,0xff,0xdb,0xdb,0xdb,0xdb,0xdb,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0xdc,0x66,0x66,0x66,0x66,0x66,0x66,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0xdc,0x66,0x66,0x66,0x66,0x66,0x7c,0x60,0x60,0xf0,0x00,
+0x00,0x00,0x00,0x00,0x00,0x76,0xcc,0xcc,0xcc,0xcc,0xcc,0x7c,0x0c,0x0c,0x1e,0x00,
+0x00,0x00,0x00,0x00,0x00,0xdc,0x76,0x66,0x60,0x60,0x60,0xf0,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x7c,0xc6,0x60,0x38,0x0c,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x10,0x30,0x30,0xfc,0x30,0x30,0x30,0x30,0x36,0x1c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0xc3,0xc3,0xc3,0xc3,0x66,0x3c,0x18,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0xc3,0xc3,0xc3,0xdb,0xdb,0xff,0x66,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0xc3,0x66,0x3c,0x18,0x3c,0x66,0xc3,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x7e,0x06,0x0c,0xf8,0x00,
+0x00,0x00,0x00,0x00,0x00,0xfe,0xcc,0x18,0x30,0x60,0xc6,0xfe,0x00,0x00,0x00,0x00,
+0x00,0x00,0x0e,0x18,0x18,0x18,0x70,0x18,0x18,0x18,0x18,0x0e,0x00,0x00,0x00,0x00,
+0x00,0x00,0x18,0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x00,
+0x00,0x00,0x70,0x18,0x18,0x18,0x0e,0x18,0x18,0x18,0x18,0x70,0x00,0x00,0x00,0x00,
+0x00,0x00,0x76,0xdc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x10,0x38,0x6c,0xc6,0xc6,0xc6,0xfe,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x3c,0x66,0xc2,0xc0,0xc0,0xc0,0xc2,0x66,0x3c,0x0c,0x06,0x7c,0x00,0x00,
+0x00,0x00,0xcc,0x00,0x00,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,
+0x00,0x0c,0x18,0x30,0x00,0x7c,0xc6,0xfe,0xc0,0xc0,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x10,0x38,0x6c,0x00,0x78,0x0c,0x7c,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,
+0x00,0x00,0xcc,0x00,0x00,0x78,0x0c,0x7c,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,
+0x00,0x60,0x30,0x18,0x00,0x78,0x0c,0x7c,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,
+0x00,0x38,0x6c,0x38,0x00,0x78,0x0c,0x7c,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x3c,0x66,0x60,0x60,0x66,0x3c,0x0c,0x06,0x3c,0x00,0x00,0x00,
+0x00,0x10,0x38,0x6c,0x00,0x7c,0xc6,0xfe,0xc0,0xc0,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0xc6,0x00,0x00,0x7c,0xc6,0xfe,0xc0,0xc0,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x60,0x30,0x18,0x00,0x7c,0xc6,0xfe,0xc0,0xc0,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x66,0x00,0x00,0x38,0x18,0x18,0x18,0x18,0x18,0x3c,0x00,0x00,0x00,0x00,
+0x00,0x18,0x3c,0x66,0x00,0x38,0x18,0x18,0x18,0x18,0x18,0x3c,0x00,0x00,0x00,0x00,
+0x00,0x60,0x30,0x18,0x00,0x38,0x18,0x18,0x18,0x18,0x18,0x3c,0x00,0x00,0x00,0x00,
+0x00,0xc6,0x00,0x10,0x38,0x6c,0xc6,0xc6,0xfe,0xc6,0xc6,0xc6,0x00,0x00,0x00,0x00,
+0x38,0x6c,0x38,0x00,0x38,0x6c,0xc6,0xc6,0xfe,0xc6,0xc6,0xc6,0x00,0x00,0x00,0x00,
+0x18,0x30,0x60,0x00,0xfe,0x66,0x60,0x7c,0x60,0x60,0x66,0xfe,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x6e,0x3b,0x1b,0x7e,0xd8,0xdc,0x77,0x00,0x00,0x00,0x00,
+0x00,0x00,0x3e,0x6c,0xcc,0xcc,0xfe,0xcc,0xcc,0xcc,0xcc,0xce,0x00,0x00,0x00,0x00,
+0x00,0x10,0x38,0x6c,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0xc6,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x60,0x30,0x18,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x30,0x78,0xcc,0x00,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,
+0x00,0x60,0x30,0x18,0x00,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,
+0x00,0x00,0xc6,0x00,0x00,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x7e,0x06,0x0c,0x78,0x00,
+0x00,0xc6,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0xc6,0x00,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x18,0x18,0x7e,0xc3,0xc0,0xc0,0xc0,0xc3,0x7e,0x18,0x18,0x00,0x00,0x00,0x00,
+0x00,0x38,0x6c,0x64,0x60,0xf0,0x60,0x60,0x60,0x60,0xe6,0xfc,0x00,0x00,0x00,0x00,
+0x00,0x00,0xc3,0x66,0x3c,0x18,0xff,0x18,0xff,0x18,0x18,0x18,0x00,0x00,0x00,0x00,
+0x00,0xfc,0x66,0x66,0x7c,0x62,0x66,0x6f,0x66,0x66,0x66,0xf3,0x00,0x00,0x00,0x00,
+0x00,0x0e,0x1b,0x18,0x18,0x18,0x7e,0x18,0x18,0x18,0x18,0x18,0xd8,0x70,0x00,0x00,
+0x00,0x18,0x30,0x60,0x00,0x78,0x0c,0x7c,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,
+0x00,0x0c,0x18,0x30,0x00,0x38,0x18,0x18,0x18,0x18,0x18,0x3c,0x00,0x00,0x00,0x00,
+0x00,0x18,0x30,0x60,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x18,0x30,0x60,0x00,0xcc,0xcc,0xcc,0xcc,0xcc,0xcc,0x76,0x00,0x00,0x00,0x00,
+0x00,0x00,0x76,0xdc,0x00,0xdc,0x66,0x66,0x66,0x66,0x66,0x66,0x00,0x00,0x00,0x00,
+0x76,0xdc,0x00,0xc6,0xe6,0xf6,0xfe,0xde,0xce,0xc6,0xc6,0xc6,0x00,0x00,0x00,0x00,
+0x00,0x3c,0x6c,0x6c,0x3e,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x38,0x6c,0x6c,0x38,0x00,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x30,0x30,0x00,0x30,0x30,0x60,0xc0,0xc6,0xc6,0x7c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0xc0,0xc0,0xc0,0xc0,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0x06,0x06,0x06,0x06,0x00,0x00,0x00,0x00,0x00,
+0x00,0xc0,0xc0,0xc2,0xc6,0xcc,0x18,0x30,0x60,0xce,0x9b,0x06,0x0c,0x1f,0x00,0x00,
+0x00,0xc0,0xc0,0xc2,0xc6,0xcc,0x18,0x30,0x66,0xce,0x96,0x3e,0x06,0x06,0x00,0x00,
+0x00,0x00,0x18,0x18,0x00,0x18,0x18,0x18,0x3c,0x3c,0x3c,0x18,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x36,0x6c,0xd8,0x6c,0x36,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0xd8,0x6c,0x36,0x6c,0xd8,0x00,0x00,0x00,0x00,0x00,0x00,
+0x11,0x44,0x11,0x44,0x11,0x44,0x11,0x44,0x11,0x44,0x11,0x44,0x11,0x44,0x11,0x44,
+0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,
+0xdd,0x77,0xdd,0x77,0xdd,0x77,0xdd,0x77,0xdd,0x77,0xdd,0x77,0xdd,0x77,0xdd,0x77,
+0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x18,0x18,0x18,0x18,0x18,0x18,0x18,0xf8,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x18,0x18,0x18,0x18,0x18,0xf8,0x18,0xf8,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x36,0x36,0x36,0x36,0x36,0x36,0x36,0xf6,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
+0x00,0x00,0x00,0x00,0x00,0xf8,0x18,0xf8,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x36,0x36,0x36,0x36,0x36,0xf6,0x06,0xf6,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
+0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
+0x00,0x00,0x00,0x00,0x00,0xfe,0x06,0xf6,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
+0x36,0x36,0x36,0x36,0x36,0xf6,0x06,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x36,0x36,0x36,0x36,0x36,0x36,0x36,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x18,0x18,0x18,0x18,0x18,0xf8,0x18,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x18,0x18,0x18,0x18,0x18,0x18,0x18,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x1f,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x18,0x18,0x18,0x18,0x18,0x18,0x18,0xff,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x18,0x18,0x18,0x18,0x18,0x1f,0x18,0x1f,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x37,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
+0x36,0x36,0x36,0x36,0x36,0x37,0x30,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x3f,0x30,0x37,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
+0x36,0x36,0x36,0x36,0x36,0xf7,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0xff,0x00,0xf7,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
+0x36,0x36,0x36,0x36,0x36,0x37,0x30,0x37,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
+0x00,0x00,0x00,0x00,0x00,0xff,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x36,0x36,0x36,0x36,0x36,0xf7,0x00,0xf7,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
+0x18,0x18,0x18,0x18,0x18,0xff,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x36,0x36,0x36,0x36,0x36,0x36,0x36,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0xff,0x00,0xff,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
+0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x18,0x18,0x18,0x18,0x18,0x1f,0x18,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x1f,0x18,0x1f,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
+0x36,0x36,0x36,0x36,0x36,0x36,0x36,0xff,0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x36,
+0x18,0x18,0x18,0x18,0x18,0xff,0x18,0xff,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x18,0x18,0x18,0x18,0x18,0x18,0x18,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,
+0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,
+0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x76,0xdc,0xd8,0xd8,0xd8,0xdc,0x76,0x00,0x00,0x00,0x00,
+0x00,0x00,0x78,0xcc,0xcc,0xcc,0xd8,0xcc,0xc6,0xc6,0xc6,0xcc,0x00,0x00,0x00,0x00,
+0x00,0x00,0xfe,0xc6,0xc6,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0xfe,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0xfe,0xc6,0x60,0x30,0x18,0x30,0x60,0xc6,0xfe,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x7e,0xd8,0xd8,0xd8,0xd8,0xd8,0x70,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x7c,0x60,0x60,0xc0,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x76,0xdc,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x7e,0x18,0x3c,0x66,0x66,0x66,0x3c,0x18,0x7e,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x38,0x6c,0xc6,0xc6,0xfe,0xc6,0xc6,0x6c,0x38,0x00,0x00,0x00,0x00,
+0x00,0x00,0x38,0x6c,0xc6,0xc6,0xc6,0x6c,0x6c,0x6c,0x6c,0xee,0x00,0x00,0x00,0x00,
+0x00,0x00,0x1e,0x30,0x18,0x0c,0x3e,0x66,0x66,0x66,0x66,0x3c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x7e,0xdb,0xdb,0xdb,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x03,0x06,0x7e,0xdb,0xdb,0xf3,0x7e,0x60,0xc0,0x00,0x00,0x00,0x00,
+0x00,0x00,0x1c,0x30,0x60,0x60,0x7c,0x60,0x60,0x60,0x30,0x1c,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x7c,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0xc6,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0xfe,0x00,0x00,0xfe,0x00,0x00,0xfe,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x18,0x18,0x7e,0x18,0x18,0x00,0x00,0xff,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x30,0x18,0x0c,0x06,0x0c,0x18,0x30,0x00,0x7e,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x0c,0x18,0x30,0x60,0x30,0x18,0x0c,0x00,0x7e,0x00,0x00,0x00,0x00,
+0x00,0x00,0x0e,0x1b,0x1b,0x1b,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0xd8,0xd8,0xd8,0x70,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x7e,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x76,0xdc,0x00,0x76,0xdc,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x38,0x6c,0x6c,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x0f,0x0c,0x0c,0x0c,0x0c,0x0c,0xec,0x6c,0x6c,0x3c,0x1c,0x00,0x00,0x00,0x00,
+0x00,0xd8,0x6c,0x6c,0x6c,0x6c,0x6c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x70,0xd8,0x30,0x60,0xc8,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x7c,0x7c,0x7c,0x7c,0x7c,0x7c,0x7c,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+};
+static int default8x16FontMetaData[256*5+1]={
+0,8,16,0,0,16,8,16,0,0,32,8,16,0,0,48,8,16,0,0,64,8,16,0,0,80,8,16,0,0,96,8,16,0,0,112,8,16,0,0,128,8,16,0,0,144,8,16,0,0,160,8,16,0,0,176,8,16,0,0,192,8,16,0,0,208,8,16,0,0,224,8,16,0,0,240,8,16,0,0,256,8,16,0,0,272,8,16,0,0,288,8,16,0,0,304,8,16,0,0,320,8,16,0,0,336,8,16,0,0,352,8,16,0,0,368,8,16,0,0,384,8,16,0,0,400,8,16,0,0,416,8,16,0,0,432,8,16,0,0,448,8,16,0,0,464,8,16,0,0,480,8,16,0,0,496,8,16,0,0,512,8,16,0,0,528,8,16,0,0,544,8,16,0,0,560,8,16,0,0,576,8,16,0,0,592,8,16,0,0,608,8,16,0,0,624,8,16,0,0,640,8,16,0,0,656,8,16,0,0,672,8,16,0,0,688,8,16,0,0,704,8,16,0,0,720,8,16,0,0,736,8,16,0,0,752,8,16,0,0,768,8,16,0,0,784,8,16,0,0,800,8,16,0,0,816,8,16,0,0,832,8,16,0,0,848,8,16,0,0,864,8,16,0,0,880,8,16,0,0,896,8,16,0,0,912,8,16,0,0,928,8,16,0,0,944,8,16,0,0,960,8,16,0,0,976,8,16,0,0,992,8,16,0,0,1008,8,16,0,0,1024,8,16,0,0,1040,8,16,0,0,1056,8,16,0,0,1072,8,16,0,0,1088,8,16,0,0,1104,8,16,0,0,1120,8,16,0,0,1136,8,16,0,0,1152,8,16,0,0,1168,8,16,0,0,1184,8,16,0,0,1200,8,16,0,0,1216,8,16,0,0,1232,8,16,0,0,1248,8,16,0,0,1264,8,16,0,0,1280,8,16,0,0,1296,8,16,0,0,1312,8,16,0,0,1328,8,16,0,0,1344,8,16,0,0,1360,8,16,0,0,1376,8,16,0,0,1392,8,16,0,0,1408,8,16,0,0,1424,8,16,0,0,1440,8,16,0,0,1456,8,16,0,0,1472,8,16,0,0,1488,8,16,0,0,1504,8,16,0,0,1520,8,16,0,0,1536,8,16,0,0,1552,8,16,0,0,1568,8,16,0,0,1584,8,16,0,0,1600,8,16,0,0,1616,8,16,0,0,1632,8,16,0,0,1648,8,16,0,0,1664,8,16,0,0,1680,8,16,0,0,1696,8,16,0,0,1712,8,16,0,0,1728,8,16,0,0,1744,8,16,0,0,1760,8,16,0,0,1776,8,16,0,0,1792,8,16,0,0,1808,8,16,0,0,1824,8,16,0,0,1840,8,16,0,0,1856,8,16,0,0,1872,8,16,0,0,1888,8,16,0,0,1904,8,16,0,0,1920,8,16,0,0,1936,8,16,0,0,1952,8,16,0,0,1968,8,16,0,0,1984,8,16,0,0,2000,8,16,0,0,2016,8,16,0,0,2032,8,16,0,0,2048,8,16,0,0,2064,8,16,0,0,2080,8,16,0,0,2096,8,16,0,0,2112,8,16,0,0,2128,8,16,0,0,2144,8,16,0,0,2160,8,16,0,0,2176,8,16,0,0,2192,8,16,0,0,2208,8,16,0,0,2224,8,16,0,0,2240,8,16,0,0,2256,8,16,0,0,2272,8,16,0,0,2288,8,16,0,0,2304,8,16,0,0,2320,8,16,0,0,2336,8,16,0,0,2352,8,16,0,0,2368,8,16,0,0,2384,8,16,0,0,2400,8,16,0,0,2416,8,16,0,0,2432,8,16,0,0,2448,8,16,0,0,2464,8,16,0,0,2480,8,16,0,0,2496,8,16,0,0,2512,8,16,0,0,2528,8,16,0,0,2544,8,16,0,0,2560,8,16,0,0,2576,8,16,0,0,2592,8,16,0,0,2608,8,16,0,0,2624,8,16,0,0,2640,8,16,0,0,2656,8,16,0,0,2672,8,16,0,0,2688,8,16,0,0,2704,8,16,0,0,2720,8,16,0,0,2736,8,16,0,0,2752,8,16,0,0,2768,8,16,0,0,2784,8,16,0,0,2800,8,16,0,0,2816,8,16,0,0,2832,8,16,0,0,2848,8,16,0,0,2864,8,16,0,0,2880,8,16,0,0,2896,8,16,0,0,2912,8,16,0,0,2928,8,16,0,0,2944,8,16,0,0,2960,8,16,0,0,2976,8,16,0,0,2992,8,16,0,0,3008,8,16,0,0,3024,8,16,0,0,3040,8,16,0,0,3056,8,16,0,0,3072,8,16,0,0,3088,8,16,0,0,3104,8,16,0,0,3120,8,16,0,0,3136,8,16,0,0,3152,8,16,0,0,3168,8,16,0,0,3184,8,16,0,0,3200,8,16,0,0,3216,8,16,0,0,3232,8,16,0,0,3248,8,16,0,0,3264,8,16,0,0,3280,8,16,0,0,3296,8,16,0,0,3312,8,16,0,0,3328,8,16,0,0,3344,8,16,0,0,3360,8,16,0,0,3376,8,16,0,0,3392,8,16,0,0,3408,8,16,0,0,3424,8,16,0,0,3440,8,16,0,0,3456,8,16,0,0,3472,8,16,0,0,3488,8,16,0,0,3504,8,16,0,0,3520,8,16,0,0,3536,8,16,0,0,3552,8,16,0,0,3568,8,16,0,0,3584,8,16,0,0,3600,8,16,0,0,3616,8,16,0,0,3632,8,16,0,0,3648,8,16,0,0,3664,8,16,0,0,3680,8,16,0,0,3696,8,16,0,0,3712,8,16,0,0,3728,8,16,0,0,3744,8,16,0,0,3760,8,16,0,0,3776,8,16,0,0,3792,8,16,0,0,3808,8,16,0,0,3824,8,16,0,0,3840,8,16,0,0,3856,8,16,0,0,3872,8,16,0,0,3888,8,16,0,0,3904,8,16,0,0,3920,8,16,0,0,3936,8,16,0,0,3952,8,16,0,0,3968,8,16,0,0,3984,8,16,0,0,4000,8,16,0,0,4016,8,16,0,0,4032,8,16,0,0,4048,8,16,0,0,4064,8,16,0,0,4080,8,16,0,0,};
+static rfbFontData default8x16Font = { default8x16FontData, default8x16FontMetaData };
diff --git a/src/rfb/keysym.h b/src/rfb/keysym.h
new file mode 100644 (file)
index 0000000..219f95b
--- /dev/null
@@ -0,0 +1,1638 @@
+#ifndef XK_0
+
+/* $XConsortium: keysym.h,v 1.15 94/04/17 20:10:55 rws Exp $ */
+
+/***********************************************************
+
+Copyright (c) 1987  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/* default keysyms */
+#define XK_MISCELLANY
+#define XK_XKB_KEYS
+#define XK_LATIN1
+#define XK_LATIN2
+#define XK_LATIN3
+#define XK_LATIN4
+#define XK_GREEK
+
+/* $TOG: keysymdef.h /main/25 1997/06/21 10:54:51 kaleb $ */
+
+/***********************************************************
+Copyright (c) 1987, 1994  X Consortium
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of the X Consortium shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from the X Consortium.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#define XK_VoidSymbol          0xFFFFFF        /* void symbol */
+
+#ifdef XK_MISCELLANY
+/*
+ * TTY Functions, cleverly chosen to map to ascii, for convenience of
+ * programming, but could have been arbitrary (at the cost of lookup
+ * tables in client code.
+ */
+
+#define XK_BackSpace           0xFF08  /* back space, back char */
+#define XK_Tab                 0xFF09
+#define XK_Linefeed            0xFF0A  /* Linefeed, LF */
+#define XK_Clear               0xFF0B
+#define XK_Return              0xFF0D  /* Return, enter */
+#define XK_Pause               0xFF13  /* Pause, hold */
+#define XK_Scroll_Lock         0xFF14
+#define XK_Sys_Req             0xFF15
+#define XK_Escape              0xFF1B
+#define XK_Delete              0xFFFF  /* Delete, rubout */
+
+
+
+/* International & multi-key character composition */
+
+#define XK_Multi_key           0xFF20  /* Multi-key character compose */
+#define XK_SingleCandidate     0xFF3C
+#define XK_MultipleCandidate   0xFF3D
+#define XK_PreviousCandidate   0xFF3E
+
+/* Japanese keyboard support */
+
+#define XK_Kanji               0xFF21  /* Kanji, Kanji convert */
+#define XK_Muhenkan            0xFF22  /* Cancel Conversion */
+#define XK_Henkan_Mode         0xFF23  /* Start/Stop Conversion */
+#define XK_Henkan              0xFF23  /* Alias for Henkan_Mode */
+#define XK_Romaji              0xFF24  /* to Romaji */
+#define XK_Hiragana            0xFF25  /* to Hiragana */
+#define XK_Katakana            0xFF26  /* to Katakana */
+#define XK_Hiragana_Katakana   0xFF27  /* Hiragana/Katakana toggle */
+#define XK_Zenkaku             0xFF28  /* to Zenkaku */
+#define XK_Hankaku             0xFF29  /* to Hankaku */
+#define XK_Zenkaku_Hankaku     0xFF2A  /* Zenkaku/Hankaku toggle */
+#define XK_Touroku             0xFF2B  /* Add to Dictionary */
+#define XK_Massyo              0xFF2C  /* Delete from Dictionary */
+#define XK_Kana_Lock           0xFF2D  /* Kana Lock */
+#define XK_Kana_Shift          0xFF2E  /* Kana Shift */
+#define XK_Eisu_Shift          0xFF2F  /* Alphanumeric Shift */
+#define XK_Eisu_toggle         0xFF30  /* Alphanumeric toggle */
+#define XK_Zen_Koho            0xFF3D  /* Multiple/All Candidate(s) */
+#define XK_Mae_Koho            0xFF3E  /* Previous Candidate */
+
+/* 0xFF31 thru 0xFF3F are under XK_KOREAN */
+
+/* Cursor control & motion */
+
+#define XK_Home                        0xFF50
+#define XK_Left                        0xFF51  /* Move left, left arrow */
+#define XK_Up                  0xFF52  /* Move up, up arrow */
+#define XK_Right               0xFF53  /* Move right, right arrow */
+#define XK_Down                        0xFF54  /* Move down, down arrow */
+#define XK_Prior               0xFF55  /* Prior, previous */
+#define XK_Page_Up             0xFF55
+#define XK_Next                        0xFF56  /* Next */
+#define XK_Page_Down           0xFF56
+#define XK_End                 0xFF57  /* EOL */
+#define XK_Begin               0xFF58  /* BOL */
+
+
+/* Misc Functions */
+
+#define XK_Select              0xFF60  /* Select, mark */
+#define XK_Print               0xFF61
+#define XK_Execute             0xFF62  /* Execute, run, do */
+#define XK_Insert              0xFF63  /* Insert, insert here */
+#define XK_Undo                        0xFF65  /* Undo, oops */
+#define XK_Redo                        0xFF66  /* redo, again */
+#define XK_Menu                        0xFF67
+#define XK_Find                        0xFF68  /* Find, search */
+#define XK_Cancel              0xFF69  /* Cancel, stop, abort, exit */
+#define XK_Help                        0xFF6A  /* Help */
+#define XK_Break               0xFF6B
+#define XK_Mode_switch         0xFF7E  /* Character set switch */
+#define XK_script_switch        0xFF7E  /* Alias for mode_switch */
+#define XK_Num_Lock            0xFF7F
+
+/* Keypad Functions, keypad numbers cleverly chosen to map to ascii */
+
+#define XK_KP_Space            0xFF80  /* space */
+#define XK_KP_Tab              0xFF89
+#define XK_KP_Enter            0xFF8D  /* enter */
+#define XK_KP_F1               0xFF91  /* PF1, KP_A, ... */
+#define XK_KP_F2               0xFF92
+#define XK_KP_F3               0xFF93
+#define XK_KP_F4               0xFF94
+#define XK_KP_Home             0xFF95
+#define XK_KP_Left             0xFF96
+#define XK_KP_Up               0xFF97
+#define XK_KP_Right            0xFF98
+#define XK_KP_Down             0xFF99
+#define XK_KP_Prior            0xFF9A
+#define XK_KP_Page_Up          0xFF9A
+#define XK_KP_Next             0xFF9B
+#define XK_KP_Page_Down                0xFF9B
+#define XK_KP_End              0xFF9C
+#define XK_KP_Begin            0xFF9D
+#define XK_KP_Insert           0xFF9E
+#define XK_KP_Delete           0xFF9F
+#define XK_KP_Equal            0xFFBD  /* equals */
+#define XK_KP_Multiply         0xFFAA
+#define XK_KP_Add              0xFFAB
+#define XK_KP_Separator                0xFFAC  /* separator, often comma */
+#define XK_KP_Subtract         0xFFAD
+#define XK_KP_Decimal          0xFFAE
+#define XK_KP_Divide           0xFFAF
+
+#define XK_KP_0                        0xFFB0
+#define XK_KP_1                        0xFFB1
+#define XK_KP_2                        0xFFB2
+#define XK_KP_3                        0xFFB3
+#define XK_KP_4                        0xFFB4
+#define XK_KP_5                        0xFFB5
+#define XK_KP_6                        0xFFB6
+#define XK_KP_7                        0xFFB7
+#define XK_KP_8                        0xFFB8
+#define XK_KP_9                        0xFFB9
+
+
+
+/*
+ * Auxilliary Functions; note the duplicate definitions for left and right
+ * function keys;  Sun keyboards and a few other manufactures have such
+ * function key groups on the left and/or right sides of the keyboard.
+ * We've not found a keyboard with more than 35 function keys total.
+ */
+
+#define XK_F1                  0xFFBE
+#define XK_F2                  0xFFBF
+#define XK_F3                  0xFFC0
+#define XK_F4                  0xFFC1
+#define XK_F5                  0xFFC2
+#define XK_F6                  0xFFC3
+#define XK_F7                  0xFFC4
+#define XK_F8                  0xFFC5
+#define XK_F9                  0xFFC6
+#define XK_F10                 0xFFC7
+#define XK_F11                 0xFFC8
+#define XK_L1                  0xFFC8
+#define XK_F12                 0xFFC9
+#define XK_L2                  0xFFC9
+#define XK_F13                 0xFFCA
+#define XK_L3                  0xFFCA
+#define XK_F14                 0xFFCB
+#define XK_L4                  0xFFCB
+#define XK_F15                 0xFFCC
+#define XK_L5                  0xFFCC
+#define XK_F16                 0xFFCD
+#define XK_L6                  0xFFCD
+#define XK_F17                 0xFFCE
+#define XK_L7                  0xFFCE
+#define XK_F18                 0xFFCF
+#define XK_L8                  0xFFCF
+#define XK_F19                 0xFFD0
+#define XK_L9                  0xFFD0
+#define XK_F20                 0xFFD1
+#define XK_L10                 0xFFD1
+#define XK_F21                 0xFFD2
+#define XK_R1                  0xFFD2
+#define XK_F22                 0xFFD3
+#define XK_R2                  0xFFD3
+#define XK_F23                 0xFFD4
+#define XK_R3                  0xFFD4
+#define XK_F24                 0xFFD5
+#define XK_R4                  0xFFD5
+#define XK_F25                 0xFFD6
+#define XK_R5                  0xFFD6
+#define XK_F26                 0xFFD7
+#define XK_R6                  0xFFD7
+#define XK_F27                 0xFFD8
+#define XK_R7                  0xFFD8
+#define XK_F28                 0xFFD9
+#define XK_R8                  0xFFD9
+#define XK_F29                 0xFFDA
+#define XK_R9                  0xFFDA
+#define XK_F30                 0xFFDB
+#define XK_R10                 0xFFDB
+#define XK_F31                 0xFFDC
+#define XK_R11                 0xFFDC
+#define XK_F32                 0xFFDD
+#define XK_R12                 0xFFDD
+#define XK_F33                 0xFFDE
+#define XK_R13                 0xFFDE
+#define XK_F34                 0xFFDF
+#define XK_R14                 0xFFDF
+#define XK_F35                 0xFFE0
+#define XK_R15                 0xFFE0
+
+/* Modifiers */
+
+#define XK_Shift_L             0xFFE1  /* Left shift */
+#define XK_Shift_R             0xFFE2  /* Right shift */
+#define XK_Control_L           0xFFE3  /* Left control */
+#define XK_Control_R           0xFFE4  /* Right control */
+#define XK_Caps_Lock           0xFFE5  /* Caps lock */
+#define XK_Shift_Lock          0xFFE6  /* Shift lock */
+
+#define XK_Meta_L              0xFFE7  /* Left meta */
+#define XK_Meta_R              0xFFE8  /* Right meta */
+#define XK_Alt_L               0xFFE9  /* Left alt */
+#define XK_Alt_R               0xFFEA  /* Right alt */
+#define XK_Super_L             0xFFEB  /* Left super */
+#define XK_Super_R             0xFFEC  /* Right super */
+#define XK_Hyper_L             0xFFED  /* Left hyper */
+#define XK_Hyper_R             0xFFEE  /* Right hyper */
+#endif /* XK_MISCELLANY */
+
+/*
+ * ISO 9995 Function and Modifier Keys
+ * Byte 3 = 0xFE
+ */
+
+#ifdef XK_XKB_KEYS
+#define        XK_ISO_Lock                                     0xFE01
+#define        XK_ISO_Level2_Latch                             0xFE02
+#define        XK_ISO_Level3_Shift                             0xFE03
+#define        XK_ISO_Level3_Latch                             0xFE04
+#define        XK_ISO_Level3_Lock                              0xFE05
+#define        XK_ISO_Group_Shift              0xFF7E  /* Alias for mode_switch */
+#define        XK_ISO_Group_Latch                              0xFE06
+#define        XK_ISO_Group_Lock                               0xFE07
+#define        XK_ISO_Next_Group                               0xFE08
+#define        XK_ISO_Next_Group_Lock                          0xFE09
+#define        XK_ISO_Prev_Group                               0xFE0A
+#define        XK_ISO_Prev_Group_Lock                          0xFE0B
+#define        XK_ISO_First_Group                              0xFE0C
+#define        XK_ISO_First_Group_Lock                         0xFE0D
+#define        XK_ISO_Last_Group                               0xFE0E
+#define        XK_ISO_Last_Group_Lock                          0xFE0F
+
+#define        XK_ISO_Left_Tab                                 0xFE20
+#define        XK_ISO_Move_Line_Up                             0xFE21
+#define        XK_ISO_Move_Line_Down                           0xFE22
+#define        XK_ISO_Partial_Line_Up                          0xFE23
+#define        XK_ISO_Partial_Line_Down                        0xFE24
+#define        XK_ISO_Partial_Space_Left                       0xFE25
+#define        XK_ISO_Partial_Space_Right                      0xFE26
+#define        XK_ISO_Set_Margin_Left                          0xFE27
+#define        XK_ISO_Set_Margin_Right                         0xFE28
+#define        XK_ISO_Release_Margin_Left                      0xFE29
+#define        XK_ISO_Release_Margin_Right                     0xFE2A
+#define        XK_ISO_Release_Both_Margins                     0xFE2B
+#define        XK_ISO_Fast_Cursor_Left                         0xFE2C
+#define        XK_ISO_Fast_Cursor_Right                        0xFE2D
+#define        XK_ISO_Fast_Cursor_Up                           0xFE2E
+#define        XK_ISO_Fast_Cursor_Down                         0xFE2F
+#define        XK_ISO_Continuous_Underline                     0xFE30
+#define        XK_ISO_Discontinuous_Underline                  0xFE31
+#define        XK_ISO_Emphasize                                0xFE32
+#define        XK_ISO_Center_Object                            0xFE33
+#define        XK_ISO_Enter                                    0xFE34
+
+#define        XK_dead_grave                                   0xFE50
+#define        XK_dead_acute                                   0xFE51
+#define        XK_dead_circumflex                              0xFE52
+#define        XK_dead_tilde                                   0xFE53
+#define        XK_dead_macron                                  0xFE54
+#define        XK_dead_breve                                   0xFE55
+#define        XK_dead_abovedot                                0xFE56
+#define        XK_dead_diaeresis                               0xFE57
+#define        XK_dead_abovering                               0xFE58
+#define        XK_dead_doubleacute                             0xFE59
+#define        XK_dead_caron                                   0xFE5A
+#define        XK_dead_cedilla                                 0xFE5B
+#define        XK_dead_ogonek                                  0xFE5C
+#define        XK_dead_iota                                    0xFE5D
+#define        XK_dead_voiced_sound                            0xFE5E
+#define        XK_dead_semivoiced_sound                        0xFE5F
+#define        XK_dead_belowdot                                0xFE60
+
+#define        XK_First_Virtual_Screen                         0xFED0
+#define        XK_Prev_Virtual_Screen                          0xFED1
+#define        XK_Next_Virtual_Screen                          0xFED2
+#define        XK_Last_Virtual_Screen                          0xFED4
+#define        XK_Terminate_Server                             0xFED5
+
+#define        XK_AccessX_Enable                               0xFE70
+#define        XK_AccessX_Feedback_Enable                      0xFE71
+#define        XK_RepeatKeys_Enable                            0xFE72
+#define        XK_SlowKeys_Enable                              0xFE73
+#define        XK_BounceKeys_Enable                            0xFE74
+#define        XK_StickyKeys_Enable                            0xFE75
+#define        XK_MouseKeys_Enable                             0xFE76
+#define        XK_MouseKeys_Accel_Enable                       0xFE77
+#define        XK_Overlay1_Enable                              0xFE78
+#define        XK_Overlay2_Enable                              0xFE79
+#define        XK_AudibleBell_Enable                           0xFE7A
+
+#define        XK_Pointer_Left                                 0xFEE0
+#define        XK_Pointer_Right                                0xFEE1
+#define        XK_Pointer_Up                                   0xFEE2
+#define        XK_Pointer_Down                                 0xFEE3
+#define        XK_Pointer_UpLeft                               0xFEE4
+#define        XK_Pointer_UpRight                              0xFEE5
+#define        XK_Pointer_DownLeft                             0xFEE6
+#define        XK_Pointer_DownRight                            0xFEE7
+#define        XK_Pointer_Button_Dflt                          0xFEE8
+#define        XK_Pointer_Button1                              0xFEE9
+#define        XK_Pointer_Button2                              0xFEEA
+#define        XK_Pointer_Button3                              0xFEEB
+#define        XK_Pointer_Button4                              0xFEEC
+#define        XK_Pointer_Button5                              0xFEED
+#define        XK_Pointer_DblClick_Dflt                        0xFEEE
+#define        XK_Pointer_DblClick1                            0xFEEF
+#define        XK_Pointer_DblClick2                            0xFEF0
+#define        XK_Pointer_DblClick3                            0xFEF1
+#define        XK_Pointer_DblClick4                            0xFEF2
+#define        XK_Pointer_DblClick5                            0xFEF3
+#define        XK_Pointer_Drag_Dflt                            0xFEF4
+#define        XK_Pointer_Drag1                                0xFEF5
+#define        XK_Pointer_Drag2                                0xFEF6
+#define        XK_Pointer_Drag3                                0xFEF7
+#define        XK_Pointer_Drag4                                0xFEF8
+#define        XK_Pointer_Drag5                                0xFEFD
+
+#define        XK_Pointer_EnableKeys                           0xFEF9
+#define        XK_Pointer_Accelerate                           0xFEFA
+#define        XK_Pointer_DfltBtnNext                          0xFEFB
+#define        XK_Pointer_DfltBtnPrev                          0xFEFC
+
+#endif
+
+/*
+ * 3270 Terminal Keys
+ * Byte 3 = 0xFD
+ */
+
+#ifdef XK_3270
+#define XK_3270_Duplicate      0xFD01
+#define XK_3270_FieldMark      0xFD02
+#define XK_3270_Right2         0xFD03
+#define XK_3270_Left2          0xFD04
+#define XK_3270_BackTab        0xFD05
+#define XK_3270_EraseEOF       0xFD06
+#define XK_3270_EraseInput     0xFD07
+#define XK_3270_Reset          0xFD08
+#define XK_3270_Quit           0xFD09
+#define XK_3270_PA1            0xFD0A
+#define XK_3270_PA2            0xFD0B
+#define XK_3270_PA3            0xFD0C
+#define XK_3270_Test           0xFD0D
+#define XK_3270_Attn           0xFD0E
+#define XK_3270_CursorBlink    0xFD0F
+#define XK_3270_AltCursor      0xFD10
+#define XK_3270_KeyClick       0xFD11
+#define XK_3270_Jump           0xFD12
+#define XK_3270_Ident          0xFD13
+#define XK_3270_Rule           0xFD14
+#define XK_3270_Copy           0xFD15
+#define XK_3270_Play           0xFD16
+#define XK_3270_Setup          0xFD17
+#define XK_3270_Record         0xFD18
+#define XK_3270_ChangeScreen   0xFD19
+#define XK_3270_DeleteWord     0xFD1A
+#define XK_3270_ExSelect       0xFD1B
+#define XK_3270_CursorSelect   0xFD1C
+#define XK_3270_PrintScreen    0xFD1D
+#define XK_3270_Enter          0xFD1E
+#endif
+
+/*
+ *  Latin 1
+ *  Byte 3 = 0
+ */
+#ifdef XK_LATIN1
+#define XK_space               0x020
+#define XK_exclam              0x021
+#define XK_quotedbl            0x022
+#define XK_numbersign          0x023
+#define XK_dollar              0x024
+#define XK_percent             0x025
+#define XK_ampersand           0x026
+#define XK_apostrophe          0x027
+#define XK_quoteright          0x027   /* deprecated */
+#define XK_parenleft           0x028
+#define XK_parenright          0x029
+#define XK_asterisk            0x02a
+#define XK_plus                0x02b
+#define XK_comma               0x02c
+#define XK_minus               0x02d
+#define XK_period              0x02e
+#define XK_slash               0x02f
+#define XK_0                   0x030
+#define XK_1                   0x031
+#define XK_2                   0x032
+#define XK_3                   0x033
+#define XK_4                   0x034
+#define XK_5                   0x035
+#define XK_6                   0x036
+#define XK_7                   0x037
+#define XK_8                   0x038
+#define XK_9                   0x039
+#define XK_colon               0x03a
+#define XK_semicolon           0x03b
+#define XK_less                0x03c
+#define XK_equal               0x03d
+#define XK_greater             0x03e
+#define XK_question            0x03f
+#define XK_at                  0x040
+#define XK_A                   0x041
+#define XK_B                   0x042
+#define XK_C                   0x043
+#define XK_D                   0x044
+#define XK_E                   0x045
+#define XK_F                   0x046
+#define XK_G                   0x047
+#define XK_H                   0x048
+#define XK_I                   0x049
+#define XK_J                   0x04a
+#define XK_K                   0x04b
+#define XK_L                   0x04c
+#define XK_M                   0x04d
+#define XK_N                   0x04e
+#define XK_O                   0x04f
+#define XK_P                   0x050
+#define XK_Q                   0x051
+#define XK_R                   0x052
+#define XK_S                   0x053
+#define XK_T                   0x054
+#define XK_U                   0x055
+#define XK_V                   0x056
+#define XK_W                   0x057
+#define XK_X                   0x058
+#define XK_Y                   0x059
+#define XK_Z                   0x05a
+#define XK_bracketleft         0x05b
+#define XK_backslash           0x05c
+#define XK_bracketright        0x05d
+#define XK_asciicircum         0x05e
+#define XK_underscore          0x05f
+#define XK_grave               0x060
+#define XK_quoteleft           0x060   /* deprecated */
+#define XK_a                   0x061
+#define XK_b                   0x062
+#define XK_c                   0x063
+#define XK_d                   0x064
+#define XK_e                   0x065
+#define XK_f                   0x066
+#define XK_g                   0x067
+#define XK_h                   0x068
+#define XK_i                   0x069
+#define XK_j                   0x06a
+#define XK_k                   0x06b
+#define XK_l                   0x06c
+#define XK_m                   0x06d
+#define XK_n                   0x06e
+#define XK_o                   0x06f
+#define XK_p                   0x070
+#define XK_q                   0x071
+#define XK_r                   0x072
+#define XK_s                   0x073
+#define XK_t                   0x074
+#define XK_u                   0x075
+#define XK_v                   0x076
+#define XK_w                   0x077
+#define XK_x                   0x078
+#define XK_y                   0x079
+#define XK_z                   0x07a
+#define XK_braceleft           0x07b
+#define XK_bar                 0x07c
+#define XK_braceright          0x07d
+#define XK_asciitilde          0x07e
+
+#define XK_nobreakspace        0x0a0
+#define XK_exclamdown          0x0a1
+#define XK_cent                       0x0a2
+#define XK_sterling            0x0a3
+#define XK_currency            0x0a4
+#define XK_yen                 0x0a5
+#define XK_brokenbar           0x0a6
+#define XK_section             0x0a7
+#define XK_diaeresis           0x0a8
+#define XK_copyright           0x0a9
+#define XK_ordfeminine         0x0aa
+#define XK_guillemotleft       0x0ab   /* left angle quotation mark */
+#define XK_notsign             0x0ac
+#define XK_hyphen              0x0ad
+#define XK_registered          0x0ae
+#define XK_macron              0x0af
+#define XK_degree              0x0b0
+#define XK_plusminus           0x0b1
+#define XK_twosuperior         0x0b2
+#define XK_threesuperior       0x0b3
+#define XK_acute               0x0b4
+#define XK_mu                  0x0b5
+#define XK_paragraph           0x0b6
+#define XK_periodcentered      0x0b7
+#define XK_cedilla             0x0b8
+#define XK_onesuperior         0x0b9
+#define XK_masculine           0x0ba
+#define XK_guillemotright      0x0bb   /* right angle quotation mark */
+#define XK_onequarter          0x0bc
+#define XK_onehalf             0x0bd
+#define XK_threequarters       0x0be
+#define XK_questiondown        0x0bf
+#define XK_Agrave              0x0c0
+#define XK_Aacute              0x0c1
+#define XK_Acircumflex         0x0c2
+#define XK_Atilde              0x0c3
+#define XK_Adiaeresis          0x0c4
+#define XK_Aring               0x0c5
+#define XK_AE                  0x0c6
+#define XK_Ccedilla            0x0c7
+#define XK_Egrave              0x0c8
+#define XK_Eacute              0x0c9
+#define XK_Ecircumflex         0x0ca
+#define XK_Ediaeresis          0x0cb
+#define XK_Igrave              0x0cc
+#define XK_Iacute              0x0cd
+#define XK_Icircumflex         0x0ce
+#define XK_Idiaeresis          0x0cf
+#define XK_ETH                 0x0d0
+#define XK_Eth                 0x0d0   /* deprecated */
+#define XK_Ntilde              0x0d1
+#define XK_Ograve              0x0d2
+#define XK_Oacute              0x0d3
+#define XK_Ocircumflex         0x0d4
+#define XK_Otilde              0x0d5
+#define XK_Odiaeresis          0x0d6
+#define XK_multiply            0x0d7
+#define XK_Ooblique            0x0d8
+#define XK_Ugrave              0x0d9
+#define XK_Uacute              0x0da
+#define XK_Ucircumflex         0x0db
+#define XK_Udiaeresis          0x0dc
+#define XK_Yacute              0x0dd
+#define XK_THORN               0x0de
+#define XK_Thorn               0x0de   /* deprecated */
+#define XK_ssharp              0x0df
+#define XK_agrave              0x0e0
+#define XK_aacute              0x0e1
+#define XK_acircumflex         0x0e2
+#define XK_atilde              0x0e3
+#define XK_adiaeresis          0x0e4
+#define XK_aring               0x0e5
+#define XK_ae                  0x0e6
+#define XK_ccedilla            0x0e7
+#define XK_egrave              0x0e8
+#define XK_eacute              0x0e9
+#define XK_ecircumflex         0x0ea
+#define XK_ediaeresis          0x0eb
+#define XK_igrave              0x0ec
+#define XK_iacute              0x0ed
+#define XK_icircumflex         0x0ee
+#define XK_idiaeresis          0x0ef
+#define XK_eth                 0x0f0
+#define XK_ntilde              0x0f1
+#define XK_ograve              0x0f2
+#define XK_oacute              0x0f3
+#define XK_ocircumflex         0x0f4
+#define XK_otilde              0x0f5
+#define XK_odiaeresis          0x0f6
+#define XK_division            0x0f7
+#define XK_oslash              0x0f8
+#define XK_ugrave              0x0f9
+#define XK_uacute              0x0fa
+#define XK_ucircumflex         0x0fb
+#define XK_udiaeresis          0x0fc
+#define XK_yacute              0x0fd
+#define XK_thorn               0x0fe
+#define XK_ydiaeresis          0x0ff
+#endif /* XK_LATIN1 */
+
+/*
+ *   Latin 2
+ *   Byte 3 = 1
+ */
+
+#ifdef XK_LATIN2
+#define XK_Aogonek             0x1a1
+#define XK_breve               0x1a2
+#define XK_Lstroke             0x1a3
+#define XK_Lcaron              0x1a5
+#define XK_Sacute              0x1a6
+#define XK_Scaron              0x1a9
+#define XK_Scedilla            0x1aa
+#define XK_Tcaron              0x1ab
+#define XK_Zacute              0x1ac
+#define XK_Zcaron              0x1ae
+#define XK_Zabovedot           0x1af
+#define XK_aogonek             0x1b1
+#define XK_ogonek              0x1b2
+#define XK_lstroke             0x1b3
+#define XK_lcaron              0x1b5
+#define XK_sacute              0x1b6
+#define XK_caron               0x1b7
+#define XK_scaron              0x1b9
+#define XK_scedilla            0x1ba
+#define XK_tcaron              0x1bb
+#define XK_zacute              0x1bc
+#define XK_doubleacute         0x1bd
+#define XK_zcaron              0x1be
+#define XK_zabovedot           0x1bf
+#define XK_Racute              0x1c0
+#define XK_Abreve              0x1c3
+#define XK_Lacute              0x1c5
+#define XK_Cacute              0x1c6
+#define XK_Ccaron              0x1c8
+#define XK_Eogonek             0x1ca
+#define XK_Ecaron              0x1cc
+#define XK_Dcaron              0x1cf
+#define XK_Dstroke             0x1d0
+#define XK_Nacute              0x1d1
+#define XK_Ncaron              0x1d2
+#define XK_Odoubleacute        0x1d5
+#define XK_Rcaron              0x1d8
+#define XK_Uring               0x1d9
+#define XK_Udoubleacute        0x1db
+#define XK_Tcedilla            0x1de
+#define XK_racute              0x1e0
+#define XK_abreve              0x1e3
+#define XK_lacute              0x1e5
+#define XK_cacute              0x1e6
+#define XK_ccaron              0x1e8
+#define XK_eogonek             0x1ea
+#define XK_ecaron              0x1ec
+#define XK_dcaron              0x1ef
+#define XK_dstroke             0x1f0
+#define XK_nacute              0x1f1
+#define XK_ncaron              0x1f2
+#define XK_odoubleacute        0x1f5
+#define XK_udoubleacute        0x1fb
+#define XK_rcaron              0x1f8
+#define XK_uring               0x1f9
+#define XK_tcedilla            0x1fe
+#define XK_abovedot            0x1ff
+#endif /* XK_LATIN2 */
+
+/*
+ *   Latin 3
+ *   Byte 3 = 2
+ */
+
+#ifdef XK_LATIN3
+#define XK_Hstroke             0x2a1
+#define XK_Hcircumflex         0x2a6
+#define XK_Iabovedot           0x2a9
+#define XK_Gbreve              0x2ab
+#define XK_Jcircumflex         0x2ac
+#define XK_hstroke             0x2b1
+#define XK_hcircumflex         0x2b6
+#define XK_idotless            0x2b9
+#define XK_gbreve              0x2bb
+#define XK_jcircumflex         0x2bc
+#define XK_Cabovedot           0x2c5
+#define XK_Ccircumflex         0x2c6
+#define XK_Gabovedot           0x2d5
+#define XK_Gcircumflex         0x2d8
+#define XK_Ubreve              0x2dd
+#define XK_Scircumflex         0x2de
+#define XK_cabovedot           0x2e5
+#define XK_ccircumflex         0x2e6
+#define XK_gabovedot           0x2f5
+#define XK_gcircumflex         0x2f8
+#define XK_ubreve              0x2fd
+#define XK_scircumflex         0x2fe
+#endif /* XK_LATIN3 */
+
+
+/*
+ *   Latin 4
+ *   Byte 3 = 3
+ */
+
+#ifdef XK_LATIN4
+#define XK_kra                 0x3a2
+#define XK_kappa               0x3a2   /* deprecated */
+#define XK_Rcedilla            0x3a3
+#define XK_Itilde              0x3a5
+#define XK_Lcedilla            0x3a6
+#define XK_Emacron             0x3aa
+#define XK_Gcedilla            0x3ab
+#define XK_Tslash              0x3ac
+#define XK_rcedilla            0x3b3
+#define XK_itilde              0x3b5
+#define XK_lcedilla            0x3b6
+#define XK_emacron             0x3ba
+#define XK_gcedilla            0x3bb
+#define XK_tslash              0x3bc
+#define XK_ENG                 0x3bd
+#define XK_eng                 0x3bf
+#define XK_Amacron             0x3c0
+#define XK_Iogonek             0x3c7
+#define XK_Eabovedot           0x3cc
+#define XK_Imacron             0x3cf
+#define XK_Ncedilla            0x3d1
+#define XK_Omacron             0x3d2
+#define XK_Kcedilla            0x3d3
+#define XK_Uogonek             0x3d9
+#define XK_Utilde              0x3dd
+#define XK_Umacron             0x3de
+#define XK_amacron             0x3e0
+#define XK_iogonek             0x3e7
+#define XK_eabovedot           0x3ec
+#define XK_imacron             0x3ef
+#define XK_ncedilla            0x3f1
+#define XK_omacron             0x3f2
+#define XK_kcedilla            0x3f3
+#define XK_uogonek             0x3f9
+#define XK_utilde              0x3fd
+#define XK_umacron             0x3fe
+#endif /* XK_LATIN4 */
+
+/*
+ * Katakana
+ * Byte 3 = 4
+ */
+
+#ifdef XK_KATAKANA
+#define XK_overline                                   0x47e
+#define XK_kana_fullstop                               0x4a1
+#define XK_kana_openingbracket                         0x4a2
+#define XK_kana_closingbracket                         0x4a3
+#define XK_kana_comma                                  0x4a4
+#define XK_kana_conjunctive                            0x4a5
+#define XK_kana_middledot                              0x4a5  /* deprecated */
+#define XK_kana_WO                                     0x4a6
+#define XK_kana_a                                      0x4a7
+#define XK_kana_i                                      0x4a8
+#define XK_kana_u                                      0x4a9
+#define XK_kana_e                                      0x4aa
+#define XK_kana_o                                      0x4ab
+#define XK_kana_ya                                     0x4ac
+#define XK_kana_yu                                     0x4ad
+#define XK_kana_yo                                     0x4ae
+#define XK_kana_tsu                                    0x4af
+#define XK_kana_tu                                     0x4af  /* deprecated */
+#define XK_prolongedsound                              0x4b0
+#define XK_kana_A                                      0x4b1
+#define XK_kana_I                                      0x4b2
+#define XK_kana_U                                      0x4b3
+#define XK_kana_E                                      0x4b4
+#define XK_kana_O                                      0x4b5
+#define XK_kana_KA                                     0x4b6
+#define XK_kana_KI                                     0x4b7
+#define XK_kana_KU                                     0x4b8
+#define XK_kana_KE                                     0x4b9
+#define XK_kana_KO                                     0x4ba
+#define XK_kana_SA                                     0x4bb
+#define XK_kana_SHI                                    0x4bc
+#define XK_kana_SU                                     0x4bd
+#define XK_kana_SE                                     0x4be
+#define XK_kana_SO                                     0x4bf
+#define XK_kana_TA                                     0x4c0
+#define XK_kana_CHI                                    0x4c1
+#define XK_kana_TI                                     0x4c1  /* deprecated */
+#define XK_kana_TSU                                    0x4c2
+#define XK_kana_TU                                     0x4c2  /* deprecated */
+#define XK_kana_TE                                     0x4c3
+#define XK_kana_TO                                     0x4c4
+#define XK_kana_NA                                     0x4c5
+#define XK_kana_NI                                     0x4c6
+#define XK_kana_NU                                     0x4c7
+#define XK_kana_NE                                     0x4c8
+#define XK_kana_NO                                     0x4c9
+#define XK_kana_HA                                     0x4ca
+#define XK_kana_HI                                     0x4cb
+#define XK_kana_FU                                     0x4cc
+#define XK_kana_HU                                     0x4cc  /* deprecated */
+#define XK_kana_HE                                     0x4cd
+#define XK_kana_HO                                     0x4ce
+#define XK_kana_MA                                     0x4cf
+#define XK_kana_MI                                     0x4d0
+#define XK_kana_MU                                     0x4d1
+#define XK_kana_ME                                     0x4d2
+#define XK_kana_MO                                     0x4d3
+#define XK_kana_YA                                     0x4d4
+#define XK_kana_YU                                     0x4d5
+#define XK_kana_YO                                     0x4d6
+#define XK_kana_RA                                     0x4d7
+#define XK_kana_RI                                     0x4d8
+#define XK_kana_RU                                     0x4d9
+#define XK_kana_RE                                     0x4da
+#define XK_kana_RO                                     0x4db
+#define XK_kana_WA                                     0x4dc
+#define XK_kana_N                                      0x4dd
+#define XK_voicedsound                                 0x4de
+#define XK_semivoicedsound                             0x4df
+#define XK_kana_switch          0xFF7E  /* Alias for mode_switch */
+#endif /* XK_KATAKANA */
+
+/*
+ *  Arabic
+ *  Byte 3 = 5
+ */
+
+#ifdef XK_ARABIC
+#define XK_Arabic_comma                                0x5ac
+#define XK_Arabic_semicolon                            0x5bb
+#define XK_Arabic_question_mark                        0x5bf
+#define XK_Arabic_hamza                                0x5c1
+#define XK_Arabic_maddaonalef                          0x5c2
+#define XK_Arabic_hamzaonalef                          0x5c3
+#define XK_Arabic_hamzaonwaw                           0x5c4
+#define XK_Arabic_hamzaunderalef                       0x5c5
+#define XK_Arabic_hamzaonyeh                           0x5c6
+#define XK_Arabic_alef                                 0x5c7
+#define XK_Arabic_beh                                  0x5c8
+#define XK_Arabic_tehmarbuta                           0x5c9
+#define XK_Arabic_teh                                  0x5ca
+#define XK_Arabic_theh                                 0x5cb
+#define XK_Arabic_jeem                                 0x5cc
+#define XK_Arabic_hah                                  0x5cd
+#define XK_Arabic_khah                                 0x5ce
+#define XK_Arabic_dal                                  0x5cf
+#define XK_Arabic_thal                                 0x5d0
+#define XK_Arabic_ra                                   0x5d1
+#define XK_Arabic_zain                                 0x5d2
+#define XK_Arabic_seen                                 0x5d3
+#define XK_Arabic_sheen                                0x5d4
+#define XK_Arabic_sad                                  0x5d5
+#define XK_Arabic_dad                                  0x5d6
+#define XK_Arabic_tah                                  0x5d7
+#define XK_Arabic_zah                                  0x5d8
+#define XK_Arabic_ain                                  0x5d9
+#define XK_Arabic_ghain                                0x5da
+#define XK_Arabic_tatweel                              0x5e0
+#define XK_Arabic_feh                                  0x5e1
+#define XK_Arabic_qaf                                  0x5e2
+#define XK_Arabic_kaf                                  0x5e3
+#define XK_Arabic_lam                                  0x5e4
+#define XK_Arabic_meem                                 0x5e5
+#define XK_Arabic_noon                                 0x5e6
+#define XK_Arabic_ha                                   0x5e7
+#define XK_Arabic_heh                                  0x5e7  /* deprecated */
+#define XK_Arabic_waw                                  0x5e8
+#define XK_Arabic_alefmaksura                          0x5e9
+#define XK_Arabic_yeh                                  0x5ea
+#define XK_Arabic_fathatan                             0x5eb
+#define XK_Arabic_dammatan                             0x5ec
+#define XK_Arabic_kasratan                             0x5ed
+#define XK_Arabic_fatha                                0x5ee
+#define XK_Arabic_damma                                0x5ef
+#define XK_Arabic_kasra                                0x5f0
+#define XK_Arabic_shadda                               0x5f1
+#define XK_Arabic_sukun                                0x5f2
+#define XK_Arabic_switch        0xFF7E  /* Alias for mode_switch */
+#endif /* XK_ARABIC */
+
+/*
+ * Cyrillic
+ * Byte 3 = 6
+ */
+#ifdef XK_CYRILLIC
+#define XK_Serbian_dje                                 0x6a1
+#define XK_Macedonia_gje                               0x6a2
+#define XK_Cyrillic_io                                 0x6a3
+#define XK_Ukrainian_ie                                0x6a4
+#define XK_Ukranian_je                                 0x6a4  /* deprecated */
+#define XK_Macedonia_dse                               0x6a5
+#define XK_Ukrainian_i                                 0x6a6
+#define XK_Ukranian_i                                  0x6a6  /* deprecated */
+#define XK_Ukrainian_yi                                0x6a7
+#define XK_Ukranian_yi                                 0x6a7  /* deprecated */
+#define XK_Cyrillic_je                                 0x6a8
+#define XK_Serbian_je                                  0x6a8  /* deprecated */
+#define XK_Cyrillic_lje                                0x6a9
+#define XK_Serbian_lje                                 0x6a9  /* deprecated */
+#define XK_Cyrillic_nje                                0x6aa
+#define XK_Serbian_nje                                 0x6aa  /* deprecated */
+#define XK_Serbian_tshe                                0x6ab
+#define XK_Macedonia_kje                               0x6ac
+#define XK_Byelorussian_shortu                         0x6ae
+#define XK_Cyrillic_dzhe                               0x6af
+#define XK_Serbian_dze                                 0x6af  /* deprecated */
+#define XK_numerosign                                  0x6b0
+#define XK_Serbian_DJE                                 0x6b1
+#define XK_Macedonia_GJE                               0x6b2
+#define XK_Cyrillic_IO                                 0x6b3
+#define XK_Ukrainian_IE                                0x6b4
+#define XK_Ukranian_JE                                 0x6b4  /* deprecated */
+#define XK_Macedonia_DSE                               0x6b5
+#define XK_Ukrainian_I                                 0x6b6
+#define XK_Ukranian_I                                  0x6b6  /* deprecated */
+#define XK_Ukrainian_YI                                0x6b7
+#define XK_Ukranian_YI                                 0x6b7  /* deprecated */
+#define XK_Cyrillic_JE                                 0x6b8
+#define XK_Serbian_JE                                  0x6b8  /* deprecated */
+#define XK_Cyrillic_LJE                                0x6b9
+#define XK_Serbian_LJE                                 0x6b9  /* deprecated */
+#define XK_Cyrillic_NJE                                0x6ba
+#define XK_Serbian_NJE                                 0x6ba  /* deprecated */
+#define XK_Serbian_TSHE                                0x6bb
+#define XK_Macedonia_KJE                               0x6bc
+#define XK_Byelorussian_SHORTU                         0x6be
+#define XK_Cyrillic_DZHE                               0x6bf
+#define XK_Serbian_DZE                                 0x6bf  /* deprecated */
+#define XK_Cyrillic_yu                                 0x6c0
+#define XK_Cyrillic_a                                  0x6c1
+#define XK_Cyrillic_be                                 0x6c2
+#define XK_Cyrillic_tse                                0x6c3
+#define XK_Cyrillic_de                                 0x6c4
+#define XK_Cyrillic_ie                                 0x6c5
+#define XK_Cyrillic_ef                                 0x6c6
+#define XK_Cyrillic_ghe                                0x6c7
+#define XK_Cyrillic_ha                                 0x6c8
+#define XK_Cyrillic_i                                  0x6c9
+#define XK_Cyrillic_shorti                             0x6ca
+#define XK_Cyrillic_ka                                 0x6cb
+#define XK_Cyrillic_el                                 0x6cc
+#define XK_Cyrillic_em                                 0x6cd
+#define XK_Cyrillic_en                                 0x6ce
+#define XK_Cyrillic_o                                  0x6cf
+#define XK_Cyrillic_pe                                 0x6d0
+#define XK_Cyrillic_ya                                 0x6d1
+#define XK_Cyrillic_er                                 0x6d2
+#define XK_Cyrillic_es                                 0x6d3
+#define XK_Cyrillic_te                                 0x6d4
+#define XK_Cyrillic_u                                  0x6d5
+#define XK_Cyrillic_zhe                                0x6d6
+#define XK_Cyrillic_ve                                 0x6d7
+#define XK_Cyrillic_softsign                           0x6d8
+#define XK_Cyrillic_yeru                               0x6d9
+#define XK_Cyrillic_ze                                 0x6da
+#define XK_Cyrillic_sha                                0x6db
+#define XK_Cyrillic_e                                  0x6dc
+#define XK_Cyrillic_shcha                              0x6dd
+#define XK_Cyrillic_che                                0x6de
+#define XK_Cyrillic_hardsign                           0x6df
+#define XK_Cyrillic_YU                                 0x6e0
+#define XK_Cyrillic_A                                  0x6e1
+#define XK_Cyrillic_BE                                 0x6e2
+#define XK_Cyrillic_TSE                                0x6e3
+#define XK_Cyrillic_DE                                 0x6e4
+#define XK_Cyrillic_IE                                 0x6e5
+#define XK_Cyrillic_EF                                 0x6e6
+#define XK_Cyrillic_GHE                                0x6e7
+#define XK_Cyrillic_HA                                 0x6e8
+#define XK_Cyrillic_I                                  0x6e9
+#define XK_Cyrillic_SHORTI                             0x6ea
+#define XK_Cyrillic_KA                                 0x6eb
+#define XK_Cyrillic_EL                                 0x6ec
+#define XK_Cyrillic_EM                                 0x6ed
+#define XK_Cyrillic_EN                                 0x6ee
+#define XK_Cyrillic_O                                  0x6ef
+#define XK_Cyrillic_PE                                 0x6f0
+#define XK_Cyrillic_YA                                 0x6f1
+#define XK_Cyrillic_ER                                 0x6f2
+#define XK_Cyrillic_ES                                 0x6f3
+#define XK_Cyrillic_TE                                 0x6f4
+#define XK_Cyrillic_U                                  0x6f5
+#define XK_Cyrillic_ZHE                                0x6f6
+#define XK_Cyrillic_VE                                 0x6f7
+#define XK_Cyrillic_SOFTSIGN                           0x6f8
+#define XK_Cyrillic_YERU                               0x6f9
+#define XK_Cyrillic_ZE                                 0x6fa
+#define XK_Cyrillic_SHA                                0x6fb
+#define XK_Cyrillic_E                                  0x6fc
+#define XK_Cyrillic_SHCHA                              0x6fd
+#define XK_Cyrillic_CHE                                0x6fe
+#define XK_Cyrillic_HARDSIGN                           0x6ff
+#endif /* XK_CYRILLIC */
+
+/*
+ * Greek
+ * Byte 3 = 7
+ */
+
+#ifdef XK_GREEK
+#define XK_Greek_ALPHAaccent                           0x7a1
+#define XK_Greek_EPSILONaccent                         0x7a2
+#define XK_Greek_ETAaccent                             0x7a3
+#define XK_Greek_IOTAaccent                            0x7a4
+#define XK_Greek_IOTAdieresis                          0x7a5
+#define XK_Greek_OMICRONaccent                         0x7a7
+#define XK_Greek_UPSILONaccent                         0x7a8
+#define XK_Greek_UPSILONdieresis                       0x7a9
+#define XK_Greek_OMEGAaccent                           0x7ab
+#define XK_Greek_accentdieresis                        0x7ae
+#define XK_Greek_horizbar                              0x7af
+#define XK_Greek_alphaaccent                           0x7b1
+#define XK_Greek_epsilonaccent                         0x7b2
+#define XK_Greek_etaaccent                             0x7b3
+#define XK_Greek_iotaaccent                            0x7b4
+#define XK_Greek_iotadieresis                          0x7b5
+#define XK_Greek_iotaaccentdieresis                    0x7b6
+#define XK_Greek_omicronaccent                         0x7b7
+#define XK_Greek_upsilonaccent                         0x7b8
+#define XK_Greek_upsilondieresis                       0x7b9
+#define XK_Greek_upsilonaccentdieresis                 0x7ba
+#define XK_Greek_omegaaccent                           0x7bb
+#define XK_Greek_ALPHA                                 0x7c1
+#define XK_Greek_BETA                                  0x7c2
+#define XK_Greek_GAMMA                                 0x7c3
+#define XK_Greek_DELTA                                 0x7c4
+#define XK_Greek_EPSILON                               0x7c5
+#define XK_Greek_ZETA                                  0x7c6
+#define XK_Greek_ETA                                   0x7c7
+#define XK_Greek_THETA                                 0x7c8
+#define XK_Greek_IOTA                                  0x7c9
+#define XK_Greek_KAPPA                                 0x7ca
+#define XK_Greek_LAMDA                                 0x7cb
+#define XK_Greek_LAMBDA                                0x7cb
+#define XK_Greek_MU                                    0x7cc
+#define XK_Greek_NU                                    0x7cd
+#define XK_Greek_XI                                    0x7ce
+#define XK_Greek_OMICRON                               0x7cf
+#define XK_Greek_PI                                    0x7d0
+#define XK_Greek_RHO                                   0x7d1
+#define XK_Greek_SIGMA                                 0x7d2
+#define XK_Greek_TAU                                   0x7d4
+#define XK_Greek_UPSILON                               0x7d5
+#define XK_Greek_PHI                                   0x7d6
+#define XK_Greek_CHI                                   0x7d7
+#define XK_Greek_PSI                                   0x7d8
+#define XK_Greek_OMEGA                                 0x7d9
+#define XK_Greek_alpha                                 0x7e1
+#define XK_Greek_beta                                  0x7e2
+#define XK_Greek_gamma                                 0x7e3
+#define XK_Greek_delta                                 0x7e4
+#define XK_Greek_epsilon                               0x7e5
+#define XK_Greek_zeta                                  0x7e6
+#define XK_Greek_eta                                   0x7e7
+#define XK_Greek_theta                                 0x7e8
+#define XK_Greek_iota                                  0x7e9
+#define XK_Greek_kappa                                 0x7ea
+#define XK_Greek_lamda                                 0x7eb
+#define XK_Greek_lambda                                0x7eb
+#define XK_Greek_mu                                    0x7ec
+#define XK_Greek_nu                                    0x7ed
+#define XK_Greek_xi                                    0x7ee
+#define XK_Greek_omicron                               0x7ef
+#define XK_Greek_pi                                    0x7f0
+#define XK_Greek_rho                                   0x7f1
+#define XK_Greek_sigma                                 0x7f2
+#define XK_Greek_finalsmallsigma                       0x7f3
+#define XK_Greek_tau                                   0x7f4
+#define XK_Greek_upsilon                               0x7f5
+#define XK_Greek_phi                                   0x7f6
+#define XK_Greek_chi                                   0x7f7
+#define XK_Greek_psi                                   0x7f8
+#define XK_Greek_omega                                 0x7f9
+#define XK_Greek_switch         0xFF7E  /* Alias for mode_switch */
+#endif /* XK_GREEK */
+
+/*
+ * Technical
+ * Byte 3 = 8
+ */
+
+#ifdef XK_TECHNICAL
+#define XK_leftradical                                 0x8a1
+#define XK_topleftradical                              0x8a2
+#define XK_horizconnector                              0x8a3
+#define XK_topintegral                                 0x8a4
+#define XK_botintegral                                 0x8a5
+#define XK_vertconnector                               0x8a6
+#define XK_topleftsqbracket                            0x8a7
+#define XK_botleftsqbracket                            0x8a8
+#define XK_toprightsqbracket                           0x8a9
+#define XK_botrightsqbracket                           0x8aa
+#define XK_topleftparens                               0x8ab
+#define XK_botleftparens                               0x8ac
+#define XK_toprightparens                              0x8ad
+#define XK_botrightparens                              0x8ae
+#define XK_leftmiddlecurlybrace                        0x8af
+#define XK_rightmiddlecurlybrace                       0x8b0
+#define XK_topleftsummation                            0x8b1
+#define XK_botleftsummation                            0x8b2
+#define XK_topvertsummationconnector                   0x8b3
+#define XK_botvertsummationconnector                   0x8b4
+#define XK_toprightsummation                           0x8b5
+#define XK_botrightsummation                           0x8b6
+#define XK_rightmiddlesummation                        0x8b7
+#define XK_lessthanequal                               0x8bc
+#define XK_notequal                                    0x8bd
+#define XK_greaterthanequal                            0x8be
+#define XK_integral                                    0x8bf
+#define XK_therefore                                   0x8c0
+#define XK_variation                                   0x8c1
+#define XK_infinity                                    0x8c2
+#define XK_nabla                                       0x8c5
+#define XK_approximate                                 0x8c8
+#define XK_similarequal                                0x8c9
+#define XK_ifonlyif                                    0x8cd
+#define XK_implies                                     0x8ce
+#define XK_identical                                   0x8cf
+#define XK_radical                                     0x8d6
+#define XK_includedin                                  0x8da
+#define XK_includes                                    0x8db
+#define XK_intersection                                0x8dc
+#define XK_union                                       0x8dd
+#define XK_logicaland                                  0x8de
+#define XK_logicalor                                   0x8df
+#define XK_partialderivative                           0x8ef
+#define XK_function                                    0x8f6
+#define XK_leftarrow                                   0x8fb
+#define XK_uparrow                                     0x8fc
+#define XK_rightarrow                                  0x8fd
+#define XK_downarrow                                   0x8fe
+#endif /* XK_TECHNICAL */
+
+/*
+ *  Special
+ *  Byte 3 = 9
+ */
+
+#ifdef XK_SPECIAL
+#define XK_blank                                       0x9df
+#define XK_soliddiamond                                0x9e0
+#define XK_checkerboard                                0x9e1
+#define XK_ht                                          0x9e2
+#define XK_ff                                          0x9e3
+#define XK_cr                                          0x9e4
+#define XK_lf                                          0x9e5
+#define XK_nl                                          0x9e8
+#define XK_vt                                          0x9e9
+#define XK_lowrightcorner                              0x9ea
+#define XK_uprightcorner                               0x9eb
+#define XK_upleftcorner                                0x9ec
+#define XK_lowleftcorner                               0x9ed
+#define XK_crossinglines                               0x9ee
+#define XK_horizlinescan1                              0x9ef
+#define XK_horizlinescan3                              0x9f0
+#define XK_horizlinescan5                              0x9f1
+#define XK_horizlinescan7                              0x9f2
+#define XK_horizlinescan9                              0x9f3
+#define XK_leftt                                       0x9f4
+#define XK_rightt                                      0x9f5
+#define XK_bott                                        0x9f6
+#define XK_topt                                        0x9f7
+#define XK_vertbar                                     0x9f8
+#endif /* XK_SPECIAL */
+
+/*
+ *  Publishing
+ *  Byte 3 = a
+ */
+
+#ifdef XK_PUBLISHING
+#define XK_emspace                                     0xaa1
+#define XK_enspace                                     0xaa2
+#define XK_em3space                                    0xaa3
+#define XK_em4space                                    0xaa4
+#define XK_digitspace                                  0xaa5
+#define XK_punctspace                                  0xaa6
+#define XK_thinspace                                   0xaa7
+#define XK_hairspace                                   0xaa8
+#define XK_emdash                                      0xaa9
+#define XK_endash                                      0xaaa
+#define XK_signifblank                                 0xaac
+#define XK_ellipsis                                    0xaae
+#define XK_doubbaselinedot                             0xaaf
+#define XK_onethird                                    0xab0
+#define XK_twothirds                                   0xab1
+#define XK_onefifth                                    0xab2
+#define XK_twofifths                                   0xab3
+#define XK_threefifths                                 0xab4
+#define XK_fourfifths                                  0xab5
+#define XK_onesixth                                    0xab6
+#define XK_fivesixths                                  0xab7
+#define XK_careof                                      0xab8
+#define XK_figdash                                     0xabb
+#define XK_leftanglebracket                            0xabc
+#define XK_decimalpoint                                0xabd
+#define XK_rightanglebracket                           0xabe
+#define XK_marker                                      0xabf
+#define XK_oneeighth                                   0xac3
+#define XK_threeeighths                                0xac4
+#define XK_fiveeighths                                 0xac5
+#define XK_seveneighths                                0xac6
+#define XK_trademark                                   0xac9
+#define XK_signaturemark                               0xaca
+#define XK_trademarkincircle                           0xacb
+#define XK_leftopentriangle                            0xacc
+#define XK_rightopentriangle                           0xacd
+#define XK_emopencircle                                0xace
+#define XK_emopenrectangle                             0xacf
+#define XK_leftsinglequotemark                         0xad0
+#define XK_rightsinglequotemark                        0xad1
+#define XK_leftdoublequotemark                         0xad2
+#define XK_rightdoublequotemark                        0xad3
+#define XK_prescription                                0xad4
+#define XK_minutes                                     0xad6
+#define XK_seconds                                     0xad7
+#define XK_latincross                                  0xad9
+#define XK_hexagram                                    0xada
+#define XK_filledrectbullet                            0xadb
+#define XK_filledlefttribullet                         0xadc
+#define XK_filledrighttribullet                        0xadd
+#define XK_emfilledcircle                              0xade
+#define XK_emfilledrect                                0xadf
+#define XK_enopencircbullet                            0xae0
+#define XK_enopensquarebullet                          0xae1
+#define XK_openrectbullet                              0xae2
+#define XK_opentribulletup                             0xae3
+#define XK_opentribulletdown                           0xae4
+#define XK_openstar                                    0xae5
+#define XK_enfilledcircbullet                          0xae6
+#define XK_enfilledsqbullet                            0xae7
+#define XK_filledtribulletup                           0xae8
+#define XK_filledtribulletdown                         0xae9
+#define XK_leftpointer                                 0xaea
+#define XK_rightpointer                                0xaeb
+#define XK_club                                        0xaec
+#define XK_diamond                                     0xaed
+#define XK_heart                                       0xaee
+#define XK_maltesecross                                0xaf0
+#define XK_dagger                                      0xaf1
+#define XK_doubledagger                                0xaf2
+#define XK_checkmark                                   0xaf3
+#define XK_ballotcross                                 0xaf4
+#define XK_musicalsharp                                0xaf5
+#define XK_musicalflat                                 0xaf6
+#define XK_malesymbol                                  0xaf7
+#define XK_femalesymbol                                0xaf8
+#define XK_telephone                                   0xaf9
+#define XK_telephonerecorder                           0xafa
+#define XK_phonographcopyright                         0xafb
+#define XK_caret                                       0xafc
+#define XK_singlelowquotemark                          0xafd
+#define XK_doublelowquotemark                          0xafe
+#define XK_cursor                                      0xaff
+#endif /* XK_PUBLISHING */
+
+/*
+ *  APL
+ *  Byte 3 = b
+ */
+
+#ifdef XK_APL
+#define XK_leftcaret                                   0xba3
+#define XK_rightcaret                                  0xba6
+#define XK_downcaret                                   0xba8
+#define XK_upcaret                                     0xba9
+#define XK_overbar                                     0xbc0
+#define XK_downtack                                    0xbc2
+#define XK_upshoe                                      0xbc3
+#define XK_downstile                                   0xbc4
+#define XK_underbar                                    0xbc6
+#define XK_jot                                         0xbca
+#define XK_quad                                        0xbcc
+#define XK_uptack                                      0xbce
+#define XK_circle                                      0xbcf
+#define XK_upstile                                     0xbd3
+#define XK_downshoe                                    0xbd6
+#define XK_rightshoe                                   0xbd8
+#define XK_leftshoe                                    0xbda
+#define XK_lefttack                                    0xbdc
+#define XK_righttack                                   0xbfc
+#endif /* XK_APL */
+
+/*
+ * Hebrew
+ * Byte 3 = c
+ */
+
+#ifdef XK_HEBREW
+#define XK_hebrew_doublelowline                        0xcdf
+#define XK_hebrew_aleph                                0xce0
+#define XK_hebrew_bet                                  0xce1
+#define XK_hebrew_beth                                 0xce1  /* deprecated */
+#define XK_hebrew_gimel                                0xce2
+#define XK_hebrew_gimmel                               0xce2  /* deprecated */
+#define XK_hebrew_dalet                                0xce3
+#define XK_hebrew_daleth                               0xce3  /* deprecated */
+#define XK_hebrew_he                                   0xce4
+#define XK_hebrew_waw                                  0xce5
+#define XK_hebrew_zain                                 0xce6
+#define XK_hebrew_zayin                                0xce6  /* deprecated */
+#define XK_hebrew_chet                                 0xce7
+#define XK_hebrew_het                                  0xce7  /* deprecated */
+#define XK_hebrew_tet                                  0xce8
+#define XK_hebrew_teth                                 0xce8  /* deprecated */
+#define XK_hebrew_yod                                  0xce9
+#define XK_hebrew_finalkaph                            0xcea
+#define XK_hebrew_kaph                                 0xceb
+#define XK_hebrew_lamed                                0xcec
+#define XK_hebrew_finalmem                             0xced
+#define XK_hebrew_mem                                  0xcee
+#define XK_hebrew_finalnun                             0xcef
+#define XK_hebrew_nun                                  0xcf0
+#define XK_hebrew_samech                               0xcf1
+#define XK_hebrew_samekh                               0xcf1  /* deprecated */
+#define XK_hebrew_ayin                                 0xcf2
+#define XK_hebrew_finalpe                              0xcf3
+#define XK_hebrew_pe                                   0xcf4
+#define XK_hebrew_finalzade                            0xcf5
+#define XK_hebrew_finalzadi                            0xcf5  /* deprecated */
+#define XK_hebrew_zade                                 0xcf6
+#define XK_hebrew_zadi                                 0xcf6  /* deprecated */
+#define XK_hebrew_qoph                                 0xcf7
+#define XK_hebrew_kuf                                  0xcf7  /* deprecated */
+#define XK_hebrew_resh                                 0xcf8
+#define XK_hebrew_shin                                 0xcf9
+#define XK_hebrew_taw                                  0xcfa
+#define XK_hebrew_taf                                  0xcfa  /* deprecated */
+#define XK_Hebrew_switch        0xFF7E  /* Alias for mode_switch */
+#endif /* XK_HEBREW */
+
+/*
+ * Thai
+ * Byte 3 = d
+ */
+
+#ifdef XK_THAI
+#define XK_Thai_kokai                                  0xda1
+#define XK_Thai_khokhai                                        0xda2
+#define XK_Thai_khokhuat                               0xda3
+#define XK_Thai_khokhwai                               0xda4
+#define XK_Thai_khokhon                                        0xda5
+#define XK_Thai_khorakhang                             0xda6  
+#define XK_Thai_ngongu                                 0xda7  
+#define XK_Thai_chochan                                        0xda8  
+#define XK_Thai_choching                               0xda9   
+#define XK_Thai_chochang                               0xdaa  
+#define XK_Thai_soso                                   0xdab
+#define XK_Thai_chochoe                                        0xdac
+#define XK_Thai_yoying                                 0xdad
+#define XK_Thai_dochada                                        0xdae
+#define XK_Thai_topatak                                        0xdaf
+#define XK_Thai_thothan                                        0xdb0
+#define XK_Thai_thonangmontho                          0xdb1
+#define XK_Thai_thophuthao                             0xdb2
+#define XK_Thai_nonen                                  0xdb3
+#define XK_Thai_dodek                                  0xdb4
+#define XK_Thai_totao                                  0xdb5
+#define XK_Thai_thothung                               0xdb6
+#define XK_Thai_thothahan                              0xdb7
+#define XK_Thai_thothong                               0xdb8
+#define XK_Thai_nonu                                   0xdb9
+#define XK_Thai_bobaimai                               0xdba
+#define XK_Thai_popla                                  0xdbb
+#define XK_Thai_phophung                               0xdbc
+#define XK_Thai_fofa                                   0xdbd
+#define XK_Thai_phophan                                        0xdbe
+#define XK_Thai_fofan                                  0xdbf
+#define XK_Thai_phosamphao                             0xdc0
+#define XK_Thai_moma                                   0xdc1
+#define XK_Thai_yoyak                                  0xdc2
+#define XK_Thai_rorua                                  0xdc3
+#define XK_Thai_ru                                     0xdc4
+#define XK_Thai_loling                                 0xdc5
+#define XK_Thai_lu                                     0xdc6
+#define XK_Thai_wowaen                                 0xdc7
+#define XK_Thai_sosala                                 0xdc8
+#define XK_Thai_sorusi                                 0xdc9
+#define XK_Thai_sosua                                  0xdca
+#define XK_Thai_hohip                                  0xdcb
+#define XK_Thai_lochula                                        0xdcc
+#define XK_Thai_oang                                   0xdcd
+#define XK_Thai_honokhuk                               0xdce
+#define XK_Thai_paiyannoi                              0xdcf
+#define XK_Thai_saraa                                  0xdd0
+#define XK_Thai_maihanakat                             0xdd1
+#define XK_Thai_saraaa                                 0xdd2
+#define XK_Thai_saraam                                 0xdd3
+#define XK_Thai_sarai                                  0xdd4   
+#define XK_Thai_saraii                                 0xdd5   
+#define XK_Thai_saraue                                 0xdd6    
+#define XK_Thai_sarauee                                        0xdd7    
+#define XK_Thai_sarau                                  0xdd8    
+#define XK_Thai_sarauu                                 0xdd9   
+#define XK_Thai_phinthu                                        0xdda
+#define XK_Thai_maihanakat_maitho                      0xdde
+#define XK_Thai_baht                                   0xddf
+#define XK_Thai_sarae                                  0xde0    
+#define XK_Thai_saraae                                 0xde1
+#define XK_Thai_sarao                                  0xde2
+#define XK_Thai_saraaimaimuan                          0xde3   
+#define XK_Thai_saraaimaimalai                         0xde4  
+#define XK_Thai_lakkhangyao                            0xde5
+#define XK_Thai_maiyamok                               0xde6
+#define XK_Thai_maitaikhu                              0xde7
+#define XK_Thai_maiek                                  0xde8   
+#define XK_Thai_maitho                                 0xde9
+#define XK_Thai_maitri                                 0xdea
+#define XK_Thai_maichattawa                            0xdeb
+#define XK_Thai_thanthakhat                            0xdec
+#define XK_Thai_nikhahit                               0xded
+#define XK_Thai_leksun                                 0xdf0 
+#define XK_Thai_leknung                                        0xdf1  
+#define XK_Thai_leksong                                        0xdf2 
+#define XK_Thai_leksam                                 0xdf3
+#define XK_Thai_leksi                                  0xdf4  
+#define XK_Thai_lekha                                  0xdf5  
+#define XK_Thai_lekhok                                 0xdf6  
+#define XK_Thai_lekchet                                        0xdf7  
+#define XK_Thai_lekpaet                                        0xdf8  
+#define XK_Thai_lekkao                                 0xdf9 
+#endif /* XK_THAI */
+
+/*
+ *   Korean
+ *   Byte 3 = e
+ */
+
+#ifdef XK_KOREAN
+
+#define XK_Hangul              0xff31    /* Hangul start/stop(toggle) */
+#define XK_Hangul_Start                0xff32    /* Hangul start */
+#define XK_Hangul_End          0xff33    /* Hangul end, English start */
+#define XK_Hangul_Hanja                0xff34    /* Start Hangul->Hanja Conversion */
+#define XK_Hangul_Jamo         0xff35    /* Hangul Jamo mode */
+#define XK_Hangul_Romaja       0xff36    /* Hangul Romaja mode */
+#define XK_Hangul_Codeinput    0xff37    /* Hangul code input mode */
+#define XK_Hangul_Jeonja       0xff38    /* Jeonja mode */
+#define XK_Hangul_Banja                0xff39    /* Banja mode */
+#define XK_Hangul_PreHanja     0xff3a    /* Pre Hanja conversion */
+#define XK_Hangul_PostHanja    0xff3b    /* Post Hanja conversion */
+#define XK_Hangul_SingleCandidate      0xff3c    /* Single candidate */
+#define XK_Hangul_MultipleCandidate    0xff3d    /* Multiple candidate */
+#define XK_Hangul_PreviousCandidate    0xff3e    /* Previous candidate */
+#define XK_Hangul_Special      0xff3f    /* Special symbols */
+#define XK_Hangul_switch       0xFF7E    /* Alias for mode_switch */
+
+/* Hangul Consonant Characters */
+#define XK_Hangul_Kiyeog                               0xea1
+#define XK_Hangul_SsangKiyeog                          0xea2
+#define XK_Hangul_KiyeogSios                           0xea3
+#define XK_Hangul_Nieun                                        0xea4
+#define XK_Hangul_NieunJieuj                           0xea5
+#define XK_Hangul_NieunHieuh                           0xea6
+#define XK_Hangul_Dikeud                               0xea7
+#define XK_Hangul_SsangDikeud                          0xea8
+#define XK_Hangul_Rieul                                        0xea9
+#define XK_Hangul_RieulKiyeog                          0xeaa
+#define XK_Hangul_RieulMieum                           0xeab
+#define XK_Hangul_RieulPieub                           0xeac
+#define XK_Hangul_RieulSios                            0xead
+#define XK_Hangul_RieulTieut                           0xeae
+#define XK_Hangul_RieulPhieuf                          0xeaf
+#define XK_Hangul_RieulHieuh                           0xeb0
+#define XK_Hangul_Mieum                                        0xeb1
+#define XK_Hangul_Pieub                                        0xeb2
+#define XK_Hangul_SsangPieub                           0xeb3
+#define XK_Hangul_PieubSios                            0xeb4
+#define XK_Hangul_Sios                                 0xeb5
+#define XK_Hangul_SsangSios                            0xeb6
+#define XK_Hangul_Ieung                                        0xeb7
+#define XK_Hangul_Jieuj                                        0xeb8
+#define XK_Hangul_SsangJieuj                           0xeb9
+#define XK_Hangul_Cieuc                                        0xeba
+#define XK_Hangul_Khieuq                               0xebb
+#define XK_Hangul_Tieut                                        0xebc
+#define XK_Hangul_Phieuf                               0xebd
+#define XK_Hangul_Hieuh                                        0xebe
+
+/* Hangul Vowel Characters */
+#define XK_Hangul_A                                    0xebf
+#define XK_Hangul_AE                                   0xec0
+#define XK_Hangul_YA                                   0xec1
+#define XK_Hangul_YAE                                  0xec2
+#define XK_Hangul_EO                                   0xec3
+#define XK_Hangul_E                                    0xec4
+#define XK_Hangul_YEO                                  0xec5
+#define XK_Hangul_YE                                   0xec6
+#define XK_Hangul_O                                    0xec7
+#define XK_Hangul_WA                                   0xec8
+#define XK_Hangul_WAE                                  0xec9
+#define XK_Hangul_OE                                   0xeca
+#define XK_Hangul_YO                                   0xecb
+#define XK_Hangul_U                                    0xecc
+#define XK_Hangul_WEO                                  0xecd
+#define XK_Hangul_WE                                   0xece
+#define XK_Hangul_WI                                   0xecf
+#define XK_Hangul_YU                                   0xed0
+#define XK_Hangul_EU                                   0xed1
+#define XK_Hangul_YI                                   0xed2
+#define XK_Hangul_I                                    0xed3
+
+/* Hangul syllable-final (JongSeong) Characters */
+#define XK_Hangul_J_Kiyeog                             0xed4
+#define XK_Hangul_J_SsangKiyeog                                0xed5
+#define XK_Hangul_J_KiyeogSios                         0xed6
+#define XK_Hangul_J_Nieun                              0xed7
+#define XK_Hangul_J_NieunJieuj                         0xed8
+#define XK_Hangul_J_NieunHieuh                         0xed9
+#define XK_Hangul_J_Dikeud                             0xeda
+#define XK_Hangul_J_Rieul                              0xedb
+#define XK_Hangul_J_RieulKiyeog                                0xedc
+#define XK_Hangul_J_RieulMieum                         0xedd
+#define XK_Hangul_J_RieulPieub                         0xede
+#define XK_Hangul_J_RieulSios                          0xedf
+#define XK_Hangul_J_RieulTieut                         0xee0
+#define XK_Hangul_J_RieulPhieuf                                0xee1
+#define XK_Hangul_J_RieulHieuh                         0xee2
+#define XK_Hangul_J_Mieum                              0xee3
+#define XK_Hangul_J_Pieub                              0xee4
+#define XK_Hangul_J_PieubSios                          0xee5
+#define XK_Hangul_J_Sios                               0xee6
+#define XK_Hangul_J_SsangSios                          0xee7
+#define XK_Hangul_J_Ieung                              0xee8
+#define XK_Hangul_J_Jieuj                              0xee9
+#define XK_Hangul_J_Cieuc                              0xeea
+#define XK_Hangul_J_Khieuq                             0xeeb
+#define XK_Hangul_J_Tieut                              0xeec
+#define XK_Hangul_J_Phieuf                             0xeed
+#define XK_Hangul_J_Hieuh                              0xeee
+
+/* Ancient Hangul Consonant Characters */
+#define XK_Hangul_RieulYeorinHieuh                     0xeef
+#define XK_Hangul_SunkyeongeumMieum                    0xef0
+#define XK_Hangul_SunkyeongeumPieub                    0xef1
+#define XK_Hangul_PanSios                              0xef2
+#define XK_Hangul_KkogjiDalrinIeung                    0xef3
+#define XK_Hangul_SunkyeongeumPhieuf                   0xef4
+#define XK_Hangul_YeorinHieuh                          0xef5
+
+/* Ancient Hangul Vowel Characters */
+#define XK_Hangul_AraeA                                        0xef6
+#define XK_Hangul_AraeAE                               0xef7
+
+/* Ancient Hangul syllable-final (JongSeong) Characters */
+#define XK_Hangul_J_PanSios                            0xef8
+#define XK_Hangul_J_KkogjiDalrinIeung                  0xef9
+#define XK_Hangul_J_YeorinHieuh                                0xefa
+
+/* Korean currency symbol */
+#define XK_Korean_Won                                  0xeff
+
+#endif /* XK_KOREAN */
+
+/* Euro currency symbol */
+#define XK_EuroSign 0x20ac
+
+#endif
diff --git a/src/rfb/rfb.h b/src/rfb/rfb.h
new file mode 100644 (file)
index 0000000..4f3a664
--- /dev/null
@@ -0,0 +1,977 @@
+#ifndef RFB_H
+#define RFB_H
+
+/*
+ * rfb.h - header file for RFB DDX implementation.
+ */
+
+/*
+ *  Copyright (C) 2005 Rohit Kumar <rokumar@novell.com>,
+ *                     Johannes E. Schindelin <johannes.schindelin@gmx.de>
+ *  Copyright (C) 2002 RealVNC Ltd.
+ *  OSXvnc Copyright (C) 2001 Dan McGuirk <mcguirk@incompleteness.net>.
+ *  Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge.  
+ *  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+#if(defined __cplusplus)
+extern "C"
+{
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <rfb/rfbproto.h>
+
+#ifdef LIBVNCSERVER_HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef __MINGW32__
+#include <winsock2.h>
+#endif
+
+#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
+#include <pthread.h>
+#if 0 /* debugging */
+#define LOCK(mutex) (rfbLog("%s:%d LOCK(%s,0x%x)\n",__FILE__,__LINE__,#mutex,&(mutex)), pthread_mutex_lock(&(mutex)))
+#define UNLOCK(mutex) (rfbLog("%s:%d UNLOCK(%s,0x%x)\n",__FILE__,__LINE__,#mutex,&(mutex)), pthread_mutex_unlock(&(mutex)))
+#define MUTEX(mutex) pthread_mutex_t (mutex)
+#define INIT_MUTEX(mutex) (rfbLog("%s:%d INIT_MUTEX(%s,0x%x)\n",__FILE__,__LINE__,#mutex,&(mutex)), pthread_mutex_init(&(mutex),NULL))
+#define TINI_MUTEX(mutex) (rfbLog("%s:%d TINI_MUTEX(%s)\n",__FILE__,__LINE__,#mutex), pthread_mutex_destroy(&(mutex)))
+#define TSIGNAL(cond) (rfbLog("%s:%d TSIGNAL(%s)\n",__FILE__,__LINE__,#cond), pthread_cond_signal(&(cond)))
+#define WAIT(cond,mutex) (rfbLog("%s:%d WAIT(%s,%s)\n",__FILE__,__LINE__,#cond,#mutex), pthread_cond_wait(&(cond),&(mutex)))
+#define COND(cond) pthread_cond_t (cond)
+#define INIT_COND(cond) (rfbLog("%s:%d INIT_COND(%s)\n",__FILE__,__LINE__,#cond), pthread_cond_init(&(cond),NULL))
+#define TINI_COND(cond) (rfbLog("%s:%d TINI_COND(%s)\n",__FILE__,__LINE__,#cond), pthread_cond_destroy(&(cond)))
+#define IF_PTHREADS(x) x
+#else
+#if !NONETWORK
+#define LOCK(mutex) pthread_mutex_lock(&(mutex));
+#define UNLOCK(mutex) pthread_mutex_unlock(&(mutex));
+#endif
+#define MUTEX(mutex) pthread_mutex_t (mutex)
+#define INIT_MUTEX(mutex) pthread_mutex_init(&(mutex),NULL)
+#define TINI_MUTEX(mutex) pthread_mutex_destroy(&(mutex))
+#define TSIGNAL(cond) pthread_cond_signal(&(cond))
+#define WAIT(cond,mutex) pthread_cond_wait(&(cond),&(mutex))
+#define COND(cond) pthread_cond_t (cond)
+#define INIT_COND(cond) pthread_cond_init(&(cond),NULL)
+#define TINI_COND(cond) pthread_cond_destroy(&(cond))
+#define IF_PTHREADS(x) x
+#endif
+#else
+#define LOCK(mutex)
+#define UNLOCK(mutex)
+#define MUTEX(mutex)
+#define INIT_MUTEX(mutex)
+#define TINI_MUTEX(mutex)
+#define TSIGNAL(cond)
+#define WAIT(cond,mutex) this_is_unsupported
+#define COND(cond)
+#define INIT_COND(cond)
+#define TINI_COND(cond)
+#define IF_PTHREADS(x)
+#endif
+
+/* end of stuff for autoconf */
+
+/* if you use pthreads, but don't define LIBVNCSERVER_HAVE_LIBPTHREAD, the structs
+   get all mixed up. So this gives a linker error reminding you to compile
+   the library and your application (at least the parts including rfb.h)
+   with the same support for pthreads. */
+#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
+#ifdef LIBVNCSERVER_HAVE_LIBZ
+#define rfbInitServer rfbInitServerWithPthreadsAndZRLE
+#else
+#define rfbInitServer rfbInitServerWithPthreadsButWithoutZRLE
+#endif
+#else
+#ifdef LIBVNCSERVER_HAVE_LIBZ
+#define rfbInitServer rfbInitServerWithoutPthreadsButWithZRLE
+#else
+#define rfbInitServer rfbInitServerWithoutPthreadsAndZRLE
+#endif
+#endif
+
+struct _rfbClientRec;
+struct _rfbScreenInfo;
+struct rfbCursor;
+
+enum rfbNewClientAction {
+       RFB_CLIENT_ACCEPT,
+       RFB_CLIENT_ON_HOLD,
+       RFB_CLIENT_REFUSE
+};
+
+enum rfbSocketState {
+       RFB_SOCKET_INIT,
+       RFB_SOCKET_READY,
+       RFB_SOCKET_SHUTDOWN
+};
+
+typedef void (*rfbKbdAddEventProcPtr) (rfbBool down, rfbKeySym keySym, struct _rfbClientRec* cl);
+typedef void (*rfbKbdReleaseAllKeysProcPtr) (struct _rfbClientRec* cl);
+typedef void (*rfbPtrAddEventProcPtr) (int buttonMask, int x, int y, struct _rfbClientRec* cl);
+typedef void (*rfbSetXCutTextProcPtr) (char* str,int len, struct _rfbClientRec* cl);
+typedef struct rfbCursor* (*rfbGetCursorProcPtr) (struct _rfbClientRec* pScreen);
+typedef rfbBool (*rfbSetTranslateFunctionProcPtr)(struct _rfbClientRec* cl);
+typedef rfbBool (*rfbPasswordCheckProcPtr)(struct _rfbClientRec* cl,const char* encryptedPassWord,int len);
+typedef enum rfbNewClientAction (*rfbNewClientHookPtr)(struct _rfbClientRec* cl);
+typedef void (*rfbDisplayHookPtr)(struct _rfbClientRec* cl);
+/* support the capability to view the caps/num/scroll states of the X server */
+typedef int  (*rfbGetKeyboardLedStateHookPtr)(struct _rfbScreenInfo* screen);
+/* If x==1 and y==1 then set the whole display
+ * else find the window underneath x and y and set the framebuffer to the dimensions
+ * of that window
+ */
+typedef void (*rfbSetSingleWindowProcPtr) (struct _rfbClientRec* cl, int x, int y);
+/* Status determines if the X11 server permits input from the local user 
+ * status==0 or 1
+ */
+typedef void (*rfbSetServerInputProcPtr) (struct _rfbClientRec* cl, int status);
+/* Permit the server to allow or deny filetransfers.   This is defaulted to deny
+ * It is called when a client initiates a connection to determine if it is permitted.
+ */
+typedef int  (*rfbFileTransferPermitted) (struct _rfbClientRec* cl);
+/* Handle the textchat messages */
+typedef void (*rfbSetTextChat) (struct _rfbClientRec* cl, int length, char *string);
+
+typedef struct {
+  uint32_t count;
+  rfbBool is16; /* is the data format short? */
+  union {
+    uint8_t* bytes;
+    uint16_t* shorts;
+  } data; /* there have to be count*3 entries */
+} rfbColourMap;
+
+/*
+ * Security handling (RFB protocol version 3.7)
+ */
+
+typedef struct _rfbSecurity {
+       uint8_t type;
+       void (*handler)(struct _rfbClientRec* cl);
+       struct _rfbSecurity* next;
+} rfbSecurityHandler;
+
+/*
+ * Protocol extension handling.
+ */
+
+typedef struct _rfbProtocolExtension {
+       /* returns FALSE if extension should be deactivated for client.
+          if newClient == NULL, it is always deactivated. */
+       rfbBool (*newClient)(struct _rfbClientRec* client, void** data);
+       /* returns FALSE if extension should be deactivated for client.
+          if init == NULL, it stays activated. */
+       rfbBool (*init)(struct _rfbClientRec* client, void* data);
+       /* if pseudoEncodings is not NULL, it contains a 0 terminated
+          list of the pseudo encodings handled by this extension. */
+       int *pseudoEncodings;
+       /* returns TRUE if that pseudo encoding is handled by the extension.
+          encodingNumber==0 means "reset encodings". */
+       rfbBool (*enablePseudoEncoding)(struct _rfbClientRec* client,
+                       void** data, int encodingNumber);
+       /* returns TRUE if message was handled */
+       rfbBool (*handleMessage)(struct _rfbClientRec* client,
+                               void* data,
+                               const rfbClientToServerMsg* message);
+       void (*close)(struct _rfbClientRec* client, void* data);
+       void (*usage)(void);
+       /* processArguments returns the number of handled arguments */
+       int (*processArgument)(int argc, char *argv[]);
+       struct _rfbProtocolExtension* next;
+} rfbProtocolExtension;
+
+typedef struct _rfbExtensionData {
+       rfbProtocolExtension* extension;
+       void* data;
+       struct _rfbExtensionData* next;
+} rfbExtensionData;
+
+/*
+ * Per-screen (framebuffer) structure.  There can be as many as you wish,
+ * each serving different clients. However, you have to call
+ * rfbProcessEvents for each of these.
+ */
+
+typedef struct _rfbScreenInfo
+{
+    /* this structure has children that are scaled versions of this screen */
+    struct _rfbScreenInfo *scaledScreenNext;
+    int scaledScreenRefCount;
+
+    int width;
+    int paddedWidthInBytes;
+    int height;
+    int depth;
+    int bitsPerPixel;
+    int sizeInBytes;
+
+    rfbPixel blackPixel;
+    rfbPixel whitePixel;
+
+    /* some screen specific data can be put into a struct where screenData
+     * points to. You need this if you have more than one screen at the
+     * same time while using the same functions.
+     */
+    void* screenData;
+  
+    /* additions by libvncserver */
+
+    rfbPixelFormat serverFormat;
+    rfbColourMap colourMap; /* set this if rfbServerFormat.trueColour==FALSE */
+    const char* desktopName;
+    char thisHost[255];
+
+    rfbBool autoPort;
+    int port;
+    SOCKET listenSock;
+    int maxSock;
+    int maxFd;
+#ifdef __MINGW32__
+    struct fd_set allFds;
+#else
+    fd_set allFds;
+#endif
+
+    enum rfbSocketState socketState;
+    SOCKET inetdSock;
+    rfbBool inetdInitDone;
+
+    int udpPort;
+    SOCKET udpSock;
+    struct _rfbClientRec* udpClient;
+    rfbBool udpSockConnected;
+    struct sockaddr_in udpRemoteAddr;
+
+    int maxClientWait;
+
+    /* http stuff */
+    rfbBool httpInitDone;
+    rfbBool httpEnableProxyConnect;
+    int httpPort;
+    char* httpDir;
+    SOCKET httpListenSock;
+    SOCKET httpSock;
+
+    rfbPasswordCheckProcPtr passwordCheck;
+    void* authPasswdData;
+    /* If rfbAuthPasswdData is given a list, this is the first
+       view only password. */
+    int authPasswdFirstViewOnly;
+
+    /* send only this many rectangles in one update */
+    int maxRectsPerUpdate;
+    /* this is the amount of milliseconds to wait at least before sending
+     * an update. */
+    int deferUpdateTime;
+#ifdef TODELETE
+    char* screen;
+#endif
+    rfbBool alwaysShared;
+    rfbBool neverShared;
+    rfbBool dontDisconnect;
+    struct _rfbClientRec* clientHead;
+    struct _rfbClientRec* pointerClient;  /* "Mutex" for pointer events */
+
+
+    /* cursor */
+    int cursorX, cursorY,underCursorBufferLen;
+    char* underCursorBuffer;
+    rfbBool dontConvertRichCursorToXCursor;
+    struct rfbCursor* cursor;
+
+    /* the frameBufferhas to be supplied by the serving process.
+     * The buffer will not be freed by 
+     */
+    char* frameBuffer;
+    rfbKbdAddEventProcPtr kbdAddEvent;
+    rfbKbdReleaseAllKeysProcPtr kbdReleaseAllKeys;
+    rfbPtrAddEventProcPtr ptrAddEvent;
+    rfbSetXCutTextProcPtr setXCutText;
+    rfbGetCursorProcPtr getCursorPtr;
+    rfbSetTranslateFunctionProcPtr setTranslateFunction;
+    rfbSetSingleWindowProcPtr setSingleWindow;
+    rfbSetServerInputProcPtr  setServerInput;
+    rfbFileTransferPermitted  getFileTransferPermission;
+    rfbSetTextChat            setTextChat;
+    
+    /* newClientHook is called just after a new client is created */
+    rfbNewClientHookPtr newClientHook;
+    /* displayHook is called just before a frame buffer update */
+    rfbDisplayHookPtr displayHook;
+
+    /* These hooks are called to pass keyboard state back to the client */
+    rfbGetKeyboardLedStateHookPtr getKeyboardLedStateHook;
+
+#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
+    MUTEX(cursorMutex);
+    rfbBool backgroundLoop;
+#endif
+
+    /* if TRUE, an ignoring signal handler is installed for SIGPIPE */
+    rfbBool ignoreSIGPIPE;
+
+    /* if not zero, only a slice of this height is processed every time
+     * an update should be sent. This should make working on a slow
+     * link more interactive. */
+    int progressiveSliceHeight;
+
+    in_addr_t listenInterface;
+    int deferPtrUpdateTime;
+
+    /* handle as many input events as possible (default off) */
+    rfbBool handleEventsEagerly;
+
+    /* rfbEncodingServerIdentity */
+    char *versionString;
+
+    /* What does the server tell the new clients which version it supports */
+    int protocolMajorVersion;
+    int protocolMinorVersion;
+
+    /* command line authorization of file transfers */
+    rfbBool permitFileTransfer;
+} rfbScreenInfo, *rfbScreenInfoPtr;
+
+
+/*
+ * rfbTranslateFnType is the type of translation functions.
+ */
+
+typedef void (*rfbTranslateFnType)(char *table, rfbPixelFormat *in,
+                                   rfbPixelFormat *out,
+                                   char *iptr, char *optr,
+                                   int bytesBetweenInputLines,
+                                   int width, int height);
+
+
+/* region stuff */
+
+struct sraRegion;
+typedef struct sraRegion* sraRegionPtr;
+
+/*
+ * Per-client structure.
+ */
+
+typedef void (*ClientGoneHookPtr)(struct _rfbClientRec* cl);
+
+typedef struct _rfbFileTransferData {
+  int fd;
+  int compressionEnabled;
+  int fileSize;
+  int numPackets;
+  int receiving;
+  int sending;
+} rfbFileTransferData;
+
+
+typedef struct _rfbStatList {
+    uint32_t type;
+    uint32_t sentCount;
+    uint32_t bytesSent;
+    uint32_t bytesSentIfRaw;
+    uint32_t rcvdCount;
+    uint32_t bytesRcvd;
+    uint32_t bytesRcvdIfRaw;
+    struct _rfbStatList *Next;
+} rfbStatList;
+
+typedef struct _rfbClientRec {
+  
+    /* back pointer to the screen */
+    rfbScreenInfoPtr screen;
+
+     /* points to a scaled version of the screen buffer in cl->scaledScreenList */
+     rfbScreenInfoPtr scaledScreen;
+     /* how did the client tell us it wanted the screen changed?  Ultra style or palm style? */
+     rfbBool PalmVNC;
+    
+  
+    /* private data. You should put any application client specific data
+     * into a struct and let clientData point to it. Don't forget to
+     * free the struct via clientGoneHook!
+     *
+     * This is useful if the IO functions have to behave client specific.
+     */
+    void* clientData;
+    ClientGoneHookPtr clientGoneHook;
+
+    SOCKET sock;
+    char *host;
+
+    /* RFB protocol minor version number */
+    int protocolMajorVersion;
+    int protocolMinorVersion;
+
+#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
+    pthread_t client_thread;
+#endif
+                                /* Possible client states: */
+    enum {
+        RFB_PROTOCOL_VERSION,   /* establishing protocol version */
+       RFB_SECURITY_TYPE,      /* negotiating security (RFB v.3.7) */
+        RFB_AUTHENTICATION,     /* authenticating */
+        RFB_INITIALISATION,     /* sending initialisation messages */
+        RFB_NORMAL              /* normal protocol messages */
+    } state;
+
+    rfbBool reverseConnection;
+    rfbBool onHold;
+    rfbBool readyForSetColourMapEntries;
+    rfbBool useCopyRect;
+    int preferredEncoding;
+    int correMaxWidth, correMaxHeight;
+
+    rfbBool viewOnly;
+
+    /* The following member is only used during VNC authentication */
+    uint8_t authChallenge[CHALLENGESIZE];
+
+    /* The following members represent the update needed to get the client's
+       framebuffer from its present state to the current state of our
+       framebuffer.
+
+       If the client does not accept CopyRect encoding then the update is
+       simply represented as the region of the screen which has been modified
+       (modifiedRegion).
+
+       If the client does accept CopyRect encoding, then the update consists of
+       two parts.  First we have a single copy from one region of the screen to
+       another (the destination of the copy is copyRegion), and second we have
+       the region of the screen which has been modified in some other way
+       (modifiedRegion).
+
+       Although the copy is of a single region, this region may have many
+       rectangles.  When sending an update, the copyRegion is always sent
+       before the modifiedRegion.  This is because the modifiedRegion may
+       overlap parts of the screen which are in the source of the copy.
+
+       In fact during normal processing, the modifiedRegion may even overlap
+       the destination copyRegion.  Just before an update is sent we remove
+       from the copyRegion anything in the modifiedRegion. */
+
+    sraRegionPtr copyRegion;   /* the destination region of the copy */
+    int copyDX, copyDY;                /* the translation by which the copy happens */
+
+    sraRegionPtr modifiedRegion;
+
+    /* As part of the FramebufferUpdateRequest, a client can express interest
+       in a subrectangle of the whole framebuffer.  This is stored in the
+       requestedRegion member.  In the normal case this is the whole
+       framebuffer if the client is ready, empty if it's not. */
+
+    sraRegionPtr requestedRegion;
+
+    /* The following member represents the state of the "deferred update" timer
+       - when the framebuffer is modified and the client is ready, in most
+       cases it is more efficient to defer sending the update by a few
+       milliseconds so that several changes to the framebuffer can be combined
+       into a single update. */
+
+      struct timeval startDeferring;
+      struct timeval startPtrDeferring;
+      int lastPtrX;
+      int lastPtrY;
+      int lastPtrButtons;
+
+    /* translateFn points to the translation function which is used to copy
+       and translate a rectangle from the framebuffer to an output buffer. */
+
+    rfbTranslateFnType translateFn;
+    char *translateLookupTable;
+    rfbPixelFormat format;
+
+    /*
+     * UPDATE_BUF_SIZE must be big enough to send at least one whole line of the
+     * framebuffer.  So for a max screen width of say 2K with 32-bit pixels this
+     * means 8K minimum.
+     */
+
+#define UPDATE_BUF_SIZE 30000
+
+    char updateBuf[UPDATE_BUF_SIZE];
+    int ublen;
+
+    /* statistics */
+    struct _rfbStatList *statEncList;
+    struct _rfbStatList *statMsgList;
+    int rawBytesEquivalent;
+    int bytesSent;
+        
+#ifdef LIBVNCSERVER_HAVE_LIBZ
+    /* zlib encoding -- necessary compression state info per client */
+
+    struct z_stream_s compStream;
+    rfbBool compStreamInited;
+    uint32_t zlibCompressLevel;
+    /* the quality level is also used by ZYWRLE */
+    int tightQualityLevel;
+
+#ifdef LIBVNCSERVER_HAVE_LIBJPEG
+    /* tight encoding -- preserve zlib streams' state for each client */
+    z_stream zsStruct[4];
+    rfbBool zsActive[4];
+    int zsLevel[4];
+    int tightCompressLevel;
+#endif
+#endif
+
+    /* Ultra Encoding support */
+    rfbBool compStreamInitedLZO;
+    char *lzoWrkMem;
+
+    rfbFileTransferData fileTransfer;
+
+    int     lastKeyboardLedState;     /* keep track of last value so we can send *change* events */
+    rfbBool enableSupportedMessages;  /* client supports SupportedMessages encoding */
+    rfbBool enableSupportedEncodings; /* client supports SupportedEncodings encoding */
+    rfbBool enableServerIdentity;     /* client supports ServerIdentity encoding */
+    rfbBool enableKeyboardLedState;   /* client supports KeyboardState encoding */
+    rfbBool enableLastRectEncoding;   /* client supports LastRect encoding */
+    rfbBool enableCursorShapeUpdates; /* client supports cursor shape updates */
+    rfbBool enableCursorPosUpdates;   /* client supports cursor position updates */
+    rfbBool useRichCursorEncoding;    /* rfbEncodingRichCursor is preferred */
+    rfbBool cursorWasChanged;         /* cursor shape update should be sent */
+    rfbBool cursorWasMoved;           /* cursor position update should be sent */
+    int cursorX,cursorY;             /* the coordinates of the cursor,
+                                        if enableCursorShapeUpdates = FALSE */
+
+    rfbBool useNewFBSize;             /* client supports NewFBSize encoding */
+    rfbBool newFBSizePending;         /* framebuffer size was changed */
+
+    struct _rfbClientRec *prev;
+    struct _rfbClientRec *next;
+
+#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
+    /* whenever a client is referenced, the refCount has to be incremented
+       and afterwards decremented, so that the client is not cleaned up
+       while being referenced.
+       Use the functions rfbIncrClientRef(cl) and rfbDecrClientRef(cl);
+    */
+    int refCount;
+    MUTEX(refCountMutex);
+    COND(deleteCond);
+
+    MUTEX(outputMutex);
+    MUTEX(updateMutex);
+    COND(updateCond);
+#endif
+
+#ifdef LIBVNCSERVER_HAVE_LIBZ
+    void* zrleData;
+    int zywrleLevel;
+    int zywrleBuf[rfbZRLETileWidth * rfbZRLETileHeight];
+#endif
+
+    /* if progressive updating is on, this variable holds the current
+     * y coordinate of the progressive slice. */
+    int progressiveSliceY;
+
+    rfbExtensionData* extensions;
+} rfbClientRec, *rfbClientPtr;
+
+/*
+ * This macro is used to test whether there is a framebuffer update needing to
+ * be sent to the client.
+ */
+
+#define FB_UPDATE_PENDING(cl)                                              \
+     (((cl)->enableCursorShapeUpdates && (cl)->cursorWasChanged) ||        \
+     (((cl)->enableCursorShapeUpdates == FALSE &&                          \
+       ((cl)->cursorX != (cl)->screen->cursorX ||                          \
+       (cl)->cursorY != (cl)->screen->cursorY))) ||                       \
+     ((cl)->useNewFBSize && (cl)->newFBSizePending) ||                     \
+     ((cl)->enableCursorPosUpdates && (cl)->cursorWasMoved) ||             \
+     !sraRgnEmpty((cl)->copyRegion) || !sraRgnEmpty((cl)->modifiedRegion))
+
+/*
+ * Macros for endian swapping.
+ */
+
+#define Swap16(s) ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff))
+
+#define Swap24(l) ((((l) & 0xff) << 16) | (((l) >> 16) & 0xff) | \
+                   (((l) & 0x00ff00)))
+
+#define Swap32(l) (((l) >> 24) | \
+                   (((l) & 0x00ff0000) >> 8)  | \
+                   (((l) & 0x0000ff00) << 8)  | \
+                   ((l) << 24))
+
+
+extern char rfbEndianTest;
+
+#define Swap16IfLE(s) (rfbEndianTest ? Swap16(s) : (s))
+#define Swap24IfLE(l) (rfbEndianTest ? Swap24(l) : (l))
+#define Swap32IfLE(l) (rfbEndianTest ? Swap32(l) : (l))
+
+/* UltraVNC uses some windows structures unmodified, so the viewer expects LittleEndian Data */
+#define Swap16IfBE(s) (rfbEndianTest ? (s) : Swap16(s))
+#define Swap24IfBE(l) (rfbEndianTest ? (l) : Swap24(l))
+#define Swap32IfBE(l) (rfbEndianTest ? (l) : Swap32(l))
+
+/* sockets.c */
+
+extern int rfbMaxClientWait;
+
+extern void rfbInitSockets(rfbScreenInfoPtr rfbScreen);
+extern void rfbShutdownSockets(rfbScreenInfoPtr rfbScreen);
+extern void rfbDisconnectUDPSock(rfbScreenInfoPtr rfbScreen);
+extern void rfbCloseClient(rfbClientPtr cl);
+extern int rfbReadExact(rfbClientPtr cl, char *buf, int len);
+extern int rfbReadExactTimeout(rfbClientPtr cl, char *buf, int len,int timeout);
+extern int rfbWriteExact(rfbClientPtr cl, const char *buf, int len);
+extern int rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec);
+extern int rfbConnect(rfbScreenInfoPtr rfbScreen, char* host, int port);
+extern int rfbConnectToTcpAddr(char* host, int port);
+extern int rfbListenOnTCPPort(int port, in_addr_t iface);
+extern int rfbListenOnUDPPort(int port, in_addr_t iface);
+extern int rfbStringToAddr(char* string,in_addr_t* addr);
+
+/* rfbserver.c */
+
+/* Routines to iterate over the client list in a thread-safe way.
+   Only a single iterator can be in use at a time process-wide. */
+typedef struct rfbClientIterator *rfbClientIteratorPtr;
+
+extern void rfbClientListInit(rfbScreenInfoPtr rfbScreen);
+extern rfbClientIteratorPtr rfbGetClientIterator(rfbScreenInfoPtr rfbScreen);
+extern rfbClientPtr rfbClientIteratorNext(rfbClientIteratorPtr iterator);
+extern void rfbReleaseClientIterator(rfbClientIteratorPtr iterator);
+extern void rfbIncrClientRef(rfbClientPtr cl);
+extern void rfbDecrClientRef(rfbClientPtr cl);
+
+extern void rfbNewClientConnection(rfbScreenInfoPtr rfbScreen,int sock);
+extern rfbClientPtr rfbNewClient(rfbScreenInfoPtr rfbScreen,int sock);
+extern rfbClientPtr rfbNewUDPClient(rfbScreenInfoPtr rfbScreen);
+extern rfbClientPtr rfbReverseConnection(rfbScreenInfoPtr rfbScreen,char *host, int port);
+extern void rfbClientConnectionGone(rfbClientPtr cl);
+extern void rfbProcessClientMessage(rfbClientPtr cl);
+extern void rfbClientConnFailed(rfbClientPtr cl, char *reason);
+extern void rfbNewUDPConnection(rfbScreenInfoPtr rfbScreen,int sock);
+extern void rfbProcessUDPInput(rfbScreenInfoPtr rfbScreen);
+extern rfbBool rfbSendFramebufferUpdate(rfbClientPtr cl, sraRegionPtr updateRegion);
+extern rfbBool rfbSendRectEncodingRaw(rfbClientPtr cl, int x,int y,int w,int h);
+extern rfbBool rfbSendUpdateBuf(rfbClientPtr cl);
+extern void rfbSendServerCutText(rfbScreenInfoPtr rfbScreen,char *str, int len);
+extern rfbBool rfbSendCopyRegion(rfbClientPtr cl,sraRegionPtr reg,int dx,int dy);
+extern rfbBool rfbSendLastRectMarker(rfbClientPtr cl);
+extern rfbBool rfbSendNewFBSize(rfbClientPtr cl, int w, int h);
+extern rfbBool rfbSendSetColourMapEntries(rfbClientPtr cl, int firstColour, int nColours);
+extern void rfbSendBell(rfbScreenInfoPtr rfbScreen);
+
+extern char *rfbProcessFileTransferReadBuffer(rfbClientPtr cl, uint32_t length);
+extern rfbBool rfbSendFileTransferChunk(rfbClientPtr cl);
+extern rfbBool rfbSendDirContent(rfbClientPtr cl, int length, char *buffer);
+extern rfbBool rfbSendFileTransferMessage(rfbClientPtr cl, uint8_t contentType, uint8_t contentParam, uint32_t size, uint32_t length, char *buffer);
+extern char *rfbProcessFileTransferReadBuffer(rfbClientPtr cl, uint32_t length);
+extern rfbBool rfbProcessFileTransfer(rfbClientPtr cl, uint8_t contentType, uint8_t contentParam, uint32_t size, uint32_t length);
+
+void rfbGotXCutText(rfbScreenInfoPtr rfbScreen, char *str, int len);
+
+/* translate.c */
+
+extern rfbBool rfbEconomicTranslate;
+
+extern void rfbTranslateNone(char *table, rfbPixelFormat *in,
+                             rfbPixelFormat *out,
+                             char *iptr, char *optr,
+                             int bytesBetweenInputLines,
+                             int width, int height);
+extern rfbBool rfbSetTranslateFunction(rfbClientPtr cl);
+extern rfbBool rfbSetClientColourMap(rfbClientPtr cl, int firstColour, int nColours);
+extern void rfbSetClientColourMaps(rfbScreenInfoPtr rfbScreen, int firstColour, int nColours);
+
+/* httpd.c */
+
+extern void rfbHttpInitSockets(rfbScreenInfoPtr rfbScreen);
+extern void rfbHttpShutdownSockets(rfbScreenInfoPtr rfbScreen);
+extern void rfbHttpCheckFds(rfbScreenInfoPtr rfbScreen);
+
+
+
+/* auth.c */
+
+extern void rfbAuthNewClient(rfbClientPtr cl);
+extern void rfbProcessClientSecurityType(rfbClientPtr cl);
+extern void rfbAuthProcessClientMessage(rfbClientPtr cl);
+extern void rfbRegisterSecurityHandler(rfbSecurityHandler* handler);
+extern void rfbUnregisterSecurityHandler(rfbSecurityHandler* handler);
+
+/* rre.c */
+
+extern rfbBool rfbSendRectEncodingRRE(rfbClientPtr cl, int x,int y,int w,int h);
+
+
+/* corre.c */
+
+extern rfbBool rfbSendRectEncodingCoRRE(rfbClientPtr cl, int x,int y,int w,int h);
+
+
+/* hextile.c */
+
+extern rfbBool rfbSendRectEncodingHextile(rfbClientPtr cl, int x, int y, int w,
+                                       int h);
+
+/* ultra.c */
+
+/* Set maximum ultra rectangle size in pixels.  Always allow at least
+ * two scan lines.
+ */
+#define ULTRA_MAX_RECT_SIZE (128*256)
+#define ULTRA_MAX_SIZE(min) ((( min * 2 ) > ULTRA_MAX_RECT_SIZE ) ? \
+                            ( min * 2 ) : ULTRA_MAX_RECT_SIZE )
+
+extern rfbBool rfbSendRectEncodingUltra(rfbClientPtr cl, int x,int y,int w,int h);
+
+
+#ifdef LIBVNCSERVER_HAVE_LIBZ
+/* zlib.c */
+
+/* Minimum zlib rectangle size in bytes.  Anything smaller will
+ * not compress well due to overhead.
+ */
+#define VNC_ENCODE_ZLIB_MIN_COMP_SIZE (17)
+
+/* Set maximum zlib rectangle size in pixels.  Always allow at least
+ * two scan lines.
+ */
+#define ZLIB_MAX_RECT_SIZE (128*256)
+#define ZLIB_MAX_SIZE(min) ((( min * 2 ) > ZLIB_MAX_RECT_SIZE ) ? \
+                           ( min * 2 ) : ZLIB_MAX_RECT_SIZE )
+
+extern rfbBool rfbSendRectEncodingZlib(rfbClientPtr cl, int x, int y, int w,
+                                   int h);
+
+#ifdef LIBVNCSERVER_HAVE_LIBJPEG
+/* tight.c */
+
+#define TIGHT_DEFAULT_COMPRESSION  6
+
+extern rfbBool rfbTightDisableGradient;
+
+extern int rfbNumCodedRectsTight(rfbClientPtr cl, int x,int y,int w,int h);
+extern rfbBool rfbSendRectEncodingTight(rfbClientPtr cl, int x,int y,int w,int h);
+
+#endif
+#endif
+
+
+/* cursor.c */
+
+typedef struct rfbCursor {
+    /* set this to true if LibVNCServer has to free this cursor */
+    rfbBool cleanup, cleanupSource, cleanupMask, cleanupRichSource;
+    unsigned char *source;                     /* points to bits */
+    unsigned char *mask;                       /* points to bits */
+    unsigned short width, height, xhot, yhot;  /* metrics */
+    unsigned short foreRed, foreGreen, foreBlue; /* device-independent colour */
+    unsigned short backRed, backGreen, backBlue; /* device-independent colour */
+    unsigned char *richSource; /* source bytes for a rich cursor */
+    unsigned char *alphaSource; /* source for alpha blending info */
+    rfbBool alphaPreMultiplied; /* if richSource already has alpha applied */
+} rfbCursor, *rfbCursorPtr;
+extern unsigned char rfbReverseByte[0x100];
+
+extern rfbBool rfbSendCursorShape(rfbClientPtr cl/*, rfbScreenInfoPtr pScreen*/);
+extern rfbBool rfbSendCursorPos(rfbClientPtr cl);
+extern void rfbConvertLSBCursorBitmapOrMask(int width,int height,unsigned char* bitmap);
+extern rfbCursorPtr rfbMakeXCursor(int width,int height,char* cursorString,char* maskString);
+extern char* rfbMakeMaskForXCursor(int width,int height,char* cursorString);
+extern char* rfbMakeMaskFromAlphaSource(int width,int height,unsigned char* alphaSource);
+extern void rfbMakeXCursorFromRichCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor);
+extern void rfbMakeRichCursorFromXCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor);
+extern void rfbFreeCursor(rfbCursorPtr cursor);
+extern void rfbSetCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr c);
+
+/* cursor handling for the pointer */
+extern void rfbDefaultPtrAddEvent(int buttonMask,int x,int y,rfbClientPtr cl);
+
+/* zrle.c */
+#ifdef LIBVNCSERVER_HAVE_LIBZ
+extern rfbBool rfbSendRectEncodingZRLE(rfbClientPtr cl, int x, int y, int w,int h);
+#endif
+
+/* stats.c */
+
+extern void rfbResetStats(rfbClientPtr cl);
+extern void rfbPrintStats(rfbClientPtr cl);
+
+/* font.c */
+
+typedef struct rfbFontData {
+  unsigned char* data;
+  /*
+    metaData is a 256*5 array:
+    for each character
+    (offset,width,height,x,y)
+  */
+  int* metaData;
+} rfbFontData,* rfbFontDataPtr;
+
+int rfbDrawChar(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,int x,int y,unsigned char c,rfbPixel colour);
+void rfbDrawString(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,int x,int y,const char* string,rfbPixel colour);
+/* if colour==backColour, background is transparent */
+int rfbDrawCharWithClip(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,int x,int y,unsigned char c,int x1,int y1,int x2,int y2,rfbPixel colour,rfbPixel backColour);
+void rfbDrawStringWithClip(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,int x,int y,const char* string,int x1,int y1,int x2,int y2,rfbPixel colour,rfbPixel backColour);
+int rfbWidthOfString(rfbFontDataPtr font,const char* string);
+int rfbWidthOfChar(rfbFontDataPtr font,unsigned char c);
+void rfbFontBBox(rfbFontDataPtr font,unsigned char c,int* x1,int* y1,int* x2,int* y2);
+/* this returns the smallest box enclosing any character of font. */
+void rfbWholeFontBBox(rfbFontDataPtr font,int *x1, int *y1, int *x2, int *y2);
+
+/* dynamically load a linux console font (4096 bytes, 256 glyphs a 8x16 */
+rfbFontDataPtr rfbLoadConsoleFont(char *filename);
+/* free a dynamically loaded font */
+void rfbFreeFont(rfbFontDataPtr font);
+
+/* draw.c */
+
+void rfbFillRect(rfbScreenInfoPtr s,int x1,int y1,int x2,int y2,rfbPixel col);
+void rfbDrawPixel(rfbScreenInfoPtr s,int x,int y,rfbPixel col);
+void rfbDrawLine(rfbScreenInfoPtr s,int x1,int y1,int x2,int y2,rfbPixel col);
+
+/* selbox.c */
+
+/* this opens a modal select box. list is an array of strings, the end marked
+   with a NULL.
+   It returns the index in the list or -1 if cancelled or something else
+   wasn't kosher. */
+typedef void (*SelectionChangedHookPtr)(int _index);
+extern int rfbSelectBox(rfbScreenInfoPtr rfbScreen,
+                       rfbFontDataPtr font, char** list,
+                       int x1, int y1, int x2, int y2,
+                       rfbPixel foreColour, rfbPixel backColour,
+                       int border,SelectionChangedHookPtr selChangedHook);
+
+/* cargs.c */
+
+extern void rfbUsage(void);
+extern void rfbPurgeArguments(int* argc,int* position,int count,char *argv[]);
+extern rfbBool rfbProcessArguments(rfbScreenInfoPtr rfbScreen,int* argc, char *argv[]);
+extern rfbBool rfbProcessSizeArguments(int* width,int* height,int* bpp,int* argc, char *argv[]);
+
+/* main.c */
+
+extern void rfbLogEnable(int enabled);
+typedef void (*rfbLogProc)(const char *format, ...);
+extern rfbLogProc rfbLog, rfbErr;
+extern void rfbLogPerror(const char *str);
+
+void rfbScheduleCopyRect(rfbScreenInfoPtr rfbScreen,int x1,int y1,int x2,int y2,int dx,int dy);
+void rfbScheduleCopyRegion(rfbScreenInfoPtr rfbScreen,sraRegionPtr copyRegion,int dx,int dy);
+
+void rfbDoCopyRect(rfbScreenInfoPtr rfbScreen,int x1,int y1,int x2,int y2,int dx,int dy);
+void rfbDoCopyRegion(rfbScreenInfoPtr rfbScreen,sraRegionPtr copyRegion,int dx,int dy);
+
+void rfbMarkRectAsModified(rfbScreenInfoPtr rfbScreen,int x1,int y1,int x2,int y2);
+void rfbMarkRegionAsModified(rfbScreenInfoPtr rfbScreen,sraRegionPtr modRegion);
+void rfbDoNothingWithClient(rfbClientPtr cl);
+enum rfbNewClientAction defaultNewClientHook(rfbClientPtr cl);
+void rfbRegisterProtocolExtension(rfbProtocolExtension* extension);
+void rfbUnregisterProtocolExtension(rfbProtocolExtension* extension);
+struct _rfbProtocolExtension* rfbGetExtensionIterator();
+void rfbReleaseExtensionIterator();
+rfbBool rfbEnableExtension(rfbClientPtr cl, rfbProtocolExtension* extension,
+       void* data);
+rfbBool rfbDisableExtension(rfbClientPtr cl, rfbProtocolExtension* extension);
+void* rfbGetExtensionClientData(rfbClientPtr cl, rfbProtocolExtension* extension);
+
+/* to check against plain passwords */
+rfbBool rfbCheckPasswordByList(rfbClientPtr cl,const char* response,int len);
+
+/* functions to make a vnc server */
+extern rfbScreenInfoPtr rfbGetScreen(int* argc,char** argv,
+ int width,int height,int bitsPerSample,int samplesPerPixel,
+ int bytesPerPixel);
+extern void rfbInitServer(rfbScreenInfoPtr rfbScreen);
+extern void rfbShutdownServer(rfbScreenInfoPtr rfbScreen,rfbBool disconnectClients);
+extern void rfbNewFramebuffer(rfbScreenInfoPtr rfbScreen,char *framebuffer,
+ int width,int height, int bitsPerSample,int samplesPerPixel,
+ int bytesPerPixel);
+
+extern void rfbScreenCleanup(rfbScreenInfoPtr screenInfo);
+extern void rfbSetServerVersionIdentity(rfbScreenInfoPtr screen, char *fmt, ...);
+
+/* functions to accept/refuse a client that has been put on hold
+   by a NewClientHookPtr function. Must not be called in other
+   situations. */
+extern void rfbStartOnHoldClient(rfbClientPtr cl);
+extern void rfbRefuseOnHoldClient(rfbClientPtr cl);
+
+/* call one of these two functions to service the vnc clients.
+ usec are the microseconds the select on the fds waits.
+ if you are using the event loop, set this to some value > 0, so the
+ server doesn't get a high load just by listening.
+ rfbProcessEvents() returns TRUE if an update was pending. */
+
+extern void rfbRunEventLoop(rfbScreenInfoPtr screenInfo, long usec, rfbBool runInBackground);
+extern rfbBool rfbProcessEvents(rfbScreenInfoPtr screenInfo,long usec);
+extern rfbBool rfbIsActive(rfbScreenInfoPtr screenInfo);
+
+/* TightVNC file transfer extension */
+void rfbRegisterTightVNCFileTransferExtension();
+void rfbUnregisterTightVNCFileTransferExtension(); 
+
+/* Statistics */
+extern char *messageNameServer2Client(uint32_t type, char *buf, int len);
+extern char *messageNameClient2Server(uint32_t type, char *buf, int len);
+extern char *encodingName(uint32_t enc, char *buf, int len);
+
+extern rfbStatList *rfbStatLookupEncoding(rfbClientPtr cl, uint32_t type);
+extern rfbStatList *rfbStatLookupMessage(rfbClientPtr cl, uint32_t type);
+
+/* Each call to rfbStatRecord* adds one to the rect count for that type */
+extern void rfbStatRecordEncodingSent(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw);
+extern void rfbStatRecordEncodingSentAdd(rfbClientPtr cl, uint32_t type, int byteCount); /* Specifically for tight encoding */
+extern void rfbStatRecordEncodingRcvd(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw);
+extern void rfbStatRecordMessageSent(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw);
+extern void rfbStatRecordMessageRcvd(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw);
+extern void rfbResetStats(rfbClientPtr cl);
+extern void rfbPrintStats(rfbClientPtr cl);
+
+extern int rfbStatGetSentBytes(rfbClientPtr cl);
+extern int rfbStatGetSentBytesIfRaw(rfbClientPtr cl);
+extern int rfbStatGetRcvdBytes(rfbClientPtr cl);
+extern int rfbStatGetRcvdBytesIfRaw(rfbClientPtr cl);
+extern int rfbStatGetMessageCountSent(rfbClientPtr cl, uint32_t type);
+extern int rfbStatGetMessageCountRcvd(rfbClientPtr cl, uint32_t type);
+extern int rfbStatGetEncodingCountSent(rfbClientPtr cl, uint32_t type);
+extern int rfbStatGetEncodingCountRcvd(rfbClientPtr cl, uint32_t type);
+
+/* Set which version you want to advertise 3.3, 3.6, 3.7 and 3.8 are currently supported*/
+extern void rfbSetProtocolVersion(rfbScreenInfoPtr rfbScreen, int major_, int minor_);
+
+/* send a TextChat message to a client */
+extern rfbBool rfbSendTextChatMessage(rfbClientPtr cl, uint32_t length, char *buffer);
+
+
+
+
+#if(defined __cplusplus)
+}
+#endif
+
+#endif
+
diff --git a/src/rfb/rfbclient.h b/src/rfb/rfbclient.h
new file mode 100644 (file)
index 0000000..b92f220
--- /dev/null
@@ -0,0 +1,335 @@
+#ifndef RFBCLIENT_H
+#define RFBCLIENT_H
+
+/*
+ *  Copyright (C) 2000, 2001 Const Kaplinsky.  All Rights Reserved.
+ *  Copyright (C) 2000 Tridia Corporation.  All Rights Reserved.
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+/*
+ * vncviewer.h
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <rfb/rfbproto.h>
+#include <rfb/keysym.h>
+
+#define rfbClientSwap16IfLE(s) \
+    (*(char *)&client->endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
+
+#define rfbClientSwap32IfLE(l) \
+    (*(char *)&client->endianTest ? ((((l) & 0xff000000) >> 24) | \
+                            (((l) & 0x00ff0000) >> 8)  | \
+                            (((l) & 0x0000ff00) << 8)  | \
+                            (((l) & 0x000000ff) << 24))  : (l))
+
+#define FLASH_PORT_OFFSET 5400
+#define LISTEN_PORT_OFFSET 5500
+#define TUNNEL_PORT_OFFSET 5500
+#define SERVER_PORT_OFFSET 5900
+
+#define DEFAULT_SSH_CMD "/usr/bin/ssh"
+#define DEFAULT_TUNNEL_CMD  \
+  (DEFAULT_SSH_CMD " -f -L %L:localhost:%R %H sleep 20")
+#define DEFAULT_VIA_CMD     \
+  (DEFAULT_SSH_CMD " -f -L %L:%H:%R %G sleep 20")
+
+#if(defined __cplusplus)
+extern "C"
+{
+#endif
+
+/* vncrec */
+
+typedef struct {
+  FILE* file;
+  struct timeval tv;
+  rfbBool readTimestamp;
+  rfbBool doNotSleep;
+} rfbVNCRec;
+
+/* client data */
+
+typedef struct rfbClientData {
+       void* tag;
+       void* data;
+       struct rfbClientData* next;
+} rfbClientData;
+
+/* app data (belongs into rfbClient?) */
+
+typedef struct {
+  rfbBool shareDesktop;
+  rfbBool viewOnly;
+
+  const char* encodingsString;
+
+  rfbBool useBGR233;
+  int nColours;
+  rfbBool forceOwnCmap;
+  rfbBool forceTrueColour;
+  int requestedDepth;
+
+  int compressLevel;
+  int qualityLevel;
+  rfbBool enableJPEG;
+  rfbBool useRemoteCursor;
+  rfbBool palmVNC;  /* use palmvnc specific SetScale (vs ultravnc) */
+  int scaleSetting; /* 0 means no scale set, else 1/scaleSetting */
+} AppData;
+
+
+struct _rfbClient;
+
+typedef void (*HandleTextChatProc)(struct _rfbClient* client, int value, char *text);
+typedef void (*HandleKeyboardLedStateProc)(struct _rfbClient* client, int value, int pad);
+typedef rfbBool (*HandleCursorPosProc)(struct _rfbClient* client, int x, int y);
+typedef void (*SoftCursorLockAreaProc)(struct _rfbClient* client, int x, int y, int w, int h);
+typedef void (*SoftCursorUnlockScreenProc)(struct _rfbClient* client);
+typedef void (*GotFrameBufferUpdateProc)(struct _rfbClient* client, int x, int y, int w, int h);
+typedef char* (*GetPasswordProc)(struct _rfbClient* client);
+typedef rfbBool (*MallocFrameBufferProc)(struct _rfbClient* client);
+typedef void (*GotXCutTextProc)(struct _rfbClient* client, const char *text, int textlen);
+typedef void (*BellProc)(struct _rfbClient* client);
+
+typedef void (*GotCursorShapeProc)(struct _rfbClient* client, int xhot, int yhot, int width, int height, int bytesPerPixel);
+typedef void (*GotCopyRectProc)(struct _rfbClient* client, int src_x, int src_y, int w, int h, int dest_x, int dest_y);
+
+typedef struct _rfbClient {
+       uint8_t* frameBuffer;
+       int width, height;
+
+       int endianTest;
+
+       AppData appData;
+
+       const char* programName;
+       char* serverHost;
+       int serverPort; /* if -1, then use file recorded by vncrec */
+       rfbBool listenSpecified;
+       int listenPort, flashPort;
+
+       struct {
+               int x, y, w, h;
+       } updateRect;
+
+       /* Note that the CoRRE encoding uses this buffer and assumes it is big enough
+          to hold 255 * 255 * 32 bits -> 260100 bytes.  640*480 = 307200 bytes.
+          Hextile also assumes it is big enough to hold 16 * 16 * 32 bits.
+          Tight encoding assumes BUFFER_SIZE is at least 16384 bytes. */
+
+#define RFB_BUFFER_SIZE (640*480)
+       char buffer[RFB_BUFFER_SIZE];
+
+       /* rfbproto.c */
+
+       int sock;
+       rfbBool canUseCoRRE;
+       rfbBool canUseHextile;
+       char *desktopName;
+       rfbPixelFormat format;
+       rfbServerInitMsg si;
+
+       /* sockets.c */
+#define RFB_BUF_SIZE 8192
+       char buf[RFB_BUF_SIZE];
+       char *bufoutptr;
+       int buffered;
+
+       /* The zlib encoding requires expansion/decompression/deflation of the
+          compressed data in the "buffer" above into another, result buffer.
+          However, the size of the result buffer can be determined precisely
+          based on the bitsPerPixel, height and width of the rectangle.  We
+          allocate this buffer one time to be the full size of the buffer. */
+
+       /* Ultra Encoding uses this buffer too */
+       
+       int ultra_buffer_size;
+       char *ultra_buffer;
+
+       int raw_buffer_size;
+       char *raw_buffer;
+
+#ifdef LIBVNCSERVER_HAVE_LIBZ
+       z_stream decompStream;
+       rfbBool decompStreamInited;
+#endif
+
+
+#ifdef LIBVNCSERVER_HAVE_LIBZ
+       /*
+        * Variables for the ``tight'' encoding implementation.
+        */
+
+       /* Separate buffer for compressed data. */
+#define ZLIB_BUFFER_SIZE 30000
+       char zlib_buffer[ZLIB_BUFFER_SIZE];
+
+       /* Four independent compression streams for zlib library. */
+       z_stream zlibStream[4];
+       rfbBool zlibStreamActive[4];
+
+       /* Filter stuff. Should be initialized by filter initialization code. */
+       rfbBool cutZeros;
+       int rectWidth, rectColors;
+       char tightPalette[256*4];
+       uint8_t tightPrevRow[2048*3*sizeof(uint16_t)];
+
+#ifdef LIBVNCSERVER_HAVE_LIBJPEG
+       /* JPEG decoder state. */
+       rfbBool jpegError;
+
+       struct jpeg_source_mgr* jpegSrcManager;
+       void* jpegBufferPtr;
+       size_t jpegBufferLen;
+
+#endif
+#endif
+
+
+       /* cursor.c */
+       uint8_t *rcSource, *rcMask;
+
+       /* private data pointer */
+       rfbClientData* clientData;
+
+       rfbVNCRec* vncRec;
+
+       /* Keyboard State support (is 'Caps Lock' set on the remote display???) */
+       int KeyboardLedStateEnabled;
+       int CurrentKeyboardLedState;
+
+       int canHandleNewFBSize;
+
+       /* hooks */
+       HandleTextChatProc         HandleTextChat;
+       HandleKeyboardLedStateProc HandleKeyboardLedState;
+       HandleCursorPosProc HandleCursorPos;
+       SoftCursorLockAreaProc SoftCursorLockArea;
+       SoftCursorUnlockScreenProc SoftCursorUnlockScreen;
+       GotFrameBufferUpdateProc GotFrameBufferUpdate;
+       /* the pointer returned by GetPassword will be freed after use! */
+       GetPasswordProc GetPassword;
+       MallocFrameBufferProc MallocFrameBuffer;
+       GotXCutTextProc GotXCutText;
+       BellProc Bell;
+
+       GotCursorShapeProc GotCursorShape;
+       GotCopyRectProc GotCopyRect;
+
+       /* Which messages are supported by the server
+        * This is a *guess* for most servers.
+        * (If we can even detect the type of server)
+        *
+        * If the server supports the "rfbEncodingSupportedMessages"
+        * then this will be updated when the encoding is received to
+        * accurately reflect the servers capabilities.
+        */
+       rfbSupportedMessages supportedMessages;
+
+       /* negotiated protocol version */
+       int major, minor;
+} rfbClient;
+
+/* cursor.c */
+
+extern rfbBool HandleCursorShape(rfbClient* client,int xhot, int yhot, int width, int height, uint32_t enc);
+
+/* listen.c */
+
+extern void listenForIncomingConnections(rfbClient* viewer);
+
+/* rfbproto.c */
+
+extern rfbBool rfbEnableClientLogging;
+typedef void (*rfbClientLogProc)(const char *format, ...);
+extern rfbClientLogProc rfbClientLog,rfbClientErr;
+extern rfbBool ConnectToRFBServer(rfbClient* client,const char *hostname, int port);
+extern rfbBool InitialiseRFBConnection(rfbClient* client);
+extern rfbBool SetFormatAndEncodings(rfbClient* client);
+extern rfbBool SendIncrementalFramebufferUpdateRequest(rfbClient* client);
+extern rfbBool SendFramebufferUpdateRequest(rfbClient* client,
+                                        int x, int y, int w, int h,
+                                        rfbBool incremental);
+extern rfbBool SendScaleSetting(rfbClient* client,int scaleSetting);
+extern rfbBool SendPointerEvent(rfbClient* client,int x, int y, int buttonMask);
+extern rfbBool SendKeyEvent(rfbClient* client,uint32_t key, rfbBool down);
+extern rfbBool SendClientCutText(rfbClient* client,char *str, int len);
+extern rfbBool HandleRFBServerMessage(rfbClient* client);
+
+extern rfbBool TextChatSend(rfbClient* client, char *text);
+extern rfbBool TextChatOpen(rfbClient* client);
+extern rfbBool TextChatClose(rfbClient* client);
+extern rfbBool TextChatFinish(rfbClient* client);
+extern rfbBool PermitServerInput(rfbClient* client, int enabled);
+
+extern void PrintPixelFormat(rfbPixelFormat *format);
+
+/* client data */
+
+void rfbClientSetClientData(rfbClient* client, void* tag, void* data);
+void* rfbClientGetClientData(rfbClient* client, void* tag);
+
+/* protocol extensions */
+
+typedef struct _rfbClientProtocolExtension {
+       int* encodings;
+       /* returns TRUE if the encoding was handled */
+       rfbBool (*handleEncoding)(rfbClient* cl,
+               rfbFramebufferUpdateRectHeader* rect);
+       /* returns TRUE if it handled the message */
+       rfbBool (*handleMessage)(rfbClient* cl,
+                rfbServerToClientMsg* message);
+       struct _rfbClientProtocolExtension* next;
+} rfbClientProtocolExtension;
+
+void rfbClientRegisterExtension(rfbClientProtocolExtension* e);
+
+/* sockets.c */
+
+extern rfbBool errorMessageOnReadFailure;
+
+extern rfbBool ReadFromRFBServer(rfbClient* client, char *out, unsigned int n);
+extern rfbBool WriteToRFBServer(rfbClient* client, char *buf, int n);
+extern int FindFreeTcpPort(void);
+extern int ListenAtTcpPort(int port);
+extern int ConnectClientToTcpAddr(unsigned int host, int port);
+extern int AcceptTcpConnection(int listenSock);
+extern rfbBool SetNonBlocking(int sock);
+
+extern rfbBool StringToIPAddr(const char *str, unsigned int *addr);
+extern rfbBool SameMachine(int sock);
+extern int WaitForMessage(rfbClient* client,unsigned int usecs);
+
+/* vncviewer.c */
+rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,int bytesPerPixel);
+rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv);
+/* rfbClientCleanup() does not touch client->frameBuffer */
+void rfbClientCleanup(rfbClient* client);
+
+#if(defined __cplusplus)
+}
+#endif
+
+#endif
+
diff --git a/src/rfb/rfbconfig.h b/src/rfb/rfbconfig.h
new file mode 100644 (file)
index 0000000..40d7e9a
--- /dev/null
@@ -0,0 +1,509 @@
+#ifndef _RFB_RFBCONFIG_H
+#define _RFB_RFBCONFIG_H 1
+/* rfb/rfbconfig.h. Generated automatically at end of configure. */
+/* rfbconfig.h.  Generated by configure.  */
+/* rfbconfig.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Enable 24 bit per pixel in native framebuffer */
+#ifndef LIBVNCSERVER_ALLOW24BPP 
+#define LIBVNCSERVER_ALLOW24BPP  1 
+#endif
+
+/* work around when write() returns ENOENT but does not mean it */
+/* #undef LIBVNCSERVER_ENOENT_WORKAROUND */
+
+/* Use ffmpeg (for vnc2mpg) */
+/* #undef LIBVNCSERVER_FFMPEG */
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_ARPA_INET_H 
+#define LIBVNCSERVER_HAVE_ARPA_INET_H  1 
+#endif
+
+/* Avahi/mDNS client build environment present */
+/* #undef LIBVNCSERVER_HAVE_AVAHI */
+
+/* Define to 1 if you have the `crypt' function. */
+/* #undef LIBVNCSERVER_HAVE_CRYPT */
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_DLFCN_H 
+#define LIBVNCSERVER_HAVE_DLFCN_H  1 
+#endif
+
+/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
+/* #undef LIBVNCSERVER_HAVE_DOPRNT */
+
+/* DPMS extension build environment present */
+/* #undef LIBVNCSERVER_HAVE_DPMS */
+
+/* FBPM extension build environment present */
+/* #undef LIBVNCSERVER_HAVE_FBPM */
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_FCNTL_H 
+#define LIBVNCSERVER_HAVE_FCNTL_H  1 
+#endif
+
+/* Define to 1 if you have the `fork' function. */
+#ifndef LIBVNCSERVER_HAVE_FORK 
+#define LIBVNCSERVER_HAVE_FORK  1 
+#endif
+
+/* Define to 1 if you have the `ftime' function. */
+#ifndef LIBVNCSERVER_HAVE_FTIME 
+#define LIBVNCSERVER_HAVE_FTIME  1 
+#endif
+
+/* Define to 1 if you have the `geteuid' function. */
+/* #undef LIBVNCSERVER_HAVE_GETEUID */
+
+/* Define to 1 if you have the `gethostbyname' function. */
+#ifndef LIBVNCSERVER_HAVE_GETHOSTBYNAME 
+#define LIBVNCSERVER_HAVE_GETHOSTBYNAME  1 
+#endif
+
+/* Define to 1 if you have the `gethostname' function. */
+#ifndef LIBVNCSERVER_HAVE_GETHOSTNAME 
+#define LIBVNCSERVER_HAVE_GETHOSTNAME  1 
+#endif
+
+/* Define to 1 if you have the `getpwnam' function. */
+/* #undef LIBVNCSERVER_HAVE_GETPWNAM */
+
+/* Define to 1 if you have the `getpwuid' function. */
+/* #undef LIBVNCSERVER_HAVE_GETPWUID */
+
+/* Define to 1 if you have the `getspnam' function. */
+/* #undef LIBVNCSERVER_HAVE_GETSPNAM */
+
+/* Define to 1 if you have the `gettimeofday' function. */
+#ifndef LIBVNCSERVER_HAVE_GETTIMEOFDAY 
+#define LIBVNCSERVER_HAVE_GETTIMEOFDAY  1 
+#endif
+
+/* Define to 1 if you have the `getuid' function. */
+/* #undef LIBVNCSERVER_HAVE_GETUID */
+
+/* Define to 1 if you have the `grantpt' function. */
+/* #undef LIBVNCSERVER_HAVE_GRANTPT */
+
+/* Define to 1 if you have the `inet_ntoa' function. */
+#ifndef LIBVNCSERVER_HAVE_INET_NTOA 
+#define LIBVNCSERVER_HAVE_INET_NTOA  1 
+#endif
+
+/* Define to 1 if you have the `initgroups' function. */
+/* #undef LIBVNCSERVER_HAVE_INITGROUPS */
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_INTTYPES_H 
+#define LIBVNCSERVER_HAVE_INTTYPES_H  1 
+#endif
+
+/* IRIX XReadDisplay available */
+/* #undef LIBVNCSERVER_HAVE_IRIX_XREADDISPLAY */
+
+/* libcrypt library present */
+/* #undef LIBVNCSERVER_HAVE_LIBCRYPT */
+
+/* openssl libcrypto library present */
+/* #undef LIBVNCSERVER_HAVE_LIBCRYPTO */
+
+/* Define to 1 if you have the `cygipc' library (-lcygipc). */
+/* #undef LIBVNCSERVER_HAVE_LIBCYGIPC */
+
+/* Define to 1 if you have the `jpeg' library (-ljpeg). */
+#ifndef LIBVNCSERVER_HAVE_LIBJPEG 
+#define LIBVNCSERVER_HAVE_LIBJPEG  1 
+#endif
+
+/* Define to 1 if you have the `nsl' library (-lnsl). */
+#ifndef LIBVNCSERVER_HAVE_LIBNSL 
+#define LIBVNCSERVER_HAVE_LIBNSL  1 
+#endif
+
+/* Define to 1 if you have the `pthread' library (-lpthread). */
+#ifndef LIBVNCSERVER_HAVE_LIBPTHREAD 
+#define LIBVNCSERVER_HAVE_LIBPTHREAD  1 
+#endif
+
+/* Define to 1 if you have the `socket' library (-lsocket). */
+/* #undef LIBVNCSERVER_HAVE_LIBSOCKET */
+
+/* openssl libssl library present */
+/* #undef LIBVNCSERVER_HAVE_LIBSSL */
+
+/* XDAMAGE extension build environment present */
+/* #undef LIBVNCSERVER_HAVE_LIBXDAMAGE */
+
+/* XFIXES extension build environment present */
+/* #undef LIBVNCSERVER_HAVE_LIBXFIXES */
+
+/* XINERAMA extension build environment present */
+/* #undef LIBVNCSERVER_HAVE_LIBXINERAMA */
+
+/* XRANDR extension build environment present */
+/* #undef LIBVNCSERVER_HAVE_LIBXRANDR */
+
+/* DEC-XTRAP extension build environment present */
+/* #undef LIBVNCSERVER_HAVE_LIBXTRAP */
+
+/* Define to 1 if you have the `z' library (-lz). */
+#ifndef LIBVNCSERVER_HAVE_LIBZ 
+#define LIBVNCSERVER_HAVE_LIBZ  1 
+#endif
+
+/* linux fb device build environment present */
+/* #undef LIBVNCSERVER_HAVE_LINUX_FB_H */
+
+/* linux/input.h present */
+/* #undef LIBVNCSERVER_HAVE_LINUX_INPUT_H */
+
+/* linux uinput device build environment present */
+/* #undef LIBVNCSERVER_HAVE_LINUX_UINPUT_H */
+
+/* video4linux build environment present */
+/* #undef LIBVNCSERVER_HAVE_LINUX_VIDEODEV_H */
+
+/* build MacOS X native display support */
+/* #undef LIBVNCSERVER_HAVE_MACOSX_NATIVE_DISPLAY */
+
+/* Define to 1 if you have the `memmove' function. */
+#ifndef LIBVNCSERVER_HAVE_MEMMOVE 
+#define LIBVNCSERVER_HAVE_MEMMOVE  1 
+#endif
+
+/* Define to 1 if you have the <memory.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_MEMORY_H 
+#define LIBVNCSERVER_HAVE_MEMORY_H  1 
+#endif
+
+/* Define to 1 if you have the `memset' function. */
+#ifndef LIBVNCSERVER_HAVE_MEMSET 
+#define LIBVNCSERVER_HAVE_MEMSET  1 
+#endif
+
+/* Define to 1 if you have the `mkfifo' function. */
+#ifndef LIBVNCSERVER_HAVE_MKFIFO 
+#define LIBVNCSERVER_HAVE_MKFIFO  1 
+#endif
+
+/* Define to 1 if you have the `mmap' function. */
+#ifndef LIBVNCSERVER_HAVE_MMAP 
+#define LIBVNCSERVER_HAVE_MMAP  1 
+#endif
+
+/* Define to 1 if you have the <netdb.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_NETDB_H 
+#define LIBVNCSERVER_HAVE_NETDB_H  1 
+#endif
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_NETINET_IN_H 
+#define LIBVNCSERVER_HAVE_NETINET_IN_H  1 
+#endif
+
+/* Define to 1 if you have the <pwd.h> header file. */
+/* #undef LIBVNCSERVER_HAVE_PWD_H */
+
+/* RECORD extension build environment present */
+/* #undef LIBVNCSERVER_HAVE_RECORD */
+
+/* Define to 1 if you have the `select' function. */
+#ifndef LIBVNCSERVER_HAVE_SELECT 
+#define LIBVNCSERVER_HAVE_SELECT  1 
+#endif
+
+/* Define to 1 if you have the `setegid' function. */
+/* #undef LIBVNCSERVER_HAVE_SETEGID */
+
+/* Define to 1 if you have the `seteuid' function. */
+/* #undef LIBVNCSERVER_HAVE_SETEUID */
+
+/* Define to 1 if you have the `setgid' function. */
+/* #undef LIBVNCSERVER_HAVE_SETGID */
+
+/* Define to 1 if you have the `setpgrp' function. */
+/* #undef LIBVNCSERVER_HAVE_SETPGRP */
+
+/* Define to 1 if you have the `setsid' function. */
+/* #undef LIBVNCSERVER_HAVE_SETSID */
+
+/* Define to 1 if you have the `setuid' function. */
+/* #undef LIBVNCSERVER_HAVE_SETUID */
+
+/* Define to 1 if you have the `setutxent' function. */
+/* #undef LIBVNCSERVER_HAVE_SETUTXENT */
+
+/* Define to 1 if you have the `shmat' function. */
+/* #undef LIBVNCSERVER_HAVE_SHMAT */
+
+/* Define to 1 if you have the `socket' function. */
+#ifndef LIBVNCSERVER_HAVE_SOCKET 
+#define LIBVNCSERVER_HAVE_SOCKET  1 
+#endif
+
+/* Solaris XReadScreen available */
+/* #undef LIBVNCSERVER_HAVE_SOLARIS_XREADSCREEN */
+
+/* Define to 1 if `stat' has the bug that it succeeds when given the
+   zero-length file name argument. */
+/* #undef LIBVNCSERVER_HAVE_STAT_EMPTY_STRING_BUG */
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_STDINT_H 
+#define LIBVNCSERVER_HAVE_STDINT_H  1 
+#endif
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_STDLIB_H 
+#define LIBVNCSERVER_HAVE_STDLIB_H  1 
+#endif
+
+/* Define to 1 if you have the `strchr' function. */
+#ifndef LIBVNCSERVER_HAVE_STRCHR 
+#define LIBVNCSERVER_HAVE_STRCHR  1 
+#endif
+
+/* Define to 1 if you have the `strcspn' function. */
+#ifndef LIBVNCSERVER_HAVE_STRCSPN 
+#define LIBVNCSERVER_HAVE_STRCSPN  1 
+#endif
+
+/* Define to 1 if you have the `strdup' function. */
+#ifndef LIBVNCSERVER_HAVE_STRDUP 
+#define LIBVNCSERVER_HAVE_STRDUP  1 
+#endif
+
+/* Define to 1 if you have the `strerror' function. */
+#ifndef LIBVNCSERVER_HAVE_STRERROR 
+#define LIBVNCSERVER_HAVE_STRERROR  1 
+#endif
+
+/* Define to 1 if you have the `strftime' function. */
+#ifndef LIBVNCSERVER_HAVE_STRFTIME 
+#define LIBVNCSERVER_HAVE_STRFTIME  1 
+#endif
+
+/* Define to 1 if you have the <strings.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_STRINGS_H 
+#define LIBVNCSERVER_HAVE_STRINGS_H  1 
+#endif
+
+/* Define to 1 if you have the <string.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_STRING_H 
+#define LIBVNCSERVER_HAVE_STRING_H  1 
+#endif
+
+/* Define to 1 if you have the `strstr' function. */
+#ifndef LIBVNCSERVER_HAVE_STRSTR 
+#define LIBVNCSERVER_HAVE_STRSTR  1 
+#endif
+
+/* Define to 1 if you have the <syslog.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_SYSLOG_H 
+#define LIBVNCSERVER_HAVE_SYSLOG_H  1 
+#endif
+
+/* Use the system libvncserver build environment for x11vnc. */
+/* #undef LIBVNCSERVER_HAVE_SYSTEM_LIBVNCSERVER */
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+/* #undef LIBVNCSERVER_HAVE_SYS_IOCTL_H */
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_SYS_SOCKET_H 
+#define LIBVNCSERVER_HAVE_SYS_SOCKET_H  1 
+#endif
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_SYS_STAT_H 
+#define LIBVNCSERVER_HAVE_SYS_STAT_H  1 
+#endif
+
+/* Define to 1 if you have the <sys/stropts.h> header file. */
+/* #undef LIBVNCSERVER_HAVE_SYS_STROPTS_H */
+
+/* Define to 1 if you have the <sys/timeb.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_SYS_TIMEB_H 
+#define LIBVNCSERVER_HAVE_SYS_TIMEB_H  1 
+#endif
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_SYS_TIME_H 
+#define LIBVNCSERVER_HAVE_SYS_TIME_H  1 
+#endif
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_SYS_TYPES_H 
+#define LIBVNCSERVER_HAVE_SYS_TYPES_H  1 
+#endif
+
+/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
+#ifndef LIBVNCSERVER_HAVE_SYS_WAIT_H 
+#define LIBVNCSERVER_HAVE_SYS_WAIT_H  1 
+#endif
+
+/* Define to 1 if you have the <termios.h> header file. */
+/* #undef LIBVNCSERVER_HAVE_TERMIOS_H */
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#ifndef LIBVNCSERVER_HAVE_UNISTD_H 
+#define LIBVNCSERVER_HAVE_UNISTD_H  1 
+#endif
+
+/* Define to 1 if you have the <utmpx.h> header file. */
+/* #undef LIBVNCSERVER_HAVE_UTMPX_H */
+
+/* Define to 1 if you have the `vfork' function. */
+#ifndef LIBVNCSERVER_HAVE_VFORK 
+#define LIBVNCSERVER_HAVE_VFORK  1 
+#endif
+
+/* Define to 1 if you have the <vfork.h> header file. */
+/* #undef LIBVNCSERVER_HAVE_VFORK_H */
+
+/* Define to 1 if you have the `vprintf' function. */
+#ifndef LIBVNCSERVER_HAVE_VPRINTF 
+#define LIBVNCSERVER_HAVE_VPRINTF  1 
+#endif
+
+/* Define to 1 if you have the `waitpid' function. */
+/* #undef LIBVNCSERVER_HAVE_WAITPID */
+
+/* Define to 1 if `fork' works. */
+#ifndef LIBVNCSERVER_HAVE_WORKING_FORK 
+#define LIBVNCSERVER_HAVE_WORKING_FORK  1 
+#endif
+
+/* Define to 1 if `vfork' works. */
+#ifndef LIBVNCSERVER_HAVE_WORKING_VFORK 
+#define LIBVNCSERVER_HAVE_WORKING_VFORK  1 
+#endif
+
+/* X11 build environment present */
+#ifndef LIBVNCSERVER_HAVE_X11 
+#define LIBVNCSERVER_HAVE_X11  1 
+#endif
+
+/* open ssl X509_print_ex_fp available */
+/* #undef LIBVNCSERVER_HAVE_X509_PRINT_EX_FP */
+
+/* XKEYBOARD extension build environment present */
+/* #undef LIBVNCSERVER_HAVE_XKEYBOARD */
+
+/* MIT-SHM extension build environment present */
+/* #undef LIBVNCSERVER_HAVE_XSHM */
+
+/* XTEST extension build environment present */
+/* #undef LIBVNCSERVER_HAVE_XTEST */
+
+/* XTEST extension has XTestGrabControl */
+/* #undef LIBVNCSERVER_HAVE_XTESTGRABCONTROL */
+
+/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
+   slash. */
+#ifndef LIBVNCSERVER_LSTAT_FOLLOWS_SLASHED_SYMLINK 
+#define LIBVNCSERVER_LSTAT_FOLLOWS_SLASHED_SYMLINK  1 
+#endif
+
+/* Need a typedef for in_addr_t */
+/* #undef LIBVNCSERVER_NEED_INADDR_T */
+
+/* Name of package */
+#ifndef LIBVNCSERVER_PACKAGE 
+#define LIBVNCSERVER_PACKAGE  "LibVNCServer" 
+#endif
+
+/* Define to the address where bug reports for this package should be sent. */
+#ifndef LIBVNCSERVER_PACKAGE_BUGREPORT 
+#define LIBVNCSERVER_PACKAGE_BUGREPORT  "http://sourceforge.net/projects/libvncserver" 
+#endif
+
+/* Define to the full name of this package. */
+#ifndef LIBVNCSERVER_PACKAGE_NAME 
+#define LIBVNCSERVER_PACKAGE_NAME  "LibVNCServer" 
+#endif
+
+/* Define to the full name and version of this package. */
+#ifndef LIBVNCSERVER_PACKAGE_STRING 
+#define LIBVNCSERVER_PACKAGE_STRING  "LibVNCServer 0.9.7" 
+#endif
+
+/* Define to the one symbol short name of this package. */
+#ifndef LIBVNCSERVER_PACKAGE_TARNAME 
+#define LIBVNCSERVER_PACKAGE_TARNAME  "libvncserver" 
+#endif
+
+/* Define to the version of this package. */
+#ifndef LIBVNCSERVER_PACKAGE_VERSION 
+#define LIBVNCSERVER_PACKAGE_VERSION  "0.9.7" 
+#endif
+
+/* The number of bytes in type char */
+/* #undef LIBVNCSERVER_SIZEOF_CHAR */
+
+/* The number of bytes in type int */
+/* #undef LIBVNCSERVER_SIZEOF_INT */
+
+/* The number of bytes in type long */
+/* #undef LIBVNCSERVER_SIZEOF_LONG */
+
+/* The number of bytes in type short */
+/* #undef LIBVNCSERVER_SIZEOF_SHORT */
+
+/* The number of bytes in type void* */
+/* #undef LIBVNCSERVER_SIZEOF_VOIDP */
+
+/* Define to 1 if you have the ANSI C header files. */
+#ifndef LIBVNCSERVER_STDC_HEADERS 
+#define LIBVNCSERVER_STDC_HEADERS  1 
+#endif
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+#ifndef LIBVNCSERVER_TIME_WITH_SYS_TIME 
+#define LIBVNCSERVER_TIME_WITH_SYS_TIME  1 
+#endif
+
+/* Version number of package */
+#ifndef LIBVNCSERVER_VERSION 
+#define LIBVNCSERVER_VERSION  "0.9.7" 
+#endif
+
+/* Disable TightVNCFileTransfer protocol */
+#ifndef LIBVNCSERVER_WITH_TIGHTVNC_FILETRANSFER 
+#define LIBVNCSERVER_WITH_TIGHTVNC_FILETRANSFER  1 
+#endif
+
+/* Define to 1 if your processor stores words with the most significant byte
+   first (like Motorola and SPARC, unlike Intel and VAX). */
+/* #undef LIBVNCSERVER_WORDS_BIGENDIAN */
+
+/* Define to 1 if the X Window System is missing or not being used. */
+/* #undef LIBVNCSERVER_X_DISPLAY_MISSING */
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+   calls it, or to nothing if 'inline' is not supported under any name.  */
+#ifndef __cplusplus
+/* #undef inline */
+#endif
+
+/* Define to `int' if <sys/types.h> does not define. */
+/* #undef pid_t */
+
+/* Define to `unsigned' if <sys/types.h> does not define. */
+/* #undef size_t */
+
+/* The type for socklen */
+/* #undef socklen_t */
+
+/* Define as `fork' if `vfork' does not work. */
+/* #undef vfork */
+/* once: _RFB_RFBCONFIG_H */
+#endif
diff --git a/src/rfb/rfbint.h b/src/rfb/rfbint.h
new file mode 100644 (file)
index 0000000..3ac64ff
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef _RFB_RFBINT_H
+#define _RFB_RFBINT_H 1
+#ifndef _GENERATED_STDINT_H
+#define _GENERATED_STDINT_H "LibVNCServer 0.9.7"
+/* generated using a gnu compiler version gcc (Debian 4.4.4-1) 4.4.4 Copyright (C) 2009 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */
+
+#include <stdint.h>
+
+
+/* system headers have good uint64_t */
+#ifndef _HAVE_UINT64_T
+#define _HAVE_UINT64_T
+#endif
+
+  /* once */
+#endif
+#endif
diff --git a/src/rfb/rfbproto.h b/src/rfb/rfbproto.h
new file mode 100644 (file)
index 0000000..f0660e1
--- /dev/null
@@ -0,0 +1,1365 @@
+#ifndef RFBPROTO_H
+#define RFBPROTO_H
+
+/*
+ *  Copyright (C) 2005 Rohit Kumar, Johannes E. Schindelin
+ *  Copyright (C) 2000-2002 Constantin Kaplinsky.  All Rights Reserved.
+ *  Copyright (C) 2000 Tridia Corporation.  All Rights Reserved.
+ *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
+ *
+ *  This is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this software; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
+ *  USA.
+ */
+
+/*
+ * rfbproto.h - header file for the RFB protocol version 3.3
+ *
+ * Uses types CARD<n> for an n-bit unsigned integer, INT<n> for an n-bit signed
+ * integer (for n = 8, 16 and 32).
+ *
+ * All multiple byte integers are in big endian (network) order (most
+ * significant byte first).  Unless noted otherwise there is no special
+ * alignment of protocol structures.
+ *
+ *
+ * Once the initial handshaking is done, all messages start with a type byte,
+ * (usually) followed by message-specific data.  The order of definitions in
+ * this file is as follows:
+ *
+ *  (1) Structures used in several types of message.
+ *  (2) Structures used in the initial handshaking.
+ *  (3) Message types.
+ *  (4) Encoding types.
+ *  (5) For each message type, the form of the data following the type byte.
+ *      Sometimes this is defined by a single structure but the more complex
+ *      messages have to be explained by comments.
+ */
+
+
+#if defined(WIN32) && !defined(__MINGW32__)
+#define LIBVNCSERVER_WORDS_BIGENDIAN
+#define rfbBool int
+#include <sys/timeb.h>
+#include <winsock.h>
+#undef SOCKET
+#define SOCKET int
+#else
+#include <rfb/rfbconfig.h>
+#include <rfb/rfbint.h>
+#endif
+
+#ifdef LIBVNCSERVER_HAVE_LIBZ
+#include <zlib.h>
+#ifdef __CHECKER__
+#undef Z_NULL
+#define Z_NULL NULL
+#endif
+#endif
+
+
+#if !defined(WIN32) || defined(__MINGW32__)
+#define max(a,b) (((a)>(b))?(a):(b))
+#ifdef LIBVNCSERVER_HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef LIBVNCSERVER_HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#define SOCKET int
+typedef int8_t rfbBool;
+#undef FALSE
+#define FALSE 0
+#undef TRUE
+#define TRUE -1
+#endif
+
+typedef uint32_t rfbKeySym;
+typedef uint32_t rfbPixel;
+
+#ifdef LIBVNCSERVER_NEED_INADDR_T
+typedef uint32_t in_addr_t;
+#endif
+
+#ifndef INADDR_NONE
+#define                INADDR_NONE     ((in_addr_t) 0xffffffff)
+#endif
+
+#define MAX_ENCODINGS 20
+
+/*****************************************************************************
+ *
+ * Structures used in several messages
+ *
+ *****************************************************************************/
+
+/*-----------------------------------------------------------------------------
+ * Structure used to specify a rectangle.  This structure is a multiple of 4
+ * bytes so that it can be interspersed with 32-bit pixel data without
+ * affecting alignment.
+ */
+
+typedef struct {
+    uint16_t x;
+    uint16_t y;
+    uint16_t w;
+    uint16_t h;
+} rfbRectangle;
+
+#define sz_rfbRectangle 8
+
+
+/*-----------------------------------------------------------------------------
+ * Structure used to specify pixel format.
+ */
+
+typedef struct {
+
+    uint8_t bitsPerPixel;              /* 8,16,32 only */
+
+    uint8_t depth;             /* 8 to 32 */
+
+    uint8_t bigEndian;         /* True if multi-byte pixels are interpreted
+                                  as big endian, or if single-bit-per-pixel
+                                  has most significant bit of the byte
+                                  corresponding to first (leftmost) pixel. Of
+                                  course this is meaningless for 8 bits/pix */
+
+    uint8_t trueColour;                /* If false then we need a "colour map" to
+                                  convert pixels to RGB.  If true, xxxMax and
+                                  xxxShift specify bits used for red, green
+                                  and blue */
+
+    /* the following fields are only meaningful if trueColour is true */
+
+    uint16_t redMax;           /* maximum red value (= 2^n - 1 where n is the
+                                  number of bits used for red). Note this
+                                  value is always in big endian order. */
+
+    uint16_t greenMax;         /* similar for green */
+
+    uint16_t blueMax;          /* and blue */
+
+    uint8_t redShift;          /* number of shifts needed to get the red
+                                  value in a pixel to the least significant
+                                  bit. To find the red value from a given
+                                  pixel, do the following:
+                                  1) Swap pixel value according to bigEndian
+                                     (e.g. if bigEndian is false and host byte
+                                     order is big endian, then swap).
+                                  2) Shift right by redShift.
+                                  3) AND with redMax (in host byte order).
+                                  4) You now have the red value between 0 and
+                                     redMax. */
+
+    uint8_t greenShift;                /* similar for green */
+
+    uint8_t blueShift;         /* and blue */
+
+    uint8_t pad1;
+    uint16_t pad2;
+
+} rfbPixelFormat;
+
+#define sz_rfbPixelFormat 16
+
+/* UltraVNC: Color settings values */
+#define rfbPFFullColors                0
+#define rfbPF256Colors         1
+#define rfbPF64Colors          2
+#define rfbPF8Colors           3
+#define rfbPF8GreyColors       4
+#define rfbPF4GreyColors       5
+#define rfbPF2GreyColors       6
+
+
+/*****************************************************************************
+ *
+ * Initial handshaking messages
+ *
+ *****************************************************************************/
+
+/*-----------------------------------------------------------------------------
+ * Protocol Version
+ *
+ * The server always sends 12 bytes to start which identifies the latest RFB
+ * protocol version number which it supports.  These bytes are interpreted
+ * as a string of 12 ASCII characters in the format "RFB xxx.yyy\n" where
+ * xxx and yyy are the major and minor version numbers (for version 3.3
+ * this is "RFB 003.003\n").
+ *
+ * The client then replies with a similar 12-byte message giving the version
+ * number of the protocol which should actually be used (which may be different
+ * to that quoted by the server).
+ *
+ * It is intended that both clients and servers may provide some level of
+ * backwards compatibility by this mechanism.  Servers in particular should
+ * attempt to provide backwards compatibility, and even forwards compatibility
+ * to some extent.  For example if a client demands version 3.1 of the
+ * protocol, a 3.0 server can probably assume that by ignoring requests for
+ * encoding types it doesn't understand, everything will still work OK.  This
+ * will probably not be the case for changes in the major version number.
+ *
+ * The format string below can be used in sprintf or sscanf to generate or
+ * decode the version string respectively.
+ */
+
+#define rfbProtocolVersionFormat "RFB %03d.%03d\n"
+#define rfbProtocolMajorVersion 3
+#define rfbProtocolMinorVersion 8
+/* UltraVNC Viewer examines rfbProtocolMinorVersion number (4, and 6)
+ * to identify if the server supports File Transfer
+ */
+
+typedef char rfbProtocolVersionMsg[13];        /* allow extra byte for null */
+
+#define sz_rfbProtocolVersionMsg 12
+
+/*
+ * Negotiation of the security type (protocol version 3.7)
+ *
+ * Once the protocol version has been decided, the server either sends a list
+ * of supported security types, or informs the client about an error (when the
+ * number of security types is 0).  Security type rfbSecTypeTight is used to
+ * enable TightVNC-specific protocol extensions.  The value rfbSecTypeVncAuth
+ * stands for classic VNC authentication.
+ *
+ * The client selects a particular security type from the list provided by the
+ * server.
+ */
+
+#define rfbSecTypeInvalid 0
+#define rfbSecTypeNone 1
+#define rfbSecTypeVncAuth 2
+
+
+/*-----------------------------------------------------------------------------
+ * Authentication
+ *
+ * Once the protocol version has been decided, the server then sends a 32-bit
+ * word indicating whether any authentication is needed on the connection.
+ * The value of this word determines the authentication scheme in use.  For
+ * version 3.0 of the protocol this may have one of the following values:
+ */
+
+#define rfbConnFailed 0
+#define rfbNoAuth 1
+#define rfbVncAuth 2
+
+#define rfbRA2 5
+#define rfbRA2ne 6
+#define rfbSSPI 7
+#define rfbSSPIne 8
+#define rfbTight 16
+#define rfbUltra 17
+#define rfbTLS 18
+
+/*
+ * rfbConnFailed:      For some reason the connection failed (e.g. the server
+ *                     cannot support the desired protocol version).  This is
+ *                     followed by a string describing the reason (where a
+ *                     string is specified as a 32-bit length followed by that
+ *                     many ASCII characters).
+ *
+ * rfbNoAuth:          No authentication is needed.
+ *
+ * rfbVncAuth:         The VNC authentication scheme is to be used.  A 16-byte
+ *                     challenge follows, which the client encrypts as
+ *                     appropriate using the password and sends the resulting
+ *                     16-byte response.  If the response is correct, the
+ *                     server sends the 32-bit word rfbVncAuthOK.  If a simple
+ *                     failure happens, the server sends rfbVncAuthFailed and
+ *                     closes the connection. If the server decides that too
+ *                     many failures have occurred, it sends rfbVncAuthTooMany
+ *                     and closes the connection.  In the latter case, the
+ *                     server should not allow an immediate reconnection by
+ *                     the client.
+ */
+
+#define rfbVncAuthOK 0
+#define rfbVncAuthFailed 1
+#define rfbVncAuthTooMany 2
+
+
+/*-----------------------------------------------------------------------------
+ * Client Initialisation Message
+ *
+ * Once the client and server are sure that they're happy to talk to one
+ * another, the client sends an initialisation message.  At present this
+ * message only consists of a boolean indicating whether the server should try
+ * to share the desktop by leaving other clients connected, or give exclusive
+ * access to this client by disconnecting all other clients.
+ */
+
+typedef struct {
+    uint8_t shared;
+} rfbClientInitMsg;
+
+#define sz_rfbClientInitMsg 1
+
+
+/*-----------------------------------------------------------------------------
+ * Server Initialisation Message
+ *
+ * After the client initialisation message, the server sends one of its own.
+ * This tells the client the width and height of the server's framebuffer,
+ * its pixel format and the name associated with the desktop.
+ */
+
+typedef struct {
+    uint16_t framebufferWidth;
+    uint16_t framebufferHeight;
+    rfbPixelFormat format;     /* the server's preferred pixel format */
+    uint32_t nameLength;
+    /* followed by char name[nameLength] */
+} rfbServerInitMsg;
+
+#define sz_rfbServerInitMsg (8 + sz_rfbPixelFormat)
+
+
+/*
+ * Following the server initialisation message it's up to the client to send
+ * whichever protocol messages it wants.  Typically it will send a
+ * SetPixelFormat message and a SetEncodings message, followed by a
+ * FramebufferUpdateRequest.  From then on the server will send
+ * FramebufferUpdate messages in response to the client's
+ * FramebufferUpdateRequest messages.  The client should send
+ * FramebufferUpdateRequest messages with incremental set to true when it has
+ * finished processing one FramebufferUpdate and is ready to process another.
+ * With a fast client, the rate at which FramebufferUpdateRequests are sent
+ * should be regulated to avoid hogging the network.
+ */
+
+
+
+/*****************************************************************************
+ *
+ * Message types
+ *
+ *****************************************************************************/
+
+/* server -> client */
+
+#define rfbFramebufferUpdate 0
+#define rfbSetColourMapEntries 1
+#define rfbBell 2
+#define rfbServerCutText 3
+/* Modif sf@2002 */
+#define rfbResizeFrameBuffer 4
+#define rfbKeyFrameUpdate 5
+#define rfbPalmVNCReSizeFrameBuffer 0xF
+
+/* client -> server */
+
+#define rfbSetPixelFormat 0
+#define rfbFixColourMapEntries 1       /* not currently supported */
+#define rfbSetEncodings 2
+#define rfbFramebufferUpdateRequest 3
+#define rfbKeyEvent 4
+#define rfbPointerEvent 5
+#define rfbClientCutText 6
+/* Modif sf@2002 - actually bidirectionnal */
+#define rfbFileTransfer 7
+/* Modif sf@2002 */
+#define rfbSetScale 8
+/* Modif rdv@2002 */
+#define rfbSetServerInput      9
+/* Modif rdv@2002 */
+#define rfbSetSW       10
+/* Modif sf@2002 - TextChat - Bidirectionnal */
+#define rfbTextChat    11
+/* Modif cs@2005 */
+#define rfbKeyFrameRequest 12
+/* PalmVNC 1.4 & 2.0 SetScale Factor message */
+#define rfbPalmVNCSetScaleFactor 0xF
+
+
+
+
+/*****************************************************************************
+ *
+ * Encoding types
+ *
+ *****************************************************************************/
+
+#define rfbEncodingRaw 0
+#define rfbEncodingCopyRect 1
+#define rfbEncodingRRE 2
+#define rfbEncodingCoRRE 4
+#define rfbEncodingHextile 5
+#define rfbEncodingZlib 6
+#define rfbEncodingTight 7
+#define rfbEncodingZlibHex 8
+#define rfbEncodingUltra 9
+#define rfbEncodingZRLE 16
+#define rfbEncodingZYWRLE 17
+
+/* Cache & XOR-Zlib - rdv@2002 */
+#define rfbEncodingCache                 0xFFFF0000
+#define rfbEncodingCacheEnable           0xFFFF0001
+#define rfbEncodingXOR_Zlib              0xFFFF0002
+#define rfbEncodingXORMonoColor_Zlib     0xFFFF0003
+#define rfbEncodingXORMultiColor_Zlib    0xFFFF0004
+#define rfbEncodingSolidColor            0xFFFF0005
+#define rfbEncodingXOREnable             0xFFFF0006
+#define rfbEncodingCacheZip              0xFFFF0007
+#define rfbEncodingSolMonoZip            0xFFFF0008
+#define rfbEncodingUltraZip              0xFFFF0009
+
+/*
+ * Special encoding numbers:
+ *   0xFFFFFF00 .. 0xFFFFFF0F -- encoding-specific compression levels;
+ *   0xFFFFFF10 .. 0xFFFFFF1F -- mouse cursor shape data;
+ *   0xFFFFFF20 .. 0xFFFFFF2F -- various protocol extensions;
+ *   0xFFFFFF30 .. 0xFFFFFFDF -- not allocated yet;
+ *   0xFFFFFFE0 .. 0xFFFFFFEF -- quality level for JPEG compressor;
+ *   0xFFFFFFF0 .. 0xFFFFFFFF -- cross-encoding compression levels.
+ */
+
+#define rfbEncodingCompressLevel0  0xFFFFFF00
+#define rfbEncodingCompressLevel1  0xFFFFFF01
+#define rfbEncodingCompressLevel2  0xFFFFFF02
+#define rfbEncodingCompressLevel3  0xFFFFFF03
+#define rfbEncodingCompressLevel4  0xFFFFFF04
+#define rfbEncodingCompressLevel5  0xFFFFFF05
+#define rfbEncodingCompressLevel6  0xFFFFFF06
+#define rfbEncodingCompressLevel7  0xFFFFFF07
+#define rfbEncodingCompressLevel8  0xFFFFFF08
+#define rfbEncodingCompressLevel9  0xFFFFFF09
+
+#define rfbEncodingXCursor         0xFFFFFF10
+#define rfbEncodingRichCursor      0xFFFFFF11
+#define rfbEncodingPointerPos      0xFFFFFF18
+
+#define rfbEncodingLastRect           0xFFFFFF20
+#define rfbEncodingNewFBSize          0xFFFFFF21
+
+#define rfbEncodingQualityLevel0   0xFFFFFFE0
+#define rfbEncodingQualityLevel1   0xFFFFFFE1
+#define rfbEncodingQualityLevel2   0xFFFFFFE2
+#define rfbEncodingQualityLevel3   0xFFFFFFE3
+#define rfbEncodingQualityLevel4   0xFFFFFFE4
+#define rfbEncodingQualityLevel5   0xFFFFFFE5
+#define rfbEncodingQualityLevel6   0xFFFFFFE6
+#define rfbEncodingQualityLevel7   0xFFFFFFE7
+#define rfbEncodingQualityLevel8   0xFFFFFFE8
+#define rfbEncodingQualityLevel9   0xFFFFFFE9
+
+
+/* LibVNCServer additions.   We claim 0xFFFE0000 - 0xFFFE00FF */
+#define rfbEncodingKeyboardLedState   0xFFFE0000
+#define rfbEncodingSupportedMessages  0xFFFE0001
+#define rfbEncodingSupportedEncodings 0xFFFE0002
+#define rfbEncodingServerIdentity     0xFFFE0003
+
+
+/*****************************************************************************
+ *
+ * Server -> client message definitions
+ *
+ *****************************************************************************/
+
+
+/*-----------------------------------------------------------------------------
+ * FramebufferUpdate - a block of rectangles to be copied to the framebuffer.
+ *
+ * This message consists of a header giving the number of rectangles of pixel
+ * data followed by the rectangles themselves.  The header is padded so that
+ * together with the type byte it is an exact multiple of 4 bytes (to help
+ * with alignment of 32-bit pixels):
+ */
+
+typedef struct {
+    uint8_t type;                      /* always rfbFramebufferUpdate */
+    uint8_t pad;
+    uint16_t nRects;
+    /* followed by nRects rectangles */
+} rfbFramebufferUpdateMsg;
+
+#define sz_rfbFramebufferUpdateMsg 4
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * KeyFrameUpdate - Acknowledgment of a key frame request, it tells the client
+ * that the next update received will be a key frame.
+ */
+
+typedef struct {
+    uint8_t type;
+} rfbKeyFrameUpdateMsg;
+
+#define sz_rfbKeyFrameUpdateMsg 1
+
+
+/*
+ * Each rectangle of pixel data consists of a header describing the position
+ * and size of the rectangle and a type word describing the encoding of the
+ * pixel data, followed finally by the pixel data.  Note that if the client has
+ * not sent a SetEncodings message then it will only receive raw pixel data.
+ * Also note again that this structure is a multiple of 4 bytes.
+ */
+
+typedef struct {
+    rfbRectangle r;
+    uint32_t encoding; /* one of the encoding types rfbEncoding... */
+} rfbFramebufferUpdateRectHeader;
+
+#define sz_rfbFramebufferUpdateRectHeader (sz_rfbRectangle + 4)
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * Supported Messages Encoding.  This encoding does not contain any pixel data.
+ * Instead, it contains 2 sets of bitflags.  These bitflags indicate what messages
+ * are supported by the server.
+ * rect->w contains byte count
+ */
+
+typedef struct {
+  uint8_t client2server[32]; /* maximum of 256 message types (256/8)=32 */
+  uint8_t server2client[32]; /* maximum of 256 message types (256/8)=32 */
+} rfbSupportedMessages;
+
+#define sz_rfbSupportedMessages 64
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * Supported Encodings Encoding.  This encoding does not contain any pixel data.
+ * Instead, it contains a list of (uint32_t) Encodings supported by this server.
+ * rect->w contains byte count
+ * rect->h contains encoding count
+ */
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * Server Identity Encoding.  This encoding does not contain any pixel data.
+ * Instead, it contains a text string containing information about the server.
+ * ie: "x11vnc: 0.8.1 lastmod: 2006-04-25 (libvncserver 0.9pre)\0"
+ * rect->w contains byte count
+ */
+
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * Raw Encoding.  Pixels are sent in top-to-bottom scanline order,
+ * left-to-right within a scanline with no padding in between.
+ */
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * KeyboardLedState Encoding.  The X coordinate contains the Locked Modifiers
+ * so that a remote troubleshooter can identify that the users 'Caps Lock' 
+ * is set...   (It helps a *lot* when the users are untrained)
+ */
+#define rfbKeyboardMaskShift        1
+#define rfbKeyboardMaskCapsLock     2
+#define rfbKeyboardMaskControl      4
+#define rfbKeyboardMaskAlt          8
+#define rfbKeyboardMaskMeta        16
+#define rfbKeyboardMaskSuper       32
+#define rfbKeyboardMaskHyper       64
+#define rfbKeyboardMaskNumLock    128
+#define rfbKeyboardMaskScrollLock 256
+#define rfbKeyboardMaskAltGraph   512
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * CopyRect Encoding.  The pixels are specified simply by the x and y position
+ * of the source rectangle.
+ */
+
+typedef struct {
+    uint16_t srcX;
+    uint16_t srcY;
+} rfbCopyRect;
+
+#define sz_rfbCopyRect 4
+
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * RRE - Rise-and-Run-length Encoding.  We have an rfbRREHeader structure
+ * giving the number of subrectangles following.  Finally the data follows in
+ * the form [<bgpixel><subrect><subrect>...] where each <subrect> is
+ * [<pixel><rfbRectangle>].
+ */
+
+typedef struct {
+    uint32_t nSubrects;
+} rfbRREHeader;
+
+#define sz_rfbRREHeader 4
+
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * CoRRE - Compact RRE Encoding.  We have an rfbRREHeader structure giving
+ * the number of subrectangles following.  Finally the data follows in the form
+ * [<bgpixel><subrect><subrect>...] where each <subrect> is
+ * [<pixel><rfbCoRRERectangle>].  This means that
+ * the whole rectangle must be at most 255x255 pixels.
+ */
+
+typedef struct {
+    uint8_t x;
+    uint8_t y;
+    uint8_t w;
+    uint8_t h;
+} rfbCoRRERectangle;
+
+#define sz_rfbCoRRERectangle 4
+
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * Hextile Encoding.  The rectangle is divided up into "tiles" of 16x16 pixels,
+ * starting at the top left going in left-to-right, top-to-bottom order.  If
+ * the width of the rectangle is not an exact multiple of 16 then the width of
+ * the last tile in each row will be correspondingly smaller.  Similarly if the
+ * height is not an exact multiple of 16 then the height of each tile in the
+ * final row will also be smaller.  Each tile begins with a "subencoding" type
+ * byte, which is a mask made up of a number of bits.  If the Raw bit is set
+ * then the other bits are irrelevant; w*h pixel values follow (where w and h
+ * are the width and height of the tile).  Otherwise the tile is encoded in a
+ * similar way to RRE, except that the position and size of each subrectangle
+ * can be specified in just two bytes.  The other bits in the mask are as
+ * follows:
+ *
+ * BackgroundSpecified - if set, a pixel value follows which specifies
+ *    the background colour for this tile.  The first non-raw tile in a
+ *    rectangle must have this bit set.  If this bit isn't set then the
+ *    background is the same as the last tile.
+ *
+ * ForegroundSpecified - if set, a pixel value follows which specifies
+ *    the foreground colour to be used for all subrectangles in this tile.
+ *    If this bit is set then the SubrectsColoured bit must be zero.
+ *
+ * AnySubrects - if set, a single byte follows giving the number of
+ *    subrectangles following.  If not set, there are no subrectangles (i.e.
+ *    the whole tile is just solid background colour).
+ *
+ * SubrectsColoured - if set then each subrectangle is preceded by a pixel
+ *    value giving the colour of that subrectangle.  If not set, all
+ *    subrectangles are the same colour, the foreground colour;  if the
+ *    ForegroundSpecified bit wasn't set then the foreground is the same as
+ *    the last tile.
+ *
+ * The position and size of each subrectangle is specified in two bytes.  The
+ * Pack macros below can be used to generate the two bytes from x, y, w, h,
+ * and the Extract macros can be used to extract the x, y, w, h values from
+ * the two bytes.
+ */
+
+#define rfbHextileRaw                  (1 << 0)
+#define rfbHextileBackgroundSpecified  (1 << 1)
+#define rfbHextileForegroundSpecified  (1 << 2)
+#define rfbHextileAnySubrects          (1 << 3)
+#define rfbHextileSubrectsColoured     (1 << 4)
+
+#define rfbHextilePackXY(x,y) (((x) << 4) | (y))
+#define rfbHextilePackWH(w,h) ((((w)-1) << 4) | ((h)-1))
+#define rfbHextileExtractX(byte) ((byte) >> 4)
+#define rfbHextileExtractY(byte) ((byte) & 0xf)
+#define rfbHextileExtractW(byte) (((byte) >> 4) + 1)
+#define rfbHextileExtractH(byte) (((byte) & 0xf) + 1)
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * zlib - zlib compressed Encoding.  We have an rfbZlibHeader structure
+ * giving the number of bytes following.  Finally the data follows is
+ * zlib compressed version of the raw pixel data as negotiated.
+ * (NOTE: also used by Ultra Encoding)
+ */
+
+typedef struct {
+    uint32_t nBytes;
+} rfbZlibHeader;
+
+#define sz_rfbZlibHeader 4
+
+#ifdef LIBVNCSERVER_HAVE_LIBZ
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * Tight Encoding.
+ *
+ *-- The first byte of each Tight-encoded rectangle is a "compression control
+ *   byte". Its format is as follows (bit 0 is the least significant one):
+ *
+ *   bit 0:    if 1, then compression stream 0 should be reset;
+ *   bit 1:    if 1, then compression stream 1 should be reset;
+ *   bit 2:    if 1, then compression stream 2 should be reset;
+ *   bit 3:    if 1, then compression stream 3 should be reset;
+ *   bits 7-4: if 1000 (0x08), then the compression type is "fill",
+ *             if 1001 (0x09), then the compression type is "jpeg",
+ *             if 0xxx, then the compression type is "basic",
+ *             values greater than 1001 are not valid.
+ *
+ * If the compression type is "basic", then bits 6..4 of the
+ * compression control byte (those xxx in 0xxx) specify the following:
+ *
+ *   bits 5-4:  decimal representation is the index of a particular zlib
+ *              stream which should be used for decompressing the data;
+ *   bit 6:     if 1, then a "filter id" byte is following this byte.
+ *
+ *-- The data that follows after the compression control byte described
+ * above depends on the compression type ("fill", "jpeg" or "basic").
+ *
+ *-- If the compression type is "fill", then the only pixel value follows, in
+ * client pixel format (see NOTE 1). This value applies to all pixels of the
+ * rectangle.
+ *
+ *-- If the compression type is "jpeg", the following data stream looks like
+ * this:
+ *
+ *   1..3 bytes:  data size (N) in compact representation;
+ *   N bytes:     JPEG image.
+ *
+ * Data size is compactly represented in one, two or three bytes, according
+ * to the following scheme:
+ *
+ *  0xxxxxxx                    (for values 0..127)
+ *  1xxxxxxx 0yyyyyyy           (for values 128..16383)
+ *  1xxxxxxx 1yyyyyyy zzzzzzzz  (for values 16384..4194303)
+ *
+ * Here each character denotes one bit, xxxxxxx are the least significant 7
+ * bits of the value (bits 0-6), yyyyyyy are bits 7-13, and zzzzzzzz are the
+ * most significant 8 bits (bits 14-21). For example, decimal value 10000
+ * should be represented as two bytes: binary 10010000 01001110, or
+ * hexadecimal 90 4E.
+ *
+ *-- If the compression type is "basic" and bit 6 of the compression control
+ * byte was set to 1, then the next (second) byte specifies "filter id" which
+ * tells the decoder what filter type was used by the encoder to pre-process
+ * pixel data before the compression. The "filter id" byte can be one of the
+ * following:
+ *
+ *   0:  no filter ("copy" filter);
+ *   1:  "palette" filter;
+ *   2:  "gradient" filter.
+ *
+ *-- If bit 6 of the compression control byte is set to 0 (no "filter id"
+ * byte), or if the filter id is 0, then raw pixel values in the client
+ * format (see NOTE 1) will be compressed. See below details on the
+ * compression.
+ *
+ *-- The "gradient" filter pre-processes pixel data with a simple algorithm
+ * which converts each color component to a difference between a "predicted"
+ * intensity and the actual intensity. Such a technique does not affect
+ * uncompressed data size, but helps to compress photo-like images better. 
+ * Pseudo-code for converting intensities to differences is the following:
+ *
+ *   P[i,j] := V[i-1,j] + V[i,j-1] - V[i-1,j-1];
+ *   if (P[i,j] < 0) then P[i,j] := 0;
+ *   if (P[i,j] > MAX) then P[i,j] := MAX;
+ *   D[i,j] := V[i,j] - P[i,j];
+ *
+ * Here V[i,j] is the intensity of a color component for a pixel at
+ * coordinates (i,j). MAX is the maximum value of intensity for a color
+ * component.
+ *
+ *-- The "palette" filter converts true-color pixel data to indexed colors
+ * and a palette which can consist of 2..256 colors. If the number of colors
+ * is 2, then each pixel is encoded in 1 bit, otherwise 8 bits is used to
+ * encode one pixel. 1-bit encoding is performed such way that the most
+ * significant bits correspond to the leftmost pixels, and each raw of pixels
+ * is aligned to the byte boundary. When "palette" filter is used, the
+ * palette is sent before the pixel data. The palette begins with an unsigned
+ * byte which value is the number of colors in the palette minus 1 (i.e. 1
+ * means 2 colors, 255 means 256 colors in the palette). Then follows the
+ * palette itself which consist of pixel values in client pixel format (see
+ * NOTE 1).
+ *
+ *-- The pixel data is compressed using the zlib library. But if the data
+ * size after applying the filter but before the compression is less then 12,
+ * then the data is sent as is, uncompressed. Four separate zlib streams
+ * (0..3) can be used and the decoder should read the actual stream id from
+ * the compression control byte (see NOTE 2).
+ *
+ * If the compression is not used, then the pixel data is sent as is,
+ * otherwise the data stream looks like this:
+ *
+ *   1..3 bytes:  data size (N) in compact representation;
+ *   N bytes:     zlib-compressed data.
+ *
+ * Data size is compactly represented in one, two or three bytes, just like
+ * in the "jpeg" compression method (see above).
+ *
+ *-- NOTE 1. If the color depth is 24, and all three color components are
+ * 8-bit wide, then one pixel in Tight encoding is always represented by
+ * three bytes, where the first byte is red component, the second byte is
+ * green component, and the third byte is blue component of the pixel color
+ * value. This applies to colors in palettes as well.
+ *
+ *-- NOTE 2. The decoder must reset compression streams' states before
+ * decoding the rectangle, if some of bits 0,1,2,3 in the compression control
+ * byte are set to 1. Note that the decoder must reset zlib streams even if
+ * the compression type is "fill" or "jpeg".
+ *
+ *-- NOTE 3. The "gradient" filter and "jpeg" compression may be used only
+ * when bits-per-pixel value is either 16 or 32, not 8.
+ *
+ *-- NOTE 4. The width of any Tight-encoded rectangle cannot exceed 2048
+ * pixels. If a rectangle is wider, it must be split into several rectangles
+ * and each one should be encoded separately.
+ *
+ */
+
+#define rfbTightExplicitFilter         0x04
+#define rfbTightFill                   0x08
+#define rfbTightJpeg                   0x09
+#define rfbTightMaxSubencoding         0x09
+
+/* Filters to improve compression efficiency */
+#define rfbTightFilterCopy             0x00
+#define rfbTightFilterPalette          0x01
+#define rfbTightFilterGradient         0x02
+
+#endif
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * XCursor encoding. This is a special encoding used to transmit X-style
+ * cursor shapes from server to clients. Note that for this encoding,
+ * coordinates in rfbFramebufferUpdateRectHeader structure hold hotspot
+ * position (r.x, r.y) and cursor size (r.w, r.h). If (w * h != 0), two RGB
+ * samples are sent after header in the rfbXCursorColors structure. They
+ * denote foreground and background colors of the cursor. If a client
+ * supports only black-and-white cursors, it should ignore these colors and
+ * assume that foreground is black and background is white. Next, two bitmaps
+ * (1 bits per pixel) follow: first one with actual data (value 0 denotes
+ * background color, value 1 denotes foreground color), second one with
+ * transparency data (bits with zero value mean that these pixels are
+ * transparent). Both bitmaps represent cursor data in a byte stream, from
+ * left to right, from top to bottom, and each row is byte-aligned. Most
+ * significant bits correspond to leftmost pixels. The number of bytes in
+ * each row can be calculated as ((w + 7) / 8). If (w * h == 0), cursor
+ * should be hidden (or default local cursor should be set by the client).
+ */
+
+typedef struct {
+    uint8_t foreRed;
+    uint8_t foreGreen;
+    uint8_t foreBlue;
+    uint8_t backRed;
+    uint8_t backGreen;
+    uint8_t backBlue;
+} rfbXCursorColors;
+
+#define sz_rfbXCursorColors 6
+
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * RichCursor encoding. This is a special encoding used to transmit cursor
+ * shapes from server to clients. It is similar to the XCursor encoding but
+ * uses client pixel format instead of two RGB colors to represent cursor
+ * image. For this encoding, coordinates in rfbFramebufferUpdateRectHeader
+ * structure hold hotspot position (r.x, r.y) and cursor size (r.w, r.h).
+ * After header, two pixmaps follow: first one with cursor image in current
+ * client pixel format (like in raw encoding), second with transparency data
+ * (1 bit per pixel, exactly the same format as used for transparency bitmap
+ * in the XCursor encoding). If (w * h == 0), cursor should be hidden (or
+ * default local cursor should be set by the client).
+ */
+
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * ZRLE - encoding combining Zlib compression, tiling, palettisation and
+ * run-length encoding.
+ */
+
+typedef struct {
+    uint32_t length;
+} rfbZRLEHeader;
+
+#define sz_rfbZRLEHeader 4
+
+#define rfbZRLETileWidth 64
+#define rfbZRLETileHeight 64
+
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * ZLIBHEX - zlib compressed Hextile Encoding.  Essentially, this is the
+ * hextile encoding with zlib compression on the tiles that can not be
+ * efficiently encoded with one of the other hextile subencodings.  The
+ * new zlib subencoding uses two bytes to specify the length of the
+ * compressed tile and then the compressed data follows.  As with the
+ * raw sub-encoding, the zlib subencoding invalidates the other
+ * values, if they are also set.
+ */
+
+#define rfbHextileZlibRaw              (1 << 5)
+#define rfbHextileZlibHex              (1 << 6)
+#define rfbHextileZlibMono             (1 << 7)
+
+
+/*-----------------------------------------------------------------------------
+ * SetColourMapEntries - these messages are only sent if the pixel
+ * format uses a "colour map" (i.e. trueColour false) and the client has not
+ * fixed the entire colour map using FixColourMapEntries.  In addition they
+ * will only start being sent after the client has sent its first
+ * FramebufferUpdateRequest.  So if the client always tells the server to use
+ * trueColour then it never needs to process this type of message.
+ */
+
+typedef struct {
+    uint8_t type;                      /* always rfbSetColourMapEntries */
+    uint8_t pad;
+    uint16_t firstColour;
+    uint16_t nColours;
+
+    /* Followed by nColours * 3 * uint16_t
+       r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */
+
+} rfbSetColourMapEntriesMsg;
+
+#define sz_rfbSetColourMapEntriesMsg 6
+
+
+
+/*-----------------------------------------------------------------------------
+ * Bell - ring a bell on the client if it has one.
+ */
+
+typedef struct {
+    uint8_t type;                      /* always rfbBell */
+} rfbBellMsg;
+
+#define sz_rfbBellMsg 1
+
+
+
+/*-----------------------------------------------------------------------------
+ * ServerCutText - the server has new text in its cut buffer.
+ */
+
+typedef struct {
+    uint8_t type;                      /* always rfbServerCutText */
+    uint8_t pad1;
+    uint16_t pad2;
+    uint32_t length;
+    /* followed by char text[length] */
+} rfbServerCutTextMsg;
+
+#define sz_rfbServerCutTextMsg 8
+
+
+/*-----------------------------------------------------------------------------
+ * //  Modif sf@2002
+ * FileTransferMsg - The client sends FileTransfer message.
+ * Bidirectional message - Files can be sent from client to server & vice versa
+ */
+
+typedef struct _rfbFileTransferMsg {
+    uint8_t type;                      /* always rfbFileTransfer */
+    uint8_t contentType;  /*  See defines below */
+    uint8_t contentParam;/*  Other possible content classification (Dir or File name, etc..) */
+    uint8_t pad;         /* It appears that UltraVNC *forgot* to Swap16IfLE(contentParam) */
+    uint32_t size;             /*  FileSize or packet index or error or other  */
+/*  uint32_t sizeH;             Additional 32Bits params to handle big values. Only for V2 (we want backward compatibility between all V1 versions) */
+    uint32_t length;
+    /* followed by data char text[length] */
+} rfbFileTransferMsg;
+
+#define sz_rfbFileTransferMsg  12
+
+#define rfbFileTransferVersion  2 /*  v1 is the old FT version ( <= 1.0.0 RC18 versions) */
+
+/*  FileTransfer Content types and Params defines */
+#define rfbDirContentRequest   1 /*  Client asks for the content of a given Server directory */
+#define rfbDirPacket                   2 /*  Full directory name or full file name. */
+                                                                 /*  Null content means end of Directory */
+#define rfbFileTransferRequest 3 /*  Client asks the server for the transfer of a given file */
+#define rfbFileHeader                  4 /*  First packet of a file transfer, containing file's features */
+#define rfbFilePacket                  5 /*  One chunk of the file */
+#define rfbEndOfFile                   6 /*  End of file transfer (the file has been received or error) */
+#define rfbAbortFileTransfer   7 /*  The file transfer must be aborted, whatever the state */
+#define rfbFileTransferOffer   8 /*  The client offers to send a file to the server */
+#define rfbFileAcceptHeader            9 /*  The server accepts or rejects the file */
+#define rfbCommand                             10 /*  The Client sends a simple command (File Delete, Dir create etc...) */
+#define rfbCommandReturn               11 /*  The Client receives the server's answer about a simple command */
+#define rfbFileChecksums               12 /*  The zipped checksums of the destination file (Delta Transfer) */
+#define rfbFileTransferAccess  14 /*  Request FileTransfer authorization */
+
+                                                               /*  rfbDirContentRequest client Request - content params  */
+#define rfbRDirContent                 1 /*  Request a Server Directory contents */
+#define rfbRDrivesList                 2 /*  Request the server's drives list */
+#define rfbRDirRecursiveList   3 /*  Request a server directory content recursive sorted list */
+#define rfbRDirRecursiveSize   4 /*  Request a server directory content recursive size */
+
+                                                               /*  rfbDirPacket & rfbCommandReturn  server Answer - content params */
+#define rfbADirectory                  1 /*  Reception of a directory name */
+#define rfbAFile                               2 /*  Reception of a file name  */
+#define rfbADrivesList                 3 /*  Reception of a list of drives */
+#define rfbADirCreate                  4 /*  Response to a create dir command  */
+#define rfbADirDelete                  5 /*  Response to a delete dir command  */
+#define rfbAFileCreate                 6 /*  Response to a create file command  */
+#define rfbAFileDelete                 7 /*  Response to a delete file command  */
+#define rfbAFileRename                 8 /*  Response to a rename file command  */
+#define rfbADirRename                  9 /*  Response to a rename dir command  */
+#define rfbADirRecursiveListItem       10 
+#define rfbADirRecursiveSize           11 
+
+                                                               /*  rfbCommand Command - content params */
+#define rfbCDirCreate                  1 /*  Request the server to create the given directory */
+#define rfbCDirDelete                  2 /*  Request the server to delete the given directory */
+#define rfbCFileCreate                 3 /*  Request the server to create the given file */
+#define rfbCFileDelete                 4 /*  Request the server to delete the given file */
+#define rfbCFileRename                 5 /*  Request the server to rename the given file  */
+#define rfbCDirRename                  6 /*  Request the server to rename the given directory */
+
+                                                               /*  Errors - content params or "size" field */
+#define rfbRErrorUnknownCmd     1  /*  Unknown FileTransfer command. */
+#define rfbRErrorCmd                   0xFFFFFFFF/*  Error when a command fails on remote side (ret in "size" field) */
+
+#define sz_rfbBlockSize                        8192  /*  Size of a File Transfer packet (before compression) */
+#define rfbZipDirectoryPrefix   "!UVNCDIR-\0" /*  Transfered directory are zipped in a file with this prefix. Must end with "-" */
+#define sz_rfbZipDirectoryPrefix 9 
+#define rfbDirPrefix                   "[ "
+#define rfbDirSuffix                   " ]"            
+
+
+
+/*-----------------------------------------------------------------------------
+ * Modif sf@2002
+ * TextChatMsg - Utilized to order the TextChat mode on server or client
+ * Bidirectional message
+ */
+
+typedef struct _rfbTextChatMsg {
+    uint8_t type;                      /* always rfbTextChat */
+    uint8_t pad1;         /*  Could be used later as an additionnal param */
+    uint16_t pad2;             /*  Could be used later as text offset, for instance */
+    uint32_t length;      /*  Specific values for Open, close, finished (-1, -2, -3) */
+    /* followed by char text[length] */
+} rfbTextChatMsg;
+
+#define sz_rfbTextChatMsg 8
+
+#define rfbTextMaxSize         4096
+#define rfbTextChatOpen                0xFFFFFFFF 
+#define rfbTextChatClose       0xFFFFFFFE  
+#define rfbTextChatFinished 0xFFFFFFFD  
+
+
+
+/*-----------------------------------------------------------------------------
+ * Modif sf@2002
+ * ResizeFrameBuffer - The Client must change the size of its framebuffer  
+ */
+
+typedef struct _rfbResizeFrameBufferMsg {
+    uint8_t type;                      /* always rfbResizeFrameBuffer */
+       uint8_t pad1;
+       uint16_t framebufferWidth;      /*  FrameBuffer width */
+       uint16_t framebufferHeigth;     /*  FrameBuffer height */
+} rfbResizeFrameBufferMsg;
+
+#define sz_rfbResizeFrameBufferMsg 6
+
+
+/*-----------------------------------------------------------------------------
+ * Copyright (C) 2001 Harakan Software
+ * PalmVNC 1.4 & 2.? ResizeFrameBuffer message
+ * ReSizeFrameBuffer - tell the RFB client to alter its framebuffer, either
+ * due to a resize of the server desktop or a client-requested scaling factor.
+ * The pixel format remains unchanged.
+ */
+
+typedef struct {
+    uint8_t type;                      /* always rfbReSizeFrameBuffer */
+       uint8_t pad1;
+       uint16_t desktop_w;     /* Desktop width */
+       uint16_t desktop_h;     /* Desktop height */
+       uint16_t buffer_w;      /* FrameBuffer width */
+       uint16_t buffer_h;      /* Framebuffer height */
+    uint16_t pad2;
+
+} rfbPalmVNCReSizeFrameBufferMsg;
+
+#define sz_rfbPalmVNCReSizeFrameBufferMsg (12)
+
+
+
+
+/*-----------------------------------------------------------------------------
+ * Union of all server->client messages.
+ */
+
+typedef union {
+    uint8_t type;
+    rfbFramebufferUpdateMsg fu;
+    rfbSetColourMapEntriesMsg scme;
+    rfbBellMsg b;
+    rfbServerCutTextMsg sct;
+       rfbResizeFrameBufferMsg rsfb;
+       rfbPalmVNCReSizeFrameBufferMsg prsfb; 
+       rfbFileTransferMsg ft;
+       rfbTextChatMsg tc;
+} rfbServerToClientMsg;
+
+
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * RDV Cache Encoding.  
+ * special is not used at this point, can be used to reset cache or other specials
+ * just put it to make sure we don't have to change the encoding again.  
+ */
+
+typedef struct {
+    uint16_t special;
+} rfbCacheRect;
+
+#define sz_rfbCacheRect 2
+
+
+
+
+/*****************************************************************************
+ *
+ * Message definitions (client -> server)
+ *
+ *****************************************************************************/
+
+
+/*-----------------------------------------------------------------------------
+ * SetPixelFormat - tell the RFB server the format in which the client wants
+ * pixels sent.
+ */
+
+typedef struct {
+    uint8_t type;                      /* always rfbSetPixelFormat */
+    uint8_t pad1;
+    uint16_t pad2;
+    rfbPixelFormat format;
+} rfbSetPixelFormatMsg;
+
+#define sz_rfbSetPixelFormatMsg (sz_rfbPixelFormat + 4)
+
+
+/*-----------------------------------------------------------------------------
+ * FixColourMapEntries - when the pixel format uses a "colour map", fix
+ * read-only colour map entries.
+ *
+ *    ***************** NOT CURRENTLY SUPPORTED *****************
+ */
+
+typedef struct {
+    uint8_t type;                      /* always rfbFixColourMapEntries */
+    uint8_t pad;
+    uint16_t firstColour;
+    uint16_t nColours;
+
+    /* Followed by nColours * 3 * uint16_t
+       r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */
+
+} rfbFixColourMapEntriesMsg;
+
+#define sz_rfbFixColourMapEntriesMsg 6
+
+
+/*-----------------------------------------------------------------------------
+ * SetEncodings - tell the RFB server which encoding types we accept.  Put them
+ * in order of preference, if we have any.  We may always receive raw
+ * encoding, even if we don't specify it here.
+ */
+
+typedef struct {
+    uint8_t type;                      /* always rfbSetEncodings */
+    uint8_t pad;
+    uint16_t nEncodings;
+    /* followed by nEncodings * uint32_t encoding types */
+} rfbSetEncodingsMsg;
+
+#define sz_rfbSetEncodingsMsg 4
+
+
+/*-----------------------------------------------------------------------------
+ * FramebufferUpdateRequest - request for a framebuffer update.  If incremental
+ * is true then the client just wants the changes since the last update.  If
+ * false then it wants the whole of the specified rectangle.
+ */
+
+typedef struct {
+    uint8_t type;                      /* always rfbFramebufferUpdateRequest */
+    uint8_t incremental;
+    uint16_t x;
+    uint16_t y;
+    uint16_t w;
+    uint16_t h;
+} rfbFramebufferUpdateRequestMsg;
+
+#define sz_rfbFramebufferUpdateRequestMsg 10
+
+
+/*-----------------------------------------------------------------------------
+ * KeyEvent - key press or release
+ *
+ * Keys are specified using the "keysym" values defined by the X Window System.
+ * For most ordinary keys, the keysym is the same as the corresponding ASCII
+ * value.  Other common keys are:
+ *
+ * BackSpace           0xff08
+ * Tab                 0xff09
+ * Return or Enter     0xff0d
+ * Escape              0xff1b
+ * Insert              0xff63
+ * Delete              0xffff
+ * Home                        0xff50
+ * End                 0xff57
+ * Page Up             0xff55
+ * Page Down           0xff56
+ * Left                        0xff51
+ * Up                  0xff52
+ * Right               0xff53
+ * Down                        0xff54
+ * F1                  0xffbe
+ * F2                  0xffbf
+ * ...                 ...
+ * F12                 0xffc9
+ * Shift               0xffe1
+ * Control             0xffe3
+ * Meta                        0xffe7
+ * Alt                 0xffe9
+ */
+
+typedef struct {
+    uint8_t type;                      /* always rfbKeyEvent */
+    uint8_t down;                      /* true if down (press), false if up */
+    uint16_t pad;
+    uint32_t key;                      /* key is specified as an X keysym */
+} rfbKeyEventMsg;
+
+#define sz_rfbKeyEventMsg 8
+
+
+/*-----------------------------------------------------------------------------
+ * PointerEvent - mouse/pen move and/or button press.
+ */
+
+typedef struct {
+    uint8_t type;                      /* always rfbPointerEvent */
+    uint8_t buttonMask;                /* bits 0-7 are buttons 1-8, 0=up, 1=down */
+    uint16_t x;
+    uint16_t y;
+} rfbPointerEventMsg;
+
+#define rfbButton1Mask 1
+#define rfbButton2Mask 2
+#define rfbButton3Mask 4
+#define rfbButton4Mask 8
+#define rfbButton5Mask 16
+/* RealVNC 335 method */
+#define rfbWheelUpMask rfbButton4Mask
+#define rfbWheelDownMask rfbButton5Mask
+
+#define sz_rfbPointerEventMsg 6
+
+
+
+/*-----------------------------------------------------------------------------
+ * ClientCutText - the client has new text in its cut buffer.
+ */
+
+typedef struct {
+    uint8_t type;                      /* always rfbClientCutText */
+    uint8_t pad1;
+    uint16_t pad2;
+    uint32_t length;
+    /* followed by char text[length] */
+} rfbClientCutTextMsg;
+
+#define sz_rfbClientCutTextMsg 8
+
+
+
+/*-----------------------------------------------------------------------------
+ * sf@2002 - Set Server Scale
+ * SetServerScale - Server must change the scale of the client buffer.
+ */
+
+typedef struct _rfbSetScaleMsg {
+    uint8_t type;                      /* always rfbSetScale */
+    uint8_t scale;             /* Scale value 1<sv<n */
+    uint16_t pad;
+} rfbSetScaleMsg;
+
+#define sz_rfbSetScaleMsg 4
+
+
+/*-----------------------------------------------------------------------------
+ * Copyright (C) 2001 Harakan Software
+ * PalmVNC 1.4 & 2.? SetScale Factor message 
+ * SetScaleFactor - tell the RFB server to alter the scale factor for the
+ * client buffer.
+ */
+typedef struct {
+    uint8_t type;                      /* always rfbPalmVNCSetScaleFactor */
+
+    uint8_t scale;             /* Scale factor (positive non-zero integer) */
+    uint16_t pad2;
+} rfbPalmVNCSetScaleFactorMsg;
+
+#define sz_rfbPalmVNCSetScaleFactorMsg (4)
+
+
+/*-----------------------------------------------------------------------------
+ * rdv@2002 - Set input status
+ * SetServerInput - Server input is dis/enabled
+ */
+
+typedef struct _rfbSetServerInputMsg {
+    uint8_t type;                      /* always rfbSetScale */
+    uint8_t status;            /* Scale value 1<sv<n */
+    uint16_t pad;
+} rfbSetServerInputMsg;
+
+#define sz_rfbSetServerInputMsg 4
+
+/*-----------------------------------------------------------------------------
+ * rdv@2002 - Set SW
+ * SetSW - Server SW/full desktop
+ */
+
+typedef struct _rfbSetSWMsg {
+    uint8_t type;                      /* always rfbSetSW */
+    uint8_t status;            
+    uint16_t x;
+    uint16_t y;
+} rfbSetSWMsg;
+
+#define sz_rfbSetSWMsg 6
+
+
+/*-----------------------------------------------------------------------------
+ * Union of all client->server messages.
+ */
+
+typedef union {
+    uint8_t type;
+    rfbSetPixelFormatMsg spf;
+    rfbFixColourMapEntriesMsg fcme;
+    rfbSetEncodingsMsg se;
+    rfbFramebufferUpdateRequestMsg fur;
+    rfbKeyEventMsg ke;
+    rfbPointerEventMsg pe;
+    rfbClientCutTextMsg cct;
+       rfbSetScaleMsg ssc;
+       rfbPalmVNCSetScaleFactorMsg pssf;
+       rfbSetServerInputMsg sim;
+       rfbFileTransferMsg ft;
+       rfbSetSWMsg sw;
+       rfbTextChatMsg tc;
+} rfbClientToServerMsg;
+
+/* 
+ * vncauth.h - describes the functions provided by the vncauth library.
+ */
+
+#define MAXPWLEN 8
+#define CHALLENGESIZE 16
+
+extern int rfbEncryptAndStorePasswd(char *passwd, char *fname);
+extern char *rfbDecryptPasswdFromFile(char *fname);
+extern void rfbRandomBytes(unsigned char *bytes);
+extern void rfbEncryptBytes(unsigned char *bytes, char *passwd);
+
+
+#endif
diff --git a/src/rfb/rfbregion.h b/src/rfb/rfbregion.h
new file mode 100755 (executable)
index 0000000..53da667
--- /dev/null
@@ -0,0 +1,65 @@
+#ifndef SRAREGION_H
+#define SRAREGION_H
+
+/* -=- SRA - Simple Region Algorithm
+ * A simple rectangular region implementation.
+ * Copyright (c) 2001 James "Wez" Weatherall, Johannes E. Schindelin
+ */
+
+/* -=- sraRect */
+
+typedef struct _rect {
+       int x1;
+       int y1;
+       int x2;
+       int y2;
+} sraRect;
+
+typedef struct sraRegion sraRegion;
+
+/* -=- Region manipulation functions */
+
+extern sraRegion *sraRgnCreate();
+extern sraRegion *sraRgnCreateRect(int x1, int y1, int x2, int y2);
+extern sraRegion *sraRgnCreateRgn(const sraRegion *src);
+
+extern void sraRgnDestroy(sraRegion *rgn);
+extern void sraRgnMakeEmpty(sraRegion *rgn);
+extern rfbBool sraRgnAnd(sraRegion *dst, const sraRegion *src);
+extern void sraRgnOr(sraRegion *dst, const sraRegion *src);
+extern rfbBool sraRgnSubtract(sraRegion *dst, const sraRegion *src);
+
+extern void sraRgnOffset(sraRegion *dst, int dx, int dy);
+
+extern rfbBool sraRgnPopRect(sraRegion *region, sraRect *rect,
+                         unsigned long flags);
+
+extern unsigned long sraRgnCountRects(const sraRegion *rgn);
+extern rfbBool sraRgnEmpty(const sraRegion *rgn);
+
+extern sraRegion *sraRgnBBox(const sraRegion *src);
+
+/* -=- rectangle iterator */
+
+typedef struct sraRectangleIterator {
+  rfbBool reverseX,reverseY;
+  int ptrSize,ptrPos;
+  struct sraSpan** sPtrs;
+} sraRectangleIterator;
+
+extern sraRectangleIterator *sraRgnGetIterator(sraRegion *s);
+extern sraRectangleIterator *sraRgnGetReverseIterator(sraRegion *s,rfbBool reverseX,rfbBool reverseY);
+extern rfbBool sraRgnIteratorNext(sraRectangleIterator *i,sraRect *r);
+extern void sraRgnReleaseIterator(sraRectangleIterator *i);
+
+void sraRgnPrint(const sraRegion *s);
+
+/* -=- Rectangle clipper (for speed) */
+
+extern rfbBool sraClipRect(int *x, int *y, int *w, int *h,
+                       int cx, int cy, int cw, int ch);
+
+extern rfbBool sraClipRect2(int *x, int *y, int *x2, int *y2,
+                       int cx, int cy, int cx2, int cy2);
+
+#endif
diff --git a/src/vncclientthread.cpp b/src/vncclientthread.cpp
new file mode 100644 (file)
index 0000000..a9dab21
--- /dev/null
@@ -0,0 +1,358 @@
+/****************************************************************************
+**
+** Copyright (C) 2007-2008 Urs Wolfer <uwolfer @ kde.org>
+**
+** This file is part of KDE.
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; see the file COPYING. If not, write to
+** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+** Boston, MA 02110-1301, USA.
+**
+****************************************************************************/
+
+#include "vncclientthread.h"
+
+#include <QMutexLocker>
+#include <QTimer>
+
+static QString outputErrorMessageString;
+
+rfbBool VncClientThread::newclient(rfbClient *cl)
+{
+    VncClientThread *t = (VncClientThread*)rfbClientGetClientData(cl, 0);
+    Q_ASSERT(t);
+
+    const int width = cl->width, height = cl->height, depth = cl->format.bitsPerPixel;
+    const int size = width * height * (depth / 8);
+    if (t->frameBuffer)
+        delete [] t->frameBuffer; // do not leak if we get a new framebuffer size
+    t->frameBuffer = new uint8_t[size];
+    cl->frameBuffer = t->frameBuffer;
+    memset(cl->frameBuffer, '\0', size);
+    cl->format.bitsPerPixel = 32;
+    cl->format.redShift = 16;
+    cl->format.greenShift = 8;
+    cl->format.blueShift = 0;
+    cl->format.redMax = 0xff;
+    cl->format.greenMax = 0xff;
+    cl->format.blueMax = 0xff;
+
+    switch (t->quality()) {
+    case RemoteView::High:
+        cl->appData.useBGR233 = 0;
+        cl->appData.encodingsString = "copyrect hextile raw";
+        cl->appData.compressLevel = 0;
+        cl->appData.qualityLevel = 9;
+        break;
+    case RemoteView::Medium:
+        cl->appData.useBGR233 = 0;
+        cl->appData.encodingsString = "tight zrle ultra copyrect hextile zlib corre rre raw";
+        cl->appData.compressLevel = 5;
+        cl->appData.qualityLevel = 7;
+        break;
+    case RemoteView::Low:
+    case RemoteView::Unknown:
+    default:
+        cl->appData.useBGR233 = 1;
+        cl->appData.encodingsString = "tight zrle ultra copyrect hextile zlib corre rre raw";
+        cl->appData.compressLevel = 9;
+        cl->appData.qualityLevel = 1;
+    }
+
+    SetFormatAndEncodings(cl);
+
+    return true;
+}
+
+void VncClientThread::updatefb(rfbClient* cl, int x, int y, int w, int h)
+{
+//     kDebug(5011) << "updated client: x: " << x << ", y: " << y << ", w: " << w << ", h: " << h;
+
+    const int width = cl->width, height = cl->height;
+
+    const QImage img(cl->frameBuffer, width, height, QImage::Format_RGB32);
+
+    if (img.isNull()) {
+        kDebug(5011) << "image not loaded";
+    }
+
+    VncClientThread *t = (VncClientThread*)rfbClientGetClientData(cl, 0);
+    Q_ASSERT(t);
+
+    t->setImage(img);
+
+    t->emitUpdated(x, y, w, h);
+}
+
+void VncClientThread::cuttext(rfbClient* cl, const char *text, int textlen)
+{
+    const QString cutText = QString::fromUtf8(text, textlen);
+    kDebug(5011) << cutText;
+
+    if (!cutText.isEmpty()) {
+        VncClientThread *t = (VncClientThread*)rfbClientGetClientData(cl, 0);
+        Q_ASSERT(t);
+
+        t->emitGotCut(cutText);
+    }
+}
+
+char *VncClientThread::passwdHandler(rfbClient *cl)
+{
+    kDebug(5011) << "password request" << kBacktrace();
+
+    VncClientThread *t = (VncClientThread*)rfbClientGetClientData(cl, 0);
+    Q_ASSERT(t);
+
+    t->passwordRequest();
+    t->m_passwordError = true;
+
+    return strdup(t->password().toLocal8Bit());
+}
+
+void VncClientThread::outputHandler(const char *format, ...)
+{
+    va_list args;
+    va_start(args, format);
+
+    QString message;
+    message.vsprintf(format, args);
+
+    va_end(args);
+
+    message = message.trimmed();
+
+    kDebug(5011) << message;
+
+    if ((message.contains("Couldn't convert ")) ||
+            (message.contains("Unable to connect to VNC server")))
+        outputErrorMessageString = i18n("Server not found.");
+
+    if ((message.contains("VNC connection failed: Authentication failed, too many tries")) ||
+            (message.contains("VNC connection failed: Too many authentication failures")))
+        outputErrorMessageString = i18n("VNC authentication failed because of too many authentication tries.");
+
+    if (message.contains("VNC connection failed: Authentication failed"))
+        outputErrorMessageString = i18n("VNC authentication failed.");
+
+    if (message.contains("VNC server closed connection"))
+        outputErrorMessageString = i18n("VNC server closed connection.");
+
+    // internal messages, not displayed to user
+    if (message.contains("VNC server supports protocol version 3.889")) // see http://bugs.kde.org/162640
+        outputErrorMessageString = "INTERNAL:APPLE_VNC_COMPATIBILTY";
+}
+
+VncClientThread::VncClientThread(QObject *parent)
+        : QThread(parent)
+        , frameBuffer(0)
+{
+    QMutexLocker locker(&mutex);
+    m_stopped = false;
+
+    QTimer *outputErrorMessagesCheckTimer = new QTimer(this);
+    outputErrorMessagesCheckTimer->setInterval(500);
+    connect(outputErrorMessagesCheckTimer, SIGNAL(timeout()), this, SLOT(checkOutputErrorMessage()));
+    outputErrorMessagesCheckTimer->start();
+}
+
+VncClientThread::~VncClientThread()
+{
+    stop();
+
+    const bool quitSuccess = wait(500);
+
+    kDebug(5011) << "Quit VNC thread success:" << quitSuccess;
+    
+    delete [] frameBuffer;
+}
+
+void VncClientThread::checkOutputErrorMessage()
+{
+    if (!outputErrorMessageString.isEmpty()) {
+        kDebug(5011) << outputErrorMessageString;
+        QString errorMessage = outputErrorMessageString;
+        outputErrorMessageString.clear();
+        // show authentication failure error only after the 3rd unsuccessful try
+        if ((errorMessage != i18n("VNC authentication failed.")) || m_passwordError)
+            outputErrorMessage(errorMessage);
+    }
+}
+
+void VncClientThread::setHost(const QString &host)
+{
+    QMutexLocker locker(&mutex);
+    m_host = host;
+}
+
+void VncClientThread::setPort(int port)
+{
+    QMutexLocker locker(&mutex);
+    m_port = port;
+}
+
+void VncClientThread::setQuality(RemoteView::Quality quality)
+{
+    m_quality = quality;
+}
+
+RemoteView::Quality VncClientThread::quality() const
+{
+    return m_quality;
+}
+
+void VncClientThread::setImage(const QImage &img)
+{
+    QMutexLocker locker(&mutex);
+    m_image = img;
+}
+
+const QImage VncClientThread::image(int x, int y, int w, int h)
+{
+    QMutexLocker locker(&mutex);
+
+    if (w == 0) // full image requested
+        return m_image;
+    else
+        return m_image.copy(x, y, w, h);
+}
+
+void VncClientThread::emitUpdated(int x, int y, int w, int h)
+{
+    emit imageUpdated(x, y, w, h);
+}
+
+void VncClientThread::emitGotCut(const QString &text)
+{
+    emit gotCut(text);
+}
+
+void VncClientThread::stop()
+{
+    QMutexLocker locker(&mutex);
+    m_stopped = true;
+}
+
+void VncClientThread::run()
+{
+    QMutexLocker locker(&mutex);
+
+    while (!m_stopped) { // try to connect as long as the server allows
+        m_passwordError = false;
+
+        rfbClientLog = outputHandler;
+        rfbClientErr = outputHandler;
+        cl = rfbGetClient(8, 3, 4);
+        cl->MallocFrameBuffer = newclient;
+        cl->canHandleNewFBSize = true;
+        cl->GetPassword = passwdHandler;
+        cl->GotFrameBufferUpdate = updatefb;
+        cl->GotXCutText = cuttext;
+        rfbClientSetClientData(cl, 0, this);
+
+        cl->serverHost = strdup(m_host.toUtf8().constData());
+
+        if (m_port < 0 || !m_port) // port is invalid or empty...
+            m_port = 5900; // fallback: try an often used VNC port
+
+        if (m_port >= 0 && m_port < 100) // the user most likely used the short form (e.g. :1)
+            m_port += 5900;
+        cl->serverPort = m_port;
+
+        kDebug(5011) << "--------------------- trying init ---------------------";
+
+        if (rfbInitClient(cl, 0, 0))
+            break;
+
+        if (m_passwordError)
+            continue;
+
+        return;
+    }
+
+    locker.unlock();
+
+    // Main VNC event loop
+    while (!m_stopped) {
+        const int i = WaitForMessage(cl, 500);
+        if (i < 0)
+            break;
+        if (i)
+            if (!HandleRFBServerMessage(cl))
+                break;
+
+        locker.relock();
+
+        while (!m_eventQueue.isEmpty()) {
+            ClientEvent* clientEvent = m_eventQueue.dequeue();
+            clientEvent->fire(cl);
+            delete clientEvent;
+        }
+
+        locker.unlock();
+    }
+
+    // Cleanup allocated resources
+    locker.relock();
+    rfbClientCleanup(cl);
+    m_stopped = true;
+}
+
+ClientEvent::~ClientEvent()
+{
+}
+
+void PointerClientEvent::fire(rfbClient* cl)
+{
+    SendPointerEvent(cl, m_x, m_y, m_buttonMask);
+}
+
+void KeyClientEvent::fire(rfbClient* cl)
+{
+    SendKeyEvent(cl, m_key, m_pressed);
+}
+
+void ClientCutEvent::fire(rfbClient* cl)
+{
+    SendClientCutText(cl, text.toUtf8().data(), text.size());
+}
+
+void VncClientThread::mouseEvent(int x, int y, int buttonMask)
+{
+    QMutexLocker lock(&mutex);
+    if (m_stopped)
+        return;
+
+    m_eventQueue.enqueue(new PointerClientEvent(x, y, buttonMask));
+}
+
+void VncClientThread::keyEvent(int key, bool pressed)
+{
+    QMutexLocker lock(&mutex);
+    if (m_stopped)
+        return;
+
+    m_eventQueue.enqueue(new KeyClientEvent(key, pressed));
+}
+
+void VncClientThread::clientCut(const QString &text)
+{
+    QMutexLocker lock(&mutex);
+    if (m_stopped)
+        return;
+
+    m_eventQueue.enqueue(new ClientCutEvent(text));
+}
+
+#include "moc_vncclientthread.cpp"
diff --git a/src/vncclientthread.h b/src/vncclientthread.h
new file mode 100644 (file)
index 0000000..6940cad
--- /dev/null
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** Copyright (C) 2007-2008 Urs Wolfer <uwolfer @ kde.org>
+**
+** This file is part of KDE.
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; see the file COPYING. If not, write to
+** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+** Boston, MA 02110-1301, USA.
+**
+****************************************************************************/
+
+#ifndef VNCCLIENTTHREAD_H
+#define VNCCLIENTTHREAD_H
+
+#ifdef QTONLY
+    #include <QDebug>
+    #define kDebug(n) qDebug()
+    #define kBacktrace() ""
+    #define i18n tr
+#else
+    #include <KDebug>
+    #include <KLocale>
+#endif
+
+#include "remoteview.h"
+
+#include <QQueue>
+#include <QThread>
+#include <QImage>
+#include <QMutex>
+
+extern "C" {
+#include <rfb/rfbclient.h>
+}
+
+class ClientEvent
+{
+public:
+    virtual ~ClientEvent();
+
+    virtual void fire(rfbClient*) = 0;
+};
+
+class KeyClientEvent : public ClientEvent
+{
+public:
+    KeyClientEvent(int key, int pressed)
+            : m_key(key), m_pressed(pressed) {}
+
+    void fire(rfbClient*);
+
+private:
+    int m_key;
+    int m_pressed;
+};
+
+class PointerClientEvent : public ClientEvent
+{
+public:
+    PointerClientEvent(int x, int y, int buttonMask)
+            : m_x(x), m_y(y), m_buttonMask(buttonMask) {}
+
+    void fire(rfbClient*);
+
+private:
+    int m_x;
+    int m_y;
+    int m_buttonMask;
+};
+
+class ClientCutEvent : public ClientEvent
+{
+public:
+    ClientCutEvent(const QString &text)
+            : text(text) {}
+
+    void fire(rfbClient*);
+
+private:
+    QString text;
+};
+
+class VncClientThread: public QThread
+{
+    Q_OBJECT
+
+public:
+    explicit VncClientThread(QObject *parent = 0);
+    ~VncClientThread();
+    const QImage image(int x = 0, int y = 0, int w = 0, int h = 0);
+    void setImage(const QImage &img);
+    void emitUpdated(int x, int y, int w, int h);
+    void emitGotCut(const QString &text);
+    void stop();
+    void setHost(const QString &host);
+    void setPort(int port);
+    void setQuality(RemoteView::Quality quality);
+    void setPassword(const QString &password) {
+        m_password = password;
+    }
+    const QString password() const {
+        return m_password;
+    }
+
+    RemoteView::Quality quality() const;
+    uint8_t *frameBuffer;
+
+signals:
+    void imageUpdated(int x, int y, int w, int h);
+    void gotCut(const QString &text);
+    void passwordRequest();
+    void outputErrorMessage(const QString &message);
+
+public slots:
+    void mouseEvent(int x, int y, int buttonMask);
+    void keyEvent(int key, bool pressed);
+    void clientCut(const QString &text);
+
+protected:
+    void run();
+
+private:
+    static rfbBool newclient(rfbClient *cl);
+    static void updatefb(rfbClient *cl, int x, int y, int w, int h);
+    static void cuttext(rfbClient *cl, const char *text, int textlen);
+    static char* passwdHandler(rfbClient *cl);
+    static void outputHandler(const char *format, ...);
+
+    QImage m_image;
+    rfbClient *cl;
+    QString m_host;
+    QString m_password;
+    int m_port;
+    QMutex mutex;
+    RemoteView::Quality m_quality;
+    QQueue<ClientEvent* > m_eventQueue;
+
+    volatile bool m_stopped;
+    volatile bool m_passwordError;
+
+private slots:
+    void checkOutputErrorMessage();
+};
+
+#endif
diff --git a/src/vncview.cpp b/src/vncview.cpp
new file mode 100644 (file)
index 0000000..5023ebf
--- /dev/null
@@ -0,0 +1,643 @@
+/****************************************************************************
+**
+** Copyright (C) 2007-2008 Urs Wolfer <uwolfer @ kde.org>
+**
+** This file is part of KDE.
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; see the file COPYING. If not, write to
+** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+** Boston, MA 02110-1301, USA.
+**
+****************************************************************************/
+
+#include "vncview.h"
+
+#include <QMessageBox>
+#include <QInputDialog>
+#define KMessageBox QMessageBox
+#define error(parent, message, caption) \
+critical(parent, caption, message)
+
+#include <QApplication>
+#include <QImage>
+#include <QPainter>
+#include <QMouseEvent>
+#include <QEvent>
+#include <QTime>
+#include <QTimer>
+
+// Definition of key modifier mask constants
+#define KMOD_Alt_R     0x01
+#define KMOD_Alt_L     0x02
+#define KMOD_Meta_L    0x04
+#define KMOD_Control_L         0x08
+#define KMOD_Shift_L   0x10
+
+VncView::VncView(QWidget *parent, const KUrl &url, RemoteView::Quality quality)
+        : RemoteView(parent),
+        m_initDone(false),
+        m_buttonMask(0),
+       cursor_x(0),
+       cursor_y(0),
+        m_repaint(false),
+        m_quitFlag(false),
+        m_firstPasswordTry(true),
+        m_authenticaionCanceled(false),
+        m_dontSendClipboard(false),
+        m_horizontalFactor(1.0),
+        m_verticalFactor(1.0),
+        m_forceLocalCursor(false),
+       force_full_repaint(false),
+       quality(quality)
+{
+    m_url = url;
+    m_host = url.host();
+    m_port = url.port();
+
+    connect(&vncThread, SIGNAL(imageUpdated(int, int, int, int)), this, SLOT(updateImage(int, int, int, int)), Qt::BlockingQueuedConnection);
+    connect(&vncThread, SIGNAL(gotCut(const QString&)), this, SLOT(setCut(const QString&)), Qt::BlockingQueuedConnection);
+    connect(&vncThread, SIGNAL(passwordRequest()), this, SLOT(requestPassword()), Qt::BlockingQueuedConnection);
+    connect(&vncThread, SIGNAL(outputErrorMessage(QString)), this, SLOT(outputErrorMessage(QString)));
+
+    m_clipboard = QApplication::clipboard();
+    connect(m_clipboard, SIGNAL(selectionChanged()), this, SLOT(clipboardSelectionChanged()));
+    connect(m_clipboard, SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
+}
+
+VncView::~VncView()
+{
+    unpressModifiers();
+
+    // Disconnect all signals so that we don't get any more callbacks from the client thread
+    disconnect(&vncThread, SIGNAL(imageUpdated(int, int, int, int)), this, SLOT(updateImage(int, int, int, int)));
+    disconnect(&vncThread, SIGNAL(gotCut(const QString&)), this, SLOT(setCut(const QString&)));
+    disconnect(&vncThread, SIGNAL(passwordRequest()), this, SLOT(requestPassword()));
+    disconnect(&vncThread, SIGNAL(outputErrorMessage(QString)), this, SLOT(outputErrorMessage(QString)));
+
+    startQuitting();
+}
+
+void VncView::forceFullRepaint()
+{
+       force_full_repaint = true;
+       repaint();
+}
+
+bool VncView::eventFilter(QObject *obj, QEvent *event)
+{
+    if (m_viewOnly) {
+        if (event->type() == QEvent::KeyPress ||
+                event->type() == QEvent::KeyRelease ||
+                event->type() == QEvent::MouseButtonDblClick ||
+                event->type() == QEvent::MouseButtonPress ||
+                event->type() == QEvent::MouseButtonRelease ||
+                event->type() == QEvent::Wheel ||
+                event->type() == QEvent::MouseMove)
+            return true;
+    }
+    return RemoteView::eventFilter(obj, event);
+}
+
+QSize VncView::framebufferSize()
+{
+    return m_frame.size();
+}
+
+QSize VncView::sizeHint() const
+{
+    return size();
+}
+
+QSize VncView::minimumSizeHint() const
+{
+    return size();
+}
+
+void VncView::scaleResize(int w, int h)
+{
+    RemoteView::scaleResize(w, h);
+    
+    kDebug(5011) << "scaleResize(): " <<w << h;
+    if (m_scale) {
+        m_verticalFactor = (qreal) h / m_frame.height();
+        m_horizontalFactor = (qreal) w / m_frame.width();
+
+        m_verticalFactor = m_horizontalFactor = qMin(m_verticalFactor, m_horizontalFactor);
+
+        const qreal newW = m_frame.width() * m_horizontalFactor;
+        const qreal newH = m_frame.height() * m_verticalFactor;
+       /*
+        setMaximumSize(newW, newH); //This is a hack to force Qt to center the view in the scroll area
+       //also causes the widget's size to flicker
+       */
+        resize(newW, newH);
+    } 
+}
+
+void VncView::updateConfiguration()
+{
+    RemoteView::updateConfiguration();
+
+    // Update the scaling mode in case KeepAspectRatio changed
+    if(parentWidget())
+           scaleResize(parentWidget()->width(), parentWidget()->height());
+    else
+       scaleResize(width(), height());
+}
+
+void VncView::startQuitting()
+{
+    kDebug(5011) << "about to quit";
+
+    const bool connected = status() == RemoteView::Connected;
+
+    setStatus(Disconnecting);
+
+    m_quitFlag = true;
+
+    if (connected) {
+        vncThread.stop();
+    }
+
+    vncThread.quit();
+
+    const bool quitSuccess = vncThread.wait(500);
+
+    kDebug(5011) << "Quit VNC thread success:" << quitSuccess;
+
+    setStatus(Disconnected);
+}
+
+bool VncView::isQuitting()
+{
+    return m_quitFlag;
+}
+
+bool VncView::start()
+{
+    vncThread.setHost(m_host);
+    vncThread.setPort(m_port);
+
+    vncThread.setQuality(quality);
+
+    // set local cursor on by default because low quality mostly means slow internet connection
+    if (quality == RemoteView::Low) {
+        showDotCursor(RemoteView::CursorOn);
+    }
+
+    setStatus(Connecting);
+
+    vncThread.start();
+    return true;
+}
+
+bool VncView::supportsScaling() const
+{
+    return true;
+}
+
+bool VncView::supportsLocalCursor() const
+{
+    return true;
+}
+
+void VncView::requestPassword()
+{
+    kDebug(5011) << "request password";
+
+    if (m_authenticaionCanceled) {
+        startQuitting();
+        return;
+    }
+
+    setStatus(Authenticating);
+
+    if (!m_url.password().isNull()) {
+        vncThread.setPassword(m_url.password());
+        return;
+    }
+
+    bool ok;
+    QString password = QInputDialog::getText(this, //krazy:exclude=qclasses
+                                             tr("Password required"),
+                                             tr("Please enter the password for the remote desktop:"),
+                                             QLineEdit::Password, QString(), &ok);
+    m_firstPasswordTry = false;
+    if (ok)
+        vncThread.setPassword(password);
+    else
+        m_authenticaionCanceled = true;
+}
+
+void VncView::outputErrorMessage(const QString &message)
+{
+    kDebug(5011) << message;
+
+    if (message == "INTERNAL:APPLE_VNC_COMPATIBILTY") {
+        setCursor(localDotCursor());
+        m_forceLocalCursor = true;
+        return;
+    }
+
+    startQuitting();
+
+    emit errorMessage(i18n("VNC failure"), message);
+}
+
+void VncView::updateImage(int x, int y, int w, int h)
+{
+//     kDebug(5011) << "got update" << width() << height();
+
+    m_x = x;
+    m_y = y;
+    m_w = w;
+    m_h = h;
+
+    if (m_horizontalFactor != 1.0 || m_verticalFactor != 1.0) {
+        // If the view is scaled, grow the update rectangle to avoid artifacts
+        m_x-=1;
+        m_y-=1;
+        m_w+=2;
+        m_h+=2;
+    }
+
+    m_frame = vncThread.image();
+
+    if (!m_initDone) {
+        setAttribute(Qt::WA_StaticContents);
+        setAttribute(Qt::WA_OpaquePaintEvent);
+        installEventFilter(this);
+
+        setCursor(((m_dotCursorState == CursorOn) || m_forceLocalCursor) ? localDotCursor() : Qt::BlankCursor);
+
+        setMouseTracking(true); // get mouse events even when there is no mousebutton pressed
+        setFocusPolicy(Qt::WheelFocus);
+        setStatus(Connected);
+//         emit framebufferSizeChanged(m_frame.width(), m_frame.height());
+        emit connected();
+        
+        if (m_scale) {
+            if (parentWidget())
+                scaleResize(parentWidget()->width(), parentWidget()->height());
+           else
+                scaleResize(width(), height());
+        } 
+        
+        m_initDone = true;
+
+    }
+
+       static QSize old_frame_size = QSize();
+    if ((y == 0 && x == 0) && (m_frame.size() != old_frame_size)) {
+           old_frame_size = m_frame.size();
+        kDebug(5011) << "Updating framebuffer size";
+        if (m_scale) {
+            //setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
+            if (parentWidget())
+                scaleResize(parentWidget()->width(), parentWidget()->height());
+        } else {
+            kDebug(5011) << "Resizing: " << m_frame.width() << m_frame.height();
+            resize(m_frame.width(), m_frame.height());
+            //setMaximumSize(m_frame.width(), m_frame.height()); //This is a hack to force Qt to center the view in the scroll area
+            //setMinimumSize(m_frame.width(), m_frame.height());
+        }
+        emit framebufferSizeChanged(m_frame.width(), m_frame.height());
+    }
+
+    m_repaint = true;
+    repaint(qRound(m_x * m_horizontalFactor), qRound(m_y * m_verticalFactor), qRound(m_w * m_horizontalFactor), qRound(m_h * m_verticalFactor));
+    m_repaint = false;
+}
+
+void VncView::setViewOnly(bool viewOnly)
+{
+    RemoteView::setViewOnly(viewOnly);
+
+    m_dontSendClipboard = viewOnly;
+
+    if (viewOnly)
+        setCursor(Qt::ArrowCursor);
+    else
+        setCursor(m_dotCursorState == CursorOn ? localDotCursor() : Qt::BlankCursor);
+}
+
+void VncView::showDotCursor(DotCursorState state)
+{
+    RemoteView::showDotCursor(state);
+
+    setCursor(state == CursorOn ? localDotCursor() : Qt::BlankCursor);
+}
+
+void VncView::enableScaling(bool scale)
+{
+    RemoteView::enableScaling(scale);
+
+    if (scale) {
+        //setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
+        //setMinimumSize(1, 1);
+        if (parentWidget())
+            scaleResize(parentWidget()->width(), parentWidget()->height());
+           else
+               scaleResize(width(), height());
+    } else {
+        m_verticalFactor = 1.0;
+        m_horizontalFactor = 1.0;
+
+        //setMaximumSize(m_frame.width(), m_frame.height()); //This is a hack to force Qt to center the view in the scroll area
+        //setMinimumSize(m_frame.width(), m_frame.height());
+        resize(m_frame.width(), m_frame.height());
+    }
+}
+
+void VncView::setCut(const QString &text)
+{
+    m_dontSendClipboard = true;
+    m_clipboard->setText(text, QClipboard::Clipboard);
+    m_clipboard->setText(text, QClipboard::Selection);
+    m_dontSendClipboard = false;
+}
+
+void VncView::paintEvent(QPaintEvent *event)
+{
+//     kDebug(5011) << "paint event: x: " << m_x << ", y: " << m_y << ", w: " << m_w << ", h: " << m_h;
+    if (m_frame.isNull() || m_frame.format() == QImage::Format_Invalid) {
+        kDebug(5011) << "no valid image to paint";
+        RemoteView::paintEvent(event);
+        return;
+    }
+
+    event->accept();
+
+    QPainter painter(this);
+
+    if (m_repaint) {
+//         kDebug(5011) << "normal repaint";
+        painter.drawImage(QRect(qRound(m_x*m_horizontalFactor), qRound(m_y*m_verticalFactor),
+                                qRound(m_w*m_horizontalFactor), qRound(m_h*m_verticalFactor)), 
+                          m_frame.copy(m_x, m_y, m_w, m_h).scaled(qRound(m_w*m_horizontalFactor), 
+                                                                  qRound(m_h*m_verticalFactor),
+                                                                  Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
+    } else {
+         kDebug(5011) << "resize repaint";
+        QRect rect = event->rect();
+        if (!force_full_repaint and (rect.width() != width() || rect.height() != height())) {
+             kDebug(5011) << "Partial repaint";
+            const int sx = rect.x()/m_horizontalFactor;
+            const int sy = rect.y()/m_verticalFactor;
+            const int sw = rect.width()/m_horizontalFactor;
+            const int sh = rect.height()/m_verticalFactor;
+            painter.drawImage(rect, 
+                              m_frame.copy(sx, sy, sw, sh).scaled(rect.width(), rect.height(),
+                                                                  Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
+        } else {
+             kDebug(5011) << "Full repaint" << width() << height() << m_frame.width() << m_frame.height();
+            painter.drawImage(QRect(0, 0, width(), height()), 
+                              m_frame.scaled(m_frame.width() * m_horizontalFactor, m_frame.height() * m_verticalFactor,
+                                             Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
+           force_full_repaint = false;
+        }
+    }
+
+    RemoteView::paintEvent(event);
+}
+
+void VncView::resizeEvent(QResizeEvent *event)
+{
+    RemoteView::resizeEvent(event);
+    scaleResize(event->size().width(), event->size().height());
+    forceFullRepaint();
+}
+
+bool VncView::event(QEvent *event)
+{
+    switch (event->type()) {
+    case QEvent::KeyPress:
+    case QEvent::KeyRelease:
+//         kDebug(5011) << "keyEvent";
+        keyEventHandler(static_cast<QKeyEvent*>(event));
+        return true;
+        break;
+    case QEvent::MouseButtonDblClick:
+    case QEvent::MouseButtonPress:
+    case QEvent::MouseButtonRelease:
+    case QEvent::MouseMove:
+//         kDebug(5011) << "mouseEvent";
+        mouseEventHandler(static_cast<QMouseEvent*>(event));
+        return true;
+        break;
+    case QEvent::Wheel:
+//         kDebug(5011) << "wheelEvent";
+        wheelEventHandler(static_cast<QWheelEvent*>(event));
+        return true;
+        break;
+    default:
+        return RemoteView::event(event);
+    }
+}
+
+
+void VncView::mouseEventHandler(QMouseEvent *e)
+{
+       static bool tap_detected = false;
+       static bool double_tap_detected = false;
+       static bool tap_drag_detected = false;
+       static QTime press_time;
+       static QTime up_time; //used for double clicks/tap&drag, for time after first tap
+static QTime foo;
+
+       if(!e) { //flush held taps
+               if(tap_detected) {
+                       m_buttonMask |= 0x01;
+                       vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
+                       m_buttonMask &= 0xfe;
+                       vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
+                       tap_detected = false;
+               } else if(double_tap_detected and press_time.elapsed() > 200) { //got tap + another press -> tap & drag
+                       m_buttonMask |= 0x01;
+                       vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
+                       foo.start();
+                       double_tap_detected = false;
+                       tap_drag_detected = true;
+               }
+                       
+               return;
+       }
+
+       if(e->x() < 0 or e->y() < 0) { //QScrollArea tends to send invalid events sometimes...
+               e->ignore();
+               return;
+       }
+
+       cursor_x = qRound(e->x()/m_horizontalFactor);
+       cursor_y = qRound(e->y()/m_verticalFactor);
+       vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); // plain move event
+
+       if(e->type() == QEvent::MouseButtonPress or e->type() == QEvent::MouseButtonDblClick) {
+               press_time.start();
+               if(tap_detected and up_time.elapsed() < 500) {
+                       tap_detected = false;
+                       double_tap_detected = true;
+
+                       QTimer::singleShot(200, 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() < 200) { //tap
+                       up_time.start();
+                       tap_detected = true;
+                       QTimer::singleShot(500, this, SLOT(mouseEventHandler()));
+               }
+
+       }
+
+/* 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;
+       */
+}
+
+void VncView::wheelEventHandler(QWheelEvent *event)
+{
+    int eb = 0;
+    if (event->delta() < 0)
+        eb |= 0x10;
+    else
+        eb |= 0x8;
+
+    const int x = qRound(event->x() / m_horizontalFactor);
+    const int y = qRound(event->y() / m_verticalFactor);
+
+       kDebug(5011) << "Wheelevent";
+    vncThread.mouseEvent(x, y, eb | m_buttonMask);
+    vncThread.mouseEvent(x, y, m_buttonMask);
+}
+
+void VncView::keyEventHandler(QKeyEvent *e)
+{
+    // strip away autorepeating KeyRelease; see bug #206598
+    if (e->isAutoRepeat() && (e->type() == QEvent::KeyRelease))
+        return;
+
+// parts of this code are based on http://italc.sourcearchive.com/documentation/1.0.9.1/vncview_8cpp-source.html
+    rfbKeySym k = e->nativeVirtualKey();
+
+    // we do not handle Key_Backtab separately as the Shift-modifier
+    // is already enabled
+    if (e->key() == Qt::Key_Backtab) {
+        k = XK_Tab;
+    }
+
+    const bool pressed = (e->type() == QEvent::KeyPress);
+
+    // handle modifiers
+    if (k == XK_Shift_L || k == XK_Control_L || k == XK_Meta_L || k == XK_Alt_L) {
+        if (pressed) {
+            m_mods[k] = true;
+        } else if (m_mods.contains(k)) {
+            m_mods.remove(k);
+        } else {
+            unpressModifiers();
+        }
+    }
+
+
+    //handle clicks via zoom buttons
+    if(e->key() == Qt::Key_F8) {
+       if(pressed)
+               m_buttonMask |= 0x01;
+       else
+               m_buttonMask &= 0xfe;
+       vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
+       kDebug(5011) << "left zoom";
+    } else if(e->key() == Qt::Key_F7) {
+       if(pressed)
+               m_buttonMask |= 0x04;
+       else
+               m_buttonMask &= 0xfb;
+       vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask);
+       kDebug(5011) << "right zoom";
+    } else if (k) {
+        vncThread.keyEvent(k, pressed);
+    }
+}
+
+void VncView::unpressModifiers()
+{
+    const QList<unsigned int> keys = m_mods.keys();
+    QList<unsigned int>::const_iterator it = keys.constBegin();
+    while (it != keys.end()) {
+        vncThread.keyEvent(*it, false);
+        it++;
+    }
+    m_mods.clear();
+}
+
+void VncView::clipboardSelectionChanged()
+{
+    kDebug(5011);
+
+    if (m_status != Connected)
+        return;
+
+    if (m_clipboard->ownsSelection() || m_dontSendClipboard)
+        return;
+
+    const QString text = m_clipboard->text(QClipboard::Selection);
+
+    vncThread.clientCut(text);
+}
+
+void VncView::clipboardDataChanged()
+{
+    kDebug(5011);
+
+    if (m_status != Connected)
+        return;
+
+    if (m_clipboard->ownsClipboard() || m_dontSendClipboard)
+        return;
+
+    const QString text = m_clipboard->text(QClipboard::Clipboard);
+
+    vncThread.clientCut(text);
+}
+
+#include "moc_vncview.cpp"
diff --git a/src/vncview.h b/src/vncview.h
new file mode 100644 (file)
index 0000000..cc2a746
--- /dev/null
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2007-2008 Urs Wolfer <uwolfer @ kde.org>
+**
+** This file is part of KDE.
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; see the file COPYING. If not, write to
+** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+** Boston, MA 02110-1301, USA.
+**
+****************************************************************************/
+
+#ifndef VNCVIEW_H
+#define VNCVIEW_H
+
+#include "remoteview.h"
+#include "vncclientthread.h"
+
+class KConfigGroup{};
+
+#include <QClipboard>
+
+extern "C" {
+#include <rfb/rfbclient.h>
+}
+
+class VncView: public RemoteView
+{
+    Q_OBJECT
+
+public:
+    explicit VncView(QWidget *parent = 0, const KUrl &url = KUrl(), RemoteView::Quality quality = RemoteView::Medium);
+    ~VncView();
+
+    QSize framebufferSize();
+    QSize sizeHint() const;
+    QSize minimumSizeHint() const;
+    void startQuitting();
+    bool isQuitting();
+    bool start();
+    bool supportsScaling() const;
+    bool supportsLocalCursor() const;
+    
+    void setQuality(int q);
+    void setViewOnly(bool viewOnly);
+    void showDotCursor(DotCursorState state);
+    
+    virtual void updateConfiguration();
+
+public slots:
+    void enableScaling(bool scale);
+    void scaleResize(int w, int h);
+    void forceFullRepaint();
+
+protected:
+    void paintEvent(QPaintEvent *event);
+    bool event(QEvent *event);
+    void resizeEvent(QResizeEvent *event);
+    bool eventFilter(QObject *obj, QEvent *event);
+
+private:
+    VncClientThread vncThread;
+    QClipboard *m_clipboard;
+    bool m_initDone;
+    int m_buttonMask;
+    QMap<unsigned int, bool> m_mods;
+    int m_x, m_y, m_w, m_h;
+    int cursor_x, cursor_y;
+    bool m_repaint;
+    bool m_quitFlag;
+    bool m_firstPasswordTry;
+    bool m_authenticaionCanceled;
+    bool m_dontSendClipboard;
+    qreal m_horizontalFactor;
+    qreal m_verticalFactor;
+    QImage m_frame;
+    bool m_forceLocalCursor;
+    bool force_full_repaint;
+    RemoteView::Quality quality;
+
+    void keyEventHandler(QKeyEvent *e);
+    void unpressModifiers();
+    void wheelEventHandler(QWheelEvent *event);
+    
+private slots:
+    void mouseEventHandler(QMouseEvent *event = 0);
+
+    void updateImage(int x, int y, int w, int h);
+    void setCut(const QString &text);
+    void requestPassword();
+    void outputErrorMessage(const QString &message);
+    void clipboardSelectionChanged();
+    void clipboardDataChanged();
+};
+
+#endif
diff --git a/vnc.pro b/vnc.pro
new file mode 100644 (file)
index 0000000..101ccfd
--- /dev/null
+++ b/vnc.pro
@@ -0,0 +1,13 @@
+TEMPLATE = app
+TARGET = 
+LIBS += -Llibvnc/libvncclient/.libs -lvncclient
+DEFINES += QTONLY
+CONFIG += silent
+
+OBJECTS_DIR = $${PWD}/tmp
+MOC_DIR = $${PWD}/tmp
+VPATH = $${PWD}/src
+INCLUDEPATH = $${PWD}/src
+
+HEADERS += remoteview.h vncclientthread.h vncview.h mainwindow.h
+SOURCES += main.cpp remoteview.cpp vncclientthread.cpp vncview.cpp