Skip to content
Open
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
53 changes: 32 additions & 21 deletions include/modules/keyboard_state.hpp
Original file line number Diff line number Diff line change
@@ -1,49 +1,60 @@
#pragma once

#include <fmt/chrono.h>
#include <gtkmm/label.h>
#include <gdk/gdk.h>
#include <glibmm/refptr.h>
#include <gtkmm/box.h>
#include <wayland-client.h>
#include <xkbcommon/xkbcommon.h>
#include <xkbcommon/xkbregistry.h>

#include <set>
#include <unordered_map>
#include <memory>
#include <string>

#include "AModule.hpp"
#include "bar.hpp"
#include "util/sleeper_thread.hpp"

extern "C" {
#include <libevdev/libevdev.h>
#include <libinput.h>
}
#include "client.hpp"
#include "util/json.hpp"

namespace waybar::modules {

class KeyboardState : public AModule {
public:
KeyboardState(const std::string&, const waybar::Bar&, const Json::Value&);
virtual ~KeyboardState();
auto update() -> void override;
KeyboardState(const std::string &, const waybar::Bar &, const Json::Value &);
~KeyboardState();
void update();

private:
auto tryAddDevice(const std::string&) -> void;

Gtk::Box box_;
Gtk::Label layout_label_;
Gtk::Label numlock_label_;
Gtk::Label capslock_label_;
Gtk::Label scrolllock_label_;

std::string layout_format_;
std::string numlock_format_;
std::string capslock_format_;
std::string scrolllock_format_;
const std::chrono::seconds interval_;
std::string tooltip_format_ = "";
std::string icon_locked_;
std::string icon_unlocked_;
std::string devices_path_;
bool hide_single_;

struct libinput* libinput_;
std::unordered_map<std::string, struct libinput_device*> libinput_devices_;
std::set<int> binding_keys;
struct wl_seat *seat_;
struct wl_keyboard *keyboard_;
struct xkb_context *xkb_context_;
struct xkb_state *xkb_state_;
struct xkb_keymap *xkb_keymap_;
struct rxkb_context *rxkb_context_;

util::SleeperThread libinput_thread_, hotplug_thread_;
void update_layout(std::string full_name);
void update_led(Gtk::Label *, std::string format, std::string name, bool locked);

public:
void register_seat(struct wl_registry *, uint32_t name, uint32_t version);
void handle_keymap(uint32_t format, int32_t fd, uint32_t size);
void handle_modifiers(uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked,
uint32_t group);
void handle_seat_capabilities(unsigned int caps);
};

} // namespace waybar::modules
15 changes: 5 additions & 10 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ pipewire = dependency('libpipewire-0.3', required: get_option('pipewire'))
playerctl = dependency('playerctl', version : ['>=2.0.0'], required: get_option('mpris'))
libpulse = dependency('libpulse', required: get_option('pulseaudio'))
libudev = dependency('libudev', required: get_option('libudev'))
libevdev = dependency('libevdev', required: get_option('libevdev'))
libmpdclient = dependency('libmpdclient', required: get_option('mpd'))
xkbcommon = dependency('xkbcommon')
xkbregistry = dependency('xkbregistry')
libjack = dependency('jack', required: get_option('jack'))
libwireplumber = dependency('wireplumber-0.5', required: get_option('wireplumber'))
Expand Down Expand Up @@ -167,6 +167,7 @@ src_files = files(
'src/modules/disk.cpp',
'src/modules/idle_inhibitor.cpp',
'src/modules/image.cpp',
'src/modules/keyboard_state.cpp',
'src/modules/load.cpp',
'src/modules/temperature.cpp',
'src/modules/user.cpp',
Expand All @@ -193,6 +194,7 @@ man_files = files(
'man/waybar-disk.5.scd',
'man/waybar-idle-inhibitor.5.scd',
'man/waybar-image.5.scd',
'man/waybar-keyboard-state.5.scd',
'man/waybar-states.5.scd',
'man/waybar-menu.5.scd',
'man/waybar-temperature.5.scd',
Expand Down Expand Up @@ -453,13 +455,6 @@ if libudev.found() and (is_linux or libepoll.found())
)
endif

if libevdev.found() and (is_linux or libepoll.found()) and libinput.found() and (is_linux or libinotify.found())
add_project_arguments('-DHAVE_LIBEVDEV', language: 'cpp')
add_project_arguments('-DHAVE_LIBINPUT', language: 'cpp')
src_files += files('src/modules/keyboard_state.cpp')
man_files += files('man/waybar-keyboard-state.5.scd')
endif

if libmpdclient.found()
add_project_arguments('-DHAVE_LIBMPDCLIENT', language: 'cpp')
src_files += files(
Expand Down Expand Up @@ -548,11 +543,11 @@ executable(
libinotify,
libepoll,
libmpdclient,
libevdev,
gtk_layer_shell,
libsndio,
tz_dep,
xkbregistry,
xkbcommon,
xkbregistry,
cava,
libgps
],
Expand Down
12 changes: 4 additions & 8 deletions src/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@
#include "modules/backlight.hpp"
#include "modules/backlight_slider.hpp"
#endif
#ifdef HAVE_LIBEVDEV
#include "modules/keyboard_state.hpp"
#endif
#ifdef HAVE_GAMEMODE
#include "modules/gamemode.hpp"
#endif
Expand Down Expand Up @@ -120,6 +117,7 @@
#include "modules/cffi.hpp"
#include "modules/custom.hpp"
#include "modules/image.hpp"
#include "modules/keyboard_state.hpp"
#include "modules/temperature.hpp"
#include "modules/user.hpp"

Expand Down Expand Up @@ -277,6 +275,9 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name,
if (ref == "image") {
return new waybar::modules::Image(id, config_[name]);
}
if (ref == "keyboard-state") {
return new waybar::modules::KeyboardState(id, bar_, config_[name]);
}
#ifdef HAVE_DBUSMENU
if (ref == "tray") {
return new waybar::modules::SNI::Tray(id, bar_, config_[name]);
Expand All @@ -295,11 +296,6 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name,
return new waybar::modules::BacklightSlider(id, config_[name]);
}
#endif
#ifdef HAVE_LIBEVDEV
if (ref == "keyboard-state") {
return new waybar::modules::KeyboardState(id, bar_, config_[name]);
}
#endif
#ifdef HAVE_LIBPULSE
if (ref == "pulseaudio") {
return new waybar::modules::Pulseaudio(id, config_[name]);
Expand Down
Loading