Compare commits

...

14 Commits

Author SHA1 Message Date
a194755b4f
fixup! modules/custom: Allow json fields as format specifiers 2023-09-07 02:49:43 +02:00
165814a57f
modules/custom: Allow json fields as format specifiers 2023-08-30 07:57:11 +02:00
Alexis Rouillard
b665843085
Merge pull request #2429 from khaneliman/hyprland-urgent
Hyprland urgent class support
2023-08-24 17:00:40 +02:00
Austin Horstman
ee4fbc58f7
hyprland add urgent ipc support 2023-08-23 12:52:29 -05:00
Austin Horstman
3081b0c576
flake lock update 2023-08-23 12:14:35 -05:00
Alexis Rouillard
b7a527b122
Merge pull request #2424 from asas1asas200/feat-keyboard-bindingkey 2023-08-20 09:40:36 +02:00
asas1asas200
54a6668846 feat(keyboard-state): add binding-keys options 2023-08-20 08:33:34 +08:00
Alexis Rouillard
ed0f7453c9
Merge pull request #2420 from Alexays/chore-subprojects
chore: update subprojects
2023-08-18 10:39:15 +02:00
Alex
19fe929d1f chore: update subprojects 2023-08-18 09:48:03 +02:00
Alexis Rouillard
0a28b50a8c
Merge pull request #2413 from PucklaJ/bluetooth-no-controller
Add format-no-controller to bluetooth module and fix it still being visible if the format string is empty
2023-08-16 17:08:48 +02:00
PucklaJ
70bc318a01 Fix bluetooth module still being visible if format is empty 2023-08-16 16:30:59 +02:00
PucklaJ
22817089db Add no-controller format to bluetooth module 2023-08-16 15:34:06 +02:00
Alexis Rouillard
aecd80702e
Merge pull request #2412 from jpalus/simpleclock-fmt-compile-fix
Fix simpleclock module compilation with recent fmt
2023-08-16 14:35:39 +02:00
Jan Palus
abd7a0cf25
Fix simpleclock module compilation with recent fmt
both `format_` and `tooltip_format` are dynamically provided formats so
wrap them in `fmt::runtime()`
2023-08-16 14:32:48 +02:00
17 changed files with 239 additions and 140 deletions

76
flake.lock generated
View File

@ -2,15 +2,15 @@
"nodes": { "nodes": {
"devshell": { "devshell": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "nixpkgs": "nixpkgs",
"nixpkgs": "nixpkgs" "systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1676293499, "lastModified": 1692523566,
"narHash": "sha256-uIOTlTxvrXxpKeTvwBI1JGDGtCxMXE3BI0LFwoQMhiQ=", "narHash": "sha256-VDJDihK6jNebVw9y3qKCVD6+6QaC/x8kxZzL4MaIPPY=",
"owner": "numtide", "owner": "numtide",
"repo": "devshell", "repo": "devshell",
"rev": "71e3022e3ab20bbf1342640547ef5bc14fb43bf4", "rev": "d208c58e2f7afef838add5f18a9936b12a71d695",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -36,27 +36,15 @@
} }
}, },
"flake-utils": { "flake-utils": {
"locked": { "inputs": {
"lastModified": 1642700792, "systems": "systems_2"
"narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "846b2ae0fc4cc943637d3d1def4454213e203cba",
"type": "github"
}, },
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"locked": { "locked": {
"lastModified": 1676283394, "lastModified": 1689068808,
"narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=", "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073", "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -67,11 +55,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1643381941, "lastModified": 1677383253,
"narHash": "sha256-pHTwvnN4tTsEKkWlXQ8JMY423epos8wUOhthpwJjtpc=", "narHash": "sha256-UfpzWfSxkfXHnb4boXZNaKsAcUrZT9Hw+tao1oZxd08=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "5efc8ca954272c4376ac929f4c5ffefcc20551d5", "rev": "9952d6bc395f5841262b006fbace8dd7e143b634",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -83,11 +71,11 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1676300157, "lastModified": 1692638711,
"narHash": "sha256-1HjRzfp6LOLfcj/HJHdVKWAkX9QRAouoh6AjzJiIerU=", "narHash": "sha256-J0LgSFgJVGCC1+j5R2QndadWI1oumusg6hCtYAzLID4=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "545c7a31e5dedea4a6d372712a18e00ce097d462", "rev": "91a22f76cd1716f9d0149e8a5c68424bb691de15",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -101,9 +89,39 @@
"inputs": { "inputs": {
"devshell": "devshell", "devshell": "devshell",
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
"flake-utils": "flake-utils_2", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"
} }
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

View File

@ -47,17 +47,12 @@
let pkgs = import nixpkgs { let pkgs = import nixpkgs {
inherit system; inherit system;
overlays = [ devshell.overlay ]; overlays = [ devshell.overlays.default ];
}; };
in in
pkgs.devshell.mkShell { pkgs.devshell.mkShell {
imports = [ "${pkgs.devshell.extraModulesDir}/language/c.nix" ]; imports = [ "${pkgs.devshell.extraModulesDir}/language/c.nix" ];
commands = [
{
package = pkgs.devshell.cli;
help = "Per project developer environments";
}
];
devshell.packages = with pkgs; [ devshell.packages = with pkgs; [
clang-tools clang-tools
gdb gdb
@ -79,6 +74,7 @@
at-spi2-atk atkmm cairo cairomm catch2 fmt_8 fontconfig at-spi2-atk atkmm cairo cairomm catch2 fmt_8 fontconfig
gdk-pixbuf glibmm gtk3 harfbuzz pango pangomm wayland-protocols gdk-pixbuf glibmm gtk3 harfbuzz pango pangomm wayland-protocols
]); ]);
env = with pkgs; [ env = with pkgs; [
{ name = "CPLUS_INCLUDE_PATH"; prefix = "$DEVSHELL_DIR/include"; } { name = "CPLUS_INCLUDE_PATH"; prefix = "$DEVSHELL_DIR/include"; }
{ name = "PKG_CONFIG_PATH"; prefix = "$DEVSHELL_DIR/lib/pkgconfig"; } { name = "PKG_CONFIG_PATH"; prefix = "$DEVSHELL_DIR/lib/pkgconfig"; }

View File

@ -59,7 +59,8 @@ class Bluetooth : public ALabel {
auto getDeviceProperties(GDBusObject*, DeviceInfo&) -> bool; auto getDeviceProperties(GDBusObject*, DeviceInfo&) -> bool;
auto getControllerProperties(GDBusObject*, ControllerInfo&) -> bool; auto getControllerProperties(GDBusObject*, ControllerInfo&) -> bool;
auto findCurController(ControllerInfo&) -> bool; // Returns std::nullopt if no controller could be found
auto findCurController() -> std::optional<ControllerInfo>;
auto findConnectedDevices(const std::string&, std::vector<DeviceInfo>&) -> void; auto findConnectedDevices(const std::string&, std::vector<DeviceInfo>&) -> void;
#ifdef WANT_RFKILL #ifdef WANT_RFKILL
@ -68,7 +69,7 @@ class Bluetooth : public ALabel {
const std::unique_ptr<GDBusObjectManager, void (*)(GDBusObjectManager*)> manager_; const std::unique_ptr<GDBusObjectManager, void (*)(GDBusObjectManager*)> manager_;
std::string state_; std::string state_;
ControllerInfo cur_controller_; std::optional<ControllerInfo> cur_controller_;
std::vector<DeviceInfo> connected_devices_; std::vector<DeviceInfo> connected_devices_;
DeviceInfo cur_focussed_device_; DeviceInfo cur_focussed_device_;
std::string device_enumerate_; std::string device_enumerate_;

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/args.h>
#include <csignal> #include <csignal>
#include <string> #include <string>
@ -34,6 +35,7 @@ class Custom : public ALabel {
std::string alt_; std::string alt_;
std::string tooltip_; std::string tooltip_;
std::vector<std::string> class_; std::vector<std::string> class_;
fmt::dynamic_format_arg_store<fmt::format_context> fields_;
int percentage_; int percentage_;
FILE* fp_; FILE* fp_;
int pid_; int pid_;

View File

@ -22,10 +22,12 @@ class Workspace {
bool is_special() const { return is_special_; }; bool is_special() const { return is_special_; };
bool is_persistent() const { return is_persistent_; }; bool is_persistent() const { return is_persistent_; };
bool is_empty() const { return windows_ == 0; }; bool is_empty() const { return windows_ == 0; };
bool is_urgent() const { return is_urgent_; };
auto handle_clicked(GdkEventButton* bt) -> bool; auto handle_clicked(GdkEventButton* bt) -> bool;
void set_active(bool value = true) { active_ = value; }; void set_active(bool value = true) { active_ = value; };
void set_persistent(bool value = true) { is_persistent_ = value; }; void set_persistent(bool value = true) { is_persistent_ = value; };
void set_urgent(bool value = true) { is_urgent_ = value; };
void set_windows(uint value) { windows_ = value; }; void set_windows(uint value) { windows_ = value; };
void update(const std::string& format, const std::string& icon); void update(const std::string& format, const std::string& icon);
@ -38,6 +40,7 @@ class Workspace {
bool active_ = false; bool active_ = false;
bool is_special_ = false; bool is_special_ = false;
bool is_persistent_ = false; bool is_persistent_ = false;
bool is_urgent_ = false;
Gtk::Button button_; Gtk::Button button_;
Gtk::Box content_; Gtk::Box content_;
@ -62,6 +65,7 @@ class Workspaces : public AModule, public EventHandler {
void sort_workspaces(); void sort_workspaces();
void create_workspace(Json::Value& value); void create_workspace(Json::Value& value);
void remove_workspace(std::string name); void remove_workspace(std::string name);
void set_urgent_workspace(std::string windowaddress);
bool all_outputs_ = false; bool all_outputs_ = false;
bool show_special_ = false; bool show_special_ = false;

View File

@ -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_;
}; };

View File

@ -42,6 +42,10 @@ Addressed by *bluetooth*
typeof: string ++ typeof: string ++
This format is used when the displayed controller is connected to at least 1 device. This format is used when the displayed controller is connected to at least 1 device.
*format-no-controller*: ++
typeof: string ++
This format is used when no bluetooth controller could be found
*format-icons*: ++ *format-icons*: ++
typeof: array/object ++ typeof: array/object ++
Based on the current battery percentage (see section *EXPERIMENTAL BATTERY PERCENTAGE FEATURE*), the corresponding icon gets selected. ++ Based on the current battery percentage (see section *EXPERIMENTAL BATTERY PERCENTAGE FEATURE*), the corresponding icon gets selected. ++
@ -113,6 +117,10 @@ Addressed by *bluetooth*
typeof: string ++ typeof: string ++
This format is used when the displayed controller is connected to at least 1 device. This format is used when the displayed controller is connected to at least 1 device.
*tooltip-format-no-controller*: ++
typeof: string ++
This format is used when no bluetooth controller could be found
*tooltip-format-enumerate-connected*: ++ *tooltip-format-enumerate-connected*: ++
typeof: string ++ typeof: string ++
This format is used to define how each connected device should be displayed within the *device_enumerate* format replacement in the tooltip menu. This format is used to define how each connected device should be displayed within the *device_enumerate* format replacement in the tooltip menu.

View File

@ -76,3 +76,4 @@ Additional to workspace name matching, the following *format-icons* can be set.
- *#workspaces button.active* - *#workspaces button.active*
- *#workspaces button.persistent* - *#workspaces button.persistent*
- *#workspaces button.special* - *#workspaces button.special*
- *#workspaces button.urgent*

View File

@ -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.

View File

@ -92,28 +92,30 @@ waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value&
std::back_inserter(device_preference_), [](auto x) { return x.asString(); }); std::back_inserter(device_preference_), [](auto x) { return x.asString(); });
} }
// NOTE: assumption made that the controller that is selcected stays unchanged // NOTE: assumption made that the controller that is selected stays unchanged
// for duration of the module // for duration of the module
if (!findCurController(cur_controller_)) { if (cur_controller_ = findCurController(); !cur_controller_) {
if (config_["controller-alias"].isString()) { if (config_["controller-alias"].isString()) {
spdlog::error("findCurController() failed: no bluetooth controller found with alias '{}'", spdlog::error("findCurController() failed: no bluetooth controller found with alias '{}'",
config_["controller-alias"].asString()); config_["controller-alias"].asString());
} else { } else {
spdlog::error("findCurController() failed: no bluetooth controller found"); spdlog::error("findCurController() failed: no bluetooth controller found");
} }
event_box_.hide(); update();
return; } else {
} // These calls only make sense if a controller could be found
findConnectedDevices(cur_controller_.path, connected_devices_); findConnectedDevices(cur_controller_->path, connected_devices_);
g_signal_connect(manager_.get(), "interface-proxy-properties-changed",
G_CALLBACK(onInterfaceProxyPropertiesChanged), this);
g_signal_connect(manager_.get(), "interface-added", G_CALLBACK(onInterfaceAddedOrRemoved),
this);
g_signal_connect(manager_.get(), "interface-removed", G_CALLBACK(onInterfaceAddedOrRemoved),
this);
g_signal_connect(manager_.get(), "interface-proxy-properties-changed",
G_CALLBACK(onInterfaceProxyPropertiesChanged), this);
g_signal_connect(manager_.get(), "interface-added", G_CALLBACK(onInterfaceAddedOrRemoved), this);
g_signal_connect(manager_.get(), "interface-removed", G_CALLBACK(onInterfaceAddedOrRemoved),
this);
#ifdef WANT_RFKILL #ifdef WANT_RFKILL
rfkill_.on_update.connect(sigc::hide(sigc::mem_fun(*this, &Bluetooth::update))); rfkill_.on_update.connect(sigc::hide(sigc::mem_fun(*this, &Bluetooth::update)));
#endif #endif
}
dp.emit(); dp.emit();
} }
@ -144,12 +146,16 @@ auto waybar::modules::Bluetooth::update() -> void {
std::string state; std::string state;
std::string tooltip_format; std::string tooltip_format;
if (!cur_controller_.powered) if (cur_controller_) {
state = "off"; if (!cur_controller_->powered)
else if (!connected_devices_.empty()) state = "off";
state = "connected"; else if (!connected_devices_.empty())
else state = "connected";
state = "on"; else
state = "on";
} else {
state = "no-controller";
}
#ifdef WANT_RFKILL #ifdef WANT_RFKILL
if (rfkill_.getState()) state = "disabled"; if (rfkill_.getState()) state = "disabled";
#endif #endif
@ -187,8 +193,6 @@ auto waybar::modules::Bluetooth::update() -> void {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
} }
format_.empty() ? event_box_.hide() : event_box_.show();
auto update_style_context = [this](const std::string& style_class, bool in_next_state) { auto update_style_context = [this](const std::string& style_class, bool in_next_state) {
if (in_next_state && !label_.get_style_context()->has_class(style_class)) { if (in_next_state && !label_.get_style_context()->has_class(style_class)) {
label_.get_style_context()->add_class(style_class); label_.get_style_context()->add_class(style_class);
@ -196,25 +200,32 @@ auto waybar::modules::Bluetooth::update() -> void {
label_.get_style_context()->remove_class(style_class); label_.get_style_context()->remove_class(style_class);
} }
}; };
update_style_context("discoverable", cur_controller_.discoverable); update_style_context("discoverable", cur_controller_ ? cur_controller_->discoverable : false);
update_style_context("discovering", cur_controller_.discovering); update_style_context("discovering", cur_controller_ ? cur_controller_->discovering : false);
update_style_context("pairable", cur_controller_.pairable); update_style_context("pairable", cur_controller_ ? cur_controller_->pairable : false);
if (!state_.empty()) { if (!state_.empty()) {
update_style_context(state_, false); update_style_context(state_, false);
} }
update_style_context(state, true); update_style_context(state, true);
state_ = state; state_ = state;
label_.set_markup(fmt::format( if (format_.empty()) {
fmt::runtime(format_), fmt::arg("status", state_), event_box_.hide();
fmt::arg("num_connections", connected_devices_.size()), } else {
fmt::arg("controller_address", cur_controller_.address), event_box_.show();
fmt::arg("controller_address_type", cur_controller_.address_type), label_.set_markup(fmt::format(
fmt::arg("controller_alias", cur_controller_.alias), fmt::runtime(format_), fmt::arg("status", state_),
fmt::arg("device_address", cur_focussed_device_.address), fmt::arg("num_connections", connected_devices_.size()),
fmt::arg("device_address_type", cur_focussed_device_.address_type), fmt::arg("controller_address", cur_controller_ ? cur_controller_->address : "null"),
fmt::arg("device_alias", cur_focussed_device_.alias), fmt::arg("icon", icon_label), fmt::arg("controller_address_type",
fmt::arg("device_battery_percentage", cur_focussed_device_.battery_percentage.value_or(0)))); cur_controller_ ? cur_controller_->address_type : "null"),
fmt::arg("controller_alias", cur_controller_ ? cur_controller_->alias : "null"),
fmt::arg("device_address", cur_focussed_device_.address),
fmt::arg("device_address_type", cur_focussed_device_.address_type),
fmt::arg("device_alias", cur_focussed_device_.alias), fmt::arg("icon", icon_label),
fmt::arg("device_battery_percentage",
cur_focussed_device_.battery_percentage.value_or(0))));
}
if (tooltipEnabled()) { if (tooltipEnabled()) {
bool tooltip_enumerate_connections_ = config_["tooltip-format-enumerate-connected"].isString(); bool tooltip_enumerate_connections_ = config_["tooltip-format-enumerate-connected"].isString();
@ -250,9 +261,10 @@ auto waybar::modules::Bluetooth::update() -> void {
label_.set_tooltip_text(fmt::format( label_.set_tooltip_text(fmt::format(
fmt::runtime(tooltip_format), fmt::arg("status", state_), fmt::runtime(tooltip_format), fmt::arg("status", state_),
fmt::arg("num_connections", connected_devices_.size()), fmt::arg("num_connections", connected_devices_.size()),
fmt::arg("controller_address", cur_controller_.address), fmt::arg("controller_address", cur_controller_ ? cur_controller_->address : "null"),
fmt::arg("controller_address_type", cur_controller_.address_type), fmt::arg("controller_address_type",
fmt::arg("controller_alias", cur_controller_.alias), cur_controller_ ? cur_controller_->address_type : "null"),
fmt::arg("controller_alias", cur_controller_ ? cur_controller_->alias : "null"),
fmt::arg("device_address", cur_focussed_device_.address), fmt::arg("device_address", cur_focussed_device_.address),
fmt::arg("device_address_type", cur_focussed_device_.address_type), fmt::arg("device_address_type", cur_focussed_device_.address_type),
fmt::arg("device_alias", cur_focussed_device_.alias), fmt::arg("icon", icon_tooltip), fmt::arg("device_alias", cur_focussed_device_.alias), fmt::arg("icon", icon_tooltip),
@ -292,8 +304,8 @@ auto waybar::modules::Bluetooth::onInterfaceProxyPropertiesChanged(
Bluetooth* bt = static_cast<Bluetooth*>(user_data); Bluetooth* bt = static_cast<Bluetooth*>(user_data);
if (interface_name == "org.bluez.Adapter1") { if (interface_name == "org.bluez.Adapter1") {
if (object_path == bt->cur_controller_.path) { if (object_path == bt->cur_controller_->path) {
bt->getControllerProperties(G_DBUS_OBJECT(object_proxy), bt->cur_controller_); bt->getControllerProperties(G_DBUS_OBJECT(object_proxy), *bt->cur_controller_);
bt->dp.emit(); bt->dp.emit();
} }
} else if (interface_name == "org.bluez.Device1" || interface_name == "org.bluez.Battery1") { } else if (interface_name == "org.bluez.Device1" || interface_name == "org.bluez.Battery1") {
@ -378,22 +390,23 @@ auto waybar::modules::Bluetooth::getControllerProperties(GDBusObject* object,
return false; return false;
} }
auto waybar::modules::Bluetooth::findCurController(ControllerInfo& controller_info) -> bool { auto waybar::modules::Bluetooth::findCurController() -> std::optional<ControllerInfo> {
bool found_controller = false; std::optional<ControllerInfo> controller_info;
GList* objects = g_dbus_object_manager_get_objects(manager_.get()); GList* objects = g_dbus_object_manager_get_objects(manager_.get());
for (GList* l = objects; l != NULL; l = l->next) { for (GList* l = objects; l != NULL; l = l->next) {
GDBusObject* object = G_DBUS_OBJECT(l->data); GDBusObject* object = G_DBUS_OBJECT(l->data);
if (getControllerProperties(object, controller_info) && ControllerInfo info;
if (getControllerProperties(object, info) &&
(!config_["controller-alias"].isString() || (!config_["controller-alias"].isString() ||
config_["controller-alias"].asString() == controller_info.alias)) { config_["controller-alias"].asString() == info.alias)) {
found_controller = true; controller_info = std::move(info);
break; break;
} }
} }
g_list_free_full(objects, g_object_unref); g_list_free_full(objects, g_object_unref);
return found_controller; return controller_info;
} }
auto waybar::modules::Bluetooth::findConnectedDevices(const std::string& cur_controller_path, auto waybar::modules::Bluetooth::findConnectedDevices(const std::string& cur_controller_path,
@ -404,7 +417,7 @@ auto waybar::modules::Bluetooth::findConnectedDevices(const std::string& cur_con
GDBusObject* object = G_DBUS_OBJECT(l->data); GDBusObject* object = G_DBUS_OBJECT(l->data);
DeviceInfo device; DeviceInfo device;
if (getDeviceProperties(object, device) && device.connected && if (getDeviceProperties(object, device) && device.connected &&
device.paired_controller == cur_controller_.path) { device.paired_controller == cur_controller_->path) {
connected_devices.push_back(device); connected_devices.push_back(device);
} }
} }

View File

@ -122,14 +122,14 @@ auto waybar::modules::Custom::update() -> void {
(output_.out.empty() || output_.exit_code != 0)) { (output_.out.empty() || output_.exit_code != 0)) {
event_box_.hide(); event_box_.hide();
} else { } else {
fields_.clear();
if (config_["return-type"].asString() == "json") { if (config_["return-type"].asString() == "json") {
parseOutputJson(); parseOutputJson();
} else { } else {
parseOutputRaw(); parseOutputRaw();
} }
auto str = fmt::format(fmt::runtime(format_), text_, fmt::arg("alt", alt_), auto str = fmt::vformat(format_, fields_);
fmt::arg("icon", getIcon(percentage_, alt_)),
fmt::arg("percentage", percentage_));
if (str.empty()) { if (str.empty()) {
event_box_.hide(); event_box_.hide();
} else { } else {
@ -173,6 +173,7 @@ void waybar::modules::Custom::parseOutputRaw() {
} else { } else {
text_ = line; text_ = line;
} }
fields_.push_back(text_);
tooltip_ = line; tooltip_ = line;
class_.clear(); class_.clear();
} else if (i == 1) { } else if (i == 1) {
@ -189,32 +190,45 @@ void waybar::modules::Custom::parseOutputRaw() {
void waybar::modules::Custom::parseOutputJson() { void waybar::modules::Custom::parseOutputJson() {
std::istringstream output(output_.out); std::istringstream output(output_.out);
std::string line; std::string line;
getline(output, line);
class_.clear(); class_.clear();
while (getline(output, line)) { auto parsed = parser_.parse(line);
auto parsed = parser_.parse(line);
// Preserve order so that first "{}" is resolved to "text" for backwards compatability
if (parsed["text"].isString()) {
auto str = parsed["text"].asString();
if (config_["escape"].isBool() && config_["escape"].asBool()) { if (config_["escape"].isBool() && config_["escape"].asBool()) {
text_ = Glib::Markup::escape_text(parsed["text"].asString()); str = Glib::Markup::escape_text(str);
} else {
text_ = parsed["text"].asString();
} }
fields_.push_back(str);
}
for (auto const& key : parsed.getMemberNames()) {
if (!parsed[key].isString()) continue;
auto str = parsed[key].asString();
if (config_["escape"].isBool() && config_["escape"].asBool()) { if (config_["escape"].isBool() && config_["escape"].asBool()) {
alt_ = Glib::Markup::escape_text(parsed["alt"].asString()); str = Glib::Markup::escape_text(str);
} else {
alt_ = parsed["alt"].asString();
} }
tooltip_ = parsed["tooltip"].asString(); fields_.push_back(fmt::arg(key.c_str(), str));
if (parsed["class"].isString()) { }
class_.push_back(parsed["class"].asString());
} else if (parsed["class"].isArray()) { tooltip_ = parsed["tooltip"].asString();
for (auto const& c : parsed["class"]) { if (parsed["class"].isString()) {
class_.push_back(c.asString()); class_.push_back(parsed["class"].asString());
} } else if (parsed["class"].isArray()) {
for (auto const& c : parsed["class"]) {
class_.push_back(c.asString());
} }
if (!parsed["percentage"].asString().empty() && parsed["percentage"].isNumeric()) { }
percentage_ = (int)lround(parsed["percentage"].asFloat());
} else { if (!parsed["percentage"].asString().empty() && parsed["percentage"].isNumeric()) {
percentage_ = 0; percentage_ = (int)lround(parsed["percentage"].asFloat());
} } else {
break; percentage_ = 0;
}
// Allow overriding icon from json, otherwise use percentage based icon
if (parsed["icon"].isNull()) {
fields_.push_back(fmt::arg("icon", getIcon(percentage_, alt_)));
} }
} }

View File

@ -58,6 +58,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
gIPC->registerForIPC("openwindow", this); gIPC->registerForIPC("openwindow", this);
gIPC->registerForIPC("closewindow", this); gIPC->registerForIPC("closewindow", this);
gIPC->registerForIPC("movewindow", this); gIPC->registerForIPC("movewindow", this);
gIPC->registerForIPC("urgent", this);
} }
auto Workspaces::update() -> void { auto Workspaces::update() -> void {
@ -75,6 +76,9 @@ auto Workspaces::update() -> void {
for (auto &workspace : workspaces_) { for (auto &workspace : workspaces_) {
workspace->set_active(workspace->name() == active_workspace_name_); workspace->set_active(workspace->name() == active_workspace_name_);
if (workspace->name() == active_workspace_name_ && workspace.get()->is_urgent()) {
workspace->set_urgent(false);
}
std::string &workspace_icon = icons_map_[""]; std::string &workspace_icon = icons_map_[""];
if (with_icon_) { if (with_icon_) {
workspace_icon = workspace->select_icon(icons_map_); workspace_icon = workspace->select_icon(icons_map_);
@ -126,6 +130,8 @@ void Workspaces::onEvent(const std::string &ev) {
} }
} else if (eventName == "openwindow" || eventName == "closewindow" || eventName == "movewindow") { } else if (eventName == "openwindow" || eventName == "closewindow" || eventName == "movewindow") {
update_window_count(); update_window_count();
} else if (eventName == "urgent") {
set_urgent_workspace(payload);
} }
dp.emit(); dp.emit();
@ -323,6 +329,7 @@ void Workspace::update(const std::string &format, const std::string &icon) {
add_or_remove_class(style_context, active(), "active"); add_or_remove_class(style_context, active(), "active");
add_or_remove_class(style_context, is_special(), "special"); add_or_remove_class(style_context, is_special(), "special");
add_or_remove_class(style_context, is_empty(), "persistent"); add_or_remove_class(style_context, is_empty(), "persistent");
add_or_remove_class(style_context, is_urgent(), "urgent");
label_.set_markup(fmt::format(fmt::runtime(format), fmt::arg("id", id()), label_.set_markup(fmt::format(fmt::runtime(format), fmt::arg("id", id()),
fmt::arg("name", name()), fmt::arg("icon", icon))); fmt::arg("name", name()), fmt::arg("icon", icon)));
@ -419,4 +426,23 @@ auto Workspace::handle_clicked(GdkEventButton *bt) -> bool {
return false; return false;
} }
void Workspaces::set_urgent_workspace(std::string windowaddress) {
const Json::Value clients_json = gIPC->getSocket1JsonReply("clients");
int workspace_id;
for (Json::Value client_json : clients_json) {
if (client_json["address"].asString().ends_with(windowaddress)) {
workspace_id = client_json["workspace"]["id"].asInt();
break;
}
}
auto workspace =
std::find_if(workspaces_.begin(), workspaces_.end(),
[&](std::unique_ptr<Workspace> &x) { return x->id() == workspace_id; });
if (workspace->get() != nullptr) {
workspace->get()->set_urgent();
}
}
} // namespace waybar::modules::hyprland } // namespace waybar::modules::hyprland

View File

@ -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;
} }
} }
} }

View File

@ -18,13 +18,13 @@ auto waybar::modules::Clock::update() -> void {
tzset(); // Update timezone information tzset(); // Update timezone information
auto now = std::chrono::system_clock::now(); auto now = std::chrono::system_clock::now();
auto localtime = fmt::localtime(std::chrono::system_clock::to_time_t(now)); auto localtime = fmt::localtime(std::chrono::system_clock::to_time_t(now));
auto text = fmt::format(format_, localtime); auto text = fmt::format(fmt::runtime(format_), localtime);
label_.set_markup(text); label_.set_markup(text);
if (tooltipEnabled()) { if (tooltipEnabled()) {
if (config_["tooltip-format"].isString()) { if (config_["tooltip-format"].isString()) {
auto tooltip_format = config_["tooltip-format"].asString(); auto tooltip_format = config_["tooltip-format"].asString();
auto tooltip_text = fmt::format(tooltip_format, localtime); auto tooltip_text = fmt::format(fmt::runtime(tooltip_format), localtime);
label_.set_tooltip_text(tooltip_text); label_.set_tooltip_text(tooltip_text);
} else { } else {
label_.set_tooltip_text(text); label_.set_tooltip_text(text);

View File

@ -1,10 +1,10 @@
[wrap-file] [wrap-file]
directory = Catch2-3.3.2 directory = Catch2-3.4.0
source_url = https://github.com/catchorg/Catch2/archive/v3.3.2.tar.gz source_url = https://github.com/catchorg/Catch2/archive/v3.4.0.tar.gz
source_filename = Catch2-3.3.2.tar.gz source_filename = Catch2-3.4.0.tar.gz
source_hash = 8361907f4d9bff3ae7c1edb027f813659f793053c99b67837a0c0375f065bae2 source_hash = 122928b814b75717316c71af69bd2b43387643ba076a6ec16e7882bfb2dfacbb
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/catch2_3.3.2-1/Catch2-3.3.2.tar.gz source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/catch2_3.4.0-1/Catch2-3.4.0.tar.gz
wrapdb_version = 3.3.2-1 wrapdb_version = 3.4.0-1
[provide] [provide]
catch2 = catch2_dep catch2 = catch2_dep

View File

@ -1,12 +1,13 @@
[wrap-file] [wrap-file]
directory = fmt-8.1.1 directory = fmt-9.1.0
source_url = https://github.com/fmtlib/fmt/archive/8.1.1.tar.gz source_url = https://github.com/fmtlib/fmt/archive/9.1.0.tar.gz
source_filename = fmt-8.1.1.tar.gz source_filename = fmt-9.1.0.tar.gz
source_hash = 3d794d3cf67633b34b2771eb9f073bde87e846e0d395d254df7b211ef1ec7346 source_hash = 5dea48d1fcddc3ec571ce2058e13910a0d4a6bab4cc09a809d8b1dd1c88ae6f2
patch_filename = fmt_8.1.1-1_patch.zip patch_filename = fmt_9.1.0-2_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/fmt_8.1.1-1/get_patch patch_url = https://wrapdb.mesonbuild.com/v2/fmt_9.1.0-2/get_patch
patch_hash = 6035a67c7a8c90bed74c293c7265c769f47a69816125f7566bccb8e2543cee5e patch_hash = 23e8c4829f3e63f509b5643fe6bb87cbed39eae9594c451b338475d14d051967
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/fmt_9.1.0-2/fmt-9.1.0.tar.gz
wrapdb_version = 9.1.0-2
[provide] [provide]
fmt = fmt_dep fmt = fmt_dep

View File

@ -1,13 +1,12 @@
[wrap-file] [wrap-file]
directory = spdlog-1.10.0 directory = spdlog-1.11.0
source_url = https://github.com/gabime/spdlog/archive/v1.10.0.tar.gz source_url = https://github.com/gabime/spdlog/archive/v1.11.0.tar.gz
source_filename = v1.10.0.tar.gz source_filename = v1.11.0.tar.gz
source_hash = 697f91700237dbae2326b90469be32b876b2b44888302afbc7aceb68bcfe8224 source_hash = ca5cae8d6cac15dae0ec63b21d6ad3530070650f68076f3a4a862ca293a858bb
patch_filename = spdlog_1.10.0-3_patch.zip patch_filename = spdlog_1.11.0-2_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/spdlog_1.10.0-3/get_patch patch_url = https://wrapdb.mesonbuild.com/v2/spdlog_1.11.0-2/get_patch
patch_hash = 5bb07b4af1e971817d4b886efbe077aaf6c36d72d3d7e461bbcf6631f3725704 patch_hash = db1364fe89502ac67f245a6c8c51290a52afd74a51eed26fa9ecb5b3443df57a
wrapdb_version = 1.10.0-3 wrapdb_version = 1.11.0-2
[provide] [provide]
spdlog = spdlog_dep spdlog = spdlog_dep