1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-26 04:17:33 +00:00

Fix (some) wayland/x11 init ordering issues.

This commit is contained in:
Brenden Matthews 2022-12-26 01:39:08 +00:00 committed by Brenden Matthews
parent 64b001f2f8
commit c48df06359
9 changed files with 108 additions and 50 deletions

View File

@ -228,11 +228,6 @@ if(BUILD_PORT_MONITORS)
set(optional_sources ${optional_sources} ${port_monitors}) set(optional_sources ${optional_sources} ${port_monitors})
endif(BUILD_PORT_MONITORS) endif(BUILD_PORT_MONITORS)
if(BUILD_GUI)
set(gui fonts.cc fonts.h gui.cc gui.h)
set(optional_sources ${optional_sources} ${gui})
endif(BUILD_GUI)
if(BUILD_X11) if(BUILD_X11)
set(x11 x11.cc x11.h) set(x11 x11.cc x11.h)
set(optional_sources ${optional_sources} ${x11}) set(optional_sources ${optional_sources} ${x11})
@ -243,6 +238,11 @@ if(BUILD_X11)
endif(BUILD_XINERAMA) endif(BUILD_XINERAMA)
endif(BUILD_X11) endif(BUILD_X11)
if(BUILD_GUI)
set(gui fonts.cc fonts.h gui.cc gui.h)
set(optional_sources ${optional_sources} ${gui})
endif(BUILD_GUI)
if(BUILD_WAYLAND) if(BUILD_WAYLAND)
set(wl_srcs wl.cc wl.h xdg-shell-protocol.c wlr-layer-shell-protocol.c x11-color.cc x11-color.h) set(wl_srcs wl.cc wl.h xdg-shell-protocol.c wlr-layer-shell-protocol.c x11-color.cc x11-color.h)
set(optional_sources ${optional_sources} ${wl_srcs}) set(optional_sources ${optional_sources} ${wl_srcs})

View File

@ -62,7 +62,6 @@
#pragma GCC diagnostic ignored "-Wvariadic-macros" #pragma GCC diagnostic ignored "-Wvariadic-macros"
#include <X11/Xutil.h> #include <X11/Xutil.h>
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#include "x11.h"
#ifdef BUILD_XDAMAGE #ifdef BUILD_XDAMAGE
#include <X11/extensions/Xdamage.h> #include <X11/extensions/Xdamage.h>
#endif #endif
@ -94,7 +93,7 @@
#ifdef BUILD_GUI #ifdef BUILD_GUI
#include "fonts.h" #include "fonts.h"
#include "gui.h" #include "gui.h"
#endif #endif /* BUILD_GUI */
#include "fs.h" #include "fs.h"
#ifdef BUILD_ICONV #ifdef BUILD_ICONV
#include "iconv_tools.h" #include "iconv_tools.h"

View File

@ -86,16 +86,16 @@ void load_fonts(bool utf8) {
} }
int font_height() { int font_height() {
// assert(selected_font < fonts.size()); assert(selected_font < fonts.size());
return display_output()->font_height(selected_font); return display_output()->font_height(selected_font);
} }
int font_ascent() { int font_ascent() {
// assert(selected_font < fonts.size()); assert(selected_font < fonts.size());
return display_output()->font_ascent(selected_font); return display_output()->font_ascent(selected_font);
} }
int font_descent() { int font_descent() {
// assert(selected_font < fonts.size()); assert(selected_font < fonts.size());
return display_output()->font_descent(selected_font); return display_output()->font_descent(selected_font);
} }

View File

@ -191,17 +191,16 @@ std::string gethostnamecxx() {
* The order of these settings cannot be completely arbitrary. Some of them * The order of these settings cannot be completely arbitrary. Some of them
* depend on others, and the setters are called in the order in which they are * depend on others, and the setters are called in the order in which they are
* defined. The order should be: x11_display_name -> out_to_x -> everything * defined. The order should be: x11_display_name -> out_to_x -> everything
* colour related * colour related -> border_*, own_window_*, etc -> own_window -> double_buffer
* -> border_*, own_window_*, etc -> own_window -> * -> imlib_cache_size.
* double_buffer -> imlib_cache_size *
* The settings order can be modified with the settings_ordering vector in
* setting.cc.
*/ */
conky::simple_config_setting<alignment> text_alignment("alignment", BOTTOM_LEFT, conky::simple_config_setting<alignment> text_alignment("alignment", BOTTOM_LEFT,
false); false);
conky::simple_config_setting<std::string> display_name("display", std::string(),
false);
priv::colour_setting color[10] = {{"color0", 0xffffff}, {"color1", 0xffffff}, priv::colour_setting color[10] = {{"color0", 0xffffff}, {"color1", 0xffffff},
{"color2", 0xffffff}, {"color3", 0xffffff}, {"color2", 0xffffff}, {"color3", 0xffffff},
{"color4", 0xffffff}, {"color5", 0xffffff}, {"color4", 0xffffff}, {"color5", 0xffffff},

View File

@ -124,7 +124,6 @@ class colour_setting
}; };
} // namespace priv } // namespace priv
extern conky::simple_config_setting<std::string> display_name;
extern conky::simple_config_setting<int> head_index; extern conky::simple_config_setting<int> head_index;
extern priv::colour_setting color[10]; extern priv::colour_setting color[10];
extern priv::colour_setting default_color; extern priv::colour_setting default_color;

View File

@ -66,13 +66,73 @@ priv::config_setting_base *get_setting(lua::state &l, int index) {
return iter->second; return iter->second;
} }
const std::vector<std::string> settings_ordering{
"display",
"out_to_x",
"use_xft",
"font",
"font0",
"font1",
"font2",
"font3",
"font4",
"font5",
"font6",
"font7",
"font8",
"font9",
"color0",
"color1",
"color2",
"color3",
"color4",
"color5",
"color6",
"color7",
"color8",
"color9",
"default_color",
"default_shade_color",
"default_outline_color",
"border_inner_margin",
"border_outer_margin",
"border_width",
"alignment",
"own_window_transparent",
"own_window_class",
"own_window_title",
"own_window_type",
"own_window_hints",
"own_window_argb_value",
"own_window_argb_visual",
"own_window_colour",
"own_window",
"double_buffer",
"out_to_wayland",
"imlib_cache_size",
};
// returns a vector of all settings, sorted in order of registration // returns a vector of all settings, sorted in order of registration
settings_vector make_settings_vector() { settings_vector make_settings_vector() {
settings_vector ret; settings_vector ret;
ret.reserve(settings->size()); ret.reserve(settings->size());
for (auto &setting : *settings) { ret.push_back(setting.second); } // for _some_ settings, the order matters, for others it does not. first we
sort(ret.begin(), ret.end(), &priv::config_setting_base::seq_compare); // fill the vec with the settings which are ordered, then we add the remainder
// in.
for (auto &name : settings_ordering) {
auto setting = settings->at(name);
ret.push_back(setting);
}
for (auto &setting : *settings) {
if (std::find(settings_ordering.begin(), settings_ordering.end(),
setting.second->name) == settings_ordering.end()) {
ret.push_back(setting.second);
}
}
auto start = ret.begin();
std::advance(start, settings_ordering.size());
sort(start, ret.end(), &priv::config_setting_base::seq_compare);
return ret; return ret;
} }
@ -252,6 +312,4 @@ void cleanup_config_settings(lua::state &l) {
l.pop(); l.pop();
} }
/////////// example settings, remove after real settings are available ///////
range_config_setting<int> asdf("asdf", 42, 47, 45, true);
} // namespace conky } // namespace conky

View File

@ -359,8 +359,6 @@ class range_config_setting : public simple_config_setting<T, Traits> {
} }
}; };
/////////// example settings, remove after real settings are available ///////
extern range_config_setting<int> asdf;
} // namespace conky } // namespace conky
#endif /* SETTING_HH */ #endif /* SETTING_HH */

View File

@ -64,12 +64,15 @@ Display *display = nullptr;
/* Window stuff */ /* Window stuff */
struct conky_x11_window window; struct conky_x11_window window;
conky::simple_config_setting<std::string> display_name("display", std::string(),
false);
/* local prototypes */ /* local prototypes */
static void update_workarea(); static void update_workarea();
static Window find_desktop_window(Window *p_root, Window *p_desktop); static Window find_desktop_window(Window *p_root, Window *p_desktop);
static Window find_subwindow(Window win, int w, int h); static Window find_subwindow(Window win, int w, int h);
static void init_X11(); static void init_x11();
static void deinit_X11(); static void deinit_x11();
/********************* <SETTINGS> ************************/ /********************* <SETTINGS> ************************/
namespace priv { namespace priv {
@ -78,7 +81,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) { init_X11(); } if (init && do_convert(l, -1).first) { init_x11(); }
++s; ++s;
} }
@ -86,7 +89,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) { deinit_X11(); } if (do_convert(l, -1).first) { deinit_x11(); }
l.pop(); l.pop();
} }
@ -94,7 +97,10 @@ void out_to_x_setting::cleanup(lua::state &l) {
#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 (!out_to_x.get(l) || !display || !window.window) { return false; } if (!out_to_x.get(l) || !display || !window.window) {
DBGP("can't enable xdbe");
return false;
}
int major, minor; int major, minor;
@ -222,8 +228,8 @@ static int __attribute__((noreturn)) x11_ioerror_handler(Display *d) {
} }
/* X11 initializer */ /* X11 initializer */
static void init_X11() { static void init_x11() {
DBGP("enter init_X11()"); DBGP("enter init_x11()");
if (display == nullptr) { if (display == nullptr) {
const std::string &dispstr = display_name.get(*state); const std::string &dispstr = display_name.get(*state);
// passing nullptr to XOpenDisplay should open the default display // passing nullptr to XOpenDisplay should open the default display
@ -233,12 +239,7 @@ static void init_X11() {
if ((display = XOpenDisplay(disp)) == nullptr) { if ((display = XOpenDisplay(disp)) == nullptr) {
std::string err = std::string err =
std::string("can't open display: ") + XDisplayName(disp); std::string("can't open display: ") + XDisplayName(disp);
#ifdef BUILD_WAYLAND
fprintf(stderr, "%s\n", err.c_str());
return;
#else
throw std::runtime_error(err); throw std::runtime_error(err);
#endif
} }
} }
@ -261,12 +262,12 @@ static void init_X11() {
XSetErrorHandler(&x11_error_handler); XSetErrorHandler(&x11_error_handler);
XSetIOErrorHandler(&x11_ioerror_handler); XSetIOErrorHandler(&x11_ioerror_handler);
DBGP("leave init_X11()"); DBGP("leave init_x11()");
} }
static void deinit_X11() { static void deinit_x11() {
if (display) { if (display) {
DBGP("deinit_X11()"); DBGP("deinit_x11()");
XCloseDisplay(display); XCloseDisplay(display);
display = nullptr; display = nullptr;
} }
@ -457,9 +458,11 @@ static int get_argb_visual(Visual **visual, int *depth) {
return 1; return 1;
} }
} }
// no argb visual available // no argb visual available
DBGP("No ARGB Visual found"); DBGP("No ARGB Visual found");
XFree(visual_list); XFree(visual_list);
return 0; return 0;
} }
#endif /* BUILD_ARGB */ #endif /* BUILD_ARGB */
@ -473,18 +476,19 @@ void destroy_window() {
} }
void x11_init_window(lua::state &l __attribute__((unused)), bool own) { void x11_init_window(lua::state &l __attribute__((unused)), bool own) {
DBGP("enter init_window()"); DBGP("enter x11_init_window()");
// own is unused if OWN_WINDOW is not defined // own is unused if OWN_WINDOW is not defined
(void)own; (void)own;
window_created = 1;
#ifdef OWN_WINDOW #ifdef OWN_WINDOW
if (own) { if (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) { return; } if (find_desktop_window(&window.root, &window.desktop) == 0U) {
DBGP2("no desktop window found");
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)) {
@ -802,7 +806,10 @@ void x11_init_window(lua::state &l __attribute__((unused)), bool own) {
if (window.window == 0u) { if (window.window == 0u) {
window.window = find_desktop_window(&window.root, &window.desktop); window.window = find_desktop_window(&window.root, &window.desktop);
} }
if (window.window == 0u) { return; } if (window.window == 0u) {
DBGP2("no root window found");
return;
}
window.visual = DefaultVisual(display, screen); window.visual = DefaultVisual(display, screen);
window.colourmap = DefaultColormap(display, screen); window.colourmap = DefaultColormap(display, screen);
@ -828,7 +835,9 @@ void x11_init_window(lua::state &l __attribute__((unused)), bool own) {
: 0) : 0)
#endif #endif
); );
DBGP("leave init_window()");
window_created = 1;
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) {

View File

@ -22,9 +22,7 @@
* *
*/ */
#ifdef BUILD_X11 #pragma once
#ifndef X11_H_
#define X11_H_
#include <X11/Xatom.h> #include <X11/Xatom.h>
#pragma GCC diagnostic push #pragma GCC diagnostic push
@ -93,6 +91,7 @@ struct conky_x11_window {
}; };
extern struct conky_x11_window window; extern struct conky_x11_window window;
extern conky::simple_config_setting<std::string> display_name;
void destroy_window(void); void destroy_window(void);
void create_gc(void); void create_gc(void);
@ -158,6 +157,3 @@ extern priv::use_xdbe_setting use_xdbe;
#else #else
extern priv::use_xpmdb_setting use_xpmdb; extern priv::use_xpmdb_setting use_xpmdb;
#endif #endif
#endif /*X11_H_*/
#endif /* BUILD_X11 */