refactor: Cleanup
This commit is contained in:
parent
c1aa3319a1
commit
8cc885c316
@ -3,6 +3,7 @@
|
||||
#include <mutex>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
// fwd
|
||||
struct _snd_ctl;
|
||||
|
@ -39,6 +39,7 @@
|
||||
#endif
|
||||
|
||||
#include "common.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "errors.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <mutex>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
// fwd
|
||||
struct _snd_mixer;
|
||||
|
@ -11,14 +11,12 @@
|
||||
#endif
|
||||
|
||||
#include "common.hpp"
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "errors.hpp"
|
||||
#include "utils/math.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace chrono = std::chrono;
|
||||
|
||||
class file_descriptor;
|
||||
|
||||
namespace net {
|
||||
@ -45,7 +43,7 @@ namespace net {
|
||||
struct link_activity {
|
||||
bytes_t transmitted{0};
|
||||
bytes_t received{0};
|
||||
chrono::system_clock::time_point time;
|
||||
std::chrono::system_clock::time_point time;
|
||||
};
|
||||
|
||||
struct link_status {
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "config.hpp"
|
||||
#include <vector>
|
||||
|
||||
#define POLYBAR_NS \
|
||||
namespace polybar { \
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <mutex>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "components/types.hpp"
|
||||
#include "errors.hpp"
|
||||
#include "events/signal_fwd.hpp"
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include "common.hpp"
|
||||
#include "errors.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
@ -27,8 +26,12 @@ namespace command_line {
|
||||
string token;
|
||||
const choices values;
|
||||
|
||||
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) {}
|
||||
explicit option(string&& flag, string&& flag_long, string&& desc, string&& token = "", const choices&& c = {})
|
||||
: flag(forward<string>(flag))
|
||||
, flag_long(forward<string>(flag_long))
|
||||
, desc(forward<string>(desc))
|
||||
, token(forward<string>(token))
|
||||
, values(forward<const choices>(c)) {}
|
||||
};
|
||||
|
||||
// }}}
|
||||
@ -67,8 +70,4 @@ namespace command_line {
|
||||
// }}}
|
||||
}
|
||||
|
||||
using cliparser = command_line::parser;
|
||||
using clioption = command_line::option;
|
||||
using clioptions = command_line::options;
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "common.hpp"
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <thread>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "events/signal_fwd.hpp"
|
||||
#include "events/signal_receiver.hpp"
|
||||
#include "events/types.hpp"
|
||||
|
@ -1,14 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "events/signal_emitter.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "utils/concurrency.hpp"
|
||||
#include "utils/functional.hpp"
|
||||
#include "utils/file.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
class file_descriptor;
|
||||
class logger;
|
||||
class signal_emitter;
|
||||
|
||||
/**
|
||||
* Message types
|
||||
*/
|
||||
|
@ -5,7 +5,7 @@
|
||||
#endif
|
||||
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
@ -23,7 +23,7 @@ namespace debug_util {
|
||||
|
||||
explicit scope_timer() : m_start(clock_t::now()) {}
|
||||
~scope_timer() {
|
||||
std::cout << std::chrono::duration_cast<duration_t>(clock_t::now() - m_start).count() << "ms" << std::endl;
|
||||
printf("%lums\n", std::chrono::duration_cast<duration_t>(clock_t::now() - m_start).count());
|
||||
}
|
||||
|
||||
private:
|
||||
@ -39,13 +39,12 @@ namespace debug_util {
|
||||
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;
|
||||
printf("execution speed: %lums\n", std::chrono::duration_cast<std::chrono::milliseconds>(finish - start).count());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void memory_usage(const T& object) noexcept {
|
||||
std::cout << "memory usage: " << sizeof(object) << "b" << std::endl;
|
||||
printf("memory usage: %lub\n", sizeof(object));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "components/config.hpp"
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "modules/meta/inotify_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "modules/meta/timer_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "components/config.hpp"
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "modules/meta/timer_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "modules/meta/timer_module.hpp"
|
||||
#include "utils/http.hpp"
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <i3ipc++/ipc.hpp>
|
||||
|
||||
#include "components/config.hpp"
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "modules/meta/event_module.hpp"
|
||||
#include "modules/meta/input_handler.hpp"
|
||||
#include "utils/i3.hpp"
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "modules/meta/timer_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <istream>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "modules/meta/timer_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "modules/meta/event_module.hpp"
|
||||
#include "modules/meta/input_handler.hpp"
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "components/config.hpp"
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "modules/meta/event_handler.hpp"
|
||||
#include "modules/meta/input_handler.hpp"
|
||||
#include "modules/meta/static_module.hpp"
|
||||
|
107
include/settings.hpp
Normal file
107
include/settings.hpp
Normal file
@ -0,0 +1,107 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "version.hpp"
|
||||
|
||||
#define APP_NAME "polybar"
|
||||
#define APP_VERSION "2.4.8-9-gc1aa331-git"
|
||||
#ifndef APP_VERSION
|
||||
#define APP_VERSION GIT_TAG
|
||||
#endif
|
||||
#define BASE_PATH "/home/jaagr/.local/var/github/jaagr/polybar"
|
||||
|
||||
#define ENABLE_ALSA 1
|
||||
#define ENABLE_MPD 1
|
||||
#define ENABLE_NETWORK 1
|
||||
#define ENABLE_I3 1
|
||||
#define ENABLE_CURL 1
|
||||
|
||||
#define WITH_XRANDR 1
|
||||
#define WITH_XRENDER 0
|
||||
#define WITH_XDAMAGE 0
|
||||
#define WITH_XSYNC 0
|
||||
#define WITH_XCOMPOSITE 0
|
||||
#define WITH_XKB 1
|
||||
#define XPP_EXTENSION_LIST xpp::randr::extension, xpp::xkb::extension
|
||||
|
||||
/* #undef DEBUG_LOGGER */
|
||||
/* #undef VERBOSE_TRACELOG */
|
||||
/* #undef DEBUG_HINTS */
|
||||
|
||||
static const size_t EVENT_SIZE{64UL};
|
||||
|
||||
static const int SIGN_PRIORITY_CONTROLLER{1};
|
||||
static const int SIGN_PRIORITY_SCREEN{2};
|
||||
static const int SIGN_PRIORITY_BAR{3};
|
||||
static const int SIGN_PRIORITY_RENDERER{4};
|
||||
static const int SIGN_PRIORITY_TRAY{5};
|
||||
|
||||
static const int SINK_PRIORITY_BAR{1};
|
||||
static const int SINK_PRIORITY_SCREEN{2};
|
||||
static const int SINK_PRIORITY_TRAY{3};
|
||||
static const int SINK_PRIORITY_MODULE{4};
|
||||
|
||||
#ifdef DEBUG_HINTS
|
||||
static const int DEBUG_HINTS_OFFSET_X{0};
|
||||
static const int DEBUG_HINTS_OFFSET_Y{0};
|
||||
#endif
|
||||
|
||||
static constexpr const char* ALSA_SOUNDCARD{"default"};
|
||||
static constexpr const char* BSPWM_SOCKET_PATH{"/tmp/bspwm_0_0-socket"};
|
||||
static constexpr const char* BSPWM_STATUS_PREFIX{"W"};
|
||||
static constexpr const char* CONNECTION_TEST_IP{"8.8.8.8"};
|
||||
static constexpr const char* PATH_ADAPTER{"/sys/class/power_supply/%adapter%"};
|
||||
static constexpr const char* PATH_BACKLIGHT_MAX{"/sys/class/backlight/%card%/max_brightness"};
|
||||
static constexpr const char* PATH_BACKLIGHT_VAL{"/sys/class/backlight/%card%/brightness"};
|
||||
static constexpr const char* PATH_BATTERY{"/sys/class/power_supply/%battery%"};
|
||||
static constexpr const char* PATH_CPU_INFO{"/proc/stat"};
|
||||
static constexpr const char* PATH_MEMORY_INFO{"/proc/meminfo"};
|
||||
static constexpr const char* PATH_MESSAGING_FIFO{"/tmp/polybar_mqueue.%pid%"};
|
||||
static constexpr const char* PATH_TEMPERATURE_INFO{"/sys/class/thermal/thermal_zone%zone%/temp"};
|
||||
|
||||
static constexpr const char* BUILDER_SPACE_TOKEN{"%__"};
|
||||
|
||||
const auto version_details = [](const std::vector<std::string>& args) {
|
||||
for (auto&& arg : args) {
|
||||
if (arg.compare(0, 3, "-vv") == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
const auto print_build_info = [](bool extended = false) {
|
||||
printf("%s %s\n\n", APP_NAME, APP_VERSION);
|
||||
printf("Features: %calsa %ccurl %ci3 %cmpd %cnetwork\n",
|
||||
(ENABLE_ALSA ? '+' : '-'),
|
||||
(ENABLE_CURL ? '+' : '-'),
|
||||
(ENABLE_I3 ? '+' : '-'),
|
||||
(ENABLE_MPD ? '+' : '-'),
|
||||
(ENABLE_NETWORK ? '+' : '-'));
|
||||
if (extended) {
|
||||
printf("\n");
|
||||
printf("Build type: RelWithDebInfo\n");
|
||||
printf("Compiler: /usr/bin/c++\n");
|
||||
printf("Compiler flags: -Wall -Wextra -Werror -O2 -pedantic -pedantic-errors\n");
|
||||
printf("Linker flags: \n");
|
||||
printf("\n");
|
||||
printf("ALSA_SOUNDCARD %s\n", ALSA_SOUNDCARD);
|
||||
printf("BSPWM_SOCKET_PATH %s\n", BSPWM_SOCKET_PATH);
|
||||
printf("BSPWM_STATUS_PREFIX %s\n", BSPWM_STATUS_PREFIX);
|
||||
printf("BUILDER_SPACE_TOKEN %s\n", BUILDER_SPACE_TOKEN);
|
||||
printf("CONNECTION_TEST_IP %s\n", CONNECTION_TEST_IP);
|
||||
printf("PATH_ADAPTER %s\n", PATH_ADAPTER);
|
||||
printf("PATH_BACKLIGHT_MAX %s\n", PATH_BACKLIGHT_MAX);
|
||||
printf("PATH_BACKLIGHT_VAL %s\n", PATH_BACKLIGHT_VAL);
|
||||
printf("PATH_BATTERY %s\n", PATH_BATTERY);
|
||||
printf("PATH_CPU_INFO %s\n", PATH_CPU_INFO);
|
||||
printf("PATH_MEMORY_INFO %s\n", PATH_MEMORY_INFO);
|
||||
printf("PATH_TEMPERATURE_INFO %s\n", PATH_TEMPERATURE_INFO);
|
||||
}
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
// vim:ft=cpp
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "version.hpp"
|
||||
@ -30,7 +31,7 @@
|
||||
#cmakedefine VERBOSE_TRACELOG
|
||||
#cmakedefine DEBUG_HINTS
|
||||
|
||||
static const size_t EVENT_SIZE{64U};
|
||||
static const size_t EVENT_SIZE{64UL};
|
||||
|
||||
static const int SIGN_PRIORITY_CONTROLLER{1};
|
||||
static const int SIGN_PRIORITY_SCREEN{2};
|
||||
@ -44,12 +45,8 @@ static const int SINK_PRIORITY_TRAY{3};
|
||||
static const int SINK_PRIORITY_MODULE{4};
|
||||
|
||||
#ifdef DEBUG_HINTS
|
||||
static const int DEBUG_HINTS_OFFSET_X {
|
||||
@DEBUG_HINTS_OFFSET_X@
|
||||
};
|
||||
static const int DEBUG_HINTS_OFFSET_Y {
|
||||
@DEBUG_HINTS_OFFSET_Y@
|
||||
};
|
||||
static const int DEBUG_HINTS_OFFSET_X{@DEBUG_HINTS_OFFSET_X@};
|
||||
static const int DEBUG_HINTS_OFFSET_Y{@DEBUG_HINTS_OFFSET_Y@};
|
||||
#endif
|
||||
|
||||
static constexpr const char* ALSA_SOUNDCARD{"@SETTING_ALSA_SOUNDCARD@"};
|
||||
@ -67,7 +64,7 @@ static constexpr const char* PATH_TEMPERATURE_INFO{"@SETTING_PATH_TEMPERATURE_IN
|
||||
|
||||
static constexpr const char* BUILDER_SPACE_TOKEN{"%__"};
|
||||
|
||||
auto version_details = [](const std::vector<std::string>& args) {
|
||||
const auto version_details = [](const std::vector<std::string>& args) {
|
||||
for (auto&& arg : args) {
|
||||
if (arg.compare(0, 3, "-vv") == 0)
|
||||
return true;
|
||||
@ -76,36 +73,34 @@ auto version_details = [](const std::vector<std::string>& args) {
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
auto print_build_info = [](bool extended = false) {
|
||||
std::cout << APP_NAME << " " << APP_VERSION << " " << "\n"
|
||||
<< "\n"
|
||||
<< "Features: "
|
||||
<< (ENABLE_ALSA ? "+" : "-") << "alsa "
|
||||
<< (ENABLE_CURL ? "+" : "-") << "curl "
|
||||
<< (ENABLE_I3 ? "+" : "-") << "i3 "
|
||||
<< (ENABLE_MPD ? "+" : "-") << "mpd "
|
||||
<< (ENABLE_NETWORK ? "+" : "-") << "network "
|
||||
<< "\n";
|
||||
if (!extended)
|
||||
return;
|
||||
std::cout << "\n"
|
||||
<< "Build type: @CMAKE_BUILD_TYPE@" << "\n"
|
||||
<< "Compiler: @CMAKE_CXX_COMPILER@" << "\n"
|
||||
<< "Compiler flags: @CMAKE_CXX_FLAGS@" << "\n"
|
||||
<< "Linker flags: @CMAKE_EXE_LINKER_FLAGS@" << "\n"
|
||||
<< "\n"
|
||||
<< "ALSA_SOUNDCARD " << ALSA_SOUNDCARD << "\n"
|
||||
<< "BSPWM_SOCKET_PATH " << BSPWM_SOCKET_PATH << "\n"
|
||||
<< "BSPWM_STATUS_PREFIX " << BSPWM_STATUS_PREFIX << "\n"
|
||||
<< "BUILDER_SPACE_TOKEN " << BUILDER_SPACE_TOKEN << "\n"
|
||||
<< "CONNECTION_TEST_IP " << CONNECTION_TEST_IP << "\n"
|
||||
<< "PATH_ADAPTER " << PATH_ADAPTER << "\n"
|
||||
<< "PATH_BACKLIGHT_MAX " << PATH_BACKLIGHT_MAX << "\n"
|
||||
<< "PATH_BACKLIGHT_VAL " << PATH_BACKLIGHT_VAL << "\n"
|
||||
<< "PATH_BATTERY " << PATH_BATTERY << "\n"
|
||||
<< "PATH_CPU_INFO " << PATH_CPU_INFO << "\n"
|
||||
<< "PATH_MEMORY_INFO " << PATH_MEMORY_INFO << "\n"
|
||||
<< "PATH_TEMPERATURE_INFO " << PATH_TEMPERATURE_INFO << "\n";
|
||||
const auto print_build_info = [](bool extended = false) {
|
||||
printf("%s %s\n\n", APP_NAME, APP_VERSION);
|
||||
printf("Features: %calsa %ccurl %ci3 %cmpd %cnetwork\n",
|
||||
(ENABLE_ALSA ? '+' : '-'),
|
||||
(ENABLE_CURL ? '+' : '-'),
|
||||
(ENABLE_I3 ? '+' : '-'),
|
||||
(ENABLE_MPD ? '+' : '-'),
|
||||
(ENABLE_NETWORK ? '+' : '-'));
|
||||
if (extended) {
|
||||
printf("\n");
|
||||
printf("Build type: @CMAKE_BUILD_TYPE@\n");
|
||||
printf("Compiler: @CMAKE_CXX_COMPILER@\n");
|
||||
printf("Compiler flags: @CMAKE_CXX_FLAGS@\n");
|
||||
printf("Linker flags: @CMAKE_EXE_LINKER_FLAGS@\n");
|
||||
printf("\n");
|
||||
printf("ALSA_SOUNDCARD %s\n", ALSA_SOUNDCARD);
|
||||
printf("BSPWM_SOCKET_PATH %s\n", BSPWM_SOCKET_PATH);
|
||||
printf("BSPWM_STATUS_PREFIX %s\n", BSPWM_STATUS_PREFIX);
|
||||
printf("BUILDER_SPACE_TOKEN %s\n", BUILDER_SPACE_TOKEN);
|
||||
printf("CONNECTION_TEST_IP %s\n", CONNECTION_TEST_IP);
|
||||
printf("PATH_ADAPTER %s\n", PATH_ADAPTER);
|
||||
printf("PATH_BACKLIGHT_MAX %s\n", PATH_BACKLIGHT_MAX);
|
||||
printf("PATH_BACKLIGHT_VAL %s\n", PATH_BACKLIGHT_VAL);
|
||||
printf("PATH_BATTERY %s\n", PATH_BATTERY);
|
||||
printf("PATH_CPU_INFO %s\n", PATH_CPU_INFO);
|
||||
printf("PATH_MEMORY_INFO %s\n", PATH_MEMORY_INFO);
|
||||
printf("PATH_TEMPERATURE_INFO %s\n", PATH_TEMPERATURE_INFO);
|
||||
}
|
||||
};
|
||||
// clang-format on
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <xcb/xcb_icccm.h>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "utils/socket.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "x11/extensions/randr.hpp"
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <streambuf>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
|
||||
@ -75,7 +77,7 @@ class fd_streambuf : public std::streambuf {
|
||||
char m_in[BUFSIZ - 1]{};
|
||||
};
|
||||
|
||||
template <typename StreamType = std::ostream>
|
||||
template <typename StreamType>
|
||||
class fd_stream : public StreamType {
|
||||
public:
|
||||
using type = fd_stream<StreamType>;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
#if WITH_XDAMAGE
|
||||
#include "x11/extensions/damage.hpp"
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
#if not WITH_XCOMPOSITE
|
||||
#error "X Composite extension is disabled..."
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
#if not WITH_XDAMAGE
|
||||
#error "X Damage extension is disabled..."
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
namespace xpp {
|
||||
#if WITH_XDAMAGE
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
#if not WITH_XRANDR
|
||||
#error "X RandR extension is disabled..."
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
#if not WITH_XRENDER
|
||||
#error "X Render extension is disabled..."
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
#if not WITH_XSYNC
|
||||
#error "X Sync extension is disabled..."
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
#if not WITH_XKB
|
||||
#error "X xkb extension is disabled..."
|
||||
|
@ -161,6 +161,6 @@ execute_process(COMMAND git describe --tags --dirty=-git
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
|
||||
|
||||
configure_file(
|
||||
${PROJECT_SOURCE_DIR}/include/config.hpp.cmake
|
||||
${CMAKE_SOURCE_DIR}/include/config.hpp
|
||||
${PROJECT_SOURCE_DIR}/include/settings.hpp.cmake
|
||||
${CMAKE_SOURCE_DIR}/include/settings.hpp
|
||||
ESCAPE_QUOTES @ONLY)
|
||||
|
@ -22,7 +22,7 @@
|
||||
#endif
|
||||
|
||||
#include "common.hpp"
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "utils/command.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/string.hpp"
|
||||
@ -67,7 +67,7 @@ namespace net {
|
||||
m_status.previous = m_status.current;
|
||||
m_status.current.transmitted = 0;
|
||||
m_status.current.received = 0;
|
||||
m_status.current.time = chrono::system_clock::now();
|
||||
m_status.current.time = std::chrono::system_clock::now();
|
||||
|
||||
for (auto ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) {
|
||||
if (ifa->ifa_addr == nullptr) {
|
||||
@ -183,7 +183,7 @@ namespace net {
|
||||
*/
|
||||
string network::format_speedrate(float bytes_diff, int minwidth) const {
|
||||
const auto duration = m_status.current.time - m_status.previous.time;
|
||||
float time_diff = chrono::duration_cast<chrono::seconds>(duration).count();
|
||||
float time_diff = std::chrono::duration_cast<std::chrono::seconds>(duration).count();
|
||||
float speedrate = bytes_diff / (time_diff ? time_diff : 1);
|
||||
|
||||
vector<string> suffixes{"GB", "MB"};
|
||||
|
@ -1,31 +1,30 @@
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
|
||||
#include "components/command_line.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace command_line {
|
||||
/**
|
||||
* Create instance
|
||||
*/
|
||||
cliparser::make_type cliparser::make(string&& scriptname, const clioptions&& opts) {
|
||||
return factory_util::unique<cliparser>(
|
||||
parser::make_type parser::make(string&& scriptname, const options&& opts) {
|
||||
return factory_util::unique<parser>(
|
||||
"Usage: " + scriptname + " bar_name [OPTION...]", forward<decltype(opts)>(opts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct parser
|
||||
*/
|
||||
cliparser::parser(string&& synopsis, const options&& opts)
|
||||
parser::parser(string&& synopsis, const options&& opts)
|
||||
: m_synopsis(forward<decltype(synopsis)>(synopsis)), m_opts(forward<decltype(opts)>(opts)) {}
|
||||
|
||||
/**
|
||||
* Print application usage message
|
||||
*/
|
||||
void cliparser::usage() const {
|
||||
std::cout << m_synopsis << "\n\n";
|
||||
void parser::usage() const {
|
||||
printf("%s\n\n", m_synopsis.c_str());
|
||||
|
||||
// get the length of the longest string in the flag column
|
||||
// which is used to align the description fields
|
||||
@ -39,38 +38,38 @@ void cliparser::usage() const {
|
||||
for (auto& opt : m_opts) {
|
||||
size_t pad = maxlen - opt.flag_long.length() - opt.token.length();
|
||||
|
||||
std::cout << " " << opt.flag << ", " << opt.flag_long;
|
||||
printf(" %s, %s", opt.flag.c_str(), opt.flag_long.c_str());
|
||||
|
||||
if (!opt.token.empty()) {
|
||||
std::cout << "=" << opt.token;
|
||||
printf("=%s", opt.token.c_str());
|
||||
pad--;
|
||||
}
|
||||
|
||||
// output the list with accepted values
|
||||
if (!opt.values.empty()) {
|
||||
std::cout << std::setw(pad + opt.desc.length()) << std::setfill(' ') << opt.desc << '\n';
|
||||
printf("%*s\n", static_cast<int>(pad + opt.desc.length()), opt.desc.c_str());
|
||||
|
||||
pad = pad + opt.flag_long.length() + opt.token.length() + 7;
|
||||
|
||||
std::cout << string(pad, ' ') << opt.token << " is one of: ";
|
||||
printf("%*c%s is one of: ", static_cast<int>(pad), ' ', opt.token.c_str());
|
||||
|
||||
for (auto& v : opt.values) {
|
||||
std::cout << v << (v != opt.values.back() ? ", " : "");
|
||||
printf("%s%s", v.c_str(), v != opt.values.back() ? ", " : "");
|
||||
}
|
||||
} else {
|
||||
std::cout << std::setw(pad + opt.desc.length()) << std::setfill(' ') << opt.desc;
|
||||
printf("%*s", static_cast<int>(pad + opt.desc.length()), opt.desc.c_str());
|
||||
}
|
||||
|
||||
std::cout << '\n';
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Process input values
|
||||
*/
|
||||
void cliparser::process_input(const vector<string>& values) {
|
||||
void parser::process_input(const vector<string>& values) {
|
||||
for (size_t i = 0; i < values.size(); i++) {
|
||||
parse(values[i], values.size() > i + 1 ? values[i + 1] : "");
|
||||
}
|
||||
@ -79,14 +78,14 @@ void cliparser::process_input(const vector<string>& values) {
|
||||
/**
|
||||
* Test if the passed option was provided
|
||||
*/
|
||||
bool cliparser::has(const string& option) const {
|
||||
bool parser::has(const string& option) const {
|
||||
return m_optvalues.find(option) != m_optvalues.end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value defined for given option
|
||||
*/
|
||||
string cliparser::get(string opt) const {
|
||||
string parser::get(string opt) const {
|
||||
if (has(forward<string>(opt))) {
|
||||
return m_optvalues.find(opt)->second;
|
||||
}
|
||||
@ -96,43 +95,43 @@ string cliparser::get(string opt) const {
|
||||
/**
|
||||
* Compare option value with given string
|
||||
*/
|
||||
bool cliparser::compare(string opt, const string& val) const {
|
||||
bool parser::compare(string opt, const string& val) const {
|
||||
return get(move(opt)) == val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare option with its short version
|
||||
*/
|
||||
auto cliparser::is_short(const string& option, const string& opt_short) const {
|
||||
auto parser::is_short(const string& option, const string& opt_short) const {
|
||||
return option.compare(0, opt_short.length(), opt_short) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare option with its long version
|
||||
*/
|
||||
auto cliparser::is_long(const string& option, const string& opt_long) const {
|
||||
auto parser::is_long(const string& option, const string& opt_long) const {
|
||||
return option.compare(0, opt_long.length(), opt_long) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare option with both versions
|
||||
*/
|
||||
auto cliparser::is(const string& option, string opt_short, string opt_long) const {
|
||||
auto parser::is(const string& option, string opt_short, string opt_long) const {
|
||||
return is_short(option, move(opt_short)) || is_long(option, move(opt_long));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse option value
|
||||
*/
|
||||
auto cliparser::parse_value(string input, const string& input_next, choices values) const {
|
||||
auto parser::parse_value(string input, const string& input_next, choices values) const {
|
||||
string opt = move(input);
|
||||
size_t pos;
|
||||
string value;
|
||||
|
||||
if (input_next.empty() && opt.compare(0, 2, "--") != 0) {
|
||||
throw value_error("Missing value for " + opt);
|
||||
throw value_error("Undefined argument for option " + opt);
|
||||
} else if ((pos = opt.find('=')) == string::npos && opt.compare(0, 2, "--") == 0) {
|
||||
throw value_error("Missing value for " + opt);
|
||||
throw value_error("Undefined argument for option " + opt);
|
||||
} else if (pos == string::npos && !input_next.empty()) {
|
||||
value = input_next;
|
||||
} else {
|
||||
@ -141,7 +140,7 @@ auto cliparser::parse_value(string input, const string& input_next, choices valu
|
||||
}
|
||||
|
||||
if (!values.empty() && std::find(values.begin(), values.end(), value) == values.end()) {
|
||||
throw value_error("Invalid value '" + value + "' for argument " + string{opt});
|
||||
throw value_error("Invalid argument for option " + opt);
|
||||
}
|
||||
|
||||
return value;
|
||||
@ -150,7 +149,7 @@ auto cliparser::parse_value(string input, const string& input_next, choices valu
|
||||
/**
|
||||
* Parse and validate passed arguments and flags
|
||||
*/
|
||||
void cliparser::parse(const string& input, const string& input_next) {
|
||||
void parser::parse(const string& input, const string& input_next) {
|
||||
if (m_skipnext) {
|
||||
m_skipnext = false;
|
||||
if (!input_next.empty()) {
|
||||
@ -176,5 +175,6 @@ void cliparser::parse(const string& input, const string& input_next) {
|
||||
throw argument_error("Unrecognized option " + input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -1,14 +1,12 @@
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "components/ipc.hpp"
|
||||
#include "config.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "events/signal.hpp"
|
||||
#include "events/signal_emitter.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/io.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include "events/signal.hpp"
|
||||
#include "events/signal_emitter.hpp"
|
||||
#include "utils/color.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/math.hpp"
|
||||
#include "utils/memory.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include "events/signal.hpp"
|
||||
#include "events/signal_emitter.hpp"
|
||||
#include "events/signal_receiver.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "x11/connection.hpp"
|
||||
#include "x11/draw.hpp"
|
||||
#include "x11/extensions/all.hpp"
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "components/logger.hpp"
|
||||
#include "components/parser.hpp"
|
||||
#include "components/renderer.hpp"
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "utils/env.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/inotify.hpp"
|
||||
@ -47,7 +47,7 @@ int main(int argc, char** argv) {
|
||||
string scriptname{argv[0]};
|
||||
vector<string> args{argv + 1, argv + argc};
|
||||
|
||||
cliparser::make_type cli{cliparser::make(move(scriptname), move(opts))};
|
||||
command_line::parser::make_type cli{command_line::parser::make(move(scriptname), move(opts))};
|
||||
cli->process_input(args);
|
||||
|
||||
if (cli->has("quiet")) {
|
||||
|
@ -36,7 +36,8 @@ namespace modules {
|
||||
if (file_util::exists((m_fstate = path_adapter + "online"))) {
|
||||
m_state_reader = make_unique<state_reader>([=] { return file_util::contents(m_fstate).compare(0, 1, "1") == 0; });
|
||||
} else if (file_util::exists((m_fstate = path_battery + "status"))) {
|
||||
m_state_reader = make_unique<state_reader>([=] { return file_util::contents(m_fstate).compare(0, 8, "Charging") == 0; });
|
||||
m_state_reader =
|
||||
make_unique<state_reader>([=] { return file_util::contents(m_fstate).compare(0, 8, "Charging") == 0; });
|
||||
} else {
|
||||
throw module_error("No suitable way to get current charge state");
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
#include <curl/curl.h>
|
||||
#include <curl/curlbuild.h>
|
||||
#include <curl/easy.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "errors.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "utils/http.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <i3ipc++/ipc.hpp>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "config.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "utils/i3.hpp"
|
||||
#include "utils/socket.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
Loading…
Reference in New Issue
Block a user