Qt 4.8
qxcbscreen.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qxcbscreen.h"
43 
44 #include <stdio.h>
45 
46 QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *screen, int number)
47  : QXcbObject(connection)
48  , m_screen(screen)
49  , m_number(number)
50 {
51  printf ("\n");
52  printf ("Information of screen %d:\n", screen->root);
53  printf (" width.........: %d\n", screen->width_in_pixels);
54  printf (" height........: %d\n", screen->height_in_pixels);
55  printf (" depth.........: %d\n", screen->root_depth);
56  printf (" white pixel...: %x\n", screen->white_pixel);
57  printf (" black pixel...: %x\n", screen->black_pixel);
58  printf ("\n");
59 
60  const quint32 mask = XCB_CW_EVENT_MASK;
61  const quint32 values[] = {
62  // XCB_CW_EVENT_MASK
63  XCB_EVENT_MASK_ENTER_WINDOW
64  | XCB_EVENT_MASK_LEAVE_WINDOW
65  | XCB_EVENT_MASK_PROPERTY_CHANGE
66  };
67 
68  xcb_change_window_attributes(xcb_connection(), screen->root, mask, values);
69 
70  xcb_generic_error_t *error;
71 
72  xcb_get_property_reply_t *reply =
73  xcb_get_property_reply(xcb_connection(),
74  xcb_get_property(xcb_connection(), false, screen->root,
76  XCB_ATOM_WINDOW, 0, 1024), &error);
77 
78  if (reply && reply->format == 32 && reply->type == XCB_ATOM_WINDOW) {
79  xcb_window_t windowManager = *((xcb_window_t *)xcb_get_property_value(reply));
80 
81  if (windowManager != XCB_WINDOW_NONE) {
82  xcb_get_property_reply_t *windowManagerReply =
83  xcb_get_property_reply(xcb_connection(),
84  xcb_get_property(xcb_connection(), false, windowManager,
86  atom(QXcbAtom::UTF8_STRING), 0, 1024), &error);
87  if (windowManagerReply && windowManagerReply->format == 8 && windowManagerReply->type == atom(QXcbAtom::UTF8_STRING)) {
88  m_windowManagerName = QString::fromUtf8((const char *)xcb_get_property_value(windowManagerReply), xcb_get_property_value_length(windowManagerReply));
89  printf("Running window manager: %s\n", qPrintable(m_windowManagerName));
90  } else if (error) {
91  connection->handleXcbError(error);
92  free(error);
93  }
94 
95  free(windowManagerReply);
96  }
97  } else if (error) {
98  connection->handleXcbError(error);
99  free(error);
100  }
101 
102  free(reply);
103 
105 }
106 
108 {
109 }
110 
112 {
113  return QRect(0, 0, m_screen->width_in_pixels, m_screen->height_in_pixels);
114 }
115 
116 int QXcbScreen::depth() const
117 {
118  return m_screen->root_depth;
119 }
120 
122 {
123  return QImage::Format_RGB32;
124 }
125 
127 {
128  return QSize(m_screen->width_in_millimeters, m_screen->height_in_millimeters);
129 }
130 
132 {
133  return m_number;
134 }
QXcbScreen(QXcbConnection *connection, xcb_screen_t *screen, int number)
Definition: qxcbscreen.cpp:46
Format
The following image formats are available in Qt.
Definition: qimage.h:91
int depth() const
Reimplement in subclass to return current depth of the screen.
Definition: qxcbscreen.cpp:116
#define error(msg)
xcb_connection_t * xcb_connection() const
Definition: qxcbobject.h:56
QImage::Format format() const
Reimplement in subclass to return the image format which corresponds to the screen format...
Definition: qxcbscreen.cpp:121
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void handleXcbError(xcb_generic_error_t *error)
QRect geometry() const
Reimplement in subclass to return the pixel geometry of the screen.
Definition: qxcbscreen.cpp:111
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
bool m_syncRequestSupported
Definition: qxcbscreen.h:77
int m_number
Definition: qxcbscreen.h:75
quint16 values[128]
unsigned int quint32
Definition: qglobal.h:938
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QSize physicalSize() const
Reimplement this function in subclass to return the physical size of the screen.
Definition: qxcbscreen.cpp:126
int screenNumber() const
Definition: qxcbscreen.cpp:131
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
xcb_screen_t * m_screen
Definition: qxcbscreen.h:74
xcb_atom_t atom(QXcbAtom::Atom atom) const
Definition: qxcbobject.h:55
QString m_windowManagerName
Definition: qxcbscreen.h:76
#define qPrintable(string)
Definition: qglobal.h:1750