From f4e8051e9e3e6705336e9c5ee2de24aa6242ab85 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Tue, 10 Jan 2017 05:12:53 +0100 Subject: [PATCH] refactor(script): Merge back script handling --- include/modules/cmdscript.hpp | 18 ---- include/modules/meta/base.hpp | 2 +- include/modules/meta/factory.hpp | 8 +- include/modules/script.hpp | 19 ++-- include/modules/tailscript.hpp | 18 ---- include/modules/unsupported.hpp | 4 +- src/modules/cmdscript.cpp | 35 ------- src/modules/script.cpp | 172 ++++++++++++++++++++++--------- src/modules/tailscript.cpp | 44 -------- 9 files changed, 132 insertions(+), 188 deletions(-) delete mode 100644 include/modules/cmdscript.hpp delete mode 100644 include/modules/tailscript.hpp delete mode 100644 src/modules/cmdscript.cpp delete mode 100644 src/modules/tailscript.cpp diff --git a/include/modules/cmdscript.hpp b/include/modules/cmdscript.hpp deleted file mode 100644 index 3b2d2a5d..00000000 --- a/include/modules/cmdscript.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "modules/script.hpp" - -POLYBAR_NS - -namespace modules { - class cmdscript_module : virtual public script_module { - public: - explicit cmdscript_module(const bar_settings&, string); - - protected: - void process(); - chrono::duration sleep_duration(); - }; -} - -POLYBAR_NS_END diff --git a/include/modules/meta/base.hpp b/include/modules/meta/base.hpp index 0aa82690..182e59b7 100644 --- a/include/modules/meta/base.hpp +++ b/include/modules/meta/base.hpp @@ -130,7 +130,7 @@ namespace modules { protected: void broadcast(); void idle(); - void sleep(chrono::duration sleep_duration); + void sleep(chrono::duration duration); void wakeup(); string get_format() const; string get_output(); diff --git a/include/modules/meta/factory.hpp b/include/modules/meta/factory.hpp index d412b9fe..8535ba4c 100644 --- a/include/modules/meta/factory.hpp +++ b/include/modules/meta/factory.hpp @@ -5,7 +5,6 @@ #include "modules/backlight.hpp" #include "modules/battery.hpp" #include "modules/bspwm.hpp" -#include "modules/cmdscript.hpp" #include "modules/counter.hpp" #include "modules/cpu.hpp" #include "modules/date.hpp" @@ -18,7 +17,6 @@ #if DEBUG #include "modules/systray.hpp" #endif -#include "modules/tailscript.hpp" #include "modules/temperature.hpp" #include "modules/text.hpp" #include "modules/xbacklight.hpp" @@ -95,11 +93,7 @@ namespace { } else if (name == "custom/text") { return new text_module(bar, move(module_name)); } else if (name == "custom/script") { - if (config::make().get("module/" + module_name, "tail", false)) { - return new tailscript_module(bar, move(module_name)); - } else { - return new cmdscript_module(bar, move(module_name)); - } + 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") { diff --git a/include/modules/script.hpp b/include/modules/script.hpp index ccfea03e..c1ec50bc 100644 --- a/include/modules/script.hpp +++ b/include/modules/script.hpp @@ -10,21 +10,23 @@ namespace modules { class script_module : public module { public: explicit script_module(const bar_settings&, string); - virtual ~script_module() {} + ~script_module() {} - virtual void start(); - virtual void stop(); + void start(); + void stop(); string get_output(); bool build(builder* builder, const string& tag) const; protected: - virtual void process() = 0; - virtual chrono::duration sleep_duration() = 0; + chrono::duration process(const mutex_wrapper()>>& handler) const; + bool check_condition(); - static constexpr const char* TAG_OUTPUT{""}; + private: static constexpr const char* TAG_LABEL{"