diff options
author | Jørgen Lind <jorgen.lind@nokia.com> | 2010-08-02 10:07:12 (GMT) |
---|---|---|
committer | Jørgen Lind <jorgen.lind@nokia.com> | 2010-08-02 13:29:40 (GMT) |
commit | 6e0edcce4c215f01416a5ee8467b7abe4665e592 (patch) | |
tree | 9f628f973a25a75a10d5010d6da42b941bc18bc8 /src/plugins/platforms | |
parent | da0d594f7d1b01145c5ec47f36d039435e04e7a5 (diff) | |
download | Qt-6e0edcce4c215f01416a5ee8467b7abe4665e592.zip Qt-6e0edcce4c215f01416a5ee8467b7abe4665e592.tar.gz Qt-6e0edcce4c215f01416a5ee8467b7abe4665e592.tar.bz2 |
Make openkode plugin handle events
And make it also work without a gui manager
Diffstat (limited to 'src/plugins/platforms')
10 files changed, 496 insertions, 293 deletions
diff --git a/src/plugins/platforms/openkode/openkode.pro b/src/plugins/platforms/openkode/openkode.pro index 2d90b15..5f2c1cc 100644 --- a/src/plugins/platforms/openkode/openkode.pro +++ b/src/plugins/platforms/openkode/openkode.pro @@ -7,18 +7,17 @@ QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms SOURCES = main.cpp \ qopenkodeintegration.cpp \ - qopenkodewindowsurface.cpp \ qopenkodewindow.cpp \ ../eglconvenience/qeglplatformcontext.cpp \ ../eglconvenience/qeglconvenience.cpp \ qopenkodeeventloopintegration.cpp HEADERS = qopenkodeintegration.h \ - qopenkodewindowsurface.h \ qopenkodewindow.h \ ../eglconvenience/qeglplatformcontext.h \ ../eglconvenience/qeglconvenience.h \ - qopenkodeeventloopintegration.h + qopenkodeeventloopintegration.h \ + openkodekeytranslator.h RESOURCES = resources.qrc diff --git a/src/plugins/platforms/openkode/openkodekeytranslator.h b/src/plugins/platforms/openkode/openkodekeytranslator.h new file mode 100644 index 0000000..e0ba5c1 --- /dev/null +++ b/src/plugins/platforms/openkode/openkodekeytranslator.h @@ -0,0 +1,244 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtOpenVG module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef OPENKODEKEYTRANSLATOR_H +#define OPENKODEKEYTRANSLATOR_H + +#ifdef KD_ATX_keyboard + +#include <KD/ATX_keyboard.h> + +QT_BEGIN_NAMESPACE + +Qt::Key keyTranslator( int key ) +{ + switch (key) { +// KD_KEY_ACCEPT_ATX: +// KD_KEY_AGAIN_ATX: +// KD_KEY_ALLCANDIDATES_ATX +// KD_KEY_ALPHANUMERIC_ATX + case KD_KEY_ALT_ATX: + return Qt::Key_Alt; + case KD_KEY_ALTGRAPH_ATX: + return Qt::Key_AltGr; +// KD_KEY_APPS_ATX +// KD_KEY_ATTN_ATX +// KD_KEY_BROWSERBACK_ATX +// KD_KEY_BROWSERFAVORITES_ATX +// KD_KEY_BROWSERFORWARD_ATX +// KD_KEY_BROWSERHOME_ATX +// KD_KEY_BROWSERREFRESH_ATX +// KD_KEY_BROWSERSEARCH_ATX +// KD_KEY_BROWSERSTOP_ATX + case KD_KEY_CAPSLOCK_ATX: + return Qt::Key_CapsLock; + case KD_KEY_CLEAR_ATX: + return Qt::Key_Clear; + case KD_KEY_CODEINPUT_ATX: + return Qt::Key_Codeinput; +// KD_KEY_COMPOSE_ATX + case KD_KEY_CONTROL_ATX: + return Qt::Key_Control; +// KD_KEY_CRSEL_ATX +// KD_KEY_CONVERT_ATX + case KD_KEY_COPY_ATX: + return Qt::Key_Copy; + case KD_KEY_CUT_ATX: + return Qt::Key_Cut; + case KD_KEY_DOWN_ATX: + return Qt::Key_Down; + case KD_KEY_END_ATX: + return Qt::Key_End; + case KD_KEY_ENTER_ATX: + return Qt::Key_Enter; +// KD_KEY_ERASEEOF_ATX +// KD_KEY_EXECUTE_ATX +// KD_KEY_EXSEL_ATX + case KD_KEY_F1_ATX: + return Qt::Key_F1; + case KD_KEY_F2_ATX: + return Qt::Key_F2; + case KD_KEY_F3_ATX: + return Qt::Key_F3; + case KD_KEY_F4_ATX: + return Qt::Key_F4; + case KD_KEY_F5_ATX: + return Qt::Key_F5; + case KD_KEY_F6_ATX: + return Qt::Key_F6; + case KD_KEY_F7_ATX: + return Qt::Key_F7; + case KD_KEY_F8_ATX: + return Qt::Key_F8; + case KD_KEY_F9_ATX: + return Qt::Key_F9; + case KD_KEY_F10_ATX: + return Qt::Key_F10; + case KD_KEY_F11_ATX: + return Qt::Key_F11; + case KD_KEY_F12_ATX: + return Qt::Key_F12; + case KD_KEY_F13_ATX: + return Qt::Key_F13; + case KD_KEY_F14_ATX: + return Qt::Key_F14; + case KD_KEY_F15_ATX: + return Qt::Key_F15; + case KD_KEY_F16_ATX: + return Qt::Key_F16; + case KD_KEY_F17_ATX: + return Qt::Key_F17; + case KD_KEY_F18_ATX: + return Qt::Key_F18; + case KD_KEY_F19_ATX: + return Qt::Key_F19; + case KD_KEY_F20_ATX: + return Qt::Key_F20; + case KD_KEY_F21_ATX: + return Qt::Key_F21; + case KD_KEY_F22_ATX: + return Qt::Key_F22; + case KD_KEY_F23_ATX: + return Qt::Key_F23; + case KD_KEY_F24_ATX: + return Qt::Key_F24; +// KD_KEY_FINALMODE_ATX +// KD_KEY_FIND_ATX +// KD_KEY_FULLWIDTH_ATX +// KD_KEY_HALFWIDTH_ATX + case KD_KEY_HANGULMODE_ATX: + return Qt::Key_Hangul; +// KD_KEY_HANJAMODE_ATX + case KD_KEY_HELP_ATX: + return Qt::Key_Help; + case KD_KEY_HIRAGANA_ATX: + return Qt::Key_Hiragana; + case KD_KEY_HOME_ATX: + return Qt::Key_Home; + case KD_KEY_INSERT_ATX: + return Qt::Key_Insert; +// KD_KEY_JAPANESEHIRAGANA_ATX: +// KD_KEY_JAPANESEKATAKANA_ATX +// KD_KEY_JAPANESEROMAJI_ATX +// KD_KEY_JUNJAMODE_ATX + case KD_KEY_KANAMODE_ATX: + return Qt::Key_Kana_Lock; //? + case KD_KEY_KANJIMODE_ATX: + return Qt::Key_Kanji; +// KD_KEY_KATAKANA_ATX +// KD_KEY_LAUNCHAPPLICATION1_ATX +// KD_KEY_LAUNCHAPPLICATION2_ATX + case KD_KEY_LAUNCHMAIL_ATX: + return Qt::Key_MailForward; + case KD_KEY_LEFT_ATX: + return Qt::Key_Left; + case KD_KEY_META_ATX: + return Qt::Key_Meta; + case KD_KEY_MEDIANEXTTRACK_ATX: + return Qt::Key_MediaNext; + case KD_KEY_MEDIAPLAYPAUSE_ATX: + return Qt::Key_MediaPause; + case KD_KEY_MEDIAPREVIOUSTRACK_ATX: + return Qt::Key_MediaPrevious; + case KD_KEY_MEDIASTOP_ATX: + return Qt::Key_MediaStop; + case KD_KEY_MODECHANGE_ATX: + return Qt::Key_Mode_switch; +// KD_KEY_NONCONVERT_ATX + case KD_KEY_NUMLOCK_ATX: + return Qt::Key_NumLock; + case KD_KEY_PAGEDOWN_ATX: + return Qt::Key_PageDown; + case KD_KEY_PAGEUP_ATX: + return Qt::Key_PageUp; + case KD_KEY_PASTE_ATX: + return Qt::Key_Paste; + case KD_KEY_PAUSE_ATX: + return Qt::Key_Pause; + case KD_KEY_PLAY_ATX: + return Qt::Key_Play; +// KD_KEY_PREVIOUSCANDIDATE_ATX + case KD_KEY_PRINTSCREEN_ATX: + return Qt::Key_Print; +// case KD_KEY_PROCESS_ATX +// case KD_KEY_PROPS_ATX + case KD_KEY_RIGHT_ATX: + return Qt::Key_Right; +// KD_KEY_ROMANCHARACTERS_ATX + case KD_KEY_SCROLL_ATX: + return Qt::Key_ScrollLock; + case KD_KEY_SELECT_ATX: + return Qt::Key_Select; +// KD_KEY_SELECTMEDIA_ATX + case KD_KEY_SHIFT_ATX: + return Qt::Key_Shift; + case KD_KEY_STOP_ATX: + return Qt::Key_Stop; + case KD_KEY_UP_ATX: + return Qt::Key_Up; +// KD_KEY_UNDO_ATX + case KD_KEY_VOLUMEDOWN_ATX: + return Qt::Key_VolumeDown; + case KD_KEY_VOLUMEMUTE_ATX: + return Qt::Key_VolumeMute; + case KD_KEY_VOLUMEUP_ATX: + return Qt::Key_VolumeUp; + case KD_KEY_WIN_ATX: + return Qt::Key_Meta; + case KD_KEY_ZOOM_ATX: + return Qt::Key_Zoom; + case 0x8: + return Qt::Key_Backspace; + case 0x1b: + return Qt::Key_Escape; + case 0x9: + return Qt::Key_Tab; + + default: + break; + } + + return Qt::Key_Escape; +} + +QT_END_NAMESPACE +#endif //KD_ATX_keyboard +#endif // OPENKODEKEYTRANSLATOR_H diff --git a/src/plugins/platforms/openkode/qopenkodeeventloopintegration.cpp b/src/plugins/platforms/openkode/qopenkodeeventloopintegration.cpp index e21e1d7..bc92d0e 100644 --- a/src/plugins/platforms/openkode/qopenkodeeventloopintegration.cpp +++ b/src/plugins/platforms/openkode/qopenkodeeventloopintegration.cpp @@ -1,12 +1,57 @@ #include "qopenkodeeventloopintegration.h" +#include <QDebug> + #include <KD/kd.h> +#include <KD/ATX_keyboard.h> QT_BEGIN_NAMESPACE +static const int QT_EVENT_WAKEUP_EVENTLOOP = KD_EVENT_USER + 1; + +void kdprocessevent( const KDEvent *event) +{ + switch (event->type) { + case KD_EVENT_INPUT: + qDebug() << "KD_EVENT_INPUT"; + break; + case KD_EVENT_INPUT_POINTER: + qDebug() << "KD_EVENT_INPUT_POINTER"; + break; + case KD_EVENT_WINDOW_CLOSE: + qDebug() << "KD_EVENT_WINDOW_CLOSE"; + break; + case KD_EVENT_WINDOWPROPERTY_CHANGE: + qDebug() << "KD_EVENT_WINDOWPROPERTY_CHANGE"; + qDebug() << event->data.windowproperty.pname; + break; + case KD_EVENT_WINDOW_FOCUS: + qDebug() << "KD_EVENT_WINDOW_FOCUS"; + break; + case KD_EVENT_WINDOW_REDRAW: + qDebug() << "KD_EVENT_WINDOW_REDRAW"; + break; + case KD_EVENT_USER: + qDebug() << "KD_EVENT_USER"; + break; + case KD_EVENT_INPUT_KEY_ATX: + qDebug() << "KD_EVENT_INPUT_KEY_ATX"; + break; + case QT_EVENT_WAKEUP_EVENTLOOP: +// qDebug() << "QT_EVENT_WAKEUP_EVENTLOOP"; + break; + default: + break; + } + + kdDefaultEvent(event); + +} + QOpenKODEEventLoopIntegration::QOpenKODEEventLoopIntegration() { m_kdThread = kdThreadSelf(); + kdInstallCallback(&kdprocessevent,QT_EVENT_WAKEUP_EVENTLOOP,this); } void QOpenKODEEventLoopIntegration::processEvents(qint64 msec) @@ -25,6 +70,8 @@ void QOpenKODEEventLoopIntegration::processEvents(qint64 msec) void QOpenKODEEventLoopIntegration::wakeup() { KDEvent *event = kdCreateEvent(); + event->type = QT_EVENT_WAKEUP_EVENTLOOP; + event->userptr = this; kdPostThreadEvent(event,m_kdThread); } diff --git a/src/plugins/platforms/openkode/qopenkodeeventloopintegration.h b/src/plugins/platforms/openkode/qopenkodeeventloopintegration.h index 868eda8..03f800c 100644 --- a/src/plugins/platforms/openkode/qopenkodeeventloopintegration.h +++ b/src/plugins/platforms/openkode/qopenkodeeventloopintegration.h @@ -4,6 +4,7 @@ #include <QtGui/QPlatformEventLoopIntegration> class KDThread; +class KDEvent; QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -14,7 +15,10 @@ public: QOpenKODEEventLoopIntegration(); void processEvents(qint64 msec); void wakeup(); + + void processInputEvent(const KDEvent *event); private: + KDThread *m_kdThread; }; diff --git a/src/plugins/platforms/openkode/qopenkodeintegration.cpp b/src/plugins/platforms/openkode/qopenkodeintegration.cpp index 5dada28..8fc3862 100644 --- a/src/plugins/platforms/openkode/qopenkodeintegration.cpp +++ b/src/plugins/platforms/openkode/qopenkodeintegration.cpp @@ -40,7 +40,6 @@ ****************************************************************************/ #include "qopenkodeintegration.h" -#include "qopenkodewindowsurface.h" #include "qopenkodewindow.h" #include "qopenkodeeventloopintegration.h" @@ -67,6 +66,7 @@ QT_BEGIN_NAMESPACE QOpenKODEScreen::QOpenKODEScreen() + : mIsFullScreen(false) { KDDesktopNV *kdDesktop = KD_NULL; KDDisplayNV *kdDisplay = KD_NULL; @@ -130,12 +130,13 @@ QOpenKODEScreen::QOpenKODEScreen() qErrnoWarning("EGL failed to initialize display"); } - const int defaultDpi = 72; - mGeometry = QRect(0, 0, mode.width, mode.height); - mPhysicalSize = QSize(mode.width * 25.4 / defaultDpi, mode.height * 25.4 / defaultDpi); +// cursor = new QOpenKODECursor(this); + mGeometry = QRect(0, 0, mode.width, mode.height); mDepth = 24; mFormat = QImage::Format_RGB32; + + } static GLuint loadShaders(const QString &vertexShader, const QString &fragmentShader) @@ -186,6 +187,7 @@ static GLuint loadShaders(const QString &vertexShader, const QString &fragmentSh } QOpenKODEIntegration::QOpenKODEIntegration() + : mEventLoopIntegration(0) { if (kdInitializeNV() == KD_ENOTINITIALIZED) { qFatal("Did not manage to initialize openkode"); @@ -195,6 +197,10 @@ QOpenKODEIntegration::QOpenKODEIntegration() mScreens.append(mPrimaryScreen); } +QOpenKODEIntegration::~QOpenKODEIntegration() +{ + delete mEventLoopIntegration; +} QPixmapData *QOpenKODEIntegration::createPixmapData(QPixmapData::PixelType type) const { @@ -212,9 +218,6 @@ QWindowSurface *QOpenKODEIntegration::createWindowSurface(QWidget *widget, WId w switch (widget->platformWindowFormat().windowApi()) { case QPlatformWindowFormat::Raster: - returnSurface = new QOpenKODEWindowSurface(widget, wid); - break; - case QPlatformWindowFormat::OpenGL: returnSurface = new QGLWindowSurface(widget); break; @@ -238,7 +241,11 @@ bool QOpenKODEIntegration::hasOpenGL() const QPlatformEventLoopIntegration *QOpenKODEIntegration::createEventLoopIntegration() const { - return new QOpenKODEEventLoopIntegration; + if (!mEventLoopIntegration) { + QOpenKODEIntegration *that = const_cast<QOpenKODEIntegration *>(this); + that->mEventLoopIntegration = new QOpenKODEEventLoopIntegration; + } + return mEventLoopIntegration; } GLuint QOpenKODEIntegration::blitterProgram() diff --git a/src/plugins/platforms/openkode/qopenkodeintegration.h b/src/plugins/platforms/openkode/qopenkodeintegration.h index 8d3d175..454aa90 100644 --- a/src/plugins/platforms/openkode/qopenkodeintegration.h +++ b/src/plugins/platforms/openkode/qopenkodeintegration.h @@ -42,6 +42,8 @@ #ifndef QGRAPHICSSYSTEM_OPENKODE_H #define QGRAPHICSSYSTEM_OPENKODE_H +#include "qopenkodeeventloopintegration.h" + #include <QtCore/qsemaphore.h> #include <QtGui/QPlatformIntegration> @@ -55,6 +57,7 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE struct KDDesktopNV; +class QOpenKODECursor; class QOpenKODEScreen : public QPlatformScreen { @@ -66,21 +69,24 @@ public: QRect geometry() const { return mGeometry; } int depth() const { return mDepth; } QImage::Format format() const { return mFormat; } - QSize physicalSize() const { return mPhysicalSize; } EGLDisplay eglDisplay() { return mEglDisplay; } -public: + + bool isFullScreen() const {return mIsFullScreen;} + void setFullScreen(bool fullscreen) { mIsFullScreen = fullscreen; } +private: QRect mGeometry; int mDepth; QImage::Format mFormat; - QSize mPhysicalSize; EGLDisplay mEglDisplay; + bool mIsFullScreen; }; class QOpenKODEIntegration : public QPlatformIntegration { public: QOpenKODEIntegration(); + ~QOpenKODEIntegration(); QPixmapData *createPixmapData(QPixmapData::PixelType type) const; QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId = 0) const; @@ -96,6 +102,7 @@ public: private: QList<QPlatformScreen *> mScreens; + QOpenKODEEventLoopIntegration *mEventLoopIntegration; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/openkode/qopenkodewindow.cpp b/src/plugins/platforms/openkode/qopenkodewindow.cpp index 81f38d2..c890641 100644 --- a/src/plugins/platforms/openkode/qopenkodewindow.cpp +++ b/src/plugins/platforms/openkode/qopenkodewindow.cpp @@ -45,6 +45,10 @@ #include <KD/kd.h> #include <KD/NV_display.h> +#include <KD/kdplatform.h> +#ifdef KD_ATX_keyboard +#include "openkodekeytranslator.h" +#endif #include <EGL/egl.h> @@ -57,6 +61,20 @@ QT_BEGIN_NAMESPACE +void kdProcessMouseEvents( const KDEvent *event ) +{ + QOpenKODEWindow *window = static_cast<QOpenKODEWindow *>(event->userptr); + window->processMouseEvents(event); +} + +#ifdef KD_ATX_keyboard +void kdProcessKeyEvents( const KDEvent *event ) +{ + QOpenKODEWindow *window = static_cast<QOpenKODEWindow *>(event->userptr); + window->processKeyEvents(event); +} +#endif //KD_ATX_keyboard + QOpenKODEWindow::QOpenKODEWindow(QWidget *tlw) : QPlatformWindow(tlw) { @@ -92,54 +110,90 @@ QOpenKODEWindow::QOpenKODEWindow(QWidget *tlw) m_kdWindow = kdCreateWindow(screen->eglDisplay(), m_eglConfig, - KD_NULL); + this); + kdInstallCallback(kdProcessMouseEvents,KD_EVENT_INPUT_POINTER,this); +#ifdef KD_ATX_keyboard + kdInstallCallback(kdProcessKeyEvents, KD_EVENT_INPUT_KEY_ATX,this); +#endif //KD_ATX_keyboard + if (!m_kdWindow) { qErrnoWarning(kdGetError(), "Error creating native window"); return; } - const KDint windowSize[2] = { tlw->width(), tlw->height()-1 }; - if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_SIZE, windowSize)) { - qErrnoWarning(kdGetError(), "Could not set native window size"); - return; + bool fullscreen = false; + KDboolean exclusive(false); + if (kdSetWindowPropertybv(m_kdWindow,KD_WINDOWPROPERTY_DESKTOP_EXCLUSIVE_NV, &exclusive)) { + fullscreen = true; } - KDboolean visibillity(false); - if (kdSetWindowPropertybv(m_kdWindow, KD_WINDOWPROPERTY_VISIBILITY, &visibillity)) { - qErrnoWarning(kdGetError(), "Could not set visibillity to false"); - } + if (fullscreen) { + tlw->setGeometry(screen->geometry()); + screen->setFullScreen(fullscreen); + }else { + const KDint windowSize[2] = { tlw->width(), tlw->height() }; + if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_SIZE, windowSize)) { + qErrnoWarning(kdGetError(), "Could not set native window size"); + } + KDboolean visibillity(false); + if (kdSetWindowPropertybv(m_kdWindow, KD_WINDOWPROPERTY_VISIBILITY, &visibillity)) { + qErrnoWarning(kdGetError(), "Could not set visibillity to false"); + } - const KDint windowPos[2] = { tlw->x(), tlw->y() }; - if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_DESKTOP_OFFSET_NV, windowPos)) { - qErrnoWarning(kdGetError(), "Could not set native window position"); - return; + const KDint windowPos[2] = { tlw->x(), tlw->y() }; + if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_DESKTOP_OFFSET_NV, windowPos)) { + qErrnoWarning(kdGetError(), "Could not set native window position"); + return; + } } - if (kdRealizeWindow(m_kdWindow, &m_eglWindow)) { - qErrnoWarning(kdGetError(), "Could not realize native window"); - return; - } - EGLSurface surface = eglCreateWindowSurface(screen->eglDisplay(),m_eglConfig,m_eglWindow,m_eglWindowAttrs.constData()); - m_platformGlContext = new QEGLPlatformContext(screen->eglDisplay(), m_eglConfig, - m_eglContextAttrs.data(), surface, m_eglApi); + + if (!fullscreen || (fullscreen && !QPlatformGLContext::defaultSharedContext())) { + if (kdRealizeWindow(m_kdWindow, &m_eglWindow)) { + qErrnoWarning(kdGetError(), "Could not realize native window"); + return; + } + + EGLSurface surface = eglCreateWindowSurface(screen->eglDisplay(),m_eglConfig,m_eglWindow,m_eglWindowAttrs.constData()); + m_platformGlContext = new QEGLPlatformContext(screen->eglDisplay(), m_eglConfig, + m_eglContextAttrs.data(), surface, m_eglApi); + m_platformGlContext->makeDefaultSaredContext(); + } else { + m_platformGlContext = static_cast<QEGLPlatformContext *>(QPlatformGLContext::defaultSharedContext()); + kdDestroyWindow(m_kdWindow); + m_kdWindow = 0; + } } + QOpenKODEWindow::~QOpenKODEWindow() { qDebug() << "destroying window" << m_kdWindow; - delete m_platformGlContext; - kdDestroyWindow(m_kdWindow); + if (m_platformGlContext != QPlatformGLContext::defaultSharedContext()) { + delete m_platformGlContext; + } + if (m_kdWindow) + kdDestroyWindow(m_kdWindow); } void QOpenKODEWindow::setGeometry(const QRect &rect) { + if (!m_kdWindow) { + QList<QPlatformScreen *> screens = QApplicationPrivate::platformIntegration()->screens(); + QOpenKODEScreen *screen = qobject_cast<QOpenKODEScreen *>(screens.at(0)); + widget()->setGeometry(screen->geometry()); + return; + } + bool needToDeleteContext = false; const QRect geo = geometry(); if (geo.size() != rect.size()) { - const KDint windowSize[2] = { rect.width(), rect.height() -1 }; + const KDint windowSize[2] = { rect.width(), rect.height() }; if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_SIZE, windowSize)) { qErrnoWarning(kdGetError(), "Could not set native window size"); //return; + } else { + needToDeleteContext = true; } } @@ -148,11 +202,16 @@ void QOpenKODEWindow::setGeometry(const QRect &rect) if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_DESKTOP_OFFSET_NV, windowPos)) { qErrnoWarning(kdGetError(), "Could not set native window position"); //return; + } else { + needToDeleteContext = true; } } //need to recreate context - delete m_platformGlContext; + if (needToDeleteContext) { + qDebug() << "deleting context"; + delete m_platformGlContext; + } QList<QPlatformScreen *> screens = QApplicationPrivate::platformIntegration()->screens(); QOpenKODEScreen *screen = qobject_cast<QOpenKODEScreen *>(screens.at(0)); @@ -163,14 +222,96 @@ void QOpenKODEWindow::setGeometry(const QRect &rect) void QOpenKODEWindow::setVisible(bool visible) { + if (!m_kdWindow) + return; KDboolean visibillity(visible); if (kdSetWindowPropertybv(m_kdWindow, KD_WINDOWPROPERTY_VISIBILITY, &visibillity)) { - qErrnoWarning(kdGetError(), "Could not set visibillity to false"); + qErrnoWarning(kdGetError(), "Could not set visibillity property"); } } +WId QOpenKODEWindow::winId() const +{ + static int i = 0; + return i++; +} + QPlatformGLContext *QOpenKODEWindow::glContext() const { return m_platformGlContext; } + +void QOpenKODEWindow::raise() +{ + if (!m_kdWindow) + return; + KDboolean focus(true); + if (kdSetWindowPropertybv(m_kdWindow, KD_WINDOWPROPERTY_FOCUS, &focus)) { + qErrnoWarning(kdGetError(), "Could not set focus"); + } +} + +void QOpenKODEWindow::lower() +{ + if (!m_kdWindow) + return; + KDboolean focus(false); + if (kdSetWindowPropertybv(m_kdWindow, KD_WINDOWPROPERTY_FOCUS, &focus)) { + qErrnoWarning(kdGetError(), "Could not set focus"); + } +} + +void QOpenKODEWindow::processMouseEvents(const KDEvent *event) +{ + int x = event->data.inputpointer.x; + int y = event->data.inputpointer.y; + Qt::MouseButtons buttons; + switch(event->data.inputpointer.select) { + case 1: + buttons = Qt::LeftButton; + break; + default: + buttons = Qt::NoButton; + } + qDebug() << x << y; + QPoint pos(x,y); + QWindowSystemInterface::handleMouseEvent(0,event->timestamp,pos,pos,buttons); +} + +void QOpenKODEWindow::processKeyEvents(const KDEvent *event) +{ +#ifdef KD_ATX_keyboard + //KD_KEY_PRESS_ATX 1 + QEvent::Type keyPressed = QEvent::KeyRelease; + if (event->data.keyboardInputKey.flags) + keyPressed = QEvent::KeyPress; +//KD_KEY_LOCATION_LEFT_ATX // dont care for now +//KD_KEY_LOCATION_RIGHT_ATX +//KD_KEY_LOCATION_NUMPAD_ATX + Qt::KeyboardModifiers mod = Qt::NoModifier; + int openkodeMods = event->data.keyboardInputKey.flags; + if (openkodeMods & KD_KEY_MODIFIER_SHIFT_ATX) + mod |= Qt::ShiftModifier; + if (openkodeMods & KD_KEY_MODIFIER_CTRL_ATX) + mod |= Qt::ControlModifier; + if (openkodeMods & KD_KEY_MODIFIER_ALT_ATX) + mod |= Qt::AltModifier; + if (openkodeMods & KD_KEY_MODIFIER_META_ATX) + mod |= Qt::MetaModifier; + + Qt::Key qtKey; + QChar keyText; + int key = event->data.keyboardInputKey.keycode; + if (key >= 0x20 && key <= 0x0ff){ // 8 bit printable Latin1 + qtKey = Qt::Key(key); + keyText = QChar(event->data.keyboardInputKeyChar.character); + if (!(mod & Qt::ShiftModifier)) + keyText = keyText.toLower(); + } else { + qtKey = keyTranslator(key); + } + QWindowSystemInterface::handleKeyEvent(0,event->timestamp,keyPressed,qtKey,mod,keyText); +#endif +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/openkode/qopenkodewindow.h b/src/plugins/platforms/openkode/qopenkodewindow.h index 3e7ee56..1980c15 100644 --- a/src/plugins/platforms/openkode/qopenkodewindow.h +++ b/src/plugins/platforms/openkode/qopenkodewindow.h @@ -51,6 +51,7 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE class QEGLPlatformContext; +class QPlatformEventLoopIntegration; class QOpenKODEWindow : public QPlatformWindow { @@ -60,10 +61,16 @@ public: void setGeometry(const QRect &rect); void setVisible(bool visible); - WId winId() const { return WId(m_eglWindow); } + WId winId() const; QPlatformGLContext *glContext() const; + void raise(); + void lower(); + + void processKeyEvents( const KDEvent *event ); + void processMouseEvents( const KDEvent *event ); + private: struct KDWindow *m_kdWindow; EGLNativeWindowType m_eglWindow; diff --git a/src/plugins/platforms/openkode/qopenkodewindowsurface.cpp b/src/plugins/platforms/openkode/qopenkodewindowsurface.cpp deleted file mode 100644 index 84e27f5..0000000 --- a/src/plugins/platforms/openkode/qopenkodewindowsurface.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtOpenVG module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qopenkodewindowsurface.h" -#include "qopenkodeintegration.h" - -#include "qopenkodewindow.h" - -#include <QtCore/qdebug.h> -#include <QtGui/QPlatformGLContext> - -QT_BEGIN_NAMESPACE - -QOpenKODEWindowSurface::QOpenKODEWindowSurface - (QWidget *window, WId) - : QWindowSurface(window), m_platformGLContext(window->platformWindow()->glContext()) -{ -} - -QOpenKODEWindowSurface::~QOpenKODEWindowSurface() -{ -} - -QPaintDevice *QOpenKODEWindowSurface::paintDevice() -{ - return &mImage; -} - -// ### TODO - this updates the entire toplevel, should only update the region -void QOpenKODEWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) -{ - m_platformGLContext->makeCurrent(); - - if (!offset.isNull()) { - qWarning("Offset flushing not supported yet"); - return; - } - - m_platformGLContext->makeCurrent(); - - QRect boundingRect = region.boundingRect(); - - int x, y, w, h; - QImage blitImage; - if (true || boundingRect == mImage.rect()) { // TODO - check optimization - blitImage = mImage; - x = y = 0; - w = mImage.width(); - h = mImage.height(); - } else { - blitImage = mImage.copy(boundingRect); - w = boundingRect.width(); - h = boundingRect.height(); - x = boundingRect.x(); - y = boundingRect.y(); - } - - GLuint shaderProgram = QOpenKODEIntegration::blitterProgram(); - - glUseProgram(shaderProgram); - - GLuint index = glGetUniformLocation(shaderProgram, "window"); - glUniform2f(index, GLfloat(mImage.width()), GLfloat(mImage.height())); - - // attributes - GLuint posId = glGetAttribLocation(shaderProgram, "pos_attr"); - GLuint texcoordId = glGetAttribLocation(shaderProgram, "texcoord_attr"); - - // sampler - index = glGetUniformLocation(shaderProgram, "tex_samp"); - - glUniform1i(index, 0); - - glDisable(GL_DEPTH_TEST); - glActiveTexture(GL_TEXTURE0); - - GLuint texId; - GLfloat coords[8] = {x, y, x, y + h, x + w, y + h, x + w, y }; - GLfloat texcoords[8] = { 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0 }; - - // Generate texture for checkered background - glGenTextures(1, &texId); - glBindTexture(GL_TEXTURE_2D, texId); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, mImage.bits()); - - // Enable vertex attribute associated with vertex position - glEnableVertexAttribArray(posId); - glEnableVertexAttribArray(texcoordId); - - // Set the quad vertices - glVertexAttribPointer(posId, 2, GL_FLOAT, 0, 0, coords); - glVertexAttribPointer(texcoordId, 2, GL_FLOAT, 0, 0, texcoords); - - // Draw the quad - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - - // Cleanup - glDisableVertexAttribArray(posId); - glDisableVertexAttribArray(texcoordId); - - // Release all textures - glBindTexture(GL_TEXTURE_2D, 0); - if (texId) - glDeleteTextures(1, &texId); - - eglWaitGL(); - - m_platformGLContext->swapBuffers(); - m_platformGLContext->doneCurrent(); - - eglWaitNative(EGL_CORE_NATIVE_ENGINE); -} - -void QOpenKODEWindowSurface::resize(const QSize &size) -{ - QWindowSurface::resize(size); - mImage = QImage(); - -} -void QOpenKODEWindowSurface::beginPaint(const QRegion ®ion) -{ - Q_UNUSED(region); - if (mImage.isNull()) { - m_platformGLContext = window()->platformWindow()->glContext(); - mImage = QImage(size(),QImage::Format_RGB888); - } -} - -void QOpenKODEWindowSurface::endPaint(const QRegion ®ion) -{ - Q_UNUSED(region); -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/openkode/qopenkodewindowsurface.h b/src/plugins/platforms/openkode/qopenkodewindowsurface.h deleted file mode 100644 index f12b625..0000000 --- a/src/plugins/platforms/openkode/qopenkodewindowsurface.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtOpenVG module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://www.qtsoftware.com/contact. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINDOWSURFACE_OPENKODE_H -#define QWINDOWSURFACE_OPENKODE_H - -#include <QtGui/private/qwindowsurface_p.h> - -#include <EGL/egl.h> - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - -class QOpenKODEWindow; -class QPlatformGLContext; - -class QOpenKODEWindowSurface : public QWindowSurface -{ -public: - QOpenKODEWindowSurface - (QWidget *window, WId winId); - ~QOpenKODEWindowSurface(); - - QPaintDevice *paintDevice(); - void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); - void resize (const QSize &size); - - void beginPaint(const QRegion ®ion); - void endPaint(const QRegion ®ion); - -private: - QImage mImage; - QPlatformGLContext *m_platformGLContext; -}; - -QT_END_NAMESPACE -QT_END_HEADER - -#endif |