From 8a4b707a7c1a18d1c2c02251da66f3d71b0aebb7 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Wed, 8 Aug 2018 15:18:14 -0400 Subject: [PATCH] Switch from macros to functions. --- src/x11.cc | 136 +++++++++++++++++++---------------------------------- 1 file changed, 48 insertions(+), 88 deletions(-) diff --git a/src/x11.cc b/src/x11.cc index 90b0945f..9f67fea4 100644 --- a/src/x11.cc +++ b/src/x11.cc @@ -32,12 +32,12 @@ #include "conky.h" #include "logging.h" -#include "x11.h" +#include #include #include #include #include -#include +#include "x11.h" #ifdef BUILD_IMLIB2 #include "imlib2.h" #endif /* BUILD_IMLIB2 */ @@ -83,9 +83,7 @@ void out_to_x_setting::lua_setter(lua::state &l, bool init) { Base::lua_setter(l, init); - if (init && do_convert(l, -1).first) { - init_X11(); - } + if (init && do_convert(l, -1).first) { init_X11(); } ++s; } @@ -93,9 +91,7 @@ void out_to_x_setting::lua_setter(lua::state &l, bool init) { void out_to_x_setting::cleanup(lua::state &l) { lua::stack_sentry s(l, -1); - if (do_convert(l, -1).first) { - deinit_X11(); - } + if (do_convert(l, -1).first) { deinit_X11(); } l.pop(); } @@ -130,9 +126,7 @@ void own_window_setting::lua_setter(lua::state &l, bool init) { #ifdef BUILD_XDBE bool use_xdbe_setting::set_up(lua::state &l) { // double_buffer makes no sense when not drawing to X - if (not out_to_x.get(l)) { - return false; - } + if (not out_to_x.get(l)) { return false; } int major, minor; @@ -266,7 +260,6 @@ conky::lua_traits::Map conky::lua_traits::map = { std::pair window_hints_traits::convert( lua::state &l, int index, const std::string &name) { - lua::stack_sentry s(l); l.checkstack(1); @@ -280,9 +273,7 @@ std::pair window_hints_traits::convert( if (newpos > pos) { l.pushstring(hints.substr(pos, newpos - pos)); auto t = conky::lua_traits::convert(l, -1, name); - if (not t.second) { - return {0, false}; - }; + if (not t.second) { return {0, false}; }; SET_HINT(ret, t.first); l.pop(); } @@ -454,7 +445,8 @@ static void update_workarea() { XineramaScreenInfo *si = XineramaQueryScreens(display, &heads); if (si == nullptr) { NORM_ERR( - "warning: XineramaQueryScreen returned nullptr, ignoring head settings"); + "warning: XineramaQueryScreen returned nullptr, ignoring head " + "settings"); return; /* queryscreens failed? */ } @@ -490,9 +482,7 @@ static Window find_desktop_window(Window *p_root, Window *p_desktop) { Window troot, parent, *children; unsigned char *buf = nullptr; - if ((p_root == nullptr) || (p_desktop == nullptr)) { - return 0; - } + if ((p_root == nullptr) || (p_desktop == nullptr)) { return 0; } /* some window managers set __SWM_VROOT to some child of root window */ @@ -626,13 +616,9 @@ static int get_argb_visual(Visual **visual, int *depth) { void destroy_window() { #ifdef BUILD_XFT - if (window.xftdraw != nullptr) { - XftDrawDestroy(window.xftdraw); - } + if (window.xftdraw != nullptr) { XftDrawDestroy(window.xftdraw); } #endif /* BUILD_XFT */ - if (window.gc != nullptr) { - XFreeGC(display, window.gc); - } + if (window.gc != nullptr) { XFreeGC(display, window.gc); } memset(&window, 0, sizeof(struct conky_window)); } @@ -647,9 +633,7 @@ static void init_window(lua::state &l __attribute__((unused)), bool own) { int depth = 0, flags = CWOverrideRedirect | CWBackingStore; Visual *visual = nullptr; - if (find_desktop_window(&window.root, &window.desktop) == 0u) { - return; - } + if (find_desktop_window(&window.root, &window.desktop) == 0u) { return; } #ifdef BUILD_ARGB if (use_argb_visual.get(l) && (get_argb_visual(&visual, &depth) != 0)) { @@ -671,9 +655,7 @@ static void init_window(lua::state &l __attribute__((unused)), bool own) { border_outer_margin.get(l); /* Sanity check to avoid making an invalid 0x0 window */ - if (b == 0) { - b = 1; - } + if (b == 0) { b = 1; } if (own_window_type.get(l) == TYPE_OVERRIDE) { /* An override_redirect True window. @@ -749,9 +731,7 @@ static void init_window(lua::state &l __attribute__((unused)), bool own) { } #endif /* BUILD_ARGB */ - if (own_window_type.get(l) == TYPE_DOCK) { - window.x = window.y = 0; - } + if (own_window_type.get(l) == TYPE_DOCK) { window.x = window.y = 0; } /* Parent is root window so WM can take control */ window.window = XCreateWindow(display, window.root, window.x, window.y, b, b, 0, @@ -1002,9 +982,7 @@ static Window find_subwindow(Window win, int w, int h) { } XFree(children); - if (j == n) { - break; - } + if (j == n) { break; } } return win; @@ -1029,9 +1007,7 @@ static inline void get_x11_desktop_current(Display *current_display, unsigned char *prop = nullptr; struct information *current_info = &info; - if (atom == None) { - return; - } + if (atom == None) { return; } if ((XGetWindowProperty(current_display, root, atom, 0, 1L, False, XA_CARDINAL, &actual_type, &actual_format, &nitems, @@ -1039,9 +1015,7 @@ static inline void get_x11_desktop_current(Display *current_display, (actual_type == XA_CARDINAL) && (nitems == 1L) && (actual_format == 32)) { current_info->x11.desktop.current = prop[0] + 1; } - if (prop != nullptr) { - XFree(prop); - } + if (prop != nullptr) { XFree(prop); } } // Get total number of available desktops @@ -1054,9 +1028,7 @@ static inline void get_x11_desktop_number(Display *current_display, Window root, unsigned char *prop = nullptr; struct information *current_info = &info; - if (atom == None) { - return; - } + if (atom == None) { return; } if ((XGetWindowProperty(current_display, root, atom, 0, 1L, False, XA_CARDINAL, &actual_type, &actual_format, &nitems, @@ -1064,9 +1036,7 @@ static inline void get_x11_desktop_number(Display *current_display, Window root, (actual_type == XA_CARDINAL) && (nitems == 1L) && (actual_format == 32)) { current_info->x11.desktop.number = prop[0]; } - if (prop != nullptr) { - XFree(prop); - } + if (prop != nullptr) { XFree(prop); } } // Get all desktop names @@ -1079,9 +1049,7 @@ static inline void get_x11_desktop_names(Display *current_display, Window root, unsigned char *prop = nullptr; struct information *current_info = &info; - if (atom == None) { - return; - } + if (atom == None) { return; } if ((XGetWindowProperty(current_display, root, atom, 0, (~0L), False, ATOM(UTF8_STRING), &actual_type, &actual_format, @@ -1091,9 +1059,7 @@ static inline void get_x11_desktop_names(Display *current_display, Window root, current_info->x11.desktop.all_names.assign( reinterpret_cast(prop), nitems); } - if (prop != nullptr) { - XFree(prop); - } + if (prop != nullptr) { XFree(prop); } } // Get current desktop name @@ -1165,7 +1131,8 @@ void print_monitor(struct text_object *obj, char *p, unsigned int p_max_size) { snprintf(p, p_max_size, "%d", XDefaultScreen(display)); } -void print_monitor_number(struct text_object *obj, char *p, unsigned int p_max_size) { +void print_monitor_number(struct text_object *obj, char *p, + unsigned int p_max_size) { (void)obj; if (not out_to_x.get(*state)) { @@ -1185,7 +1152,8 @@ void print_desktop(struct text_object *obj, char *p, unsigned int p_max_size) { snprintf(p, p_max_size, "%d", info.x11.desktop.current); } -void print_desktop_number(struct text_object *obj, char *p, unsigned int p_max_size) { +void print_desktop_number(struct text_object *obj, char *p, + unsigned int p_max_size) { (void)obj; if (not out_to_x.get(*state)) { @@ -1195,7 +1163,8 @@ void print_desktop_number(struct text_object *obj, char *p, unsigned int p_max_s snprintf(p, p_max_size, "%d", info.x11.desktop.number); } -void print_desktop_name(struct text_object *obj, char *p, unsigned int p_max_size) { +void print_desktop_name(struct text_object *obj, char *p, + unsigned int p_max_size) { (void)obj; if (not out_to_x.get(*state)) { @@ -1249,13 +1218,9 @@ void set_struts(int sidenum) { sizes[i] = 0; } else { if (i <= 1 || i >= 8) { - if (sizes[i] > display_width) { - sizes[i] = display_width; - } + if (sizes[i] > display_width) { sizes[i] = display_width; } } else { - if (sizes[i] > display_height) { - sizes[i] = display_height; - } + if (sizes[i] > display_height) { sizes[i] = display_height; } } } } @@ -1296,35 +1261,29 @@ void xpmdb_swap_buffers(void) { } #endif /* BUILD_XDBE */ -#define LOCK_TEMPLATE_1(func) \ -void print_##func(struct text_object *obj, char *p, unsigned int p_max_size) { \ - (void)obj; \ - XKeyboardState x; \ - XGetKeyboardControl(display, &x); \ - snprintf(p, p_max_size, "%s", (x.led_mask & 1 ? "On" : "Off")); \ +void print_kdb_led(const int keybit, char *p, unsigned int p_max_size) { + XKeyboardState x; + XGetKeyboardControl(display, &x); + snprintf(p, p_max_size, "%s", (x.led_mask & keybit ? "On" : "Off")); +} +void print_caps_led(struct text_object *obj, char *p, unsigned int p_max_size) { + (void)obj; + print_kdb_led(1, p, p_max_size); } -#define LOCK_TEMPLATE_2(func) \ -void print_##func(struct text_object *obj, char *p, unsigned int p_max_size) { \ - (void)obj; \ - XKeyboardState x; \ - XGetKeyboardControl(display, &x); \ - snprintf(p, p_max_size, "%s", (x.led_mask & 2 ? "On" : "Off")); \ +void print_num_led(struct text_object *obj, char *p, unsigned int p_max_size) { + (void)obj; + print_kdb_led(2, p, p_max_size); } -#define LOCK_TEMPLATE_4(func) \ -void print_##func(struct text_object *obj, char *p, unsigned int p_max_size) { \ - (void)obj; \ - XKeyboardState x; \ - XGetKeyboardControl(display, &x); \ - snprintf(p, p_max_size, "%s", (x.led_mask & 4 ? "On" : "Off")); \ +void print_scroll_led(struct text_object *obj, char *p, + unsigned int p_max_size) { + (void)obj; + print_kdb_led(4, p, p_max_size); } -LOCK_TEMPLATE_2(num_led) -LOCK_TEMPLATE_1(caps_led) -LOCK_TEMPLATE_4(scroll_led) - -void print_kb_layout(struct text_object *obj, char *p, unsigned int p_max_size) { +void print_kb_layout(struct text_object *obj, char *p, + unsigned int p_max_size) { (void)obj; char *group = NULL; @@ -1339,7 +1298,8 @@ void print_kb_layout(struct text_object *obj, char *p, unsigned int p_max_size) XFree(group); } -void print_mouse_speed(struct text_object *obj, char *p, unsigned int p_max_size) { +void print_mouse_speed(struct text_object *obj, char *p, + unsigned int p_max_size) { (void)obj; int acc_num = 0; int acc_denom = 0;