| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 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 The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qxcbwmsupport.h" |
| 41 | #include "qxcbscreen.h" |
| 42 | |
| 43 | #include <qdebug.h> |
| 44 | |
| 45 | QT_BEGIN_NAMESPACE |
| 46 | |
| 47 | QXcbWMSupport::QXcbWMSupport(QXcbConnection *c) |
| 48 | : QXcbObject(c) |
| 49 | { |
| 50 | updateNetWMAtoms(); |
| 51 | updateVirtualRoots(); |
| 52 | } |
| 53 | |
| 54 | bool QXcbWMSupport::isSupportedByWM(xcb_atom_t atom) const |
| 55 | { |
| 56 | return net_wm_atoms.contains(t: atom); |
| 57 | } |
| 58 | |
| 59 | |
| 60 | |
| 61 | void QXcbWMSupport::updateNetWMAtoms() |
| 62 | { |
| 63 | net_wm_atoms.clear(); |
| 64 | |
| 65 | xcb_window_t root = connection()->primaryScreen()->root(); |
| 66 | int offset = 0; |
| 67 | int remaining = 0; |
| 68 | do { |
| 69 | auto reply = Q_XCB_REPLY(xcb_get_property, xcb_connection(), false, root, atom(QXcbAtom::_NET_SUPPORTED), XCB_ATOM_ATOM, offset, 1024); |
| 70 | if (!reply) |
| 71 | break; |
| 72 | |
| 73 | remaining = 0; |
| 74 | |
| 75 | if (reply->type == XCB_ATOM_ATOM && reply->format == 32) { |
| 76 | int len = xcb_get_property_value_length(R: reply.get())/sizeof(xcb_atom_t); |
| 77 | xcb_atom_t *atoms = (xcb_atom_t *)xcb_get_property_value(R: reply.get()); |
| 78 | int s = net_wm_atoms.size(); |
| 79 | net_wm_atoms.resize(asize: s + len); |
| 80 | memcpy(dest: net_wm_atoms.data() + s, src: atoms, n: len*sizeof(xcb_atom_t)); |
| 81 | |
| 82 | remaining = reply->bytes_after; |
| 83 | offset += len; |
| 84 | } |
| 85 | } while (remaining > 0); |
| 86 | } |
| 87 | |
| 88 | // update the virtual roots array |
| 89 | void QXcbWMSupport::updateVirtualRoots() |
| 90 | { |
| 91 | net_virtual_roots.clear(); |
| 92 | |
| 93 | if (!isSupportedByWM(atom: atom(atom: QXcbAtom::_NET_VIRTUAL_ROOTS))) |
| 94 | return; |
| 95 | |
| 96 | xcb_window_t root = connection()->primaryScreen()->root(); |
| 97 | int offset = 0; |
| 98 | int remaining = 0; |
| 99 | do { |
| 100 | auto reply = Q_XCB_REPLY(xcb_get_property, xcb_connection(), |
| 101 | false, root, atom(QXcbAtom::_NET_VIRTUAL_ROOTS), XCB_ATOM_WINDOW, offset, 1024); |
| 102 | if (!reply) |
| 103 | break; |
| 104 | |
| 105 | remaining = 0; |
| 106 | |
| 107 | if (reply->type == XCB_ATOM_WINDOW && reply->format == 32) { |
| 108 | int len = xcb_get_property_value_length(R: reply.get())/sizeof(xcb_window_t); |
| 109 | xcb_window_t *roots = (xcb_window_t *)xcb_get_property_value(R: reply.get()); |
| 110 | int s = net_virtual_roots.size(); |
| 111 | net_virtual_roots.resize(asize: s + len); |
| 112 | memcpy(dest: net_virtual_roots.data() + s, src: roots, n: len*sizeof(xcb_window_t)); |
| 113 | |
| 114 | remaining = reply->bytes_after; |
| 115 | offset += len; |
| 116 | } |
| 117 | |
| 118 | } while (remaining > 0); |
| 119 | |
| 120 | //#define VIRTUAL_ROOTS_DEBUG |
| 121 | #ifdef VIRTUAL_ROOTS_DEBUG |
| 122 | qDebug("======== updateVirtualRoots" ); |
| 123 | for (int i = 0; i < net_virtual_roots.size(); ++i) |
| 124 | qDebug() << connection()->atomName(net_virtual_roots.at(i)); |
| 125 | qDebug("======== updateVirtualRoots" ); |
| 126 | #endif |
| 127 | } |
| 128 | |
| 129 | QT_END_NAMESPACE |
| 130 | |