mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
button: Add AButton class
The AButton class is designed as full a substitute to ALabel. The GtkButton attribute 'button_' is initialized with a label. This label can the be referenced by the subsequent inheritors of AButton instead of the GtkLabel attribute 'label_' of ALabel. For convenience a GtkLabel* 'label_' attribute is added to AButton. If the button cannot be clicked it is disabled, effectively acting like its label predecessor. GtkButton seems to catch one-click mouse events regardless of the flags set on it. Therefore, 'signal_pressed' is connected to a function creating a fake GdkEventButton* and calling 'handleToggle' (for details on this possible bug in GTK see: https://stackoverflow.com/questions/45334911 ) In accordance with other GtkButtons (i.e. the sway/workspace ones) set_relief(Gtk::RELIEF_NONE) is called on the 'button_' instance.
This commit is contained in:
34
include/AButton.hpp
Normal file
34
include/AButton.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <glibmm/markup.h>
|
||||
#include <gtkmm/button.h>
|
||||
#include <gtkmm/label.h>
|
||||
#include <json/json.h>
|
||||
|
||||
#include "AModule.hpp"
|
||||
|
||||
namespace waybar {
|
||||
|
||||
class AButton : public AModule {
|
||||
public:
|
||||
AButton(const Json::Value &, const std::string &, const std::string &, const std::string &format,
|
||||
uint16_t interval = 0, bool ellipsize = false, bool enable_click = false,
|
||||
bool enable_scroll = false);
|
||||
virtual ~AButton() = default;
|
||||
virtual auto update() -> void;
|
||||
virtual std::string getIcon(uint16_t, const std::string &alt = "", uint16_t max = 0);
|
||||
virtual std::string getIcon(uint16_t, const std::vector<std::string> &alts, uint16_t max = 0);
|
||||
|
||||
protected:
|
||||
Gtk::Button button_ = Gtk::Button(name_);
|
||||
Gtk::Label *label_ = (Gtk::Label *)button_.get_child();
|
||||
std::string format_;
|
||||
const std::chrono::seconds interval_;
|
||||
bool alt_ = false;
|
||||
std::string default_format_;
|
||||
|
||||
virtual bool handleToggle(GdkEventButton *const &e);
|
||||
virtual std::string getState(uint8_t value, bool lesser = false);
|
||||
};
|
||||
|
||||
} // namespace waybar
|
@ -23,8 +23,8 @@
|
||||
#endif
|
||||
#ifdef HAVE_HYPRLAND
|
||||
#include "modules/hyprland/backend.hpp"
|
||||
#include "modules/hyprland/window.hpp"
|
||||
#include "modules/hyprland/language.hpp"
|
||||
#include "modules/hyprland/window.hpp"
|
||||
#endif
|
||||
#if defined(__linux__) && !defined(NO_FILESYSTEM)
|
||||
#include "modules/battery.hpp"
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#include "util/json.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
@ -14,7 +14,7 @@ struct udev_device;
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class Backlight : public ALabel {
|
||||
class Backlight : public AButton {
|
||||
class BacklightDev {
|
||||
public:
|
||||
BacklightDev() = default;
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
@ -24,7 +24,7 @@ namespace fs = std::experimental::filesystem;
|
||||
namespace fs = std::filesystem;
|
||||
#endif
|
||||
|
||||
class Battery : public ALabel {
|
||||
class Battery : public AButton {
|
||||
public:
|
||||
Battery(const std::string&, const Json::Value&);
|
||||
~Battery();
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#ifdef WANT_RFKILL
|
||||
#include "util/rfkill.hpp"
|
||||
#endif
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class Bluetooth : public ALabel {
|
||||
class Bluetooth : public AButton {
|
||||
struct ControllerInfo {
|
||||
std::string path;
|
||||
std::string address;
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <date/tz.h>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar {
|
||||
@ -14,7 +14,7 @@ namespace modules {
|
||||
const std::string kCalendarPlaceholder = "calendar";
|
||||
const std::string KTimezonedTimeListPlaceholder = "timezoned_time_list";
|
||||
|
||||
class Clock : public ALabel {
|
||||
class Clock : public AButton {
|
||||
public:
|
||||
Clock(const std::string&, const Json::Value&);
|
||||
~Clock() = default;
|
||||
|
@ -9,12 +9,12 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class Cpu : public ALabel {
|
||||
class Cpu : public AButton {
|
||||
public:
|
||||
Cpu(const std::string&, const Json::Value&);
|
||||
~Cpu() = default;
|
||||
|
@ -5,14 +5,14 @@
|
||||
#include <csignal>
|
||||
#include <string>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#include "util/command.hpp"
|
||||
#include "util/json.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class Custom : public ALabel {
|
||||
class Custom : public AButton {
|
||||
public:
|
||||
Custom(const std::string&, const std::string&, const Json::Value&);
|
||||
~Custom();
|
||||
|
@ -5,13 +5,13 @@
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#include "util/format.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class Disk : public ALabel {
|
||||
class Disk : public AButton {
|
||||
public:
|
||||
Disk(const std::string&, const Json::Value&);
|
||||
~Disk() = default;
|
||||
|
@ -1,30 +1,28 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
namespace waybar::modules::hyprland {
|
||||
class IPC {
|
||||
public:
|
||||
public:
|
||||
IPC() { startIPC(); }
|
||||
|
||||
void registerForIPC(const std::string&, std::function<void(const std::string&)>);
|
||||
|
||||
std::string getSocket1Reply(const std::string& rq);
|
||||
|
||||
private:
|
||||
private:
|
||||
void startIPC();
|
||||
void parseIPC(const std::string&);
|
||||
|
||||
void startIPC();
|
||||
void parseIPC(const std::string&);
|
||||
|
||||
std::mutex callbackMutex;
|
||||
std::deque<std::pair<std::string, std::function<void(const std::string&)>>> callbacks;
|
||||
std::mutex callbackMutex;
|
||||
std::deque<std::pair<std::string, std::function<void(const std::string&)>>> callbacks;
|
||||
};
|
||||
|
||||
inline std::unique_ptr<IPC> gIPC;
|
||||
inline bool modulesReady = false;
|
||||
};
|
||||
|
||||
}; // namespace waybar::modules::hyprland
|
||||
|
@ -1,20 +1,20 @@
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#include "bar.hpp"
|
||||
#include "modules/hyprland/backend.hpp"
|
||||
#include "util/json.hpp"
|
||||
|
||||
namespace waybar::modules::hyprland {
|
||||
|
||||
class Language : public waybar::ALabel {
|
||||
public:
|
||||
class Language : public waybar::AButton {
|
||||
public:
|
||||
Language(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
~Language() = default;
|
||||
|
||||
auto update() -> void;
|
||||
|
||||
private:
|
||||
private:
|
||||
void onEvent(const std::string&);
|
||||
|
||||
void initLanguage();
|
||||
@ -26,4 +26,4 @@ private:
|
||||
std::string layoutName_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace waybar::modules::hyprland
|
||||
|
@ -10,13 +10,13 @@
|
||||
namespace waybar::modules::hyprland {
|
||||
|
||||
class Window : public waybar::ALabel {
|
||||
public:
|
||||
public:
|
||||
Window(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
~Window() = default;
|
||||
|
||||
auto update() -> void;
|
||||
|
||||
private:
|
||||
private:
|
||||
void onEvent(const std::string&);
|
||||
|
||||
std::mutex mutex_;
|
||||
@ -25,4 +25,4 @@ private:
|
||||
std::string lastView;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace waybar::modules::hyprland
|
@ -2,13 +2,13 @@
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#include "bar.hpp"
|
||||
#include "client.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class IdleInhibitor : public ALabel {
|
||||
class IdleInhibitor : public AButton {
|
||||
sigc::connection timeout_;
|
||||
|
||||
public:
|
||||
|
@ -4,12 +4,12 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#include "bar.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class Inhibitor : public ALabel {
|
||||
class Inhibitor : public AButton {
|
||||
public:
|
||||
Inhibitor(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
~Inhibitor() override;
|
||||
|
@ -1,9 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <fstream>
|
||||
#include <jack/jack.h>
|
||||
#include <jack/thread.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
@ -11,26 +13,26 @@ namespace waybar::modules {
|
||||
|
||||
class JACK : public ALabel {
|
||||
public:
|
||||
JACK(const std::string&, const Json::Value&);
|
||||
JACK(const std::string &, const Json::Value &);
|
||||
~JACK() = default;
|
||||
auto update() -> void;
|
||||
|
||||
int bufSize(jack_nframes_t size);
|
||||
int sampleRate(jack_nframes_t rate);
|
||||
int xrun();
|
||||
void shutdown();
|
||||
int bufSize(jack_nframes_t size);
|
||||
int sampleRate(jack_nframes_t rate);
|
||||
int xrun();
|
||||
void shutdown();
|
||||
|
||||
private:
|
||||
std::string JACKState();
|
||||
std::string JACKState();
|
||||
|
||||
jack_client_t* client_;
|
||||
jack_nframes_t bufsize_;
|
||||
jack_nframes_t samplerate_;
|
||||
unsigned int xruns_;
|
||||
float load_;
|
||||
bool running_;
|
||||
std::mutex mutex_;
|
||||
std::string state_;
|
||||
jack_client_t *client_;
|
||||
jack_nframes_t bufsize_;
|
||||
jack_nframes_t samplerate_;
|
||||
unsigned int xruns_;
|
||||
float load_;
|
||||
bool running_;
|
||||
std::mutex mutex_;
|
||||
std::string state_;
|
||||
util::SleeperThread thread_;
|
||||
};
|
||||
|
||||
|
@ -5,12 +5,12 @@
|
||||
#include <fstream>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class Memory : public ALabel {
|
||||
class Memory : public AButton {
|
||||
public:
|
||||
Memory(const std::string&, const Json::Value&);
|
||||
~Memory() = default;
|
||||
|
@ -7,12 +7,12 @@
|
||||
#include <condition_variable>
|
||||
#include <thread>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#include "modules/mpd/state.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class MPD : public ALabel {
|
||||
class MPD : public AButton {
|
||||
friend class detail::Context;
|
||||
|
||||
// State machine
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <condition_variable>
|
||||
#include <thread>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
class MPD;
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
#ifdef WANT_RFKILL
|
||||
#include "util/rfkill.hpp"
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class Network : public ALabel {
|
||||
class Network : public AButton {
|
||||
public:
|
||||
Network(const std::string&, const Json::Value&);
|
||||
~Network();
|
||||
|
@ -7,11 +7,11 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class Pulseaudio : public ALabel {
|
||||
class Pulseaudio : public AButton {
|
||||
public:
|
||||
Pulseaudio(const std::string&, const Json::Value&);
|
||||
~Pulseaudio();
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
#include <fmt/chrono.h>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class Clock : public ALabel {
|
||||
class Clock : public AButton {
|
||||
public:
|
||||
Clock(const std::string&, const Json::Value&);
|
||||
~Clock() = default;
|
||||
|
@ -4,12 +4,12 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class Sndio : public ALabel {
|
||||
class Sndio : public AButton {
|
||||
public:
|
||||
Sndio(const std::string &, const Json::Value &);
|
||||
~Sndio();
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#include "bar.hpp"
|
||||
#include "client.hpp"
|
||||
#include "modules/sway/ipc/client.hpp"
|
||||
@ -14,7 +14,7 @@
|
||||
|
||||
namespace waybar::modules::sway {
|
||||
|
||||
class Language : public ALabel, public sigc::trackable {
|
||||
class Language : public AButton, public sigc::trackable {
|
||||
public:
|
||||
Language(const std::string& id, const Json::Value& config);
|
||||
~Language() = default;
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#include "bar.hpp"
|
||||
#include "client.hpp"
|
||||
#include "modules/sway/ipc/client.hpp"
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
namespace waybar::modules::sway {
|
||||
|
||||
class Mode : public ALabel, public sigc::trackable {
|
||||
class Mode : public AButton, public sigc::trackable {
|
||||
public:
|
||||
Mode(const std::string&, const Json::Value&);
|
||||
~Mode() = default;
|
||||
|
@ -4,12 +4,12 @@
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "AButton.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class Temperature : public ALabel {
|
||||
class Temperature : public AButton {
|
||||
public:
|
||||
Temperature(const std::string&, const Json::Value&);
|
||||
~Temperature() = default;
|
||||
|
Reference in New Issue
Block a user