File: xcbwrapper.cpp

package info (click to toggle)
libkscreen 4%3A6.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,436 kB
  • sloc: cpp: 12,115; xml: 83; makefile: 10; sh: 1
file content (53 lines) | stat: -rw-r--r-- 1,291 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
    K Win - the KDE window manager
    This file is part of the KDE project.

    SPDX-FileCopyrightText: 2012, 2013 Martin Gräßlin <mgraesslin@kde.org>
    SPDX-FileCopyrightText: 2015 Daniel Vrátil <dvratil@redhat.com>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "xcbwrapper.h"

static xcb_connection_t *sXRandR11XCBConnection = nullptr;

xcb_connection_t *XCB::connection()
{
    // Use our own connection to make sure that we won't mess up Qt's connection
    // if something goes wrong on our side.
    if (sXRandR11XCBConnection == nullptr) {
        sXRandR11XCBConnection = xcb_connect(nullptr, nullptr);
    }
    return sXRandR11XCBConnection;
}

void XCB::closeConnection()
{
    if (sXRandR11XCBConnection) {
        xcb_disconnect(sXRandR11XCBConnection);
        sXRandR11XCBConnection = nullptr;
    }
}

xcb_screen_t *XCB::screenOfDisplay(xcb_connection_t *c, int screen)
{
    for (auto iter = xcb_setup_roots_iterator(xcb_get_setup(c)); iter.rem; --screen, xcb_screen_next(&iter)) {
        if (screen == 0) {
            return iter.data;
        }
    }

    return nullptr;
}

XCB::GrabServer::GrabServer()
{
    xcb_grab_server(connection());
}

XCB::GrabServer::~GrabServer()
{
    xcb_ungrab_server(connection());
    xcb_flush(connection());
}