Debian Codegraph @

src/backend/imageGrabber/GnomeX11Wrapper.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 Damir Porobic <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "GnomeX11Wrapper.h"
21
22 QRect GnomeX11Wrapper::getActiveWindowRect() const
23 {
24 auto windowId = X11Wrapper::getActiveWindowId();
25 auto windowRect = X11Wrapper::getWindowRect(windowId);
26
27 auto frameExtents = getGtkFrameExtents(windowId);
28
29 return windowRect.adjusted(frameExtents.left, frameExtents.top, -frameExtents.right, -frameExtents.bottom);
30 }
31
32 GnomeX11Wrapper::FrameExtents GnomeX11Wrapper::getGtkFrameExtents(unsigned int windowId)
33 {
34 FrameExtents values{};
35 auto connection = QX11Info::connection();
36 auto atom_cookie = xcb_intern_atom(connection, 0, strlen("_GTK_FRAME_EXTENTS"), "_GTK_FRAME_EXTENTS");
37 ScopedCPointer<xcb_intern_atom_reply_t> atom_reply(xcb_intern_atom_reply(connection, atom_cookie, nullptr));
38
39 if (!atom_reply.isNull()) {
40 auto cookie = xcb_get_property(connection, 0, windowId, atom_reply->atom, XCB_ATOM_CARDINAL, 0, 4);
41 ScopedCPointer<xcb_get_property_reply_t> reply(xcb_get_property_reply(connection, cookie, nullptr));
42
43 if (!reply.isNull()) {
44 int length = xcb_get_property_value_length(reply.data());
45 if (length != 0) {
46 auto gtkFrameExtents = static_cast<uint32_t*>(xcb_get_property_value(reply.data()));
47 values.left = (int)gtkFrameExtents[0];
48 values.right = (int)gtkFrameExtents[1];
49 values.top = (int)gtkFrameExtents[2];
50 values.bottom = (int)gtkFrameExtents[3];
51 }
52 }
53 }
54
55 return values;
56 }