File indexing completed on 2024-05-05 09:51:09
0001 /* 0002 K Win - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2012, 2013 Martin Gräßlin <mgraesslin@kde.org> 0006 SPDX-FileCopyrightText: 2015 Daniel Vrátil <dvratil@redhat.com> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include "xcbwrapper.h" 0012 0013 static xcb_connection_t *sXRandR11XCBConnection = nullptr; 0014 0015 xcb_connection_t *XCB::connection() 0016 { 0017 // Use our own connection to make sure that we won't mess up Qt's connection 0018 // if something goes wrong on our side. 0019 if (sXRandR11XCBConnection == nullptr) { 0020 sXRandR11XCBConnection = xcb_connect(nullptr, nullptr); 0021 } 0022 return sXRandR11XCBConnection; 0023 } 0024 0025 void XCB::closeConnection() 0026 { 0027 if (sXRandR11XCBConnection) { 0028 xcb_disconnect(sXRandR11XCBConnection); 0029 sXRandR11XCBConnection = nullptr; 0030 } 0031 } 0032 0033 xcb_screen_t *XCB::screenOfDisplay(xcb_connection_t *c, int screen) 0034 { 0035 for (auto iter = xcb_setup_roots_iterator(xcb_get_setup(c)); iter.rem; --screen, xcb_screen_next(&iter)) { 0036 if (screen == 0) { 0037 return iter.data; 0038 } 0039 } 0040 0041 return nullptr; 0042 } 0043 0044 XCB::GrabServer::GrabServer() 0045 { 0046 xcb_grab_server(connection()); 0047 } 0048 0049 XCB::GrabServer::~GrabServer() 0050 { 0051 xcb_ungrab_server(connection()); 0052 xcb_flush(connection()); 0053 }