1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 18:45:10 +00:00

Switch from macros to functions.

This commit is contained in:
Brenden Matthews 2018-08-08 15:18:14 -04:00
parent 693ad0bafc
commit 8a4b707a7c

View File

@ -32,12 +32,12 @@
#include "conky.h" #include "conky.h"
#include "logging.h" #include "logging.h"
#include "x11.h" #include <X11/XKBlib.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xmd.h> #include <X11/Xmd.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/XKBlib.h> #include "x11.h"
#ifdef BUILD_IMLIB2 #ifdef BUILD_IMLIB2
#include "imlib2.h" #include "imlib2.h"
#endif /* BUILD_IMLIB2 */ #endif /* BUILD_IMLIB2 */
@ -83,9 +83,7 @@ void out_to_x_setting::lua_setter(lua::state &l, bool init) {
Base::lua_setter(l, init); Base::lua_setter(l, init);
if (init && do_convert(l, -1).first) { if (init && do_convert(l, -1).first) { init_X11(); }
init_X11();
}
++s; ++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) { void out_to_x_setting::cleanup(lua::state &l) {
lua::stack_sentry s(l, -1); lua::stack_sentry s(l, -1);
if (do_convert(l, -1).first) { if (do_convert(l, -1).first) { deinit_X11(); }
deinit_X11();
}
l.pop(); l.pop();
} }
@ -130,9 +126,7 @@ void own_window_setting::lua_setter(lua::state &l, bool init) {
#ifdef BUILD_XDBE #ifdef BUILD_XDBE
bool use_xdbe_setting::set_up(lua::state &l) { bool use_xdbe_setting::set_up(lua::state &l) {
// double_buffer makes no sense when not drawing to X // double_buffer makes no sense when not drawing to X
if (not out_to_x.get(l)) { if (not out_to_x.get(l)) { return false; }
return false;
}
int major, minor; int major, minor;
@ -266,7 +260,6 @@ conky::lua_traits<window_hints>::Map conky::lua_traits<window_hints>::map = {
std::pair<uint16_t, bool> window_hints_traits::convert( std::pair<uint16_t, bool> window_hints_traits::convert(
lua::state &l, int index, const std::string &name) { lua::state &l, int index, const std::string &name) {
lua::stack_sentry s(l); lua::stack_sentry s(l);
l.checkstack(1); l.checkstack(1);
@ -280,9 +273,7 @@ std::pair<uint16_t, bool> window_hints_traits::convert(
if (newpos > pos) { if (newpos > pos) {
l.pushstring(hints.substr(pos, newpos - pos)); l.pushstring(hints.substr(pos, newpos - pos));
auto t = conky::lua_traits<window_hints>::convert(l, -1, name); auto t = conky::lua_traits<window_hints>::convert(l, -1, name);
if (not t.second) { if (not t.second) { return {0, false}; };
return {0, false};
};
SET_HINT(ret, t.first); SET_HINT(ret, t.first);
l.pop(); l.pop();
} }
@ -454,7 +445,8 @@ static void update_workarea() {
XineramaScreenInfo *si = XineramaQueryScreens(display, &heads); XineramaScreenInfo *si = XineramaQueryScreens(display, &heads);
if (si == nullptr) { if (si == nullptr) {
NORM_ERR( NORM_ERR(
"warning: XineramaQueryScreen returned nullptr, ignoring head settings"); "warning: XineramaQueryScreen returned nullptr, ignoring head "
"settings");
return; /* queryscreens failed? */ return; /* queryscreens failed? */
} }
@ -490,9 +482,7 @@ static Window find_desktop_window(Window *p_root, Window *p_desktop) {
Window troot, parent, *children; Window troot, parent, *children;
unsigned char *buf = nullptr; unsigned char *buf = nullptr;
if ((p_root == nullptr) || (p_desktop == nullptr)) { if ((p_root == nullptr) || (p_desktop == nullptr)) { return 0; }
return 0;
}
/* some window managers set __SWM_VROOT to some child of root window */ /* 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() { void destroy_window() {
#ifdef BUILD_XFT #ifdef BUILD_XFT
if (window.xftdraw != nullptr) { if (window.xftdraw != nullptr) { XftDrawDestroy(window.xftdraw); }
XftDrawDestroy(window.xftdraw);
}
#endif /* BUILD_XFT */ #endif /* BUILD_XFT */
if (window.gc != nullptr) { if (window.gc != nullptr) { XFreeGC(display, window.gc); }
XFreeGC(display, window.gc);
}
memset(&window, 0, sizeof(struct conky_window)); 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; int depth = 0, flags = CWOverrideRedirect | CWBackingStore;
Visual *visual = nullptr; Visual *visual = nullptr;
if (find_desktop_window(&window.root, &window.desktop) == 0u) { if (find_desktop_window(&window.root, &window.desktop) == 0u) { return; }
return;
}
#ifdef BUILD_ARGB #ifdef BUILD_ARGB
if (use_argb_visual.get(l) && (get_argb_visual(&visual, &depth) != 0)) { 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); border_outer_margin.get(l);
/* Sanity check to avoid making an invalid 0x0 window */ /* Sanity check to avoid making an invalid 0x0 window */
if (b == 0) { if (b == 0) { b = 1; }
b = 1;
}
if (own_window_type.get(l) == TYPE_OVERRIDE) { if (own_window_type.get(l) == TYPE_OVERRIDE) {
/* An override_redirect True window. /* An override_redirect True window.
@ -749,9 +731,7 @@ static void init_window(lua::state &l __attribute__((unused)), bool own) {
} }
#endif /* BUILD_ARGB */ #endif /* BUILD_ARGB */
if (own_window_type.get(l) == TYPE_DOCK) { if (own_window_type.get(l) == TYPE_DOCK) { window.x = window.y = 0; }
window.x = window.y = 0;
}
/* Parent is root window so WM can take control */ /* Parent is root window so WM can take control */
window.window = window.window =
XCreateWindow(display, window.root, window.x, window.y, b, b, 0, 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); XFree(children);
if (j == n) { if (j == n) { break; }
break;
}
} }
return win; return win;
@ -1029,9 +1007,7 @@ static inline void get_x11_desktop_current(Display *current_display,
unsigned char *prop = nullptr; unsigned char *prop = nullptr;
struct information *current_info = &info; struct information *current_info = &info;
if (atom == None) { if (atom == None) { return; }
return;
}
if ((XGetWindowProperty(current_display, root, atom, 0, 1L, False, if ((XGetWindowProperty(current_display, root, atom, 0, 1L, False,
XA_CARDINAL, &actual_type, &actual_format, &nitems, 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)) { (actual_type == XA_CARDINAL) && (nitems == 1L) && (actual_format == 32)) {
current_info->x11.desktop.current = prop[0] + 1; current_info->x11.desktop.current = prop[0] + 1;
} }
if (prop != nullptr) { if (prop != nullptr) { XFree(prop); }
XFree(prop);
}
} }
// Get total number of available desktops // 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; unsigned char *prop = nullptr;
struct information *current_info = &info; struct information *current_info = &info;
if (atom == None) { if (atom == None) { return; }
return;
}
if ((XGetWindowProperty(current_display, root, atom, 0, 1L, False, if ((XGetWindowProperty(current_display, root, atom, 0, 1L, False,
XA_CARDINAL, &actual_type, &actual_format, &nitems, 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)) { (actual_type == XA_CARDINAL) && (nitems == 1L) && (actual_format == 32)) {
current_info->x11.desktop.number = prop[0]; current_info->x11.desktop.number = prop[0];
} }
if (prop != nullptr) { if (prop != nullptr) { XFree(prop); }
XFree(prop);
}
} }
// Get all desktop names // Get all desktop names
@ -1079,9 +1049,7 @@ static inline void get_x11_desktop_names(Display *current_display, Window root,
unsigned char *prop = nullptr; unsigned char *prop = nullptr;
struct information *current_info = &info; struct information *current_info = &info;
if (atom == None) { if (atom == None) { return; }
return;
}
if ((XGetWindowProperty(current_display, root, atom, 0, (~0L), False, if ((XGetWindowProperty(current_display, root, atom, 0, (~0L), False,
ATOM(UTF8_STRING), &actual_type, &actual_format, 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( current_info->x11.desktop.all_names.assign(
reinterpret_cast<const char *>(prop), nitems); reinterpret_cast<const char *>(prop), nitems);
} }
if (prop != nullptr) { if (prop != nullptr) { XFree(prop); }
XFree(prop);
}
} }
// Get current desktop name // 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)); 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; (void)obj;
if (not out_to_x.get(*state)) { 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); 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; (void)obj;
if (not out_to_x.get(*state)) { 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); 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; (void)obj;
if (not out_to_x.get(*state)) { if (not out_to_x.get(*state)) {
@ -1249,13 +1218,9 @@ void set_struts(int sidenum) {
sizes[i] = 0; sizes[i] = 0;
} else { } else {
if (i <= 1 || i >= 8) { if (i <= 1 || i >= 8) {
if (sizes[i] > display_width) { if (sizes[i] > display_width) { sizes[i] = display_width; }
sizes[i] = display_width;
}
} else { } else {
if (sizes[i] > display_height) { if (sizes[i] > display_height) { sizes[i] = display_height; }
sizes[i] = display_height;
}
} }
} }
} }
@ -1296,35 +1261,29 @@ void xpmdb_swap_buffers(void) {
} }
#endif /* BUILD_XDBE */ #endif /* BUILD_XDBE */
#define LOCK_TEMPLATE_1(func) \ void print_kdb_led(const int keybit, char *p, unsigned int p_max_size) {
void print_##func(struct text_object *obj, char *p, unsigned int p_max_size) { \ XKeyboardState x;
(void)obj; \ XGetKeyboardControl(display, &x);
XKeyboardState x; \ snprintf(p, p_max_size, "%s", (x.led_mask & keybit ? "On" : "Off"));
XGetKeyboardControl(display, &x); \ }
snprintf(p, p_max_size, "%s", (x.led_mask & 1 ? "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_num_led(struct text_object *obj, char *p, unsigned int p_max_size) {
void print_##func(struct text_object *obj, char *p, unsigned int p_max_size) { \ (void)obj;
(void)obj; \ print_kdb_led(2, p, p_max_size);
XKeyboardState x; \
XGetKeyboardControl(display, &x); \
snprintf(p, p_max_size, "%s", (x.led_mask & 2 ? "On" : "Off")); \
} }
#define LOCK_TEMPLATE_4(func) \ void print_scroll_led(struct text_object *obj, char *p,
void print_##func(struct text_object *obj, char *p, unsigned int p_max_size) { \ unsigned int p_max_size) {
(void)obj; \ (void)obj;
XKeyboardState x; \ print_kdb_led(4, p, p_max_size);
XGetKeyboardControl(display, &x); \
snprintf(p, p_max_size, "%s", (x.led_mask & 4 ? "On" : "Off")); \
} }
LOCK_TEMPLATE_2(num_led) void print_kb_layout(struct text_object *obj, char *p,
LOCK_TEMPLATE_1(caps_led) unsigned int p_max_size) {
LOCK_TEMPLATE_4(scroll_led)
void print_kb_layout(struct text_object *obj, char *p, unsigned int p_max_size) {
(void)obj; (void)obj;
char *group = NULL; char *group = NULL;
@ -1339,7 +1298,8 @@ void print_kb_layout(struct text_object *obj, char *p, unsigned int p_max_size)
XFree(group); 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; (void)obj;
int acc_num = 0; int acc_num = 0;
int acc_denom = 0; int acc_denom = 0;