1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the plugins of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #include "qxcbwmsupport.h"
43 #include "qxcbscreen.h"
49 QXcbWMSupport::QXcbWMSupport(QXcbConnection *c)
56 bool QXcbWMSupport::isSupportedByWM(xcb_atom_t atom) const
58 return net_wm_atoms.contains(atom);
63 void QXcbWMSupport::updateNetWMAtoms()
67 xcb_window_t root = connection()->screens().at(connection()->primaryScreen())->root();
71 xcb_get_property_cookie_t cookie = xcb_get_property(xcb_connection(), false, root, atom(QXcbAtom::_NET_SUPPORTED), XCB_ATOM_ATOM, offset, 1024);
72 xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, NULL);
78 if (reply->type == XCB_ATOM_ATOM && reply->format == 32) {
79 int len = xcb_get_property_value_length(reply)/4;
80 xcb_atom_t *atoms = (xcb_atom_t *)xcb_get_property_value(reply);
81 int s = net_wm_atoms.size();
82 net_wm_atoms.resize(s + len);
83 memcpy(net_wm_atoms.data() + s, atoms, len*sizeof(xcb_atom_t));
85 remaining = reply->bytes_after;
90 } while (remaining > 0);
93 // update the virtual roots array
94 void QXcbWMSupport::updateVirtualRoots()
96 net_virtual_roots.clear();
98 if (!isSupportedByWM(atom(QXcbAtom::_NET_VIRTUAL_ROOTS)))
101 xcb_window_t root = connection()->screens().at(connection()->primaryScreen())->root();
105 xcb_get_property_cookie_t cookie = xcb_get_property(xcb_connection(), false, root, atom(QXcbAtom::_NET_VIRTUAL_ROOTS), XCB_ATOM_ATOM, offset, 1024);
106 xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, NULL);
112 if (reply->type == XCB_ATOM_ATOM && reply->format == 32) {
113 int len = xcb_get_property_value_length(reply)/4;
114 xcb_atom_t *atoms = (xcb_atom_t *)xcb_get_property_value(reply);
115 int s = net_wm_atoms.size();
116 net_wm_atoms.resize(s + len);
117 memcpy(net_wm_atoms.data() + s, atoms, len*sizeof(xcb_atom_t));
119 remaining = reply->bytes_after;
124 } while (remaining > 0);
127 qDebug() << "======== updateVirtualRoots";
128 for (int i = 0; i < net_virtual_roots.size(); ++i)
129 qDebug() << connection()->atomName(net_virtual_roots.at(i));
130 qDebug() << "======== updateVirtualRoots";