refactor: Optimize build
This commit is contained in:
parent
4b576bd23b
commit
c6d85b2b92
@ -1,7 +1,6 @@
|
||||
#
|
||||
# Core setup
|
||||
#
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
@ -15,25 +14,27 @@ if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
endif()
|
||||
|
||||
# Generic compiler flags
|
||||
# Compiler flags
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
|
||||
|
||||
# Debug specific compiler flags
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-stack-protector")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g2")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pedantic")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pedantic-errors")
|
||||
|
||||
# Release specific compiler flags
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
|
||||
# Linker flags
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
|
||||
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -s")
|
||||
|
||||
# Compiler specific flags
|
||||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL Clang)
|
||||
# Check compiler
|
||||
if(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
|
||||
message_colored(STATUS "Using supported compiler ${CMAKE_CXX_COMPILER_ID}" 32)
|
||||
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL GNU)
|
||||
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
|
||||
message_colored(STATUS "Using supported compiler ${CMAKE_CXX_COMPILER_ID}" 32)
|
||||
else()
|
||||
message_colored(WARNING "Using unsupported compiler ${CMAKE_CXX_COMPILER_ID} !" 31)
|
||||
|
@ -2,14 +2,23 @@
|
||||
# Output build summary
|
||||
#
|
||||
|
||||
message(STATUS "---------------------------")
|
||||
message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
|
||||
function(colored_option message_level text var color_on color_off)
|
||||
string(ASCII 27 esc)
|
||||
if(${var})
|
||||
message(${message_level} "${esc}[${color_on}m${text}${esc}[0m")
|
||||
else()
|
||||
message(${message_level} "${esc}[${color_off}m${text}${esc}[0m")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
message(STATUS "--------------------------")
|
||||
message_colored(STATUS " Build type: ${CMAKE_BUILD_TYPE}" "32;1")
|
||||
message(STATUS " Compiler C: ${CMAKE_C_COMPILER}")
|
||||
message(STATUS " Compiler C++: ${CMAKE_CXX_COMPILER}")
|
||||
message(STATUS " Compiler flags: ${CMAKE_CXX_FLAGS}")
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
message(STATUS " + debug flags:: ${CMAKE_CXX_FLAGS_DEBUG}")
|
||||
message(STATUS " debug flags: ${CMAKE_CXX_FLAGS_DEBUG}")
|
||||
if(NOT DEFINED ${DEBUG_LOGGER})
|
||||
set(DEBUG_LOGGER ON)
|
||||
endif()
|
||||
@ -17,50 +26,52 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(ENABLE_CCACHE ON)
|
||||
endif()
|
||||
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
message(STATUS " + release flags:: ${CMAKE_CXX_FLAGS_RELEASE}")
|
||||
message(STATUS " release: ${CMAKE_CXX_FLAGS_RELEASE}")
|
||||
elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
|
||||
message(STATUS " + minsizerel flags:: ${CMAKE_CXX_FLAGS_MINSIZEREL}")
|
||||
message(STATUS " minsizerel: ${CMAKE_CXX_FLAGS_MINSIZEREL}")
|
||||
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
||||
message(STATUS " + relwithdebinfo flags:: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
|
||||
message(STATUS " relwithdebinfo: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
|
||||
endif()
|
||||
|
||||
message(STATUS " Linker flags: ${CMAKE_EXE_LINKER_FLAGS}")
|
||||
|
||||
if(CXXLIB_CLANG)
|
||||
message(STATUS " Linking C++ library: libc++")
|
||||
message(STATUS " C++ library: libc++")
|
||||
elseif(CXXLIB_GCC)
|
||||
message(STATUS " Linking C++ library: libstdc++")
|
||||
message(STATUS " C++ library: libstdc++")
|
||||
else()
|
||||
message(STATUS " Linking C++ library: system default")
|
||||
message(STATUS " C++ library: system default")
|
||||
endif()
|
||||
|
||||
message(STATUS "--------------------------------------------")
|
||||
message(STATUS " Build testsuite ${BUILD_TESTS}")
|
||||
message(STATUS " Enable debug logger ${DEBUG_LOGGER}")
|
||||
message(STATUS " Enable extra tracing ${VERBOSE_TRACELOG}")
|
||||
message(STATUS " Enable ccache support ${ENABLE_CCACHE}")
|
||||
message(STATUS "--------------------------------------------")
|
||||
message(STATUS " Enable alsa support ${ENABLE_ALSA}")
|
||||
message(STATUS " Enable i3 support ${ENABLE_I3}")
|
||||
message(STATUS " Enable mpd support ${ENABLE_MPD}")
|
||||
message(STATUS " Enable network support ${ENABLE_NETWORK}")
|
||||
message(STATUS "--------------------------------------------")
|
||||
message(STATUS " Enable X RandR ${ENABLE_RANDR_EXT}")
|
||||
message(STATUS " Enable X Render ${ENABLE_RENDER_EXT}")
|
||||
message(STATUS " Enable X Damage ${ENABLE_DAMAGE_EXT}")
|
||||
message(STATUS "--------------------------------------------")
|
||||
message(STATUS " ALSA_SOUNDCARD ${SETTING_ALSA_SOUNDCARD}")
|
||||
message(STATUS " BSPWM_SOCKET_PATH ${SETTING_BSPWM_SOCKET_PATH}")
|
||||
message(STATUS " BSPWM_STATUS_PREFIX ${SETTING_BSPWM_STATUS_PREFIX}")
|
||||
message(STATUS " CONNECTION_TEST_IP ${SETTING_CONNECTION_TEST_IP}")
|
||||
message(STATUS " PATH_ADAPTER_STATUS ${SETTING_PATH_ADAPTER_STATUS}")
|
||||
message(STATUS " PATH_BACKLIGHT_VAL ${SETTING_PATH_BACKLIGHT_VAL}")
|
||||
message(STATUS " PATH_BACKLIGHT_MAX ${SETTING_PATH_BACKLIGHT_MAX}")
|
||||
message(STATUS " PATH_BATTERY_CAPACITY ${SETTING_PATH_BATTERY_CAPACITY}")
|
||||
message(STATUS " PATH_BATTERY_CAPACITY_MAX ${SETTING_PATH_BATTERY_CAPACITY_MAX}")
|
||||
message(STATUS " PATH_BATTERY_CAPACITY_PERC ${SETTING_PATH_BATTERY_CAPACITY_PERC}")
|
||||
message(STATUS " PATH_BATTERY_VOLTAGE ${SETTING_PATH_BATTERY_VOLTAGE}")
|
||||
message(STATUS " PATH_BATTERY_RATE ${SETTING_PATH_BATTERY_RATE}")
|
||||
message(STATUS " PATH_CPU_INFO ${SETTING_PATH_CPU_INFO}")
|
||||
message(STATUS " PATH_MEMORY_INFO ${SETTING_PATH_MEMORY_INFO}")
|
||||
message(STATUS " PATH_MESSAGING_FIFO ${SETTING_PATH_MESSAGING_FIFO}")
|
||||
message(STATUS " PATH_TEMPERATURE_INFO ${SETTING_PATH_TEMPERATURE_INFO}")
|
||||
message(STATUS "--------------------------------------------")
|
||||
message(STATUS "--------------------------")
|
||||
colored_option(STATUS " Build testsuite ${BUILD_TESTS}" BUILD_TESTS "32;1" "37;2")
|
||||
colored_option(STATUS " Debug logging ${DEBUG_LOGGER}" DEBUG_LOGGER "32;1" "37;2")
|
||||
colored_option(STATUS " Verbose tracing ${VERBOSE_TRACELOG}" VERBOSE_TRACELOG "32;1" "37;2")
|
||||
colored_option(STATUS " Enable ccache ${ENABLE_CCACHE}" ENABLE_CCACHE "32;1" "37;2")
|
||||
message(STATUS "--------------------------")
|
||||
colored_option(STATUS " Enable alsa ${ENABLE_ALSA}" ENABLE_ALSA "32;1" "37;2")
|
||||
colored_option(STATUS " Enable i3 ${ENABLE_I3}" ENABLE_I3 "32;1" "37;2")
|
||||
colored_option(STATUS " Enable mpd ${ENABLE_MPD}" ENABLE_MPD "32;1" "37;2")
|
||||
colored_option(STATUS " Enable network ${ENABLE_NETWORK}" ENABLE_NETWORK "32;1" "37;2")
|
||||
message(STATUS "--------------------------")
|
||||
colored_option(STATUS " Enable X RandR ${ENABLE_RANDR_EXT}" ENABLE_RANDR_EXT "32;1" "37;2")
|
||||
colored_option(STATUS " Enable X Render ${ENABLE_RENDER_EXT}" ENABLE_RENDER_EXT "32;1" "37;2")
|
||||
colored_option(STATUS " Enable X Damage ${ENABLE_DAMAGE_EXT}" ENABLE_DAMAGE_EXT "32;1" "37;2")
|
||||
message(STATUS "--------------------------")
|
||||
# message(STATUS " ALSA_SOUNDCARD ${SETTING_ALSA_SOUNDCARD}")
|
||||
# message(STATUS " BSPWM_SOCKET_PATH ${SETTING_BSPWM_SOCKET_PATH}")
|
||||
# message(STATUS " BSPWM_STATUS_PREFIX ${SETTING_BSPWM_STATUS_PREFIX}")
|
||||
# message(STATUS " CONNECTION_TEST_IP ${SETTING_CONNECTION_TEST_IP}")
|
||||
# message(STATUS " PATH_ADAPTER_STATUS ${SETTING_PATH_ADAPTER_STATUS}")
|
||||
# message(STATUS " PATH_BACKLIGHT_VAL ${SETTING_PATH_BACKLIGHT_VAL}")
|
||||
# message(STATUS " PATH_BACKLIGHT_MAX ${SETTING_PATH_BACKLIGHT_MAX}")
|
||||
# message(STATUS " PATH_BATTERY_CAPACITY ${SETTING_PATH_BATTERY_CAPACITY}")
|
||||
# message(STATUS " PATH_BATTERY_CAPACITY_MAX ${SETTING_PATH_BATTERY_CAPACITY_MAX}")
|
||||
# message(STATUS " PATH_BATTERY_CAPACITY_PERC ${SETTING_PATH_BATTERY_CAPACITY_PERC}")
|
||||
# message(STATUS " PATH_BATTERY_VOLTAGE ${SETTING_PATH_BATTERY_VOLTAGE}")
|
||||
# message(STATUS " PATH_BATTERY_RATE ${SETTING_PATH_BATTERY_RATE}")
|
||||
# message(STATUS " PATH_CPU_INFO ${SETTING_PATH_CPU_INFO}")
|
||||
# message(STATUS " PATH_MEMORY_INFO ${SETTING_PATH_MEMORY_INFO}")
|
||||
# message(STATUS " PATH_MESSAGING_FIFO ${SETTING_PATH_MESSAGING_FIFO}")
|
||||
# message(STATUS " PATH_TEMPERATURE_INFO ${SETTING_PATH_TEMPERATURE_INFO}")
|
||||
# message(STATUS "--------------------------")
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
#include "common.hpp"
|
||||
#include "config.hpp"
|
||||
#include "utils/threading.hpp"
|
||||
#include "utils/concurrency.hpp"
|
||||
|
||||
#define MAX_LINEAR_DB_SCALE 24
|
||||
|
||||
@ -42,7 +42,7 @@ class alsa_ctl_interface {
|
||||
private:
|
||||
int m_numid = 0;
|
||||
|
||||
threading_util::spin_lock m_lock;
|
||||
concurrency_util::spin_lock m_lock;
|
||||
|
||||
snd_hctl_t* m_hctl = nullptr;
|
||||
snd_hctl_elem_t* m_elem = nullptr;
|
||||
@ -77,7 +77,7 @@ class alsa_mixer {
|
||||
private:
|
||||
string m_name;
|
||||
|
||||
threading_util::spin_lock m_lock;
|
||||
concurrency_util::spin_lock m_lock;
|
||||
|
||||
snd_mixer_t* m_hardwaremixer = nullptr;
|
||||
snd_mixer_elem_t* m_mixerelement = nullptr;
|
||||
|
@ -3,14 +3,16 @@
|
||||
#include <mpd/client.h>
|
||||
#include <stdlib.h>
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/logger.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
// fwd
|
||||
class logger;
|
||||
|
||||
namespace chrono = std::chrono;
|
||||
|
||||
namespace mpd {
|
||||
DEFINE_ERROR(mpd_exception);
|
||||
DEFINE_CHILD_ERROR(client_error, mpd_exception);
|
||||
@ -72,9 +74,8 @@ namespace mpd {
|
||||
class mpdstatus;
|
||||
class mpdconnection {
|
||||
public:
|
||||
explicit mpdconnection(const logger& logger, string host, unsigned int port = 6600,
|
||||
string password = "", unsigned int timeout = 15)
|
||||
: m_log(logger), m_host(host), m_port(port), m_password(password), m_timeout(timeout) {}
|
||||
explicit mpdconnection(
|
||||
const logger& logger, string host, unsigned int port = 6600, string password = "", unsigned int timeout = 15);
|
||||
|
||||
void connect();
|
||||
void disconnect();
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <arpa/inet.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <iwlib.h>
|
||||
@ -13,6 +14,8 @@
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace chrono = std::chrono;
|
||||
|
||||
namespace net {
|
||||
DEFINE_ERROR(network_error);
|
||||
|
||||
|
@ -4,18 +4,13 @@
|
||||
#define BOOST_DI_CFG_DIAGNOSTICS_LEVEL 2
|
||||
#endif
|
||||
|
||||
#include <atomic>
|
||||
#include <boost/di.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <cassert>
|
||||
#include <cerrno>
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "config.hpp"
|
||||
@ -28,8 +23,19 @@
|
||||
}
|
||||
#define POLYBAR_NS_PATH "polybar::v2_0_0"
|
||||
|
||||
#ifndef PIPE_READ
|
||||
#define PIPE_READ 0
|
||||
#endif
|
||||
#ifndef PIPE_WRITE
|
||||
#define PIPE_WRITE 1
|
||||
#endif
|
||||
|
||||
#ifndef STDOUT_FILENO
|
||||
#define STDOUT_FILENO 1
|
||||
#endif
|
||||
#ifndef STDERR_FILENO
|
||||
#define STDERR_FILENO 2
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
#include "debug.hpp"
|
||||
@ -42,12 +48,8 @@ POLYBAR_NS
|
||||
//==================================================
|
||||
|
||||
namespace di = boost::di;
|
||||
namespace chrono = std::chrono;
|
||||
namespace this_thread = std::this_thread;
|
||||
namespace placeholders = std::placeholders;
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
using std::string;
|
||||
using std::stringstream;
|
||||
using std::size_t;
|
||||
@ -66,36 +68,8 @@ using std::map;
|
||||
using std::vector;
|
||||
using std::to_string;
|
||||
using std::strerror;
|
||||
using std::getenv;
|
||||
using std::thread;
|
||||
using std::exception;
|
||||
|
||||
using boost::optional;
|
||||
|
||||
using stateflag = std::atomic<bool>;
|
||||
|
||||
//==================================================
|
||||
// Instance factory
|
||||
//==================================================
|
||||
|
||||
namespace factory {
|
||||
template <class InstanceType, class... Deps>
|
||||
unique_ptr<InstanceType> generic_instance(Deps... deps) {
|
||||
return make_unique<InstanceType>(deps...);
|
||||
}
|
||||
|
||||
template <class InstanceType, class... Deps>
|
||||
shared_ptr<InstanceType> generic_singleton(Deps... deps) {
|
||||
static auto instance = make_shared<InstanceType>(deps...);
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
struct null_deleter {
|
||||
template <typename T>
|
||||
void operator()(T*) const {}
|
||||
};
|
||||
|
||||
//==================================================
|
||||
// Errors and exceptions
|
||||
//==================================================
|
||||
@ -121,25 +95,4 @@ class system_error : public application_error {
|
||||
}
|
||||
#define DEFINE_ERROR(error) DEFINE_CHILD_ERROR(error, application_error)
|
||||
|
||||
//==================================================
|
||||
// Various tools and helpers functions
|
||||
//==================================================
|
||||
|
||||
auto has_env = [](const char* var) { return getenv(var) != nullptr; };
|
||||
auto read_env = [](const char* var, string&& fallback = "") {
|
||||
const char* value{getenv(var)};
|
||||
return value != nullptr ? value : fallback;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
auto time_execution(const T& expr) noexcept {
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
expr();
|
||||
auto finish = std::chrono::high_resolution_clock::now();
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(finish - start).count();
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
using callback = function<void(Args...)>;
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -4,11 +4,10 @@
|
||||
#include "components/config.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "components/types.hpp"
|
||||
#include "utils/threading.hpp"
|
||||
#include "utils/concurrency.hpp"
|
||||
#include "utils/throttle.hpp"
|
||||
#include "x11/connection.hpp"
|
||||
#include "x11/fontmanager.hpp"
|
||||
#include "x11/tray.hpp"
|
||||
#include "x11/events.hpp"
|
||||
#include "x11/types.hpp"
|
||||
#include "x11/window.hpp"
|
||||
|
||||
@ -16,17 +15,12 @@ POLYBAR_NS
|
||||
|
||||
// fwd
|
||||
class tray_manager;
|
||||
class font_manager;
|
||||
|
||||
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<fontmanager> fontmanager,
|
||||
unique_ptr<tray_manager> tray_manager)
|
||||
: m_connection(conn)
|
||||
, m_conf(config)
|
||||
, m_log(logger)
|
||||
, m_fontmanager(forward<decltype(fontmanager)>(fontmanager))
|
||||
, m_tray(forward<decltype(tray_manager)>(tray_manager)) {}
|
||||
|
||||
explicit bar(connection& conn, const config& config, const logger& logger, unique_ptr<font_manager> font_manager,
|
||||
unique_ptr<tray_manager> tray_manager);
|
||||
~bar();
|
||||
|
||||
void bootstrap(bool nodraw = false);
|
||||
@ -79,10 +73,10 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::propert
|
||||
connection& m_connection;
|
||||
const config& m_conf;
|
||||
const logger& m_log;
|
||||
unique_ptr<fontmanager> m_fontmanager;
|
||||
unique_ptr<font_manager> m_fontmanager;
|
||||
unique_ptr<tray_manager> m_tray;
|
||||
|
||||
threading_util::spin_lock m_lock;
|
||||
concurrency_util::spin_lock m_lock;
|
||||
throttle_util::throttle_t m_throttler;
|
||||
|
||||
xcb_screen_t* m_screen;
|
||||
@ -115,21 +109,6 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose, evt::propert
|
||||
XftDraw* m_xftdraw;
|
||||
};
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* Configure injection module
|
||||
*/
|
||||
template <typename T = unique_ptr<bar>>
|
||||
di::injector<T> configure_bar() {
|
||||
// clang-format off
|
||||
return di::make_injector(
|
||||
configure_connection(),
|
||||
configure_config(),
|
||||
configure_logger(),
|
||||
configure_fontmanager(),
|
||||
configure_tray_manager());
|
||||
// clang-format on
|
||||
}
|
||||
}
|
||||
di::injector<unique_ptr<bar>> configure_bar();
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/property_tree/ini_parser.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "utils/env.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "x11/xresources.hpp"
|
||||
|
||||
@ -78,7 +80,7 @@ class config {
|
||||
template <typename T>
|
||||
vector<T> get_list(string section, string key) const {
|
||||
vector<T> vec;
|
||||
optional<T> value;
|
||||
boost::optional<T> value;
|
||||
|
||||
while ((value = m_ptree.get_optional<T>(build_path(section, key) + "-" + to_string(vec.size()))) != boost::none) {
|
||||
auto str_val = m_ptree.get<string>(build_path(section, key) + "-" + to_string(vec.size()));
|
||||
@ -98,7 +100,7 @@ class config {
|
||||
template <typename T>
|
||||
vector<T> get_list(string section, string key, vector<T> default_value) const {
|
||||
vector<T> vec;
|
||||
optional<T> value;
|
||||
boost::optional<T> value;
|
||||
|
||||
while ((value = m_ptree.get_optional<T>(build_path(section, key) + "-" + to_string(vec.size()))) != boost::none) {
|
||||
auto str_val = m_ptree.get<string>(build_path(section, key) + "-" + to_string(vec.size()));
|
||||
@ -173,8 +175,8 @@ class config {
|
||||
var.erase(pos);
|
||||
}
|
||||
|
||||
if (has_env(var.c_str()))
|
||||
return boost::lexical_cast<T>(read_env(var.c_str()));
|
||||
if (env_util::has(var.c_str()))
|
||||
return boost::lexical_cast<T>(env_util::get(var.c_str()));
|
||||
|
||||
return fallback;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/bar.hpp"
|
||||
#include "components/config.hpp"
|
||||
#include "components/eventloop.hpp"
|
||||
#include "components/ipc.hpp"
|
||||
@ -14,6 +13,14 @@
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
// fwd decl {{{
|
||||
|
||||
class bar;
|
||||
|
||||
// }}}
|
||||
|
||||
using watch_t = inotify_util::watch_t;
|
||||
|
||||
class controller {
|
||||
public:
|
||||
explicit controller(connection& conn, const logger& logger, const config& config, unique_ptr<eventloop> eventloop,
|
||||
@ -72,22 +79,6 @@ class controller {
|
||||
bool m_writeback{false};
|
||||
};
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* Configure injection module
|
||||
*/
|
||||
template <typename T = unique_ptr<controller>>
|
||||
di::injector<T> configure_controller(inotify_util::watch_t& confwatch) {
|
||||
// clang-format off
|
||||
return di::make_injector(
|
||||
di::bind<>().to(confwatch),
|
||||
configure_connection(),
|
||||
configure_logger(),
|
||||
configure_config(),
|
||||
configure_eventloop(),
|
||||
configure_bar());
|
||||
// clang-format on
|
||||
}
|
||||
}
|
||||
di::injector<unique_ptr<controller>> configure_controller(watch_t& confwatch);
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <moodycamel/blockingconcurrentqueue.h>
|
||||
#include <chrono>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/base.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
@ -30,7 +31,7 @@ class eventloop {
|
||||
~eventloop() noexcept;
|
||||
|
||||
bool enqueue(const entry_t& i);
|
||||
void run(chrono::duration<double, std::milli> timeframe, int limit);
|
||||
void run(std::chrono::duration<double, std::milli> timeframe, int limit);
|
||||
void stop();
|
||||
|
||||
void set_update_cb(callback<>&& cb);
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "utils/functional.hpp"
|
||||
#include "utils/concurrency.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <cstdio>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "utils/factory.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
@ -22,7 +23,6 @@ class logger {
|
||||
explicit logger(string level_name) : logger(parse_loglevel_name(level_name)) {}
|
||||
|
||||
void verbosity(loglevel level);
|
||||
|
||||
void verbosity(string level);
|
||||
|
||||
/**
|
||||
@ -159,7 +159,7 @@ namespace {
|
||||
*/
|
||||
template <typename T = const logger&>
|
||||
di::injector<T> configure_logger(loglevel level = loglevel::NONE) {
|
||||
auto instance = factory::generic_singleton<logger>(level);
|
||||
auto instance = factory_util::generic_singleton<logger>(level);
|
||||
return di::make_injector(di::bind<>().to(instance));
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/signals.hpp"
|
||||
#include "components/types.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -1,10 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/types.hpp"
|
||||
|
||||
#include "utils/functional.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
// fwd decl {{{
|
||||
|
||||
enum class mousebtn;
|
||||
enum class syntaxtag;
|
||||
enum class alignment;
|
||||
enum class attribute;
|
||||
enum class gc;
|
||||
class color;
|
||||
|
||||
// }}}
|
||||
|
||||
/**
|
||||
* @TODO: Allow multiple signal handlers
|
||||
*/
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "version.hpp"
|
||||
|
||||
@ -21,7 +22,7 @@
|
||||
|
||||
#ifdef DEBUG
|
||||
#cmakedefine01 DRAW_CLICKABLE_AREA_HINTS
|
||||
#cmakedefine DRAW_CLICKABLE_AREA_HINTS_OFFSET_Y @DRAW_CLICKABLE_AREA_HINTS_OFFSET_Y@
|
||||
#cmakedefine DRAW_CLICKABLE_AREA_HINTS_OFFSET_Y @DRAW_CLICKABLE_AREA_HINTS_OFFSET_Y @
|
||||
#ifndef DRAW_CLICKABLE_AREA_HINTS_OFFSET_Y
|
||||
#define DRAW_CLICKABLE_AREA_HINTS_OFFSET_Y 0
|
||||
#endif
|
||||
@ -46,16 +47,31 @@
|
||||
#define PATH_MESSAGING_FIFO "@SETTING_PATH_MESSAGING_FIFO@"
|
||||
#define PATH_TEMPERATURE_INFO "@SETTING_PATH_TEMPERATURE_INFO@"
|
||||
|
||||
auto print_build_info = []() {
|
||||
// clang-format off
|
||||
std::cout << APP_NAME << " " << GIT_TAG
|
||||
<< "\n\n"
|
||||
<< "Built with: "
|
||||
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
|
||||
auto print_build_info = [](bool extended = false) {
|
||||
std::cout << APP_NAME << " " << GIT_TAG << " " << "\n"
|
||||
<< "\n"
|
||||
<< "Features: "
|
||||
<< (ENABLE_ALSA ? "+" : "-") << "alsa "
|
||||
<< (ENABLE_I3 ? "+" : "-") << "i3 "
|
||||
<< (ENABLE_MPD ? "+" : "-") << "mpd "
|
||||
<< (ENABLE_NETWORK ? "+" : "-") << "network "
|
||||
<< "\n\n"
|
||||
<< "\n";
|
||||
if (!extended)
|
||||
return;
|
||||
std::cout << "\n"
|
||||
<< "Build type: @CMAKE_BUILD_TYPE@" << "\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"
|
||||
@ -73,7 +89,7 @@ auto print_build_info = []() {
|
||||
<< "PATH_CPU_INFO " << PATH_CPU_INFO << "\n"
|
||||
<< "PATH_MEMORY_INFO " << PATH_MEMORY_INFO << "\n"
|
||||
<< "PATH_TEMPERATURE_INFO " << PATH_TEMPERATURE_INFO << "\n";
|
||||
// clang-format on
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
// vim:ft=cpp
|
||||
|
@ -2,6 +2,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
|
||||
template <class T>
|
||||
void benchmark_execution_speed(const T& expr) noexcept {
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/config.hpp"
|
||||
#include "drawtypes/label.hpp"
|
||||
@ -7,6 +9,8 @@
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace chrono = std::chrono;
|
||||
|
||||
namespace drawtypes {
|
||||
class animation : public non_copyable_mixin<animation> {
|
||||
public:
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "components/config.hpp"
|
||||
#include "config.hpp"
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/inotify_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "common.hpp"
|
||||
#include "config.hpp"
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/inotify_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
@ -67,7 +67,7 @@ namespace modules {
|
||||
map<battery_value, string> m_valuepath;
|
||||
std::atomic<int> m_percentage{0};
|
||||
int m_fullat{100};
|
||||
interval_t m_interval;
|
||||
chrono::duration<double> m_interval;
|
||||
chrono::system_clock::time_point m_lastpoll;
|
||||
string m_timeformat;
|
||||
int m_unchanged{SKIP_N_UNCHANGED};
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/event_module.hpp"
|
||||
#include "utils/bspwm.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/timer_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <istream>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/timer_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/timer_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "components/config.hpp"
|
||||
#include "config.hpp"
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/timer_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include "components/config.hpp"
|
||||
#include "config.hpp"
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/event_module.hpp"
|
||||
#include "utils/i3.hpp"
|
||||
#include "utils/io.hpp"
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/static_module.hpp"
|
||||
#include "utils/command.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <istream>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/timer_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/static_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -1,558 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/builder.hpp"
|
||||
#include "components/config.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "utils/inotify.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "utils/threading.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
#define DEFAULT_FORMAT "format"
|
||||
|
||||
#define DEFINE_MODULE(name, type) struct name : public type<name>
|
||||
#define CONST_MOD(name) static_cast<name const&>(*this)
|
||||
#define CAST_MOD(name) static_cast<name*>(this)
|
||||
|
||||
// fwd decl
|
||||
namespace drawtypes {
|
||||
class label;
|
||||
using label_t = shared_ptr<label>;
|
||||
class ramp;
|
||||
using ramp_t = shared_ptr<ramp>;
|
||||
class progressbar;
|
||||
using progressbar_t = shared_ptr<progressbar>;
|
||||
class animation;
|
||||
using animation_t = shared_ptr<animation>;
|
||||
using icon = label;
|
||||
using icon_t = label_t;
|
||||
class iconset;
|
||||
using iconset_t = shared_ptr<iconset>;
|
||||
}
|
||||
|
||||
namespace modules {
|
||||
using namespace drawtypes;
|
||||
|
||||
DEFINE_ERROR(module_error);
|
||||
DEFINE_CHILD_ERROR(undefined_format, module_error);
|
||||
DEFINE_CHILD_ERROR(undefined_format_tag, module_error);
|
||||
|
||||
// class definition : module_format {{{
|
||||
|
||||
struct module_format {
|
||||
string value;
|
||||
vector<string> tags;
|
||||
string fg;
|
||||
string bg;
|
||||
string ul;
|
||||
string ol;
|
||||
int spacing;
|
||||
int padding;
|
||||
int margin;
|
||||
int offset;
|
||||
|
||||
string decorate(builder* builder, string output) {
|
||||
if (offset != 0)
|
||||
builder->offset(offset);
|
||||
if (margin > 0)
|
||||
builder->space(margin);
|
||||
if (!bg.empty())
|
||||
builder->background(bg);
|
||||
if (!fg.empty())
|
||||
builder->color(fg);
|
||||
if (!ul.empty())
|
||||
builder->underline(ul);
|
||||
if (!ol.empty())
|
||||
builder->overline(ol);
|
||||
if (padding > 0)
|
||||
builder->space(padding);
|
||||
|
||||
builder->append(output);
|
||||
|
||||
if (padding > 0)
|
||||
builder->space(padding);
|
||||
if (!ol.empty())
|
||||
builder->overline_close();
|
||||
if (!ul.empty())
|
||||
builder->underline_close();
|
||||
if (!fg.empty())
|
||||
builder->color_close();
|
||||
if (!bg.empty())
|
||||
builder->background_close();
|
||||
if (margin > 0)
|
||||
builder->space(margin);
|
||||
|
||||
return builder->flush();
|
||||
}
|
||||
};
|
||||
|
||||
// }}}
|
||||
// class definition : module_formatter {{{
|
||||
|
||||
class module_formatter {
|
||||
public:
|
||||
explicit module_formatter(const config& conf, string modname) : m_conf(conf), m_modname(modname) {}
|
||||
|
||||
void add(string name, string fallback, vector<string>&& tags, vector<string>&& whitelist = {}) {
|
||||
auto format = make_unique<module_format>();
|
||||
|
||||
format->value = m_conf.get<string>(m_modname, name, fallback);
|
||||
format->fg = m_conf.get<string>(m_modname, name + "-foreground", "");
|
||||
format->bg = m_conf.get<string>(m_modname, name + "-background", "");
|
||||
format->ul = m_conf.get<string>(m_modname, name + "-underline", "");
|
||||
format->ol = m_conf.get<string>(m_modname, name + "-overline", "");
|
||||
format->spacing = m_conf.get<int>(m_modname, name + "-spacing", DEFAULT_SPACING);
|
||||
format->padding = m_conf.get<int>(m_modname, name + "-padding", 0);
|
||||
format->margin = m_conf.get<int>(m_modname, name + "-margin", 0);
|
||||
format->offset = m_conf.get<int>(m_modname, name + "-offset", 0);
|
||||
format->tags.swap(tags);
|
||||
|
||||
for (auto&& tag : string_util::split(format->value, ' ')) {
|
||||
if (tag[0] != '<' || tag[tag.length() - 1] != '>')
|
||||
continue;
|
||||
if (find(format->tags.begin(), format->tags.end(), tag) != format->tags.end())
|
||||
continue;
|
||||
if (find(whitelist.begin(), whitelist.end(), tag) != whitelist.end())
|
||||
continue;
|
||||
throw undefined_format_tag("[" + m_modname + "] Undefined \"" + name + "\" tag: " + tag);
|
||||
}
|
||||
|
||||
m_formats.insert(make_pair(name, move(format)));
|
||||
}
|
||||
|
||||
shared_ptr<module_format> get(string format_name) {
|
||||
auto format = m_formats.find(format_name);
|
||||
if (format == m_formats.end())
|
||||
throw undefined_format("Format \"" + format_name + "\" has not been added");
|
||||
return format->second;
|
||||
}
|
||||
|
||||
bool has(string tag, string format_name) {
|
||||
auto format = m_formats.find(format_name);
|
||||
if (format == m_formats.end())
|
||||
throw undefined_format(format_name.c_str());
|
||||
return format->second->value.find(tag) != string::npos;
|
||||
}
|
||||
|
||||
bool has(string tag) {
|
||||
for (auto&& format : m_formats)
|
||||
if (format.second->value.find(tag) != string::npos)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
const config& m_conf;
|
||||
string m_modname;
|
||||
map<string, shared_ptr<module_format>> m_formats;
|
||||
};
|
||||
|
||||
// }}}
|
||||
|
||||
// class definition : module_interface {{{
|
||||
|
||||
struct module_interface {
|
||||
public:
|
||||
virtual ~module_interface() {}
|
||||
|
||||
virtual string name() const = 0;
|
||||
virtual bool running() const = 0;
|
||||
|
||||
virtual void setup() = 0;
|
||||
virtual void start() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void halt(string error_message) = 0;
|
||||
virtual string contents() = 0;
|
||||
|
||||
virtual bool handle_event(string cmd) = 0;
|
||||
virtual bool receive_events() const = 0;
|
||||
|
||||
virtual void set_update_cb(callback<>&& cb) = 0;
|
||||
virtual void set_stop_cb(callback<>&& cb) = 0;
|
||||
};
|
||||
|
||||
// }}}
|
||||
// class definition : module {{{
|
||||
|
||||
template <class Impl>
|
||||
class module : public module_interface {
|
||||
public:
|
||||
module(const bar_settings bar, const logger& logger, const config& config, string name)
|
||||
: m_bar(bar)
|
||||
, m_log(logger)
|
||||
, m_conf(config)
|
||||
, m_name("module/" + name)
|
||||
, m_builder(make_unique<builder>(bar))
|
||||
, m_formatter(make_unique<module_formatter>(m_conf, m_name)) {}
|
||||
|
||||
~module() noexcept {
|
||||
m_log.trace("%s: Deconstructing", name());
|
||||
|
||||
for (auto&& thread_ : m_threads) {
|
||||
if (thread_.joinable()) {
|
||||
thread_.join();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void set_update_cb(callback<>&& cb) {
|
||||
m_update_callback = forward<decltype(cb)>(cb);
|
||||
}
|
||||
|
||||
void set_stop_cb(callback<>&& cb) {
|
||||
m_stop_callback = forward<decltype(cb)>(cb);
|
||||
}
|
||||
|
||||
string name() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
bool running() const {
|
||||
return m_enabled.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
m_log.trace("%s: Setup", m_name);
|
||||
|
||||
try {
|
||||
CAST_MOD(Impl)->setup();
|
||||
} catch (const std::exception& err) {
|
||||
m_log.err("%s: Setup failed", m_name);
|
||||
halt(err.what());
|
||||
}
|
||||
}
|
||||
|
||||
void stop() {
|
||||
if (!running()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_log.info("%s: Stopping", name());
|
||||
m_enabled.store(false, std::memory_order_relaxed);
|
||||
|
||||
wakeup();
|
||||
|
||||
std::lock_guard<threading_util::spin_lock> guard(m_lock);
|
||||
{
|
||||
CAST_MOD(Impl)->teardown();
|
||||
|
||||
if (m_mainthread.joinable()) {
|
||||
m_mainthread.join();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_stop_callback) {
|
||||
m_stop_callback();
|
||||
}
|
||||
}
|
||||
|
||||
void halt(string error_message) {
|
||||
m_log.err("%s: %s", name(), error_message);
|
||||
m_log.warn("Stopping '%s'...", name());
|
||||
stop();
|
||||
}
|
||||
|
||||
void teardown() {}
|
||||
|
||||
string contents() {
|
||||
return m_cache;
|
||||
}
|
||||
|
||||
bool handle_event(string cmd) {
|
||||
return CAST_MOD(Impl)->handle_event(cmd);
|
||||
}
|
||||
|
||||
bool receive_events() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
void broadcast() {
|
||||
if (!running()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_cache = CAST_MOD(Impl)->get_output();
|
||||
|
||||
if (m_update_callback)
|
||||
m_update_callback();
|
||||
else
|
||||
m_log.warn("%s: No handler, ignoring broadcast...", name());
|
||||
}
|
||||
|
||||
void idle() {
|
||||
CAST_MOD(Impl)->sleep(25ms);
|
||||
}
|
||||
|
||||
void sleep(chrono::duration<double> sleep_duration) {
|
||||
std::unique_lock<std::mutex> lck(m_sleeplock);
|
||||
m_sleephandler.wait_for(lck, sleep_duration);
|
||||
}
|
||||
|
||||
void wakeup() {
|
||||
m_log.trace("%s: Release sleep lock", name());
|
||||
m_sleephandler.notify_all();
|
||||
}
|
||||
|
||||
string get_format() const {
|
||||
return DEFAULT_FORMAT;
|
||||
}
|
||||
|
||||
string get_output() {
|
||||
if (!running()) {
|
||||
m_log.trace("%s: Module is disabled", name());
|
||||
return "";
|
||||
}
|
||||
|
||||
auto format_name = CONST_MOD(Impl).get_format();
|
||||
auto format = m_formatter->get(format_name);
|
||||
|
||||
int i = 0;
|
||||
bool tag_built = true;
|
||||
|
||||
for (auto tag : string_util::split(format->value, ' ')) {
|
||||
bool is_blankspace = tag.empty();
|
||||
|
||||
if (tag[0] == '<' && tag[tag.length() - 1] == '>') {
|
||||
if (i > 0)
|
||||
m_builder->space(format->spacing);
|
||||
if (!(tag_built = CONST_MOD(Impl).build(m_builder.get(), tag)) && i > 0)
|
||||
m_builder->remove_trailing_space(format->spacing);
|
||||
if (tag_built)
|
||||
i++;
|
||||
} else if (is_blankspace && tag_built) {
|
||||
m_builder->node(" ");
|
||||
} else if (!is_blankspace) {
|
||||
m_builder->node(tag);
|
||||
}
|
||||
}
|
||||
|
||||
return format->decorate(m_builder.get(), m_builder->flush());
|
||||
}
|
||||
|
||||
protected:
|
||||
callback<> m_update_callback;
|
||||
callback<> m_stop_callback;
|
||||
|
||||
threading_util::spin_lock m_lock;
|
||||
|
||||
const bar_settings m_bar;
|
||||
const logger& m_log;
|
||||
const config& m_conf;
|
||||
|
||||
std::mutex m_sleeplock;
|
||||
std::condition_variable m_sleephandler;
|
||||
|
||||
string m_name;
|
||||
unique_ptr<builder> m_builder;
|
||||
unique_ptr<module_formatter> m_formatter;
|
||||
vector<thread> m_threads;
|
||||
thread m_mainthread;
|
||||
|
||||
private:
|
||||
stateflag m_enabled{true};
|
||||
string m_cache;
|
||||
};
|
||||
|
||||
// }}}
|
||||
|
||||
// class definition : static_module {{{
|
||||
|
||||
template <class Impl>
|
||||
class static_module : public module<Impl> {
|
||||
public:
|
||||
using module<Impl>::module;
|
||||
|
||||
void start() {
|
||||
CAST_MOD(Impl)->broadcast();
|
||||
}
|
||||
|
||||
bool build(builder*, string) const {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// }}}
|
||||
// class definition : timer_module {{{
|
||||
|
||||
using interval_t = chrono::duration<double>;
|
||||
|
||||
template <class Impl>
|
||||
class timer_module : public module<Impl> {
|
||||
public:
|
||||
using module<Impl>::module;
|
||||
|
||||
void start() {
|
||||
CAST_MOD(Impl)->m_mainthread = thread(&timer_module::runner, this);
|
||||
}
|
||||
|
||||
protected:
|
||||
interval_t m_interval = 1s;
|
||||
|
||||
void runner() {
|
||||
try {
|
||||
while (CONST_MOD(Impl).running()) {
|
||||
std::lock_guard<threading_util::spin_lock> guard(this->m_lock);
|
||||
{
|
||||
if (CAST_MOD(Impl)->update())
|
||||
CAST_MOD(Impl)->broadcast();
|
||||
}
|
||||
CAST_MOD(Impl)->sleep(m_interval);
|
||||
}
|
||||
} catch (const module_error& err) {
|
||||
CAST_MOD(Impl)->halt(err.what());
|
||||
} catch (const std::exception& err) {
|
||||
CAST_MOD(Impl)->halt(err.what());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// }}}
|
||||
// class definition : event_module {{{
|
||||
|
||||
template <class Impl>
|
||||
class event_module : public module<Impl> {
|
||||
public:
|
||||
using module<Impl>::module;
|
||||
|
||||
void start() {
|
||||
CAST_MOD(Impl)->m_mainthread = thread(&event_module::runner, this);
|
||||
}
|
||||
|
||||
protected:
|
||||
void runner() {
|
||||
try {
|
||||
// Send initial broadcast to warmup cache
|
||||
if (CONST_MOD(Impl).running()) {
|
||||
CAST_MOD(Impl)->update();
|
||||
CAST_MOD(Impl)->broadcast();
|
||||
}
|
||||
|
||||
while (CONST_MOD(Impl).running()) {
|
||||
CAST_MOD(Impl)->idle();
|
||||
|
||||
if (!CONST_MOD(Impl).running())
|
||||
break;
|
||||
|
||||
std::lock_guard<threading_util::spin_lock> guard(this->m_lock);
|
||||
{
|
||||
if (!CAST_MOD(Impl)->has_event())
|
||||
continue;
|
||||
if (!CONST_MOD(Impl).running())
|
||||
break;
|
||||
if (!CAST_MOD(Impl)->update())
|
||||
continue;
|
||||
|
||||
CAST_MOD(Impl)->broadcast();
|
||||
}
|
||||
}
|
||||
} catch (const module_error& err) {
|
||||
CAST_MOD(Impl)->halt(err.what());
|
||||
} catch (const std::exception& err) {
|
||||
CAST_MOD(Impl)->halt(err.what());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// }}}
|
||||
// class definition : inotify_module {{{
|
||||
|
||||
template <class Impl>
|
||||
class inotify_module : public module<Impl> {
|
||||
public:
|
||||
using module<Impl>::module;
|
||||
|
||||
void start() {
|
||||
CAST_MOD(Impl)->m_mainthread = thread(&inotify_module::runner, this);
|
||||
}
|
||||
|
||||
protected:
|
||||
void runner() {
|
||||
try {
|
||||
// Send initial broadcast to warmup cache
|
||||
if (CONST_MOD(Impl).running()) {
|
||||
CAST_MOD(Impl)->on_event(nullptr);
|
||||
CAST_MOD(Impl)->broadcast();
|
||||
}
|
||||
|
||||
while (CONST_MOD(Impl).running()) {
|
||||
CAST_MOD(Impl)->poll_events();
|
||||
}
|
||||
} catch (const module_error& err) {
|
||||
CAST_MOD(Impl)->halt(err.what());
|
||||
} catch (const std::exception& err) {
|
||||
CAST_MOD(Impl)->halt(err.what());
|
||||
}
|
||||
}
|
||||
|
||||
void watch(string path, int mask = IN_ALL_EVENTS) {
|
||||
this->m_log.trace("%s: Attach inotify at %s", CONST_MOD(Impl).name(), path);
|
||||
m_watchlist.insert(make_pair(path, mask));
|
||||
}
|
||||
|
||||
void idle() {
|
||||
CAST_MOD(Impl)->sleep(200ms);
|
||||
}
|
||||
|
||||
void poll_events() {
|
||||
vector<inotify_util::watch_t> watches;
|
||||
|
||||
try {
|
||||
for (auto&& w : m_watchlist) {
|
||||
watches.emplace_back(inotify_util::make_watch(w.first));
|
||||
watches.back()->attach(w.second);
|
||||
}
|
||||
} catch (const system_error& e) {
|
||||
watches.clear();
|
||||
this->m_log.err("%s: Error while creating inotify watch (what: %s)", CONST_MOD(Impl).name(), e.what());
|
||||
CAST_MOD(Impl)->sleep(0.1s);
|
||||
return;
|
||||
}
|
||||
|
||||
while (CONST_MOD(Impl).running()) {
|
||||
std::unique_lock<threading_util::spin_lock> guard(this->m_lock);
|
||||
{
|
||||
for (auto&& w : watches) {
|
||||
this->m_log.trace_x("%s: Poll inotify watch %s", CONST_MOD(Impl).name(), w->path());
|
||||
|
||||
if (w->poll(1000 / watches.size())) {
|
||||
auto event = w->get_event();
|
||||
|
||||
for (auto&& w : watches) {
|
||||
try {
|
||||
w->remove();
|
||||
} catch (const system_error&) {
|
||||
}
|
||||
}
|
||||
|
||||
if (CAST_MOD(Impl)->on_event(event.get()))
|
||||
CAST_MOD(Impl)->broadcast();
|
||||
|
||||
CAST_MOD(Impl)->idle();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CONST_MOD(Impl).running())
|
||||
break;
|
||||
}
|
||||
}
|
||||
guard.unlock();
|
||||
CAST_MOD(Impl)->idle();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
map<string, int> m_watchlist;
|
||||
};
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
171
include/modules/meta/base.hpp
Normal file
171
include/modules/meta/base.hpp
Normal file
@ -0,0 +1,171 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/config.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "components/types.hpp"
|
||||
#include "utils/concurrency.hpp"
|
||||
#include "utils/functional.hpp"
|
||||
#include "utils/inotify.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
#define DEFAULT_FORMAT "format"
|
||||
|
||||
#define DEFINE_MODULE(name, type) struct name : public type<name>
|
||||
#define CONST_MOD(name) static_cast<name const&>(*this)
|
||||
#define CAST_MOD(name) static_cast<name*>(this)
|
||||
|
||||
// fwd decl {{{
|
||||
|
||||
namespace drawtypes {
|
||||
class label;
|
||||
using label_t = shared_ptr<label>;
|
||||
class ramp;
|
||||
using ramp_t = shared_ptr<ramp>;
|
||||
class progressbar;
|
||||
using progressbar_t = shared_ptr<progressbar>;
|
||||
class animation;
|
||||
using animation_t = shared_ptr<animation>;
|
||||
using icon = label;
|
||||
using icon_t = label_t;
|
||||
class iconset;
|
||||
using iconset_t = shared_ptr<iconset>;
|
||||
}
|
||||
|
||||
class builder;
|
||||
|
||||
// }}}
|
||||
|
||||
namespace modules {
|
||||
namespace chrono = std::chrono;
|
||||
using namespace std::chrono_literals;
|
||||
using namespace drawtypes;
|
||||
|
||||
DEFINE_ERROR(module_error);
|
||||
DEFINE_CHILD_ERROR(undefined_format, module_error);
|
||||
DEFINE_CHILD_ERROR(undefined_format_tag, module_error);
|
||||
|
||||
// class definition : module_format {{{
|
||||
|
||||
struct module_format {
|
||||
string value;
|
||||
vector<string> tags;
|
||||
string fg;
|
||||
string bg;
|
||||
string ul;
|
||||
string ol;
|
||||
int spacing;
|
||||
int padding;
|
||||
int margin;
|
||||
int offset;
|
||||
|
||||
string decorate(builder* builder, string output);
|
||||
};
|
||||
|
||||
// }}}
|
||||
// class definition : module_formatter {{{
|
||||
|
||||
class module_formatter {
|
||||
public:
|
||||
explicit module_formatter(const config& conf, string modname) : m_conf(conf), m_modname(modname) {}
|
||||
|
||||
void add(string name, string fallback, vector<string>&& tags, vector<string>&& whitelist = {});
|
||||
bool has(string tag, string format_name);
|
||||
bool has(string tag);
|
||||
shared_ptr<module_format> get(string format_name);
|
||||
|
||||
protected:
|
||||
const config& m_conf;
|
||||
string m_modname;
|
||||
map<string, shared_ptr<module_format>> m_formats;
|
||||
};
|
||||
|
||||
// }}}
|
||||
|
||||
// class definition : module_interface {{{
|
||||
|
||||
struct module_interface {
|
||||
public:
|
||||
virtual ~module_interface() {}
|
||||
|
||||
virtual string name() const = 0;
|
||||
virtual bool running() const = 0;
|
||||
|
||||
virtual void setup() = 0;
|
||||
virtual void start() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void halt(string error_message) = 0;
|
||||
virtual string contents() = 0;
|
||||
|
||||
virtual bool handle_event(string cmd) = 0;
|
||||
virtual bool receive_events() const = 0;
|
||||
|
||||
virtual void set_update_cb(callback<>&& cb) = 0;
|
||||
virtual void set_stop_cb(callback<>&& cb) = 0;
|
||||
};
|
||||
|
||||
// }}}
|
||||
// class definition : module {{{
|
||||
|
||||
template <class Impl>
|
||||
class module : public module_interface {
|
||||
public:
|
||||
module(const bar_settings bar, const logger& logger, const config& config, string name);
|
||||
~module() noexcept;
|
||||
|
||||
void set_update_cb(callback<>&& cb);
|
||||
void set_stop_cb(callback<>&& cb);
|
||||
|
||||
string name() const;
|
||||
bool running() const;
|
||||
void setup();
|
||||
void stop();
|
||||
void halt(string error_message);
|
||||
void teardown();
|
||||
string contents();
|
||||
bool handle_event(string cmd);
|
||||
bool receive_events() const;
|
||||
|
||||
protected:
|
||||
void broadcast();
|
||||
void idle();
|
||||
void sleep(chrono::duration<double> sleep_duration);
|
||||
void wakeup();
|
||||
string get_format() const;
|
||||
string get_output();
|
||||
|
||||
protected:
|
||||
callback<> m_update_callback;
|
||||
callback<> m_stop_callback;
|
||||
|
||||
concurrency_util::spin_lock m_lock;
|
||||
|
||||
const bar_settings m_bar;
|
||||
const logger& m_log;
|
||||
const config& m_conf;
|
||||
|
||||
std::mutex m_sleeplock;
|
||||
std::condition_variable m_sleephandler;
|
||||
|
||||
string m_name;
|
||||
unique_ptr<builder> m_builder;
|
||||
unique_ptr<module_formatter> m_formatter;
|
||||
vector<thread> m_threads;
|
||||
thread m_mainthread;
|
||||
|
||||
private:
|
||||
stateflag m_enabled{true};
|
||||
string m_cache;
|
||||
};
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
185
include/modules/meta/base.inl
Normal file
185
include/modules/meta/base.inl
Normal file
@ -0,0 +1,185 @@
|
||||
#include "components/builder.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
// module<Impl> public {{{
|
||||
|
||||
template <typename Impl>
|
||||
module<Impl>::module(const bar_settings bar, const logger& logger, const config& config, string name)
|
||||
: m_bar(bar)
|
||||
, m_log(logger)
|
||||
, m_conf(config)
|
||||
, m_name("module/" + name)
|
||||
, m_builder(make_unique<builder>(bar))
|
||||
, m_formatter(make_unique<module_formatter>(m_conf, m_name)) {}
|
||||
|
||||
template <typename Impl>
|
||||
module<Impl>::~module() noexcept {
|
||||
m_log.trace("%s: Deconstructing", name());
|
||||
|
||||
for (auto&& thread_ : m_threads) {
|
||||
if (thread_.joinable()) {
|
||||
thread_.join();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
void module<Impl>::set_update_cb(callback<>&& cb) {
|
||||
m_update_callback = forward<decltype(cb)>(cb);
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
void module<Impl>::set_stop_cb(callback<>&& cb) {
|
||||
m_stop_callback = forward<decltype(cb)>(cb);
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
string module<Impl>::name() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
bool module<Impl>::running() const {
|
||||
return m_enabled.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
void module<Impl>::setup() {
|
||||
m_log.trace("%s: Setup", m_name);
|
||||
|
||||
try {
|
||||
CAST_MOD(Impl)->setup();
|
||||
} catch (const std::exception& err) {
|
||||
m_log.err("%s: Setup failed", m_name);
|
||||
halt(err.what());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
void module<Impl>::stop() {
|
||||
if (!running()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_log.info("%s: Stopping", name());
|
||||
m_enabled.store(false, std::memory_order_relaxed);
|
||||
|
||||
wakeup();
|
||||
|
||||
std::lock_guard<concurrency_util::spin_lock> guard(m_lock);
|
||||
{
|
||||
CAST_MOD(Impl)->teardown();
|
||||
|
||||
if (m_mainthread.joinable()) {
|
||||
m_mainthread.join();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_stop_callback) {
|
||||
m_stop_callback();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
void module<Impl>::halt(string error_message) {
|
||||
m_log.err("%s: %s", name(), error_message);
|
||||
m_log.warn("Stopping '%s'...", name());
|
||||
stop();
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
void module<Impl>::teardown() {}
|
||||
|
||||
template <typename Impl>
|
||||
string module<Impl>::contents() {
|
||||
return m_cache;
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
bool module<Impl>::handle_event(string cmd) {
|
||||
return CAST_MOD(Impl)->handle_event(cmd);
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
bool module<Impl>::receive_events() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
// }}}
|
||||
// module<Impl> protected {{{
|
||||
|
||||
template <typename Impl>
|
||||
void module<Impl>::broadcast() {
|
||||
if (!running()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_cache = CAST_MOD(Impl)->get_output();
|
||||
|
||||
if (m_update_callback)
|
||||
m_update_callback();
|
||||
else
|
||||
m_log.warn("%s: No handler, ignoring broadcast...", name());
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
void module<Impl>::idle() {
|
||||
CAST_MOD(Impl)->sleep(25ms);
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
void module<Impl>::sleep(chrono::duration<double> sleep_duration) {
|
||||
std::unique_lock<std::mutex> lck(m_sleeplock);
|
||||
m_sleephandler.wait_for(lck, sleep_duration);
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
void module<Impl>::wakeup() {
|
||||
m_log.trace("%s: Release sleep lock", name());
|
||||
m_sleephandler.notify_all();
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
string module<Impl>::get_format() const {
|
||||
return DEFAULT_FORMAT;
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
string module<Impl>::get_output() {
|
||||
if (!running()) {
|
||||
m_log.trace("%s: Module is disabled", name());
|
||||
return "";
|
||||
}
|
||||
|
||||
auto format_name = CONST_MOD(Impl).get_format();
|
||||
auto format = m_formatter->get(format_name);
|
||||
|
||||
int i = 0;
|
||||
bool tag_built = true;
|
||||
|
||||
for (auto tag : string_util::split(format->value, ' ')) {
|
||||
bool is_blankspace = tag.empty();
|
||||
|
||||
if (tag[0] == '<' && tag[tag.length() - 1] == '>') {
|
||||
if (i > 0)
|
||||
m_builder->space(format->spacing);
|
||||
if (!(tag_built = CONST_MOD(Impl).build(m_builder.get(), tag)) && i > 0)
|
||||
m_builder->remove_trailing_space(format->spacing);
|
||||
if (tag_built)
|
||||
i++;
|
||||
} else if (is_blankspace && tag_built) {
|
||||
m_builder->node(" ");
|
||||
} else if (!is_blankspace) {
|
||||
m_builder->node(tag);
|
||||
}
|
||||
}
|
||||
|
||||
return format->decorate(m_builder.get(), m_builder->flush());
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
23
include/modules/meta/event_module.hpp
Normal file
23
include/modules/meta/event_module.hpp
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
// #include "components/types.hpp"
|
||||
// #include "components/builder.hpp"
|
||||
|
||||
#include "modules/meta/base.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template <class Impl>
|
||||
class event_module : public module<Impl> {
|
||||
public:
|
||||
using module<Impl>::module;
|
||||
|
||||
void start();
|
||||
|
||||
protected:
|
||||
void runner();
|
||||
};
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
51
include/modules/meta/event_module.inl
Normal file
51
include/modules/meta/event_module.inl
Normal file
@ -0,0 +1,51 @@
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
// public {{{
|
||||
|
||||
template <class Impl>
|
||||
void event_module<Impl>::start() {
|
||||
CAST_MOD(Impl)->m_mainthread = thread(&event_module::runner, this);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// protected {{{
|
||||
|
||||
template <class Impl>
|
||||
void event_module<Impl>::runner() {
|
||||
try {
|
||||
// Send initial broadcast to warmup cache
|
||||
if (CONST_MOD(Impl).running()) {
|
||||
CAST_MOD(Impl)->update();
|
||||
CAST_MOD(Impl)->broadcast();
|
||||
}
|
||||
|
||||
while (CONST_MOD(Impl).running()) {
|
||||
CAST_MOD(Impl)->idle();
|
||||
|
||||
if (!CONST_MOD(Impl).running())
|
||||
break;
|
||||
|
||||
std::lock_guard<concurrency_util::spin_lock> guard(this->m_lock);
|
||||
{
|
||||
if (!CAST_MOD(Impl)->has_event())
|
||||
continue;
|
||||
if (!CONST_MOD(Impl).running())
|
||||
break;
|
||||
if (!CAST_MOD(Impl)->update())
|
||||
continue;
|
||||
|
||||
CAST_MOD(Impl)->broadcast();
|
||||
}
|
||||
}
|
||||
} catch (const module_error& err) {
|
||||
CAST_MOD(Impl)->halt(err.what());
|
||||
} catch (const std::exception& err) {
|
||||
CAST_MOD(Impl)->halt(err.what());
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
27
include/modules/meta/inotify_module.hpp
Normal file
27
include/modules/meta/inotify_module.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "components/builder.hpp"
|
||||
#include "modules/meta/base.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template <class Impl>
|
||||
class inotify_module : public module<Impl> {
|
||||
public:
|
||||
using module<Impl>::module;
|
||||
|
||||
void start();
|
||||
|
||||
protected:
|
||||
void runner();
|
||||
void watch(string path, int mask = IN_ALL_EVENTS);
|
||||
void idle();
|
||||
void poll_events();
|
||||
|
||||
private:
|
||||
map<string, int> m_watchlist;
|
||||
};
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
96
include/modules/meta/inotify_module.inl
Normal file
96
include/modules/meta/inotify_module.inl
Normal file
@ -0,0 +1,96 @@
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
// public {{{
|
||||
|
||||
template <class Impl>
|
||||
void inotify_module<Impl>::start() {
|
||||
CAST_MOD(Impl)->m_mainthread = thread(&inotify_module::runner, this);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// protected {{{
|
||||
|
||||
template <class Impl>
|
||||
void inotify_module<Impl>::runner() {
|
||||
try {
|
||||
// Send initial broadcast to warmup cache
|
||||
if (CONST_MOD(Impl).running()) {
|
||||
CAST_MOD(Impl)->on_event(nullptr);
|
||||
CAST_MOD(Impl)->broadcast();
|
||||
}
|
||||
|
||||
while (CONST_MOD(Impl).running()) {
|
||||
CAST_MOD(Impl)->poll_events();
|
||||
}
|
||||
} catch (const module_error& err) {
|
||||
CAST_MOD(Impl)->halt(err.what());
|
||||
} catch (const std::exception& err) {
|
||||
CAST_MOD(Impl)->halt(err.what());
|
||||
}
|
||||
}
|
||||
|
||||
template <class Impl>
|
||||
void inotify_module<Impl>::watch(string path, int mask) {
|
||||
this->m_log.trace("%s: Attach inotify at %s", CONST_MOD(Impl).name(), path);
|
||||
m_watchlist.insert(make_pair(path, mask));
|
||||
}
|
||||
|
||||
template <class Impl>
|
||||
void inotify_module<Impl>::idle() {
|
||||
CAST_MOD(Impl)->sleep(200ms);
|
||||
}
|
||||
|
||||
template <class Impl>
|
||||
void inotify_module<Impl>::poll_events() {
|
||||
vector<inotify_util::watch_t> watches;
|
||||
|
||||
try {
|
||||
for (auto&& w : m_watchlist) {
|
||||
watches.emplace_back(inotify_util::make_watch(w.first));
|
||||
watches.back()->attach(w.second);
|
||||
}
|
||||
} catch (const system_error& e) {
|
||||
watches.clear();
|
||||
this->m_log.err("%s: Error while creating inotify watch (what: %s)", CONST_MOD(Impl).name(), e.what());
|
||||
CAST_MOD(Impl)->sleep(0.1s);
|
||||
return;
|
||||
}
|
||||
|
||||
while (CONST_MOD(Impl).running()) {
|
||||
std::unique_lock<concurrency_util::spin_lock> guard(this->m_lock);
|
||||
{
|
||||
for (auto&& w : watches) {
|
||||
this->m_log.trace_x("%s: Poll inotify watch %s", CONST_MOD(Impl).name(), w->path());
|
||||
|
||||
if (w->poll(1000 / watches.size())) {
|
||||
auto event = w->get_event();
|
||||
|
||||
for (auto&& w : watches) {
|
||||
try {
|
||||
w->remove();
|
||||
} catch (const system_error&) {
|
||||
}
|
||||
}
|
||||
|
||||
if (CAST_MOD(Impl)->on_event(event.get()))
|
||||
CAST_MOD(Impl)->broadcast();
|
||||
|
||||
CAST_MOD(Impl)->idle();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CONST_MOD(Impl).running())
|
||||
break;
|
||||
}
|
||||
}
|
||||
guard.unlock();
|
||||
CAST_MOD(Impl)->idle();
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
21
include/modules/meta/static_module.hpp
Normal file
21
include/modules/meta/static_module.hpp
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
// #include "components/builder.hpp"
|
||||
// #include "components/types.hpp"
|
||||
|
||||
#include "modules/meta/base.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template <class Impl>
|
||||
class static_module : public module<Impl> {
|
||||
public:
|
||||
using module<Impl>::module;
|
||||
|
||||
void start();
|
||||
bool build(builder*, string) const;
|
||||
};
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
15
include/modules/meta/static_module.inl
Normal file
15
include/modules/meta/static_module.inl
Normal file
@ -0,0 +1,15 @@
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template <typename Impl>
|
||||
void static_module<Impl>::start() {
|
||||
CAST_MOD(Impl)->broadcast();
|
||||
}
|
||||
|
||||
template <typename Impl>
|
||||
bool static_module<Impl>::build(builder*, string) const {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
28
include/modules/meta/timer_module.hpp
Normal file
28
include/modules/meta/timer_module.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#include "modules/meta/base.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace chrono = std::chrono;
|
||||
|
||||
namespace modules {
|
||||
using interval_t = chrono::duration<double>;
|
||||
|
||||
template <class Impl>
|
||||
class timer_module : public module<Impl> {
|
||||
public:
|
||||
using module<Impl>::module;
|
||||
|
||||
void start();
|
||||
|
||||
protected:
|
||||
interval_t m_interval{1};
|
||||
|
||||
void runner();
|
||||
};
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
35
include/modules/meta/timer_module.inl
Normal file
35
include/modules/meta/timer_module.inl
Normal file
@ -0,0 +1,35 @@
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
// public {{{
|
||||
|
||||
template <typename Impl>
|
||||
void timer_module<Impl>::start() {
|
||||
CAST_MOD(Impl)->m_mainthread = thread(&timer_module::runner, this);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// protected {{{
|
||||
|
||||
template <typename Impl>
|
||||
void timer_module<Impl>::runner() {
|
||||
try {
|
||||
while (CONST_MOD(Impl).running()) {
|
||||
std::lock_guard<concurrency_util::spin_lock> guard(this->m_lock);
|
||||
{
|
||||
if (CAST_MOD(Impl)->update())
|
||||
CAST_MOD(Impl)->broadcast();
|
||||
}
|
||||
CAST_MOD(Impl)->sleep(m_interval);
|
||||
}
|
||||
} catch (const module_error& err) {
|
||||
CAST_MOD(Impl)->halt(err.what());
|
||||
} catch (const std::exception& err) {
|
||||
CAST_MOD(Impl)->halt(err.what());
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
@ -1,15 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <csignal>
|
||||
#include <chrono>
|
||||
|
||||
#include "adapters/mpd.hpp"
|
||||
#include "modules/meta.hpp"
|
||||
#include "utils/threading.hpp"
|
||||
#include "modules/meta/event_module.hpp"
|
||||
#include "utils/concurrency.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
using namespace mpd;
|
||||
|
||||
namespace chrono = std::chrono;
|
||||
|
||||
namespace modules {
|
||||
class mpd_module : public event_module<mpd_module> {
|
||||
public:
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "adapters/net.hpp"
|
||||
#include "components/config.hpp"
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/timer_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -1,10 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "modules/meta.hpp"
|
||||
#include <chrono>
|
||||
|
||||
#include "modules/meta/event_module.hpp"
|
||||
#include "utils/command.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace chrono = std::chrono;
|
||||
|
||||
#define OUTPUT_ACTION(BUTTON) \
|
||||
if (!m_actions[BUTTON].empty()) \
|
||||
m_builder->cmd(BUTTON, string_util::replace_all(m_actions[BUTTON], "%counter%", counter_str))
|
||||
@ -29,7 +33,7 @@ namespace modules {
|
||||
|
||||
string m_exec;
|
||||
bool m_tail = false;
|
||||
interval_t m_interval = 0s;
|
||||
chrono::duration<double> m_interval{0};
|
||||
size_t m_maxlen = 0;
|
||||
bool m_ellipsis = true;
|
||||
map<mousebtn, string> m_actions;
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <istream>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/timer_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/static_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/event_module.hpp"
|
||||
#include "modules/meta/timer_module.hpp"
|
||||
|
||||
#define DEFINE_UNSUPPORTED_MODULE(MODULE_NAME, MODULE_TYPE) \
|
||||
class MODULE_NAME : public module<MODULE_NAME> { \
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "adapters/alsa.hpp"
|
||||
#include "components/config.hpp"
|
||||
#include "config.hpp"
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/event_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
@ -51,14 +51,10 @@ namespace modules {
|
||||
|
||||
map<mixer, mixer_t> m_mixers;
|
||||
map<control, control_t> m_controls;
|
||||
|
||||
int m_headphoneid = 0;
|
||||
|
||||
bool m_mapped;
|
||||
|
||||
int m_headphoneid{0};
|
||||
bool m_mapped{false};
|
||||
stateflag m_muted{false};
|
||||
stateflag m_headphones{false};
|
||||
|
||||
std::atomic<int> m_volume{0};
|
||||
};
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "components/config.hpp"
|
||||
#include "x11/connection.hpp"
|
||||
#include "x11/randr.hpp"
|
||||
#include "x11/xutils.hpp"
|
||||
#include "config.hpp"
|
||||
#include "modules/meta.hpp"
|
||||
#include "modules/meta/static_module.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
class connection;
|
||||
|
||||
namespace modules {
|
||||
/**
|
||||
* Backlight module built using the RandR X extension.
|
||||
@ -28,6 +28,8 @@ namespace modules {
|
||||
public:
|
||||
using static_module::static_module;
|
||||
|
||||
xbacklight_module(const bar_settings bar, const logger& logger, const config& config, string name);
|
||||
|
||||
void setup();
|
||||
void teardown();
|
||||
void handle(const evt::randr_notify& evt);
|
||||
@ -47,7 +49,7 @@ namespace modules {
|
||||
static constexpr auto EVENT_SCROLLUP = "xbacklight+";
|
||||
static constexpr auto EVENT_SCROLLDOWN = "xbacklight-";
|
||||
|
||||
connection& m_connection{configure_connection().create<connection&>()};
|
||||
connection& m_connection;
|
||||
monitor_t m_output;
|
||||
xcb_window_t m_proxy;
|
||||
xcb_timestamp_t m_timestamp;
|
||||
|
@ -3,14 +3,16 @@
|
||||
#include <bitset>
|
||||
|
||||
#include "components/config.hpp"
|
||||
#include "modules/meta.hpp"
|
||||
#include "x11/connection.hpp"
|
||||
#include "modules/meta/static_module.hpp"
|
||||
#include "x11/events.hpp"
|
||||
#include "x11/ewmh.hpp"
|
||||
#include "x11/icccm.hpp"
|
||||
#include "x11/window.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
class connection;
|
||||
|
||||
namespace modules {
|
||||
/**
|
||||
* Wrapper used to update the event mask of the
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "utils/threading.hpp"
|
||||
#include "utils/concurrency.hpp"
|
||||
#include "utils/functional.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
@ -69,7 +70,7 @@ namespace command_util {
|
||||
pid_t m_forkpid;
|
||||
int m_forkstatus;
|
||||
|
||||
threading_util::spin_lock m_pipelock;
|
||||
concurrency_util::spin_lock m_pipelock;
|
||||
};
|
||||
|
||||
using command_t = unique_ptr<command>;
|
||||
|
@ -1,13 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "utils/mixins.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace threading_util {
|
||||
namespace this_thread = std::this_thread;
|
||||
|
||||
using std::thread;
|
||||
|
||||
template <typename T>
|
||||
using atomic = std::atomic<T>;
|
||||
|
||||
using stateflag = atomic<bool>;
|
||||
|
||||
namespace concurrency_util {
|
||||
namespace locking_strategy {
|
||||
struct no_backoff {
|
||||
bool operator()() {
|
12
include/utils/env.hpp
Normal file
12
include/utils/env.hpp
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace env_util {
|
||||
bool has(const char* var);
|
||||
string get(const char* var, string fallback = "");
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
25
include/utils/factory.hpp
Normal file
25
include/utils/factory.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace factory_util {
|
||||
struct null_deleter {
|
||||
template <typename T>
|
||||
void operator()(T*) const {}
|
||||
};
|
||||
|
||||
template <class InstanceType, class... Deps>
|
||||
unique_ptr<InstanceType> generic_instance(Deps... deps) {
|
||||
return make_unique<InstanceType>(deps...);
|
||||
}
|
||||
|
||||
template <class InstanceType, class... Deps>
|
||||
shared_ptr<InstanceType> generic_singleton(Deps... deps) {
|
||||
static auto instance = make_shared<InstanceType>(deps...);
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
12
include/utils/functional.hpp
Normal file
12
include/utils/functional.hpp
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
template <typename... Args>
|
||||
using callback = function<void(Args...)>;
|
||||
|
||||
POLYBAR_NS_END
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
// TODO: move to functional.hpp
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
#include "components/logger.hpp"
|
||||
|
@ -1,12 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <deque>
|
||||
#include <chrono>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/logger.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace chrono = std::chrono;
|
||||
|
||||
namespace throttle_util {
|
||||
using timewindow = chrono::duration<double, std::milli>;
|
||||
using timepoint_clock = chrono::high_resolution_clock;
|
||||
|
23
include/utils/time.hpp
Normal file
23
include/utils/time.hpp
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace chrono = std::chrono;
|
||||
|
||||
namespace time_util {
|
||||
using clock_t = chrono::high_resolution_clock;
|
||||
|
||||
template <typename T, typename Dur = chrono::milliseconds>
|
||||
auto measure(const T& expr) noexcept {
|
||||
auto start = clock_t::now();
|
||||
expr();
|
||||
auto finish = clock_t::now();
|
||||
return chrono::duration_cast<Dur>(finish - start).count();
|
||||
}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
@ -5,6 +5,7 @@
|
||||
#include <xcb/xcb.h>
|
||||
#include <iomanip>
|
||||
#include <xpp/xpp.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "utils/memory.hpp"
|
||||
@ -13,6 +14,16 @@
|
||||
#include "x11/types.hpp"
|
||||
#include "x11/xutils.hpp"
|
||||
|
||||
#ifdef ENABLE_DAMAGE_EXT
|
||||
#include "x11/damage.hpp"
|
||||
#endif
|
||||
#ifdef ENABLE_RANDR_EXT
|
||||
#include "x11/randr.hpp"
|
||||
#endif
|
||||
#ifdef ENABLE_RENDER_EXT
|
||||
#include "x11/render.hpp"
|
||||
#endif
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
using xpp_connection = xpp::connection<
|
||||
@ -60,7 +71,7 @@ class connection : public xpp_connection {
|
||||
|
||||
void send_dummy_event(xcb_window_t t, uint32_t ev = XCB_EVENT_MASK_STRUCTURE_NOTIFY) const;
|
||||
|
||||
optional<xcb_visualtype_t*> visual_type(xcb_screen_t* screen, int match_depth = 32);
|
||||
boost::optional<xcb_visualtype_t*> visual_type(xcb_screen_t* screen, int match_depth = 32);
|
||||
|
||||
static string error_str(int error_code);
|
||||
|
||||
@ -86,15 +97,6 @@ class connection : public xpp_connection {
|
||||
xcb_screen_t* m_screen = nullptr;
|
||||
};
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* Configure injection module
|
||||
*/
|
||||
template <typename T = connection&>
|
||||
di::injector<T> configure_connection() {
|
||||
return di::make_injector(
|
||||
di::bind<>().to(factory::generic_singleton<connection>(xutils::get_connection())));
|
||||
}
|
||||
}
|
||||
di::injector<connection&> configure_connection();
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
9
include/x11/damage.hpp
Normal file
9
include/x11/damage.hpp
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
|
||||
#ifndef ENABLE_DAMAGE_EXT
|
||||
#error "X Damage extension is disabled..."
|
||||
#endif
|
||||
|
||||
#include <xpp/proto/damage.hpp>
|
61
include/x11/events.hpp
Normal file
61
include/x11/events.hpp
Normal file
@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
|
||||
#include <xpp/xpp.hpp>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
class connection;
|
||||
|
||||
namespace evt {
|
||||
// window focus events
|
||||
using focus_in = xpp::x::event::focus_in<connection&>;
|
||||
using focus_out = xpp::x::event::focus_out<connection&>;
|
||||
|
||||
// cursor events
|
||||
using enter_notify = xpp::x::event::enter_notify<connection&>;
|
||||
using leave_notify = xpp::x::event::leave_notify<connection&>;
|
||||
using motion_notify = xpp::x::event::motion_notify<connection&>;
|
||||
|
||||
// keyboard events
|
||||
using button_press = xpp::x::event::button_press<connection&>;
|
||||
using button_release = xpp::x::event::button_release<connection&>;
|
||||
using key_press = xpp::x::event::key_press<connection&>;
|
||||
using key_release = xpp::x::event::key_release<connection&>;
|
||||
using keymap_notify = xpp::x::event::keymap_notify<connection&>;
|
||||
|
||||
// render events
|
||||
using circulate_notify = xpp::x::event::circulate_notify<connection&>;
|
||||
using circulate_request = xpp::x::event::circulate_request<connection&>;
|
||||
using colormap_notify = xpp::x::event::colormap_notify<connection&>;
|
||||
using configure_notify = xpp::x::event::configure_notify<connection&>;
|
||||
using configure_request = xpp::x::event::configure_request<connection&>;
|
||||
using create_notify = xpp::x::event::create_notify<connection&>;
|
||||
using destroy_notify = xpp::x::event::destroy_notify<connection&>;
|
||||
using expose = xpp::x::event::expose<connection&>;
|
||||
using graphics_exposure = xpp::x::event::graphics_exposure<connection&>;
|
||||
using gravity_notify = xpp::x::event::gravity_notify<connection&>;
|
||||
using map_notify = xpp::x::event::map_notify<connection&>;
|
||||
using map_request = xpp::x::event::map_request<connection&>;
|
||||
using mapping_notify = xpp::x::event::mapping_notify<connection&>;
|
||||
using no_exposure = xpp::x::event::no_exposure<connection&>;
|
||||
using reparent_notify = xpp::x::event::reparent_notify<connection&>;
|
||||
using resize_request = xpp::x::event::resize_request<connection&>;
|
||||
using unmap_notify = xpp::x::event::unmap_notify<connection&>;
|
||||
using visibility_notify = xpp::x::event::visibility_notify<connection&>;
|
||||
|
||||
// data events
|
||||
using client_message = xpp::x::event::client_message<connection&>;
|
||||
using ge_generic = xpp::x::event::ge_generic<connection&>;
|
||||
using property_notify = xpp::x::event::property_notify<connection&>;
|
||||
|
||||
// selection events
|
||||
using selection_clear = xpp::x::event::selection_clear<connection&>;
|
||||
using selection_notify = xpp::x::event::selection_notify<connection&>;
|
||||
using selection_request = xpp::x::event::selection_request<connection&>;
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
@ -1,18 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <X11/Xlib-xcb.h>
|
||||
#include <xcb/xcbext.h>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "x11/color.hpp"
|
||||
#include "x11/connection.hpp"
|
||||
#include "x11/types.hpp"
|
||||
#include "x11/xlib.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
// fwd
|
||||
class connection;
|
||||
|
||||
#define XFT_MAXCHARS (1 << 16)
|
||||
extern array<char, XFT_MAXCHARS> xft_widths;
|
||||
extern array<wchar_t, XFT_MAXCHARS> xft_chars;
|
||||
@ -32,20 +32,15 @@ struct fonttype {
|
||||
};
|
||||
|
||||
struct fonttype_deleter {
|
||||
void operator()(fonttype* f) {
|
||||
if (f->xft != nullptr)
|
||||
XftFontClose(xlib::get_display(), f->xft);
|
||||
else
|
||||
xcb_close_font(xutils::get_connection(), f->ptr);
|
||||
}
|
||||
void operator()(fonttype* f);
|
||||
};
|
||||
|
||||
using font_t = unique_ptr<fonttype, fonttype_deleter>;
|
||||
|
||||
class fontmanager {
|
||||
class font_manager {
|
||||
public:
|
||||
explicit fontmanager(connection& conn, const logger& logger);
|
||||
~fontmanager();
|
||||
explicit font_manager(connection& conn, const logger& logger);
|
||||
~font_manager();
|
||||
|
||||
void set_preferred_font(int index);
|
||||
|
||||
@ -79,14 +74,6 @@ class fontmanager {
|
||||
XftColor m_xftcolor;
|
||||
};
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* Configure injection module
|
||||
*/
|
||||
template <typename T = unique_ptr<fontmanager>>
|
||||
di::injector<T> configure_fontmanager() {
|
||||
return di::make_injector(configure_connection(), configure_logger());
|
||||
}
|
||||
}
|
||||
di::injector<unique_ptr<font_manager>> configure_font_manager();
|
||||
|
||||
POLYBAR_NS_END
|
@ -3,7 +3,6 @@
|
||||
#include <xcb/xcb_icccm.h>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "x11/connection.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
|
@ -3,15 +3,23 @@
|
||||
#include "config.hpp"
|
||||
|
||||
#ifndef ENABLE_RANDR_EXT
|
||||
#error "RandR extension is disabled..."
|
||||
#error "X RandR extension is disabled..."
|
||||
#endif
|
||||
|
||||
#include <xpp/proto/randr.hpp>
|
||||
#include <xpp/xpp.hpp>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "utils/memory.hpp"
|
||||
#include "x11/connection.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
class connection;
|
||||
|
||||
namespace evt {
|
||||
using randr_notify = xpp::randr::event::notify<connection&>;
|
||||
using randr_screen_change_notify = xpp::randr::event::screen_change_notify<connection&>;
|
||||
}
|
||||
|
||||
struct backlight_values {
|
||||
uint32_t atom = 0;
|
||||
uint32_t min = 0;
|
||||
@ -28,16 +36,7 @@ struct randr_output {
|
||||
xcb_randr_output_t output;
|
||||
backlight_values backlight;
|
||||
|
||||
/**
|
||||
* Workaround for the inconsistent naming
|
||||
* of outputs between my intel and nvidia
|
||||
* drivers (xf86-video-intel drops the dash)
|
||||
*/
|
||||
bool match(const string& o, bool strict = false) const {
|
||||
if (strict && name != o)
|
||||
return false;
|
||||
return name == o || name == string_util::replace(o, "-", "");
|
||||
}
|
||||
bool match(const string& o, bool strict = false) const;
|
||||
};
|
||||
|
||||
using monitor_t = shared_ptr<randr_output>;
|
||||
|
9
include/x11/render.hpp
Normal file
9
include/x11/render.hpp
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "config.hpp"
|
||||
|
||||
#ifndef ENABLE_RENDER_EXT
|
||||
#error "X Render extension is disabled..."
|
||||
#endif
|
||||
|
||||
#include <xpp/proto/render.hpp>
|
@ -1,12 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <mutex>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "components/types.hpp"
|
||||
#include "x11/graphics.hpp"
|
||||
#include "utils/concurrency.hpp"
|
||||
|
||||
#define _NET_SYSTEM_TRAY_ORIENTATION_HORZ 0
|
||||
#define _NET_SYSTEM_TRAY_ORIENTATION_VERT 1
|
||||
@ -24,6 +23,10 @@ POLYBAR_NS
|
||||
class connection;
|
||||
struct xembed_data;
|
||||
|
||||
namespace graphics_util {
|
||||
struct root_pixmap;
|
||||
}
|
||||
|
||||
using root_pixmap = graphics_util::root_pixmap;
|
||||
|
||||
// class definition : settings {{{
|
||||
|
@ -2,118 +2,47 @@
|
||||
|
||||
#include "config.hpp"
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
#include <xcb/xcb_util.h>
|
||||
#ifdef ENABLE_DAMAGE_EXT
|
||||
#include <xpp/proto/damage.hpp>
|
||||
#endif
|
||||
// fwd
|
||||
#ifdef ENABLE_RANDR_EXT
|
||||
#include <xpp/proto/randr.hpp>
|
||||
#endif
|
||||
#ifdef ENABLE_RENDER_EXT
|
||||
#include <xpp/proto/render.hpp>
|
||||
namespace xpp {
|
||||
namespace randr {
|
||||
class extension;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <xpp/xpp.hpp>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "x11/connection.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
// xpp types {{{
|
||||
|
||||
class connection;
|
||||
|
||||
using registry = xpp::event::registry<connection&
|
||||
using gcontext = xpp::gcontext<connection&>;
|
||||
using pixmap = xpp::pixmap<connection&>;
|
||||
using drawable = xpp::drawable<connection&>;
|
||||
using colormap = xpp::colormap<connection&>;
|
||||
using atom = xpp::atom<connection&>;
|
||||
using font = xpp::font<connection&>;
|
||||
using cursor = xpp::cursor<connection&>;
|
||||
|
||||
using registry = xpp::event::registry<connection&,
|
||||
#ifdef ENABLE_DAMAGE_EXT
|
||||
,
|
||||
xpp::damage::extension
|
||||
#endif
|
||||
#ifdef ENABLE_RANDR_EXT
|
||||
#ifdef ENABLE_DAMAGE_EXT
|
||||
,
|
||||
#endif
|
||||
xpp::randr::extension
|
||||
#endif
|
||||
#ifdef ENABLE_RENDER_EXT
|
||||
#ifdef ENABLE_RANDR_EXT
|
||||
,
|
||||
#endif
|
||||
xpp::render::extension
|
||||
#endif
|
||||
>;
|
||||
|
||||
using atom = xpp::atom<connection&>;
|
||||
using colormap = xpp::colormap<connection&>;
|
||||
using cursor = xpp::cursor<connection&>;
|
||||
using drawable = xpp::drawable<connection&>;
|
||||
using font = xpp::font<connection&>;
|
||||
using gcontext = xpp::gcontext<connection&>;
|
||||
using pixmap = xpp::pixmap<connection&>;
|
||||
|
||||
// }}}
|
||||
|
||||
namespace evt {
|
||||
// window focus events {{{
|
||||
|
||||
using focus_in = xpp::x::event::focus_in<connection&>;
|
||||
using focus_out = xpp::x::event::focus_out<connection&>;
|
||||
|
||||
// }}}
|
||||
// cursor events {{{
|
||||
|
||||
using enter_notify = xpp::x::event::enter_notify<connection&>;
|
||||
using leave_notify = xpp::x::event::leave_notify<connection&>;
|
||||
using motion_notify = xpp::x::event::motion_notify<connection&>;
|
||||
|
||||
// }}}
|
||||
// keyboard events {{{
|
||||
|
||||
using button_press = xpp::x::event::button_press<connection&>;
|
||||
using button_release = xpp::x::event::button_release<connection&>;
|
||||
using key_press = xpp::x::event::key_press<connection&>;
|
||||
using key_release = xpp::x::event::key_release<connection&>;
|
||||
using keymap_notify = xpp::x::event::keymap_notify<connection&>;
|
||||
|
||||
// }}}
|
||||
// render events {{{
|
||||
|
||||
using circulate_notify = xpp::x::event::circulate_notify<connection&>;
|
||||
using circulate_request = xpp::x::event::circulate_request<connection&>;
|
||||
using colormap_notify = xpp::x::event::colormap_notify<connection&>;
|
||||
using configure_notify = xpp::x::event::configure_notify<connection&>;
|
||||
using configure_request = xpp::x::event::configure_request<connection&>;
|
||||
using create_notify = xpp::x::event::create_notify<connection&>;
|
||||
using destroy_notify = xpp::x::event::destroy_notify<connection&>;
|
||||
using expose = xpp::x::event::expose<connection&>;
|
||||
using graphics_exposure = xpp::x::event::graphics_exposure<connection&>;
|
||||
using gravity_notify = xpp::x::event::gravity_notify<connection&>;
|
||||
using map_notify = xpp::x::event::map_notify<connection&>;
|
||||
using map_request = xpp::x::event::map_request<connection&>;
|
||||
using mapping_notify = xpp::x::event::mapping_notify<connection&>;
|
||||
using no_exposure = xpp::x::event::no_exposure<connection&>;
|
||||
using reparent_notify = xpp::x::event::reparent_notify<connection&>;
|
||||
using resize_request = xpp::x::event::resize_request<connection&>;
|
||||
using unmap_notify = xpp::x::event::unmap_notify<connection&>;
|
||||
using visibility_notify = xpp::x::event::visibility_notify<connection&>;
|
||||
|
||||
// }}}
|
||||
// data events {{{
|
||||
|
||||
using client_message = xpp::x::event::client_message<connection&>;
|
||||
using ge_generic = xpp::x::event::ge_generic<connection&>;
|
||||
using property_notify = xpp::x::event::property_notify<connection&>;
|
||||
|
||||
// }}}
|
||||
// selection events {{{
|
||||
|
||||
using selection_clear = xpp::x::event::selection_clear<connection&>;
|
||||
using selection_notify = xpp::x::event::selection_notify<connection&>;
|
||||
using selection_request = xpp::x::event::selection_request<connection&>;
|
||||
|
||||
// }}}
|
||||
|
||||
#ifdef ENABLE_RANDR_EXT
|
||||
using randr_notify = xpp::randr::event::notify<connection&>;
|
||||
using randr_screen_change_notify = xpp::randr::event::screen_change_notify<connection&>;
|
||||
#endif
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -32,133 +32,4 @@ class window : public xpp::window<connection_t&> {
|
||||
void redraw();
|
||||
};
|
||||
|
||||
// struct cw_size {
|
||||
// cw_size(uint16_t w, uint16_t h) : w(w), h(h){};
|
||||
// uint16_t w;
|
||||
// uint16_t h;
|
||||
// };
|
||||
// struct cw_pos {
|
||||
// cw_pos(int16_t x, int16_t y) : x(x), y(y){};
|
||||
// int16_t x;
|
||||
// int16_t y;
|
||||
// };
|
||||
// struct cw_border {
|
||||
// cw_border(uint16_t border_width) : border_width(border_width){};
|
||||
// uint16_t border_width;
|
||||
// };
|
||||
// struct cw_class {
|
||||
// cw_class(uint16_t class_) : class_(class_){};
|
||||
// uint16_t class_;
|
||||
// };
|
||||
// struct cw_parent {
|
||||
// cw_parent(xcb_window_t parent) : parent(parent){};
|
||||
// xcb_window_t parent;
|
||||
// };
|
||||
// struct cw_depth {
|
||||
// cw_depth(uint8_t depth) : depth(depth){};
|
||||
// uint8_t depth;
|
||||
// };
|
||||
// struct cw_visual {
|
||||
// cw_visual(xcb_visualid_t visualid) : visualid(visualid){};
|
||||
// xcb_visualid_t visualid;
|
||||
// };
|
||||
// struct cw_mask {
|
||||
// cw_mask(uint32_t mask) : mask(mask){};
|
||||
// const uint32_t mask;
|
||||
// };
|
||||
// struct cw_params {
|
||||
// cw_params(const xcb_params_cw_t* params) : params(params){};
|
||||
// const xcb_params_cw_t* params;
|
||||
// };
|
||||
// struct cw_flush {
|
||||
// cw_flush(bool checked = true) : checked(checked){};
|
||||
// bool checked;
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * Create X window
|
||||
// *
|
||||
// * Example usage:
|
||||
// * @code cpp
|
||||
// * auto win = winspec()
|
||||
// * << cw_size(100, 200)
|
||||
// * << cw_pos(10, -20)
|
||||
// * << cw_border(9)
|
||||
// * << cw_class(XCB_WINDOW_CLASS_INPUT_ONLY)
|
||||
// * << cw_parent(0x000110a);
|
||||
// * << cw_flush(false);
|
||||
// * @endcode
|
||||
// */
|
||||
// class winspec {
|
||||
// public:
|
||||
// explicit winspec(connection& conn) : m_connection(conn) {}
|
||||
//
|
||||
// winspec& operator<<(cw_size w) {
|
||||
// m_width = w.w;
|
||||
// m_height = w.h;
|
||||
// return *this;
|
||||
// }
|
||||
// winspec& operator<<(cw_pos p) {
|
||||
// m_x = p.x;
|
||||
// m_y = p.y;
|
||||
// return *this;
|
||||
// }
|
||||
// winspec& operator<<(cw_border b) {
|
||||
// m_border = b.border_width;
|
||||
// return *this;
|
||||
// }
|
||||
// winspec& operator<<(cw_class c) {
|
||||
// m_class = c.class_;
|
||||
// return *this;
|
||||
// }
|
||||
// winspec& operator<<(cw_parent p) {
|
||||
// m_parent = p.parent;
|
||||
// return *this;
|
||||
// }
|
||||
// winspec& operator<<(cw_depth d) {
|
||||
// m_depth = d.depth;
|
||||
// return *this;
|
||||
// }
|
||||
// winspec& operator<<(cw_visual v) {
|
||||
// m_visual = v.visualid;
|
||||
// return *this;
|
||||
// }
|
||||
// winspec& operator<<(cw_mask m) {
|
||||
// m_mask = m.mask;
|
||||
// return *this;
|
||||
// }
|
||||
// winspec& operator<<(cw_params p) {
|
||||
// m_params = p.params;
|
||||
// return *this;
|
||||
// }
|
||||
//
|
||||
// window operator<<(cw_flush f) {
|
||||
// if (f.checked)
|
||||
// m_connection.create_window_checked(m_depth, m_window, m_parent, m_x, m_y, m_width,
|
||||
// m_height,
|
||||
// m_border, m_class, m_visual, m_mask, m_params);
|
||||
// else
|
||||
// m_connection.create_window(m_depth, m_window, m_parent, m_x, m_y, m_width, m_height,
|
||||
// m_border,
|
||||
// m_class, m_visual, m_mask, m_params);
|
||||
// return m_window;
|
||||
// }
|
||||
//
|
||||
// protected:
|
||||
// connection& m_connection;
|
||||
// window m_window{m_connection};
|
||||
//
|
||||
// uint8_t m_depth;
|
||||
// xcb_window_t m_parent;
|
||||
// int16_t m_x;
|
||||
// int16_t m_y;
|
||||
// uint16_t m_width;
|
||||
// uint16_t m_height;
|
||||
// uint16_t m_border;
|
||||
// uint16_t m_class;
|
||||
// xcb_visualid_t m_visual;
|
||||
// uint32_t m_mask;
|
||||
// const xcb_params_cw_t* m_params;
|
||||
// };
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
151
include/x11/winspec.hpp
Normal file
151
include/x11/winspec.hpp
Normal file
@ -0,0 +1,151 @@
|
||||
#pragma once
|
||||
|
||||
#include "common.hpp"
|
||||
#include "x11/connection.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
using connection_t = connection;
|
||||
|
||||
struct cw_size {
|
||||
cw_size(uint16_t w, uint16_t h) : w(w), h(h) {}
|
||||
uint16_t w;
|
||||
uint16_t h;
|
||||
};
|
||||
struct cw_pos {
|
||||
cw_pos(int16_t x, int16_t y) : x(x), y(y) {}
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
};
|
||||
struct cw_border {
|
||||
cw_border(uint16_t border_width) : border_width(border_width) {}
|
||||
uint16_t border_width;
|
||||
};
|
||||
struct cw_class {
|
||||
cw_class(uint16_t class_) : class_(class_) {}
|
||||
uint16_t class_;
|
||||
};
|
||||
struct cw_parent {
|
||||
cw_parent(xcb_window_t parent) : parent(parent) {}
|
||||
xcb_window_t parent;
|
||||
};
|
||||
struct cw_depth {
|
||||
cw_depth(uint8_t depth) : depth(depth) {}
|
||||
uint8_t depth;
|
||||
};
|
||||
struct cw_visual {
|
||||
cw_visual(xcb_visualid_t visualid) : visualid(visualid) {}
|
||||
xcb_visualid_t visualid;
|
||||
};
|
||||
struct cw_mask {
|
||||
cw_mask(uint32_t mask) : mask(mask) {}
|
||||
const uint32_t mask;
|
||||
};
|
||||
struct cw_params {
|
||||
cw_params(const xcb_params_cw_t* params) : params(params) {}
|
||||
const xcb_params_cw_t* params;
|
||||
};
|
||||
struct cw_flush {
|
||||
cw_flush(bool checked = true) : checked(checked) {}
|
||||
bool checked;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create X window
|
||||
*
|
||||
* Example usage:
|
||||
* @code cpp
|
||||
* auto win = winspec(conn)
|
||||
* << cw_size(100, 200)
|
||||
* << cw_pos(10, -20)
|
||||
* << cw_border(9)
|
||||
* << cw_class(XCB_WINDOW_CLASS_INPUT_ONLY)
|
||||
* << cw_parent(0x000110a);
|
||||
* << cw_flush(false);
|
||||
* @endcode
|
||||
*/
|
||||
class winspec {
|
||||
public:
|
||||
explicit winspec(connection& conn, uint32_t id = XCB_NONE) : m_connection(conn), m_window(id) {}
|
||||
|
||||
explicit operator xcb_window_t() const {
|
||||
return m_window;
|
||||
}
|
||||
|
||||
explicit operator xcb_rectangle_t() const {
|
||||
return {m_x, m_y, m_width, m_height};
|
||||
}
|
||||
|
||||
winspec& operator<<(cw_size w) {
|
||||
m_width = w.w;
|
||||
m_height = w.h;
|
||||
return *this;
|
||||
}
|
||||
winspec& operator<<(cw_pos p) {
|
||||
m_x = p.x;
|
||||
m_y = p.y;
|
||||
return *this;
|
||||
}
|
||||
winspec& operator<<(cw_border b) {
|
||||
m_border = b.border_width;
|
||||
return *this;
|
||||
}
|
||||
winspec& operator<<(cw_class c) {
|
||||
m_class = c.class_;
|
||||
return *this;
|
||||
}
|
||||
winspec& operator<<(cw_parent p) {
|
||||
m_parent = p.parent;
|
||||
return *this;
|
||||
}
|
||||
winspec& operator<<(cw_depth d) {
|
||||
m_depth = d.depth;
|
||||
return *this;
|
||||
}
|
||||
winspec& operator<<(cw_visual v) {
|
||||
m_visual = v.visualid;
|
||||
return *this;
|
||||
}
|
||||
winspec& operator<<(cw_mask m) {
|
||||
m_mask = m.mask;
|
||||
return *this;
|
||||
}
|
||||
winspec& operator<<(cw_params p) {
|
||||
m_params = p.params;
|
||||
return *this;
|
||||
}
|
||||
|
||||
xcb_window_t operator<<(cw_flush f) {
|
||||
if (m_window == XCB_NONE) {
|
||||
m_window = m_connection.generate_id();
|
||||
}
|
||||
|
||||
if (f.checked) {
|
||||
m_connection.create_window_checked(
|
||||
m_depth, m_window, m_parent, m_x, m_y, m_width, m_height, m_border, m_class, m_visual, m_mask, m_params);
|
||||
} else {
|
||||
m_connection.create_window(
|
||||
m_depth, m_window, m_parent, m_x, m_y, m_width, m_height, m_border, m_class, m_visual, m_mask, m_params);
|
||||
}
|
||||
|
||||
return m_window;
|
||||
}
|
||||
|
||||
protected:
|
||||
connection& m_connection;
|
||||
uint32_t m_window;
|
||||
|
||||
uint8_t m_depth;
|
||||
xcb_window_t m_parent;
|
||||
int16_t m_x;
|
||||
int16_t m_y;
|
||||
uint16_t m_width;
|
||||
uint16_t m_height;
|
||||
uint16_t m_border;
|
||||
uint16_t m_class;
|
||||
xcb_visualid_t m_visual;
|
||||
uint32_t m_mask;
|
||||
const xcb_params_cw_t* m_params;
|
||||
};
|
||||
|
||||
POLYBAR_NS_END
|
@ -1,10 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "x11/connection.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
class connection;
|
||||
|
||||
namespace wm_util {
|
||||
void set_wmname(connection& conn, xcb_window_t win, string wm_name, string wm_class);
|
||||
void set_wmprotocols(connection& conn, xcb_window_t win, vector<xcb_atom_t> flags);
|
||||
|
@ -22,15 +22,6 @@ class xresource_manager {
|
||||
XrmDatabase m_db;
|
||||
};
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* Configure injection module
|
||||
*/
|
||||
template <typename T = const xresource_manager&>
|
||||
di::injector<T> configure_xresource_manager() {
|
||||
auto instance = factory::generic_singleton<xresource_manager>();
|
||||
return di::make_injector(di::bind<>().to(instance));
|
||||
}
|
||||
}
|
||||
di::injector<const xresource_manager&> configure_xresource_manager();
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -1,21 +1,15 @@
|
||||
#
|
||||
# Create library and executable
|
||||
# Create executable
|
||||
#
|
||||
|
||||
set(BINARY_NAME ${PROJECT_NAME})
|
||||
set(LIBRARY_NAME lib${PROJECT_NAME})
|
||||
|
||||
file(GLOB_RECURSE HEADERS RELATIVE ${PROJECT_SOURCE_DIR}/include *.h[p]*)
|
||||
file(GLOB_RECURSE SOURCES RELATIVE ${PROJECT_SOURCE_DIR}/src *.c[p]*)
|
||||
|
||||
list(REMOVE_ITEM SOURCES main.cpp)
|
||||
|
||||
configure_file(
|
||||
${PROJECT_SOURCE_DIR}/include/config.hpp.cmake
|
||||
${CMAKE_SOURCE_DIR}/include/config.hpp
|
||||
ESCAPE_QUOTES @ONLY)
|
||||
|
||||
# Strip disabled libs {{{
|
||||
# Generate source tree {{{
|
||||
|
||||
file(GLOB_RECURSE SOURCES RELATIVE ${PROJECT_SOURCE_DIR}/src *.c[p]*)
|
||||
|
||||
if(NOT ENABLE_ALSA)
|
||||
list(REMOVE_ITEM SOURCES adapters/alsa.cpp modules/volume.cpp)
|
||||
@ -31,60 +25,26 @@ if(NOT ENABLE_I3)
|
||||
endif()
|
||||
|
||||
# }}}
|
||||
|
||||
# Target: main library {{{
|
||||
|
||||
make_library(${LIBRARY_NAME} STATIC
|
||||
HEADER_INSTALL_DIR
|
||||
${PROJECT_NAME}
|
||||
HEADERS
|
||||
${HEADERS}
|
||||
SOURCES
|
||||
${SOURCES})
|
||||
|
||||
target_include_directories(${LIBRARY_NAME}_static PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
# }}}
|
||||
# Target: main executable {{{
|
||||
|
||||
make_executable(${BINARY_NAME}
|
||||
SOURCES main.cpp
|
||||
TARGET_DEPENDS ${LIBRARY_NAME}_static)
|
||||
|
||||
# }}}
|
||||
|
||||
# Link dependencies {{{
|
||||
# Locate dependencies {{{
|
||||
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
|
||||
find_package(Boost REQUIRED)
|
||||
find_package(Threads REQUIRED)
|
||||
find_package(Freetype REQUIRED Freetype2)
|
||||
find_package(X11 REQUIRED COMPONENTS Xft Xutil)
|
||||
find_package(X11_XCB REQUIRED)
|
||||
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(FONTCONFIG REQUIRED fontconfig)
|
||||
|
||||
target_link_libraries(${LIBRARY_NAME}_static PUBLIC ${BOOST_LIBRARIES})
|
||||
target_link_libraries(${LIBRARY_NAME}_static PUBLIC ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(${LIBRARY_NAME}_static PUBLIC Threads::Threads)
|
||||
target_link_libraries(${LIBRARY_NAME}_static PUBLIC ${X11_LIBRARIES})
|
||||
target_link_libraries(${LIBRARY_NAME}_static PUBLIC ${X11_X11_LIB})
|
||||
target_link_libraries(${LIBRARY_NAME}_static PUBLIC ${X11_XCB_LIB})
|
||||
target_link_libraries(${LIBRARY_NAME}_static PUBLIC ${X11_Xft_LIB})
|
||||
target_link_libraries(${LIBRARY_NAME}_static PUBLIC ${FREETYPE_LIBRARIES})
|
||||
target_link_libraries(${LIBRARY_NAME}_static PUBLIC ${FONTCONFIG_LIBRARIES})
|
||||
set(APP_LIBRARIES ${APP_LIBRARIES} ${BOOST_LIBRARIES})
|
||||
set(APP_LIBRARIES ${APP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
|
||||
set(APP_LIBRARIES ${APP_LIBRARIES} ${X11_Xft_LIB})
|
||||
|
||||
target_include_directories(${LIBRARY_NAME}_static PUBLIC ${BOOST_INCLUDE_DIR})
|
||||
target_include_directories(${LIBRARY_NAME}_static PUBLIC ${FONTCONFIG_INCLUDE_DIRS})
|
||||
target_include_directories(${LIBRARY_NAME}_static PUBLIC ${PROJECT_SOURCE_DIR}/include)
|
||||
target_include_directories(${LIBRARY_NAME}_static PUBLIC ${PROJECT_SOURCE_DIR}/lib/boost/include)
|
||||
target_include_directories(${LIBRARY_NAME}_static PUBLIC ${PROJECT_SOURCE_DIR}/lib/concurrentqueue/include)
|
||||
|
||||
target_compile_definitions(${BINARY_NAME} PUBLIC
|
||||
${X11_XCB_DEFINITIONS}
|
||||
${XCB_DEFINITIONS})
|
||||
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${BOOST_INCLUDE_DIR})
|
||||
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${FONTCONFIG_INCLUDE_DIRS})
|
||||
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/include)
|
||||
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/lib/boost/include)
|
||||
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/lib/concurrentqueue/include)
|
||||
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
# xpp library
|
||||
set(XCB_PROTOS xproto)
|
||||
@ -98,15 +58,16 @@ if(ENABLE_DAMAGE_EXT)
|
||||
set(XCB_PROTOS "${XCB_PROTOS}" damage)
|
||||
endif()
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/xpp ${PROJECT_BINARY_DIR}/lib/xpp)
|
||||
target_link_libraries(${LIBRARY_NAME}_static PUBLIC ${XPP_LIBRARIES})
|
||||
set(APP_LIBRARIES ${APP_LIBRARIES} ${XPP_LIBRARIES})
|
||||
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${XPP_INCLUDE_DIRS})
|
||||
|
||||
# }}}
|
||||
|
||||
# Optional dependency: alsalib {{{
|
||||
|
||||
if(ENABLE_ALSA)
|
||||
find_package(ALSA REQUIRED)
|
||||
target_link_libraries(${LIBRARY_NAME}_static PUBLIC ${ALSA_LIBRARY})
|
||||
set(APP_LIBRARIES ${APP_LIBRARIES} ${ALSA_LIBRARY})
|
||||
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${ALSA_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
# }}}
|
||||
@ -114,7 +75,8 @@ endif()
|
||||
|
||||
if(ENABLE_MPD)
|
||||
find_package(LibMPDClient REQUIRED)
|
||||
target_link_libraries(${LIBRARY_NAME}_static PUBLIC ${LIBMPDCLIENT_LIBRARIES})
|
||||
set(APP_LIBRARIES ${APP_LIBRARIES} ${LIBMPDCLIENT_LIBRARY})
|
||||
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${LIBMPDCLIENT_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
# }}}
|
||||
@ -122,7 +84,8 @@ endif()
|
||||
|
||||
if(ENABLE_NETWORK)
|
||||
find_package(Libiw REQUIRED)
|
||||
target_link_libraries(${LIBRARY_NAME}_static PUBLIC ${LIBIW_LIBRARY})
|
||||
set(APP_LIBRARIES ${APP_LIBRARIES} ${LIBIW_LIBRARY})
|
||||
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${LIBIW_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
# }}}
|
||||
@ -130,21 +93,31 @@ endif()
|
||||
|
||||
if(ENABLE_I3)
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/i3ipcpp ${PROJECT_BINARY_DIR}/lib/i3ipcpp)
|
||||
target_include_directories(${LIBRARY_NAME}_static PUBLIC ${I3IPCPP_INCLUDE_DIRS})
|
||||
target_link_libraries(${LIBRARY_NAME}_static PUBLIC ${I3IPCPP_LIBRARIES})
|
||||
set(APP_LIBRARIES ${APP_LIBRARIES} ${I3IPCPP_LIBRARIES})
|
||||
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${I3IPCPP_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
# }}}
|
||||
# Create executable target {{{
|
||||
|
||||
# Export target details {{{
|
||||
make_executable(${PROJECT_NAME} SOURCES
|
||||
${SOURCES}
|
||||
INCLUDE_DIRS
|
||||
${APP_INCLUDE_DIRS}
|
||||
RAW_DEPENDS
|
||||
${APP_LIBRARIES})
|
||||
|
||||
set(APP_BINARY ${PROJECT_SOURCE_DIR}/bin/${BINARY_NAME} PARENT_SCOPE)
|
||||
set(APP_LIBRARIES ${LIBRARY_NAME}_static ${XPP_LIBRARY} PARENT_SCOPE)
|
||||
set(APP_INCLUDE_DIRS
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
${PROJECT_SOURCE_DIR}/lib/boost/include
|
||||
${PROJECT_SOURCE_DIR}/lib/concurrentqueue/include
|
||||
${XPP_INCLUDE_DIRS}
|
||||
PARENT_SCOPE)
|
||||
target_link_libraries(${PROJECT_NAME} Threads::Threads)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC
|
||||
${X11_XCB_DEFINITIONS}
|
||||
${XCB_DEFINITIONS})
|
||||
|
||||
# }}}
|
||||
# Export target details {{{
|
||||
|
||||
set(APP_BINARY ${PROJECT_SOURCE_DIR}/bin/${PROJECT_NAME} PARENT_SCOPE)
|
||||
set(APP_LIBRARIES ${APP_LIBRARIES} PARENT_SCOPE)
|
||||
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} PARENT_SCOPE)
|
||||
|
||||
# }}}
|
||||
|
@ -37,7 +37,7 @@ alsa_ctl_interface::alsa_ctl_interface(int numid) : m_numid(numid) {
|
||||
}
|
||||
|
||||
alsa_ctl_interface::~alsa_ctl_interface() {
|
||||
std::lock_guard<threading_util::spin_lock> guard(m_lock);
|
||||
std::lock_guard<concurrency_util::spin_lock> guard(m_lock);
|
||||
snd_ctl_close(m_ctl);
|
||||
snd_hctl_close(m_hctl);
|
||||
}
|
||||
@ -49,7 +49,7 @@ int alsa_ctl_interface::get_numid() {
|
||||
bool alsa_ctl_interface::wait(int timeout) {
|
||||
assert(m_ctl);
|
||||
|
||||
std::lock_guard<threading_util::spin_lock> guard(m_lock);
|
||||
std::lock_guard<concurrency_util::spin_lock> guard(m_lock);
|
||||
|
||||
int err = 0;
|
||||
|
||||
@ -73,7 +73,7 @@ bool alsa_ctl_interface::test_device_plugged() {
|
||||
assert(m_elem);
|
||||
assert(m_value);
|
||||
|
||||
std::lock_guard<threading_util::spin_lock> guard(m_lock);
|
||||
std::lock_guard<concurrency_util::spin_lock> guard(m_lock);
|
||||
|
||||
int err = 0;
|
||||
if ((err = snd_hctl_elem_read(m_elem, m_value)) < 0)
|
||||
@ -114,7 +114,7 @@ alsa_mixer::alsa_mixer(string mixer_control_name) : m_name(mixer_control_name) {
|
||||
}
|
||||
|
||||
alsa_mixer::~alsa_mixer() {
|
||||
std::lock_guard<threading_util::spin_lock> guard(m_lock);
|
||||
std::lock_guard<concurrency_util::spin_lock> guard(m_lock);
|
||||
snd_mixer_elem_remove(m_mixerelement);
|
||||
snd_mixer_detach(m_hardwaremixer, ALSA_SOUNDCARD);
|
||||
snd_mixer_close(m_hardwaremixer);
|
||||
@ -127,7 +127,7 @@ string alsa_mixer::get_name() {
|
||||
bool alsa_mixer::wait(int timeout) {
|
||||
assert(m_hardwaremixer);
|
||||
|
||||
std::unique_lock<threading_util::spin_lock> guard(m_lock);
|
||||
std::unique_lock<concurrency_util::spin_lock> guard(m_lock);
|
||||
|
||||
int err = 0;
|
||||
|
||||
@ -140,7 +140,7 @@ bool alsa_mixer::wait(int timeout) {
|
||||
}
|
||||
|
||||
int alsa_mixer::process_events() {
|
||||
std::lock_guard<threading_util::spin_lock> guard(m_lock);
|
||||
std::lock_guard<concurrency_util::spin_lock> guard(m_lock);
|
||||
|
||||
int num_events = snd_mixer_handle_events(m_hardwaremixer);
|
||||
|
||||
@ -151,7 +151,7 @@ int alsa_mixer::process_events() {
|
||||
}
|
||||
|
||||
int alsa_mixer::get_volume() {
|
||||
std::lock_guard<threading_util::spin_lock> guard(m_lock);
|
||||
std::lock_guard<concurrency_util::spin_lock> guard(m_lock);
|
||||
long chan_n = 0, vol_total = 0, vol, vol_min, vol_max;
|
||||
|
||||
snd_mixer_selem_get_playback_volume_range(m_mixerelement, &vol_min, &vol_max);
|
||||
@ -170,7 +170,7 @@ int alsa_mixer::get_volume() {
|
||||
}
|
||||
|
||||
int alsa_mixer::get_normalized_volume() {
|
||||
std::lock_guard<threading_util::spin_lock> guard(m_lock);
|
||||
std::lock_guard<concurrency_util::spin_lock> guard(m_lock);
|
||||
long chan_n = 0, vol_total = 0, vol, vol_min, vol_max;
|
||||
double normalized, min_norm;
|
||||
|
||||
@ -202,7 +202,7 @@ void alsa_mixer::set_volume(float percentage) {
|
||||
if (is_muted())
|
||||
return;
|
||||
|
||||
std::lock_guard<threading_util::spin_lock> guard(m_lock);
|
||||
std::lock_guard<concurrency_util::spin_lock> guard(m_lock);
|
||||
|
||||
long vol_min, vol_max;
|
||||
|
||||
@ -214,7 +214,7 @@ void alsa_mixer::set_normalized_volume(float percentage) {
|
||||
if (is_muted())
|
||||
return;
|
||||
|
||||
std::lock_guard<threading_util::spin_lock> guard(m_lock);
|
||||
std::lock_guard<concurrency_util::spin_lock> guard(m_lock);
|
||||
|
||||
long vol_min, vol_max;
|
||||
double min_norm;
|
||||
@ -236,19 +236,19 @@ void alsa_mixer::set_normalized_volume(float percentage) {
|
||||
}
|
||||
|
||||
void alsa_mixer::set_mute(bool mode) {
|
||||
std::lock_guard<threading_util::spin_lock> guard(m_lock);
|
||||
std::lock_guard<concurrency_util::spin_lock> guard(m_lock);
|
||||
snd_mixer_selem_set_playback_switch_all(m_mixerelement, mode);
|
||||
}
|
||||
|
||||
void alsa_mixer::toggle_mute() {
|
||||
std::lock_guard<threading_util::spin_lock> guard(m_lock);
|
||||
std::lock_guard<concurrency_util::spin_lock> guard(m_lock);
|
||||
int state;
|
||||
snd_mixer_selem_get_playback_switch(m_mixerelement, SND_MIXER_SCHN_MONO, &state);
|
||||
snd_mixer_selem_set_playback_switch_all(m_mixerelement, !state);
|
||||
}
|
||||
|
||||
bool alsa_mixer::is_muted() {
|
||||
std::lock_guard<threading_util::spin_lock> guard(m_lock);
|
||||
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(
|
||||
|
@ -1,4 +1,7 @@
|
||||
#include <thread>
|
||||
|
||||
#include "adapters/mpd.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "utils/math.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
@ -82,10 +85,13 @@ namespace mpd {
|
||||
// }}}
|
||||
// class: mpdconnection {{{
|
||||
|
||||
mpdconnection::mpdconnection(
|
||||
const logger& logger, string host, unsigned int port, string password, unsigned int timeout)
|
||||
: m_log(logger), m_host(host), m_port(port), m_password(password), m_timeout(timeout) {}
|
||||
|
||||
void mpdconnection::connect() {
|
||||
try {
|
||||
m_log.trace("mpdconnection.connect: %s, %i, \"%s\", timeout: %i", m_host, m_port, m_password,
|
||||
m_timeout);
|
||||
m_log.trace("mpdconnection.connect: %s, %i, \"%s\", timeout: %i", m_host, m_port, m_password, m_timeout);
|
||||
m_connection.reset(mpd_connection_new(m_host.c_str(), m_port, m_timeout * 1000));
|
||||
check_errors(m_connection.get());
|
||||
|
||||
@ -127,7 +133,7 @@ namespace mpd {
|
||||
} catch (const mpd_exception& e) {
|
||||
}
|
||||
|
||||
this_thread::sleep_for(chrono::duration<double>(interval));
|
||||
std::this_thread::sleep_for(chrono::duration<double>(interval));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -4,13 +4,14 @@
|
||||
#include "components/parser.hpp"
|
||||
#include "components/signals.hpp"
|
||||
#include "utils/bspwm.hpp"
|
||||
#include "x11/draw.hpp"
|
||||
#include "x11/graphics.hpp"
|
||||
#include "utils/color.hpp"
|
||||
#include "utils/math.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "x11/draw.hpp"
|
||||
#include "x11/randr.hpp"
|
||||
#include "x11/draw.hpp"
|
||||
#include "x11/fonts.hpp"
|
||||
#include "x11/graphics.hpp"
|
||||
#include "x11/tray.hpp"
|
||||
#include "x11/wm.hpp"
|
||||
#include "x11/xlib.hpp"
|
||||
#include "x11/xutils.hpp"
|
||||
@ -21,11 +22,36 @@
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
/**
|
||||
* Configure injection module
|
||||
*/
|
||||
di::injector<unique_ptr<bar>> configure_bar() {
|
||||
// clang-format off
|
||||
return di::make_injector(
|
||||
configure_connection(),
|
||||
configure_config(),
|
||||
configure_logger(),
|
||||
configure_font_manager(),
|
||||
configure_tray_manager());
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct bar instance
|
||||
*/
|
||||
bar::bar(connection& conn, const config& config, const logger& logger, unique_ptr<font_manager> font_manager,
|
||||
unique_ptr<tray_manager> tray_manager)
|
||||
: m_connection(conn)
|
||||
, m_conf(config)
|
||||
, m_log(logger)
|
||||
, m_fontmanager(forward<decltype(font_manager)>(font_manager))
|
||||
, m_tray(forward<decltype(tray_manager)>(tray_manager)) {}
|
||||
|
||||
/**
|
||||
* Cleanup signal handlers and destroy the bar window
|
||||
*/
|
||||
bar::~bar() {
|
||||
std::lock_guard<threading_util::spin_lock> lck(m_lock);
|
||||
std::lock_guard<concurrency_util::spin_lock> lck(m_lock);
|
||||
|
||||
// Disconnect signal handlers {{{
|
||||
g_signals::parser::alignment_change = nullptr;
|
||||
@ -69,7 +95,7 @@ void bar::bootstrap(bool nodraw) {
|
||||
m_screensize.h = geom->height;
|
||||
|
||||
// limit the amount of allowed input events to 1 per 60ms
|
||||
m_throttler = throttle_util::make_throttler(1, 60ms);
|
||||
m_throttler = throttle_util::make_throttler(1, chrono::milliseconds{60});
|
||||
|
||||
m_opts.separator = string_util::trim(m_conf.get<string>(bs, "separator", ""), '"');
|
||||
m_opts.locale = m_conf.get<string>(bs, "locale", "");
|
||||
@ -345,14 +371,14 @@ const bar_settings bar::settings() const {
|
||||
* @param force Unless true, do not parse unchanged data
|
||||
*/
|
||||
void bar::parse(string data, bool force) {
|
||||
std::lock_guard<threading_util::spin_lock> lck(m_lock);
|
||||
std::lock_guard<concurrency_util::spin_lock> lck(m_lock);
|
||||
{
|
||||
if (data == m_prevdata && !force)
|
||||
return;
|
||||
|
||||
m_prevdata = data;
|
||||
|
||||
// TODO: move to fontmanager
|
||||
// TODO: move to font_manager
|
||||
m_xftdraw = XftDrawCreate(xlib::get_display(), m_pixmap, xlib::get_visual(), m_colormap);
|
||||
|
||||
m_opts.align = alignment::LEFT;
|
||||
@ -760,7 +786,7 @@ void bar::handle(const evt::button_press& evt) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<threading_util::spin_lock> lck(m_lock);
|
||||
std::lock_guard<concurrency_util::spin_lock> lck(m_lock);
|
||||
{
|
||||
m_log.trace_x("bar: Received button press event: %i at pos(%i, %i)", static_cast<int>(evt->detail), evt->event_x,
|
||||
evt->event_y);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
#include "components/command_line.hpp"
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "components/config.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/env.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
@ -25,10 +28,11 @@ void config::load(string file, string barname) {
|
||||
if (std::find(bars.begin(), bars.end(), m_current_bar) == bars.end())
|
||||
throw application_error("Undefined bar: " + m_current_bar);
|
||||
|
||||
if (has_env("XDG_CONFIG_HOME"))
|
||||
file = string_util::replace(file, read_env("XDG_CONFIG_HOME"), "$XDG_CONFIG_HOME");
|
||||
if (has_env("HOME"))
|
||||
file = string_util::replace(file, read_env("HOME"), "~");
|
||||
if (env_util::has("XDG_CONFIG_HOME"))
|
||||
file = string_util::replace(file, env_util::get("XDG_CONFIG_HOME"), "$XDG_CONFIG_HOME");
|
||||
if (env_util::has("HOME"))
|
||||
file = string_util::replace(file, env_util::get("HOME"), "~");
|
||||
|
||||
m_logger.trace("config: Loaded %s", file);
|
||||
m_logger.trace("config: Current bar section: [%s]", bar_section());
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
#include <chrono>
|
||||
#include <csignal>
|
||||
#include <mutex>
|
||||
|
||||
#include "x11/color.hpp"
|
||||
#include "components/bar.hpp"
|
||||
|
||||
#include "components/controller.hpp"
|
||||
|
||||
#include "modules/backlight.hpp"
|
||||
@ -20,7 +24,6 @@
|
||||
#include "modules/xbacklight.hpp"
|
||||
#include "modules/xwindow.hpp"
|
||||
|
||||
#include "components/bar.hpp"
|
||||
#include "components/config.hpp"
|
||||
#include "components/eventloop.hpp"
|
||||
#include "components/ipc.hpp"
|
||||
@ -46,6 +49,23 @@ POLYBAR_NS
|
||||
|
||||
using namespace modules;
|
||||
|
||||
namespace chrono = std::chrono;
|
||||
|
||||
/**
|
||||
* Configure injection module
|
||||
*/
|
||||
di::injector<unique_ptr<controller>> configure_controller(watch_t& confwatch) {
|
||||
// clang-format off
|
||||
return di::make_injector(
|
||||
di::bind<>().to(confwatch),
|
||||
configure_connection(),
|
||||
configure_logger(),
|
||||
configure_config(),
|
||||
configure_eventloop(),
|
||||
configure_bar());
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop modules and cleanup X components,
|
||||
* threads and spawned processes
|
||||
@ -231,7 +251,7 @@ void controller::install_confwatch() {
|
||||
}
|
||||
|
||||
m_threads.emplace_back([this] {
|
||||
this_thread::sleep_for(1s);
|
||||
this_thread::sleep_for(chrono::seconds{1});
|
||||
|
||||
try {
|
||||
if (!m_running)
|
||||
@ -396,7 +416,7 @@ void controller::bootstrap_modules() {
|
||||
throw application_error("Inter-process messaging needs to be enabled");
|
||||
module.reset(new ipc_module(bar, m_log, m_conf, module_name));
|
||||
m_ipc->attach_callback(
|
||||
bind(&ipc_module::on_message, dynamic_cast<ipc_module*>(module.get()), placeholders::_1));
|
||||
bind(&ipc_module::on_message, static_cast<ipc_module*>(module.get()), placeholders::_1));
|
||||
} else
|
||||
throw application_error("Unknown module: " + module_name);
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
#include "components/eventloop.hpp"
|
||||
#include "components/types.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "utils/time.hpp"
|
||||
#include "x11/color.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
@ -10,7 +13,7 @@ eventloop::~eventloop() noexcept {
|
||||
for (auto&& block : m_modules) {
|
||||
for (auto&& module : block.second) {
|
||||
auto module_name = module->name();
|
||||
auto cleanup_ms = time_execution([&module] {
|
||||
auto cleanup_ms = time_util::measure([&module] {
|
||||
module->stop();
|
||||
module.reset();
|
||||
});
|
||||
@ -38,7 +41,7 @@ bool eventloop::enqueue(const entry_t& i) {
|
||||
* @param timeframe Time to wait for subsequent events
|
||||
* @param limit Maximum amount of subsequent events to swallow within timeframe
|
||||
*/
|
||||
void eventloop::run(chrono::duration<double, std::milli> timeframe, int limit) {
|
||||
void eventloop::run(std::chrono::duration<double, std::milli> timeframe, int limit) {
|
||||
m_log.info("Starting event loop", timeframe.count(), limit);
|
||||
m_running = true;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "components/ipc.hpp"
|
||||
#include "config.hpp"
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "components/logger.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
#include "x11/color.hpp"
|
||||
#include "components/types.hpp"
|
||||
|
||||
#include "components/parser.hpp"
|
||||
#include "utils/math.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
@ -1,32 +1,33 @@
|
||||
#include "components/signals.hpp"
|
||||
#include "components/types.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
/**
|
||||
* Signals used to communicate with the bar window
|
||||
*/
|
||||
callback<string> g_signals::bar::action_click = nullptr;
|
||||
callback<bool> g_signals::bar::visibility_change = nullptr;
|
||||
callback<string> g_signals::bar::action_click{nullptr};
|
||||
callback<bool> g_signals::bar::visibility_change{nullptr};
|
||||
|
||||
/**
|
||||
* Signals used to communicate with the input parser
|
||||
*/
|
||||
callback<alignment> g_signals::parser::alignment_change = nullptr;
|
||||
callback<attribute> g_signals::parser::attribute_set = nullptr;
|
||||
callback<attribute> g_signals::parser::attribute_unset = nullptr;
|
||||
callback<attribute> g_signals::parser::attribute_toggle = nullptr;
|
||||
callback<mousebtn, string> g_signals::parser::action_block_open = nullptr;
|
||||
callback<mousebtn> g_signals::parser::action_block_close = nullptr;
|
||||
callback<gc, color> g_signals::parser::color_change = nullptr;
|
||||
callback<int> g_signals::parser::font_change = nullptr;
|
||||
callback<int> g_signals::parser::pixel_offset = nullptr;
|
||||
callback<uint16_t> g_signals::parser::ascii_text_write = nullptr;
|
||||
callback<uint16_t> g_signals::parser::unicode_text_write = nullptr;
|
||||
callback<const char*, size_t> g_signals::parser::string_write = nullptr;
|
||||
callback<alignment> g_signals::parser::alignment_change{nullptr};
|
||||
callback<attribute> g_signals::parser::attribute_set{nullptr};
|
||||
callback<attribute> g_signals::parser::attribute_unset{nullptr};
|
||||
callback<attribute> g_signals::parser::attribute_toggle{nullptr};
|
||||
callback<mousebtn, string> g_signals::parser::action_block_open{nullptr};
|
||||
callback<mousebtn> g_signals::parser::action_block_close{nullptr};
|
||||
callback<gc, color> g_signals::parser::color_change{nullptr};
|
||||
callback<int> g_signals::parser::font_change{nullptr};
|
||||
callback<int> g_signals::parser::pixel_offset{nullptr};
|
||||
callback<uint16_t> g_signals::parser::ascii_text_write{nullptr};
|
||||
callback<uint16_t> g_signals::parser::unicode_text_write{nullptr};
|
||||
callback<const char*, size_t> g_signals::parser::string_write{nullptr};
|
||||
|
||||
/**
|
||||
* Signals used to communicate with the tray manager
|
||||
*/
|
||||
callback<uint16_t> g_signals::tray::report_slotcount = nullptr;
|
||||
callback<uint16_t> g_signals::tray::report_slotcount{nullptr};
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -1,3 +1,6 @@
|
||||
#include "x11/color.hpp"
|
||||
#include "components/types.hpp"
|
||||
|
||||
#include "drawtypes/progressbar.hpp"
|
||||
#include "utils/math.hpp"
|
||||
|
||||
|
15
src/main.cpp
15
src/main.cpp
@ -1,13 +1,16 @@
|
||||
#include <X11/Xlib-xcb.h>
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
#include "components/bar.hpp"
|
||||
#include "components/command_line.hpp"
|
||||
#include "components/config.hpp"
|
||||
#include "components/controller.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "x11/xutils.hpp"
|
||||
#include "config.hpp"
|
||||
#include "utils/env.hpp"
|
||||
#include "utils/inotify.hpp"
|
||||
#include "x11/xutils.hpp"
|
||||
|
||||
using namespace polybar;
|
||||
|
||||
@ -67,7 +70,7 @@ int main(int argc, char** argv) {
|
||||
cli.usage();
|
||||
return EXIT_SUCCESS;
|
||||
} else if (cli.has("version")) {
|
||||
print_build_info();
|
||||
print_build_info(version_details(args));
|
||||
return EXIT_SUCCESS;
|
||||
} else if (args.empty() || args[0][0] == '-') {
|
||||
cli.usage();
|
||||
@ -81,10 +84,10 @@ int main(int argc, char** argv) {
|
||||
|
||||
if (cli.has("config"))
|
||||
conf.load(cli.get("config"), args[0]);
|
||||
else if (has_env("XDG_CONFIG_HOME"))
|
||||
conf.load(read_env("XDG_CONFIG_HOME") + "/polybar/config", args[0]);
|
||||
else if (has_env("HOME"))
|
||||
conf.load(read_env("HOME") + "/.config/polybar/config", args[0]);
|
||||
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"))
|
||||
conf.load(env_util::get("HOME") + "/.config/polybar/config", args[0]);
|
||||
else
|
||||
throw application_error("Define configuration using --config=PATH");
|
||||
|
||||
|
@ -1,12 +1,19 @@
|
||||
#include "modules/backlight.hpp"
|
||||
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "drawtypes/progressbar.hpp"
|
||||
#include "drawtypes/ramp.hpp"
|
||||
#include "utils/file.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/inotify_module.inl"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template class module<backlight_module>;
|
||||
template class inotify_module<backlight_module>;
|
||||
|
||||
void brightness_handle::filepath(string path) {
|
||||
if (!file_util::exists(path))
|
||||
throw module_error("The file '" + path + "' does not exist");
|
||||
|
@ -1,14 +1,22 @@
|
||||
#include "modules/battery.hpp"
|
||||
|
||||
#include "drawtypes/animation.hpp"
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "drawtypes/progressbar.hpp"
|
||||
#include "drawtypes/ramp.hpp"
|
||||
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/math.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/inotify_module.inl"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template class module<battery_module>;
|
||||
template class inotify_module<battery_module>;
|
||||
|
||||
/**
|
||||
* Bootstrap module by setting up required components
|
||||
*/
|
||||
@ -30,7 +38,7 @@ namespace modules {
|
||||
}
|
||||
|
||||
m_fullat = m_conf.get<int>(name(), "full-at", 100);
|
||||
m_interval = interval_t{m_conf.get<float>(name(), "poll-interval", 5.0f)};
|
||||
m_interval = chrono::duration<double>{m_conf.get<float>(name(), "poll-interval", 5.0f)};
|
||||
m_lastpoll = chrono::system_clock::now();
|
||||
|
||||
// Load state and capacity level
|
||||
|
@ -5,9 +5,15 @@
|
||||
#include "drawtypes/iconset.hpp"
|
||||
#include "drawtypes/label.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/event_module.inl"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template class module<bspwm_module>;
|
||||
template class event_module<bspwm_module>;
|
||||
|
||||
void bspwm_module::setup() { // {{{
|
||||
// Create ipc subscriber
|
||||
m_subscriber = bspwm_util::make_subscriber();
|
||||
|
@ -1,8 +1,14 @@
|
||||
#include "modules/counter.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/timer_module.inl"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template class module<counter_module>;
|
||||
template class timer_module<counter_module>;
|
||||
|
||||
void counter_module::setup() {
|
||||
m_interval = chrono::duration<double>(m_conf.get<float>(name(), "interval", 1));
|
||||
m_formatter->add(DEFAULT_FORMAT, TAG_COUNTER, {TAG_COUNTER});
|
||||
|
@ -1,12 +1,19 @@
|
||||
#include "modules/cpu.hpp"
|
||||
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "drawtypes/progressbar.hpp"
|
||||
#include "drawtypes/ramp.hpp"
|
||||
#include "utils/math.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/timer_module.inl"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template class module<cpu_module>;
|
||||
template class timer_module<cpu_module>;
|
||||
|
||||
void cpu_module::setup() {
|
||||
m_interval = chrono::duration<double>(m_conf.get<float>(name(), "interval", 1));
|
||||
|
||||
|
@ -1,8 +1,14 @@
|
||||
#include "modules/date.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/timer_module.inl"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template class module<date_module>;
|
||||
template class timer_module<date_module>;
|
||||
|
||||
void date_module::setup() {
|
||||
if (!m_bar.locale.empty())
|
||||
setlocale(LC_TIME, m_bar.locale.c_str());
|
||||
|
@ -1,16 +1,23 @@
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
#include "modules/fs.hpp"
|
||||
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "drawtypes/progressbar.hpp"
|
||||
#include "drawtypes/ramp.hpp"
|
||||
#include "modules/fs.hpp"
|
||||
#include "utils/math.hpp"
|
||||
#include "utils/mtab.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/timer_module.inl"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template class module<fs_module>;
|
||||
template class timer_module<fs_module>;
|
||||
|
||||
/**
|
||||
* Bootstrap the module by reading config values and
|
||||
* setting up required components
|
||||
|
@ -5,9 +5,15 @@
|
||||
#include "drawtypes/iconset.hpp"
|
||||
#include "drawtypes/label.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/event_module.inl"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template class module<i3_module>;
|
||||
template class event_module<i3_module>;
|
||||
|
||||
i3_workspace::operator bool() {
|
||||
return label && *label;
|
||||
}
|
||||
|
@ -1,9 +1,16 @@
|
||||
#include "modules/ipc.hpp"
|
||||
|
||||
#include "components/ipc.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/static_module.inl"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template class module<ipc_module>;
|
||||
template class static_module<ipc_module>;
|
||||
|
||||
/**
|
||||
* Load user-defined ipc hooks and
|
||||
* create formatting tags
|
||||
|
@ -1,10 +1,17 @@
|
||||
#include "modules/memory.hpp"
|
||||
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "drawtypes/progressbar.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/timer_module.inl"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template class module<memory_module>;
|
||||
template class timer_module<memory_module>;
|
||||
|
||||
void memory_module::setup() {
|
||||
m_interval = chrono::duration<double>(m_conf.get<float>(name(), "interval", 1));
|
||||
|
||||
|
@ -3,9 +3,15 @@
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "utils/scope.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/static_module.inl"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template class module<menu_module>;
|
||||
template class static_module<menu_module>;
|
||||
|
||||
void menu_module::setup() {
|
||||
string default_format{TAG_LABEL_TOGGLE + string{" "} + TAG_MENU};
|
||||
|
||||
|
97
src/modules/meta/base.cpp
Normal file
97
src/modules/meta/base.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
#include "components/builder.hpp"
|
||||
#include "modules/meta/base.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
// module_format {{{
|
||||
|
||||
string module_format::decorate(builder* builder, string output) {
|
||||
if (offset != 0)
|
||||
builder->offset(offset);
|
||||
if (margin > 0)
|
||||
builder->space(margin);
|
||||
if (!bg.empty())
|
||||
builder->background(bg);
|
||||
if (!fg.empty())
|
||||
builder->color(fg);
|
||||
if (!ul.empty())
|
||||
builder->underline(ul);
|
||||
if (!ol.empty())
|
||||
builder->overline(ol);
|
||||
if (padding > 0)
|
||||
builder->space(padding);
|
||||
|
||||
builder->append(output);
|
||||
|
||||
if (padding > 0)
|
||||
builder->space(padding);
|
||||
if (!ol.empty())
|
||||
builder->overline_close();
|
||||
if (!ul.empty())
|
||||
builder->underline_close();
|
||||
if (!fg.empty())
|
||||
builder->color_close();
|
||||
if (!bg.empty())
|
||||
builder->background_close();
|
||||
if (margin > 0)
|
||||
builder->space(margin);
|
||||
|
||||
return builder->flush();
|
||||
}
|
||||
|
||||
// }}}
|
||||
// module_formatter {{{
|
||||
|
||||
void module_formatter::add(string name, string fallback, vector<string>&& tags, vector<string>&& whitelist) {
|
||||
auto format = make_unique<module_format>();
|
||||
|
||||
format->value = m_conf.get<string>(m_modname, name, fallback);
|
||||
format->fg = m_conf.get<string>(m_modname, name + "-foreground", "");
|
||||
format->bg = m_conf.get<string>(m_modname, name + "-background", "");
|
||||
format->ul = m_conf.get<string>(m_modname, name + "-underline", "");
|
||||
format->ol = m_conf.get<string>(m_modname, name + "-overline", "");
|
||||
format->spacing = m_conf.get<int>(m_modname, name + "-spacing", DEFAULT_SPACING);
|
||||
format->padding = m_conf.get<int>(m_modname, name + "-padding", 0);
|
||||
format->margin = m_conf.get<int>(m_modname, name + "-margin", 0);
|
||||
format->offset = m_conf.get<int>(m_modname, name + "-offset", 0);
|
||||
format->tags.swap(tags);
|
||||
|
||||
for (auto&& tag : string_util::split(format->value, ' ')) {
|
||||
if (tag[0] != '<' || tag[tag.length() - 1] != '>')
|
||||
continue;
|
||||
if (find(format->tags.begin(), format->tags.end(), tag) != format->tags.end())
|
||||
continue;
|
||||
if (find(whitelist.begin(), whitelist.end(), tag) != whitelist.end())
|
||||
continue;
|
||||
throw undefined_format_tag("[" + m_modname + "] Undefined \"" + name + "\" tag: " + tag);
|
||||
}
|
||||
|
||||
m_formats.insert(make_pair(name, move(format)));
|
||||
}
|
||||
|
||||
bool module_formatter::has(string tag, string format_name) {
|
||||
auto format = m_formats.find(format_name);
|
||||
if (format == m_formats.end())
|
||||
throw undefined_format(format_name.c_str());
|
||||
return format->second->value.find(tag) != string::npos;
|
||||
}
|
||||
|
||||
bool module_formatter::has(string tag) {
|
||||
for (auto&& format : m_formats)
|
||||
if (format.second->value.find(tag) != string::npos)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
shared_ptr<module_format> module_formatter::get(string format_name) {
|
||||
auto format = m_formats.find(format_name);
|
||||
if (format == m_formats.end())
|
||||
throw undefined_format("Format \"" + format_name + "\" has not been added");
|
||||
return format->second;
|
||||
}
|
||||
|
||||
// }}}
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
104
src/modules/meta/inotify_module.cpp
Normal file
104
src/modules/meta/inotify_module.cpp
Normal file
@ -0,0 +1,104 @@
|
||||
#include "modules/meta/inotify_module.hpp"
|
||||
|
||||
#include "modules/backlight.hpp"
|
||||
#include "modules/battery.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
// public {{{
|
||||
|
||||
template <class Impl>
|
||||
void inotify_module<Impl>::start() {
|
||||
CAST_MOD(Impl)->m_mainthread = thread(&inotify_module::runner, this);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// protected {{{
|
||||
|
||||
template <class Impl>
|
||||
void inotify_module<Impl>::runner() {
|
||||
try {
|
||||
// Send initial broadcast to warmup cache
|
||||
if (CONST_MOD(Impl).running()) {
|
||||
CAST_MOD(Impl)->on_event(nullptr);
|
||||
CAST_MOD(Impl)->broadcast();
|
||||
}
|
||||
|
||||
while (CONST_MOD(Impl).running()) {
|
||||
CAST_MOD(Impl)->poll_events();
|
||||
}
|
||||
} catch (const module_error& err) {
|
||||
CAST_MOD(Impl)->halt(err.what());
|
||||
} catch (const std::exception& err) {
|
||||
CAST_MOD(Impl)->halt(err.what());
|
||||
}
|
||||
}
|
||||
|
||||
template <class Impl>
|
||||
void inotify_module<Impl>::watch(string path, int mask) {
|
||||
this->m_log.trace("%s: Attach inotify at %s", CONST_MOD(Impl).name(), path);
|
||||
m_watchlist.insert(make_pair(path, mask));
|
||||
}
|
||||
|
||||
template <class Impl>
|
||||
void inotify_module<Impl>::idle() {
|
||||
CAST_MOD(Impl)->sleep(200ms);
|
||||
}
|
||||
|
||||
template <class Impl>
|
||||
void inotify_module<Impl>::poll_events() {
|
||||
vector<inotify_util::watch_t> watches;
|
||||
|
||||
try {
|
||||
for (auto&& w : m_watchlist) {
|
||||
watches.emplace_back(inotify_util::make_watch(w.first));
|
||||
watches.back()->attach(w.second);
|
||||
}
|
||||
} catch (const system_error& e) {
|
||||
watches.clear();
|
||||
this->m_log.err("%s: Error while creating inotify watch (what: %s)", CONST_MOD(Impl).name(), e.what());
|
||||
CAST_MOD(Impl)->sleep(0.1s);
|
||||
return;
|
||||
}
|
||||
|
||||
while (CONST_MOD(Impl).running()) {
|
||||
std::unique_lock<concurrency_util::spin_lock> guard(this->m_lock);
|
||||
{
|
||||
for (auto&& w : watches) {
|
||||
this->m_log.trace_x("%s: Poll inotify watch %s", CONST_MOD(Impl).name(), w->path());
|
||||
|
||||
if (w->poll(1000 / watches.size())) {
|
||||
auto event = w->get_event();
|
||||
|
||||
for (auto&& w : watches) {
|
||||
try {
|
||||
w->remove();
|
||||
} catch (const system_error&) {
|
||||
}
|
||||
}
|
||||
|
||||
if (CAST_MOD(Impl)->on_event(event.get()))
|
||||
CAST_MOD(Impl)->broadcast();
|
||||
|
||||
CAST_MOD(Impl)->idle();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CONST_MOD(Impl).running())
|
||||
break;
|
||||
}
|
||||
}
|
||||
guard.unlock();
|
||||
CAST_MOD(Impl)->idle();
|
||||
}
|
||||
}
|
||||
|
||||
// }}}
|
||||
|
||||
template class inotify_module<backlight_module>;
|
||||
template class inotify_module<battery_module>;
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
@ -4,11 +4,17 @@
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "drawtypes/progressbar.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/event_module.inl"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
using namespace mpd;
|
||||
|
||||
namespace modules {
|
||||
template class module<mpd_module>;
|
||||
template class event_module<mpd_module>;
|
||||
|
||||
void mpd_module::setup() {
|
||||
m_host = m_conf.get<string>(name(), "host", m_host);
|
||||
m_port = m_conf.get<unsigned int>(name(), "port", m_port);
|
||||
|
@ -4,9 +4,15 @@
|
||||
#include "drawtypes/label.hpp"
|
||||
#include "drawtypes/ramp.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/timer_module.inl"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template class module<network_module>;
|
||||
template class timer_module<network_module>;
|
||||
|
||||
void network_module::setup() {
|
||||
// Load configuration values
|
||||
REQ_CONFIG_VALUE(name(), m_interface, "interface");
|
||||
@ -69,8 +75,8 @@ namespace modules {
|
||||
}
|
||||
|
||||
bool network_module::update() {
|
||||
net::network* network = m_wireless ? dynamic_cast<net::network*>(m_wireless.get())
|
||||
: dynamic_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);
|
||||
|
@ -1,8 +1,14 @@
|
||||
#include "modules/script.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/event_module.inl"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template class module<script_module>;
|
||||
template class event_module<script_module>;
|
||||
|
||||
void script_module::setup() {
|
||||
m_formatter->add(DEFAULT_FORMAT, TAG_OUTPUT, {TAG_OUTPUT});
|
||||
|
||||
@ -19,7 +25,7 @@ namespace modules {
|
||||
m_actions[mousebtn::SCROLL_UP] = m_conf.get<string>(name(), "scroll-up", "");
|
||||
m_actions[mousebtn::SCROLL_DOWN] = m_conf.get<string>(name(), "scroll-down", "");
|
||||
|
||||
m_interval = interval_t{m_conf.get<float>(name(), "interval", m_tail ? 0.0f : 2.0f)};
|
||||
m_interval = chrono::duration<double>{m_conf.get<float>(name(), "interval", m_tail ? 0.0f : 2.0f)};
|
||||
}
|
||||
|
||||
void script_module::stop() {
|
||||
|
@ -5,9 +5,15 @@
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/math.hpp"
|
||||
|
||||
#include "modules/meta/base.inl"
|
||||
#include "modules/meta/timer_module.inl"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace modules {
|
||||
template class module<temperature_module>;
|
||||
template class timer_module<temperature_module>;
|
||||
|
||||
void temperature_module::setup() {
|
||||
m_zone = m_conf.get<int>(name(), "thermal-zone", 0);
|
||||
m_tempwarn = m_conf.get<int>(name(), "warn-temperature", 80);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user