Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use HCL color space (Rec.2020 for luma) instead of HSV #1235

Merged
merged 24 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cmake/ConkyBuildOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,6 @@ option(BUILD_PULSEAUDIO
option(BUILD_INTEL_BACKLIGHT
"Enable support for Intel backlight" false)

option(BUILD_HSV_GRADIENT "Enable gradient in HSV colour space" true)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


message(STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS})
message(STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS})

Expand Down
14 changes: 12 additions & 2 deletions doc/config_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ values:
Substitute N by a number between 0 and 9 inclusive. Use the same
format as a font variable.
- name: forced_redraw
desc: Boolean value, if true, Conky will redraw everything when you switch the workspace. This may cause delays/flickering on some WMs.
desc: |-
Boolean value, if true, Conky will redraw everything when you switch the
workspace. This may cause delays/flickering on some WMs.
- name: format_human_readable
desc: |-
If enabled, values which are in bytes will be printed in
Expand Down Expand Up @@ -373,7 +375,8 @@ values:
desc: |-
If own_window_transparent no, set a specified background
colour. Takes either a hex value (e.g. '#ffffff'),
a shorthand hex value (e.g. '#fff'), or a valid RGB name (see `/usr/lib/X11/rgb.txt`).
a shorthand hex value (e.g. '#fff'), or a valid RGB nam
(see `/usr/lib/X11/rgb.txt`).
default: black
args:
- seconds
Expand Down Expand Up @@ -433,6 +436,13 @@ values:
desc: Shows the time range covered by a graph.
- name: show_graph_scale
desc: Shows the maximum value in scaled graphs.
- name: graph_gradient_mode
desc: |-
Changes the color space used for interpolation. Arguments are hcl, hsv,
and rgb (default).
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add args here, like:

    args:
      - (rbg|hcl|hsv)

args:
- (rbg|hcl|hsv)
default: rgb
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, good catch. Thanks!

- name: stippled_borders
desc: Border stippling (dashing) in pixels.
- name: temperature_unit
Expand Down
7 changes: 2 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ set(conky_sources
exec.h
fs.cc
fs.h
gradient.cc
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're including the sources like this, we can remove all references to BUILD_HSV_GRADIENT from the CMake files and source. The build option is defined in ConkyBuildOptions.cmake.

gradient.h
mail.cc
mail.h
misc.cc
Expand Down Expand Up @@ -304,11 +306,6 @@ if(BUILD_INTEL_BACKLIGHT)
set(optional_sources ${optional_sources} ${intel_backlight})
endif(BUILD_INTEL_BACKLIGHT)

if(BUILD_HSV_GRADIENT)
set(hsv_gradient hsv_gradient.cc hsv_gradient.h)
set(optional_sources ${optional_sources} ${hsv_gradient})
endif(BUILD_HSV_GRADIENT)

if(BUILD_TESTS)
# Create a library strictly for testing
add_library(conky_core ${conky_sources} ${optional_sources})
Expand Down
16 changes: 9 additions & 7 deletions src/cmus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ void cmus_cb::work() {

} else if (strncmp(line, "position ", 9) == 0) {
cmus.curtime = line + 9;
cmus.timeleft =
strtol(cmus.totaltime.c_str(), nullptr, 10) -
strtol(cmus.curtime.c_str(), nullptr, 10);
cmus.timeleft = strtol(cmus.totaltime.c_str(), nullptr, 10) -
strtol(cmus.curtime.c_str(), nullptr, 10);
if (cmus.curtime.size() > 0) {
cmus.progress = static_cast<float>(strtol(cmus.curtime.c_str(), nullptr, 10)) /
strtol(cmus.totaltime.c_str(), nullptr, 10);
cmus.progress =
static_cast<float>(strtol(cmus.curtime.c_str(), nullptr, 10)) /
strtol(cmus.totaltime.c_str(), nullptr, 10);
} else {
cmus.progress = 0;
}
Expand Down Expand Up @@ -189,7 +189,8 @@ void print_cmus_totaltime(struct text_object *obj, char *p,
lround(music_player_interval.get(*state) / active_update_interval()), 1l);
const cmus_result &cmus =
conky::register_cb<cmus_cb>(period)->get_result_copy();
format_seconds_short(p, p_max_size, strtol(cmus.totaltime.c_str(), nullptr, 10));
format_seconds_short(p, p_max_size,
strtol(cmus.totaltime.c_str(), nullptr, 10));
}

void print_cmus_timeleft(struct text_object *obj, char *p,
Expand All @@ -209,7 +210,8 @@ void print_cmus_curtime(struct text_object *obj, char *p,
lround(music_player_interval.get(*state) / active_update_interval()), 1l);
const cmus_result &cmus =
conky::register_cb<cmus_cb>(period)->get_result_copy();
format_seconds_short(p, p_max_size, strtol(cmus.curtime.c_str(), nullptr, 10));
format_seconds_short(p, p_max_size,
strtol(cmus.curtime.c_str(), nullptr, 10));
}

#undef CMUS_PRINT_GENERATOR
63 changes: 0 additions & 63 deletions src/colours.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,69 +83,6 @@ unsigned int adjust_colours(unsigned int colour) {
return colour;
}

/* this function returns the next colour between two colours for a gradient */
std::unique_ptr<unsigned long[]> do_gradient(int width,
unsigned long first_colour,
unsigned long last_colour) {
int red1, green1, blue1; // first colour
int red2, green2, blue2; // last colour
int reddiff, greendiff, bluediff; // difference
short redshift = (2 * colour_depth / 3 + colour_depth % 3);
short greenshift = (colour_depth / 3);

// Make sure the width is always at least 2
width = std::max(2, width);

std::unique_ptr<unsigned long[]> colours(new unsigned long[width]);

if (colour_depth == 0) { set_up_gradient(); }
red1 = (first_colour & redmask) >> redshift;
green1 = (first_colour & greenmask) >> greenshift;
blue1 = first_colour & bluemask;
red2 = (last_colour & redmask) >> redshift;
green2 = (last_colour & greenmask) >> greenshift;
blue2 = last_colour & bluemask;
reddiff = abs(red1 - red2);
greendiff = abs(green1 - green2);
bluediff = abs(blue1 - blue2);
#ifdef HAVE_OPENMP
#pragma omp parallel for schedule(dynamic, 10) shared(colours)
#endif /* HAVE_OPENMP */
for (int i = 0; i < width; i++) {
int red3 = 0, green3 = 0, blue3 = 0; // colour components

float factor = (static_cast<float>(i) / (width - 1));

/* the '+ 0.5' bit rounds our floats to ints properly */
if (red1 >= red2) {
red3 = -(factor * reddiff) - 0.5;
} else if (red1 < red2) {
red3 = factor * reddiff + 0.5;
}
if (green1 >= green2) {
green3 = -(factor * greendiff) - 0.5;
} else if (green1 < green2) {
green3 = factor * greendiff + 0.5;
}
if (blue1 >= blue2) {
blue3 = -(factor * bluediff) - 0.5;
} else if (blue1 < blue2) {
blue3 = factor * bluediff + 0.5;
}
red3 += red1;
green3 += green1;
blue3 += blue1;
if (red3 < 0) { red3 = 0; }
if (green3 < 0) { green3 = 0; }
if (blue3 < 0) { blue3 = 0; }
if (red3 > bluemask) { red3 = bluemask; }
if (green3 > bluemask) { green3 = bluemask; }
if (blue3 > bluemask) { blue3 = bluemask; }
colours[i] = (red3 << redshift) | (green3 << greenshift) | blue3;
}
return colours;
}

#ifdef BUILD_X11
long get_x11_color(const char *name) {
XColor color;
Expand Down
1 change: 0 additions & 1 deletion src/colours.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <string>

unsigned int adjust_colours(unsigned int);
std::unique_ptr<unsigned long[]> do_gradient(int, unsigned long, unsigned long);

long get_x11_color(const std::string &colour);
// XXX: when everyone uses C++ strings, remove this C version
Expand Down
3 changes: 2 additions & 1 deletion src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ void print_cached(struct text_object *obj, char *p, unsigned int p_max_size) {
p_max_size);
}

void print_free_bufcache(struct text_object *obj, char *p, unsigned int p_max_size) {
void print_free_bufcache(struct text_object *obj, char *p,
unsigned int p_max_size) {
human_readable(apply_base_multiplier(obj->data.s, info.free_bufcache), p,
p_max_size);
}
Expand Down
40 changes: 29 additions & 11 deletions src/conky.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@
#include "openbsd.h"
#endif /* __OpenBSD__ */

#ifdef BUILD_HSV_GRADIENT
#include "hsv_gradient.h"
#endif /* BUILD_HSV_GRADIENT */
#include "gradient.h"

#ifdef BUILD_OLD_CONFIG
#include "convertconf.h"
Expand Down Expand Up @@ -294,12 +292,19 @@ conky::range_config_setting<int> diskio_avg_samples("diskio_avg_samples", 1, 14,
2, true);

#ifdef BUILD_GUI

/* graph */
conky::simple_config_setting<bool> show_graph_scale("show_graph_scale", false,
false);
conky::simple_config_setting<bool> show_graph_range("show_graph_range", false,
false);

enum gradient_state { RGB_GRADIENT = 0, HSV_GRADIENT, HCL_GRADIENT };
template <>
conky::lua_traits<gradient_state>::Map conky::lua_traits<gradient_state>::map =
{{"rgb", RGB_GRADIENT}, {"hsv", HSV_GRADIENT}, {"hcl", HCL_GRADIENT}};
static conky::simple_config_setting<gradient_state> graph_gradient_mode(
"graph_gradient_mode", RGB_GRADIENT, false);

/* Position on the screen */
conky::simple_config_setting<int> gap_x("gap_x", 5, true);
conky::simple_config_setting<int> gap_y("gap_y", 60, true);
Expand Down Expand Up @@ -401,6 +406,22 @@ int dpi_scale(int value) {
#endif /* BUILD_GUI */
}

#ifdef BUILD_GUI
conky::gradient_factory *create_gradient_factory(int width,
unsigned long first_colour,
unsigned long last_colour) {
switch (graph_gradient_mode.get(*state)) {
case RGB_GRADIENT:
return new conky::rgb_gradient_factory(width, first_colour, last_colour);
case HSV_GRADIENT:
return new conky::hsv_gradient_factory(width, first_colour, last_colour);
case HCL_GRADIENT:
return new conky::hcl_gradient_factory(width, first_colour, last_colour);
}
return nullptr;
}
#endif /* BUILD_GUI */

/* formatted text to render on screen, generated in generate_text(),
* drawn in draw_stuff() */

Expand Down Expand Up @@ -1294,13 +1315,10 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
std::unique_ptr<unsigned long[]> tmpcolour;

if (current->last_colour != 0 || current->first_colour != 0) {
#ifdef BUILD_HSV_GRADIENT
tmpcolour = do_hsv_gradient(w - 1, current->last_colour,
current->first_colour);
#else /* BUILD_HSV_GRADIENT */
tmpcolour = do_gradient(w - 1, current->last_colour,
current->first_colour);
#endif /* BUILD_HSV_GRADIENT */
auto factory = create_gradient_factory(w, current->last_colour,
current->first_colour);
tmpcolour = factory->create_gradient();
delete factory;
}
colour_idx = 0;
for (i = w - 2; i > -1; i--) {
Expand Down
34 changes: 22 additions & 12 deletions src/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(freq, nullptr) get_cpu_count();
if ((arg == nullptr) || strlen(arg) >= 3 ||
strtol(&arg[0], nullptr, 10) == 0 ||
static_cast<unsigned int>(strtol(&arg[0], nullptr, 10)) > info.cpu_count) {
static_cast<unsigned int>(strtol(&arg[0], nullptr, 10)) >
info.cpu_count) {
obj->data.i = 1;
/* NORM_ERR("freq: Invalid CPU number or you don't have that many CPUs! "
"Displaying the clock for CPU 1."); */
Expand All @@ -445,7 +446,8 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(freq_g, nullptr) get_cpu_count();
if ((arg == nullptr) || strlen(arg) >= 3 ||
strtol(&arg[0], nullptr, 10) == 0 ||
static_cast<unsigned int>(strtol(&arg[0], nullptr, 10)) > info.cpu_count) {
static_cast<unsigned int>(strtol(&arg[0], nullptr, 10)) >
info.cpu_count) {
obj->data.i = 1;
/* NORM_ERR("freq_g: Invalid CPU number or you don't have that many "
"CPUs! Displaying the clock for CPU 1."); */
Expand All @@ -457,7 +459,8 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(cpugovernor, nullptr) get_cpu_count();
if ((arg == nullptr) || strlen(arg) >= 3 ||
strtol(&arg[0], nullptr, 10) == 0 ||
static_cast<unsigned int>(strtol(&arg[0], nullptr, 10)) > info.cpu_count) {
static_cast<unsigned int>(strtol(&arg[0], nullptr, 10)) >
info.cpu_count) {
obj->data.i = 1;
/* NORM_ERR("cpugovernor: Invalid CPU number or you don't have that "
"many CPUs! Displaying the scaling governor for CPU 1."); */
Expand All @@ -484,7 +487,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
#if defined(__linux__)
END OBJ(voltage_mv, 0) get_cpu_count();
if (!arg || strlen(arg) >= 3 || strtol(&arg[0], nullptr, 10) == 0 ||
(unsigned int)strtol(&arg[0], nullptr, 10) > info.cpu_count) {
(unsigned int)strtol(&arg[0], nullptr, 10) > info.cpu_count) {
obj->data.i = 1;
/* NORM_ERR("voltage_mv: Invalid CPU number or you don't have that many "
"CPUs! Displaying voltage for CPU 1."); */
Expand All @@ -494,7 +497,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
obj->callbacks.print = &print_voltage_mv;
END OBJ(voltage_v, 0) get_cpu_count();
if (!arg || strlen(arg) >= 3 || strtol(&arg[0], nullptr, 10) == 0 ||
(unsigned int)strtol(&arg[0], nullptr, 10) > info.cpu_count) {
(unsigned int)strtol(&arg[0], nullptr, 10) > info.cpu_count) {
obj->data.i = 1;
/* NORM_ERR("voltage_v: Invalid CPU number or you don't have that many "
"CPUs! Displaying voltage for CPU 1."); */
Expand Down Expand Up @@ -1029,20 +1032,24 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(fs_used, &update_fs_stats) init_fs(obj, arg);
obj->callbacks.print = &print_fs_used;
#ifdef BUILD_GUI
END OBJ(hr, nullptr) obj->data.l = arg != nullptr ? strtol(arg, nullptr, 10) : 1;
END OBJ(hr, nullptr) obj->data.l =
arg != nullptr ? strtol(arg, nullptr, 10) : 1;
obj->callbacks.print = &new_hr;
#endif /* BUILD_GUI */
END OBJ(nameserver, &update_dns_data) parse_nameserver_arg(obj, arg);
obj->callbacks.print = &print_nameserver;
obj->callbacks.free = &free_dns_data;
END OBJ(offset, nullptr) obj->data.l = arg != nullptr ? strtol(arg, nullptr, 10) : 1;
END OBJ(offset, nullptr) obj->data.l =
arg != nullptr ? strtol(arg, nullptr, 10) : 1;
obj->callbacks.print = &new_offset;
END OBJ(voffset, nullptr) obj->data.l = arg != nullptr ? strtol(arg, nullptr, 10) : 1;
END OBJ(voffset, nullptr) obj->data.l =
arg != nullptr ? strtol(arg, nullptr, 10) : 1;
obj->callbacks.print = &new_voffset;
END OBJ(save_coordinates, nullptr) obj->data.l =
arg != nullptr ? strtol(arg, nullptr, 10) : 0;
obj->callbacks.print = &new_save_coordinates;
END OBJ_ARG(goto, nullptr, "goto needs arguments") obj->data.l = strtol(arg, nullptr, 10);
END OBJ_ARG(goto, nullptr, "goto needs arguments") obj->data.l =
strtol(arg, nullptr, 10);
obj->callbacks.print = &new_goto;
#ifdef BUILD_GUI
END OBJ(tab, nullptr) scan_tab(obj, arg);
Expand Down Expand Up @@ -1505,17 +1512,20 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
parse_net_stat_arg(obj, arg, free_at_crash);
obj->callbacks.print = &print_totalup;
END OBJ(updates, nullptr) obj->callbacks.print = &print_updates;
END OBJ_IF(if_updatenr, nullptr) obj->data.i = arg != nullptr ? strtol(arg, nullptr, 10) : 0;
END OBJ_IF(if_updatenr, nullptr) obj->data.i =
arg != nullptr ? strtol(arg, nullptr, 10) : 0;
if (obj->data.i == 0) {
CRIT_ERR(obj, free_at_crash,
"if_updatenr needs a number above 0 as argument");
}
set_updatereset(obj->data.i > get_updatereset() ? obj->data.i
: get_updatereset());
obj->callbacks.iftest = &updatenr_iftest;
END OBJ(alignr, nullptr) obj->data.l = arg != nullptr ? strtol(arg, nullptr, 10) : 1;
END OBJ(alignr, nullptr) obj->data.l =
arg != nullptr ? strtol(arg, nullptr, 10) : 1;
obj->callbacks.print = &new_alignr;
END OBJ(alignc, nullptr) obj->data.l = arg != nullptr ? strtol(arg, nullptr, 10) : 0;
END OBJ(alignc, nullptr) obj->data.l =
arg != nullptr ? strtol(arg, nullptr, 10) : 0;
obj->callbacks.print = &new_alignc;
END OBJ(upspeed, &update_net_stats)
parse_net_stat_arg(obj, arg, free_at_crash);
Expand Down
Loading