1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-25 13:55:47 -05:00

refactor(clang-format): Apply fixes

This commit is contained in:
Michael Carlberg 2016-11-25 08:42:31 +01:00
parent 1adb1be404
commit 8db3e79919
41 changed files with 185 additions and 189 deletions

View file

@ -1,9 +1,9 @@
#pragma once
#include <stdio.h>
#include <cmath>
#include <functional>
#include <string>
#include <cmath>
#include <alsa/asoundlib.h>

View file

@ -1,6 +1,7 @@
#pragma once
#include <chrono>
#include <arpa/inet.h>
#include <ifaddrs.h>
#include <iwlib.h>

View file

@ -18,7 +18,7 @@
namespace polybar { \
inline namespace v2_0_0 {
#define POLYBAR_NS_END \
} \
} \
}
#define POLYBAR_NS_PATH "polybar::v2_0_0"

View file

@ -19,8 +19,7 @@ class renderer;
class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::property_notify> {
public:
explicit bar(connection& conn, const config& config, const logger& logger,
unique_ptr<tray_manager> tray_manager);
explicit bar(connection& conn, const config& config, const logger& logger, unique_ptr<tray_manager> tray_manager);
~bar();
void bootstrap(bool nodraw = false);

View file

@ -69,23 +69,23 @@ class builder {
string m_output;
map<syntaxtag, int> m_tags{
// clang-format off
{syntaxtag::A, 0},
{syntaxtag::B, 0},
{syntaxtag::F, 0},
{syntaxtag::T, 0},
{syntaxtag::u, 0},
{syntaxtag::o, 0},
// clang-format on
// clang-format off
{syntaxtag::A, 0},
{syntaxtag::B, 0},
{syntaxtag::F, 0},
{syntaxtag::T, 0},
{syntaxtag::u, 0},
{syntaxtag::o, 0},
// clang-format on
};
map<syntaxtag, string> m_colors{
// clang-format off
{syntaxtag::B, ""},
{syntaxtag::F, ""},
{syntaxtag::u, ""},
{syntaxtag::o, ""},
// clang-format on
// clang-format off
{syntaxtag::B, ""},
{syntaxtag::F, ""},
{syntaxtag::u, ""},
{syntaxtag::o, ""},
// clang-format on
};
uint8_t m_attributes{static_cast<uint8_t>(attribute::NONE)};

View file

@ -23,8 +23,7 @@ namespace command_line {
string token;
const choices values;
explicit option(
string flag, string flag_long, string desc, string token = "", const choices c = {})
explicit option(string flag, string flag_long, string desc, string token = "", const choices c = {})
: flag(flag), flag_long(flag_long), desc(desc), token(token), values(c) {}
};
@ -33,8 +32,7 @@ namespace command_line {
class parser {
public:
explicit parser(const string& synopsis, const options& opts)
: m_synopsis(synopsis), m_opts(opts) {}
explicit parser(const string& synopsis, const options& opts) : m_synopsis(synopsis), m_opts(opts) {}
void usage() const;

View file

@ -1,7 +1,7 @@
#pragma once
#include <boost/optional.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <boost/property_tree/ptree.hpp>

View file

@ -35,7 +35,9 @@ class controller {
~controller();
void bootstrap(bool writeback = false, bool dump_wmname = false);
bool run();
void run();
bool completed();
protected:
void install_sigmask();

View file

@ -2,8 +2,8 @@
#include "common.hpp"
#include "components/logger.hpp"
#include "utils/functional.hpp"
#include "utils/concurrency.hpp"
#include "utils/functional.hpp"
POLYBAR_NS

View file

@ -1,17 +1,16 @@
#ifdef DEBUG
#pragma once
#include <iostream>
#include <chrono>
#include <iostream>
template <class T>
void benchmark_execution_speed(const T& expr) noexcept {
auto start = std::chrono::high_resolution_clock::now();
expr();
auto finish = std::chrono::high_resolution_clock::now();
std::cout << "execution speed: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(finish - start).count() << "ms"
<< std::endl;
std::cout << "execution speed: " << std::chrono::duration_cast<std::chrono::milliseconds>(finish - start).count()
<< "ms" << std::endl;
}
template <class T>

View file

@ -38,8 +38,7 @@ namespace drawtypes {
using animation_t = shared_ptr<animation>;
animation_t load_animation(
const config& conf, string section, string name = "animation", bool required = true);
animation_t load_animation(const config& conf, string section, string name = "animation", bool required = true);
}
POLYBAR_NS_END

View file

@ -39,9 +39,8 @@ namespace drawtypes {
bool m_ellipsis = true;
explicit label(string text, int font) : m_font(font), m_text(text), m_tokenized(m_text) {}
explicit label(string text, string foreground = "", string background = "",
string underline = "", string overline = "", int font = 0, int padding = 0, int margin = 0,
size_t maxlen = 0, bool ellipsis = true,
explicit label(string text, string foreground = "", string background = "", string underline = "",
string overline = "", int font = 0, int padding = 0, int margin = 0, size_t maxlen = 0, bool ellipsis = true,
const vector<struct bounds>& bound = {})
: m_foreground(foreground)
, m_background(background)
@ -68,16 +67,13 @@ namespace drawtypes {
private:
string m_text, m_tokenized;
const vector<struct bounds> m_token_bounds;
};
label_t load_label(
const config& conf, string section, string name, bool required = true, string def = "");
label_t load_label(const config& conf, string section, string name, bool required = true, string def = "");
label_t load_optional_label(const config& conf, string section, string name, string def = "");
icon_t load_icon(
const config& conf, string section, string name, bool required = true, string def = "");
icon_t load_icon(const config& conf, string section, string name, bool required = true, string def = "");
icon_t load_optional_icon(const config& conf, string section, string name, string def = "");
}

View file

@ -27,8 +27,7 @@ namespace modules {
string percentage_free_s;
string percentage_used_s;
explicit fs_mount(const string& mountpoint, bool mounted = false)
: mountpoint(mountpoint), mounted(mounted) {}
explicit fs_mount(const string& mountpoint, bool mounted = false) : mountpoint(mountpoint), mounted(mounted) {}
};
using fs_mount_t = unique_ptr<fs_mount>;

View file

@ -1,7 +1,7 @@
#pragma once
#include <csignal>
#include <chrono>
#include <csignal>
#include "adapters/mpd.hpp"
#include "modules/meta/event_module.hpp"

View file

@ -1,9 +1,9 @@
#pragma once
#include "components/config.hpp"
#include "x11/randr.hpp"
#include "config.hpp"
#include "modules/meta/static_module.hpp"
#include "x11/randr.hpp"
POLYBAR_NS
@ -23,8 +23,7 @@ namespace modules {
*
* TODO: Implement backlight configuring using scroll events
*/
class xbacklight_module : public static_module<xbacklight_module>,
public xpp::event::sink<evt::randr_notify> {
class xbacklight_module : public static_module<xbacklight_module>, public xpp::event::sink<evt::randr_notify> {
public:
using static_module::static_module;

View file

@ -10,8 +10,7 @@ namespace file_util {
*/
class file_ptr {
public:
explicit file_ptr(const string& path, const string& mode = "a+")
: m_path(string(path)), m_mode(string(mode)) {
explicit file_ptr(const string& path, const string& mode = "a+") : m_path(string(path)), m_mode(string(mode)) {
m_ptr = fopen(m_path.c_str(), m_mode.c_str());
}

View file

@ -1,7 +1,7 @@
#pragma once
#include <sys/inotify.h>
#include <poll.h>
#include <sys/inotify.h>
#include <cstdio>
#include "common.hpp"

View file

@ -48,7 +48,8 @@ namespace math_util {
template <typename ValueType, typename ReturnType = int>
ReturnType percentage_to_value(ValueType percentage, ValueType min_value, ValueType max_value) {
if (std::is_integral<ReturnType>())
return cap<ReturnType>(percentage * (max_value - min_value) / 100.0f + 0.5f, 0, max_value - min_value) + min_value;
return cap<ReturnType>(percentage * (max_value - min_value) / 100.0f + 0.5f, 0, max_value - min_value) +
min_value;
else
return cap<ReturnType>(percentage * (max_value - min_value) / 100.0f, 0.0f, max_value - min_value) + min_value;
}

View file

@ -36,9 +36,8 @@ namespace socket_util {
* conn->receive(...);
* @endcode
*/
auto make_unix_connection = [](string&& path) -> unique_ptr<unix_connection> {
return make_unique<unix_connection>(forward<string>(path));
};
auto make_unix_connection = [](
string&& path) -> unique_ptr<unix_connection> { return make_unique<unix_connection>(forward<string>(path)); };
}
POLYBAR_NS_END

View file

@ -18,8 +18,8 @@ namespace string_util {
bool compare(const string& s1, const string& s2);
string replace(const string& haystack, string needle, string repl, size_t start = 0, size_t end = string::npos);
string replace_all(const string& haystack, string needle, string repl, size_t start = 0, size_t end = string::npos);
string replace_all_bounded(const string& haystack, string needle, string replacement,
size_t min, size_t max, size_t start = 0, size_t end = string::npos);
string replace_all_bounded(const string& haystack, string needle, string replacement, size_t min, size_t max,
size_t start = 0, size_t end = string::npos);
string squeeze(const string& haystack, char needle);
string strip(const string& haystack, char needle);
string strip_trailing_newline(const string& haystack);

View file

@ -1,7 +1,7 @@
#pragma once
#include <deque>
#include <chrono>
#include <deque>
#include "common.hpp"
#include "components/logger.hpp"
@ -41,8 +41,7 @@ namespace throttle_util {
/**
* Construct throttler
*/
explicit event_throttler(int limit, timewindow timewindow)
: m_limit(limit), m_timewindow(timewindow) {}
explicit event_throttler(int limit, timewindow timewindow) : m_limit(limit), m_timewindow(timewindow) {}
/**
* Check if event is allowed to pass

View file

@ -3,9 +3,9 @@
#include <X11/X.h>
#include <X11/Xlib-xcb.h>
#include <xcb/xcb.h>
#include <boost/optional.hpp>
#include <iomanip>
#include <xpp/xpp.hpp>
#include <boost/optional.hpp>
#include "common.hpp"
#include "utils/memory.hpp"
@ -63,8 +63,7 @@ class connection : public xpp_connection {
xcb_screen_t* screen();
shared_ptr<xcb_client_message_event_t> make_client_message(
xcb_atom_t type, xcb_window_t target) const;
shared_ptr<xcb_client_message_event_t> make_client_message(xcb_atom_t type, xcb_window_t target) const;
void send_client_message(shared_ptr<xcb_client_message_event_t> message, xcb_window_t target,
uint32_t event_mask = 0xFFFFFF, bool propagate = false) const;

View file

@ -18,7 +18,8 @@ namespace graphics_util {
xcb_pixmap_t pixmap{0};
};
bool create_window(connection& conn, xcb_window_t* win, int16_t x = 0, int16_t y = 0, uint16_t w = 1, uint16_t h = 1, xcb_window_t root = 0);
bool create_window(connection& conn, xcb_window_t* win, int16_t x = 0, int16_t y = 0, uint16_t w = 1, uint16_t h = 1,
xcb_window_t root = 0);
bool create_pixmap(connection& conn, xcb_drawable_t dst, uint16_t w, uint16_t h, xcb_pixmap_t* pixmap);
bool create_pixmap(connection& conn, xcb_drawable_t dst, uint16_t w, uint16_t h, uint8_t d, xcb_pixmap_t* pixmap);
bool create_gc(connection& conn, xcb_drawable_t drawable, xcb_gcontext_t* gc);

View file

@ -16,8 +16,7 @@ alsa_ctl_interface::alsa_ctl_interface(int numid) : m_numid(numid) {
snd_ctl_elem_info_set_id(m_info, m_id);
if ((err = snd_ctl_open(&m_ctl, ALSA_SOUNDCARD, SND_CTL_NONBLOCK | SND_CTL_READONLY)) < 0)
throw_exception<alsa_ctl_interface_error>(
"Could not open control '" + string{ALSA_SOUNDCARD} + "'", err);
throw_exception<alsa_ctl_interface_error>("Could not open control '" + string{ALSA_SOUNDCARD} + "'", err);
if ((err = snd_ctl_elem_info(m_ctl, m_info)) < 0)
throw_exception<alsa_ctl_interface_error>("Could not get control datal", err);
@ -29,12 +28,10 @@ alsa_ctl_interface::alsa_ctl_interface(int numid) : m_numid(numid) {
if ((err = snd_hctl_load(m_hctl)) < 0)
throw_exception<alsa_ctl_interface_error>("Failed to load hctl", err);
if ((m_elem = snd_hctl_find_elem(m_hctl, m_id)) == nullptr)
throw alsa_ctl_interface_error(
"Could not find control with id " + to_string(snd_ctl_elem_id_get_numid(m_id)));
throw alsa_ctl_interface_error("Could not find control with id " + to_string(snd_ctl_elem_id_get_numid(m_id)));
if ((err = snd_ctl_subscribe_events(m_ctl, 1)) < 0)
throw alsa_ctl_interface_error(
"Could not subscribe to events: " + to_string(snd_ctl_elem_id_get_numid(m_id)));
throw alsa_ctl_interface_error("Could not subscribe to events: " + to_string(snd_ctl_elem_id_get_numid(m_id)));
}
alsa_ctl_interface::~alsa_ctl_interface() {
@ -158,10 +155,8 @@ int alsa_mixer::get_volume() {
snd_mixer_selem_get_playback_volume_range(m_mixerelement, &vol_min, &vol_max);
for (int i = 0; i <= SND_MIXER_SCHN_LAST; i++) {
if (snd_mixer_selem_has_playback_channel(
m_mixerelement, static_cast<snd_mixer_selem_channel_id_t>(i))) {
snd_mixer_selem_get_playback_volume(
m_mixerelement, static_cast<snd_mixer_selem_channel_id_t>(i), &vol);
if (snd_mixer_selem_has_playback_channel(m_mixerelement, static_cast<snd_mixer_selem_channel_id_t>(i))) {
snd_mixer_selem_get_playback_volume(m_mixerelement, static_cast<snd_mixer_selem_channel_id_t>(i), &vol);
vol_total += vol;
chan_n++;
}
@ -178,10 +173,8 @@ int alsa_mixer::get_normalized_volume() {
snd_mixer_selem_get_playback_dB_range(m_mixerelement, &vol_min, &vol_max);
for (int i = 0; i <= SND_MIXER_SCHN_LAST; i++) {
if (snd_mixer_selem_has_playback_channel(
m_mixerelement, static_cast<snd_mixer_selem_channel_id_t>(i))) {
snd_mixer_selem_get_playback_dB(
m_mixerelement, static_cast<snd_mixer_selem_channel_id_t>(i), &vol);
if (snd_mixer_selem_has_playback_channel(m_mixerelement, static_cast<snd_mixer_selem_channel_id_t>(i))) {
snd_mixer_selem_get_playback_dB(m_mixerelement, static_cast<snd_mixer_selem_channel_id_t>(i), &vol);
vol_total += vol;
chan_n++;
}
@ -207,7 +200,8 @@ void alsa_mixer::set_volume(float percentage) {
long vol_min, vol_max;
snd_mixer_selem_get_playback_volume_range(m_mixerelement, &vol_min, &vol_max);
snd_mixer_selem_set_playback_volume_all(m_mixerelement, math_util::percentage_to_value<int>(percentage, vol_min, vol_max));
snd_mixer_selem_set_playback_volume_all(
m_mixerelement, math_util::percentage_to_value<int>(percentage, vol_min, vol_max));
}
void alsa_mixer::set_normalized_volume(float percentage) {
@ -251,11 +245,9 @@ bool alsa_mixer::is_muted() {
std::lock_guard<concurrency_util::spin_lock> guard(m_lock);
int state = 0;
for (int i = 0; i <= SND_MIXER_SCHN_LAST; i++) {
if (snd_mixer_selem_has_playback_channel(
m_mixerelement, static_cast<snd_mixer_selem_channel_id_t>(i))) {
if (snd_mixer_selem_has_playback_channel(m_mixerelement, static_cast<snd_mixer_selem_channel_id_t>(i))) {
int state_ = 0;
snd_mixer_selem_get_playback_switch(
m_mixerelement, static_cast<snd_mixer_selem_channel_id_t>(i), &state_);
snd_mixer_selem_get_playback_switch(m_mixerelement, static_cast<snd_mixer_selem_channel_id_t>(i), &state_);
state = state || state_;
}
}

View file

@ -1,6 +1,11 @@
#include "adapters/net.hpp"
#include <cerrno>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <limits.h>
#include <linux/ethtool.h>
@ -10,11 +15,6 @@
#include <netinet/in.h>
#include <signal.h>
#include <sys/socket.h>
#include <cerrno>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <sstream>
#ifdef inline
#undef inline

View file

@ -1,6 +1,6 @@
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include "components/command_line.hpp"

View file

@ -163,7 +163,7 @@ void controller::bootstrap(bool writeback, bool dump_wmname) {
/**
* Launch the controller
*/
bool controller::run() {
void controller::run() {
assert(!m_connection.connection_has_error());
m_log.info("Starting application");
@ -201,8 +201,13 @@ bool controller::run() {
uninstall_confwatch();
m_running = false;
}
return !m_reload;
/**
* Get completion state
*/
bool controller::completed() {
return !m_running && !m_reload;
}
/**

View file

@ -12,8 +12,8 @@ namespace drawtypes {
}
label_t label::clone() {
return label_t{new label(m_text, m_foreground, m_background, m_underline, m_overline, m_font,
m_padding, m_margin, m_maxlen, m_ellipsis, m_token_bounds)};
return label_t{new label(m_text, m_foreground, m_background, m_underline, m_overline, m_font, m_padding, m_margin,
m_maxlen, m_ellipsis, m_token_bounds)};
}
void label::reset_tokens() {

View file

@ -14,26 +14,16 @@
using namespace polybar;
struct exit_success {};
struct exit_failure {};
int main(int argc, char** argv) {
XInitThreads();
logger& logger{configure_logger<decltype(logger)>(loglevel::WARNING).create<decltype(logger)>()};
//==================================================
// Connect to X server
//==================================================
xcb_connection_t* connection;
if ((connection = xutils::get_connection()) == nullptr) {
logger.err("A connection to X could not be established... ");
return EXIT_FAILURE;
}
int xfd = xcb_get_file_descriptor(connection);
uint8_t exit_code{EXIT_SUCCESS};
stateflag quit{false};
// clang-format off
const command_line::options opts{
command_line::option{"-h", "--help", "Show help options"},
command_line::option{"-h", "--help", "Show help options"},
command_line::option{"-v", "--version", "Print version information"},
command_line::option{"-l", "--log", "Set the logging verbosity (default: WARNING)", "LEVEL", {"warning", "info", "trace"}},
command_line::option{"-q", "--quiet", "Be quiet (will override -l)"},
@ -45,36 +35,46 @@ int main(int argc, char** argv) {
};
// clang-format on
stateflag terminate{false};
logger& logger{configure_logger<decltype(logger)>(loglevel::WARNING).create<decltype(logger)>()};
while (!terminate) {
//==================================================
// Connect to X server
//==================================================
XInitThreads();
xcb_connection_t* connection{nullptr};
if ((connection = xutils::get_connection()) == nullptr) {
logger.err("A connection to X could not be established... ");
throw exit_failure{};
}
int xfd{xcb_get_file_descriptor(connection)};
while (!quit) {
try {
//==================================================
// Parse command line arguments
//==================================================
vector<string> args(argv + 1, argv + argc);
cliparser cli{configure_cliparser<decltype(cli)>(argv[0], opts).create<decltype(cli)>()};
vector<string> args;
for (int i = 1; i < argc; i++) {
args.emplace_back(argv[i]);
}
cli.process_input(args);
if (cli.has("quiet"))
if (cli.has("quiet")) {
logger.verbosity(loglevel::ERROR);
else if (cli.has("log"))
} else if (cli.has("log")) {
logger.verbosity(cli.get("log"));
}
if (cli.has("help")) {
cli.usage();
return EXIT_SUCCESS;
throw exit_success{};
} else if (cli.has("version")) {
print_build_info(version_details(args));
return EXIT_SUCCESS;
throw exit_success{};
} else if (args.empty() || args[0][0] == '-') {
cli.usage();
return EXIT_FAILURE;
throw exit_failure{};
}
//==================================================
@ -82,21 +82,22 @@ int main(int argc, char** argv) {
//==================================================
config& conf{configure_config<decltype(conf)>().create<decltype(conf)>()};
if (cli.has("config"))
if (cli.has("config")) {
conf.load(cli.get("config"), args[0]);
else if (env_util::has("XDG_CONFIG_HOME"))
} else if (env_util::has("XDG_CONFIG_HOME")) {
conf.load(env_util::get("XDG_CONFIG_HOME") + "/polybar/config", args[0]);
else if (env_util::has("HOME"))
} else if (env_util::has("HOME")) {
conf.load(env_util::get("HOME") + "/.config/polybar/config", args[0]);
else
} else {
throw application_error("Define configuration using --config=PATH");
}
//==================================================
// Dump requested data
//==================================================
if (cli.has("dump")) {
std::cout << conf.get<string>(conf.bar_section(), cli.get("dump")) << std::endl;
return EXIT_SUCCESS;
throw exit_success{};
}
//==================================================
@ -104,31 +105,49 @@ int main(int argc, char** argv) {
//==================================================
inotify_util::watch_t watch;
if (cli.has("reload"))
if (cli.has("reload")) {
watch = inotify_util::make_watch(conf.filepath());
}
//==================================================
// Create controller and run application
// Create controller
//==================================================
auto app = configure_controller(watch).create<unique_ptr<controller>>();
auto ctrl = configure_controller(watch).create<unique_ptr<controller>>();
app->bootstrap(cli.has("stdout"), cli.has("print-wmname"));
ctrl->bootstrap(cli.has("stdout"), cli.has("print-wmname"));
if (cli.has("print-wmname"))
break;
if (cli.has("print-wmname")) {
throw exit_success{};
}
if ((terminate = app->run()) == false)
//==================================================
// Run application
//==================================================
ctrl->run();
if (ctrl->completed()) {
quit = true;
} else {
logger.info("Reloading application...");
} catch (const std::exception& err) {
}
} catch (const exit_success& term) {
exit_code = EXIT_SUCCESS;
quit = true;
} catch (const exit_failure& term) {
exit_code = EXIT_FAILURE;
quit = true;
} catch (const exception& err) {
logger.err(err.what());
return EXIT_FAILURE;
exit_code = EXIT_FAILURE;
quit = true;
}
};
}
logger.trace("Close connection to X server");
xcb_disconnect(connection);
close(xfd);
logger.info("Reached end of application...");
close(xfd);
return EXIT_SUCCESS;
return exit_code;
}

View file

@ -1,5 +1,5 @@
#include "components/builder.hpp"
#include "modules/meta/base.hpp"
#include "components/builder.hpp"
POLYBAR_NS

View file

@ -24,9 +24,9 @@ namespace modules {
// Add formats and elements {{{
m_formatter->add(FORMAT_ONLINE, TAG_LABEL_SONG,
{TAG_BAR_PROGRESS, TAG_TOGGLE, TAG_TOGGLE_STOP, TAG_LABEL_SONG, TAG_LABEL_TIME, TAG_ICON_RANDOM, TAG_ICON_REPEAT,
TAG_ICON_REPEAT_ONE, TAG_ICON_PREV, TAG_ICON_STOP, TAG_ICON_PLAY, TAG_ICON_PAUSE, TAG_ICON_NEXT,
TAG_ICON_SEEKB, TAG_ICON_SEEKF});
{TAG_BAR_PROGRESS, TAG_TOGGLE, TAG_TOGGLE_STOP, TAG_LABEL_SONG, TAG_LABEL_TIME, TAG_ICON_RANDOM,
TAG_ICON_REPEAT, TAG_ICON_REPEAT_ONE, TAG_ICON_PREV, TAG_ICON_STOP, TAG_ICON_PLAY, TAG_ICON_PAUSE,
TAG_ICON_NEXT, TAG_ICON_SEEKB, TAG_ICON_SEEKF});
m_formatter->add(FORMAT_OFFLINE, "", {TAG_LABEL_OFFLINE});

View file

@ -25,8 +25,7 @@ namespace modules {
m_interval = chrono::duration<double>(m_conf.get<float>(name(), "interval", 1));
// Add formats
m_formatter->add(FORMAT_CONNECTED, TAG_LABEL_CONNECTED,
{TAG_RAMP_SIGNAL, TAG_RAMP_QUALITY, TAG_LABEL_CONNECTED});
m_formatter->add(FORMAT_CONNECTED, TAG_LABEL_CONNECTED, {TAG_RAMP_SIGNAL, TAG_RAMP_QUALITY, TAG_LABEL_CONNECTED});
m_formatter->add(FORMAT_DISCONNECTED, TAG_LABEL_DISCONNECTED, {TAG_LABEL_DISCONNECTED});
// Create elements for format-connected
@ -41,8 +40,7 @@ namespace modules {
// Create elements for format-disconnected
if (m_formatter->has(TAG_LABEL_DISCONNECTED, FORMAT_DISCONNECTED)) {
m_label[connection_state::DISCONNECTED] =
load_optional_label(m_conf, name(), TAG_LABEL_DISCONNECTED, "");
m_label[connection_state::DISCONNECTED] = load_optional_label(m_conf, name(), TAG_LABEL_DISCONNECTED, "");
m_label[connection_state::DISCONNECTED]->reset_tokens();
m_label[connection_state::DISCONNECTED]->replace_token("%ifname%", m_interface);
}
@ -53,8 +51,7 @@ namespace modules {
{TAG_ANIMATION_PACKETLOSS, TAG_LABEL_PACKETLOSS, TAG_LABEL_CONNECTED});
if (m_formatter->has(TAG_LABEL_PACKETLOSS, FORMAT_PACKETLOSS)) {
m_label[connection_state::PACKETLOSS] =
load_optional_label(m_conf, name(), TAG_LABEL_PACKETLOSS, "");
m_label[connection_state::PACKETLOSS] = load_optional_label(m_conf, name(), TAG_LABEL_PACKETLOSS, "");
}
if (m_formatter->has(TAG_ANIMATION_PACKETLOSS, FORMAT_PACKETLOSS))
m_animation_packetloss = load_animation(m_conf, name(), TAG_ANIMATION_PACKETLOSS);
@ -77,8 +74,8 @@ namespace modules {
}
bool network_module::update() {
net::network* network = m_wireless ? static_cast<net::network*>(m_wireless.get())
: static_cast<net::network*>(m_wired.get());
net::network* network =
m_wireless ? static_cast<net::network*>(m_wireless.get()) : static_cast<net::network*>(m_wired.get());
if (!network->query(m_accumulate)) {
m_log.warn("%s: Failed to query interface '%s'", name(), m_interface);

View file

@ -52,10 +52,8 @@ namespace modules {
}
// Add formats and elements
m_formatter->add(
FORMAT_VOLUME, TAG_LABEL_VOLUME, {TAG_RAMP_VOLUME, TAG_LABEL_VOLUME, TAG_BAR_VOLUME});
m_formatter->add(
FORMAT_MUTED, TAG_LABEL_MUTED, {TAG_RAMP_VOLUME, TAG_LABEL_MUTED, TAG_BAR_VOLUME});
m_formatter->add(FORMAT_VOLUME, TAG_LABEL_VOLUME, {TAG_RAMP_VOLUME, TAG_LABEL_VOLUME, TAG_BAR_VOLUME});
m_formatter->add(FORMAT_MUTED, TAG_LABEL_MUTED, {TAG_RAMP_VOLUME, TAG_LABEL_MUTED, TAG_BAR_VOLUME});
if (m_formatter->has(TAG_BAR_VOLUME))
m_bar_volume = load_progressbar(m_bar, m_conf, name(), TAG_BAR_VOLUME);
@ -108,19 +106,19 @@ namespace modules {
m_headphones = false;
if (m_mixers[mixer::MASTER]) {
m_volume = m_volume * (m_mapped ? m_mixers[mixer::MASTER]->get_normalized_volume() / 100.0f :
m_mixers[mixer::MASTER]->get_volume() / 100.0f);
m_volume = m_volume * (m_mapped ? m_mixers[mixer::MASTER]->get_normalized_volume() / 100.0f
: m_mixers[mixer::MASTER]->get_volume() / 100.0f);
m_muted = m_muted || m_mixers[mixer::MASTER]->is_muted();
}
if (m_controls[control::HEADPHONE] && m_controls[control::HEADPHONE]->test_device_plugged()) {
m_headphones = true;
m_volume = m_volume * (m_mapped ? m_mixers[mixer::HEADPHONE]->get_normalized_volume() / 100.0f :
m_mixers[mixer::HEADPHONE]->get_volume() / 100.0f);
m_volume = m_volume * (m_mapped ? m_mixers[mixer::HEADPHONE]->get_normalized_volume() / 100.0f
: m_mixers[mixer::HEADPHONE]->get_volume() / 100.0f);
m_muted = m_muted || m_mixers[mixer::HEADPHONE]->is_muted();
} else if (m_mixers[mixer::SPEAKER]) {
m_volume = m_volume * (m_mapped ? m_mixers[mixer::SPEAKER]->get_normalized_volume() / 100.0f :
m_mixers[mixer::SPEAKER]->get_volume() / 100.0f);
m_volume = m_volume * (m_mapped ? m_mixers[mixer::SPEAKER]->get_normalized_volume() / 100.0f
: m_mixers[mixer::SPEAKER]->get_volume() / 100.0f);
m_muted = m_muted || m_mixers[mixer::SPEAKER]->is_muted();
}
@ -193,15 +191,13 @@ namespace modules {
}
} else if (cmd.compare(0, strlen(EVENT_VOLUME_UP), EVENT_VOLUME_UP) == 0) {
for (auto&& mixer : mixers) {
m_mapped ?
mixer->set_normalized_volume(math_util::cap<float>(mixer->get_normalized_volume() + 5, 0, 100)) :
mixer->set_volume(math_util::cap<float>(mixer->get_volume() + 5, 0, 100));
m_mapped ? mixer->set_normalized_volume(math_util::cap<float>(mixer->get_normalized_volume() + 5, 0, 100))
: mixer->set_volume(math_util::cap<float>(mixer->get_volume() + 5, 0, 100));
}
} else if (cmd.compare(0, strlen(EVENT_VOLUME_DOWN), EVENT_VOLUME_DOWN) == 0) {
for (auto&& mixer : mixers) {
m_mapped ?
mixer->set_normalized_volume(math_util::cap<float>(mixer->get_normalized_volume() - 5, 0, 100)) :
mixer->set_volume(math_util::cap<float>(mixer->get_volume() - 5, 0, 100));
m_mapped ? mixer->set_normalized_volume(math_util::cap<float>(mixer->get_normalized_volume() - 5, 0, 100))
: mixer->set_volume(math_util::cap<float>(mixer->get_volume() - 5, 0, 100));
}
} else {
return false;

View file

@ -81,12 +81,11 @@ namespace string_util {
/**
* Replace all occurrences with bounded replacement
*/
string replace_all_bounded(const string& haystack, string needle, string replacement,
size_t min, size_t max, size_t start, size_t end) {
string replace_all_bounded(
const string& haystack, string needle, string replacement, size_t min, size_t max, size_t start, size_t end) {
if (max != 0 && replacement.length() > max) {
replacement = replacement.erase(max);
}
else if (min != 0 && replacement.length() < min) {
} else if (min != 0 && replacement.length() < min) {
replacement.insert(0, min - replacement.length(), ' ');
}
return replace_all(haystack, needle, replacement, start, end);

View file

@ -12,7 +12,8 @@ namespace graphics_util {
/**
* Create a basic window
*/
bool create_window(connection& conn, xcb_window_t* win, int16_t x, int16_t y, uint16_t w, uint16_t h, xcb_window_t root) {
bool create_window(
connection& conn, xcb_window_t* win, int16_t x, int16_t y, uint16_t w, uint16_t h, xcb_window_t root) {
if (!root) {
root = conn.screen()->root;
}

View file

@ -1,6 +1,6 @@
#include "x11/randr.hpp"
#include "x11/connection.hpp"
#include "utils/string.hpp"
#include "x11/connection.hpp"
POLYBAR_NS

View file

@ -489,14 +489,15 @@ void tray_manager::query_atom() { // {{{
void tray_manager::create_window() { // {{{
m_log.trace("tray: Create tray window");
// clang-format off
auto win = winspec(m_connection, m_tray)
<< cw_size(calculate_w(), calculate_h())
<< cw_pos(calculate_x(calculate_w()), calculate_y())
<< cw_class(XCB_WINDOW_CLASS_INPUT_OUTPUT)
<< cw_params_backing_store(XCB_BACKING_STORE_WHEN_MAPPED)
<< cw_params_event_mask(XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_STRUCTURE_NOTIFY)
<< cw_params_override_redirect(true)
;
<< cw_params_override_redirect(true);
// clang-format on
if (!m_opts.transparent) {
win << cw_params_back_pixel(m_opts.background);

View file

@ -5,8 +5,8 @@
#include "x11/window.hpp"
#include "x11/xutils.hpp"
#include "x11/color.hpp"
#include "components/types.hpp"
#include "x11/color.hpp"
POLYBAR_NS

View file

@ -1,8 +1,8 @@
#include <xcb/xcb_icccm.h>
#include "x11/atoms.hpp"
#include "x11/wm.hpp"
#include "x11/connection.hpp"
#include "x11/wm.hpp"
POLYBAR_NS
@ -17,13 +17,12 @@ namespace wm_util {
}
void set_windowtype(connection& conn, xcb_window_t win, vector<xcb_atom_t> types) {
conn.change_property(XCB_PROP_MODE_REPLACE, win, _NET_WM_WINDOW_TYPE, XCB_ATOM_ATOM, 32,
types.size(), types.data());
conn.change_property(
XCB_PROP_MODE_REPLACE, win, _NET_WM_WINDOW_TYPE, XCB_ATOM_ATOM, 32, types.size(), types.data());
}
void set_wmstate(connection& conn, xcb_window_t win, vector<xcb_atom_t> states) {
conn.change_property(
XCB_PROP_MODE_REPLACE, win, _NET_WM_STATE, XCB_ATOM_ATOM, 32, states.size(), states.data());
conn.change_property(XCB_PROP_MODE_REPLACE, win, _NET_WM_STATE, XCB_ATOM_ATOM, 32, states.size(), states.data());
}
void set_wmpid(connection& conn, xcb_window_t win, pid_t pid) {
@ -33,18 +32,16 @@ namespace wm_util {
void set_wmdesktop(connection& conn, xcb_window_t win, uint32_t desktop) {
const uint32_t value_list[1]{desktop};
conn.change_property(
XCB_PROP_MODE_REPLACE, win, _NET_WM_DESKTOP, XCB_ATOM_CARDINAL, 32, 1, value_list);
conn.change_property(XCB_PROP_MODE_REPLACE, win, _NET_WM_DESKTOP, XCB_ATOM_CARDINAL, 32, 1, value_list);
}
void set_trayorientation(connection& conn, xcb_window_t win, uint32_t orientation) {
conn.change_property(XCB_PROP_MODE_REPLACE, win, _NET_SYSTEM_TRAY_ORIENTATION,
_NET_SYSTEM_TRAY_ORIENTATION, 32, 1, &orientation);
conn.change_property(
XCB_PROP_MODE_REPLACE, win, _NET_SYSTEM_TRAY_ORIENTATION, _NET_SYSTEM_TRAY_ORIENTATION, 32, 1, &orientation);
}
void set_trayvisual(connection& conn, xcb_window_t win, xcb_visualid_t visual) {
conn.change_property(
XCB_PROP_MODE_REPLACE, win, _NET_SYSTEM_TRAY_VISUAL, XCB_ATOM_VISUALID, 32, 1, &visual);
conn.change_property(XCB_PROP_MODE_REPLACE, win, _NET_SYSTEM_TRAY_VISUAL, XCB_ATOM_VISUALID, 32, 1, &visual);
}
}

View file

@ -27,8 +27,7 @@ namespace xembed {
/**
* Send _XEMBED messages
*/
void send_message(
connection& conn, xcb_window_t target, long message, long d1, long d2, long d3) {
void send_message(connection& conn, xcb_window_t target, long message, long d1, long d2, long d3) {
auto msg = conn.make_client_message(_XEMBED, target);
msg->data.data32[0] = XCB_CURRENT_TIME;
msg->data.data32[1] = message;

View file

@ -1,5 +1,5 @@
#include "x11/atoms.hpp"
#include "x11/xutils.hpp"
#include "x11/atoms.hpp"
#include "x11/connection.hpp"
#include "x11/xlib.hpp"