Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GtkButton instead of GtkLabel for Modules #1120

Merged
merged 4 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions include/AButton.hpp
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion include/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions include/modules/backlight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <string_view>
#include <vector>

#include "ALabel.hpp"
#include "AButton.hpp"
#include "util/json.hpp"
#include "util/sleeper_thread.hpp"

Expand All @@ -14,7 +14,7 @@ struct udev_device;

namespace waybar::modules {

class Backlight : public ALabel {
class Backlight : public AButton {
class BacklightDev {
public:
BacklightDev() = default;
Expand Down
4 changes: 2 additions & 2 deletions include/modules/battery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <string>
#include <vector>

#include "ALabel.hpp"
#include "AButton.hpp"
#include "util/sleeper_thread.hpp"

namespace waybar::modules {
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions include/modules/bluetooth.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "ALabel.hpp"
#include "AButton.hpp"
#ifdef WANT_RFKILL
#include "util/rfkill.hpp"
#endif
Expand All @@ -12,7 +12,7 @@

namespace waybar::modules {

class Bluetooth : public ALabel {
class Bluetooth : public AButton {
struct ControllerInfo {
std::string path;
std::string address;
Expand Down
4 changes: 2 additions & 2 deletions include/modules/clock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <date/tz.h>

#include "ALabel.hpp"
#include "AButton.hpp"
#include "util/sleeper_thread.hpp"

namespace waybar {
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions include/modules/cpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions include/modules/custom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions include/modules/disk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 10 additions & 12 deletions include/modules/hyprland/backend.hpp
Original file line number Diff line number Diff line change
@@ -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:

void startIPC();
void parseIPC(const std::string&);
private:
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
10 changes: 5 additions & 5 deletions include/modules/hyprland/language.hpp
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -26,4 +26,4 @@ class Language : public waybar::ALabel {
std::string layoutName_;
};

}
} // namespace waybar::modules::hyprland
6 changes: 3 additions & 3 deletions include/modules/hyprland/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand All @@ -25,4 +25,4 @@ class Window : public waybar::ALabel {
std::string lastView;
};

}
} // namespace waybar::modules::hyprland
4 changes: 2 additions & 2 deletions include/modules/idle_inhibitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions include/modules/inhibitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 18 additions & 16 deletions include/modules/jack.hpp
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
#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"

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();

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_;
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_;
util::SleeperThread thread_;
};

Expand Down
4 changes: 2 additions & 2 deletions include/modules/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions include/modules/mpd/mpd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/modules/mpd/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <condition_variable>
#include <thread>

#include "ALabel.hpp"
#include "AButton.hpp"

namespace waybar::modules {
class MPD;
Expand Down
Loading