diff --git a/.gitignore b/.gitignore
index 9c0b786da..ec72b01fc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,11 +11,17 @@ doc/*.html
Makefile
CMakeCache.txt
CMakeFiles
+cmake_install.cmake
+cmake_uninstall.cmake
+CPackConfig.cmake
+CPackSourceConfig.cmake
+
data/convertconf.h
data/defconfig.h
*.so
*.a
/config.h
+/build.h
# Compiler cache
.cache
diff --git a/3rdparty/toluapp/.gitignore b/3rdparty/toluapp/.gitignore
index 567609b12..aa2884da8 100644
--- a/3rdparty/toluapp/.gitignore
+++ b/3rdparty/toluapp/.gitignore
@@ -1 +1,4 @@
build/
+
+# ignore generated Makefile; keep stub
+Makefile
diff --git a/cmake/ConkyBuildOptions.cmake b/cmake/ConkyBuildOptions.cmake
index 610ea8454..06cf0fba9 100644
--- a/cmake/ConkyBuildOptions.cmake
+++ b/cmake/ConkyBuildOptions.cmake
@@ -193,8 +193,8 @@ dependent_option(BUILD_XSHAPE "Enable Xshape support" true
"BUILD_X11" false
"Xshape support requires X11")
dependent_option(BUILD_XINPUT "Build Xinput 2 support" true
- "BUILD_X11;BUILD_MOUSE_EVENTS" false
- "Xinput 2 support requires X11 and BUILD_MOUSE_EVENTS enabled")
+ "BUILD_X11" false
+ "Xinput 2 support requires X11")
# if we build with any GUI support
if(BUILD_X11)
@@ -206,8 +206,8 @@ if(BUILD_WAYLAND)
endif(BUILD_WAYLAND)
dependent_option(BUILD_MOUSE_EVENTS "Enable mouse event support" true
- "BUILD_WAYLAND OR OWN_WINDOW" false
- "Mouse event support requires Wayland or OWN_WINDOW enabled")
+ "BUILD_WAYLAND OR BUILD_X11" false
+ "Mouse event support requires Wayland or X11 enabled")
# Lua library options
dependent_option(BUILD_LUA_CAIRO "Build cairo bindings for Lua" false
@@ -247,9 +247,11 @@ option(BUILD_IRC "Enable if you want IRC support" false)
option(BUILD_HTTP "Enable if you want HTTP support" false)
-if(BUILD_HTTP)
+if(NOT BUILD_HTTP)
set(HTTPPORT "10080" CACHE STRING "Port to use for out_to_http")
-endif(BUILD_HTTP)
+else(NOT BUILD_HTTP)
+ set(HTTPPORT "10080")
+endif(NOT BUILD_HTTP)
option(BUILD_ICONV "Enable iconv support" false)
diff --git a/data/conky-dfly-smp.conf b/data/conky-dfly-smp.conf
index fac3afb04..09d7918b0 100644
--- a/data/conky-dfly-smp.conf
+++ b/data/conky-dfly-smp.conf
@@ -10,7 +10,10 @@
--
-- For more on Lua, see:
-- https://www.lua.org/pil/contents.html
+--
+-- Conky Lua API: https://conky.cc/lua
+-- Configuration settings: https://conky.cc/config_settings
conky.config = {
alignment = 'bottom_left',
background = false,
@@ -36,7 +39,8 @@ conky.config = {
extra_newline = false,
own_window = false,
own_window_class = 'Conky',
- own_window_type = 'desktop',
+ own_window_type = 'normal',
+ own_window_hints = 'undecorated,sticky,below,skip_taskbar,skip_pager',
stippled_borders = 0,
update_interval = 3.0,
uppercase = false,
@@ -45,6 +49,7 @@ conky.config = {
show_graph_range = false
}
+-- Variables: https://conky.cc/variables
conky.text = [[
$sysname $version on $machine
$hr
diff --git a/data/conky.conf b/data/conky.conf
index fc341baaa..ed269e96f 100644
--- a/data/conky.conf
+++ b/data/conky.conf
@@ -10,7 +10,10 @@
--
-- For more on Lua, see:
-- https://www.lua.org/pil/contents.html
+--
+-- Conky Lua API: https://conky.cc/lua
+-- Configuration settings: https://conky.cc/config_settings
conky.config = {
alignment = 'top_left',
background = false,
@@ -39,7 +42,8 @@ conky.config = {
out_to_x = true,
own_window = true,
own_window_class = 'Conky',
- own_window_type = 'desktop',
+ own_window_type = 'normal',
+ own_window_hints = 'undecorated,sticky,below,skip_taskbar,skip_pager',
show_graph_range = false,
show_graph_scale = false,
stippled_borders = 0,
@@ -49,6 +53,7 @@ conky.config = {
use_xft = true,
}
+-- Variables: https://conky.cc/variables
conky.text = [[
${color grey}Info:$color ${scroll 32 Conky $conky_version - $sysname $nodename $kernel $machine}
$hr
diff --git a/data/conky_no_x11.conf b/data/conky_no_x11.conf
index 4246daad9..4ea6e13c0 100644
--- a/data/conky_no_x11.conf
+++ b/data/conky_no_x11.conf
@@ -10,7 +10,10 @@
--
-- For more on Lua, see:
-- https://www.lua.org/pil/contents.html
+--
+-- Conky Lua API: https://conky.cc/lua
+-- Configuration settings: https://conky.cc/config_settings
conky.config = {
background = false,
cpu_avg_samples = 2,
@@ -22,6 +25,7 @@ conky.config = {
use_spacer = 'none',
};
+-- Variables: https://conky.cc/variables
conky.text =
[[${scroll 16 $nodename - $sysname $kernel on $machine | }
Uptime: $uptime
diff --git a/doc/config_settings.yaml b/doc/config_settings.yaml
index 7d67dbcee..7cb8d8dc6 100644
--- a/doc/config_settings.yaml
+++ b/doc/config_settings.yaml
@@ -27,10 +27,38 @@ desc: |-
values:
- name: alignment
desc: |-
- Aligned position on screen, may be top_left, top_right,
- top_middle, bottom_left, bottom_right, bottom_middle, middle_left,
- middle_middle, middle_right, or none (also can be abbreviated as tl,
- tr, tm, bl, br, bm, ml, mm, mr). See also gap_x and gap_y.
+ Aligned position on screen, may be `none` or one of:
+
+
+
+ top_left (or tl ) |
+ top_middle (or tm ) |
+ top_right (or tr ) |
+
+
+ middle_left (or ml ) |
+ middle_middle (or mm ) |
+ middle_right (or mr ) |
+
+
+ bottom_left (or bl ) |
+ bottom_middle (or bm ) |
+ bottom_right (or br ) |
+
+
+
+ In case of `panel` and `dock` windows, it might make more sense to use one
+ of the following aliases:
+
+ | Alias | Value |
+ |:------:|:-------------:|
+ | `top` | `top_middle` |
+ | `left` | `middle_left` |
+ |`right` |`middle_right` |
+ |`bottom`|`bottom_middle`|
+ |`center`|`middle_middle`|
+
+ See also `gap_x` and `gap_y` settings.
- name: append_file
desc: Append the file given as argument.
- name: background
@@ -437,7 +465,7 @@ values:
default: false
- name: own_window_type
desc: |-
- If own_window is set, under X11 you can specify type of window conky
+ If `own_window` is set, under X11 you can specify type of window conky
displayed as:
- `normal` mode makes conky show as normal window. This mode can be
@@ -464,6 +492,7 @@ values:
panels/windows as those will cover conky.
`own_window_hints` are ignored for `override` windows.
+ To make conky mount on root window, set `own_window` to `false`.
default: normal
args:
- (normal|desktop|dock|panel|utility|override)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d2303d616..e1d1c9143 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -119,14 +119,6 @@ set(conky_sources
display-console.hh
display-file.cc
display-file.hh
- display-ncurses.cc
- display-ncurses.hh
- display-http.cc
- display-http.hh
- display-x11.cc
- display-x11.hh
- display-wayland.cc
- display-wayland.hh
lua-config.cc
lua-config.hh
setting.cc
@@ -236,8 +228,23 @@ if(BUILD_PORT_MONITORS)
set(optional_sources ${optional_sources} ${port_monitors})
endif(BUILD_PORT_MONITORS)
+if(BUILD_HTTP)
+ set(http
+ display-http.cc
+ display-http.hh
+ )
+ set(optional_sources ${optional_sources} ${http})
+endif(BUILD_HTTP)
+
if(BUILD_X11)
- set(x11 x11.cc x11.h)
+ set(x11
+ display-x11.cc
+ display-x11.hh
+ x11-settings.cc
+ x11-settings.h
+ x11.cc
+ x11.h
+ )
set(optional_sources ${optional_sources} ${x11})
endif(BUILD_X11)
@@ -245,14 +252,22 @@ if(BUILD_GUI)
set(gui fonts.cc fonts.h gui.cc gui.h)
set(optional_sources ${optional_sources} ${gui})
- if(BUILD_MOUSE_EVENTS)
+ if(BUILD_MOUSE_EVENTS OR BUILD_XINPUT)
set(mouse_events mouse-events.cc mouse-events.h)
set(optional_sources ${optional_sources} ${mouse_events})
- endif(BUILD_MOUSE_EVENTS)
+ endif(BUILD_MOUSE_EVENTS OR BUILD_XINPUT)
endif(BUILD_GUI)
+
if(BUILD_WAYLAND)
- set(wl_srcs wl.cc wl.h xdg-shell-protocol.c wlr-layer-shell-protocol.c)
+ set(wl_srcs
+ wl.cc
+ wl.h
+ display-wayland.cc
+ display-wayland.hh
+ xdg-shell-protocol.c
+ wlr-layer-shell-protocol.c
+ )
set(optional_sources ${optional_sources} ${wl_srcs})
# generate protocol implementations
@@ -324,7 +339,12 @@ if(BUILD_ICONV)
endif(BUILD_ICONV)
if(BUILD_NCURSES)
- set(ncurses_srcs nc.cc nc.h)
+ set(ncurses_srcs
+ nc.cc
+ nc.h
+ display-ncurses.cc
+ display-ncurses.hh
+ )
set(optional_sources ${optional_sources} ${ncurses_srcs})
endif(BUILD_NCURSES)
diff --git a/src/colours.cc b/src/colours.cc
index f40ae3ace..0de586e18 100644
--- a/src/colours.cc
+++ b/src/colours.cc
@@ -26,25 +26,21 @@
* along with this program. If not, see .
*
*/
-#include "conky.h"
-#include "gui.h"
+
+#include "colours.h"
+
#include "logging.h"
-#include "x11-color.h"
+
+#include
#ifdef BUILD_X11
-std::unordered_map Colour::x11_pixels;
+#include
+#include
+#include
#endif /* BUILD_X11 */
-static int hex_nibble_value(char c) {
- if (c >= '0' && c <= '9') {
- return c - '0';
- } else if (c >= 'a' && c <= 'f') {
- return c - 'a' + 10;
- } else if (c >= 'A' && c <= 'F') {
- return c - 'A' + 10;
- }
- return -1;
-}
+// sourced from X11, doesn't actually need X11
+#include "x11-color.h"
Colour Colour::from_argb32(uint32_t argb) {
Colour out;
@@ -55,29 +51,91 @@ Colour Colour::from_argb32(uint32_t argb) {
return out;
}
-Colour error_colour{0xff, 0x00, 0x00, 0xff};
+#ifdef BUILD_X11
+unsigned long Colour::to_x11_color(Display *display, int screen,
+ bool transparency, bool premultiply) {
+ static std::unordered_map x11_pixels;
-Colour parse_color(const char *name) {
+ if (display == nullptr) {
+ /* cannot work if display is not open */
+ return 0;
+ }
+
+ unsigned long pixel;
+
+ /* Either get a cached X11 pixel or allocate one */
+ if (auto pixel_iter = x11_pixels.find(*this);
+ pixel_iter != x11_pixels.end()) {
+ pixel = pixel_iter->second;
+ } else {
+ XColor xcolor{};
+ xcolor.red = this->red * 257;
+ xcolor.green = this->green * 257;
+ xcolor.blue = this->blue * 257;
+ if (XAllocColor(display, DefaultColormap(display, screen), &xcolor) == 0) {
+ // NORM_ERR("can't allocate X color");
+ return 0;
+ }
+
+ /* Save pixel value in the cache to avoid reallocating it */
+ x11_pixels[*this] = xcolor.pixel;
+ pixel = static_cast(xcolor.pixel);
+ }
+
+ pixel &= 0xffffff;
+#ifdef BUILD_ARGB
+ if (transparency) {
+ if (premultiply)
+ pixel = (red * alpha / 255) << 16 | (green * alpha / 255) << 8 |
+ (blue * alpha / 255);
+ pixel |= ((unsigned long)alpha << 24);
+ }
+#endif /* BUILD_ARGB */
+ return pixel;
+}
+#endif /* BUILD_X11 */
+
+std::optional parse_color_name(const std::string &name) {
unsigned short r, g, b;
- size_t len = strlen(name);
+ size_t len = name.length();
// Parse X11 color names.
- if (OsLookupColor(-1, name, len, &r, &g, &b)) {
- Colour out = {(uint8_t)r, (uint8_t)g, (uint8_t)b, 0xff};
- return out;
+ if (OsLookupColor(name.c_str(), len, &r, &g, &b)) {
+ return Colour{(uint8_t)r, (uint8_t)g, (uint8_t)b, 0xff};
+ } else {
+ return std::nullopt;
}
+}
- // Remove a leading '#' if present.
+std::optional parse_hex_color(const std::string &color) {
+ const char *name = color.c_str();
+ size_t len = color.length();
+ // Skip a leading '#' if present.
if (name[0] == '#') {
name++;
len--;
}
- unsigned char argb[4] = {0xff, 0, 0, 0};
+ static auto hex_nibble_value = [](char c) {
+ if (c >= '0' && c <= '9') {
+ return c - '0';
+ } else if (c >= 'a' && c <= 'f') {
+ return c - 'a' + 10;
+ } else if (c >= 'A' && c <= 'F') {
+ return c - 'A' + 10;
+ }
+ return -1;
+ };
+ const auto none = [&]() {
+ NORM_ERR("can't parse hex color '%s' (%d)", name, len);
+ return std::nullopt;
+ };
+
+ uint8_t argb[4] = {0xff, 0, 0, 0};
if (len == 3 || len == 4) {
bool skip_alpha = (len == 3);
for (size_t i = 0; i < len; i++) {
int nib = hex_nibble_value(name[i]);
- if (nib < 0) { goto err; }
+ if (nib < 0) { return none(); }
// Duplicate the nibble, so "#abc" -> 0xaa, 0xbb, 0xcc
int val = (nib << 4) + nib;
@@ -88,27 +146,35 @@ Colour parse_color(const char *name) {
for (size_t i = 0; i + 1 < len; i += 2) {
int nib1 = hex_nibble_value(name[i]);
int nib2 = hex_nibble_value(name[i + 1]);
- if (nib1 < 0 || nib2 < 0) { goto err; }
+ if (nib1 < 0 || nib2 < 0) { return none(); }
int val = (nib1 << 4) + nib2;
argb[skip_alpha + i / 2] = val;
}
} else {
- goto err;
+ return none();
}
- Colour out;
- out.alpha = argb[0];
- out.red = argb[1];
- out.green = argb[2];
- out.blue = argb[3];
- return out;
-
-err:
- NORM_ERR("can't parse X color '%s' (%d)", name, len);
- return error_colour;
+ return Colour(argb[1], argb[2], argb[3], argb[0]);
}
-Colour parse_color(const std::string &colour) {
- return parse_color(colour.c_str());
+Colour parse_color(const std::string &color) {
+ std::optional result;
+
+#define TRY_PARSER(name) \
+ std::optional value_##name = name(color); \
+ if (value_##name.has_value()) { return value_##name.value(); }
+
+ std::optional value_parse_color_name = parse_color_name(color);
+ if (value_parse_color_name.has_value()) {
+ return value_parse_color_name.value();
+ }
+ std::optional value_parse_hex_color = parse_hex_color(color);
+ if (value_parse_hex_color.has_value()) {
+ return value_parse_hex_color.value();
+ }
+
+#undef TRY_PARSER
+
+ return ERROR_COLOUR;
}
diff --git a/src/colours.h b/src/colours.h
index 7b2d2cfe2..a6d526816 100644
--- a/src/colours.h
+++ b/src/colours.h
@@ -26,31 +26,50 @@
* along with this program. If not, see .
*
*/
-#pragma once
-#include
+#ifndef _COLOURS_H_
+#define _COLOURS_H_
+
+#include "config.h"
+
#include
#include
#include
#include
#include
+
#ifdef BUILD_X11
-#include "x11.h"
+#include
#endif /* BUILD_X11 */
struct Colour {
uint8_t red;
uint8_t green;
uint8_t blue;
- uint8_t alpha;
+ uint8_t alpha = 0xff;
public:
+ Colour() = default;
+ Colour(uint8_t r, uint8_t g, uint8_t b, uint8_t a = UINT8_MAX)
+ : red(r), green(g), blue(b), alpha(a) {}
+ Colour(const Colour &) = default;
+ Colour(Colour &&) = default;
+
+ void operator=(const Colour &c) {
+ red = c.red;
+ green = c.green;
+ blue = c.blue;
+ alpha = c.alpha;
+ }
+
// Compare two instances.
bool operator==(const Colour &c) const {
return c.red == red && c.green == green && c.blue == blue &&
c.alpha == alpha;
}
+ uint8_t *data() { return reinterpret_cast(this); }
+
// Express the color as a 32-bit ARGB integer (alpha in MSB).
uint32_t to_argb32(void) const {
uint32_t out;
@@ -61,58 +80,20 @@ struct Colour {
// Construct from a 32-bit ARGB integer (alpha in MSB).
static Colour from_argb32(uint32_t argb);
-#ifdef BUILD_X11
class Hash {
public:
size_t operator()(const Colour &c) const { return c.to_argb32(); }
};
- static std::unordered_map x11_pixels;
+#ifdef BUILD_X11
unsigned long to_x11_color(Display *display, int screen,
- bool premultiply = false) {
- if (display == nullptr) {
- /* cannot work if display is not open */
- return 0;
- }
-
- unsigned long pixel;
-
- /* Either get a cached X11 pixel or allocate one */
- if (auto pixel_iter = x11_pixels.find(*this);
- pixel_iter != x11_pixels.end()) {
- pixel = pixel_iter->second;
- } else {
- XColor xcolor{};
- xcolor.red = red * 257;
- xcolor.green = green * 257;
- xcolor.blue = blue * 257;
- if (XAllocColor(display, DefaultColormap(display, screen), &xcolor) ==
- 0) {
- // NORM_ERR("can't allocate X color");
- return 0;
- }
-
- /* Save pixel value in the cache to avoid reallocating it */
- x11_pixels[*this] = xcolor.pixel;
- pixel = static_cast(xcolor.pixel);
- }
-
- pixel &= 0xffffff;
-#ifdef BUILD_ARGB
- if (have_argb_visual) {
- if (premultiply)
- pixel = (red * alpha / 255) << 16 | (green * alpha / 255) << 8 |
- (blue * alpha / 255);
- pixel |= ((unsigned long)alpha << 24);
- }
-#endif /* BUILD_ARGB */
- return pixel;
- }
+ bool transparency = false,
+ bool premultiply = false);
#endif /* BUILD_X11 */
};
-extern Colour error_colour;
+const Colour ERROR_COLOUR = Colour{UINT8_MAX, 0, 0, UINT8_MAX};
+
+Colour parse_color(const std::string &color);
-Colour parse_color(const std::string &colour);
-// XXX: when everyone uses C++ strings, remove this C version
-Colour parse_color(const char *);
+#endif /* _COLOURS_H_ */
diff --git a/src/conky-imlib2.cc b/src/conky-imlib2.cc
index af4728448..042b043d4 100644
--- a/src/conky-imlib2.cc
+++ b/src/conky-imlib2.cc
@@ -22,8 +22,9 @@
*/
#include "conky-imlib2.h"
-#include "config.h"
-#include "conky.h"
+
+#include "common.h"
+#include "display-output.hh"
#include "logging.h"
#include "text_object.h"
@@ -47,22 +48,24 @@ struct image_list_s {
};
struct image_list_s *image_list_start, *image_list_end;
+std::array, 100> saved_coordinates;
/* areas to update */
Imlib_Updates updates, current_update;
/* our virtual framebuffer image we draw into */
Imlib_Image buffer, image;
-namespace {
-Imlib_Context context;
-
conky::range_config_setting imlib_cache_flush_interval(
"imlib_cache_flush_interval", 0, std::numeric_limits::max(),
0, true);
-unsigned int cimlib_cache_flush_last = 0;
+conky::simple_config_setting imlib_draw_blended("draw_blended", true,
+ true);
-conky::simple_config_setting draw_blended("draw_blended", true, true);
+namespace {
+Imlib_Context context;
+
+unsigned int cimlib_cache_flush_last = 0;
} // namespace
void imlib_cache_size_setting::lua_setter(lua::state &l, bool init) {
@@ -162,8 +165,9 @@ void cimlib_add_image(const char *args) {
tmp += 3;
int i;
if (sscanf(tmp, "%d", &i) == 1) {
- cur->x = get_saved_coordinates_x(i);
- cur->y = get_saved_coordinates_y(i);
+ const auto &coordinates = saved_coordinates.at(static_cast(i));
+ cur->x = coordinates[0];
+ cur->y = coordinates[1];
}
}
if (cur->flush_interval < 0) {
@@ -237,7 +241,8 @@ static void cimlib_draw_all(int *clip_x, int *clip_y, int *clip_x2,
}
}
-void cimlib_render(int x, int y, int width, int height) {
+void cimlib_render(int x, int y, int width, int height, uint32_t flush_interval,
+ bool draw_blended) {
int clip_x = INT_MAX, clip_y = INT_MAX;
int clip_x2 = 0, clip_y2 = 0;
time_t now;
@@ -248,8 +253,8 @@ void cimlib_render(int x, int y, int width, int height) {
/* cheque if it's time to flush our cache */
now = time(nullptr);
- if ((imlib_cache_flush_interval.get(*state) != 0u) &&
- now - imlib_cache_flush_interval.get(*state) > cimlib_cache_flush_last) {
+ if ((flush_interval != 0u) &&
+ now - flush_interval > cimlib_cache_flush_last) {
int size = imlib_get_cache_size();
imlib_set_cache_size(0);
imlib_set_cache_size(size);
@@ -265,7 +270,7 @@ void cimlib_render(int x, int y, int width, int height) {
imlib_image_clear();
/* check if we should blend when rendering */
- if (draw_blended.get(*state)) {
+ if (draw_blended) {
/* we can blend stuff now */
imlib_context_set_blend(1);
} else {
@@ -295,3 +300,5 @@ void cimlib_render(int x, int y, int width, int height) {
void print_image_callback(struct text_object *obj, char *, unsigned int) {
cimlib_add_image(obj->data.s);
}
+
+imlib_cache_size_setting imlib_cache_size;
diff --git a/src/conky-imlib2.h b/src/conky-imlib2.h
index 4484dc855..11a166979 100644
--- a/src/conky-imlib2.h
+++ b/src/conky-imlib2.h
@@ -24,17 +24,24 @@
#ifndef _CONKY_IMBLI2_H_
#define _CONKY_IMBLI2_H_
-#include "conky.h"
+#include "setting.hh"
+#include "text_object.h"
+
+#include
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wvariadic-macros"
#include
#pragma GCC diagnostic pop
+using saved_coordinates_t = std::array, 100>;
+extern saved_coordinates_t saved_coordinates;
+
void cimlib_add_image(const char *args);
void cimlib_set_cache_size(long size);
void cimlib_set_cache_flush_interval(long interval);
-void cimlib_render(int x, int y, int width, int height);
+void cimlib_render(int x, int y, int width, int height, uint32_t flush_interval,
+ bool draw_blended);
void cimlib_cleanup(void);
void print_image_callback(struct text_object *, char *, unsigned int);
@@ -53,4 +60,7 @@ class imlib_cache_size_setting
4096 * 1024, true) {}
};
+extern conky::range_config_setting imlib_cache_flush_interval;
+extern conky::simple_config_setting imlib_draw_blended;
+
#endif /* _CONKY_IMBLI2_H_ */
diff --git a/src/conky.cc b/src/conky.cc
index b2dbc4f66..0681782b6 100644
--- a/src/conky.cc
+++ b/src/conky.cc
@@ -28,6 +28,9 @@
*/
#include "conky.h"
+
+#include "config.h"
+
#include
#include
#include
@@ -40,24 +43,37 @@
#include
#include
#include
-#include "common.h"
-#include "config.h"
-#include "text_object.h"
-#ifdef HAVE_DIRENT_H
-#include
-#endif /* HAVE_DIRENT_H */
+
+#include
+#include
+#include
+#include
#include
+#include
#include
+#include
+
#ifdef HAVE_SYS_INOTIFY_H
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc99-extensions"
#include
#pragma clang diagnostic pop
#endif /* HAVE_SYS_INOTIFY_H */
+
+#ifdef HAVE_DIRENT_H
+#include
+#endif /* HAVE_DIRENT_H */
+
+#include "common.h"
+#include "text_object.h"
+
#ifdef BUILD_WAYLAND
#include "wl.h"
#endif /* BUILD_WAYLAND */
+
#ifdef BUILD_X11
+#include "x11.h"
+
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wvariadic-macros"
#include
@@ -69,21 +85,18 @@
#include "conky-imlib2.h"
#endif /* BUILD_IMLIB2 */
#endif /* BUILD_X11 */
+
#ifdef BUILD_NCURSES
#include
-#endif
-#include
-#include
-#include
-#include
-#include
-#include
-#if defined BUILD_RSS
-#include
-#endif
+#endif /* BUILD_NCURSES */
+
#ifdef BUILD_CURL
#include
-#endif
+#endif /* BUILD_CURL */
+
+#ifdef BUILD_RSS
+#include
+#endif /* BUILD_RSS */
/* local headers */
#include "colours.h"
@@ -97,7 +110,7 @@
#include "fs.h"
#ifdef BUILD_ICONV
#include "iconv_tools.h"
-#endif
+#endif /* BUILD_ICONV */
#include "llua.h"
#include "logging.h"
#include "mail.h"
@@ -108,12 +121,13 @@
#include "template.h"
#include "timeinfo.h"
#include "top.h"
+
#ifdef BUILD_MYSQL
#include "mysql.h"
#endif /* BUILD_MYSQL */
#ifdef BUILD_NVIDIA
#include "nvidia.h"
-#endif
+#endif /* BUILD_NVIDIA */
#ifdef BUILD_CURL
#include "ccurl_thread.h"
#endif /* BUILD_CURL */
@@ -394,18 +408,6 @@ int calc_text_width(const char *s) {
return slen;
}
-int dpi_scale(int value) {
-#ifdef BUILD_GUI
- if (display_output()) {
- return display_output()->dpi_scale(value);
- } else {
- return value;
- }
-#else /* BUILD_GUI */
- return value;
-#endif /* BUILD_GUI */
-}
-
#ifdef BUILD_GUI
conky::gradient_factory *create_gradient_factory(int width, Colour first_colour,
Colour last_colour) {
@@ -766,7 +768,7 @@ void remove_first_char(char *s) { memmove(s, s + 1, strlen(s)); }
static int get_string_width_special(char *s, int special_index) {
char *p, *final;
- special_t *current = specials;
+ special_node *current = specials;
int width = 0;
long i;
@@ -789,22 +791,23 @@ static int get_string_width_special(char *s, int special_index) {
/*for (i = 0; i < static_cast(strlen(p)); i++) {
*(p + i) = *(p + i + 1);
}*/
- if (current->type == GRAPH || current->type == GAUGE ||
- current->type == BAR) {
+ if (current->type == text_node_t::GRAPH ||
+ current->type == text_node_t::GAUGE ||
+ current->type == text_node_t::BAR) {
width += current->width;
}
- if (current->type == FONT) {
+ if (current->type == text_node_t::FONT) {
// put all following text until the next fontchange/stringend in
// influenced_by_font but do not include specials
char *influenced_by_font = strdup(p);
- special_t *current_after_font = current;
+ special_node *current_after_font = current;
// influenced_by_font gets special chars removed, so after this loop i
// counts the number of letters (not special chars) influenced by font
for (i = 0; influenced_by_font[i] != 0; i++) {
if (influenced_by_font[i] == SPECIAL_CHAR) {
// remove specials and stop at fontchange
current_after_font = current_after_font->next;
- if (current_after_font->type == FONT) {
+ if (current_after_font->type == text_node_t::FONT) {
influenced_by_font[i] = 0;
break;
}
@@ -867,50 +870,34 @@ void update_text_area() {
alignment align = text_alignment.get(*state);
/* get text position on workarea */
- switch (align) {
- case TOP_LEFT:
- case TOP_RIGHT:
- case TOP_MIDDLE:
+ switch (vertical_alignment(align)) {
+ case axis_align::START:
y = workarea[1] + dpi_scale(gap_y.get(*state));
break;
-
- case BOTTOM_LEFT:
- case BOTTOM_RIGHT:
- case BOTTOM_MIDDLE:
+ case axis_align::END:
default:
y = workarea[3] - text_height - dpi_scale(gap_y.get(*state));
break;
-
- case MIDDLE_LEFT:
- case MIDDLE_RIGHT:
- case MIDDLE_MIDDLE:
+ case axis_align::MIDDLE:
y = workarea[1] + (workarea[3] - workarea[1]) / 2 - text_height / 2 -
dpi_scale(gap_y.get(*state));
break;
}
- switch (align) {
- case TOP_LEFT:
- case BOTTOM_LEFT:
- case MIDDLE_LEFT:
+ switch (horizontal_alignment(align)) {
+ case axis_align::START:
default:
x = workarea[0] + dpi_scale(gap_x.get(*state));
break;
-
- case TOP_RIGHT:
- case BOTTOM_RIGHT:
- case MIDDLE_RIGHT:
+ case axis_align::END:
x = workarea[2] - text_width - dpi_scale(gap_x.get(*state));
break;
-
- case TOP_MIDDLE:
- case BOTTOM_MIDDLE:
- case MIDDLE_MIDDLE:
+ case axis_align::MIDDLE:
x = workarea[0] + (workarea[2] - workarea[0]) / 2 - text_width / 2 -
dpi_scale(gap_x.get(*state));
break;
}
#ifdef OWN_WINDOW
- if (align == NONE) { // Let the WM manage the window
+ if (align == alignment::NONE) { // Let the WM manage the window
x = window.x;
y = window.y;
@@ -941,20 +928,14 @@ static int cur_x, cur_y; /* current x and y for drawing */
#endif
// draw_mode also without BUILD_GUI because we only need to print to stdout with
// FG
-static int draw_mode; /* FG, BG or OUTLINE */
+static draw_mode_t draw_mode; /* FG, BG or OUTLINE */
#ifdef BUILD_GUI
/*static*/ Colour current_color;
-static int saved_coordinates_x[100];
-static int saved_coordinates_y[100];
-
-int get_saved_coordinates_x(int i) { return saved_coordinates_x[i]; }
-int get_saved_coordinates_y(int i) { return saved_coordinates_y[i]; }
-
static int text_size_updater(char *s, int special_index) {
int w = 0;
char *p;
- special_t *current = specials;
+ special_node *current = specials;
for (int i = 0; i < special_index; i++) { current = current->next; }
@@ -969,26 +950,27 @@ static int text_size_updater(char *s, int special_index) {
w += get_string_width(s);
*p = SPECIAL_CHAR;
- if (current->type == BAR || current->type == GAUGE ||
- current->type == GRAPH) {
+ if (current->type == text_node_t::BAR ||
+ current->type == text_node_t::GAUGE ||
+ current->type == text_node_t::GRAPH) {
w += current->width;
if (current->height > last_font_height) {
last_font_height = current->height;
last_font_height += font_height();
}
- } else if (current->type == OFFSET) {
+ } else if (current->type == text_node_t::OFFSET) {
if (current->arg > 0) { w += current->arg; }
- } else if (current->type == VOFFSET) {
+ } else if (current->type == text_node_t::VOFFSET) {
last_font_height += current->arg;
- } else if (current->type == GOTO) {
+ } else if (current->type == text_node_t::GOTO) {
if (current->arg > cur_x) { w = static_cast(current->arg); }
- } else if (current->type == TAB) {
+ } else if (current->type == text_node_t::TAB) {
int start = current->arg;
int step = current->width;
if ((step == 0) || step < 0) { step = 10; }
w += step - (cur_x - text_start_x - start) % step;
- } else if (current->type == FONT) {
+ } else if (current->type == text_node_t::FONT) {
selected_font = current->font_added;
if (font_height() > last_font_height) {
last_font_height = font_height();
@@ -1033,7 +1015,7 @@ static void draw_string(const char *s) {
#ifdef BUILD_GUI
width_of_s = get_string_width(s);
#endif /* BUILD_GUI */
- if (draw_mode == FG) {
+ if (draw_mode == draw_mode_t::FG) {
for (auto output : display_outputs())
if (!output->graphical()) output->draw_string(s, 0);
}
@@ -1163,11 +1145,11 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
s = p + 1;
}
/* draw special */
- special_t *current = specials;
+ special_node *current = specials;
for (int i = 0; i < special_index; i++) { current = current->next; }
switch (current->type) {
#ifdef BUILD_GUI
- case HORIZONTAL_LINE:
+ case text_node_t::HORIZONTAL_LINE:
if (display_output() && display_output()->graphical()) {
int h = current->height;
int mid = font_ascent() / 2;
@@ -1183,7 +1165,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
}
break;
- case STIPPLED_HR:
+ case text_node_t::STIPPLED_HR:
if (display_output() && display_output()->graphical()) {
int h = current->height;
char tmp_s = current->arg;
@@ -1201,7 +1183,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
}
break;
- case BAR:
+ case text_node_t::BAR:
if (display_output() && display_output()->graphical()) {
int h, by;
double bar_usage, scale;
@@ -1229,7 +1211,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
}
break;
- case GAUGE: /* new GAUGE */
+ case text_node_t::GAUGE: /* new GAUGE */
if (display_output() && display_output()->graphical()) {
int h, by = 0;
Colour last_colour = current_color;
@@ -1279,7 +1261,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
}
break;
- case GRAPH:
+ case text_node_t::GRAPH:
if (display_output() && display_output()->graphical()) {
int h, by, i = 0, j = 0;
int colour_idx = 0;
@@ -1415,7 +1397,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
}
break;
- case FONT:
+ case text_node_t::FONT:
if (display_output() && display_output()->graphical()) {
int old = font_ascent();
@@ -1431,41 +1413,42 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
}
break;
#endif /* BUILD_GUI */
- case FG:
- if (draw_mode == FG) {
+ case text_node_t::FG:
+ if (draw_mode == draw_mode_t::FG) {
set_foreground_color(Colour::from_argb32(current->arg));
}
break;
#ifdef BUILD_GUI
- case BG:
- if (draw_mode == BG) {
+ case text_node_t::BG:
+ if (draw_mode == draw_mode_t::BG) {
set_foreground_color(Colour::from_argb32(current->arg));
}
break;
- case OUTLINE:
- if (draw_mode == OUTLINE) {
+ case text_node_t::OUTLINE:
+ if (draw_mode == draw_mode_t::OUTLINE) {
set_foreground_color(Colour::from_argb32(current->arg));
}
break;
- case OFFSET:
+ case text_node_t::OFFSET:
w += current->arg;
break;
- case VOFFSET:
+ case text_node_t::VOFFSET:
cur_y += current->arg;
break;
- case SAVE_COORDINATES:
- saved_coordinates_x[static_cast(current->arg)] =
- cur_x - text_start_x;
- saved_coordinates_y[static_cast(current->arg)] =
- cur_y - text_start_y - last_font_height;
+ case text_node_t::SAVE_COORDINATES:
+#ifdef BUILD_IMLIB2
+ saved_coordinates[static_cast(current->arg)] =
+ std::array{cur_x - text_start_x,
+ cur_y - text_start_y - last_font_height};
+#endif /* BUILD_IMLIB2 */
break;
- case TAB: {
+ case text_node_t::TAB: {
int start = current->arg;
int step = current->width;
@@ -1474,7 +1457,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
break;
}
- case ALIGNR: {
+ case text_node_t::ALIGNR: {
/* TODO: add back in "+ window.border_inner_margin" to the end of
* this line? */
int pos_x = text_start_x + text_width -
@@ -1491,7 +1474,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
break;
}
- case ALIGNC: {
+ case text_node_t::ALIGNC: {
int pos_x = (text_width) / 2 -
get_string_width_special(s, special_index) / 2 -
(cur_x - text_start_x);
@@ -1507,17 +1490,20 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
break;
}
#endif /* BUILD_GUI */
- case GOTO:
+ case text_node_t::GOTO:
if (current->arg >= 0) {
#ifdef BUILD_GUI
cur_x = static_cast(current->arg);
// make sure shades are 1 pixel to the right of the text
- if (draw_mode == BG) { cur_x++; }
+ if (draw_mode == draw_mode_t::BG) { cur_x++; }
#endif /* BUILD_GUI */
cur_x = static_cast(current->arg);
for (auto output : display_outputs()) output->gotox(cur_x);
}
break;
+ default:
+ // do nothing; not a special node or support not enabled
+ break;
}
#ifdef BUILD_GUI
@@ -1599,7 +1585,9 @@ void draw_stuff() {
#ifdef BUILD_IMLIB2
text_offset_x = text_offset_y = 0;
- cimlib_render(text_start_x, text_start_y, window.width, window.height);
+ cimlib_render(text_start_x, text_start_y, window.width, window.height,
+ imlib_cache_flush_interval.get(*state),
+ imlib_draw_blended.get(*state));
#endif /* BUILD_IMLIB2 */
for (auto output : display_outputs()) {
@@ -1611,7 +1599,7 @@ void draw_stuff() {
if (draw_shades.get(*state) && !draw_outline.get(*state)) {
text_offset_x = text_offset_y = 1;
set_foreground_color(default_shade_color.get(*state));
- draw_mode = BG;
+ draw_mode = draw_mode_t::BG;
draw_text();
text_offset_x = text_offset_y = 0;
}
@@ -1623,7 +1611,7 @@ void draw_stuff() {
for (text_offset_y = -1; text_offset_y < 2; text_offset_y++) {
if (text_offset_x == 0 && text_offset_y == 0) { continue; }
set_foreground_color(default_outline_color.get(*state));
- draw_mode = OUTLINE;
+ draw_mode = draw_mode_t::OUTLINE;
draw_text();
}
}
@@ -1637,7 +1625,7 @@ void draw_stuff() {
#endif /* BUILD_GUI */
// always draw text
- draw_mode = FG;
+ draw_mode = draw_mode_t::FG;
draw_text();
#ifdef BUILD_GUI
@@ -1874,10 +1862,10 @@ static void reload_config() {
initialisation(argc_copy, argv_copy);
}
-void free_specials(special_t *¤t) {
+void free_specials(special_node *¤t) {
if (current != nullptr) {
free_specials(current->next);
- if (current->type == GRAPH) { free(current->graph); }
+ if (current->type == text_node_t::GRAPH) { free(current->graph); }
delete current;
current = nullptr;
}
diff --git a/src/conky.h b/src/conky.h
index 1592a50b4..c7a357248 100644
--- a/src/conky.h
+++ b/src/conky.h
@@ -32,11 +32,14 @@
#define __STDC_FORMAT_MACROS
+#include "config.h"
+
#include
#include /* defines */
#include /* struct uname_s */
#include
#include
+
#include "colours.h"
#include "common.h" /* at least for struct dns_data */
#include "luamm.hh"
@@ -311,11 +314,6 @@ void set_updatereset(int);
int get_updatereset(void);
int get_total_updates(void);
-int dpi_scale(int value);
-
-int get_saved_coordinates_x(int);
-int get_saved_coordinates_y(int);
-
/* defined in conky.c */
int spaced_print(char *, int, const char *, int, ...)
__attribute__((format(printf, 3, 5)));
diff --git a/src/core.cc b/src/core.cc
index ad69e21cc..0ce2cbdcb 100644
--- a/src/core.cc
+++ b/src/core.cc
@@ -27,9 +27,12 @@
*
*/
+#include "config.h"
+
/* local headers */
-#include "core.h"
#include "algebra.h"
+#include "core.h"
+
#include "bsdapm.h"
#include "build.h"
#include "colour-settings.h"
@@ -40,11 +43,11 @@
#include "exec.h"
#include "i8k.h"
#include "misc.h"
+#include "proc.h"
#include "text_object.h"
#ifdef BUILD_IMLIB2
#include "conky-imlib2.h"
#endif /* BUILD_IMLIB2 */
-#include "proc.h"
#ifdef BUILD_MYSQL
#include "mysql.h"
#endif /* BUILD_MYSQL */
@@ -1893,9 +1896,10 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->callbacks.print = &print_combine;
obj->callbacks.free = &free_combine;
#ifdef BUILD_NVIDIA
- END OBJ_ARG(
- nvidia, 0,
- "nvidia needs an argument") if (set_nvidia_query(obj, arg, NONSPECIAL)) {
+ END OBJ_ARG(nvidia, 0, "nvidia needs an argument") if (set_nvidia_query(
+ obj, arg,
+ text_node_t::
+ NONSPECIAL)) {
CRIT_ERR_FREE(obj, free_at_crash,
"nvidia: invalid argument"
" specified: '%s'",
@@ -1905,7 +1909,8 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->callbacks.free = &free_nvidia;
END OBJ_ARG(
nvidiabar, 0,
- "nvidiabar needs an argument") if (set_nvidia_query(obj, arg, BAR)) {
+ "nvidiabar needs an argument") if (set_nvidia_query(obj, arg,
+ text_node_t::BAR)) {
CRIT_ERR_FREE(obj, free_at_crash,
"nvidiabar: invalid argument"
" specified: '%s'",
@@ -1915,7 +1920,9 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->callbacks.free = &free_nvidia;
END OBJ_ARG(
nvidiagraph, 0,
- "nvidiagraph needs an argument") if (set_nvidia_query(obj, arg, GRAPH)) {
+ "nvidiagraph needs an argument") if (set_nvidia_query(obj, arg,
+ text_node_t::
+ GRAPH)) {
CRIT_ERR_FREE(obj, free_at_crash,
"nvidiagraph: invalid argument"
" specified: '%s'",
@@ -1925,7 +1932,9 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->callbacks.free = &free_nvidia;
END OBJ_ARG(
nvidiagauge, 0,
- "nvidiagauge needs an argument") if (set_nvidia_query(obj, arg, GAUGE)) {
+ "nvidiagauge needs an argument") if (set_nvidia_query(obj, arg,
+ text_node_t::
+ GAUGE)) {
CRIT_ERR_FREE(obj, free_at_crash,
"nvidiagauge: invalid argument"
" specified: '%s'",
diff --git a/src/display-console.cc b/src/display-console.cc
index 7e1732351..eb2eeb0df 100644
--- a/src/display-console.cc
+++ b/src/display-console.cc
@@ -43,9 +43,11 @@ namespace {
conky::display_output_console console_output("console");
} // namespace
-void init_console_output() {}
-namespace priv {} // namespace priv
+template <>
+void register_output(display_outputs_t &outputs) {
+ outputs.push_back(&console_output);
+}
display_output_console::display_output_console(const std::string &name_)
: display_output_base(name_) {
diff --git a/src/display-file.cc b/src/display-file.cc
index 12dbac882..f1ff4c0f1 100644
--- a/src/display-file.cc
+++ b/src/display-file.cc
@@ -49,9 +49,10 @@ namespace {
conky::display_output_file file_output("file");
} // namespace
-extern void init_file_output() {}
-
-namespace priv {} // namespace priv
+template <>
+void register_output(display_outputs_t &outputs) {
+ outputs.push_back(&file_output);
+}
display_output_file::display_output_file(const std::string &name_)
: display_output_base(name_) {
diff --git a/src/display-http.cc b/src/display-http.cc
index 91e0a458b..78bfeee89 100644
--- a/src/display-http.cc
+++ b/src/display-http.cc
@@ -33,26 +33,20 @@
#include
#include
-#ifdef BUILD_HTTP
#include
-#endif /* BUILD_HTTP */
namespace conky {
namespace {
-
-#ifdef BUILD_HTTP
conky::display_output_http http_output;
-#else
-conky::disabled_display_output http_output_disabled("http", "BUILD_HTTP");
-#endif
-
} // namespace
-extern void init_http_output() {}
+template <>
+void register_output(display_outputs_t &outputs) {
+ outputs.push_back(&http_output);
+}
// TODO: cleanup namespace
// namespace priv {
-#ifdef BUILD_HTTP
#ifdef MHD_YES
/* older API */
#define MHD_Result int
@@ -130,12 +124,8 @@ std::string string_replace_all(std::string original, const std::string &oldpart,
return original;
}
-#endif /* BUILD_HTTP */
-
//} // namespace priv
-#ifdef BUILD_HTTP
-
display_output_http::display_output_http() : display_output_base("http") {
priority = 0;
httpd = NULL;
@@ -192,6 +182,4 @@ void display_output_http::draw_string(const char *s, int) {
webpage.append("
");
}
-#endif /* BUILD_HTTP */
-
} // namespace conky
diff --git a/src/display-http.hh b/src/display-http.hh
index b9d3ad5e9..300028600 100644
--- a/src/display-http.hh
+++ b/src/display-http.hh
@@ -23,6 +23,8 @@
#ifndef DISPLAY_HTTP_HH
#define DISPLAY_HTTP_HH
+#include "config.h"
+
#include
#include
#include
diff --git a/src/display-ncurses.cc b/src/display-ncurses.cc
index 86b1722eb..65fc3e5cc 100644
--- a/src/display-ncurses.cc
+++ b/src/display-ncurses.cc
@@ -35,33 +35,24 @@
#include
#include
#include
-#ifdef BUILD_NCURSES
+
#include
-#endif
-#ifdef BUILD_NCURSES
extern WINDOW* ncurses_window;
-#endif
namespace conky {
namespace {
-
-#ifdef BUILD_NCURSES
conky::display_output_ncurses ncurses_output;
-#else
-conky::disabled_display_output ncurses_output_disabled("ncurses",
- "BUILD_NCURSES");
-#endif
-
} // namespace
-extern void init_ncurses_output() {}
+template <>
+void register_output(display_outputs_t& outputs) {
+ outputs.push_back(&ncurses_output);
+}
// namespace priv {
//} // namespace priv
-#ifdef BUILD_NCURSES
-
#define COLORS_BUILTIN 8
Colour ncurses_colors[COLORS_BUILTIN + COLORS_CUSTOM] = {
@@ -96,7 +87,7 @@ Colour from_ncurses(int nccolor) {
if (nccolor >= 0 && nccolor < COLORS_BUILTIN + COLORS_CUSTOM) {
return ncurses_colors[nccolor];
}
- return error_colour;
+ return ERROR_COLOUR;
}
display_output_ncurses::display_output_ncurses()
@@ -179,7 +170,4 @@ void display_output_ncurses::flush() {
refresh();
clear();
}
-
-#endif /* BUILD_NCURSES */
-
} // namespace conky
diff --git a/src/display-ncurses.hh b/src/display-ncurses.hh
index d7e1f7c34..2d1c1a0b8 100644
--- a/src/display-ncurses.hh
+++ b/src/display-ncurses.hh
@@ -23,6 +23,8 @@
#ifndef DISPLAY_NCURSES_HH
#define DISPLAY_NCURSES_HH
+#include "config.h"
+
#include
#include
#include
diff --git a/src/display-output.cc b/src/display-output.cc
index fe9587419..fafcf8c45 100644
--- a/src/display-output.cc
+++ b/src/display-output.cc
@@ -27,7 +27,6 @@
#include
#include "display-output.hh"
-#include "logging.h"
#include
#include
@@ -35,28 +34,37 @@
#include
namespace conky {
-namespace {
-typedef std::unordered_map
- display_outputs_t;
-
-/*
- * We cannot construct this object statically, because order of object
- * construction in different modules is not defined, so register_source could be
- * called before this object is constructed. Therefore, we create it on the
- * first call to register_source.
- */
-display_outputs_t *display_outputs;
-
-} // namespace
-
-// HACK: force the linker to link all the objects in with test enabled
-extern void init_console_output();
-extern void init_ncurses_output();
-extern void init_file_output();
-extern void init_http_output();
-extern void init_x11_output();
-extern void init_wayland_output();
+inline void log_missing(const char *name, const char *flag) {
+ DBGP(
+ "%s display output disabled. Enable by recompiling with '%s' "
+ "flag enabled.",
+ name, flag);
+}
+#ifndef BUILD_HTTP
+template <>
+void register_output(display_outputs_t &outputs) {
+ log_missing("HTTP", "BUILD_HTTP");
+}
+#endif
+#ifndef BUILD_NCURSES
+template <>
+void register_output(display_outputs_t &outputs) {
+ log_missing("ncurses", "BUILD_NCURSES");
+}
+#endif
+#ifndef BUILD_WAYLAND
+template <>
+void register_output(display_outputs_t &outputs) {
+ log_missing("Wayland", "BUILD_WAYLAND");
+}
+#endif
+#ifndef BUILD_X11
+template <>
+void register_output(display_outputs_t &outputs) {
+ log_missing("X11", "BUILD_X11");
+}
+#endif
/*
* The selected and active display output.
@@ -69,55 +77,18 @@ std::vector active_display_outputs;
*/
std::vector current_display_outputs;
-namespace priv {
-void do_register_display_output(const std::string &name,
- display_output_base *output) {
- struct display_output_constructor {
- display_output_constructor() { display_outputs = new display_outputs_t(); }
- ~display_output_constructor() {
- delete display_outputs;
- display_outputs = nullptr;
- }
- };
- static display_output_constructor constructor;
-
- bool inserted = display_outputs->insert({name, output}).second;
- if (!inserted) {
- throw std::logic_error("Display output with name '" + name +
- "' already registered");
- }
-}
-
-} // namespace priv
-
-display_output_base::display_output_base(const std::string &name_)
- : name(name_), is_active(false), is_graphical(false), priority(-1) {
- priv::do_register_display_output(name, this);
-}
-
-disabled_display_output::disabled_display_output(const std::string &name,
- const std::string &define)
- : display_output_base(name) {
- priority = -2;
- // XXX some generic way of reporting errors? NORM_ERR?
- DBGP(
- "Support for display output '%s' has been disabled during compilation. "
- "Please recompile with '%s'",
- name.c_str(), define.c_str());
-}
-
bool initialize_display_outputs() {
- init_console_output();
- init_ncurses_output();
- init_file_output();
- init_http_output();
- init_x11_output();
- init_wayland_output();
-
std::vector outputs;
- outputs.reserve(display_outputs->size());
+ outputs.reserve(static_cast(output_t::OUTPUT_COUNT));
+ register_output(outputs);
+ register_output(outputs);
+ register_output(outputs);
+ register_output(outputs);
+ register_output(outputs);
+ register_output(outputs);
+
+ for (auto out : outputs) { NORM_ERR("FOUND: %s", out->name.c_str()); }
- for (auto &output : *display_outputs) { outputs.push_back(output.second); }
// Sort display outputs by descending priority, to try graphical ones first.
sort(outputs.begin(), outputs.end(), &display_output_base::priority_compare);
diff --git a/src/display-output.hh b/src/display-output.hh
index 45c65856c..e74733ef9 100644
--- a/src/display-output.hh
+++ b/src/display-output.hh
@@ -30,6 +30,7 @@
#include
#include "colours.h"
+#include "logging.h"
#include "luamm.hh"
namespace conky {
@@ -57,11 +58,11 @@ class display_output_base {
public:
const std::string name;
- bool is_active;
- bool is_graphical;
- int priority;
+ bool is_active = false;
+ bool is_graphical = false;
+ int priority = -1;
- explicit display_output_base(const std::string &name_);
+ explicit display_output_base(const std::string &name) : name(name){};
virtual ~display_output_base() {}
@@ -106,7 +107,11 @@ class display_output_base {
virtual void draw_arc(int /*x*/, int /*y*/, int /*w*/, int /*h*/, int /*a1*/,
int /*a2*/) {}
virtual void move_win(int /*x*/, int /*y*/) {}
- virtual int dpi_scale(int value) { return value; }
+ template ::value, T>::type>
+ T dpi_scale(T value) {
+ return value;
+ }
virtual void begin_draw_stuff() {}
virtual void end_draw_stuff() {}
@@ -137,6 +142,20 @@ class display_output_base {
virtual bool active() { return is_active; }
};
+using display_outputs_t = std::vector;
+
+enum class output_t : uint32_t {
+ CONSOLE,
+ NCURSES,
+ FILE,
+ HTTP,
+ X11,
+ WAYLAND,
+ OUTPUT_COUNT
+};
+template
+void register_output(display_outputs_t &outputs);
+
/*
* The selected and active display outputs.
*/
@@ -148,17 +167,6 @@ extern std::vector active_display_outputs;
*/
extern std::vector current_display_outputs;
-/*
- * Use this to declare a display output that has been disabled during
- * compilation. We can then print a nice error message telling the used which
- * setting to enable.
- */
-class disabled_display_output : public display_output_base {
- public:
- const std::string define;
- disabled_display_output(const std::string &name, const std::string &define);
-};
-
} // namespace conky
// XXX: move to namespace?
@@ -178,6 +186,21 @@ static inline conky::display_output_base *display_output() {
return nullptr;
}
+template ::value, T>::type>
+inline T dpi_scale(T value) {
+#ifdef BUILD_GUI
+ auto output = display_output();
+ if (output) {
+ return output->dpi_scale(value);
+ } else {
+ return value;
+ }
+#else /* BUILD_GUI */
+ return value;
+#endif /* BUILD_GUI */
+}
+
static inline void unset_display_output() {
conky::current_display_outputs.clear();
}
diff --git a/src/display-wayland.cc b/src/display-wayland.cc
index 9693a4663..9505eb4da 100644
--- a/src/display-wayland.cc
+++ b/src/display-wayland.cc
@@ -24,9 +24,8 @@
*
*/
-#include
+#include "display-wayland.hh"
-#ifdef BUILD_WAYLAND
#include
// #include "wayland.h"
#include
@@ -44,23 +43,18 @@
#include
#include
-#endif /* BUILD_WAYLAND */
-
#include
#include
#include
#include "conky.h"
-#include "display-wayland.hh"
+#include "display-output.hh"
#include "gui.h"
#include "llua.h"
#include "logging.h"
-#ifdef BUILD_X11
-#include "x11.h"
-#endif
-#ifdef BUILD_WAYLAND
+
#include "fonts.h"
-#endif
+
#ifdef BUILD_MOUSE_EVENTS
#include
#include