summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/xcb
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2011-02-08 09:11:32 (GMT)
committerSamuel Rødal <samuel.rodal@nokia.com>2011-02-08 09:11:32 (GMT)
commit4d6150a045a37fe82ec4abad2721eba4374a8c37 (patch)
tree57d643d8e47240be478fbf9763cec4b1142497c3 /src/plugins/platforms/xcb
parent864e16ad2858ba752070528b1ba03edeafa54579 (diff)
downloadQt-4d6150a045a37fe82ec4abad2721eba4374a8c37.zip
Qt-4d6150a045a37fe82ec4abad2721eba4374a8c37.tar.gz
Qt-4d6150a045a37fe82ec4abad2721eba4374a8c37.tar.bz2
Add WM_DELETE_WINDOW support and clean up atom / connection handling.
Diffstat (limited to 'src/plugins/platforms/xcb')
-rw-r--r--src/plugins/platforms/xcb/qxcbconnection.cpp14
-rw-r--r--src/plugins/platforms/xcb/qxcbconnection.h4
-rw-r--r--src/plugins/platforms/xcb/qxcbobject.h62
-rw-r--r--src/plugins/platforms/xcb/qxcbscreen.cpp2
-rw-r--r--src/plugins/platforms/xcb/qxcbscreen.h8
-rw-r--r--src/plugins/platforms/xcb/qxcbwindow.cpp45
-rw-r--r--src/plugins/platforms/xcb/qxcbwindow.h7
-rw-r--r--src/plugins/platforms/xcb/qxcbwindowsurface.cpp16
-rw-r--r--src/plugins/platforms/xcb/qxcbwindowsurface.h4
-rw-r--r--src/plugins/platforms/xcb/xcb.pro1
10 files changed, 124 insertions, 39 deletions
diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp
index df655a3..023f673 100644
--- a/src/plugins/platforms/xcb/qxcbconnection.cpp
+++ b/src/plugins/platforms/xcb/qxcbconnection.cpp
@@ -55,7 +55,7 @@ QXcbConnection::QXcbConnection(const char *displayName)
m_connection = xcb_connect(m_displayName.constData(), &primaryScreen);
- m_setup = xcb_get_setup(m_connection);
+ m_setup = xcb_get_setup(xcb_connection());
xcb_screen_iterator_t it = xcb_setup_roots_iterator(m_setup);
@@ -64,7 +64,7 @@ QXcbConnection::QXcbConnection(const char *displayName)
xcb_screen_next(&it);
}
- QSocketNotifier *socket = new QSocketNotifier(xcb_get_file_descriptor(m_connection), QSocketNotifier::Read, this);
+ QSocketNotifier *socket = new QSocketNotifier(xcb_get_file_descriptor(xcb_connection()), QSocketNotifier::Read, this);
connect(socket, SIGNAL(activated(int)), this, SLOT(eventDispatcher()));
initializeAllAtoms();
@@ -74,7 +74,7 @@ QXcbConnection::~QXcbConnection()
{
qDeleteAll(m_screens);
- xcb_disconnect(m_connection);
+ xcb_disconnect(xcb_connection());
}
QXcbWindow *platformWindowFromId(xcb_window_t id)
@@ -95,7 +95,7 @@ break;
void QXcbConnection::eventDispatcher()
{
- while (xcb_generic_event_t *event = xcb_poll_for_event(m_connection)) {
+ while (xcb_generic_event_t *event = xcb_poll_for_event(xcb_connection())) {
switch (event->response_type & ~0x80) {
case XCB_EXPOSE:
HANDLE_PLATFORM_WINDOW_EVENT(xcb_expose_event_t, window, handleExposeEvent);
@@ -107,6 +107,8 @@ void QXcbConnection::eventDispatcher()
HANDLE_PLATFORM_WINDOW_EVENT(xcb_motion_notify_event_t, event, handleMotionNotifyEvent);
case XCB_CONFIGURE_NOTIFY:
HANDLE_PLATFORM_WINDOW_EVENT(xcb_configure_notify_event_t, event, handleConfigureNotifyEvent);
+ case XCB_CLIENT_MESSAGE:
+ HANDLE_PLATFORM_WINDOW_EVENT(xcb_client_message_event_t, window, handleClientMessageEvent);
default:
break;
@@ -299,8 +301,8 @@ void QXcbConnection::initializeAllAtoms() {
Q_ASSERT(i == QXcbAtom::NAtoms);
for (i = 0; i < QXcbAtom::NAtoms; ++i)
- cookies[i] = xcb_intern_atom(m_connection, false, strlen(names[i]), names[i]);
+ cookies[i] = xcb_intern_atom(xcb_connection(), false, strlen(names[i]), names[i]);
for (i = 0; i < QXcbAtom::NAtoms; ++i)
- m_allAtoms[i] = xcb_intern_atom_reply(m_connection, cookies[i], 0)->atom;
+ m_allAtoms[i] = xcb_intern_atom_reply(xcb_connection(), cookies[i], 0)->atom;
}
diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h
index e0b506f..9fb641e 100644
--- a/src/plugins/platforms/xcb/qxcbconnection.h
+++ b/src/plugins/platforms/xcb/qxcbconnection.h
@@ -222,12 +222,12 @@ public:
QList<QXcbScreen *> screens() const { return m_screens; }
int primaryScreen() const { return m_primaryScreen; }
- xcb_connection_t *connection() const { return m_connection; }
-
xcb_atom_t atom(QXcbAtom::Atom atom);
const char *displayName() const { return m_displayName.constData(); }
+ xcb_connection_t *xcb_connection() const { return m_connection; }
+
private slots:
void eventDispatcher();
diff --git a/src/plugins/platforms/xcb/qxcbobject.h b/src/plugins/platforms/xcb/qxcbobject.h
new file mode 100644
index 0000000..cabfd7c
--- /dev/null
+++ b/src/plugins/platforms/xcb/qxcbobject.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** 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 QXCBOBJECT_H
+#define QXCBOBJECT_H
+
+#include "qxcbconnection.h"
+
+class QXcbObject
+{
+public:
+ QXcbObject(QXcbConnection *connection = 0) : m_connection(connection) {}
+
+ void setConnection(QXcbConnection *connection) { m_connection = connection; }
+ QXcbConnection *connection() const { return m_connection; }
+
+ xcb_atom_t atom(QXcbAtom::Atom atom) const { return m_connection->atom(atom); }
+ xcb_connection_t *xcb_connection() const { return m_connection->xcb_connection(); }
+
+private:
+ QXcbConnection *m_connection;
+};
+
+#endif
diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp
index bbd3fd4..1adde6b 100644
--- a/src/plugins/platforms/xcb/qxcbscreen.cpp
+++ b/src/plugins/platforms/xcb/qxcbscreen.cpp
@@ -44,7 +44,7 @@
#include <stdio.h>
QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *screen)
- : m_connection(connection)
+ : QXcbObject(connection)
, m_screen(screen)
{
printf ("\n");
diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h
index 22b182b..88de1a8 100644
--- a/src/plugins/platforms/xcb/qxcbscreen.h
+++ b/src/plugins/platforms/xcb/qxcbscreen.h
@@ -46,9 +46,11 @@
#include <xcb/xcb.h>
+#include "qxcbobject.h"
+
class QXcbConnection;
-class QXcbScreen : public QPlatformScreen
+class QXcbScreen : public QXcbObject, public QPlatformScreen
{
public:
QXcbScreen(QXcbConnection *connection, xcb_screen_t *screen);
@@ -58,14 +60,10 @@ public:
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;
};
diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp
index c6bb6d7..c7bcd38 100644
--- a/src/plugins/platforms/xcb/qxcbwindow.cpp
+++ b/src/plugins/platforms/xcb/qxcbwindow.cpp
@@ -55,6 +55,8 @@ QXcbWindow::QXcbWindow(QWidget *tlw)
{
m_screen = static_cast<QXcbScreen *>(QPlatformScreen::platformScreenForWidget(tlw));
+ setConnection(m_screen->connection());
+
const quint32 mask = XCB_CW_BACK_PIXMAP | XCB_CW_EVENT_MASK;
const quint32 values[] = {
// XCB_CW_BACK_PIXMAP
@@ -67,8 +69,8 @@ QXcbWindow::QXcbWindow(QWidget *tlw)
| XCB_EVENT_MASK_BUTTON_MOTION
};
- m_window = xcb_generate_id(connection());
- xcb_create_window(connection(),
+ m_window = xcb_generate_id(xcb_connection());
+ xcb_create_window(xcb_connection(),
XCB_COPY_FROM_PARENT, // depth -- same as root
m_window, // window id
m_screen->root(), // parent window id
@@ -82,12 +84,25 @@ QXcbWindow::QXcbWindow(QWidget *tlw)
mask, // value mask
values); // value list
+ xcb_atom_t properties[] = {
+ atom(QXcbAtom::WM_DELETE_WINDOW)
+ };
+
+ xcb_change_property(xcb_connection(),
+ XCB_PROP_MODE_REPLACE,
+ m_window,
+ atom(QXcbAtom::WM_PROTOCOLS),
+ 4,
+ 32,
+ sizeof(properties) / sizeof(xcb_atom_t),
+ properties);
+
printf("m_window: %d\n", m_window);
}
QXcbWindow::~QXcbWindow()
{
- xcb_destroy_window(connection(), m_window);
+ xcb_destroy_window(xcb_connection(), m_window);
}
void QXcbWindow::setGeometry(const QRect &rect)
@@ -98,9 +113,9 @@ void QXcbWindow::setGeometry(const QRect &rect)
void QXcbWindow::setVisible(bool visible)
{
if (visible)
- xcb_map_window(connection(), m_window);
+ xcb_map_window(xcb_connection(), m_window);
else
- xcb_unmap_window(connection(), m_window);
+ xcb_unmap_window(xcb_connection(), m_window);
}
Qt::WindowFlags QXcbWindow::setWindowFlags(Qt::WindowFlags flags)
@@ -125,11 +140,11 @@ void QXcbWindow::setParent(const QPlatformWindow *)
void QXcbWindow::setWindowTitle(const QString &title)
{
QByteArray ba = title.toUtf8();
- xcb_change_property (connection(),
+ xcb_change_property (xcb_connection(),
XCB_PROP_MODE_REPLACE,
m_window,
- m_screen->connection()->atom(QXcbAtom::_NET_WM_NAME),
- m_screen->connection()->atom(QXcbAtom::UTF8_STRING),
+ atom(QXcbAtom::_NET_WM_NAME),
+ atom(QXcbAtom::UTF8_STRING),
8,
ba.length(),
ba.constData());
@@ -147,11 +162,6 @@ 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)
@@ -162,6 +172,15 @@ void QXcbWindow::handleExposeEvent(xcb_expose_event_t *event)
surface->flush(widget(), widget()->geometry(), QPoint());
}
+void QXcbWindow::handleClientMessageEvent(xcb_client_message_event_t *event)
+{
+ if (event->format == 32 && event->type == atom(QXcbAtom::WM_PROTOCOLS)) {
+ if (event->data.data32[0] == atom(QXcbAtom::WM_DELETE_WINDOW)) {
+ QWindowSystemInterface::handleCloseEvent(widget());
+ }
+ }
+}
+
void QXcbWindow::handleConfigureNotifyEvent(xcb_configure_notify_event_t *event)
{
int xpos = geometry().x();
diff --git a/src/plugins/platforms/xcb/qxcbwindow.h b/src/plugins/platforms/xcb/qxcbwindow.h
index d74786b..a772d30 100644
--- a/src/plugins/platforms/xcb/qxcbwindow.h
+++ b/src/plugins/platforms/xcb/qxcbwindow.h
@@ -46,9 +46,11 @@
#include <xcb/xcb.h>
+#include "qxcbobject.h"
+
class QXcbScreen;
-class QXcbWindow : public QPlatformWindow
+class QXcbWindow : public QXcbObject, public QPlatformWindow
{
public:
QXcbWindow(QWidget *tlw);
@@ -73,6 +75,7 @@ public:
xcb_window_t window() const { return m_window; }
void handleExposeEvent(xcb_expose_event_t *event);
+ void handleClientMessageEvent(xcb_client_message_event_t *event);
void handleConfigureNotifyEvent(xcb_configure_notify_event_t *event);
void handleButtonPressEvent(xcb_button_press_event_t *event);
void handleButtonReleaseEvent(xcb_button_release_event_t *event);
@@ -81,8 +84,6 @@ public:
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;
diff --git a/src/plugins/platforms/xcb/qxcbwindowsurface.cpp b/src/plugins/platforms/xcb/qxcbwindowsurface.cpp
index ad91c34..e3b2c6c 100644
--- a/src/plugins/platforms/xcb/qxcbwindowsurface.cpp
+++ b/src/plugins/platforms/xcb/qxcbwindowsurface.cpp
@@ -52,6 +52,9 @@ QXcbWindowSurface::QXcbWindowSurface(QWidget *widget, bool setDefaultSurface)
{
setStaticContentsSupport(false);
setPartialUpdateSupport(false);
+
+ QXcbScreen *screen = static_cast<QXcbScreen *>(QPlatformScreen::platformScreenForWidget(widget));
+ setConnection(screen->connection());
}
QXcbWindowSurface::~QXcbWindowSurface()
@@ -68,15 +71,12 @@ void QXcbWindowSurface::flush(QWidget *widget, const QRegion &region, const QPoi
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);
+ m_gc = xcb_generate_id(xcb_connection());
+ xcb_create_gc(xcb_connection(), m_gc, window->window(), 0, 0);
- xcb_put_image(xcb_con,
+ xcb_put_image(xcb_connection(),
XCB_IMAGE_FORMAT_Z_PIXMAP,
window->window(),
m_gc,
@@ -89,8 +89,8 @@ void QXcbWindowSurface::flush(QWidget *widget, const QRegion &region, const QPoi
m_image.numBytes(),
m_image.bits());
- xcb_free_gc(xcb_con, m_gc);
- xcb_flush(xcb_con);
+ xcb_free_gc(xcb_connection(), m_gc);
+ xcb_flush(xcb_connection());
}
void QXcbWindowSurface::resize(const QSize &size)
diff --git a/src/plugins/platforms/xcb/qxcbwindowsurface.h b/src/plugins/platforms/xcb/qxcbwindowsurface.h
index 74be9a2..66b9c29 100644
--- a/src/plugins/platforms/xcb/qxcbwindowsurface.h
+++ b/src/plugins/platforms/xcb/qxcbwindowsurface.h
@@ -46,7 +46,9 @@
#include <xcb/xcb.h>
-class QXcbWindowSurface : public QWindowSurface
+#include "qxcbobject.h"
+
+class QXcbWindowSurface : public QXcbObject, public QWindowSurface
{
public:
QXcbWindowSurface(QWidget *widget, bool setDefaultSurface = true);
diff --git a/src/plugins/platforms/xcb/xcb.pro b/src/plugins/platforms/xcb/xcb.pro
index cbbda0d..f63495c 100644
--- a/src/plugins/platforms/xcb/xcb.pro
+++ b/src/plugins/platforms/xcb/xcb.pro
@@ -12,6 +12,7 @@ SOURCES = \
qxcbwindowsurface.cpp
HEADERS = \
+ qxcbobject.h \
qxcbintegration.h \
qxcbconnection.h \
qxcbscreen.h \