File indexing completed on 2024-04-28 05:46:51
0001 /***************************************************************************** 0002 * Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU Lesser General Public License as * 0006 * published by the Free Software Foundation; either version 2.1 of the * 0007 * License, or (at your option) version 3, or any later version accepted * 0008 * by the membership of KDE e.V. (or its successor approved by the * 0009 * membership of KDE e.V.), which shall act as a proxy defined in * 0010 * Section 6 of version 3 of the license. * 0011 * * 0012 * This program is distributed in the hope that it will be useful, * 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0015 * Lesser General Public License for more details. * 0016 * * 0017 * You should have received a copy of the GNU Lesser General Public * 0018 * License along with this library. If not, * 0019 * see <http://www.gnu.org/licenses/>. * 0020 *****************************************************************************/ 0021 0022 #include "x11utils.h" 0023 0024 #ifndef _QTC_UTILS_X11UTILS_P_H_ 0025 #define _QTC_UTILS_X11UTILS_P_H_ 0026 0027 extern void *qtc_disp; 0028 extern xcb_connection_t *qtc_xcb_conn; 0029 extern int qtc_default_screen_no; 0030 extern xcb_window_t qtc_root_window; 0031 extern xcb_screen_t *qtc_default_screen; 0032 extern xcb_atom_t qtc_x11_kde_net_wm_blur_behind_region; 0033 extern xcb_atom_t qtc_x11_kde_net_wm_shadow; 0034 extern xcb_atom_t qtc_x11_net_wm_moveresize; 0035 extern xcb_atom_t qtc_x11_net_wm_cm_s_default; 0036 0037 template <typename Ret, typename Cookie, typename... Args, typename... Args2> 0038 static inline Ret* 0039 _qtcX11Call(Cookie (*func)(xcb_connection_t*, Args...), 0040 Ret *(reply_func)(xcb_connection_t*, Cookie, xcb_generic_error_t**), 0041 Args2... args) 0042 { 0043 xcb_connection_t *conn = qtc_xcb_conn; 0044 QTC_RET_IF_FAIL(conn, nullptr); 0045 Cookie cookie = func(conn, args...); 0046 return reply_func(conn, cookie, 0); 0047 } 0048 #define qtcX11Call(name, args...) \ 0049 (_qtcX11Call(xcb_##name, xcb_##name##_reply, args)) 0050 0051 template <typename... Args, typename... Args2> 0052 static inline xcb_void_cookie_t 0053 _qtcX11CallVoid(xcb_void_cookie_t (*func)(xcb_connection_t*, Args...), 0054 Args2... args) 0055 { 0056 xcb_connection_t *conn = qtc_xcb_conn; 0057 QTC_RET_IF_FAIL(conn, xcb_void_cookie_t()); 0058 return func(conn, args...); 0059 } 0060 #define qtcX11CallVoid(name, args...) \ 0061 (_qtcX11CallVoid(xcb_##name, args)) 0062 0063 #define qtcX11CallVoidChecked(name, args...) \ 0064 (_qtcX11CallVoid(xcb_##name##_checked, args)) 0065 0066 QTC_ALWAYS_INLINE static inline xcb_atom_t 0067 qtcX11GetAtom(const char *name, bool create) 0068 { 0069 xcb_intern_atom_reply_t *r = qtcX11Call(intern_atom, !create, 0070 strlen(name), name); 0071 xcb_atom_t atom = r ? r->atom : 0; 0072 free(r); 0073 return atom; 0074 } 0075 0076 #endif