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

Fix issues building without BUILD_ARGB flag

Fix half-saved change in display-wayland.cc

Signed-off-by: Tin <tin.svagelj@live.com>
This commit is contained in:
Tin 2023-11-10 13:36:44 +01:00 committed by Brenden Matthews
parent 4936c7492c
commit f6d42c5a69
No known key found for this signature in database
GPG Key ID: 137B7AC2BDFD8DF0
2 changed files with 692 additions and 689 deletions

View File

@ -24,7 +24,7 @@
* *
*/ */
#include <> #include <config.h>
#ifdef BUILD_WAYLAND #ifdef BUILD_WAYLAND
#include <wayland-client.h> #include <wayland-client.h>

View File

@ -93,7 +93,7 @@ xcb_errors_context_t *xcb_errors_ctx;
struct conky_x11_window window; struct conky_x11_window window;
#ifdef BUILD_ARGB #ifdef BUILD_ARGB
bool have_argb_visual; bool have_argb_visual = false;
#endif /* BUILD_ARGB */ #endif /* BUILD_ARGB */
conky::simple_config_setting<std::string> display_name("display", std::string(), conky::simple_config_setting<std::string> display_name("display", std::string(),
@ -495,6 +495,7 @@ static Window find_desktop_window(Window *p_root, Window *p_desktop) {
} }
#ifdef OWN_WINDOW #ifdef OWN_WINDOW
#ifdef BUILD_ARGB
namespace { namespace {
/* helper function for set_transparent_background() */ /* helper function for set_transparent_background() */
void do_set_background(Window win, uint8_t alpha) { void do_set_background(Window win, uint8_t alpha) {
@ -504,6 +505,7 @@ void do_set_background(Window win, uint8_t alpha) {
XSetWindowBackground(display, win, xcolor); XSetWindowBackground(display, win, xcolor);
} }
} // namespace } // namespace
#endif /* BUILD_ARGB */
/* if no argb visual is configured sets background to ParentRelative for the /* if no argb visual is configured sets background to ParentRelative for the
Window and all parents, else real transparency is used */ Window and all parents, else real transparency is used */
@ -514,10 +516,11 @@ void set_transparent_background(Window win) {
do_set_background(win, set_transparent.get(*state) do_set_background(win, set_transparent.get(*state)
? 0 ? 0
: own_window_argb_value.get(*state)); : own_window_argb_value.get(*state));
} else { return;
}
#endif /* BUILD_ARGB */ #endif /* BUILD_ARGB */
// pseudo transparency
// pseudo transparency
if (set_transparent.get(*state)) { if (set_transparent.get(*state)) {
Window parent = win; Window parent = win;
unsigned int i; unsigned int i;
@ -531,14 +534,14 @@ void set_transparent_background(Window win) {
XQueryTree(display, parent, &r, &parent, &children, &n); XQueryTree(display, parent, &r, &parent, &children, &n);
XFree(children); XFree(children);
} }
} else { return;
do_set_background(win, 0);
} }
#ifdef BUILD_ARGB #ifdef BUILD_ARGB
} do_set_background(win, 0);
#endif /* BUILD_ARGB */ #endif /* BUILD_ARGB */
} }
#endif #endif /* OWN_WINDOW */
#ifdef BUILD_ARGB #ifdef BUILD_ARGB
static int get_argb_visual(Visual **visual, int *depth) { static int get_argb_visual(Visual **visual, int *depth) {
@ -593,20 +596,16 @@ void x11_init_window(lua::state &l, bool own) {
return; return;
} }
window.visual = DefaultVisual(display, screen);
window.colourmap = DefaultColormap(display, screen);
depth = CopyFromParent;
visual = CopyFromParent;
#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)) {
have_argb_visual = true; have_argb_visual = true;
window.visual = visual; window.visual = visual;
window.colourmap = XCreateColormap(display, DefaultRootWindow(display), window.colourmap = XCreateColormap(display, DefaultRootWindow(display),
window.visual, AllocNone); window.visual, AllocNone);
} else {
#endif /* BUILD_ARGB */
window.visual = DefaultVisual(display, screen);
window.colourmap = DefaultColormap(display, screen);
depth = CopyFromParent;
visual = CopyFromParent;
#ifdef BUILD_ARGB
have_argb_visual = false;
} }
#endif /* BUILD_ARGB */ #endif /* BUILD_ARGB */
@ -647,14 +646,12 @@ void x11_init_window(lua::state &l, bool own) {
True, True,
0, 0,
0}; 0};
flags |= CWBackPixel;
#ifdef BUILD_ARGB #ifdef BUILD_ARGB
if (have_argb_visual) { if (have_argb_visual) {
attrs.colormap = window.colourmap; attrs.colormap = window.colourmap;
flags &= ~CWBackPixel;
flags |= CWBorderPixel | CWColormap; flags |= CWBorderPixel | CWColormap;
} else {
#endif /* BUILD_ARGB */
flags |= CWBackPixel;
#ifdef BUILD_ARGB
} }
#endif /* BUILD_ARGB */ #endif /* BUILD_ARGB */
@ -693,16 +690,14 @@ void x11_init_window(lua::state &l, bool own) {
XWMHints wmHint; XWMHints wmHint;
Atom xa; Atom xa;
flags |= CWBackPixel;
#ifdef BUILD_ARGB #ifdef BUILD_ARGB
if (have_argb_visual) { if (have_argb_visual) {
attrs.colormap = window.colourmap; attrs.colormap = window.colourmap;
flags &= ~CWBackPixel;
flags |= CWBorderPixel | CWColormap; flags |= CWBorderPixel | CWColormap;
} else { } else {
#endif /* BUILD_ARGB */ #endif /* BUILD_ARGB */
flags |= CWBackPixel;
#ifdef BUILD_ARGB
}
#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 */ /* Parent is root window so WM can take control */
@ -729,7 +724,8 @@ void x11_init_window(lua::state &l, bool own) {
/* allow only decorated windows to be given mouse input */ /* allow only decorated windows to be given mouse input */
int major_version; int major_version;
int minor_version; int minor_version;
if (XShapeQueryVersion(display, &major_version, &minor_version) == 0) { if (XShapeQueryVersion(display, &major_version, &minor_version) ==
0) {
NORM_ERR("Input shapes are not supported"); NORM_ERR("Input shapes are not supported");
} else { } else {
if (own_window.get(*state) && if (own_window.get(*state) &&
@ -916,8 +912,8 @@ void x11_init_window(lua::state &l, bool own) {
fflush(stderr); fflush(stderr);
XMapWindow(display, window.window); XMapWindow(display, window.window);
}
} else else
#endif /* OWN_WINDOW */ #endif /* OWN_WINDOW */
{ {
XWindowAttributes attrs; XWindowAttributes attrs;
@ -997,9 +993,9 @@ void x11_init_window(lua::state &l, bool own) {
window_created = 1; window_created = 1;
DBGP("leave x11_init_window()"); DBGP("leave x11_init_window()");
} }
static Window find_subwindow(Window win, int w, int h) { static Window find_subwindow(Window win, int w, int h) {
unsigned int i, j; unsigned int i, j;
Window troot, parent, *children; Window troot, parent, *children;
unsigned int n; unsigned int n;
@ -1016,7 +1012,8 @@ static Window find_subwindow(Window win, int w, int h) {
/* Window must be mapped and same size as display or /* Window must be mapped and same size as display or
* work space */ * work space */
if (attrs.map_state != 0 && if (attrs.map_state != 0 &&
((attrs.width == display_width && attrs.height == display_height) || ((attrs.width == display_width &&
attrs.height == display_height) ||
(attrs.width == w && attrs.height == h))) { (attrs.width == w && attrs.height == h))) {
win = children[j]; win = children[j];
break; break;
@ -1029,19 +1026,19 @@ static Window find_subwindow(Window win, int w, int h) {
} }
return win; return win;
} }
void create_gc() { void create_gc() {
XGCValues values; XGCValues values;
values.graphics_exposures = 0; values.graphics_exposures = 0;
values.function = GXcopy; values.function = GXcopy;
window.gc = XCreateGC(display, window.drawable, window.gc = XCreateGC(display, window.drawable,
GCFunction | GCGraphicsExposures, &values); GCFunction | GCGraphicsExposures, &values);
} }
// Get current desktop number // Get current desktop number
static inline void get_x11_desktop_current(Display *current_display, static inline void get_x11_desktop_current(Display * current_display,
Window root, Atom atom) { Window root, Atom atom) {
Atom actual_type; Atom actual_type;
int actual_format; int actual_format;
@ -1055,15 +1052,16 @@ static inline void get_x11_desktop_current(Display *current_display,
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,
&bytes_after, &prop) == Success) && &bytes_after, &prop) == Success) &&
(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) { XFree(prop); } if (prop != nullptr) { XFree(prop); }
} }
// Get total number of available desktops // Get total number of available desktops
static inline void get_x11_desktop_number(Display *current_display, Window root, static inline void get_x11_desktop_number(Display * current_display,
Atom atom) { Window root, Atom atom) {
Atom actual_type; Atom actual_type;
int actual_format; int actual_format;
unsigned long nitems; unsigned long nitems;
@ -1076,15 +1074,16 @@ static inline void get_x11_desktop_number(Display *current_display, Window root,
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,
&bytes_after, &prop) == Success) && &bytes_after, &prop) == Success) &&
(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) { XFree(prop); } if (prop != nullptr) { XFree(prop); }
} }
// Get all desktop names // Get all desktop names
static inline void get_x11_desktop_names(Display *current_display, Window root, static inline void get_x11_desktop_names(Display * current_display,
Atom atom) { Window root, Atom atom) {
Atom actual_type; Atom actual_type;
int actual_format; int actual_format;
unsigned long nitems; unsigned long nitems;
@ -1103,10 +1102,10 @@ static inline void get_x11_desktop_names(Display *current_display, Window root,
reinterpret_cast<const char *>(prop), nitems); reinterpret_cast<const char *>(prop), nitems);
} }
if (prop != nullptr) { XFree(prop); } if (prop != nullptr) { XFree(prop); }
} }
// Get current desktop name // Get current desktop name
static inline void get_x11_desktop_current_name(const std::string &names) { static inline void get_x11_desktop_current_name(const std::string &names) {
struct information *current_info = &info; struct information *current_info = &info;
unsigned int i = 0, j = 0; unsigned int i = 0, j = 0;
int k = 0; int k = 0;
@ -1120,9 +1119,9 @@ static inline void get_x11_desktop_current_name(const std::string &names) {
j = i; j = i;
} }
} }
} }
void get_x11_desktop_info(Display *current_display, Atom atom) { void get_x11_desktop_info(Display * current_display, Atom atom) {
Window root; Window root;
static Atom atom_current, atom_number, atom_names; static Atom atom_current, atom_number, atom_names;
struct information *current_info = &info; struct information *current_info = &info;
@ -1133,7 +1132,8 @@ void get_x11_desktop_info(Display *current_display, Atom atom) {
/* Check if we initialise else retrieve changed property */ /* Check if we initialise else retrieve changed property */
if (atom == 0) { if (atom == 0) {
atom_current = XInternAtom(current_display, "_NET_CURRENT_DESKTOP", True); atom_current = XInternAtom(current_display, "_NET_CURRENT_DESKTOP", True);
atom_number = XInternAtom(current_display, "_NET_NUMBER_OF_DESKTOPS", True); atom_number =
XInternAtom(current_display, "_NET_NUMBER_OF_DESKTOPS", True);
atom_names = XInternAtom(current_display, "_NET_DESKTOP_NAMES", True); atom_names = XInternAtom(current_display, "_NET_DESKTOP_NAMES", True);
get_x11_desktop_current(current_display, root, atom_current); get_x11_desktop_current(current_display, root, atom_current);
get_x11_desktop_number(current_display, root, atom_number); get_x11_desktop_number(current_display, root, atom_number);
@ -1160,11 +1160,12 @@ void get_x11_desktop_info(Display *current_display, Atom atom) {
get_x11_desktop_current_name(current_info->x11.desktop.all_names); get_x11_desktop_current_name(current_info->x11.desktop.all_names);
} }
} }
} }
static const char NOT_IN_X[] = "Not running in X"; static const char NOT_IN_X[] = "Not running in X";
void print_monitor(struct text_object *obj, char *p, unsigned int p_max_size) { void print_monitor(struct text_object * obj, char *p,
unsigned int p_max_size) {
(void)obj; (void)obj;
if (!out_to_x.get(*state)) { if (!out_to_x.get(*state)) {
@ -1172,9 +1173,9 @@ void print_monitor(struct text_object *obj, char *p, unsigned int p_max_size) {
return; return;
} }
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, void print_monitor_number(struct text_object * obj, char *p,
unsigned int p_max_size) { unsigned int p_max_size) {
(void)obj; (void)obj;
@ -1183,9 +1184,10 @@ void print_monitor_number(struct text_object *obj, char *p,
return; return;
} }
snprintf(p, p_max_size, "%d", XScreenCount(display)); snprintf(p, p_max_size, "%d", XScreenCount(display));
} }
void print_desktop(struct text_object *obj, char *p, unsigned int p_max_size) { void print_desktop(struct text_object * obj, char *p,
unsigned int p_max_size) {
(void)obj; (void)obj;
if (!out_to_x.get(*state)) { if (!out_to_x.get(*state)) {
@ -1193,9 +1195,9 @@ void print_desktop(struct text_object *obj, char *p, unsigned int p_max_size) {
return; return;
} }
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, void print_desktop_number(struct text_object * obj, char *p,
unsigned int p_max_size) { unsigned int p_max_size) {
(void)obj; (void)obj;
@ -1204,9 +1206,9 @@ void print_desktop_number(struct text_object *obj, char *p,
return; return;
} }
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, void print_desktop_name(struct text_object * obj, char *p,
unsigned int p_max_size) { unsigned int p_max_size) {
(void)obj; (void)obj;
@ -1215,11 +1217,11 @@ void print_desktop_name(struct text_object *obj, char *p,
} else { } else {
strncpy(p, info.x11.desktop.name.c_str(), p_max_size); strncpy(p, info.x11.desktop.name.c_str(), p_max_size);
} }
} }
#ifdef OWN_WINDOW #ifdef OWN_WINDOW
/* reserve window manager space */ /* reserve window manager space */
void set_struts(int sidenum) { void set_struts(int sidenum) {
Atom strut; Atom strut;
if ((strut = ATOM(_NET_WM_STRUT)) != None) { if ((strut = ATOM(_NET_WM_STRUT)) != None) {
/* reserve space at left, right, top, bottom */ /* reserve space at left, right, top, bottom */
@ -1269,8 +1271,8 @@ void set_struts(int sidenum) {
} }
XChangeProperty(display, window.window, strut, XA_CARDINAL, 32, XChangeProperty(display, window.window, strut, XA_CARDINAL, 32,
PropModeReplace, reinterpret_cast<unsigned char *>(&sizes), PropModeReplace,
4); reinterpret_cast<unsigned char *>(&sizes), 4);
if ((strut = ATOM(_NET_WM_STRUT_PARTIAL)) != None) { if ((strut = ATOM(_NET_WM_STRUT_PARTIAL)) != None) {
XChangeProperty(display, window.window, strut, XA_CARDINAL, 32, XChangeProperty(display, window.window, strut, XA_CARDINAL, 32,
@ -1278,11 +1280,11 @@ void set_struts(int sidenum) {
reinterpret_cast<unsigned char *>(&sizes), 12); reinterpret_cast<unsigned char *>(&sizes), 12);
} }
} }
} }
#endif /* OWN_WINDOW */ #endif /* OWN_WINDOW */
#ifdef BUILD_XDBE #ifdef BUILD_XDBE
void xdbe_swap_buffers() { void xdbe_swap_buffers() {
if (use_xdbe.get(*state)) { if (use_xdbe.get(*state)) {
XdbeSwapInfo swap; XdbeSwapInfo swap;
@ -1290,7 +1292,7 @@ void xdbe_swap_buffers() {
swap.swap_action = XdbeBackground; swap.swap_action = XdbeBackground;
XdbeSwapBuffers(display, &swap, 1); XdbeSwapBuffers(display, &swap, 1);
} }
} }
#else #else
void xpmdb_swap_buffers(void) { void xpmdb_swap_buffers(void) {
if (use_xpmdb.get(*state)) { if (use_xpmdb.get(*state)) {
@ -1304,30 +1306,30 @@ void xpmdb_swap_buffers(void) {
} }
#endif /* BUILD_XDBE */ #endif /* BUILD_XDBE */
void print_kdb_led(const int keybit, char *p, unsigned int p_max_size) { void print_kdb_led(const int keybit, char *p, unsigned int p_max_size) {
XKeyboardState x; XKeyboardState x;
XGetKeyboardControl(display, &x); XGetKeyboardControl(display, &x);
snprintf(p, p_max_size, "%s", (x.led_mask & keybit ? "On" : "Off")); snprintf(p, p_max_size, "%s", (x.led_mask & keybit ? "On" : "Off"));
} }
void print_key_caps_lock(struct text_object *obj, char *p, void print_key_caps_lock(struct text_object * obj, char *p,
unsigned int p_max_size) { unsigned int p_max_size) {
(void)obj; (void)obj;
print_kdb_led(1, p, p_max_size); print_kdb_led(1, p, p_max_size);
} }
void print_key_num_lock(struct text_object *obj, char *p, void print_key_num_lock(struct text_object * obj, char *p,
unsigned int p_max_size) { unsigned int p_max_size) {
(void)obj; (void)obj;
print_kdb_led(2, p, p_max_size); print_kdb_led(2, p, p_max_size);
} }
void print_key_scroll_lock(struct text_object *obj, char *p, void print_key_scroll_lock(struct text_object * obj, char *p,
unsigned int p_max_size) { unsigned int p_max_size) {
(void)obj; (void)obj;
print_kdb_led(4, p, p_max_size); print_kdb_led(4, p, p_max_size);
} }
void print_keyboard_layout(struct text_object *obj, char *p, void print_keyboard_layout(struct text_object * obj, char *p,
unsigned int p_max_size) { unsigned int p_max_size) {
(void)obj; (void)obj;
@ -1342,9 +1344,9 @@ void print_keyboard_layout(struct text_object *obj, char *p,
snprintf(p, p_max_size, "%s", (group != NULL ? group : "unknown")); snprintf(p, p_max_size, "%s", (group != NULL ? group : "unknown"));
XFree(group); XFree(group);
XkbFreeKeyboard(desc, XkbGBN_AllComponentsMask, True); XkbFreeKeyboard(desc, XkbGBN_AllComponentsMask, True);
} }
void print_mouse_speed(struct text_object *obj, char *p, void print_mouse_speed(struct text_object * obj, char *p,
unsigned int p_max_size) { unsigned int p_max_size) {
(void)obj; (void)obj;
int acc_num = 0; int acc_num = 0;
@ -1353,19 +1355,20 @@ void print_mouse_speed(struct text_object *obj, char *p,
XGetPointerControl(display, &acc_num, &acc_denom, &threshold); XGetPointerControl(display, &acc_num, &acc_denom, &threshold);
snprintf(p, p_max_size, "%d%%", (110 - threshold)); snprintf(p, p_max_size, "%d%%", (110 - threshold));
} }
InputEvent *xev_as_input_event(XEvent &ev) { InputEvent *xev_as_input_event(XEvent & ev) {
if (ev.type == KeyPress || ev.type == KeyRelease || ev.type == ButtonPress || if (ev.type == KeyPress || ev.type == KeyRelease ||
ev.type == ButtonRelease || ev.type == MotionNotify || ev.type == ButtonPress || ev.type == ButtonRelease ||
ev.type == EnterNotify || ev.type == LeaveNotify) { ev.type == MotionNotify || ev.type == EnterNotify ||
ev.type == LeaveNotify) {
return reinterpret_cast<InputEvent *>(&ev); return reinterpret_cast<InputEvent *>(&ev);
} else { } else {
return nullptr; return nullptr;
} }
} }
void propagate_x11_event(XEvent &ev) { void propagate_x11_event(XEvent & ev) {
InputEvent *i_ev = xev_as_input_event(ev); InputEvent *i_ev = xev_as_input_event(ev);
/* forward the event to the desktop window */ /* forward the event to the desktop window */
if (i_ev != nullptr) { if (i_ev != nullptr) {
@ -1383,12 +1386,12 @@ void propagate_x11_event(XEvent &ev) {
if (i_ev != nullptr) { time = i_ev->common.time; } if (i_ev != nullptr) { time = i_ev->common.time; }
XSetInputFocus(display, window.desktop, RevertToPointerRoot, time); XSetInputFocus(display, window.desktop, RevertToPointerRoot, time);
} }
} }
#ifdef BUILD_MOUSE_EVENTS #ifdef BUILD_MOUSE_EVENTS
// Assuming parent has a simple linear stack of descendants, this function // Assuming parent has a simple linear stack of descendants, this function
// returns the last leaf on the graph. // returns the last leaf on the graph.
inline Window last_descendant(Display *display, Window parent) { inline Window last_descendant(Display * display, Window parent) {
Window _ignored, *children; Window _ignored, *children;
uint32_t count; uint32_t count;
@ -1402,9 +1405,9 @@ inline Window last_descendant(Display *display, Window parent) {
} }
return current; return current;
} }
Window query_x11_window_at_pos(Display *display, int x, int y) { Window query_x11_window_at_pos(Display * display, int x, int y) {
Window root = DefaultRootWindow(display); Window root = DefaultRootWindow(display);
// these values are ignored but NULL can't be passed // these values are ignored but NULL can't be passed
@ -1416,10 +1419,10 @@ Window query_x11_window_at_pos(Display *display, int x, int y) {
XQueryPointer(display, window.root, &root_return, &last, &root_x_return, XQueryPointer(display, window.root, &root_return, &last, &root_x_return,
&root_y_return, &win_x_return, &win_y_return, &mask_return); &root_y_return, &win_x_return, &win_y_return, &mask_return);
// X11 correctly returns a window which covers conky area, but returned window // X11 correctly returns a window which covers conky area, but returned
// is not window.window, but instead a parent node in some cases and the // window is not window.window, but instead a parent node in some cases and
// window.window we want to check for is a 1x1 child of that window. // the window.window we want to check for is a 1x1 child of that window.
return last_descendant(display, last); return last_descendant(display, last);
} }
#endif /* BUILD_MOUSE_EVENTS */ #endif /* BUILD_MOUSE_EVENTS */