Skip to content

Commit

Permalink
Move dpi_scale to display-output.hh
Browse files Browse the repository at this point in the history
Signed-off-by: Tin Švagelj <[email protected]>
  • Loading branch information
Caellian committed Apr 23, 2024
1 parent c69dcaf commit 3093cdd
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 69 deletions.
9 changes: 5 additions & 4 deletions src/colours.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@

#include "colours.h"

#include "conky.h"
#include "gui.h"
#include "logging.h"

#include <optional>

#ifdef BUILD_X11
#include <X11/Xlib.h>
#include <string.h>
#include <strings.h>

#include <X11/Xlib.h>
#endif /* BUILD_X11 */

// sourced from X11, doesn't actually need X11
#include "x11-color.h"

Colour Colour::from_argb32(uint32_t argb) {
Expand Down
11 changes: 8 additions & 3 deletions src/colours.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#pragma once

#include <config.h>
#ifndef _COLOURS_H_
#define _COLOURS_H_

#include "config.h"

#include <cassert>
#include <climits>
#include <memory>
#include <optional>
#include <string>
#include <unordered_map>

#ifdef BUILD_X11
#include <X11/Xlib.h>
#endif /* BUILD_X11 */
Expand Down Expand Up @@ -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_ */
7 changes: 5 additions & 2 deletions src/conky-imlib2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
3 changes: 2 additions & 1 deletion src/conky-imlib2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 2 additions & 13 deletions src/conky.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#include "conky.h"

#include "config.h"

#include <algorithm>
#include <cerrno>
#include <climits>
Expand Down Expand Up @@ -63,7 +65,6 @@
#endif /* HAVE_DIRENT_H */

#include "common.h"
#include "config.h"
#include "text_object.h"

#ifdef BUILD_WAYLAND
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions src/conky.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@

#define __STDC_FORMAT_MACROS

#include "config.h"

#include <arpa/inet.h>
#include <config.h> /* defines */
#include <sys/utsname.h> /* struct uname_s */
#include <csignal>
#include <memory>

#include "colours.h"
#include "common.h" /* at least for struct dns_data */
#include "luamm.hh"
Expand Down Expand Up @@ -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);

Expand Down
25 changes: 17 additions & 8 deletions src/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 */
Expand Down Expand Up @@ -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'",
Expand All @@ -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'",
Expand All @@ -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'",
Expand All @@ -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'",
Expand Down
4 changes: 0 additions & 4 deletions src/display-http.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@

#include "config.h"

#ifndef BUILD_HTTP
#error display-http.hh included when BUILD_HTTP is disabled
#endif

#include <limits>
#include <string>
#include <type_traits>
Expand Down
4 changes: 0 additions & 4 deletions src/display-ncurses.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@

#include "config.h"

#ifndef BUILD_NCURSES
#error display-ncurses.hh included when BUILD_NCURSES is disabled
#endif

#include <limits>
#include <string>
#include <type_traits>
Expand Down
21 changes: 20 additions & 1 deletion src/display-output.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T, typename = typename std::enable_if<
std::is_arithmetic<T>::value, T>::type>
T dpi_scale(T value) {
return value;
}

virtual void begin_draw_stuff() {}
virtual void end_draw_stuff() {}
Expand Down Expand Up @@ -182,6 +186,21 @@ static inline conky::display_output_base *display_output() {
return nullptr;
}

template <typename T, typename = typename std::enable_if<
std::is_arithmetic<T>::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();
}
Expand Down
6 changes: 4 additions & 2 deletions src/display-wayland.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T, typename>
T display_output_wayland::dpi_scale(T value) {
return value;
}

void display_output_wayland::end_draw_stuff() {
window_commit_buffer(global_window);
Expand Down
8 changes: 3 additions & 5 deletions src/display-wayland.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@

#include "config.h"

#ifndef BUILD_WAYLAND
#error display-wayland.hh included when BUILD_WAYLAND is disabled
#endif

#include <limits>
#include <string>
#include <type_traits>
Expand Down Expand Up @@ -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 <typename T, typename = typename std::enable_if<
std::is_arithmetic<T>::value, T>::type>
T dpi_scale(T value);

virtual void end_draw_stuff();
virtual void clear_text(int);
Expand Down
6 changes: 4 additions & 2 deletions src/display-x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T, typename>
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;
}
Expand Down
8 changes: 3 additions & 5 deletions src/display-x11.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@

#include "config.h"

#ifndef BUILD_X11
#error display-x11.hh included when BUILD_X11 is disabled
#endif

#include <limits>
#include <string>
#include <type_traits>
Expand Down Expand Up @@ -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 <typename T, typename = typename std::enable_if<
std::is_arithmetic<T>::value, T>::type>
T dpi_scale(T value);

virtual void end_draw_stuff();
virtual void clear_text(int);
Expand Down
6 changes: 3 additions & 3 deletions src/gui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iostream>
#endif
Expand Down
6 changes: 4 additions & 2 deletions src/text_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
#ifndef _TEXT_OBJECT_H
#define _TEXT_OBJECT_H

#include <stdint.h> /* uint8_t */
#include "config.h" /* for the defines */
#include "config.h"

#include "exec.h"
#include "specials.h" /* enum special_types */

#include <cstdint> /* uint8_t */

enum class draw_mode_t : uint32_t {
BG = static_cast<uint32_t>(text_node_t::BG),
FG = static_cast<uint32_t>(text_node_t::FG),
Expand Down
8 changes: 0 additions & 8 deletions src/x11-settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3093cdd

Please sign in to comment.