Merge pull request #2424 from asas1asas200/feat-keyboard-bindingkey
This commit is contained in:
commit
b7a527b122
|
@ -3,6 +3,7 @@
|
||||||
#include <fmt/chrono.h>
|
#include <fmt/chrono.h>
|
||||||
#include <gtkmm/label.h>
|
#include <gtkmm/label.h>
|
||||||
|
|
||||||
|
#include <set>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "AModule.hpp"
|
#include "AModule.hpp"
|
||||||
|
@ -40,6 +41,7 @@ class KeyboardState : public AModule {
|
||||||
|
|
||||||
struct libinput* libinput_;
|
struct libinput* libinput_;
|
||||||
std::unordered_map<std::string, struct libinput_device*> libinput_devices_;
|
std::unordered_map<std::string, struct libinput_device*> libinput_devices_;
|
||||||
|
std::set<int> binding_keys;
|
||||||
|
|
||||||
util::SleeperThread libinput_thread_, hotplug_thread_;
|
util::SleeperThread libinput_thread_, hotplug_thread_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,6 +48,11 @@ You must be a member of the input group to use this module.
|
||||||
default: chooses first valid input device ++
|
default: chooses first valid input device ++
|
||||||
Which libevdev input device to show the state of. Libevdev devices can be found in /dev/input. The device should support number lock, caps lock, and scroll lock events.
|
Which libevdev input device to show the state of. Libevdev devices can be found in /dev/input. The device should support number lock, caps lock, and scroll lock events.
|
||||||
|
|
||||||
|
*binding-keys*: ++
|
||||||
|
typeof: array ++
|
||||||
|
default: [58, 69, 70] ++
|
||||||
|
Customize the key to trigger this module, the key number can be find in /usr/include/linux/input-event-codes.h or running sudo libinput debug-events --show-keycodes.
|
||||||
|
|
||||||
# FORMAT REPLACEMENTS
|
# FORMAT REPLACEMENTS
|
||||||
|
|
||||||
*{name}*: Caps, Num, or Scroll.
|
*{name}*: Caps, Num, or Scroll.
|
||||||
|
|
|
@ -142,6 +142,21 @@ waybar::modules::KeyboardState::KeyboardState(const std::string& id, const Bar&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto keys = config_["binding-keys"];
|
||||||
|
if (keys.isArray()) {
|
||||||
|
for (const auto& key : keys) {
|
||||||
|
if (key.isInt()) {
|
||||||
|
binding_keys.insert(key.asInt());
|
||||||
|
} else {
|
||||||
|
spdlog::warn("Cannot read key binding {} as int.", key.asString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
binding_keys.insert(KEY_CAPSLOCK);
|
||||||
|
binding_keys.insert(KEY_NUMLOCK);
|
||||||
|
binding_keys.insert(KEY_SCROLLLOCK);
|
||||||
|
}
|
||||||
|
|
||||||
DIR* dev_dir = opendir(devices_path_.c_str());
|
DIR* dev_dir = opendir(devices_path_.c_str());
|
||||||
if (dev_dir == nullptr) {
|
if (dev_dir == nullptr) {
|
||||||
throw errno_error(errno, "Failed to open " + devices_path_);
|
throw errno_error(errno, "Failed to open " + devices_path_);
|
||||||
|
@ -171,14 +186,8 @@ waybar::modules::KeyboardState::KeyboardState(const std::string& id, const Bar&
|
||||||
auto state = libinput_event_keyboard_get_key_state(keyboard_event);
|
auto state = libinput_event_keyboard_get_key_state(keyboard_event);
|
||||||
if (state == LIBINPUT_KEY_STATE_RELEASED) {
|
if (state == LIBINPUT_KEY_STATE_RELEASED) {
|
||||||
uint32_t key = libinput_event_keyboard_get_key(keyboard_event);
|
uint32_t key = libinput_event_keyboard_get_key(keyboard_event);
|
||||||
switch (key) {
|
if (binding_keys.contains(key)) {
|
||||||
case KEY_CAPSLOCK:
|
dp.emit();
|
||||||
case KEY_NUMLOCK:
|
|
||||||
case KEY_SCROLLLOCK:
|
|
||||||
dp.emit();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue