diff --git a/src/colours.cc b/src/colours.cc index 9392ea336..0de586e18 100644 --- a/src/colours.cc +++ b/src/colours.cc @@ -29,16 +29,17 @@ #include "colours.h" -#include "conky.h" -#include "gui.h" #include "logging.h" +#include + #ifdef BUILD_X11 +#include #include #include - -#include #endif /* BUILD_X11 */ + +// sourced from X11, doesn't actually need X11 #include "x11-color.h" Colour Colour::from_argb32(uint32_t argb) { diff --git a/src/colours.h b/src/colours.h index 12861bf1b..a6d526816 100644 --- a/src/colours.h +++ b/src/colours.h @@ -26,15 +26,18 @@ * along with this program. If not, see . * */ -#pragma once -#include +#ifndef _COLOURS_H_ +#define _COLOURS_H_ + +#include "config.h" + #include #include #include -#include #include #include + #ifdef BUILD_X11 #include #endif /* BUILD_X11 */ @@ -92,3 +95,5 @@ struct Colour { const Colour ERROR_COLOUR = Colour{UINT8_MAX, 0, 0, UINT8_MAX}; Colour parse_color(const std::string &color); + +#endif /* _COLOURS_H_ */ diff --git a/src/conky-imlib2.cc b/src/conky-imlib2.cc index c898498b7..f07ebe751 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" @@ -292,3 +293,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..18336f6c1 100644 --- a/src/conky-imlib2.h +++ b/src/conky-imlib2.h @@ -24,7 +24,8 @@ #ifndef _CONKY_IMBLI2_H_ #define _CONKY_IMBLI2_H_ -#include "conky.h" +#include "setting.hh" +#include "text_object.h" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wvariadic-macros" diff --git a/src/conky.cc b/src/conky.cc index 99222d7f3..2ebeff94a 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -29,6 +29,8 @@ #include "conky.h" +#include "config.h" + #include #include #include @@ -63,7 +65,6 @@ #endif /* HAVE_DIRENT_H */ #include "common.h" -#include "config.h" #include "text_object.h" #ifdef BUILD_WAYLAND @@ -407,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) { diff --git a/src/conky.h b/src/conky.h index 1592a50b4..bd2059a8f 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,8 +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); diff --git a/src/core.cc b/src/core.cc index 6145a17fb..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, text_node_t::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, text_node_t::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, text_node_t::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, text_node_t::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-http.hh b/src/display-http.hh index 550b25fb1..300028600 100644 --- a/src/display-http.hh +++ b/src/display-http.hh @@ -25,10 +25,6 @@ #include "config.h" -#ifndef BUILD_HTTP -#error display-http.hh included when BUILD_HTTP is disabled -#endif - #include #include #include diff --git a/src/display-ncurses.hh b/src/display-ncurses.hh index 6c2e4ff09..2d1c1a0b8 100644 --- a/src/display-ncurses.hh +++ b/src/display-ncurses.hh @@ -25,10 +25,6 @@ #include "config.h" -#ifndef BUILD_NCURSES -#error display-ncurses.hh included when BUILD_NCURSES is disabled -#endif - #include #include #include diff --git a/src/display-output.hh b/src/display-output.hh index 27f95bbb0..e74733ef9 100644 --- a/src/display-output.hh +++ b/src/display-output.hh @@ -107,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() {} @@ -182,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 c8fd8c5df..9505eb4da 100644 --- a/src/display-wayland.cc +++ b/src/display-wayland.cc @@ -913,8 +913,10 @@ void display_output_wayland::move_win(int x, int y) { // window.y = y; // TODO } - -int display_output_wayland::dpi_scale(int value) { return value; } +template +T display_output_wayland::dpi_scale(T value) { + return value; +} void display_output_wayland::end_draw_stuff() { window_commit_buffer(global_window); diff --git a/src/display-wayland.hh b/src/display-wayland.hh index e6d26896f..6bc60da5f 100644 --- a/src/display-wayland.hh +++ b/src/display-wayland.hh @@ -25,10 +25,6 @@ #include "config.h" -#ifndef BUILD_WAYLAND -#error display-wayland.hh included when BUILD_WAYLAND is disabled -#endif - #include #include #include @@ -75,7 +71,9 @@ class display_output_wayland : public display_output_base { virtual void fill_rect(int, int, int, int); virtual void draw_arc(int, int, int, int, int, int); virtual void move_win(int, int); - virtual int dpi_scale(int); + template ::value, T>::type> + T dpi_scale(T value); virtual void end_draw_stuff(); virtual void clear_text(int); diff --git a/src/display-x11.cc b/src/display-x11.cc index 4bce1d3dc..f9b179149 100644 --- a/src/display-x11.cc +++ b/src/display-x11.cc @@ -974,10 +974,12 @@ void display_output_x11::move_win(int x, int y) { #endif /* OWN_WINDOW */ } -int display_output_x11::dpi_scale(int value) { +const size_t PIXELS_PER_INCH = 96; +template +T display_output_x11::dpi_scale(T value) { #if defined(BUILD_XFT) if (use_xft.get(*state) && xft_dpi > 0) { - return (value * xft_dpi + (value > 0 ? 48 : -48)) / 96; + return (value * xft_dpi + (value > 0 ? 48 : -48)) / PIXELS_PER_INCH; } else { return value; } diff --git a/src/display-x11.hh b/src/display-x11.hh index c34795d66..131a886e0 100644 --- a/src/display-x11.hh +++ b/src/display-x11.hh @@ -25,10 +25,6 @@ #include "config.h" -#ifndef BUILD_X11 -#error display-x11.hh included when BUILD_X11 is disabled -#endif - #include #include #include @@ -73,7 +69,9 @@ class display_output_x11 : public display_output_base { virtual void fill_rect(int, int, int, int); virtual void draw_arc(int, int, int, int, int, int); virtual void move_win(int, int); - virtual int dpi_scale(int); + template ::value, T>::type> + T dpi_scale(T value); virtual void end_draw_stuff(); virtual void clear_text(int); diff --git a/src/gui.cc b/src/gui.cc index 9bd931ed5..5e6d242e2 100644 --- a/src/gui.cc +++ b/src/gui.cc @@ -37,9 +37,9 @@ #include "wl.h" #endif /* BUILD_WAYLAND */ -#ifdef BUILD_IMLIB2 -#include "conky-imlib2.h" -#endif /* BUILD_IMLIB2 */ +// #ifdef BUILD_IMLIB2 +// #include "conky-imlib2.h" +// #endif /* BUILD_IMLIB2 */ #ifndef OWN_WINDOW #include #endif diff --git a/src/text_object.h b/src/text_object.h index c21bb13b7..b6f3c6d5b 100644 --- a/src/text_object.h +++ b/src/text_object.h @@ -29,11 +29,13 @@ #ifndef _TEXT_OBJECT_H #define _TEXT_OBJECT_H -#include /* uint8_t */ -#include "config.h" /* for the defines */ +#include "config.h" + #include "exec.h" #include "specials.h" /* enum special_types */ +#include /* uint8_t */ + enum class draw_mode_t : uint32_t { BG = static_cast(text_node_t::BG), FG = static_cast(text_node_t::FG), diff --git a/src/x11-settings.cc b/src/x11-settings.cc index 09abcb51e..d8b4effa6 100644 --- a/src/x11-settings.cc +++ b/src/x11-settings.cc @@ -124,11 +124,3 @@ priv::use_xdbe_setting use_xdbe; #else priv::use_xpmdb_setting use_xpmdb; #endif - -#ifdef BUILD_IMLIB2 -/* - * the only reason this is not in imlib2.cc is so that we can be sure it's - * setter executes after use_xdbe - */ -imlib_cache_size_setting imlib_cache_size; -#endif