From e19aa1d43af943d83eae532833b2ada0baaed31f Mon Sep 17 00:00:00 2001 From: Thomas Sarboni Date: Sat, 30 Jan 2021 01:41:45 +0100 Subject: [PATCH 01/18] [sway/window] Add app_id to usable fields in title --- src/modules/sway/window.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/sway/window.cpp b/src/modules/sway/window.cpp index e9203451..d8f113f7 100644 --- a/src/modules/sway/window.cpp +++ b/src/modules/sway/window.cpp @@ -56,7 +56,8 @@ auto Window::update() -> void { bar_.window.get_style_context()->remove_class("solo"); bar_.window.get_style_context()->remove_class("empty"); } - label_.set_markup(fmt::format(format_, window_)); + label_.set_markup(fmt::format(format_, fmt::arg("title", window_), + fmt::arg("app_id", app_id_))); if (tooltipEnabled()) { label_.set_tooltip_text(window_); } From d2a1f4175052f47ee618feaf32e7034bea63f6d3 Mon Sep 17 00:00:00 2001 From: nullobsi Date: Sun, 31 Jan 2021 11:53:53 -0800 Subject: [PATCH 02/18] Use g_unichar_iswide to properly align calendar on CJK locales --- include/util/ustring_clen.hpp | 5 +++++ meson.build | 1 + src/modules/clock.cpp | 15 ++++++++++----- src/util/ustring_clen.cpp | 9 +++++++++ 4 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 include/util/ustring_clen.hpp create mode 100644 src/util/ustring_clen.cpp diff --git a/include/util/ustring_clen.hpp b/include/util/ustring_clen.hpp new file mode 100644 index 00000000..cddd2e1a --- /dev/null +++ b/include/util/ustring_clen.hpp @@ -0,0 +1,5 @@ +#pragma once +#include + +// calculate column width of ustring +int ustring_clen(const Glib::ustring &str); \ No newline at end of file diff --git a/meson.build b/meson.build index 49e71f26..373ec86b 100644 --- a/meson.build +++ b/meson.build @@ -147,6 +147,7 @@ src_files = files( 'src/main.cpp', 'src/bar.cpp', 'src/client.cpp', + 'src/util/ustring_clen.cpp' ) if is_linux diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 5b2c3f43..0aade690 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -5,6 +5,7 @@ #include #include +#include "util/ustring_clen.hpp" #ifdef HAVE_LANGINFO_1STDAY #include #include @@ -154,12 +155,16 @@ auto waybar::modules::Clock::weekdays_header(const date::weekday& first_dow, std do { if (wd != first_dow) os << ' '; Glib::ustring wd_ustring(date::format(locale_, "%a", wd)); - auto wd_len = wd_ustring.length(); - if (wd_len > 2) { - wd_ustring = wd_ustring.substr(0, 2); - wd_len = 2; + auto clen = ustring_clen(wd_ustring); + auto wd_len = wd_ustring.length(); + fmt::print("{} {}\n", clen, wd_len); + while (clen > 2) { + wd_ustring = wd_ustring.substr(0, wd_len-1); + wd_len--; + clen = ustring_clen(wd_ustring); } - const std::string pad(2 - wd_len, ' '); + fmt::print("{} {}", clen, wd_len); + const std::string pad(2 - clen, ' '); os << pad << wd_ustring; } while (++wd != first_dow); os << "\n"; diff --git a/src/util/ustring_clen.cpp b/src/util/ustring_clen.cpp new file mode 100644 index 00000000..cd7d9cf5 --- /dev/null +++ b/src/util/ustring_clen.cpp @@ -0,0 +1,9 @@ +#include "util/ustring_clen.hpp" + +int ustring_clen(const Glib::ustring &str){ + int total = 0; + for (auto i = str.begin(); i != str.end(); ++i) { + total += g_unichar_iswide(*i) + 1; + } + return total; +} \ No newline at end of file From ecba117dc05b6677c951c4b1c3f1dd2442494aab Mon Sep 17 00:00:00 2001 From: nullobsi Date: Sun, 31 Jan 2021 11:56:25 -0800 Subject: [PATCH 03/18] remove unnessecary logging --- src/modules/clock.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 0aade690..22bedc78 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -157,13 +157,11 @@ auto waybar::modules::Clock::weekdays_header(const date::weekday& first_dow, std Glib::ustring wd_ustring(date::format(locale_, "%a", wd)); auto clen = ustring_clen(wd_ustring); auto wd_len = wd_ustring.length(); - fmt::print("{} {}\n", clen, wd_len); while (clen > 2) { wd_ustring = wd_ustring.substr(0, wd_len-1); wd_len--; clen = ustring_clen(wd_ustring); } - fmt::print("{} {}", clen, wd_len); const std::string pad(2 - clen, ' '); os << pad << wd_ustring; } while (++wd != first_dow); From 8c70513a248fb9c22ff37d14e9a06b983099ab71 Mon Sep 17 00:00:00 2001 From: nullobsi Date: Sun, 31 Jan 2021 13:58:41 -0800 Subject: [PATCH 04/18] add common `align` config property to set text alignment add fixed-length property to set the fixed width of the label --- src/ALabel.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ALabel.cpp b/src/ALabel.cpp index 9371a0e7..4d15cc17 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -28,6 +28,15 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st label_.set_single_line_mode(true); } + if (config_["fixed-length"].isUInt()) { + label_.set_width_chars(config_["fixed-length"].asUInt()); + } + + if (config_["align"].isDouble()) { + auto align = config_["align"].asFloat(); + label_.set_xalign(align); + } + if (config_["rotate"].isUInt()) { label_.set_angle(config["rotate"].asUInt()); } From c8d7b6fa92ea006d35b4c425fb38fb8fe83f7d98 Mon Sep 17 00:00:00 2001 From: nullobsi Date: Sun, 31 Jan 2021 14:03:49 -0800 Subject: [PATCH 05/18] rename fixed-length to min-length --- src/ALabel.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ALabel.cpp b/src/ALabel.cpp index 4d15cc17..ed5740a2 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -20,7 +20,7 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st } event_box_.add(label_); if (config_["max-length"].isUInt()) { - label_.set_max_width_chars(config_["max-length"].asUInt()); + label_.set_max_width_chars(config_["max-length"].asInt()); label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END); label_.set_single_line_mode(true); } else if (ellipsize && label_.get_max_width_chars() == -1) { @@ -28,8 +28,8 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st label_.set_single_line_mode(true); } - if (config_["fixed-length"].isUInt()) { - label_.set_width_chars(config_["fixed-length"].asUInt()); + if (config_["min-length"].isUInt()) { + label_.set_width_chars(config_["min-length"].asUInt()); } if (config_["align"].isDouble()) { From 72cd753c0259f695adc4bf372048256bc403a47d Mon Sep 17 00:00:00 2001 From: nullobsi Date: Mon, 1 Feb 2021 01:44:51 -0800 Subject: [PATCH 06/18] align should use rotate property --- src/ALabel.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ALabel.cpp b/src/ALabel.cpp index ed5740a2..8d9c9b41 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -32,14 +32,24 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st label_.set_width_chars(config_["min-length"].asUInt()); } - if (config_["align"].isDouble()) { - auto align = config_["align"].asFloat(); - label_.set_xalign(align); - } + uint rotate = 0; if (config_["rotate"].isUInt()) { - label_.set_angle(config["rotate"].asUInt()); + rotate = config["rotate"].asUInt(); + label_.set_angle(rotate); } + + if (config_["align"].isDouble()) { + auto align = config_["align"].asFloat(); + if (rotate == 90 || rotate == 270) { + label_.set_yalign(align); + } else { + label_.set_xalign(align); + } + + } + + } auto ALabel::update() -> void { From 97f7050d7defb4dc3e23a1709ce063dbfaa38d9f Mon Sep 17 00:00:00 2001 From: nullobsi Date: Mon, 1 Feb 2021 08:34:51 -0800 Subject: [PATCH 07/18] Update man pages --- man/waybar-backlight.5.scd | 8 ++++++++ man/waybar-battery.5.scd | 8 ++++++++ man/waybar-bluetooth.5.scd | 8 ++++++++ man/waybar-clock.5.scd | 8 ++++++++ man/waybar-cpu.5.scd | 8 ++++++++ man/waybar-custom.5.scd | 8 ++++++++ man/waybar-disk.5.scd | 8 ++++++++ man/waybar-idle-inhibitor.5.scd | 8 ++++++++ man/waybar-memory.5.scd | 8 ++++++++ man/waybar-mpd.5.scd | 8 ++++++++ man/waybar-network.5.scd | 8 ++++++++ man/waybar-pulseaudio.5.scd | 8 ++++++++ man/waybar-sndio.5.scd | 8 ++++++++ man/waybar-sway-language.5.scd | 8 ++++++++ man/waybar-sway-mode.5.scd | 8 ++++++++ man/waybar-sway-window.5.scd | 8 ++++++++ man/waybar-temperature.5.scd | 8 ++++++++ 17 files changed, 136 insertions(+) diff --git a/man/waybar-backlight.5.scd b/man/waybar-backlight.5.scd index e6116e3e..d14e4f24 100644 --- a/man/waybar-backlight.5.scd +++ b/man/waybar-backlight.5.scd @@ -24,6 +24,14 @@ The *backlight* module displays the current backlight level. typeof: integer ++ The maximum length in characters the module should display. +*min-length*: ++ + typeof: integer ++ + The minimum length in characters the module should take up. + +*align*: ++ + typeof: float ++ + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + *rotate*: ++ typeof: integer ++ Positive value to rotate the text label. diff --git a/man/waybar-battery.5.scd b/man/waybar-battery.5.scd index a4650cd6..48c2ee19 100644 --- a/man/waybar-battery.5.scd +++ b/man/waybar-battery.5.scd @@ -55,6 +55,14 @@ The *battery* module displays the current capacity and state (eg. charging) of y typeof: integer++ The maximum length in character the module should display. +*min-length*: ++ + typeof: integer ++ + The minimum length in characters the module should take up. + +*align*: ++ + typeof: float ++ + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + *rotate*: ++ typeof: integer++ Positive value to rotate the text label. diff --git a/man/waybar-bluetooth.5.scd b/man/waybar-bluetooth.5.scd index 5d7d7dd5..0cd9386a 100644 --- a/man/waybar-bluetooth.5.scd +++ b/man/waybar-bluetooth.5.scd @@ -35,6 +35,14 @@ Addressed by *bluetooth* typeof: integer ++ The maximum length in character the module should display. +*min-length*: ++ + typeof: integer ++ + The minimum length in characters the module should take up. + +*align*: ++ + typeof: float ++ + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. diff --git a/man/waybar-clock.5.scd b/man/waybar-clock.5.scd index 9f36c435..28688ee9 100644 --- a/man/waybar-clock.5.scd +++ b/man/waybar-clock.5.scd @@ -45,6 +45,14 @@ The *clock* module displays the current date and time. typeof: integer ++ The maximum length in character the module should display. +*min-length*: ++ + typeof: integer ++ + The minimum length in characters the module should take up. + +*align*: ++ + typeof: float ++ + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + *rotate*: ++ typeof: integer ++ Positive value to rotate the text label. diff --git a/man/waybar-cpu.5.scd b/man/waybar-cpu.5.scd index cb83134f..c8b12e26 100644 --- a/man/waybar-cpu.5.scd +++ b/man/waybar-cpu.5.scd @@ -24,6 +24,14 @@ The *cpu* module displays the current cpu utilization. typeof: integer ++ The maximum length in character the module should display. +*min-length*: ++ + typeof: integer ++ + The minimum length in characters the module should take up. + +*align*: ++ + typeof: float ++ + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + *rotate*: ++ typeof: integer ++ Positive value to rotate the text label. diff --git a/man/waybar-custom.5.scd b/man/waybar-custom.5.scd index 3e820c63..8f9dcfaf 100644 --- a/man/waybar-custom.5.scd +++ b/man/waybar-custom.5.scd @@ -67,6 +67,14 @@ Addressed by *custom/* typeof: integer ++ The maximum length in character the module should display. +*min-length*: ++ + typeof: integer ++ + The minimum length in characters the module should take up. + +*align*: ++ + typeof: float ++ + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. diff --git a/man/waybar-disk.5.scd b/man/waybar-disk.5.scd index 431d7c8f..58797141 100644 --- a/man/waybar-disk.5.scd +++ b/man/waybar-disk.5.scd @@ -39,6 +39,14 @@ Addressed by *disk* typeof: integer ++ The maximum length in character the module should display. +*min-length*: ++ + typeof: integer ++ + The minimum length in characters the module should take up. + +*align*: ++ + typeof: float ++ + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. diff --git a/man/waybar-idle-inhibitor.5.scd b/man/waybar-idle-inhibitor.5.scd index 9d231d86..0b0bdd03 100644 --- a/man/waybar-idle-inhibitor.5.scd +++ b/man/waybar-idle-inhibitor.5.scd @@ -27,6 +27,14 @@ screensaving, also known as "presentation mode". typeof: integer ++ The maximum length in character the module should display. +*min-length*: ++ + typeof: integer ++ + The minimum length in characters the module should take up. + +*align*: ++ + typeof: float ++ + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. A click also toggles the state diff --git a/man/waybar-memory.5.scd b/man/waybar-memory.5.scd index 81c62165..3ff4c35b 100644 --- a/man/waybar-memory.5.scd +++ b/man/waybar-memory.5.scd @@ -34,6 +34,14 @@ Addressed by *memory* typeof: integer ++ The maximum length in character the module should display. +*min-length*: ++ + typeof: integer ++ + The minimum length in characters the module should take up. + +*align*: ++ + typeof: float ++ + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. diff --git a/man/waybar-mpd.5.scd b/man/waybar-mpd.5.scd index 8c33c624..5bbc00a7 100644 --- a/man/waybar-mpd.5.scd +++ b/man/waybar-mpd.5.scd @@ -81,6 +81,14 @@ Addressed by *mpd* typeof: integer ++ The maximum length in character the module should display. +*min-length*: ++ + typeof: integer ++ + The minimum length in characters the module should take up. + +*align*: ++ + typeof: float ++ + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. diff --git a/man/waybar-network.5.scd b/man/waybar-network.5.scd index ab459ae0..f274881e 100644 --- a/man/waybar-network.5.scd +++ b/man/waybar-network.5.scd @@ -64,6 +64,14 @@ Addressed by *network* typeof: integer ++ The maximum length in character the module should display. +*min-length*: ++ + typeof: integer ++ + The minimum length in characters the module should take up. + +*align*: ++ + typeof: float ++ + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. diff --git a/man/waybar-pulseaudio.5.scd b/man/waybar-pulseaudio.5.scd index c3f50e0b..d894290f 100644 --- a/man/waybar-pulseaudio.5.scd +++ b/man/waybar-pulseaudio.5.scd @@ -50,6 +50,14 @@ Additionally you can control the volume by scrolling *up* or *down* while the cu typeof: integer ++ The maximum length in character the module should display. +*min-length*: ++ + typeof: integer ++ + The minimum length in characters the module should take up. + +*align*: ++ + typeof: float ++ + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + *scroll-step*: ++ typeof: float ++ default: 1.0 ++ diff --git a/man/waybar-sndio.5.scd b/man/waybar-sndio.5.scd index a61c3325..90a73f48 100644 --- a/man/waybar-sndio.5.scd +++ b/man/waybar-sndio.5.scd @@ -26,6 +26,14 @@ cursor is over the module, and clicking on the module toggles mute. typeof: integer ++ The maximum length in character the module should display. +*min-length*: ++ + typeof: integer ++ + The minimum length in characters the module should take up. + +*align*: ++ + typeof: float ++ + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + *scroll-step*: ++ typeof: int ++ default: 5 ++ diff --git a/man/waybar-sway-language.5.scd b/man/waybar-sway-language.5.scd index a288cca9..769924f0 100644 --- a/man/waybar-sway-language.5.scd +++ b/man/waybar-sway-language.5.scd @@ -25,6 +25,14 @@ Addressed by *sway/language* typeof: integer ++ The maximum length in character the module should display. +*min-length*: ++ + typeof: integer ++ + The minimum length in characters the module should take up. + +*align*: ++ + typeof: float ++ + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. diff --git a/man/waybar-sway-mode.5.scd b/man/waybar-sway-mode.5.scd index 958a1edb..b8b59cd3 100644 --- a/man/waybar-sway-mode.5.scd +++ b/man/waybar-sway-mode.5.scd @@ -25,6 +25,14 @@ Addressed by *sway/mode* typeof: integer ++ The maximum length in character the module should display. +*min-length*: ++ + typeof: integer ++ + The minimum length in characters the module should take up. + +*align*: ++ + typeof: float ++ + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. diff --git a/man/waybar-sway-window.5.scd b/man/waybar-sway-window.5.scd index 4863a76c..40250e6f 100644 --- a/man/waybar-sway-window.5.scd +++ b/man/waybar-sway-window.5.scd @@ -25,6 +25,14 @@ Addressed by *sway/window* typeof: integer ++ The maximum length in character the module should display. +*min-length*: ++ + typeof: integer ++ + The minimum length in characters the module should take up. + +*align*: ++ + typeof: float ++ + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + *on-click*: ++ typeof: string ++ Command to execute when clicked on the module. diff --git a/man/waybar-temperature.5.scd b/man/waybar-temperature.5.scd index 7810a59b..8d11e517 100644 --- a/man/waybar-temperature.5.scd +++ b/man/waybar-temperature.5.scd @@ -63,6 +63,14 @@ Addressed by *temperature* typeof: integer ++ The maximum length in characters the module should display. +*min-length*: ++ + typeof: integer ++ + The minimum length in characters the module should take up. + +*align*: ++ + typeof: float ++ + The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + *on-click*: ++ typeof: string ++ Command to execute when you clicked on the module. From ac6667b1c979aa9493c4ae033d121a712743e484 Mon Sep 17 00:00:00 2001 From: jgmdev Date: Tue, 2 Feb 2021 01:03:28 -0400 Subject: [PATCH 08/18] [wlr/taskbar] More icon search improvements. * Added ~/.local/share prefix to search in user defined apps. * Add support for apps that don't properly set an id like pamac. --- src/modules/wlr/taskbar.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index 83ce3662..15b927a8 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -15,6 +15,7 @@ #include #include +#include #include @@ -64,6 +65,9 @@ static std::vector search_prefix() } while(end != std::string::npos); } + std::string home_dir = std::getenv("HOME"); + prefixes.push_back(home_dir + "/.local/share/"); + for (auto& p : prefixes) spdlog::debug("Using 'desktop' search path prefix: {}", p); @@ -111,6 +115,26 @@ static std::string get_from_icon_theme(const Glib::RefPtr& icon_ return ""; } +/* Method 3 - as last resort perform a search for most appropriate desktop info file */ +static std::string get_from_desktop_app_info_search(const std::string &app_id) +{ + std::string desktop_file = ""; + + gchar*** desktop_list = g_desktop_app_info_search(app_id.c_str()); + if (desktop_list != nullptr && desktop_list[0] != nullptr) { + for (size_t i=0; desktop_list[0][i]; i++) { + if(desktop_file == "") { + desktop_file = desktop_list[0][i]; + } + break; + } + g_strfreev(desktop_list[0]); + } + g_free(desktop_list); + + return get_from_desktop_app_info(desktop_file); +} + static bool image_load_icon(Gtk::Image& image, const Glib::RefPtr& icon_theme, const std::string &app_id_list, int size) { @@ -142,9 +166,11 @@ static bool image_load_icon(Gtk::Image& image, const Glib::RefPtrload_icon(icon_name, size, Gtk::ICON_LOOKUP_FORCE_SIZE); if (pixbuf) { From 7eb2a6b7090c371656dd2df7fd44af6d430b43cb Mon Sep 17 00:00:00 2001 From: Genesis Date: Tue, 2 Feb 2021 21:58:26 +0100 Subject: [PATCH 09/18] Add a configuration entry to disable auto_back_and_forth on Sway workspaces --- include/modules/sway/workspaces.hpp | 2 +- man/waybar-sway-workspaces.5.scd | 12 ++++++++---- src/modules/sway/workspaces.cpp | 14 ++++++++++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/include/modules/sway/workspaces.hpp b/include/modules/sway/workspaces.hpp index 92ec0516..c6443836 100644 --- a/include/modules/sway/workspaces.hpp +++ b/include/modules/sway/workspaces.hpp @@ -20,7 +20,7 @@ class Workspaces : public AModule, public sigc::trackable { auto update() -> void; private: - static inline const std::string workspace_switch_cmd_ = "workspace --no-auto-back-and-forth \"{}\""; + static inline const std::string workspace_switch_cmd_ = "workspace {} \"{}\""; static int convertWorkspaceNameToNum(std::string name); diff --git a/man/waybar-sway-workspaces.5.scd b/man/waybar-sway-workspaces.5.scd index 5e516892..f2808b90 100644 --- a/man/waybar-sway-workspaces.5.scd +++ b/man/waybar-sway-workspaces.5.scd @@ -66,12 +66,16 @@ Addressed by *sway/workspaces* Lists workspaces that should always be shown, even when non existent *on-update*: ++ - typeof: string ++ - Command to execute when the module is updated. + typeof: string ++ + Command to execute when the module is updated. *numeric-first*: ++ - typeof: bool ++ - Whether to put workspaces starting with numbers before workspaces that do not start with a number. + typeof: bool ++ + Whether to put workspaces starting with numbers before workspaces that do not start with a number. + +*disable-auto-back-and-forth*: ++ + typeof: bool ++ + Whether to disable *workspace_auto_back_and_forth* when clicking on workspaces. If this is set to *true*, clicking on a workspace you are already on won't do anything, even if *workspace_auto_back_and_forth* is enabled in the Sway configuration. # FORMAT REPLACEMENTS diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index d0c24632..43dcf33c 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -257,11 +257,19 @@ Gtk::Button &Workspaces::addButton(const Json::Value &node) { ipc_.sendCmd( IPC_COMMAND, fmt::format(workspace_switch_cmd_ + "; move workspace to output \"{}\"; " + workspace_switch_cmd_, + "--no-auto-back-and-forth", node["name"].asString(), node["target_output"].asString(), + "--no-auto-back-and-forth", node["name"].asString())); } else { - ipc_.sendCmd(IPC_COMMAND, fmt::format(workspace_switch_cmd_, node["name"].asString())); + ipc_.sendCmd( + IPC_COMMAND, + fmt::format("workspace {} \"{}\"", + config_["disable-auto-back-and-forth"].asBool() + ? "--no-auto-back-and-forth" + : "", + node["name"].asString())); } } catch (const std::exception &e) { spdlog::error("Workspaces: {}", e.what()); @@ -322,7 +330,9 @@ bool Workspaces::handleScroll(GdkEventScroll *e) { } } try { - ipc_.sendCmd(IPC_COMMAND, fmt::format(workspace_switch_cmd_, name)); + ipc_.sendCmd( + IPC_COMMAND, + fmt::format(workspace_switch_cmd_, "--no-auto-back-and-forth", name)); } catch (const std::exception &e) { spdlog::error("Workspaces: {}", e.what()); } From 22ed153004e904ed58fe3d4817576552ff1fa57b Mon Sep 17 00:00:00 2001 From: jgmdev Date: Wed, 3 Feb 2021 21:04:10 -0400 Subject: [PATCH 10/18] [wlr/taskbar] Fix unhandled exception crash when icon name is a path. --- src/modules/wlr/taskbar.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index 15b927a8..93c6a77f 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -1,5 +1,7 @@ #include "modules/wlr/taskbar.hpp" +#include "glibmm/error.h" +#include "glibmm/fileutils.h" #include "glibmm/refptr.h" #include "util/format.hpp" @@ -74,6 +76,18 @@ static std::vector search_prefix() return prefixes; } +Glib::RefPtr load_icon_from_file(std::string icon_path, int size) +{ + try { + auto pb = Gdk::Pixbuf::create_from_file(icon_path, size, size); + return pb; + } catch(Glib::Error&) { + return {}; + } catch(...) { + return {}; + } +} + /* Method 1 - get the correct icon name from the desktop file */ static std::string get_from_desktop_app_info(const std::string &app_id) { @@ -172,7 +186,17 @@ static bool image_load_icon(Gtk::Image& image, const Glib::RefPtrload_icon(icon_name, size, Gtk::ICON_LOOKUP_FORCE_SIZE); + Glib::RefPtr pixbuf; + + try { + pixbuf = icon_theme->load_icon(icon_name, size, Gtk::ICON_LOOKUP_FORCE_SIZE); + } catch(...) { + if (Glib::file_test(icon_name, Glib::FILE_TEST_EXISTS)) + pixbuf = load_icon_from_file(icon_name, size); + else + pixbuf = {}; + } + if (pixbuf) { image.set(pixbuf); found = true; From 8a284e7c74e25c07a603612393a9a07bf31baee7 Mon Sep 17 00:00:00 2001 From: jgmdev Date: Wed, 3 Feb 2021 21:14:04 -0400 Subject: [PATCH 11/18] [wlr/taskbar] Declared load_icon_from_file() static. --- src/modules/wlr/taskbar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index 93c6a77f..1135a8e5 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -76,7 +76,7 @@ static std::vector search_prefix() return prefixes; } -Glib::RefPtr load_icon_from_file(std::string icon_path, int size) +static Glib::RefPtr load_icon_from_file(std::string icon_path, int size) { try { auto pb = Gdk::Pixbuf::create_from_file(icon_path, size, size); From e293b89f6ba08ca92c834bad4473d708530521de Mon Sep 17 00:00:00 2001 From: jgmdev Date: Thu, 4 Feb 2021 04:57:08 -0400 Subject: [PATCH 12/18] [wlr/taskbar] Removed unnecessary catch statement. --- src/modules/wlr/taskbar.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index 1135a8e5..c2acbd9a 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -81,8 +81,6 @@ static Glib::RefPtr load_icon_from_file(std::string icon_path, int try { auto pb = Gdk::Pixbuf::create_from_file(icon_path, size, size); return pb; - } catch(Glib::Error&) { - return {}; } catch(...) { return {}; } From fffb52dd936b7e633996e1a506577c7409cef1fc Mon Sep 17 00:00:00 2001 From: jgmdev Date: Sun, 7 Feb 2021 00:50:52 -0400 Subject: [PATCH 13/18] [wlr/taskbar] Check StartupWMClass on list returned by g_desktop_app_info_searchi() --- src/modules/wlr/taskbar.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index c2acbd9a..e91b19a7 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -137,8 +137,13 @@ static std::string get_from_desktop_app_info_search(const std::string &app_id) for (size_t i=0; desktop_list[0][i]; i++) { if(desktop_file == "") { desktop_file = desktop_list[0][i]; + } else { + auto tmp_info = Gio::DesktopAppInfo::create(desktop_list[0][i]); + auto startup_class = tmp_info->get_startup_wm_class(); + + if (startup_class == app_id) + desktop_file = desktop_list[0][i]; } - break; } g_strfreev(desktop_list[0]); } From f14a73584f4eeb1c2c761ba293ad616cb7020975 Mon Sep 17 00:00:00 2001 From: jgmdev Date: Sun, 7 Feb 2021 01:01:57 -0400 Subject: [PATCH 14/18] [wlr/taskbar] Added break when matching StartupWMClass is found. --- src/modules/wlr/taskbar.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index e91b19a7..08e8bf34 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -141,8 +141,10 @@ static std::string get_from_desktop_app_info_search(const std::string &app_id) auto tmp_info = Gio::DesktopAppInfo::create(desktop_list[0][i]); auto startup_class = tmp_info->get_startup_wm_class(); - if (startup_class == app_id) + if (startup_class == app_id) { desktop_file = desktop_list[0][i]; + break; + } } } g_strfreev(desktop_list[0]); From e4a65c72dd8d48a787f065ce330230c45b2e74cb Mon Sep 17 00:00:00 2001 From: jgmdev Date: Sun, 7 Feb 2021 04:27:16 -0400 Subject: [PATCH 15/18] Added missing 'if' space. --- src/modules/wlr/taskbar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index 08e8bf34..ef46f36a 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -135,7 +135,7 @@ static std::string get_from_desktop_app_info_search(const std::string &app_id) gchar*** desktop_list = g_desktop_app_info_search(app_id.c_str()); if (desktop_list != nullptr && desktop_list[0] != nullptr) { for (size_t i=0; desktop_list[0][i]; i++) { - if(desktop_file == "") { + if (desktop_file == "") { desktop_file = desktop_list[0][i]; } else { auto tmp_info = Gio::DesktopAppInfo::create(desktop_list[0][i]); From 65853812306414b525ea6beb25dc915249dc922e Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Mon, 8 Feb 2021 22:30:01 -0800 Subject: [PATCH 16/18] fix(client): remove unnecessary wl_output_roundtrip At this point we're not awaiting any protocol events and flushing wayland queue makes little sense. As #1019 shows, it may be even harmful as an extra roundtrip could process wl_output disappearance and delete output object right from under our code. --- src/client.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client.cpp b/src/client.cpp index 0ad4e6bb..9983bb56 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -124,7 +124,6 @@ void waybar::Client::handleOutputDone(void *data, struct zxdg_output_v1 * /*xdg_ auto configs = client->getOutputConfigs(output); if (!configs.empty()) { - wl_display_roundtrip(client->wl_display); for (const auto &config : configs) { client->bars.emplace_back(std::make_unique(&output, config)); } From 89b5e819a34388e39829bd3cbe52d5fb28a08297 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Mon, 8 Feb 2021 23:05:31 -0800 Subject: [PATCH 17/18] fix(client): improve guard from repeated xdg_output.done events Multiple .done events may arrive in batch. In this case libwayland would queue xdg_output.destroy and dispatch all pending events, triggering this callback several times for the same output. Delete xdg_output pointer immediately on the first event and use the value as a guard for reentering. --- src/client.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 9983bb56..fcfcd98c 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -120,16 +120,26 @@ void waybar::Client::handleOutputDone(void *data, struct zxdg_output_v1 * /*xdg_ auto client = waybar::Client::inst(); try { auto &output = client->getOutput(data); - spdlog::debug("Output detection done: {} ({})", output.name, output.identifier); + /** + * Multiple .done events may arrive in batch. In this case libwayland would queue + * xdg_output.destroy and dispatch all pending events, triggering this callback several times + * for the same output. .done events can also arrive after that for a scale or position changes. + * We wouldn't want to draw a duplicate bar for each such event either. + * + * All the properties we care about are immutable so it's safe to delete the xdg_output object + * on the first event and use the ptr value to check that the callback was already invoked. + */ + if (output.xdg_output) { + output.xdg_output.reset(); + spdlog::debug("Output detection done: {} ({})", output.name, output.identifier); - auto configs = client->getOutputConfigs(output); - if (!configs.empty()) { - for (const auto &config : configs) { - client->bars.emplace_back(std::make_unique(&output, config)); + auto configs = client->getOutputConfigs(output); + if (!configs.empty()) { + for (const auto &config : configs) { + client->bars.emplace_back(std::make_unique(&output, config)); + } } } - // unsubscribe - output.xdg_output.reset(); } catch (const std::exception &e) { std::cerr << e.what() << std::endl; } From 95a6689077b5a42833ba3a228f0e56e7a4b71d66 Mon Sep 17 00:00:00 2001 From: Andy Russell Date: Mon, 8 Feb 2021 23:52:29 -0500 Subject: [PATCH 18/18] disable Idle Inhibitor module if unsupported --- src/modules/idle_inhibitor.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/idle_inhibitor.cpp b/src/modules/idle_inhibitor.cpp index 9978bbac..26889c23 100644 --- a/src/modules/idle_inhibitor.cpp +++ b/src/modules/idle_inhibitor.cpp @@ -12,6 +12,10 @@ waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& bar_(bar), idle_inhibitor_(nullptr), pid_(-1) { + if (waybar::Client::inst()->idle_inhibit_manager == nullptr) { + throw std::runtime_error("idle-inhibit not available"); + } + event_box_.add_events(Gdk::BUTTON_PRESS_MASK); event_box_.signal_button_press_event().connect( sigc::mem_fun(*this, &IdleInhibitor::handleToggle));