diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py index 3da679cf..aa6a7c06 100644 --- a/.ycm_extra_conf.py +++ b/.ycm_extra_conf.py @@ -48,7 +48,6 @@ def DirectoryOfThisScript(): flags.append('-I'+ DirectoryOfThisScript() +'/src') flags.append('-I'+ DirectoryOfThisScript() +'/include') -flags.append('-I'+ DirectoryOfThisScript() +'/lib/boost/include') flags.append('-I'+ DirectoryOfThisScript() +'/lib/concurrentqueue/include') flags.append('-I'+ DirectoryOfThisScript() +'/lib/i3ipcpp/include') flags.append('-I'+ DirectoryOfThisScript() +'/lib/xpp/include') diff --git a/include/components/config.hpp b/include/components/config.hpp index a49539e6..2cf216ec 100644 --- a/include/components/config.hpp +++ b/include/components/config.hpp @@ -1,6 +1,4 @@ #pragma once - -#include #include #include "common.hpp" @@ -12,9 +10,6 @@ POLYBAR_NS -using boost::optional; -using boost::none; - #define GET_CONFIG_VALUE(section, var, name) var = m_conf.get(section, name, var) #define REQ_CONFIG_VALUE(section, var, name) var = m_conf.get(section, name) #define DEPR_CONFIG_VALUE(section, var, old, name) var = m_conf.deprecated(section, old, name, var) @@ -58,19 +53,11 @@ class config { */ template T get(const string& section, const string& key) const { - optional value{opt(section, key)}; - - if (value == none) { + auto it = m_sections.find(section); + if (it == m_sections.end() || it->second.find(key) == it->second.end()) { throw key_error("Missing parameter [" + section + "." + key + "]"); } - - string string_value{opt(section, key).get()}; - - if (!string_value.empty()) { - return dereference(section, key, opt(section, key).get(), value.get()); - } - - return move(value.get()); + return dereference(section, key, it->second.at(key), convert(string{it->second.at(key)})); } /** @@ -79,19 +66,13 @@ class config { */ template T get(const string& section, const string& key, const T& default_value) const { - optional value{opt(section, key)}; - - if (value == none) { + try { + T result{get(section, key)}; + string string_value{get(section, key)}; + return dereference(move(section), move(key), move(string_value), move(result)); + } catch (const key_error& err) { return default_value; } - - string string_value{opt(section, key).get()}; - - if (!string_value.empty()) { - return dereference(section, key, opt(section, key).get(), value.get()); - } - - return move(value.get()); } /** @@ -107,23 +88,28 @@ class config { */ template vector get_list(const string& section, const string& key) const { - vector vec; - optional value; + vector results; - while ((value = opt(section, key + "-" + to_string(vec.size()))) != none) { - string string_value{get(section, key + "-" + to_string(vec.size()))}; + while (true) { + try { + string string_value{get(section, key + "-" + to_string(results.size()))}; + T value{get(section, key + "-" + to_string(results.size()))}; - if (!string_value.empty()) { - vec.emplace_back(dereference(section, key, move(string_value), move(value.get()))); - } else { - vec.emplace_back(move(value.get())); + if (!string_value.empty()) { + results.emplace_back(dereference(section, key, move(string_value), move(value))); + } else { + results.emplace_back(move(value)); + } + } catch (const key_error& err) { + break; } } - if (vec.empty()) + if (results.empty()) { throw key_error("Missing parameter [" + section + "." + key + "-0]"); + } - return vec; + return results; } /** @@ -132,23 +118,29 @@ class config { */ template vector get_list(const string& section, const string& key, const vector& default_value) const { - vector vec; - optional value; + vector results; - while ((value = opt(section, key + "-" + to_string(vec.size()))) != none) { - string string_value{get(section, key + "-" + to_string(vec.size()))}; + while (true) { + try { + string string_value{get(section, key + "-" + to_string(results.size()))}; + T value{get(section, key + "-" + to_string(results.size()))}; - if (!string_value.empty()) { - vec.emplace_back(dereference(section, key, move(string_value), move(value.get()))); - } else { - vec.emplace_back(move(value.get())); + if (!string_value.empty()) { + results.emplace_back(dereference(section, key, move(string_value), move(value))); + } else { + results.emplace_back(move(value)); + } + } catch (const key_error& err) { + break; } } - if (vec.empty()) - return default_value; - else - return vec; + if (!results.empty()) { + return results; + ; + } + + return default_value; } /** @@ -188,18 +180,6 @@ class config { template T convert(string&& value) const; - template - const optional opt(const string& section, const string& key) const { - sectionmap_t::const_iterator s; - valuemap_t::const_iterator v; - - if ((s = m_sections.find(section)) != m_sections.end() && (v = s->second.find(key)) != s->second.end()) { - return {convert(string{v->second})}; - } - - return none; - } - /** * Dereference value reference */ @@ -232,20 +212,19 @@ class config { template T dereference_local(string section, const string& key, const string& current_section) const { if (section == "BAR") { - m_logger.warn("${BAR.key} is deprecated. Use ${root.key} instead"); + m_log.warn("${BAR.key} is deprecated. Use ${root.key} instead"); } section = string_util::replace(section, "BAR", this->section(), 0, 3); section = string_util::replace(section, "root", this->section(), 0, 4); section = string_util::replace(section, "self", current_section, 0, 4); - optional result{opt(section, key)}; - - if (result == none) { + try { + T result{get(section, key)}; + return dereference(string(section), move(key), get(section, key), move(result)); + } catch (const key_error& err) { throw value_error("Unexisting reference defined [" + section + "." + key + "]"); } - - return dereference(section, key, opt(section, key).get(), result.get()); } /** @@ -265,14 +244,13 @@ class config { if (env_util::has(var.c_str())) { string env_value{env_util::get(var.c_str())}; - m_logger.info("Found matching environment variable ${" + var + "} with the value \"" + env_value + "\""); + m_log.info("Found matching environment variable ${" + var + "} with the value \"" + env_value + "\""); return convert(move(env_value)); - } - - if (!env_default.empty()) { - m_logger.info("The environment variable ${" + var + "} is undefined or empty, using defined fallback value \"" + env_default + "\""); + } else if (!env_default.empty()) { + m_log.info("The environment variable ${" + var + "} is undefined or empty, using defined fallback value \"" + + env_default + "\""); } else { - m_logger.info("The environment variable ${" + var + "} is undefined or empty"); + m_log.info("The environment variable ${" + var + "} is undefined or empty"); } return convert(move(env_default)); @@ -298,7 +276,7 @@ class config { private: static constexpr const char* KEY_INHERIT{"inherit"}; - const logger& m_logger; + const logger& m_log; const xresource_manager& m_xrm; string m_file; string m_barname; diff --git a/include/components/renderer.hpp b/include/components/renderer.hpp index 659d600c..5c5d9c90 100644 --- a/include/components/renderer.hpp +++ b/include/components/renderer.hpp @@ -105,6 +105,7 @@ class renderer xcb_rectangle_t m_cleared{0, 0, 0U, 0U}; reserve_area m_cleararea{}; + uint8_t m_depth{32}; xcb_window_t m_window; xcb_colormap_t m_colormap; xcb_visualtype_t* m_visual; diff --git a/include/components/types.hpp b/include/components/types.hpp index 583b3107..e0485e12 100644 --- a/include/components/types.hpp +++ b/include/components/types.hpp @@ -96,7 +96,6 @@ struct bar_settings { bar_settings(const bar_settings& other) = default; xcb_window_t window{XCB_NONE}; - monitor_t monitor{}; edge origin{edge::TOP}; struct size size { diff --git a/include/x11/connection.hpp b/include/x11/connection.hpp index bb50b09e..42583f7a 100644 --- a/include/x11/connection.hpp +++ b/include/x11/connection.hpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include "common.hpp" @@ -74,7 +73,7 @@ class connection : public xpp_connection { void send_dummy_event(xcb_window_t target, uint32_t event = XCB_EVENT_MASK_STRUCTURE_NOTIFY) const; - boost::optional visual_type(xcb_screen_t* screen, int match_depth = 32); + xcb_visualtype_t* visual_type(xcb_screen_t* screen, int match_depth = 32); static string error_str(int error_code); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 005044ac..3033c5b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,7 +42,6 @@ endif() # Locate dependencies {{{ set(THREADS_PREFER_PTHREAD_FLAG ON) -find_package(Boost REQUIRED) find_package(Threads REQUIRED) find_package(X11 REQUIRED COMPONENTS Xft Xutil) find_package(X11_XCB REQUIRED) @@ -51,9 +50,8 @@ pkg_check_modules(FONTCONFIG REQUIRED fontconfig) set(APP_LIBRARIES ${APP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) set(APP_LIBRARIES ${APP_LIBRARIES} ${X11_Xft_LIB}) -set(APP_LIBRARIES ${APP_LIBRARIES} ${FONTCONFIG_LIBRARIES}) +#set(APP_LIBRARIES ${APP_LIBRARIES} ${FONTCONFIG_LIBRARIES}) -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/concurrentqueue/include) diff --git a/src/components/config.cpp b/src/components/config.cpp index 81936700..574a65b3 100644 --- a/src/components/config.cpp +++ b/src/components/config.cpp @@ -26,7 +26,7 @@ config::make_type config::make(string path, string bar) { * Construct config object */ config::config(const logger& logger, const xresource_manager& xrm, string&& path, string&& bar) - : m_logger(logger), m_xrm(xrm), m_file(forward(path)), m_barname(forward(bar)) { + : m_log(logger), m_xrm(xrm), m_file(forward(path)), m_barname(forward(bar)) { if (!file_util::exists(m_file)) { throw application_error("Could not find config file: " + m_file); } @@ -45,8 +45,8 @@ config::config(const logger& logger, const xresource_manager& xrm, string&& path throw application_error("Undefined bar: " + m_barname); } - m_logger.trace("config: Loaded %s", m_file); - m_logger.trace("config: Current bar section: [%s]", section()); + m_log.trace("config: Loaded %s", m_file); + m_log.trace("config: Current bar section: [%s]", section()); } /** @@ -69,7 +69,7 @@ string config::section() const { void config::warn_deprecated(const string& section, const string& key, string replacement) const { try { auto value = get(section, key); - m_logger.warn("The config parameter `%s.%s` is deprecated, use `%s` instead.", section, key, move(replacement)); + m_log.warn("The config parameter `%s.%s` is deprecated, use `%s` instead.", section, key, move(replacement)); } catch (const key_error& err) { } } @@ -149,7 +149,7 @@ void config::copy_inherited() { throw value_error("[" + section.first + "." + KEY_INHERIT + "] invalid reference \"" + inherit + "\""); } - m_logger.trace("config: Copying missing params (sub=\"%s\", base=\"%s\")", section.first, inherit); + m_log.trace("config: Copying missing params (sub=\"%s\", base=\"%s\")", section.first, inherit); // Iterate the base and copy the parameters // that hasn't been defined for the sub-section @@ -191,13 +191,13 @@ template <> bool config::convert(string&& value) const { string lower{string_util::lower(forward(value))}; - if (lower.compare(0, 4, "true") == 0) { + if (lower == "true") { return true; - } else if (lower.compare(0, 3, "yes") == 0) { + } else if (lower == "yes") { return true; - } else if (lower.compare(0, 2, "on") == 0) { + } else if (lower == "on") { return true; - } else if (lower.compare(0, 1, "1") == 0) { + } else if (lower == "1") { return true; } else { return false; diff --git a/src/components/renderer.cpp b/src/components/renderer.cpp index 16f59ddc..4f1fee26 100644 --- a/src/components/renderer.cpp +++ b/src/components/renderer.cpp @@ -44,7 +44,17 @@ renderer::renderer(connection& conn, signal_emitter& emitter, const logger& logg m_sig.attach(this); m_log.trace("renderer: Get TrueColor visual"); - m_visual = m_connection.visual_type(m_connection.screen(), 32).get(); + + if ((m_visual = m_connection.visual_type(m_connection.screen(), 32)) == nullptr) { + m_log.err("No 32-bit TrueColor visual found..."); + m_depth = 24; + } + if ((m_visual = m_connection.visual_type(m_connection.screen(), 24)) == nullptr) { + m_log.err("No 24-bit TrueColor visual found, aborting..."); + } + if (m_visual == nullptr) { + throw application_error("No matching TrueColor visual found..."); + } m_log.trace("renderer: Allocate colormap"); m_colormap = m_connection.generate_id(); diff --git a/src/utils/string.cpp b/src/utils/string.cpp index 835d6d75..e96c8a3a 100644 --- a/src/utils/string.cpp +++ b/src/utils/string.cpp @@ -1,4 +1,3 @@ -#include #include #include diff --git a/src/x11/connection.cpp b/src/x11/connection.cpp index c9d42840..c04ba88f 100644 --- a/src/x11/connection.cpp +++ b/src/x11/connection.cpp @@ -179,7 +179,7 @@ void connection::send_dummy_event(xcb_window_t target, uint32_t event) const { * Try to get a visual type for the given screen that * matches the given depth */ -boost::optional connection::visual_type(xcb_screen_t* screen, int match_depth) { +xcb_visualtype_t* connection::visual_type(xcb_screen_t* screen, int match_depth) { xcb_depth_iterator_t depth_iter = xcb_screen_allowed_depths_iterator(screen); if (depth_iter.data) { for (; depth_iter.rem; xcb_depth_next(&depth_iter)) { @@ -193,7 +193,7 @@ boost::optional connection::visual_type(xcb_screen_t* screen, return visual_type(screen, 0); } } - return {}; + return nullptr; } /** diff --git a/src/x11/randr.cpp b/src/x11/randr.cpp index a10e87d2..5af18940 100644 --- a/src/x11/randr.cpp +++ b/src/x11/randr.cpp @@ -1,4 +1,5 @@ #include +#include #include "components/types.hpp" #include "utils/string.hpp"