From a39015b7bd01d62fb254bb186c8533d934fb50cd Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Fri, 24 Feb 2023 08:43:15 -0500 Subject: [PATCH] Apply `clang-format`. --- src/colour-settings.cc | 11 ++++---- src/colour-settings.h | 2 +- src/colours.cc | 2 +- src/colours.h | 6 ++-- src/conky.cc | 12 ++++++-- src/conky.h | 2 +- src/core.cc | 38 ++++++++++++++++---------- src/display-ncurses.cc | 62 +++++++++++++++++++++--------------------- src/display-output.hh | 2 +- src/display-wayland.cc | 28 +++++++++---------- src/display-x11.cc | 7 +++-- src/x11.cc | 4 +-- 12 files changed, 96 insertions(+), 80 deletions(-) diff --git a/src/colour-settings.cc b/src/colour-settings.cc index c6d58f7a..3aa67c76 100644 --- a/src/colour-settings.cc +++ b/src/colour-settings.cc @@ -34,9 +34,10 @@ void colour_setting::lua_setter(lua::state &l, bool init) { } } // namespace priv -priv::colour_setting color[COLORS_CUSTOM] = {{"color0", white_argb32}, {"color1", white_argb32}, - {"color2", white_argb32}, {"color3", white_argb32}, - {"color4", white_argb32}, {"color5", white_argb32}, - {"color6", white_argb32}, {"color7", white_argb32}, - {"color8", white_argb32}, {"color9", white_argb32}}; +priv::colour_setting color[COLORS_CUSTOM] = { + {"color0", white_argb32}, {"color1", white_argb32}, + {"color2", white_argb32}, {"color3", white_argb32}, + {"color4", white_argb32}, {"color5", white_argb32}, + {"color6", white_argb32}, {"color7", white_argb32}, + {"color8", white_argb32}, {"color9", white_argb32}}; priv::colour_setting default_color("default_color", white_argb32); diff --git a/src/colour-settings.h b/src/colour-settings.h index bbed97db..646d8695 100644 --- a/src/colour-settings.h +++ b/src/colour-settings.h @@ -23,8 +23,8 @@ */ #pragma once -#include "config.h" #include "colours.h" +#include "config.h" #include "setting.hh" namespace priv { diff --git a/src/colours.cc b/src/colours.cc index ab32a97e..aa9446cd 100644 --- a/src/colours.cc +++ b/src/colours.cc @@ -51,7 +51,7 @@ Colour Colour::from_argb32(uint32_t argb) { return out; } -Colour error_colour { 0xff, 0x00, 0x00, 0xff }; +Colour error_colour{0xff, 0x00, 0x00, 0xff}; Colour parse_color(const char *name) { unsigned short r, g, b; diff --git a/src/colours.h b/src/colours.h index 803773a4..1d989c02 100644 --- a/src/colours.h +++ b/src/colours.h @@ -29,10 +29,10 @@ #ifndef _COLOURS_H #define _COLOURS_H -#include -#include #include #include +#include +#include #ifdef BUILD_X11 #include "x11.h" #endif /* BUILD_X11 */ @@ -43,7 +43,7 @@ struct Colour { uint8_t blue; uint8_t alpha; -public: + public: // Compare two instances. bool operator==(const Colour &c) const { return c.red == red && c.green == green && c.blue == blue && diff --git a/src/conky.cc b/src/conky.cc index 1cd5b14b..30c308cb 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -1432,16 +1432,22 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) { break; #endif /* BUILD_GUI */ case FG: - if (draw_mode == FG) { set_foreground_color(Colour::from_argb32(current->arg)); } + if (draw_mode == FG) { + set_foreground_color(Colour::from_argb32(current->arg)); + } break; #ifdef BUILD_GUI case BG: - if (draw_mode == BG) { set_foreground_color(Colour::from_argb32(current->arg)); } + if (draw_mode == BG) { + set_foreground_color(Colour::from_argb32(current->arg)); + } break; case OUTLINE: - if (draw_mode == OUTLINE) { set_foreground_color(Colour::from_argb32(current->arg)); } + if (draw_mode == OUTLINE) { + set_foreground_color(Colour::from_argb32(current->arg)); + } break; case OFFSET: diff --git a/src/conky.h b/src/conky.h index b83269c9..646fb4ff 100644 --- a/src/conky.h +++ b/src/conky.h @@ -37,9 +37,9 @@ #include /* struct uname_s */ #include #include +#include "colours.h" #include "common.h" /* at least for struct dns_data */ #include "luamm.hh" -#include "colours.h" #if defined(HAS_MCHECK_H) #include diff --git a/src/core.cc b/src/core.cc index fa0e799a..bf007263 100644 --- a/src/core.cc +++ b/src/core.cc @@ -32,8 +32,8 @@ #include "algebra.h" #include "bsdapm.h" #include "build.h" -#include "colours.h" #include "colour-settings.h" +#include "colours.h" #include "combine.h" #include "diskio.h" #include "entropy.h" @@ -751,7 +751,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, #endif /* BUILD_GUI */ END OBJ(color, nullptr) #ifdef BUILD_GUI - if (out_to_gui(*state)) { + if (out_to_gui(*state)) { Colour c = arg != nullptr ? parse_color(arg) : default_color.get(*state); obj->data.l = c.to_argb32(); set_current_text_color(c); @@ -767,34 +767,44 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, obj->callbacks.print = &new_fg; #ifdef BUILD_GUI END OBJ(color0, nullptr) Colour c = color[0].get(*state); - obj->data.l = c.to_argb32(); set_current_text_color(c); + obj->data.l = c.to_argb32(); + set_current_text_color(c); obj->callbacks.print = &new_fg; END OBJ(color1, nullptr) Colour c = color[1].get(*state); - obj->data.l = c.to_argb32(); set_current_text_color(c); + obj->data.l = c.to_argb32(); + set_current_text_color(c); obj->callbacks.print = &new_fg; END OBJ(color2, nullptr) Colour c = color[2].get(*state); - obj->data.l = c.to_argb32(); set_current_text_color(c); + obj->data.l = c.to_argb32(); + set_current_text_color(c); obj->callbacks.print = &new_fg; END OBJ(color3, nullptr) Colour c = color[3].get(*state); - obj->data.l = c.to_argb32(); set_current_text_color(c); + obj->data.l = c.to_argb32(); + set_current_text_color(c); obj->callbacks.print = &new_fg; END OBJ(color4, nullptr) Colour c = color[4].get(*state); - obj->data.l = c.to_argb32(); set_current_text_color(c); + obj->data.l = c.to_argb32(); + set_current_text_color(c); obj->callbacks.print = &new_fg; END OBJ(color5, nullptr) Colour c = color[5].get(*state); - obj->data.l = c.to_argb32(); set_current_text_color(c); + obj->data.l = c.to_argb32(); + set_current_text_color(c); obj->callbacks.print = &new_fg; END OBJ(color6, nullptr) Colour c = color[6].get(*state); - obj->data.l = c.to_argb32(); set_current_text_color(c); + obj->data.l = c.to_argb32(); + set_current_text_color(c); obj->callbacks.print = &new_fg; END OBJ(color7, nullptr) Colour c = color[7].get(*state); - obj->data.l = c.to_argb32(); set_current_text_color(c); + obj->data.l = c.to_argb32(); + set_current_text_color(c); obj->callbacks.print = &new_fg; END OBJ(color8, nullptr) Colour c = color[8].get(*state); - obj->data.l = c.to_argb32(); set_current_text_color(c); + obj->data.l = c.to_argb32(); + set_current_text_color(c); obj->callbacks.print = &new_fg; END OBJ(color9, nullptr) Colour c = color[9].get(*state); - obj->data.l = c.to_argb32(); set_current_text_color(c); + obj->data.l = c.to_argb32(); + set_current_text_color(c); obj->callbacks.print = &new_fg; END OBJ(font, nullptr) scan_font(obj, arg); obj->callbacks.print = &new_font; @@ -1440,14 +1450,14 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, #ifdef BUILD_GUI obj->data.l = (arg != nullptr ? parse_color(arg) : default_shade_color.get(*state)) - .to_argb32(); + .to_argb32(); obj->callbacks.print = &new_bg; #endif /* BUILD_GUI */ END OBJ(outlinecolor, nullptr) #ifdef BUILD_GUI obj->data.l = (arg != nullptr ? parse_color(arg) : default_outline_color.get(*state)) - .to_argb32(); + .to_argb32(); obj->callbacks.print = &new_outline; #endif /* BUILD_GUI */ END OBJ(stippled_hr, nullptr) diff --git a/src/display-ncurses.cc b/src/display-ncurses.cc index 74faf2c2..7e976118 100644 --- a/src/display-ncurses.cc +++ b/src/display-ncurses.cc @@ -26,8 +26,8 @@ #include -#include "conky.h" #include "colours.h" +#include "conky.h" #include "display-ncurses.hh" #include "gui.h" #include "nc.h" @@ -40,7 +40,7 @@ #endif #ifdef BUILD_NCURSES -extern WINDOW *ncurses_window; +extern WINDOW* ncurses_window; #endif namespace conky { @@ -65,39 +65,38 @@ extern void init_ncurses_output() {} #define COLORS_BUILTIN 8 Colour ncurses_colors[COLORS_BUILTIN + COLORS_CUSTOM] = { - {0x00, 0x00, 0x00, 0xff}, // BLACK - {0xff, 0x00, 0x00, 0xff}, // RED - {0x00, 0xff, 0x00, 0xff}, // GREEN - {0xff, 0xff, 0x00, 0xff}, // YELLOW - {0x00, 0x00, 0xff, 0xff}, // BLUE - {0xff, 0x00, 0xff, 0xff}, // MAGENTA - {0x00, 0xff, 0xff, 0xff}, // CYAN - {0xff, 0xff, 0xff, 0xff}, // WHITE + {0x00, 0x00, 0x00, 0xff}, // BLACK + {0xff, 0x00, 0x00, 0xff}, // RED + {0x00, 0xff, 0x00, 0xff}, // GREEN + {0xff, 0xff, 0x00, 0xff}, // YELLOW + {0x00, 0x00, 0xff, 0xff}, // BLUE + {0xff, 0x00, 0xff, 0xff}, // MAGENTA + {0x00, 0xff, 0xff, 0xff}, // CYAN + {0xff, 0xff, 0xff, 0xff}, // WHITE }; - // Find the nearest ncurses color. - int to_ncurses(const Colour& c) { - int mindiff = INT_MAX; - int best_nccolor = 0; - for (int nccolor = 0; nccolor < COLORS_BUILTIN + COLORS_CUSTOM; nccolor++) { - const Colour& other = ncurses_colors[nccolor]; - int diff = abs(c.red - other.red) + - abs(c.green - other.green) + - abs(c.blue - other.blue); +// Find the nearest ncurses color. +int to_ncurses(const Colour& c) { + int mindiff = INT_MAX; + int best_nccolor = 0; + for (int nccolor = 0; nccolor < COLORS_BUILTIN + COLORS_CUSTOM; nccolor++) { + const Colour& other = ncurses_colors[nccolor]; + int diff = abs(c.red - other.red) + abs(c.green - other.green) + + abs(c.blue - other.blue); - if (diff < mindiff) { - mindiff = diff; - best_nccolor = nccolor; - } + if (diff < mindiff) { + mindiff = diff; + best_nccolor = nccolor; } - return best_nccolor; } + return best_nccolor; +} Colour from_ncurses(int nccolor) { - if (nccolor >= 0 && nccolor < COLORS_BUILTIN + COLORS_CUSTOM) { - return ncurses_colors[nccolor]; - } - return error_colour; + if (nccolor >= 0 && nccolor < COLORS_BUILTIN + COLORS_CUSTOM) { + return ncurses_colors[nccolor]; + } + return error_colour; } display_output_ncurses::display_output_ncurses() @@ -114,9 +113,10 @@ bool display_output_ncurses::detect() { } bool display_output_ncurses::initialize() { - for(int i = 0; i < COLORS_CUSTOM; i++) { + for (int i = 0; i < COLORS_CUSTOM; i++) { Colour c = color[i].get(*state); - init_color(COLORS_BUILTIN + i, (1000*c.red)/255, (1000*c.green)/255, (1000*c.blue)/255); + init_color(COLORS_BUILTIN + i, (1000 * c.red) / 255, (1000 * c.green) / 255, + (1000 * c.blue) / 255); ncurses_colors[COLORS_BUILTIN + i] = c; } @@ -139,7 +139,7 @@ void display_output_ncurses::begin_draw_text() { void display_output_ncurses::end_draw_text() {} -void display_output_ncurses::draw_string(const char *s, int) { +void display_output_ncurses::draw_string(const char* s, int) { printw("%s", s); } diff --git a/src/display-output.hh b/src/display-output.hh index 6af426e2..45c65856 100644 --- a/src/display-output.hh +++ b/src/display-output.hh @@ -29,8 +29,8 @@ #include #include -#include "luamm.hh" #include "colours.h" +#include "luamm.hh" namespace conky { diff --git a/src/display-wayland.cc b/src/display-wayland.cc index f0fc77ed..9090922f 100644 --- a/src/display-wayland.cc +++ b/src/display-wayland.cc @@ -523,9 +523,9 @@ bool display_output_wayland::main_loop_wait(double t) { bool scale_changed = global_window->scale != global_window->pending_scale; /* resize window if it isn't right size */ - if ((fixed_size == 0) && (text_width + 2 * border_total != width || - text_height + 2 * border_total != height || - scale_changed)) { + if ((fixed_size == 0) && + (text_width + 2 * border_total != width || + text_height + 2 * border_total != height || scale_changed)) { /* clamp text_width to configured maximum */ if (maximum_width.get(*state)) { int mw = global_window->scale * maximum_width.get(*state); @@ -668,11 +668,10 @@ void display_output_wayland::cleanup() { void display_output_wayland::set_foreground_color(Colour c) { current_color = c; #ifdef BUILD_ARGB - current_color.alpha = own_window_argb_value.get(*state); + current_color.alpha = own_window_argb_value.get(*state); #endif /* BUILD_ARGB */ if (global_window->cr) { - cairo_set_source_rgba(global_window->cr, - current_color.red / 255.0, + cairo_set_source_rgba(global_window->cr, current_color.red / 255.0, current_color.green / 255.0, current_color.blue / 255.0, current_color.alpha / 255.0); @@ -813,11 +812,8 @@ void display_output_wayland::clear_text(int exposures) { #endif } #endif - cairo_set_source_rgba(window->cr, - color.red / 255.0, - color.green / 255.0, - color.blue / 255.0, - color.alpha / 255.0); + cairo_set_source_rgba(window->cr, color.red / 255.0, color.green / 255.0, + color.blue / 255.0, color.alpha / 255.0); cairo_set_operator(window->cr, CAIRO_OPERATOR_SOURCE); cairo_paint(window->cr); cairo_restore(window->cr); @@ -841,7 +837,8 @@ int display_output_wayland::font_descent(unsigned int f) { return pango_fonts[f].metrics.descent; } -void display_output_wayland::setup_fonts(void) { /* Nothing to do here */ } +void display_output_wayland::setup_fonts(void) { /* Nothing to do here */ +} void display_output_wayland::set_font(unsigned int f) { assert(f < pango_fonts.size()); @@ -1045,8 +1042,8 @@ void window_allocate_buffer(struct window *window) { int scale = window->pending_scale; struct shm_pool *pool; - pool = shm_pool_create(window->shm, data_length_for_shm_surface( - &window->rectangle, scale)); + pool = shm_pool_create( + window->shm, data_length_for_shm_surface(&window->rectangle, scale)); if (!pool) { fprintf(stderr, "could not allocate shm pool\n"); return; @@ -1127,7 +1124,8 @@ void window_resize(struct window *window, int width, int height) { void window_commit_buffer(struct window *window) { assert(window->cairo_surface != nullptr); - wl_surface_set_buffer_scale(global_window->surface, global_window->pending_scale); + wl_surface_set_buffer_scale(global_window->surface, + global_window->pending_scale); wl_surface_attach(window->surface, get_buffer_from_cairo_surface(window->cairo_surface), 0, 0); /* repaint all the pixels in the surface, change size to only repaint changed diff --git a/src/display-x11.cc b/src/display-x11.cc index 69d5efe8..61759be8 100644 --- a/src/display-x11.cc +++ b/src/display-x11.cc @@ -51,8 +51,8 @@ #include #include -#include "conky.h" #include "colours.h" +#include "conky.h" #include "display-x11.hh" #include "gui.h" #include "llua.h" @@ -64,7 +64,7 @@ // TODO: cleanup externs (move to conky.h ?) #ifdef OWN_WINDOW extern int fixed_size, fixed_pos; -#endif /* OWN_WINDOW */ +#endif /* OWN_WINDOW */ extern int text_start_x, text_start_y; /* text start position in window */ extern int text_offset_x, text_offset_y; /* offset for start position */ extern int text_width, @@ -612,7 +612,8 @@ void display_output_x11::set_foreground_color(Colour c) { current_color.alpha = own_window_argb_value.get(*state); } #endif /* BUILD_ARGB */ - XSetForeground(display, window.gc, current_color.to_x11_color(display, screen)); + XSetForeground(display, window.gc, + current_color.to_x11_color(display, screen)); } int display_output_x11::calc_text_width(const char *s) { diff --git a/src/x11.cc b/src/x11.cc index f599eec7..771a9c8a 100644 --- a/src/x11.cc +++ b/src/x11.cc @@ -599,7 +599,6 @@ void x11_init_window(lua::state &l __attribute__((unused)), bool own) { 0, 0}; - XWMHints wmHint; Atom xa; @@ -630,7 +629,8 @@ void x11_init_window(lua::state &l __attribute__((unused)), bool own) { if (own_window_type.get(l) == TYPE_UTILITY) { XRectangle rect; XserverRegion region = XFixesCreateRegion(display, &rect, 1); - XFixesSetWindowShapeRegion(display, window.window, ShapeInput, 0, 0, region); + XFixesSetWindowShapeRegion(display, window.window, ShapeInput, 0, 0, + region); XFixesDestroyRegion(display, region); } #endif /* BUILD_XFIXES */