forked from desktop-app/cmake_helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux_xcb_helper.cpp
53 lines (45 loc) · 1.25 KB
/
linux_xcb_helper.cpp
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
// This file is part of Desktop App Toolkit,
// a set of libraries for developing nice desktop applications.
//
// For license and copyright information please follow this link:
// https://github.com/desktop-app/legal/blob/master/LEGAL
//
#include <dlfcn.h>
#include <stdlib.h>
#include <xcb/xcb.h>
#include <xcb/xcbext.h>
unsigned int xcb_send_request_with_fds(
xcb_connection_t *c,
int flags,
struct iovec *vector,
const xcb_protocol_request_t *req,
unsigned int num_fds,
int *fds) {
const auto send_request_with_fds = reinterpret_cast<unsigned int(*)(
xcb_connection_t*,
int,
struct iovec*,
const xcb_protocol_request_t*,
unsigned int,
int*)>(dlsym(RTLD_NEXT, "xcb_send_request_with_fds"));
if (!dlerror()) {
return send_request_with_fds(c, flags, vector, req, num_fds, fds);
}
const auto send_fd = reinterpret_cast<void(*)(xcb_connection_t*, int)>(
dlsym(RTLD_NEXT, "xcb_send_fd"));
if (dlerror()) {
abort();
}
const auto send_request = reinterpret_cast<unsigned int(*)(
xcb_connection_t*,
int,
struct iovec*,
const xcb_protocol_request_t*)>(dlsym(RTLD_NEXT, "xcb_send_request"));
if (dlerror()) {
abort();
}
for (int i = 0; i != num_fds; ++i) {
send_fd(c, fds[i]);
}
return send_request(c, flags, vector, req);
}