Changeset View
Changeset View
Standalone View
Standalone View
kcms/touchpadx/src/backends/x11/xcbatom.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2013 Alexander Mezin <mezin.alexander@gmail.com> | ||||
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, Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | | ||||
19 | #include "xcbatom.h" | ||||
20 | | ||||
21 | #include <cstdlib> | ||||
22 | #include <cstring> | ||||
23 | | ||||
24 | XcbAtom::XcbAtom() : m_connection(0), m_reply(0), m_fetched(false) | ||||
25 | { | ||||
26 | } | ||||
27 | | ||||
28 | XcbAtom::XcbAtom(xcb_connection_t *c, const char *name, bool onlyIfExists) | ||||
29 | : m_reply(0), m_fetched(false) | ||||
30 | { | ||||
31 | intern(c, name, onlyIfExists); | ||||
32 | } | ||||
33 | | ||||
34 | void XcbAtom::intern(xcb_connection_t *c, const char *name, bool onlyIfExists) | ||||
35 | { | ||||
36 | m_connection = c; | ||||
37 | m_cookie = xcb_intern_atom(c, onlyIfExists, std::strlen(name), name); | ||||
38 | } | ||||
39 | | ||||
40 | XcbAtom::~XcbAtom() | ||||
41 | { | ||||
42 | std::free(m_reply); | ||||
43 | } | ||||
44 | | ||||
45 | xcb_atom_t XcbAtom::atom() | ||||
46 | { | ||||
47 | if (!m_fetched) { | ||||
48 | m_fetched = true; | ||||
49 | m_reply = xcb_intern_atom_reply(m_connection, m_cookie, 0); | ||||
50 | } | ||||
51 | if (m_reply) { | ||||
52 | return m_reply->atom; | ||||
53 | } else { | ||||
54 | return 0; | ||||
55 | } | ||||
56 | } |