Compare commits

...

23 Commits

Author SHA1 Message Date
Chase Geigle
3f7b6c0e85 fix(plugin): Warn only for built plugins on a failed load. 2018-09-20 15:57:35 -05:00
Chase Geigle
e5f5fa59d2 refactor(plugin): Remove unused include. 2018-09-20 15:50:54 -05:00
Chase Geigle
01891e0567 refactor(plugin): Add missing braces to if statement. 2018-09-20 15:50:53 -05:00
Chase Geigle
d8687e2a3a refactor(controller): Use \brief instead of @brief for comment. 2018-09-20 15:50:53 -05:00
Chase Geigle
67835c9fb2 refactor(cmake): Add to net-src in modules CMakeLists. 2018-09-20 15:50:53 -05:00
Chase Geigle
0fbd5367b5 fix(tests): Link against shared modules library for builder test. 2018-09-20 15:50:53 -05:00
Chase Geigle
cd8b5be4c0 refactor(cmake): Add CMAKE_DL_LIBS to required lib list. 2018-09-20 15:50:53 -05:00
Chase Geigle
890abda4f7 fix(xkeyboard): Fix incorrect name for xkeyboard module. 2018-09-20 15:50:53 -05:00
Chase Geigle
0e08f47c5c fix(alsa): Add missing internal/volume alias. 2018-09-20 15:50:53 -05:00
Chase Geigle
ce6ac7869e refactor(cmake): Use a source list instead of static libs 2018-09-20 15:50:52 -05:00
Chase Geigle
95588a2c21 fix(gcc): Build all components directly into polybar executable
gcc-5 seemed to be having issues trying to link with the components
separated out into a separate static library, so for now it's easier to
just fall back on building all components together with main.cpp.
2018-09-20 15:50:52 -05:00
Chase Geigle
455e8c5596 fix(plugin): Use extern vector for list of plugin names. 2018-09-20 15:50:52 -05:00
Chase Geigle
0ba1732d59 fix(restack): Avoid double-free on exit with restackers.
Switch to maintaining a singleton in each restacker's shared library to
avoid creating memory in one DSO and freeing it in another.
2018-09-20 15:50:52 -05:00
Chase Geigle
e374dd467e fix(restack): Add missing virtual dstructor to wm_restacker. 2018-09-20 15:50:52 -05:00
Chase Geigle
cb0a351404 fix(cmake): Enable -fPIC for static jsoncpp. 2018-09-20 15:50:52 -05:00
Chase Geigle
6ff04022c4 fix(cmake): Add missing xpp dependencies
This is a spurious failure: it only fails out if the xpp headers aren't
generated before the drawtypes, modules, or utils directories begin
building. By depending on xpp explicitly, this ensures that xpp's
headers are generated first.
2018-09-20 15:50:52 -05:00
Chase Geigle
42fda5b105 feat(plugin): Add initial draft plugin architecture.
Modules and other features that require optional libraries are now
dynamically loaded on the construction of the controller via dlopen().
This allows polybar to be built with support for all of the features on
one machine, but gracefully fall back and disable those features on
machines where the required optional shared libraries are not found.
2018-09-20 15:50:51 -05:00
Chase Geigle
15e444abe7 fix(cairo): Silence possibly uninitialized variable warning. 2018-09-20 15:50:51 -05:00
Chase Geigle
7b042a6466 feat(cmake): Add MODULE library type to make_library. 2018-09-20 15:50:51 -05:00
Chase Geigle
61dba1b2dc refactor(modules): Use self-registration for modules. 2018-09-20 15:50:51 -05:00
Chase Geigle
9bccdee394 feat(cmake): add INTERNAL type for make_library
This will allow us to make internal static libraries that can be shared
across components that are not targets for installation.
2018-09-20 15:50:51 -05:00
Chase Geigle
a5fff81368 refactor(cmake): Build modules with lib deps as shared libraries 2018-09-20 15:50:51 -05:00
Chase Geigle
b31226ffcc refactor(cmake): Break out adapters into static libs
Each adapter now links against the shared libraries it requires, and the
polybar executable inherits these through linking to them via
TARGET_DEPS.
2018-09-20 15:50:51 -05:00
49 changed files with 651 additions and 236 deletions

View File

@@ -4,22 +4,22 @@
find_package(Threads REQUIRED)
list(APPEND libs ${CMAKE_THREAD_LIBS_INIT})
list(APPEND libs ${CMAKE_DL_LIBS})
querylib(TRUE "pkg-config" cairo-fc libs dirs)
querylib(ENABLE_ALSA "pkg-config" alsa libs dirs)
querylib(ENABLE_CURL "pkg-config" libcurl libs dirs)
querylib(ENABLE_MPD "pkg-config" libmpdclient libs dirs)
querylib(ENABLE_ALSA "pkg-config" alsa alsa-libs alsa-dirs)
querylib(ENABLE_CURL "pkg-config" libcurl curl-libs curl-dirs)
querylib(ENABLE_MPD "pkg-config" libmpdclient mpd-libs mpd-dirs)
if(WITH_LIBNL)
querylib(ENABLE_NETWORK "pkg-config" libnl-genl-3.0 libs dirs)
querylib(ENABLE_NETWORK "pkg-config" libnl-genl-3.0 net-libs net-dirs)
else()
querylib(ENABLE_NETWORK "cmake" Libiw libs dirs)
querylib(ENABLE_NETWORK "cmake" Libiw net-libs net-dirs)
endif()
querylib(ENABLE_PULSEAUDIO "pkg-config" libpulse libs dirs)
querylib(ENABLE_PULSEAUDIO "pkg-config" libpulse pulse-libs pulse-dirs)
querylib(WITH_XCOMPOSITE "pkg-config" xcb-composite libs dirs)
querylib(WITH_XDAMAGE "pkg-config" xcb-damage libs dirs)
querylib(WITH_XKB "pkg-config" xcb-xkb libs dirs)
querylib(WITH_XKB "pkg-config" xcb-xkb xkb-libs xkb-dirs)
querylib(WITH_XRANDR "pkg-config" xcb-randr libs dirs)
querylib(WITH_XRANDR_MONITORS "pkg-config" "xcb-randr>=1.12" libs dirs)
querylib(WITH_XRENDER "pkg-config" xcb-render libs dirs)

View File

@@ -88,7 +88,7 @@ endfunction()
# make_library {{{
function(make_library target_name)
set(zero_value_args SHARED STATIC)
set(zero_value_args SHARED STATIC INTERNAL MODULE)
set(one_value_args PACKAGE HEADER_INSTALL_DIR)
set(multi_value_args SOURCES HEADERS INCLUDE_DIRS PKG_DEPENDS CMAKE_DEPENDS TARGET_DEPENDS RAW_DEPENDS)
@@ -101,13 +101,6 @@ function(make_library target_name)
set(LIB_HEADERS_ABS ${LIB_HEADERS_ABS} ${PROJECT_SOURCE_DIR}/include/${HEADER})
endforeach()
# add defined INCLUDE_DIRS
foreach(DIR ${LIB_INCLUDE_DIRS})
string(TOUPPER ${DIR} DIR)
include_directories(${DIR})
include_directories(${${DIR}_INCLUDE_DIRS})
endforeach()
# add INCLUDE_DIRS for all external dependencies
foreach(DEP ${LIB_TARGET_DEPENDS} ${LIB_PKG_DEPENDS} ${LIB_CMAKE_DEPENDS})
string(TOUPPER ${DEP} DEP)
@@ -120,12 +113,31 @@ function(make_library target_name)
if(LIB_STATIC)
list(APPEND library_targets ${target_name}_static)
endif()
if(LIB_MODULE)
list(APPEND library_targets ${target_name}_module)
endif()
foreach(library_target_name ${library_targets})
message(STATUS "${library_target_name}")
add_library(${library_target_name}
${LIB_HEADERS_ABS}
${LIB_SOURCES})
if(library_target_name MATCHES "_shared$")
add_library(${library_target_name}
SHARED
${LIB_HEADERS_ABS}
${LIB_SOURCES})
elseif(library_target_name MATCHES "_module$")
add_library(${library_target_name}
MODULE
${LIB_HEADERS_ABS}
${LIB_SOURCES})
else()
add_library(${library_target_name}
${LIB_HEADERS_ABS}
${LIB_SOURCES})
endif()
# add defined INCLUDE_DIRS
target_include_directories(${library_target_name} PRIVATE ${LIB_INCLUDE_DIRS})
# link libraries from pkg-config imports
foreach(DEP ${LIB_PKG_DEPENDS})
@@ -153,29 +165,42 @@ function(make_library target_name)
endif()
endforeach()
if(${LIB_RAW_DEPENDS})
if(LIB_BUILD_STATIC)
target_link_libraries(${library_target_name} ${LIB_RAW_DEPENDS})
endif()
if(LIB_RAW_DEPENDS)
target_link_libraries(${library_target_name} ${LIB_RAW_DEPENDS})
endif()
# set the output file basename
set_target_properties(${library_target_name} PROPERTIES OUTPUT_NAME ${target_name})
# install headers
install(FILES ${LIBRARY_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${LIB_HEADERS_ABS})
# set output file folder
set_target_properties(${library_target_name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
# install targets
install(TARGETS ${LIBRARY_TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library)
if(NOT LIB_INTERNAL)
# install headers
install(FILES ${LIB_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${LIB_HEADERS_ABS})
# install targets
install(TARGETS ${library_targets}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library)
endif()
endforeach()
endfunction()
# }}}
# add_sources {{{
macro(add_sources varname)
foreach(SRC ${ARGN})
list(APPEND ${varname} ${CMAKE_CURRENT_SOURCE_DIR}/${SRC})
endforeach()
set(${varname} ${${varname}} PARENT_SCOPE)
endmacro()
# }}}
# queryfont {{{
function(queryfont output_variable fontname)

View File

@@ -158,7 +158,7 @@ namespace cairo {
while (!chars.empty()) {
auto remaining = chars.size();
for (auto&& f : fns) {
unsigned int matches;
unsigned int matches = 0;
// Match as many glyphs as possible if the default/preferred font
// is being tested. Otherwise test one glyph at a time against

View File

@@ -1,5 +1,6 @@
#pragma once
#include <list>
#include <moodycamel/blockingconcurrentqueue.h>
#include <thread>
@@ -9,6 +10,7 @@
#include "events/signal_receiver.hpp"
#include "events/types.hpp"
#include "utils/file.hpp"
#include "utils/plugin.hpp"
#include "x11/types.hpp"
POLYBAR_NS
@@ -142,6 +144,11 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, signals::eve
* @brief Misc threads
*/
vector<std::thread> m_threads;
/**
* \brief Loaded plugins
*/
std::list<plugin_handle> m_plugins;
};
POLYBAR_NS_END

View File

@@ -1,115 +1,31 @@
#pragma once
#include "common.hpp"
#include "modules/backlight.hpp"
#include "modules/battery.hpp"
#include "modules/bspwm.hpp"
#include "modules/counter.hpp"
#include "modules/cpu.hpp"
#include "modules/date.hpp"
#include "modules/fs.hpp"
#include "modules/ipc.hpp"
#include "modules/memory.hpp"
#include "modules/menu.hpp"
#include "modules/meta/base.hpp"
#include "modules/script.hpp"
#if DEBUG
#include "modules/systray.hpp"
#endif
#include "modules/temperature.hpp"
#include "modules/text.hpp"
#include "modules/xbacklight.hpp"
#include "modules/xwindow.hpp"
#include "modules/xworkspaces.hpp"
#if ENABLE_I3
#include "modules/i3.hpp"
#endif
#if ENABLE_MPD
#include "modules/mpd.hpp"
#endif
#if ENABLE_NETWORK
#include "modules/network.hpp"
#endif
#if ENABLE_ALSA
#include "modules/alsa.hpp"
#endif
#if ENABLE_PULSEAUDIO
#include "modules/pulseaudio.hpp"
#endif
#if ENABLE_CURL
#include "modules/github.hpp"
#endif
#if ENABLE_XKEYBOARD
#include "modules/xkeyboard.hpp"
#endif
#if not(ENABLE_I3 && ENABLE_MPD && ENABLE_NETWORK && ENABLE_ALSA && ENABLE_PULSEAUDIO && ENABLE_CURL && ENABLE_XKEYBOARD)
#include "modules/unsupported.hpp"
#endif
POLYBAR_NS
using namespace modules;
namespace modules {
namespace {
module_interface* make_module(string&& name, const bar_settings& bar, string module_name, const logger& m_log) {
if (name == "internal/counter") {
return new counter_module(bar, move(module_name));
} else if (name == "internal/backlight") {
return new backlight_module(bar, move(module_name));
} else if (name == "internal/battery") {
return new battery_module(bar, move(module_name));
} else if (name == "internal/bspwm") {
return new bspwm_module(bar, move(module_name));
} else if (name == "internal/cpu") {
return new cpu_module(bar, move(module_name));
} else if (name == "internal/date") {
return new date_module(bar, move(module_name));
} else if (name == "internal/github") {
return new github_module(bar, move(module_name));
} else if (name == "internal/fs") {
return new fs_module(bar, move(module_name));
} else if (name == "internal/memory") {
return new memory_module(bar, move(module_name));
} else if (name == "internal/i3") {
return new i3_module(bar, move(module_name));
} else if (name == "internal/mpd") {
return new mpd_module(bar, move(module_name));
} else if (name == "internal/volume") {
m_log.warn("internal/volume is deprecated, use internal/alsa instead");
return new alsa_module(bar, move(module_name));
} else if (name == "internal/alsa") {
return new alsa_module(bar, move(module_name));
} else if (name == "internal/pulseaudio") {
return new pulseaudio_module(bar, move(module_name));
} else if (name == "internal/network") {
return new network_module(bar, move(module_name));
#if DEBUG
} else if (name == "internal/systray") {
return new systray_module(bar, move(module_name));
#endif
} else if (name == "internal/temperature") {
return new temperature_module(bar, move(module_name));
} else if (name == "internal/xbacklight") {
return new xbacklight_module(bar, move(module_name));
} else if (name == "internal/xkeyboard") {
return new xkeyboard_module(bar, move(module_name));
} else if (name == "internal/xwindow") {
return new xwindow_module(bar, move(module_name));
} else if (name == "internal/xworkspaces") {
return new xworkspaces_module(bar, move(module_name));
} else if (name == "custom/text") {
return new text_module(bar, move(module_name));
} else if (name == "custom/script") {
return new script_module(bar, move(module_name));
} else if (name == "custom/menu") {
return new menu_module(bar, move(module_name));
} else if (name == "custom/ipc") {
return new ipc_module(bar, move(module_name));
} else {
throw application_error("Unknown module: " + name);
using factory_function = module_interface* (*)(const bar_settings&, string, const logger&);
using factory_map = std::unordered_map<string, factory_function>;
factory_map& get_factory_map();
template <class Module>
class module_registration {
public:
module_registration(string name, factory_function ff) {
get_factory_map()[std::move(name)] = ff;
}
}
}
};
module_interface* make_module(string&& name, const bar_settings& bar, string module_name, const logger& m_log);
} // namespace modules
#define POLYBAR_MODULE(MODULE_TYPE, MODULE_NAME) \
module_interface* MODULE_TYPE##_create(const bar_settings& bar, std::string module_name, const logger&) { \
return new MODULE_TYPE(bar, std::move(module_name)); \
} \
module_registration<MODULE_TYPE> MODULE_TYPE##_registration(MODULE_NAME, &MODULE_TYPE##_create)
POLYBAR_NS_END

25
include/utils/plugin.hpp Normal file
View File

@@ -0,0 +1,25 @@
#pragma once
#include "common.hpp"
#include "components/logger.hpp"
POLYBAR_NS
class plugin_handle {
public:
plugin_handle(const char* libname);
~plugin_handle();
plugin_handle(const plugin_handle&) = delete;
plugin_handle& operator=(const plugin_handle&) = delete;
plugin_handle(plugin_handle&&);
plugin_handle& operator=(plugin_handle&&);
private:
void* m_handle = nullptr;
};
extern std::vector<const char*> plugin_names;
POLYBAR_NS_END

44
include/utils/restack.hpp Normal file
View File

@@ -0,0 +1,44 @@
#pragma once
#include <unordered_map>
#include "common.hpp"
#include "components/types.hpp"
#include "x11/extensions/randr.hpp"
POLYBAR_NS
class connection;
class logger;
namespace restack {
struct wm_restacker {
virtual void operator()(connection& conn, const bar_settings& opts, const logger& log) const = 0;
virtual ~wm_restacker() = default;
};
using factory_function = const wm_restacker& (*)();
using restacker_map = std::unordered_map<std::string, factory_function>;
restacker_map& get_restacker_map();
const wm_restacker* get_restacker(const std::string& name);
template <class Restacker>
struct restacker_registration {
restacker_registration(std::string name, factory_function ff) {
get_restacker_map()[std::move(name)] = ff;
}
};
#define POLYBAR_RESTACKER(RESTACKER_TYPE, RESTACKER_NAME) \
const wm_restacker& get_##RESTACKER_TYPE() {\
static RESTACKER_TYPE local_restacker;\
return local_restacker;\
}\
restacker_registration<RESTACKER_TYPE> RESTACKER_TYPE##_registration(RESTACKER_NAME, &get_##RESTACKER_TYPE)
} // namespace restack
POLYBAR_NS_END

View File

@@ -39,8 +39,12 @@ list(APPEND dirs ${XPP_INCLUDE_DIRS})
if(ENABLE_I3)
add_subdirectory(i3ipcpp)
list(APPEND libs ${I3IPCPP_LIBRARIES})
list(APPEND dirs ${I3IPCPP_INCLUDE_DIRS})
set_property(TARGET i3ipc++ PROPERTY POSITION_INDEPENDENT_CODE ON)
if(TARGET jsoncpp_lib_static)
set_property(TARGET jsoncpp_lib_static PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
set(I3IPCPP_LIBRARIES ${I3IPCPP_LIBRARIES} PARENT_SCOPE)
set(I3IPCPP_INCLUDE_DIRS ${I3IPCPP_INCLUDE_DIRS} PARENT_SCOPE)
endif()
# }}}

View File

@@ -2,68 +2,16 @@
# Configure src
#
# Source tree {{{
file(GLOB_RECURSE files RELATIVE ${CMAKE_CURRENT_LIST_DIR} *.c[p]*)
list(REMOVE_ITEM files ipc.cpp)
if(NOT ENABLE_ALSA)
list(REMOVE_ITEM files modules/alsa.cpp)
list(REMOVE_ITEM files adapters/alsa/control.cpp)
list(REMOVE_ITEM files adapters/alsa/mixer.cpp)
endif()
if(NOT ENABLE_CURL)
list(REMOVE_ITEM files modules/github.cpp)
list(REMOVE_ITEM files utils/http.cpp)
endif()
if(NOT ENABLE_MPD)
list(REMOVE_ITEM files modules/mpd.cpp)
list(REMOVE_ITEM files adapters/mpd.cpp)
endif()
if(NOT ENABLE_NETWORK)
list(REMOVE_ITEM files modules/network.cpp)
list(REMOVE_ITEM files adapters/net.cpp)
list(REMOVE_ITEM files adapters/net_iw.cpp)
list(REMOVE_ITEM files adapters/net_nl.cpp)
endif()
if(WITH_LIBNL)
list(REMOVE_ITEM files adapters/net_iw.cpp)
else()
list(REMOVE_ITEM files adapters/net_nl.cpp)
endif()
if(NOT ENABLE_I3)
list(REMOVE_ITEM files modules/i3.cpp)
list(REMOVE_ITEM files utils/i3.cpp)
endif()
if(NOT ENABLE_PULSEAUDIO)
list(REMOVE_ITEM files modules/pulseaudio.cpp)
list(REMOVE_ITEM files adapters/pulseaudio.cpp)
endif()
if(NOT WITH_XRANDR)
list(REMOVE_ITEM files x11/extensions/randr.cpp)
endif()
if(NOT WITH_XRENDER)
list(REMOVE_ITEM files x11/extensions/render.cpp)
endif()
if(NOT WITH_XDAMAGE)
list(REMOVE_ITEM files x11/extensions/damage.cpp)
endif()
if(NOT WITH_XSYNC)
list(REMOVE_ITEM files x11/extensions/sync.cpp)
endif()
if(NOT WITH_XCOMPOSITE)
list(REMOVE_ITEM files x11/extensions/composite.cpp)
endif()
if(NOT WITH_XKB)
list(REMOVE_ITEM files x11/extensions/xkb.cpp)
list(REMOVE_ITEM files modules/xkeyboard.cpp)
endif()
if(NOT WITH_XRM)
list(REMOVE_ITEM files x11/xresources.cpp)
endif()
if(NOT WITH_XCURSOR)
list(REMOVE_ITEM files x11/cursor.cpp)
endif()
add_subdirectory(cairo)
add_subdirectory(components)
add_subdirectory(drawtypes)
add_subdirectory(events)
add_subdirectory(modules)
add_subdirectory(utils)
add_subdirectory(x11)
# }}}
@@ -71,9 +19,12 @@ endif()
make_executable(polybar
SOURCES
main.cpp
${files}
INCLUDE_DIRS
${dirs}
TARGET_DEPENDS
polybar-modules-internal_shared
RAW_DEPENDS
${libs}
Threads::Threads)

1
src/cairo/CMakeLists.txt Normal file
View File

@@ -0,0 +1 @@
add_sources(files utils.cpp)

View File

@@ -0,0 +1,12 @@
add_sources(files
bar.cpp
builder.cpp
command_line.cpp
config.cpp
controller.cpp
ipc.cpp
logger.cpp
parser.cpp
renderer.cpp
screen.cpp
taskqueue.cpp)

View File

@@ -9,7 +9,7 @@
#include "components/types.hpp"
#include "events/signal.hpp"
#include "events/signal_emitter.hpp"
#include "utils/bspwm.hpp"
#include "utils/restack.hpp"
#include "utils/color.hpp"
#include "utils/factory.hpp"
#include "utils/math.hpp"
@@ -25,10 +25,6 @@
#include "x11/cursor.hpp"
#endif
#if ENABLE_I3
#include "utils/i3.hpp"
#endif
POLYBAR_NS
using namespace signals::ui;
@@ -437,26 +433,10 @@ void bar::restack_window() {
return;
}
auto restacked = false;
if (wm_restack == "bspwm") {
restacked = bspwm_util::restack_to_root(m_connection, m_opts.monitor, m_opts.window);
#if ENABLE_I3
} else if (wm_restack == "i3" && m_opts.override_redirect) {
restacked = i3_util::restack_to_root(m_connection, m_opts.window);
} else if (wm_restack == "i3" && !m_opts.override_redirect) {
m_log.warn("Ignoring restack of i3 window (not needed when `override-redirect = false`)");
wm_restack.clear();
#endif
if (auto restacker = restack::get_restacker(wm_restack)) {
(*restacker)(m_connection, m_opts, m_log);
} else {
m_log.warn("Ignoring unsupported wm-restack option '%s'", wm_restack);
wm_restack.clear();
}
if (restacked) {
m_log.info("Successfully restacked bar window");
} else if (!wm_restack.empty()) {
m_log.err("Failed to restack bar window");
}
}

View File

@@ -8,11 +8,14 @@
#include "components/types.hpp"
#include "events/signal.hpp"
#include "events/signal_emitter.hpp"
#include "modules/ipc.hpp"
#include "modules/meta/event_handler.hpp"
#include "modules/meta/factory.hpp"
#include "modules/meta/input_handler.hpp"
#include "utils/command.hpp"
#include "utils/factory.hpp"
#include "utils/inotify.hpp"
#include "utils/plugin.hpp"
#include "utils/string.hpp"
#include "utils/time.hpp"
#include "x11/connection.hpp"
@@ -74,6 +77,17 @@ controller::controller(connection& conn, signal_emitter& emitter, const logger&
sigaction(SIGUSR1, &act, nullptr);
sigaction(SIGALRM, &act, nullptr);
m_log.trace("controller: Load plugins");
for (const auto name : plugin_names) {
if (name) {
try {
m_plugins.emplace_back(name);
} catch (const application_error& err) {
m_log.warn("Failed to load plugin '%s': %s", name, err.what());
}
}
}
m_log.trace("controller: Setup user-defined modules");
size_t created_modules{0};
@@ -101,7 +115,7 @@ controller::controller(connection& conn, signal_emitter& emitter, const logger&
throw application_error("Inter-process messaging needs to be enabled");
}
m_modules[align].emplace_back(make_module(move(type), m_bar->settings(), module_name, m_log));
m_modules[align].emplace_back(modules::make_module(move(type), m_bar->settings(), module_name, m_log));
created_modules++;
} catch (const runtime_error& err) {
m_log.err("Disabling module \"%s\" (reason: %s)", module_name, err.what());
@@ -163,8 +177,8 @@ bool controller::run(bool writeback, string snapshot_dst) {
size_t started_modules{0};
for (const auto& block : m_modules) {
for (const auto& module : block.second) {
auto inp_handler = dynamic_cast<input_handler*>(&*module);
auto evt_handler = dynamic_cast<event_handler_interface*>(&*module);
auto inp_handler = dynamic_cast<modules::input_handler*>(&*module);
auto evt_handler = dynamic_cast<modules::event_handler_interface*>(&*module);
if (inp_handler != nullptr) {
m_inputhandlers.emplace_back(inp_handler);
@@ -273,8 +287,7 @@ void controller::read_events() {
int events = select(maxfd + 1, &readfds, nullptr, nullptr, nullptr);
// Check for errors
if (events == -1) {
if (events == -1) {
/*
* The Interrupt errno is generated when polybar is stopped, so it
* shouldn't generate an error message
@@ -676,7 +689,7 @@ bool controller::on(const signals::ipc::hook& evt) {
if (!module->running()) {
continue;
}
auto ipc = dynamic_cast<ipc_module*>(module.get());
auto ipc = dynamic_cast<modules::ipc_module*>(module.get());
if (ipc != nullptr) {
ipc->on_message(hook);
}

View File

@@ -0,0 +1,6 @@
add_sources(files
animation.cpp
iconset.cpp
label.cpp
progressbar.cpp
ramp.cpp)

View File

@@ -0,0 +1,3 @@
add_sources(files
signal_emitter.cpp
signal_receiver.cpp)

128
src/modules/CMakeLists.txt Normal file
View File

@@ -0,0 +1,128 @@
if(ENABLE_ALSA)
make_library(polybar-modules-alsa
MODULE
SOURCES
../adapters/alsa/control.cpp
../adapters/alsa/mixer.cpp
alsa.cpp
INCLUDE_DIRS
${dirs}
${alsa-dirs}
RAW_DEPENDS
${libs}
${alsa-libs})
endif()
if(ENABLE_CURL)
make_library(polybar-modules-github
MODULE
SOURCES
../utils/http.cpp
github.cpp
INCLUDE_DIRS
${dirs}
${curl-dirs}
RAW_DEPENDS
${libs}
${curl-libs})
endif()
if(ENABLE_MPD)
make_library(polybar-modules-mpd
MODULE
SOURCES
../adapters/mpd.cpp
mpd.cpp
INCLUDE_DIRS
${dirs}
${mpd-dirs}
RAW_DEPENDS
${libs}
${mpd-libs})
endif()
if(ENABLE_NETWORK)
list(APPEND net-src ../adapters/net.cpp network.cpp)
if(WITH_LIBNL)
list(APPEND net-src ../adapters/net_nl.cpp)
else()
list(APPEND net-src ../adapters/net_iw.cpp)
endif()
make_library(polybar-modules-network
MODULE
SOURCES
${net-src}
INCLUDE_DIRS
${dirs}
${net-dirs}
RAW_DEPENDS
${libs}
${net-libs})
endif()
if(ENABLE_I3)
make_library(polybar-modules-i3
MODULE
SOURCES
i3.cpp
INCLUDE_DIRS
${dirs}
${I3IPCPP_INCLUDE_DIRS}
RAW_DEPENDS
${libs})
endif()
if(ENABLE_PULSEAUDIO)
make_library(polybar-modules-pulseaudio
MODULE
SOURCES
../adapters/pulseaudio.cpp
pulseaudio.cpp
INCLUDE_DIRS
${dirs}
${pulse-dirs}
RAW_DEPENDS
${libs}
${pulse-libs})
endif()
if(WITH_XKB)
make_library(polybar-modules-xkeyboard
MODULE
SOURCES
../x11/extensions/xkb.cpp
xkeyboard.cpp
INCLUDE_DIRS
${dirs}
${xkb-dirs}
RAW_DEPENDS
${libs}
${xkb-libs})
endif()
make_library(polybar-modules-internal
SHARED
SOURCES
backlight.cpp
battery.cpp
bspwm.cpp
counter.cpp
cpu.cpp
date.cpp
fs.cpp
ipc.cpp
memory.cpp
menu.cpp
meta/base.cpp
meta/factory.cpp
script.cpp
systray.cpp
temperature.cpp
text.cpp
xbacklight.cpp
xwindow.cpp
xworkspaces.cpp
INCLUDE_DIRS
${dirs}
RAW_DEPENDS
${libs})

View File

@@ -1,10 +1,11 @@
#include "modules/alsa.hpp"
#include "adapters/alsa/control.hpp"
#include "adapters/alsa/generic.hpp"
#include "adapters/alsa/mixer.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
#include "drawtypes/ramp.hpp"
#include "modules/alsa.hpp"
#include "modules/meta/factory.hpp"
#include "utils/math.hpp"
#include "modules/meta/base.inl"
@@ -18,6 +19,14 @@ using namespace alsa;
namespace modules {
template class module<alsa_module>;
POLYBAR_MODULE(alsa_module, "internal/alsa");
module_interface* volume_module_create(const bar_settings& bar, std::string module_name, const logger& m_log) {
m_log.warn("internal/volume is deprecated, use internal/alsa instead");
return alsa_module_create(bar, std::move(module_name), m_log);
}
module_registration<alsa_module> volume_module_registration("internal/volume", &volume_module_create);
alsa_module::alsa_module(const bar_settings& bar, string name_) : event_module<alsa_module>(bar, move(name_)) {
// Load configuration values
m_mapped = m_conf.get(name(), "mapped", m_mapped);

View File

@@ -6,12 +6,15 @@
#include "utils/file.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<backlight_module>;
POLYBAR_MODULE(backlight_module, "internal/backlight");
void backlight_module::brightness_handle::filepath(const string& path) {
if (!file_util::exists(path)) {
throw module_error("The file '" + path + "' does not exist");

View File

@@ -8,12 +8,15 @@
#include "utils/string.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<battery_module>;
POLYBAR_MODULE(battery_module, "internal/battery");
template <typename ValueReader>
typename ValueReader::return_type read(ValueReader& reader) {
std::lock_guard<ValueReader> guard(reader);

View File

@@ -8,6 +8,7 @@
#include "utils/string.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
@@ -40,6 +41,8 @@ namespace {
namespace modules {
template class module<bspwm_module>;
POLYBAR_MODULE(bspwm_module, "internal/bspwm");
bspwm_module::bspwm_module(const bar_settings& bar, string name_) : event_module<bspwm_module>(bar, move(name_)) {
auto socket_path = bspwm_util::get_socket_path();

View File

@@ -1,12 +1,15 @@
#include "modules/counter.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<counter_module>;
POLYBAR_MODULE(counter_module, "internal/counter");
counter_module::counter_module(const bar_settings& bar, string name_)
: timer_module<counter_module>(bar, move(name_)) {
m_interval = m_conf.get(name(), "interval", m_interval);

View File

@@ -9,12 +9,15 @@
#include "utils/math.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<cpu_module>;
POLYBAR_MODULE(cpu_module, "internal/cpu");
cpu_module::cpu_module(const bar_settings& bar, string name_) : timer_module<cpu_module>(bar, move(name_)) {
m_interval = m_conf.get<decltype(m_interval)>(name(), "interval", 1s);

View File

@@ -2,12 +2,15 @@
#include "drawtypes/label.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<date_module>;
POLYBAR_MODULE(date_module, "internal/date");
date_module::date_module(const bar_settings& bar, string name_) : timer_module<date_module>(bar, move(name_)) {
if (!m_bar.locale.empty()) {
datetime_stream.imbue(std::locale(m_bar.locale.c_str()));

View File

@@ -10,6 +10,7 @@
#include "utils/string.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
@@ -21,6 +22,8 @@ POLYBAR_NS
namespace modules {
template class module<fs_module>;
POLYBAR_MODULE(fs_module, "internal/fs");
/**
* Bootstrap the module by reading config values and
* setting up required components

View File

@@ -5,12 +5,15 @@
#include "utils/concurrency.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<github_module>;
POLYBAR_MODULE(github_module, "internal/github");
/**
* Construct module
*/

View File

@@ -7,12 +7,15 @@
#include "utils/file.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<i3_module>;
POLYBAR_MODULE(i3_module, "internal/i3");
i3_module::i3_module(const bar_settings& bar, string name_) : event_module<i3_module>(bar, move(name_)) {
auto socket_path = i3ipc::get_socketpath();

View File

@@ -2,12 +2,15 @@
#include "components/ipc.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<ipc_module>;
POLYBAR_MODULE(ipc_module, "custom/ipc");
/**
* Load user-defined ipc hooks and
* create formatting tags

View File

@@ -9,12 +9,15 @@
#include "utils/math.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<memory_module>;
POLYBAR_MODULE(memory_module, "internal/memory");
memory_module::memory_module(const bar_settings& bar, string name_) : timer_module<memory_module>(bar, move(name_)) {
m_interval = m_conf.get<decltype(m_interval)>(name(), "interval", 1s);

View File

@@ -5,12 +5,15 @@
#include "utils/scope.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<menu_module>;
POLYBAR_MODULE(menu_module, "custom/menu");
menu_module::menu_module(const bar_settings& bar, string name_) : static_module<menu_module>(bar, move(name_)) {
m_expand_right = m_conf.get(name(), "expand-right", m_expand_right);

View File

@@ -0,0 +1,24 @@
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
factory_map& get_factory_map() {
static factory_map fmap;
return fmap;
}
module_interface* make_module(string&& name, const bar_settings& bar, string module_name, const logger& m_log) {
const auto& fmap = get_factory_map();
auto it = fmap.find(name);
if (it != fmap.end()) {
return it->second(bar, move(module_name), m_log);
} else {
throw application_error("Unknown module: " + name);
}
}
} // namespace modules
POLYBAR_NS_END

View File

@@ -7,12 +7,15 @@
#include "utils/factory.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<mpd_module>;
POLYBAR_MODULE(mpd_module, "internal/mpd");
mpd_module::mpd_module(const bar_settings& bar, string name_) : event_module<mpd_module>(bar, move(name_)) {
m_host = m_conf.get(name(), "host", m_host);
m_port = m_conf.get(name(), "port", m_port);

View File

@@ -6,12 +6,15 @@
#include "utils/factory.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<network_module>;
POLYBAR_MODULE(network_module, "internal/network");
network_module::network_module(const bar_settings& bar, string name_)
: timer_module<network_module>(bar, move(name_)) {
// Load configuration values

View File

@@ -6,6 +6,7 @@
#include "utils/math.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
#include "settings.hpp"
@@ -14,6 +15,8 @@ POLYBAR_NS
namespace modules {
template class module<pulseaudio_module>;
POLYBAR_MODULE(pulseaudio_module, "internal/pulseaudio");
pulseaudio_module::pulseaudio_module(const bar_settings& bar, string name_) : event_module<pulseaudio_module>(bar, move(name_)) {
// Load configuration values
m_interval = m_conf.get(name(), "interval", m_interval);

View File

@@ -1,12 +1,15 @@
#include "modules/script.hpp"
#include "drawtypes/label.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<script_module>;
POLYBAR_MODULE(script_module, "custom/script");
/**
* Construct script module by loading configuration values
* and setting up formatting objects

View File

@@ -5,12 +5,17 @@
#include "x11/tray_manager.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<systray_module>;
#if DEBUG
POLYBAR_MODULE(systray_module, "internal/systray");
#endif
/**
* Construct module
*/

View File

@@ -7,12 +7,15 @@
#include <cmath>
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<temperature_module>;
POLYBAR_MODULE(temperature_module, "internal/temperature");
temperature_module::temperature_module(const bar_settings& bar, string name_)
: timer_module<temperature_module>(bar, move(name_)) {
m_zone = m_conf.get(name(), "thermal-zone", 0);

View File

@@ -1,12 +1,15 @@
#include "modules/text.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<text_module>;
POLYBAR_MODULE(text_module, "custom/text");
text_module::text_module(const bar_settings& bar, string name_) : static_module<text_module>(bar, move(name_)) {
m_formatter->add("content", "", {});

View File

@@ -7,12 +7,15 @@
#include "x11/winspec.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<xbacklight_module>;
POLYBAR_MODULE(xbacklight_module, "internal/xbacklight");
/**
* Construct module
*/

View File

@@ -6,12 +6,15 @@
#include "x11/connection.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<xkeyboard_module>;
POLYBAR_MODULE(xkeyboard_module, "internal/xkeyboard");
/**
* Construct module
*/

View File

@@ -5,12 +5,15 @@
#include "x11/connection.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
namespace modules {
template class module<xwindow_module>;
POLYBAR_MODULE(xwindow_module, "internal/xwindow");
/**
* Wrapper used to update the event mask of the
* currently active to enable title tracking

View File

@@ -10,6 +10,7 @@
#include "x11/connection.hpp"
#include "modules/meta/base.inl"
#include "modules/meta/factory.hpp"
POLYBAR_NS
@@ -22,6 +23,8 @@ namespace {
namespace modules {
template class module<xworkspaces_module>;
POLYBAR_MODULE(xworkspaces_module, "internal/xworkspaces");
/**
* Construct module
*/

28
src/utils/CMakeLists.txt Normal file
View File

@@ -0,0 +1,28 @@
add_sources(files
bspwm.cpp
command.cpp
concurrency.cpp
env.cpp
factory.cpp
file.cpp
inotify.cpp
io.cpp
plugin.cpp
process.cpp
restack.cpp
socket.cpp
string.cpp
throttle.cpp)
if(ENABLE_I3)
make_library(polybar-utils-i3
SHARED
SOURCES
i3.cpp
INCLUDE_DIRS
${dirs}
${I3IPCPP_INCLUDE_DIRS}
RAW_DEPENDS
${libs}
${I3IPCPP_LIBRARIES})
endif()

View File

@@ -1,8 +1,10 @@
#include <sys/un.h>
#include "components/logger.hpp"
#include "errors.hpp"
#include "utils/bspwm.hpp"
#include "utils/env.hpp"
#include "utils/restack.hpp"
#include "x11/connection.hpp"
POLYBAR_NS
@@ -146,6 +148,21 @@ namespace bspwm_util {
}
return conn;
}
}
} // namespace bspwm_util
namespace restack {
struct bspwm_restacker : public wm_restacker {
void operator()(connection& conn, const bar_settings& opts, const logger& log) const override {
auto restacked = bspwm_util::restack_to_root(conn, opts.monitor, opts.window);
if (restacked) {
log.info("Successfully restacked bar window");
} else {
log.err("Failed to restack bar window");
}
}
};
POLYBAR_RESTACKER(bspwm_restacker, "bspwm");
} // namespace restack
POLYBAR_NS_END

View File

@@ -2,8 +2,10 @@
#include <i3ipc++/ipc.hpp>
#include "common.hpp"
#include "components/logger.hpp"
#include "settings.hpp"
#include "utils/i3.hpp"
#include "utils/restack.hpp"
#include "utils/socket.hpp"
#include "utils/string.hpp"
#include "x11/connection.hpp"
@@ -78,6 +80,25 @@ namespace i3_util {
}
return false;
}
}
} // namespace i3_util
namespace restack {
struct i3_restacker : public wm_restacker {
void operator()(connection& conn, const bar_settings& opts, const logger& log) const override {
if (opts.override_redirect) {
auto restacked = i3_util::restack_to_root(conn, opts.window);
if (restacked) {
log.info("Successfully restacked bar window");
} else {
log.err("Failed to restack bar window");
}
} else {
log.warn("Ignoring restack of i3 window (not needed when `override-redirect = false`)");
}
}
};
POLYBAR_RESTACKER(i3_restacker, "i3");
} // namespace restack
POLYBAR_NS_END

67
src/utils/plugin.cpp Normal file
View File

@@ -0,0 +1,67 @@
#include <dlfcn.h>
#include "components/logger.hpp"
#include "errors.hpp"
#include "settings.hpp"
#include "utils/plugin.hpp"
POLYBAR_NS
// clang-format off
std::vector<const char*> plugin_names = {
#if ENABLE_I3
"libpolybar-utils-i3.so",
#endif
#if ENABLE_ALSA
"libpolybar-modules-alsa.so",
#endif
#if ENABLE_CURL
"libpolybar-modules-github.so",
#endif
#if ENABLE_I3
"libpolybar-modules-i3.so",
#endif
#if ENABLE_MPD
"libpolybar-modules-mpd.so",
#endif
#if ENABLE_NETWORK
"libpolybar-modules-network.so",
#endif
#if ENABLE_PLUSEAUDIO
"libpolybar-modules-pulseaudio.so",
#endif
#if WITH_XKB
"libpolybar-modules-xkeyboard.so",
#endif
nullptr
};
// clang-format on
plugin_handle::plugin_handle(const char* libname) {
m_handle = ::dlopen(libname, RTLD_NOW | RTLD_GLOBAL);
if (!m_handle) {
throw application_error(::dlerror());
}
}
plugin_handle::~plugin_handle() {
if (m_handle) {
::dlclose(m_handle);
}
}
plugin_handle::plugin_handle(plugin_handle&& ph) {
m_handle = ph.m_handle;
ph.m_handle = nullptr;
}
plugin_handle& plugin_handle::operator=(plugin_handle&& ph) {
if (m_handle) {
::dlclose(m_handle);
}
m_handle = ph.m_handle;
ph.m_handle = nullptr;
return *this;
}
POLYBAR_NS_END

24
src/utils/restack.cpp Normal file
View File

@@ -0,0 +1,24 @@
#include "utils/restack.hpp"
POLYBAR_NS
namespace restack {
restacker_map& get_restacker_map() {
static restacker_map rmap;
return rmap;
}
const wm_restacker* get_restacker(const std::string& name) {
const auto& rmap = get_restacker_map();
auto it = rmap.find(name);
if (it != rmap.end()) {
return &it->second();
} else {
return nullptr;
}
}
} // namespace restack
POLYBAR_NS_END

36
src/x11/CMakeLists.txt Normal file
View File

@@ -0,0 +1,36 @@
add_sources(files
atoms.cpp
connection.cpp
ewmh.cpp
icccm.cpp
registry.cpp
tray_client.cpp
tray_manager.cpp
window.cpp
winspec.cpp
xembed.cpp)
if(WITH_XRANDR)
add_sources(files extensions/randr.cpp)
endif()
if(WITH_XRENDER)
add_sources(files extensions/render.cpp)
endif()
if(WITH_XDAMAGE)
add_sources(files extensions/damage.cpp)
endif()
if(WITH_XSYNC)
add_sources(files extensions/sync.cpp)
endif()
if(WITH_XCOMPOSITE)
add_sources(files extensions/composite.cpp)
endif()
if(WITH_XKB)
add_sources(files extensions/xkb.cpp)
endif()
if(WITH_XRM)
add_sources(files xresources.cpp)
endif()
if(WITH_XCURSOR)
add_sources(files cursor.cpp)
endif()

View File

@@ -39,7 +39,7 @@ string(REGEX REPLACE "-Werror[^ ]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REPLACE "-pedantic-errors" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
function(unit_test file tests)
set(multi_value_args SOURCES)
set(multi_value_args SOURCES RAW_DEPENDS)
cmake_parse_arguments("BIN" "" "" "${multi_value_args}" ${ARGN})
@@ -47,9 +47,10 @@ function(unit_test file tests)
# unit_test function become cleaner
SET(sources "")
FOREACH(f ${BIN_SOURCES})
# Do not add main.cpp, because it will override the main function
if(NOT "${f}" STREQUAL "main.cpp")
if(NOT IS_ABSOLUTE ${f})
LIST(APPEND sources "../src/${f}")
else()
LIST(APPEND sources ${f})
endif()
ENDFOREACH(f)
@@ -58,7 +59,7 @@ function(unit_test file tests)
add_executable(${name} unit_tests/${file}.cpp ${sources})
# Link against gmock (this automatically links against gtest)
target_link_libraries(${name} gmock_main ${libs})
target_link_libraries(${name} gmock_main ${libs} ${BIN_RAW_DEPENDS})
add_test(NAME ${name} COMMAND ${name})
@@ -98,7 +99,9 @@ unit_test(components/bar unit_tests)
unit_test(components/builder unit_tests
SOURCES
${files})
${files}
RAW_DEPENDS
polybar-modules-internal_shared)
# Compile all unit tests with 'make all_unit_tests'
add_custom_target("all_unit_tests" DEPENDS ${unit_tests})