diff options
author | Samuel Rødal <samuel.rodal@nokia.com> | 2011-02-07 15:29:19 (GMT) |
---|---|---|
committer | Samuel Rødal <samuel.rodal@nokia.com> | 2011-02-07 15:50:35 (GMT) |
commit | 8298a9d4190de1d2055da8be446c8ae4b22b6618 (patch) | |
tree | 0446c2ca4bcab9228d05b3bc81d90ca4cae255a0 /src | |
parent | ed4dddfb3f2a357875fb9e471e7d5db98633f34c (diff) | |
download | Qt-8298a9d4190de1d2055da8be446c8ae4b22b6618.zip Qt-8298a9d4190de1d2055da8be446c8ae4b22b6618.tar.gz Qt-8298a9d4190de1d2055da8be446c8ae4b22b6618.tar.bz2 |
Initial (incomplete) XCB platform port.
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/platforms/xcb/main.cpp | 72 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbconnection.cpp | 110 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbconnection.h | 75 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbintegration.cpp | 116 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbintegration.h | 78 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbscreen.cpp | 77 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbscreen.h | 72 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbwindow.cpp | 189 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbwindow.h | 90 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbwindowsurface.cpp | 106 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbwindowsurface.h | 66 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/xcb.pro | 26 |
12 files changed, 1077 insertions, 0 deletions
diff --git a/src/plugins/platforms/xcb/main.cpp b/src/plugins/platforms/xcb/main.cpp new file mode 100644 index 0000000..1966003 --- /dev/null +++ b/src/plugins/platforms/xcb/main.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui/QPlatformIntegrationPlugin> +#include "qxcbintegration.h" + +QT_BEGIN_NAMESPACE + +class QXcbIntegrationPlugin : public QPlatformIntegrationPlugin +{ +public: + QStringList keys() const; + QPlatformIntegration *create(const QString&, const QStringList&); +}; + +QStringList QXcbIntegrationPlugin::keys() const +{ + QStringList list; + list << "xcb"; + return list; +} + +QPlatformIntegration* QXcbIntegrationPlugin::create(const QString& system, const QStringList& paramList) +{ + Q_UNUSED(paramList); + if (system.toLower() == "xcb") + return new QXcbIntegration; + + return 0; +} + +Q_EXPORT_PLUGIN2(xcb, QXcbIntegrationPlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp new file mode 100644 index 0000000..d5e44ad --- /dev/null +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxcbconnection.h" +#include "qxcbscreen.h" +#include "qxcbwindow.h" + +#include <QtAlgorithms> +#include <QSocketNotifier> + +#include <stdio.h> + +QXcbConnection::QXcbConnection(const char *displayName) +{ + int primaryScreen; + + m_connection = xcb_connect(displayName, &primaryScreen); + + m_setup = xcb_get_setup(m_connection); + + xcb_screen_iterator_t it = xcb_setup_roots_iterator(m_setup); + + while (it.rem) { + m_screens << new QXcbScreen(this, it.data); + xcb_screen_next(&it); + } + + QSocketNotifier *socket = new QSocketNotifier(xcb_get_file_descriptor(m_connection), QSocketNotifier::Read, this); + connect(socket, SIGNAL(activated(int)), this, SLOT(eventDispatcher())); +} + +QXcbConnection::~QXcbConnection() +{ + qDeleteAll(m_screens); + + xcb_disconnect(m_connection); +} + +QXcbWindow *platformWindowFromId(xcb_window_t id) +{ + QWidget *widget = QWidget::find(id); + if (widget) + return static_cast<QXcbWindow *>(widget->platformWindow()); + return 0; +} + +#define HANDLE_PLATFORM_WINDOW_EVENT(event_t, window, handler) \ +{ \ + event_t *e = (event_t *)event; \ + if (QXcbWindow *platformWindow = platformWindowFromId(e->window)) \ + platformWindow->handler(e); \ +} \ +break; + +void QXcbConnection::eventDispatcher() +{ + while (xcb_generic_event_t *event = xcb_poll_for_event(m_connection)) { + switch (event->response_type & ~0x80) { + case XCB_EXPOSE: + HANDLE_PLATFORM_WINDOW_EVENT(xcb_expose_event_t, window, handleExposeEvent); + case XCB_BUTTON_PRESS: + HANDLE_PLATFORM_WINDOW_EVENT(xcb_button_press_event_t, event, handleButtonPressEvent); + case XCB_BUTTON_RELEASE: + HANDLE_PLATFORM_WINDOW_EVENT(xcb_button_release_event_t, event, handleButtonReleaseEvent); + case XCB_MOTION_NOTIFY: + HANDLE_PLATFORM_WINDOW_EVENT(xcb_motion_notify_event_t, event, handleMotionNotifyEvent); + default: + break; + + } + } +} diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h new file mode 100644 index 0000000..509e798 --- /dev/null +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBCONNECTION_H +#define QXCBCONNECTION_H + +#include <xcb/xcb.h> + +#include <QList> +#include <QObject> + +class QXcbScreen; + +class QXcbConnection : public QObject +{ + Q_OBJECT +public: + QXcbConnection(const char *displayName = 0); + ~QXcbConnection(); + + QList<QXcbScreen *> screens() const { return m_screens; } + int primaryScreen() const { return m_primaryScreen; } + + xcb_connection_t *connection() const { return m_connection; } + +private slots: + void eventDispatcher(); + +private: + xcb_connection_t *m_connection; + const xcb_setup_t *m_setup; + + QList<QXcbScreen *> m_screens; + int m_primaryScreen; +}; + +#endif diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp new file mode 100644 index 0000000..5da86010 --- /dev/null +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxcbintegration.h" +#include "qxcbconnection.h" +#include "qxcbscreen.h" +#include "qxcbwindow.h" +#include "qxcbwindowsurface.h" + +#include <xcb/xcb.h> + +#include <private/qpixmap_raster_p.h> + +#include "qgenericunixfontdatabase.h" + +#include <stdio.h> + +QXcbIntegration::QXcbIntegration() + : m_connection(new QXcbConnection) +{ + foreach (QXcbScreen *screen, m_connection->screens()) + m_screens << screen; + + m_fontDatabase = new QGenericUnixFontDatabase(); +} + +QXcbIntegration::~QXcbIntegration() +{ + delete m_connection; +} + +QPixmapData *QXcbIntegration::createPixmapData(QPixmapData::PixelType type) const +{ + return new QRasterPixmapData(type); +} + +QPlatformWindow *QXcbIntegration::createPlatformWindow(QWidget *widget, WId winId) const +{ + Q_UNUSED(winId); + return new QXcbWindow(widget); +} + +QWindowSurface *QXcbIntegration::createWindowSurface(QWidget *widget, WId winId) const +{ + Q_UNUSED(winId); + return new QXcbWindowSurface(widget); +} + +QList<QPlatformScreen *> QXcbIntegration::screens() const +{ + return m_screens; +} + +void QXcbIntegration::moveToScreen(QWidget *window, int screen) +{ + Q_UNUSED(window); + Q_UNUSED(screen); +} + +bool QXcbIntegration::isVirtualDesktop() +{ + return false; +} + +QPlatformFontDatabase *QXcbIntegration::fontDatabase() const +{ + return m_fontDatabase; +} + +QPixmap QXcbIntegration::grabWindow(WId window, int x, int y, int width, int height) const +{ + Q_UNUSED(window); + Q_UNUSED(x); + Q_UNUSED(y); + Q_UNUSED(width); + Q_UNUSED(height); + return QPixmap(); +} diff --git a/src/plugins/platforms/xcb/qxcbintegration.h b/src/plugins/platforms/xcb/qxcbintegration.h new file mode 100644 index 0000000..8b599b3 --- /dev/null +++ b/src/plugins/platforms/xcb/qxcbintegration.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBINTEGRATION_H +#define QXCBINTEGRATION_H + +#include <QtGui/QPlatformIntegration> +#include <QtGui/QPlatformScreen> + +QT_BEGIN_NAMESPACE + +class QXcbConnection; + +class QXcbIntegration : public QPlatformIntegration +{ +public: + QXcbIntegration(); + ~QXcbIntegration(); + + QPixmapData *createPixmapData(QPixmapData::PixelType type) const; + QPlatformWindow *createPlatformWindow(QWidget *widget, WId winId) const; + QWindowSurface *createWindowSurface(QWidget *widget, WId winId) const; + + QList<QPlatformScreen *> screens() const; + void moveToScreen(QWidget *window, int screen); + bool isVirtualDesktop(); + QPixmap grabWindow(WId window, int x, int y, int width, int height) const; + + QPlatformFontDatabase *fontDatabase() const; + +private: + QList<QPlatformScreen *> m_screens; + QXcbConnection *m_connection; + + QPlatformFontDatabase *m_fontDatabase; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp new file mode 100644 index 0000000..bbd3fd4 --- /dev/null +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxcbscreen.h" + +#include <stdio.h> + +QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *screen) + : m_connection(connection) + , m_screen(screen) +{ + printf ("\n"); + printf ("Informations of screen %d:\n", screen->root); + printf (" width.........: %d\n", screen->width_in_pixels); + printf (" height........: %d\n", screen->height_in_pixels); + printf (" depth.........: %d\n", screen->root_depth); + printf (" white pixel...: %x\n", screen->white_pixel); + printf (" black pixel...: %x\n", screen->black_pixel); + printf ("\n"); +} + +QXcbScreen::~QXcbScreen() +{ +} + +QRect QXcbScreen::geometry() const +{ + return QRect(0, 0, m_screen->width_in_pixels, m_screen->height_in_pixels); +} + +int QXcbScreen::depth() const +{ + return m_screen->root_depth; +} + +QImage::Format QXcbScreen::format() const +{ + return QImage::Format_RGB32; +} diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h new file mode 100644 index 0000000..22b182b --- /dev/null +++ b/src/plugins/platforms/xcb/qxcbscreen.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBSCREEN_H +#define QXCBSCREEN_H + +#include <QtGui/QPlatformScreen> + +#include <xcb/xcb.h> + +class QXcbConnection; + +class QXcbScreen : public QPlatformScreen +{ +public: + QXcbScreen(QXcbConnection *connection, xcb_screen_t *screen); + ~QXcbScreen(); + + QRect geometry() const; + int depth() const; + QImage::Format format() const; + + QXcbConnection *connection() const { return m_connection; } + + xcb_screen_t *screen() const { return m_screen; } + xcb_window_t root() const { return m_screen->root; } + +private: + QXcbConnection *m_connection; + + xcb_screen_t *m_screen; +}; + +#endif diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp new file mode 100644 index 0000000..71bef2f --- /dev/null +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxcbwindow.h" + +#include "qxcbconnection.h" +#include "qxcbscreen.h" + +#include <private/qwindowsurface_p.h> + +#include <QtGui/QWindowSystemInterface> + +#include <stdio.h> + +QXcbWindow::QXcbWindow(QWidget *tlw) + : QPlatformWindow(tlw) +{ + m_screen = static_cast<QXcbScreen *>(QPlatformScreen::platformScreenForWidget(tlw)); + + const quint32 mask = XCB_CW_BACK_PIXMAP | XCB_CW_EVENT_MASK; + const quint32 values[] = { + // XCB_CW_BACK_PIXMAP + XCB_NONE, + // XCB_CW_EVENT_MASK + XCB_EVENT_MASK_EXPOSURE + | XCB_EVENT_MASK_BUTTON_PRESS + | XCB_EVENT_MASK_BUTTON_RELEASE + | XCB_EVENT_MASK_BUTTON_MOTION + }; + + m_window = xcb_generate_id(connection()); + xcb_create_window(connection(), + XCB_COPY_FROM_PARENT, // depth -- same as root + m_window, // window id + m_screen->root(), // parent window id + tlw->x(), + tlw->y(), + tlw->width(), + tlw->height(), + 0, // border width + XCB_WINDOW_CLASS_INPUT_OUTPUT, // window class + m_screen->screen()->root_visual, // visual + mask, // value mask + values); // value list + + printf("m_window: %d\n", m_window); +} + +QXcbWindow::~QXcbWindow() +{ + xcb_destroy_window(connection(), m_window); +} + +void QXcbWindow::setGeometry(const QRect &rect) +{ + QPlatformWindow::setGeometry(rect); +} + +void QXcbWindow::setVisible(bool visible) +{ + if (visible) + xcb_map_window(connection(), m_window); + else + xcb_unmap_window(connection(), m_window); +} + +Qt::WindowFlags QXcbWindow::setWindowFlags(Qt::WindowFlags flags) +{ + return flags; +} + +Qt::WindowFlags QXcbWindow::windowFlags() const +{ + return 0; +} + +WId QXcbWindow::winId() const +{ + return m_window; +} + +void QXcbWindow::setParent(const QPlatformWindow *) +{ +} + +void QXcbWindow::setWindowTitle(const QString &) +{ +} + +void QXcbWindow::raise() +{ +} + +void QXcbWindow::lower() +{ +} + +void QXcbWindow::requestActivateWindow() +{ +} + +xcb_connection_t *QXcbWindow::connection() const +{ + return m_screen->connection()->connection(); +} + +void QXcbWindow::handleExposeEvent(xcb_expose_event_t *event) +{ + if (event->count != 0) + return; + + QWindowSurface *surface = widget()->windowSurface(); + if (surface) + surface->flush(widget(), widget()->geometry(), QPoint()); +} + +static Qt::MouseButtons translateMouseButtons(int s) +{ + Qt::MouseButtons ret = 0; + if (s & XCB_BUTTON_MASK_1) + ret |= Qt::LeftButton; + if (s & XCB_BUTTON_MASK_2) + ret |= Qt::MidButton; + if (s & XCB_BUTTON_MASK_3) + ret |= Qt::RightButton; + return ret; +} + +void QXcbWindow::handleButtonPressEvent(xcb_button_press_event_t *event) +{ + handleMouseEvent(event->detail, event->state, event->time, QPoint(event->event_x, event->event_y), QPoint(event->root_x, event->root_y)); +} + +void QXcbWindow::handleButtonReleaseEvent(xcb_button_release_event_t *event) +{ + handleMouseEvent(event->detail, event->state, event->time, QPoint(event->event_x, event->event_y), QPoint(event->root_x, event->root_y)); +} + +void QXcbWindow::handleMouseEvent(xcb_button_t detail, uint16_t state, xcb_timestamp_t time, const QPoint &local, const QPoint &global) +{ + Qt::MouseButtons buttons = translateMouseButtons(state); + Qt::MouseButtons button = translateMouseButtons(detail); + buttons ^= button; // X event uses state *before*, Qt uses state *after* + + QWindowSystemInterface::handleMouseEvent(widget(), time, local, global, buttons); +} + +void QXcbWindow::handleMotionNotifyEvent(xcb_motion_notify_event_t *event) +{ +} + diff --git a/src/plugins/platforms/xcb/qxcbwindow.h b/src/plugins/platforms/xcb/qxcbwindow.h new file mode 100644 index 0000000..51c1856 --- /dev/null +++ b/src/plugins/platforms/xcb/qxcbwindow.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBWINDOW_H +#define QXCBWINDOW_H + +#include <QtGui/QPlatformWindow> + +#include <xcb/xcb.h> + +class QXcbScreen; + +class QXcbWindow : public QPlatformWindow +{ +public: + QXcbWindow(QWidget *tlw); + ~QXcbWindow(); + + void setGeometry(const QRect &rect); + + void setVisible(bool visible); + Qt::WindowFlags setWindowFlags(Qt::WindowFlags flags); + Qt::WindowFlags windowFlags() const; + WId winId() const; + void setParent(const QPlatformWindow *window); + + void setWindowTitle(const QString &title); + void raise(); + void lower(); + + void requestActivateWindow(); + + QPlatformGLContext *glContext() const { return 0; } + + xcb_window_t window() const { return m_window; } + + void handleExposeEvent(xcb_expose_event_t *event); + void handleButtonPressEvent(xcb_button_press_event_t *event); + void handleButtonReleaseEvent(xcb_button_release_event_t *event); + void handleMotionNotifyEvent(xcb_motion_notify_event_t *event); + + void handleMouseEvent(xcb_button_t detail, uint16_t state, xcb_timestamp_t time, const QPoint &local, const QPoint &global); + +private: + xcb_connection_t *connection() const; + + QXcbScreen *m_screen; + + xcb_window_t m_window; +}; + +#endif diff --git a/src/plugins/platforms/xcb/qxcbwindowsurface.cpp b/src/plugins/platforms/xcb/qxcbwindowsurface.cpp new file mode 100644 index 0000000..27912cc --- /dev/null +++ b/src/plugins/platforms/xcb/qxcbwindowsurface.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxcbwindowsurface.h" + +#include "qxcbconnection.h" +#include "qxcbscreen.h" +#include "qxcbwindow.h" + +#include <stdio.h> + +QXcbWindowSurface::QXcbWindowSurface(QWidget *widget, bool setDefaultSurface) + : QWindowSurface(widget, setDefaultSurface) +{ + setStaticContentsSupport(false); + setPartialUpdateSupport(false); +} + +QXcbWindowSurface::~QXcbWindowSurface() +{ +} + +QPaintDevice *QXcbWindowSurface::paintDevice() +{ + return &m_image; +} + +void QXcbWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) +{ + Q_UNUSED(region); + Q_UNUSED(offset); + + QXcbScreen *screen = static_cast<QXcbScreen *>(QPlatformScreen::platformScreenForWidget(widget)); + QXcbWindow *window = static_cast<QXcbWindow *>(widget->window()->platformWindow()); + + xcb_connection_t *xcb_con = screen->connection()->connection(); + + m_gc = xcb_generate_id(xcb_con); + xcb_create_gc(xcb_con, m_gc, window->window(), 0, 0); + + xcb_put_image(xcb_con, + XCB_IMAGE_FORMAT_Z_PIXMAP, + window->window(), + m_gc, + m_image.width(), + m_image.height(), + 0, + 0, + 0, + 24, + m_image.numBytes(), + m_image.bits()); + + xcb_free_gc(xcb_con, m_gc); + xcb_flush(xcb_con); +} + +void QXcbWindowSurface::resize(const QSize &size) +{ + QWindowSurface::resize(size); + m_image = QImage(size, QImage::Format_RGB32); +} + +bool QXcbWindowSurface::scroll(const QRegion &area, int dx, int dy) +{ + return false; +} + diff --git a/src/plugins/platforms/xcb/qxcbwindowsurface.h b/src/plugins/platforms/xcb/qxcbwindowsurface.h new file mode 100644 index 0000000..74be9a2 --- /dev/null +++ b/src/plugins/platforms/xcb/qxcbwindowsurface.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui 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 Technology Preview License Agreement accompanying +** this package. +** +** 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.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXCBWINDOWSURFACE_H +#define QXCBWINDOWSURFACE_H + +#include <private/qwindowsurface_p.h> + +#include <xcb/xcb.h> + +class QXcbWindowSurface : public QWindowSurface +{ +public: + QXcbWindowSurface(QWidget *widget, bool setDefaultSurface = true); + ~QXcbWindowSurface(); + + QPaintDevice *paintDevice(); + void flush(QWidget *widget, const QRegion ®ion, const QPoint &offset); + void resize(const QSize &size); + bool scroll(const QRegion &area, int dx, int dy); + +private: + QImage m_image; + + xcb_gcontext_t m_gc; +}; + +#endif diff --git a/src/plugins/platforms/xcb/xcb.pro b/src/plugins/platforms/xcb/xcb.pro new file mode 100644 index 0000000..cbbda0d --- /dev/null +++ b/src/plugins/platforms/xcb/xcb.pro @@ -0,0 +1,26 @@ +TARGET = xcb + +include(../../qpluginbase.pri) +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms + +SOURCES = \ + main.cpp \ + qxcbintegration.cpp \ + qxcbconnection.cpp \ + qxcbscreen.cpp \ + qxcbwindow.cpp \ + qxcbwindowsurface.cpp + +HEADERS = \ + qxcbintegration.h \ + qxcbconnection.h \ + qxcbscreen.h \ + qxcbwindow.h \ + qxcbwindowsurface.h + +LIBS += -lxcb + +include (../fontdatabases/genericunix/genericunix.pri) + +target.path += $$[QT_INSTALL_PLUGINS]/platforms +INSTALLS += target |