GCC Code Coverage Report


Directory: ./
File: backends/xrandr/xcbwrapper.cpp
Date: 2023-04-20 22:59:23
Exec Total Coverage
Lines: 0 19 0.0%
Branches: 0 8 0.0%

Line Branch Exec Source
1 /********************************************************************
2 K Win - the KDE window manager
3 This file is part of the KDE project.
4
5 Copyright (C) 2012, 2013 Martin Gräßlin <mgraesslin@kde.org>
6 Copyright (C) 2015 Daniel Vrátil <dvratil@redhat.com>
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *********************************************************************/
21 #include "xcbwrapper.h"
22
23 static xcb_connection_t* sXRandR11XCBConnection = nullptr;
24
25 xcb_connection_t* XCB::connection()
26 {
27 // Use our own connection to make sure that we won't mess up Qt's connection
28 // if something goes wrong on our side.
29 if (sXRandR11XCBConnection == nullptr) {
30 sXRandR11XCBConnection = xcb_connect(nullptr, nullptr);
31 }
32 return sXRandR11XCBConnection;
33 }
34
35 void XCB::closeConnection()
36 {
37 if (sXRandR11XCBConnection) {
38 xcb_disconnect(sXRandR11XCBConnection);
39 sXRandR11XCBConnection = nullptr;
40 }
41 }
42
43 xcb_screen_t* XCB::screenOfDisplay(xcb_connection_t* c, int screen)
44 {
45 for (auto iter = xcb_setup_roots_iterator(xcb_get_setup(c)); iter.rem;
46 --screen, xcb_screen_next(&iter)) {
47 if (screen == 0) {
48 return iter.data;
49 }
50 }
51
52 return nullptr;
53 }
54
55 XCB::GrabServer::GrabServer()
56 {
57 xcb_grab_server(connection());
58 }
59
60 XCB::GrabServer::~GrabServer()
61 {
62 xcb_ungrab_server(connection());
63 xcb_flush(connection());
64 }
65