mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-25 12:10:03 +00:00
Fix (some) wayland/x11 init ordering issues.
This commit is contained in:
parent
64b001f2f8
commit
c48df06359
@ -228,11 +228,6 @@ if(BUILD_PORT_MONITORS)
|
||||
set(optional_sources ${optional_sources} ${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)
|
||||
set(x11 x11.cc x11.h)
|
||||
set(optional_sources ${optional_sources} ${x11})
|
||||
@ -243,6 +238,11 @@ if(BUILD_X11)
|
||||
endif(BUILD_XINERAMA)
|
||||
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)
|
||||
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})
|
||||
|
@ -62,7 +62,6 @@
|
||||
#pragma GCC diagnostic ignored "-Wvariadic-macros"
|
||||
#include <X11/Xutil.h>
|
||||
#pragma GCC diagnostic pop
|
||||
#include "x11.h"
|
||||
#ifdef BUILD_XDAMAGE
|
||||
#include <X11/extensions/Xdamage.h>
|
||||
#endif
|
||||
@ -94,7 +93,7 @@
|
||||
#ifdef BUILD_GUI
|
||||
#include "fonts.h"
|
||||
#include "gui.h"
|
||||
#endif
|
||||
#endif /* BUILD_GUI */
|
||||
#include "fs.h"
|
||||
#ifdef BUILD_ICONV
|
||||
#include "iconv_tools.h"
|
||||
|
@ -86,16 +86,16 @@ void load_fonts(bool utf8) {
|
||||
}
|
||||
|
||||
int font_height() {
|
||||
// assert(selected_font < fonts.size());
|
||||
assert(selected_font < fonts.size());
|
||||
return display_output()->font_height(selected_font);
|
||||
}
|
||||
|
||||
int font_ascent() {
|
||||
// assert(selected_font < fonts.size());
|
||||
assert(selected_font < fonts.size());
|
||||
return display_output()->font_ascent(selected_font);
|
||||
}
|
||||
|
||||
int font_descent() {
|
||||
// assert(selected_font < fonts.size());
|
||||
assert(selected_font < fonts.size());
|
||||
return display_output()->font_descent(selected_font);
|
||||
}
|
||||
|
11
src/gui.cc
11
src/gui.cc
@ -191,17 +191,16 @@ std::string gethostnamecxx() {
|
||||
* 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
|
||||
* defined. The order should be: x11_display_name -> out_to_x -> everything
|
||||
* colour related
|
||||
* -> border_*, own_window_*, etc -> own_window ->
|
||||
* double_buffer -> imlib_cache_size
|
||||
* colour related -> border_*, own_window_*, etc -> own_window -> 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,
|
||||
false);
|
||||
|
||||
conky::simple_config_setting<std::string> display_name("display", std::string(),
|
||||
false);
|
||||
|
||||
priv::colour_setting color[10] = {{"color0", 0xffffff}, {"color1", 0xffffff},
|
||||
{"color2", 0xffffff}, {"color3", 0xffffff},
|
||||
{"color4", 0xffffff}, {"color5", 0xffffff},
|
||||
|
@ -124,7 +124,6 @@ class colour_setting
|
||||
};
|
||||
} // namespace priv
|
||||
|
||||
extern conky::simple_config_setting<std::string> display_name;
|
||||
extern conky::simple_config_setting<int> head_index;
|
||||
extern priv::colour_setting color[10];
|
||||
extern priv::colour_setting default_color;
|
||||
|
@ -66,13 +66,73 @@ priv::config_setting_base *get_setting(lua::state &l, int index) {
|
||||
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
|
||||
settings_vector make_settings_vector() {
|
||||
settings_vector ret;
|
||||
ret.reserve(settings->size());
|
||||
|
||||
for (auto &setting : *settings) { ret.push_back(setting.second); }
|
||||
sort(ret.begin(), ret.end(), &priv::config_setting_base::seq_compare);
|
||||
// for _some_ settings, the order matters, for others it does not. first we
|
||||
// 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;
|
||||
}
|
||||
@ -252,6 +312,4 @@ void cleanup_config_settings(lua::state &l) {
|
||||
l.pop();
|
||||
}
|
||||
|
||||
/////////// example settings, remove after real settings are available ///////
|
||||
range_config_setting<int> asdf("asdf", 42, 47, 45, true);
|
||||
} // namespace conky
|
||||
|
@ -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
|
||||
|
||||
#endif /* SETTING_HH */
|
||||
|
51
src/x11.cc
51
src/x11.cc
@ -64,12 +64,15 @@ Display *display = nullptr;
|
||||
/* Window stuff */
|
||||
struct conky_x11_window window;
|
||||
|
||||
conky::simple_config_setting<std::string> display_name("display", std::string(),
|
||||
false);
|
||||
|
||||
/* local prototypes */
|
||||
static void update_workarea();
|
||||
static Window find_desktop_window(Window *p_root, Window *p_desktop);
|
||||
static Window find_subwindow(Window win, int w, int h);
|
||||
static void init_X11();
|
||||
static void deinit_X11();
|
||||
static void init_x11();
|
||||
static void deinit_x11();
|
||||
|
||||
/********************* <SETTINGS> ************************/
|
||||
namespace priv {
|
||||
@ -78,7 +81,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;
|
||||
}
|
||||
@ -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) {
|
||||
lua::stack_sentry s(l, -1);
|
||||
|
||||
if (do_convert(l, -1).first) { deinit_X11(); }
|
||||
if (do_convert(l, -1).first) { deinit_x11(); }
|
||||
|
||||
l.pop();
|
||||
}
|
||||
@ -94,7 +97,10 @@ void out_to_x_setting::cleanup(lua::state &l) {
|
||||
#ifdef BUILD_XDBE
|
||||
bool use_xdbe_setting::set_up(lua::state &l) {
|
||||
// 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;
|
||||
|
||||
@ -222,8 +228,8 @@ static int __attribute__((noreturn)) x11_ioerror_handler(Display *d) {
|
||||
}
|
||||
|
||||
/* X11 initializer */
|
||||
static void init_X11() {
|
||||
DBGP("enter init_X11()");
|
||||
static void init_x11() {
|
||||
DBGP("enter init_x11()");
|
||||
if (display == nullptr) {
|
||||
const std::string &dispstr = display_name.get(*state);
|
||||
// passing nullptr to XOpenDisplay should open the default display
|
||||
@ -233,12 +239,7 @@ static void init_X11() {
|
||||
if ((display = XOpenDisplay(disp)) == nullptr) {
|
||||
std::string err =
|
||||
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);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -261,12 +262,12 @@ static void init_X11() {
|
||||
XSetErrorHandler(&x11_error_handler);
|
||||
XSetIOErrorHandler(&x11_ioerror_handler);
|
||||
|
||||
DBGP("leave init_X11()");
|
||||
DBGP("leave init_x11()");
|
||||
}
|
||||
|
||||
static void deinit_X11() {
|
||||
static void deinit_x11() {
|
||||
if (display) {
|
||||
DBGP("deinit_X11()");
|
||||
DBGP("deinit_x11()");
|
||||
XCloseDisplay(display);
|
||||
display = nullptr;
|
||||
}
|
||||
@ -457,9 +458,11 @@ static int get_argb_visual(Visual **visual, int *depth) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// no argb visual available
|
||||
DBGP("No ARGB Visual found");
|
||||
XFree(visual_list);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* BUILD_ARGB */
|
||||
@ -473,18 +476,19 @@ void destroy_window() {
|
||||
}
|
||||
|
||||
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
|
||||
(void)own;
|
||||
|
||||
window_created = 1;
|
||||
|
||||
#ifdef OWN_WINDOW
|
||||
if (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) {
|
||||
DBGP2("no desktop window found");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef BUILD_ARGB
|
||||
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) {
|
||||
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.colourmap = DefaultColormap(display, screen);
|
||||
@ -828,7 +835,9 @@ void x11_init_window(lua::state &l __attribute__((unused)), bool own) {
|
||||
: 0)
|
||||
#endif
|
||||
);
|
||||
DBGP("leave init_window()");
|
||||
|
||||
window_created = 1;
|
||||
DBGP("leave x11_init_window()");
|
||||
}
|
||||
|
||||
static Window find_subwindow(Window win, int w, int h) {
|
||||
|
@ -22,9 +22,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef BUILD_X11
|
||||
#ifndef X11_H_
|
||||
#define X11_H_
|
||||
#pragma once
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
#pragma GCC diagnostic push
|
||||
@ -93,6 +91,7 @@ struct conky_x11_window {
|
||||
};
|
||||
|
||||
extern struct conky_x11_window window;
|
||||
extern conky::simple_config_setting<std::string> display_name;
|
||||
|
||||
void destroy_window(void);
|
||||
void create_gc(void);
|
||||
@ -158,6 +157,3 @@ extern priv::use_xdbe_setting use_xdbe;
|
||||
#else
|
||||
extern priv::use_xpmdb_setting use_xpmdb;
|
||||
#endif
|
||||
|
||||
#endif /*X11_H_*/
|
||||
#endif /* BUILD_X11 */
|
||||
|
Loading…
Reference in New Issue
Block a user