From a5d6670121184b0c362d9549f61090bab5e1c9ec Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Tue, 24 Jan 2017 08:01:04 +0100 Subject: [PATCH] refactor(clang-tidy): Apply fixes --- include/adapters/alsa/mixer.hpp | 2 +- include/components/renderer.hpp | 23 +++++++++++------------ include/utils/string.hpp | 2 +- include/x11/draw.hpp | 14 -------------- src/adapters/alsa/mixer.cpp | 5 +++-- src/components/command_line.cpp | 3 +-- src/components/controller.cpp | 4 ++-- src/components/renderer.cpp | 21 ++++++--------------- src/modules/volume.cpp | 9 ++++++--- src/utils/file.cpp | 2 +- src/x11/draw.cpp | 22 ---------------------- src/x11/extensions/randr.cpp | 3 ++- src/x11/graphics.cpp | 10 ++++++---- src/x11/tray_manager.cpp | 4 ++-- src/x11/window.cpp | 3 ++- 15 files changed, 44 insertions(+), 83 deletions(-) delete mode 100644 include/x11/draw.hpp delete mode 100644 src/x11/draw.cpp diff --git a/include/adapters/alsa/mixer.hpp b/include/adapters/alsa/mixer.hpp index 24542848..b8e17f59 100644 --- a/include/adapters/alsa/mixer.hpp +++ b/include/adapters/alsa/mixer.hpp @@ -18,7 +18,7 @@ POLYBAR_NS namespace alsa { class mixer { public: - explicit mixer(string&& mixer_selem_name, string&& sound_card_name); + explicit mixer(string&& mixer_selem_name, string&& soundcard_name); ~mixer(); mixer(const mixer& o) = delete; diff --git a/include/components/renderer.hpp b/include/components/renderer.hpp index 7ddfbee0..47569c7c 100644 --- a/include/components/renderer.hpp +++ b/include/components/renderer.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include "cairo/fwd.hpp" @@ -38,7 +37,7 @@ class renderer static make_type make(const bar_settings& bar); explicit renderer( - connection& conn, signal_emitter& emitter, const config&, const logger& logger, const bar_settings& bar); + connection& conn, signal_emitter& sig, const config&, const logger& logger, const bar_settings& bar); ~renderer(); xcb_window_t window() const; @@ -106,19 +105,19 @@ class renderer unique_ptr m_surface; map m_blocks; - cairo_operator_t m_comp_bg; - cairo_operator_t m_comp_fg; - cairo_operator_t m_comp_ol; - cairo_operator_t m_comp_ul; - cairo_operator_t m_comp_border; + int m_comp_bg{0}; + int m_comp_fg{0}; + int m_comp_ol{0}; + int m_comp_ul{0}; + int m_comp_border{0}; alignment m_align; std::bitset<3> m_attr; - int m_font; - unsigned int m_bg; - unsigned int m_fg; - unsigned int m_ol; - unsigned int m_ul; + int m_font{0}; + unsigned int m_bg{0U}; + unsigned int m_fg{0U}; + unsigned int m_ol{0U}; + unsigned int m_ul{0U}; vector m_actions; bool m_fixedcenter; diff --git a/include/utils/string.hpp b/include/utils/string.hpp index 02dcc5e5..5fb73976 100644 --- a/include/utils/string.hpp +++ b/include/utils/string.hpp @@ -90,7 +90,7 @@ namespace string_util { string floating_point(double value, size_t precision, bool fixed = false, const string& locale = ""); string filesize_mb(unsigned long long kbytes, size_t precision = 0, const string& locale = ""); string filesize_gb(unsigned long long kbytes, size_t precision = 0, const string& locale = ""); - string filesize(unsigned long long bytes, size_t precision = 0, bool fixed = false, const string& locale = ""); + string filesize(unsigned long long kbytes, size_t precision = 0, bool fixed = false, const string& locale = ""); hash_type hash(const string& src); } diff --git a/include/x11/draw.hpp b/include/x11/draw.hpp deleted file mode 100644 index 7f77a064..00000000 --- a/include/x11/draw.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include - -#include "common.hpp" - -POLYBAR_NS - -namespace draw_util { - void fill(xcb_connection_t* c, xcb_drawable_t d, xcb_gcontext_t g, const xcb_rectangle_t rect); - void fill(xcb_connection_t* c, xcb_drawable_t d, xcb_gcontext_t g, short int x, short int y, unsigned short int w, unsigned short int h); -} - -POLYBAR_NS_END diff --git a/src/adapters/alsa/mixer.cpp b/src/adapters/alsa/mixer.cpp index 217f333b..47a9d5cf 100644 --- a/src/adapters/alsa/mixer.cpp +++ b/src/adapters/alsa/mixer.cpp @@ -12,7 +12,8 @@ namespace alsa { /** * Construct mixer object */ - mixer::mixer(string&& mixer_selem_name, string&& soundcard_name) : m_name(forward(mixer_selem_name)), s_name(soundcard_name) { + mixer::mixer(string&& mixer_selem_name, string&& soundcard_name) + : m_name(forward(mixer_selem_name)), s_name(soundcard_name) { int err = 0; if ((err = snd_mixer_open(&m_mixer, 1)) == -1) { @@ -60,7 +61,7 @@ namespace alsa { /** * Get the name of the soundcard that is associated with the mixer */ - const string& mixer::get_sound_card() { + const string& mixer::get_sound_card() { return s_name; } diff --git a/src/components/command_line.cpp b/src/components/command_line.cpp index 859c0710..35759a0f 100644 --- a/src/components/command_line.cpp +++ b/src/components/command_line.cpp @@ -10,8 +10,7 @@ namespace command_line { * Create instance */ parser::make_type parser::make(string&& scriptname, const options&& opts) { - return factory_util::unique( - "Usage: " + scriptname + " [OPTION]... BAR", forward(opts)); + return factory_util::unique("Usage: " + scriptname + " [OPTION]... BAR", forward(opts)); } /** diff --git a/src/components/controller.cpp b/src/components/controller.cpp index 64289ede..904d98f3 100644 --- a/src/components/controller.cpp +++ b/src/components/controller.cpp @@ -23,7 +23,7 @@ #include "x11/tray_manager.hpp" #include "x11/types.hpp" -#include +#include POLYBAR_NS @@ -586,7 +586,7 @@ bool controller::on(const signals::ui::ready&) { enqueue(make_update_evt(true)); if (!m_snapshot_dst.empty()) { - m_threads.emplace_back(thread([&]{ + m_threads.emplace_back(thread([&] { this_thread::sleep_for(3s); m_sig.emit(signals::ui::request_snapshot{move(m_snapshot_dst)}); enqueue(make_update_evt(true)); diff --git a/src/components/renderer.cpp b/src/components/renderer.cpp index ba425e84..32e15c0e 100644 --- a/src/components/renderer.cpp +++ b/src/components/renderer.cpp @@ -1,22 +1,13 @@ #include "components/renderer.hpp" #include "cairo/context.hpp" -#include "cairo/font.hpp" -#include "cairo/surface.hpp" -#include "cairo/types.hpp" -#include "cairo/utils.hpp" #include "components/config.hpp" -#include "components/logger.hpp" -#include "errors.hpp" #include "events/signal.hpp" #include "events/signal_receiver.hpp" -#include "utils/color.hpp" #include "utils/factory.hpp" #include "utils/file.hpp" #include "utils/math.hpp" -#include "utils/string.hpp" #include "x11/atoms.hpp" #include "x11/connection.hpp" -#include "x11/draw.hpp" #include "x11/extensions/all.hpp" #include "x11/generic.hpp" #include "x11/winspec.hpp" @@ -388,7 +379,7 @@ void renderer::reserve_space(edge side, unsigned int w) { */ void renderer::fill_background() { m_context->save(); - *m_context << m_comp_bg; + *m_context << static_cast(m_comp_bg); if (m_bar.radius != 0.0) { // clang-format off @@ -424,7 +415,7 @@ void renderer::fill_overline(double x, double w) { if (m_bar.overline.size && m_attr.test(static_cast(attribute::OVERLINE))) { m_log.trace_x("renderer: overline(x=%f, w=%f)", x, w); m_context->save(); - *m_context << m_comp_ol; + *m_context << static_cast(m_comp_ol); *m_context << m_ol; *m_context << cairo::rect{x, static_cast(m_rect.y), w, static_cast(m_bar.overline.size)}; m_context->fill(); @@ -439,7 +430,7 @@ void renderer::fill_underline(double x, double w) { if (m_bar.underline.size && m_attr.test(static_cast(attribute::UNDERLINE))) { m_log.trace_x("renderer: underline(x=%f, w=%f)", x, w); m_context->save(); - *m_context << m_comp_ul; + *m_context << static_cast(m_comp_ul); *m_context << m_ul; *m_context << cairo::rect{x, static_cast(m_rect.y + m_rect.height - m_bar.underline.size), w, static_cast(m_bar.underline.size)}; @@ -453,7 +444,7 @@ void renderer::fill_underline(double x, double w) { */ void renderer::fill_borders() { m_context->save(); - *m_context << m_comp_border; + *m_context << static_cast(m_comp_border); cairo::rect top{0.0, 0.0, 0.0, 0.0}; top.x += m_bar.borders.at(edge::LEFT).size; @@ -508,7 +499,7 @@ void renderer::draw_text(const string& contents) { if (m_bg && m_bg != m_bar.background) { block.bg = m_bg; - block.bg_operator = m_comp_bg; + block.bg_operator = static_cast(m_comp_bg); block.bg_rect.x = m_rect.x + m_blocks[m_align].x; block.bg_rect.y = m_rect.y; block.bg_rect.h = m_rect.height; @@ -516,7 +507,7 @@ void renderer::draw_text(const string& contents) { m_context->save(); *m_context << origin; - *m_context << m_comp_fg; + *m_context << static_cast(m_comp_fg); *m_context << m_fg; *m_context << block; m_context->restore(); diff --git a/src/modules/volume.cpp b/src/modules/volume.cpp index d2c84d9c..5ad0a116 100644 --- a/src/modules/volume.cpp +++ b/src/modules/volume.cpp @@ -229,13 +229,16 @@ namespace modules { bool headphones{m_headphones}; if (m_mixer[mixer::MASTER] && !m_mixer[mixer::MASTER]->get_name().empty()) { - mixers.emplace_back(new mixer_t::element_type(string{m_mixer[mixer::MASTER]->get_name()}, string{m_mixer[mixer::MASTER]->get_sound_card()})); + mixers.emplace_back(new mixer_t::element_type( + string{m_mixer[mixer::MASTER]->get_name()}, string{m_mixer[mixer::MASTER]->get_sound_card()})); } if (m_mixer[mixer::HEADPHONE] && !m_mixer[mixer::HEADPHONE]->get_name().empty() && headphones) { - mixers.emplace_back(new mixer_t::element_type(string{m_mixer[mixer::HEADPHONE]->get_name()}, string{m_mixer[mixer::HEADPHONE]->get_sound_card()})); + mixers.emplace_back(new mixer_t::element_type( + string{m_mixer[mixer::HEADPHONE]->get_name()}, string{m_mixer[mixer::HEADPHONE]->get_sound_card()})); } if (m_mixer[mixer::SPEAKER] && !m_mixer[mixer::SPEAKER]->get_name().empty() && !headphones) { - mixers.emplace_back(new mixer_t::element_type(string{m_mixer[mixer::SPEAKER]->get_name()}, string{m_mixer[mixer::HEADPHONE]->get_sound_card()})); + mixers.emplace_back(new mixer_t::element_type( + string{m_mixer[mixer::SPEAKER]->get_name()}, string{m_mixer[mixer::HEADPHONE]->get_sound_card()})); } if (cmd.compare(0, strlen(EVENT_TOGGLE_MUTE), EVENT_TOGGLE_MUTE) == 0) { diff --git a/src/utils/file.cpp b/src/utils/file.cpp index 9f94f761..90a2289a 100644 --- a/src/utils/file.cpp +++ b/src/utils/file.cpp @@ -208,7 +208,7 @@ namespace file_util { * Get glob results using given pattern */ vector glob(const string& pattern) { - glob_t result; + glob_t result{}; vector ret; if (glob(pattern.c_str(), GLOB_TILDE, nullptr, &result) == 0) { diff --git a/src/x11/draw.cpp b/src/x11/draw.cpp deleted file mode 100644 index 8c515d1c..00000000 --- a/src/x11/draw.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "x11/draw.hpp" -#include "utils/color.hpp" - -POLYBAR_NS - -namespace draw_util { - /** - * Fill region of drawable with color defined by gcontext - */ - void fill(xcb_connection_t* c, xcb_drawable_t d, xcb_gcontext_t g, const xcb_rectangle_t rect) { - xcb_poly_fill_rectangle(c, d, g, 1, &rect); - } - - /** - * Fill region of drawable with color defined by gcontext - */ - void fill(xcb_connection_t* c, xcb_drawable_t d, xcb_gcontext_t g, short int x, short int y, unsigned short int w, unsigned short int h) { - fill(c, d, g, {x, y, w, h}); - } -} - -POLYBAR_NS_END diff --git a/src/x11/extensions/randr.cpp b/src/x11/extensions/randr.cpp index 80eed695..ef1096f6 100644 --- a/src/x11/extensions/randr.cpp +++ b/src/x11/extensions/randr.cpp @@ -61,7 +61,8 @@ namespace randr_util { /** * Define monitor */ - monitor_t make_monitor(xcb_randr_output_t randr, string name, unsigned short int w, unsigned short int h, short int x, short int y) { + monitor_t make_monitor( + xcb_randr_output_t randr, string name, unsigned short int w, unsigned short int h, short int x, short int y) { monitor_t mon{new monitor_t::element_type{}}; mon->output = randr; mon->name = move(name); diff --git a/src/x11/graphics.cpp b/src/x11/graphics.cpp index 9e65f6c3..bc363d2b 100644 --- a/src/x11/graphics.cpp +++ b/src/x11/graphics.cpp @@ -13,8 +13,8 @@ namespace graphics_util { /** * Create a basic window */ - bool create_window( - connection& conn, xcb_window_t* win, short int x, short int y, unsigned short int w, unsigned short int h, xcb_window_t root) { + bool create_window(connection& conn, xcb_window_t* win, short int x, short int y, unsigned short int w, + unsigned short int h, xcb_window_t root) { if (!root) { root = conn.screen()->root; } @@ -35,14 +35,16 @@ namespace graphics_util { * Create a basic pixmap with the same depth as the * root depth of the default screen */ - bool create_pixmap(connection& conn, xcb_drawable_t dst, unsigned short int w, unsigned short int h, xcb_pixmap_t* pixmap) { + bool create_pixmap( + connection& conn, xcb_drawable_t dst, unsigned short int w, unsigned short int h, xcb_pixmap_t* pixmap) { return graphics_util::create_pixmap(conn, dst, w, h, conn.screen()->root_depth, pixmap); } /** * Create a basic pixmap with specific depth */ - bool create_pixmap(connection& conn, xcb_drawable_t dst, unsigned short int w, unsigned short int h, unsigned char d, xcb_pixmap_t* pixmap) { + bool create_pixmap(connection& conn, xcb_drawable_t dst, unsigned short int w, unsigned short int h, unsigned char d, + xcb_pixmap_t* pixmap) { try { *pixmap = conn.generate_id(); conn.create_pixmap_checked(d, *pixmap, dst, w, h); diff --git a/src/x11/tray_manager.cpp b/src/x11/tray_manager.cpp index 06df063f..e81c909c 100644 --- a/src/x11/tray_manager.cpp +++ b/src/x11/tray_manager.cpp @@ -13,7 +13,6 @@ #include "utils/process.hpp" #include "x11/atoms.hpp" #include "x11/connection.hpp" -#include "x11/draw.hpp" #include "x11/graphics.hpp" #include "x11/tray_manager.hpp" #include "x11/window.hpp" @@ -489,7 +488,8 @@ void tray_manager::refresh_window() { auto height = calculate_h(); if (m_opts.transparent && !m_rootpixmap.pixmap) { - draw_util::fill(m_connection, m_pixmap, m_gc, 0, 0, width, height); + xcb_rectangle_t rect{0, 0, static_cast(width), static_cast(height)}; + m_connection.poly_fill_rectangle(m_pixmap, m_gc, 1, &rect); } m_connection.clear_area(0, m_tray, 0, 0, width, height); diff --git a/src/x11/window.cpp b/src/x11/window.cpp index 86058351..a01192e0 100644 --- a/src/x11/window.cpp +++ b/src/x11/window.cpp @@ -17,7 +17,8 @@ window& window::operator=(const xcb_window_t win) { /** * Create window and check for errors */ -window window::create_checked(short int x, short int y, unsigned short int w, unsigned short int h, unsigned int mask, const xcb_params_cw_t* p) { +window window::create_checked( + short int x, short int y, unsigned short int w, unsigned short int h, unsigned int mask, const xcb_params_cw_t* p) { if (*this == XCB_NONE) { *this = connection().generate_id(); }