mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Add more configuaration
This commit is contained in:
parent
6dfa31fb17
commit
642e28166b
@ -6,8 +6,10 @@
|
|||||||
#else
|
#else
|
||||||
#include <fmt/chrono.h>
|
#include <fmt/chrono.h>
|
||||||
#endif
|
#endif
|
||||||
#include "ALabel.hpp"
|
#include "AModule.hpp"
|
||||||
|
#include "bar.hpp"
|
||||||
#include "util/sleeper_thread.hpp"
|
#include "util/sleeper_thread.hpp"
|
||||||
|
#include <gtkmm/label.h>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <libevdev/libevdev.h>
|
#include <libevdev/libevdev.h>
|
||||||
@ -15,16 +17,30 @@ extern "C" {
|
|||||||
|
|
||||||
namespace waybar::modules {
|
namespace waybar::modules {
|
||||||
|
|
||||||
class KeyboardState : public ALabel {
|
class KeyboardState : public AModule {
|
||||||
public:
|
public:
|
||||||
KeyboardState(const std::string&, const Json::Value&);
|
KeyboardState(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||||
~KeyboardState();
|
~KeyboardState();
|
||||||
auto update() -> void;
|
auto update() -> void;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const Bar& bar_;
|
||||||
|
Gtk::Box box_;
|
||||||
|
Gtk::Label numlock_label_;
|
||||||
|
Gtk::Label capslock_label_;
|
||||||
|
Gtk::Label scrolllock_label_;
|
||||||
|
|
||||||
|
std::string numlock_format_;
|
||||||
|
std::string capslock_format_;
|
||||||
|
std::string scrolllock_format_;
|
||||||
|
const std::chrono::seconds interval_;
|
||||||
|
std::string icon_locked_;
|
||||||
|
std::string icon_unlocked_;
|
||||||
|
|
||||||
std::string dev_path_;
|
std::string dev_path_;
|
||||||
int fd_;
|
int fd_;
|
||||||
libevdev* dev_;
|
libevdev* dev_;
|
||||||
|
|
||||||
util::SleeperThread thread_;
|
util::SleeperThread thread_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
// Choose the order of the modules
|
// Choose the order of the modules
|
||||||
"modules-left": ["sway/workspaces", "sway/mode", "custom/media"],
|
"modules-left": ["sway/workspaces", "sway/mode", "custom/media"],
|
||||||
"modules-center": ["sway/window"],
|
"modules-center": ["sway/window"],
|
||||||
"modules-right": ["mpd", "idle_inhibitor", "pulseaudio", "network", "cpu", "memory", "temperature", "backlight", "sway/language", "battery", "battery#bat2", "clock", "tray"],
|
"modules-right": ["keyboard_state", "mpd", "idle_inhibitor", "pulseaudio", "network", "cpu", "memory", "temperature", "backlight", "sway/language", "battery", "battery#bat2", "clock", "tray"],
|
||||||
// Modules configuration
|
// Modules configuration
|
||||||
// "sway/workspaces": {
|
// "sway/workspaces": {
|
||||||
// "disable-scroll": true,
|
// "disable-scroll": true,
|
||||||
@ -23,6 +23,16 @@
|
|||||||
// "default": ""
|
// "default": ""
|
||||||
// }
|
// }
|
||||||
// },
|
// },
|
||||||
|
"keyboard_state": {
|
||||||
|
"numlock": true,
|
||||||
|
"format": "{name} {icon}",
|
||||||
|
"format-icons": {
|
||||||
|
"locked": "",
|
||||||
|
"unlocked": ""
|
||||||
|
},
|
||||||
|
"capslock": true,
|
||||||
|
"device-path": "/dev/input/by-path/platform-i8042-serio-0-event-kbd"
|
||||||
|
},
|
||||||
"sway/mode": {
|
"sway/mode": {
|
||||||
"format": "<span style=\"italic\">{}</span>"
|
"format": "<span style=\"italic\">{}</span>"
|
||||||
},
|
},
|
||||||
@ -145,3 +155,4 @@
|
|||||||
// "exec": "$HOME/.config/waybar/mediaplayer.py --player spotify 2> /dev/null" // Filter player based on name
|
// "exec": "$HOME/.config/waybar/mediaplayer.py --player spotify 2> /dev/null" // Filter player based on name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name) const {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_LIBEVDEV
|
#ifdef HAVE_LIBEVDEV
|
||||||
if (ref == "keyboard_state") {
|
if (ref == "keyboard_state") {
|
||||||
return new waybar::modules::KeyboardState(id, config_[name]);
|
return new waybar::modules::KeyboardState(id, bar_, config_[name]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_LIBPULSE
|
#ifdef HAVE_LIBPULSE
|
||||||
|
@ -7,8 +7,44 @@ extern "C" {
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
waybar::modules::KeyboardState::KeyboardState(const std::string& id, const Json::Value& config)
|
waybar::modules::KeyboardState::KeyboardState(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||||
: ALabel(config, "keyboard_state", id, "{temperatureC}", 1) {
|
: AModule(config, "keyboard_state", id, false, !config["disable-scroll"].asBool()),
|
||||||
|
bar_(bar),
|
||||||
|
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0),
|
||||||
|
numlock_label_(""),
|
||||||
|
capslock_label_(""),
|
||||||
|
numlock_format_(config_["format"].isString() ? config_["format"].asString()
|
||||||
|
: config_["format"]["numlock"].isString() ? config_["format"]["numlock"].asString()
|
||||||
|
: "{name} {icon}"),
|
||||||
|
capslock_format_(config_["format"].isString() ? config_["format"].asString()
|
||||||
|
: config_["format"]["capslock"].isString() ? config_["format"]["capslock"].asString()
|
||||||
|
: "{name} {icon}"),
|
||||||
|
scrolllock_format_(config_["format"].isString() ? config_["format"].asString()
|
||||||
|
: config_["format"]["scrolllock"].isString() ? config_["format"]["scrolllock"].asString()
|
||||||
|
: "{name} {icon}"),
|
||||||
|
interval_(std::chrono::seconds(config_["interval"].isUInt() ? config_["interval"].asUInt() : 1)),
|
||||||
|
icon_locked_(config_["format-icons"]["locked"].isString()
|
||||||
|
? config_["format-icons"]["locked"].asString()
|
||||||
|
: "locked"),
|
||||||
|
icon_unlocked_(config_["format-icons"]["unlocked"].isString()
|
||||||
|
? config_["format-icons"]["unlocked"].asString()
|
||||||
|
: "unlocked")
|
||||||
|
{
|
||||||
|
box_.set_name("keyboard_state");
|
||||||
|
if (config_["numlock"].asBool()) {
|
||||||
|
box_.pack_end(numlock_label_, false, false, 0);
|
||||||
|
}
|
||||||
|
if (config_["capslock"].asBool()) {
|
||||||
|
box_.pack_end(capslock_label_, false, false, 0);
|
||||||
|
}
|
||||||
|
if (config_["scrolllock"].asBool()) {
|
||||||
|
box_.pack_end(scrolllock_label_, false, false, 0);
|
||||||
|
}
|
||||||
|
if (!id.empty()) {
|
||||||
|
box_.get_style_context()->add_class(id);
|
||||||
|
}
|
||||||
|
event_box_.add(box_);
|
||||||
|
|
||||||
if (config_["device-path"].isString()) {
|
if (config_["device-path"].isString()) {
|
||||||
dev_path_ = config_["device-path"].asString();
|
dev_path_ = config_["device-path"].asString();
|
||||||
} else {
|
} else {
|
||||||
@ -26,8 +62,10 @@ waybar::modules::KeyboardState::KeyboardState(const std::string& id, const Json:
|
|||||||
if (!libevdev_has_event_type(dev_, EV_LED)) {
|
if (!libevdev_has_event_type(dev_, EV_LED)) {
|
||||||
throw std::runtime_error("Device doesn't support LED events");
|
throw std::runtime_error("Device doesn't support LED events");
|
||||||
}
|
}
|
||||||
if (!libevdev_has_event_code(dev_, EV_LED, LED_NUML) || !libevdev_has_event_code(dev_, EV_LED, LED_CAPSL)) {
|
if (!libevdev_has_event_code(dev_, EV_LED, LED_NUML)
|
||||||
throw std::runtime_error("Device doesn't support num lock or caps lock events");
|
|| !libevdev_has_event_code(dev_, EV_LED, LED_CAPSL)
|
||||||
|
|| !libevdev_has_event_code(dev_, EV_LED, LED_SCROLLL)) {
|
||||||
|
throw std::runtime_error("Device doesn't support num lock, caps lock, or scroll lock events");
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_ = [this] {
|
thread_ = [this] {
|
||||||
@ -58,16 +96,22 @@ auto waybar::modules::KeyboardState::update() -> void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int numl = libevdev_get_event_value(dev_, EV_LED, LED_NUML);
|
int numl = libevdev_get_event_value(dev_, EV_LED, LED_NUML);
|
||||||
//int capsl = libevdev_get_event_value(dev_, EV_LED, LED_CAPSL);
|
int capsl = libevdev_get_event_value(dev_, EV_LED, LED_CAPSL);
|
||||||
|
int scrolll = libevdev_get_event_value(dev_, EV_LED, LED_SCROLLL);
|
||||||
|
|
||||||
std::string text;
|
std::string text;
|
||||||
if (numl) {
|
text = fmt::format(numlock_format_,
|
||||||
text = fmt::format(format_, "num lock enabled");
|
fmt::arg("icon", numl ? icon_locked_ : icon_unlocked_),
|
||||||
label_.set_markup(text);
|
fmt::arg("name", "Num"));
|
||||||
} else {
|
numlock_label_.set_markup(text);
|
||||||
text = fmt::format(format_, "num lock disabled");
|
text = fmt::format(capslock_format_,
|
||||||
label_.set_markup(text);
|
fmt::arg("icon", capsl ? icon_locked_ : icon_unlocked_),
|
||||||
}
|
fmt::arg("name", "Caps"));
|
||||||
|
capslock_label_.set_markup(text);
|
||||||
|
text = fmt::format(scrolllock_format_,
|
||||||
|
fmt::arg("icon", scrolll ? icon_locked_ : icon_unlocked_),
|
||||||
|
fmt::arg("name", "Scroll"));
|
||||||
|
scrolllock_label_.set_markup(text);
|
||||||
|
|
||||||
ALabel::update();
|
AModule::update();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user