Compare commits

...

47 Commits
0.6.8 ... 0.7.1

Author SHA1 Message Date
0834551161 chore: 0.7.1 2019-07-11 17:02:47 +02:00
ccd1586c65 Merge pull request #405 from crwxrws/fix-400
fix(pulseaudio): connect scroll event handler
2019-07-09 09:46:05 +02:00
617b370104 fix(pulseaudio): connect scroll event handler
Reconnect the event handler that was removed in commit 527144a.

Fixes Alexays#400
2019-07-06 15:51:00 +02:00
d607a4e33f Fix deadlock on workspace scrolling (#403)
Fix deadlock on workspace scrolling
2019-07-06 10:30:57 +02:00
a6c0bc5a52 Fix deadlock on workspace scrolling
Make the mutex guard lifecycle finish before the send ipc command
by adding scope around the code.

Fixes #395 .
2019-07-05 20:47:44 -07:00
67ad0e69ce Merge pull request #397 from Jamedjo/jej/add-css-classes-for-multiple-bars
Allow CSS to select specific waybars when multiple are in use
2019-07-04 14:20:03 +02:00
ae88d6bc3c feat(bar): individual bars can be named for CSS
Allows CSS to select individual waybars when multiple are configured
2019-07-04 02:15:56 +01:00
4f3c38c542 feat(bar): add CSS class for window position 2019-07-04 02:15:50 +01:00
a6980fca7f feat: ellipsize modules 2019-06-28 14:16:09 +02:00
bd5146fdcf fix(Label): ELLIPSIZE all label modules 2019-06-28 13:49:04 +02:00
22ddbde394 style(workspaces): update hover style 2019-06-28 13:41:53 +02:00
c916fe258e fix(network): no need to check family here 2019-06-25 07:55:55 +02:00
9c8e39c30c chore: 0.7.0 2019-06-22 18:17:16 +02:00
5b270dae0d refactor: AModule (#387)
refactor: AModule
2019-06-22 18:15:50 +02:00
c621afb0c4 Merge branch 'master' into clean 2019-06-22 18:15:34 +02:00
bcf4725349 Cleanup on clean branch (#391)
Cleanup on clean branch
2019-06-18 09:43:34 +02:00
12b30ca25f AModule::getScrollDir: convert reset if-else into switch 2019-06-17 20:42:19 +02:00
86d6668ed4 AModule::getScrollDir: convert if-else chain into switch statement 2019-06-17 20:40:13 +02:00
7c85aec8e0 AModule::getScrollDir: get deltas in a more C++ way 2019-06-17 20:29:37 +02:00
2c038d1977 AModule::getScrollDir: move dir inside the only scope it is relevant 2019-06-17 20:09:53 +02:00
ff9d598c16 fix: add proper mutex 2019-06-17 11:39:45 +02:00
71a9a75aad refactor: remove fix workaround 2019-06-16 15:14:31 +02:00
05f796158b fix: typo 2019-06-16 15:13:40 +02:00
1d2dd953e7 revert: default config 2019-06-16 15:09:26 +02:00
527144a440 refactor(pulseaudio): proper scroll override 2019-06-16 15:08:08 +02:00
cda6282277 Merge pull request #389 from Synthetica9/x-scroll
AModule: handle X axis scrolling
2019-06-16 14:54:53 +02:00
7f13478396 AModule: handle X axis scrolling 2019-06-16 13:17:34 +02:00
90a9c0e25f refactor: get rid of some mutex 2019-06-15 15:01:03 +02:00
340ec7be91 refactor: AModule 2019-06-15 14:57:52 +02:00
e7eef6b493 Merge pull request #385 from nenad/patch/add-total-memory
Expose total memory to the formatting directive
2019-06-15 11:16:30 +02:00
1b7068e61d Expose total memory to the formatting directive 2019-06-14 22:48:16 +02:00
dabe2bebbb feat(sway/window): handle floating nodes 2019-06-14 11:27:40 +02:00
486b5a5d38 fix(sway/window): check output recursively 2019-06-14 10:57:22 +02:00
11bbc3b24d Fix twitchy scrolling on touchpads (#381)
Fix twitchy scrolling on touchpads
2019-06-14 10:38:25 +02:00
7f74de977c chore: 0.6.9 2019-06-14 10:27:41 +02:00
028b184f7b fix(workspaces): persistant class with empty outputs 2019-06-12 09:50:33 +02:00
564fdcb369 fix(custom): exit status 2019-06-11 22:09:47 +02:00
396f7d4525 Workspaces: implement horizontal continuous scrolling 2019-06-11 18:44:54 +02:00
3c9b533997 fix(window): avoid hexpand 2019-06-11 17:57:17 +02:00
ae397c8fa2 ALabel: add smooth-scrolling-threshold 2019-06-11 17:56:10 +02:00
ec75be0bc3 fix(Tray): click behaviour 2019-06-11 17:53:16 +02:00
ed4521d113 Workspaces: fix twitchy scrolling on touchpads
Previously, any and all scroll events were interpreted as reason to switch
workspaces. This resulted in twitchy behaviour, where the scrolling was
practically unusable.

Now, we pool all scroll values, and only scroll if the value is larger than the
new config option "smooth-scrolling-threshold". If this option is not set, the
behaviour is unchanged.
2019-06-11 17:22:24 +02:00
c2e9ed6091 feat(workspaces): add class to persistant workspaces 2019-06-11 14:08:48 +02:00
a37b4687ff Revert "refactor(window): we don't need to subscribe workspace events"
This reverts commit 648eecdd83.
2019-06-11 14:06:31 +02:00
ee29a35aa5 Update README.md 2019-06-11 13:55:35 +02:00
0be8e200ce adds the wl output name as a css class (#373)
adds the wl output name as a css class
2019-06-10 12:15:05 +02:00
46e5dd93d4 adds the wl output name as a css class
now you can have a custom styling for each bar
2019-06-08 11:04:34 -07:00
29 changed files with 324 additions and 269 deletions

View File

@ -2,7 +2,8 @@
> Highly customizable Wayland bar for Sway and Wlroots based compositors.<br>
> Available in Arch [community](https://www.archlinux.org/packages/community/x86_64/waybar/) or
[AUR](https://aur.archlinux.org/packages/waybar-git/) and [openSUSE](https://build.opensuse.org/package/show/X11:Wayland/waybar)
[AUR](https://aur.archlinux.org/packages/waybar-git/) and [openSUSE](https://build.opensuse.org/package/show/X11:Wayland/waybar)<br>
> *Waybar [examples](https://github.com/Alexays/Waybar/wiki/Examples)*
**Current features**
- Sway (Workspaces, Binding mode, Focused window name)
@ -42,6 +43,7 @@ $ waybar
gtkmm3
jsoncpp
libinput
libsigc++
fmt
wayland

View File

@ -1,41 +1,30 @@
#pragma once
#include <glibmm/markup.h>
#include <gtkmm/eventbox.h>
#include <gtkmm/label.h>
#include <json/json.h>
#include "IModule.hpp"
#include "AModule.hpp"
namespace waybar {
class ALabel : public IModule {
class ALabel : public AModule {
public:
ALabel(const Json::Value &, const std::string &, const std::string &, const std::string &format,
uint16_t interval = 0);
virtual ~ALabel();
uint16_t interval = 0, bool ellipsize = false);
virtual ~ALabel() = default;
virtual auto update() -> void;
virtual std::string getIcon(uint16_t, const std::string &alt = "", uint16_t max = 0);
virtual operator Gtk::Widget &();
protected:
bool tooltipEnabled();
Gtk::EventBox event_box_;
Gtk::Label label_;
const Json::Value & config_;
std::string format_;
std::string click_param;
std::mutex mutex_;
const std::chrono::seconds interval_;
bool alt_ = false;
std::string default_format_;
virtual bool handleToggle(GdkEventButton *const &ev);
virtual bool handleScroll(GdkEventScroll *);
virtual bool handleToggle(GdkEventButton *const &e);
virtual std::string getState(uint8_t value, bool lesser = false);
private:
std::vector<int> pid_;
};
} // namespace waybar

40
include/AModule.hpp Normal file
View File

@ -0,0 +1,40 @@
#pragma once
#include <glibmm/dispatcher.h>
#include <glibmm/markup.h>
#include <gtkmm/eventbox.h>
#include <json/json.h>
#include "IModule.hpp"
namespace waybar {
class AModule : public IModule {
public:
AModule(const Json::Value &, const std::string &, const std::string &,
bool enable_click = false, bool enable_scroll = false);
virtual ~AModule();
virtual auto update() -> void;
virtual operator Gtk::Widget &();
Glib::Dispatcher dp;
protected:
enum SCROLL_DIR { NONE, UP, DOWN, LEFT, RIGHT };
SCROLL_DIR getScrollDir(GdkEventScroll *e);
bool tooltipEnabled();
const Json::Value &config_;
Gtk::EventBox event_box_;
std::string click_param_;
virtual bool handleToggle(GdkEventButton *const &ev);
virtual bool handleScroll(GdkEventScroll *);
private:
std::vector<int> pid_;
gdouble distance_scrolled_y_;
gdouble distance_scrolled_x_;
};
} // namespace waybar

View File

@ -1,7 +1,5 @@
#pragma once
#include <glibmm/dispatcher.h>
#include <gtkmm/box.h>
#include <gtkmm/widget.h>
namespace waybar {
@ -11,7 +9,6 @@ class IModule {
virtual ~IModule() = default;
virtual auto update() -> void = 0;
virtual operator Gtk::Widget &() = 0;
Glib::Dispatcher dp; // Hmmm Maybe I should create an abstract class ?
};
} // namespace waybar

View File

@ -4,8 +4,9 @@
#include <gtkmm/cssprovider.h>
#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <gtkmm/box.h>
#include <json/json.h>
#include "IModule.hpp"
#include "AModule.hpp"
#include "idle-inhibit-unstable-v1-client-protocol.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "xdg-output-unstable-v1-client-protocol.h"
@ -73,9 +74,9 @@ class Bar {
Gtk::Box center_;
Gtk::Box right_;
Gtk::Box box_;
std::vector<std::unique_ptr<waybar::IModule>> modules_left_;
std::vector<std::unique_ptr<waybar::IModule>> modules_center_;
std::vector<std::unique_ptr<waybar::IModule>> modules_right_;
std::vector<std::unique_ptr<waybar::AModule>> modules_left_;
std::vector<std::unique_ptr<waybar::AModule>> modules_center_;
std::vector<std::unique_ptr<waybar::AModule>> modules_right_;
};
} // namespace waybar

View File

@ -37,7 +37,7 @@ namespace waybar {
class Factory {
public:
Factory(const Bar& bar, const Json::Value& config);
IModule* makeModule(const std::string& name) const;
AModule* makeModule(const std::string& name) const;
private:
const Bar& bar_;

View File

@ -21,14 +21,13 @@ class Pulseaudio : public ALabel {
static void sourceInfoCb(pa_context*, const pa_source_info* i, int, void* data);
static void serverInfoCb(pa_context*, const pa_server_info*, void*);
static void volumeModifyCb(pa_context*, int, void*);
bool handleVolume(GdkEventScroll* e);
bool handleScroll(GdkEventScroll* e);
const std::string getPortIcon() const;
pa_threaded_mainloop* mainloop_;
pa_mainloop_api* mainloop_api_;
pa_context* context_;
bool scrolling_;
// SINK
uint32_t sink_idx_{0};
uint16_t volume_;

View File

@ -1,7 +1,7 @@
#pragma once
#include <fmt/format.h>
#include "IModule.hpp"
#include "AModule.hpp"
#include "bar.hpp"
#include "modules/sni/host.hpp"
#include "modules/sni/watcher.hpp"
@ -9,19 +9,17 @@
namespace waybar::modules::SNI {
class Tray : public IModule {
class Tray : public AModule {
public:
Tray(const std::string&, const Bar&, const Json::Value&);
~Tray() = default;
auto update() -> void;
operator Gtk::Widget&();
private:
void onAdd(std::unique_ptr<Item>& item);
void onRemove(std::unique_ptr<Item>& item);
static inline std::size_t nb_hosts_ = 0;
const Json::Value& config_;
Gtk::Box box_;
SNI::Watcher watcher_;
SNI::Host host_;

View File

@ -5,7 +5,6 @@
#include <sys/un.h>
#include <unistd.h>
#include <cstring>
#include <iostream>
#include <memory>
#include <mutex>
#include "ipc.hpp"

View File

@ -22,6 +22,7 @@ class Mode : public ALabel, public sigc::trackable {
std::string mode_;
util::JsonParser parser_;
std::mutex mutex_;
util::SleeperThread thread_;
Ipc ipc_;

View File

@ -21,17 +21,18 @@ class Window : public ALabel, public sigc::trackable {
void onEvent(const struct Ipc::ipc_response&);
void onCmd(const struct Ipc::ipc_response&);
void worker();
std::tuple<std::size_t, int, std::string, std::string> getFocusedNode(const Json::Value& nodes);
std::tuple<std::size_t, int, std::string, std::string> getFocusedNode(const Json::Value& nodes,
std::string& output);
void getTree();
const Bar& bar_;
std::mutex mutex_;
std::string window_;
int windowId_;
std::string app_id_;
std::string old_app_id_;
std::size_t app_nb_;
util::JsonParser parser_;
std::mutex mutex_;
util::SleeperThread thread_;
Ipc ipc_;

View File

@ -3,7 +3,7 @@
#include <fmt/format.h>
#include <gtkmm/button.h>
#include <gtkmm/label.h>
#include "IModule.hpp"
#include "AModule.hpp"
#include "bar.hpp"
#include "client.hpp"
#include "modules/sway/ipc/client.hpp"
@ -12,12 +12,11 @@
namespace waybar::modules::sway {
class Workspaces : public IModule, public sigc::trackable {
class Workspaces : public AModule, public sigc::trackable {
public:
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
~Workspaces() = default;
auto update() -> void;
operator Gtk::Widget&();
private:
void onCmd(const struct Ipc::ipc_response&);
@ -33,14 +32,12 @@ class Workspaces : public IModule, public sigc::trackable {
bool handleScroll(GdkEventScroll*);
const Bar& bar_;
const Json::Value& config_;
std::vector<Json::Value> workspaces_;
std::vector<std::string> workspaces_order_;
std::mutex mutex_;
Gtk::Box box_;
util::JsonParser parser_;
bool scrolling_;
std::unordered_map<std::string, Gtk::Button> buttons_;
std::mutex mutex_;
util::SleeperThread thread_;
Ipc ipc_;

View File

@ -33,7 +33,7 @@ inline int close(FILE* fp, pid_t pid) {
fclose(fp);
while (waitpid(pid, &stat, 0) == -1) {
if (errno != EINTR) {
stat = -1;
stat = 0;
break;
}
}

View File

@ -14,7 +14,10 @@ class SleeperThread {
SleeperThread(std::function<void()> func)
: thread_{[this, func] {
while (do_run_) func();
while (do_run_) {
signal_ = false;
func();
}
}} {}
SleeperThread& operator=(std::function<void()> func) {
@ -42,7 +45,10 @@ class SleeperThread {
}
auto wake_up() {
{
std::lock_guard<std::mutex> lck(mutex_);
signal_ = true;
}
condvar_.notify_all();
}

View File

@ -1,6 +1,6 @@
project(
'waybar', 'cpp', 'c',
version: '0.6.8',
version: '0.7.1',
license: 'MIT',
default_options : [
'cpp_std=c++17',
@ -65,6 +65,7 @@ libmpdclient = dependency('libmpdclient', required: get_option('mpd'))
src_files = files(
'src/factory.cpp',
'src/AModule.cpp',
'src/ALabel.cpp',
'src/modules/memory.cpp',
'src/modules/battery.cpp',

View File

@ -36,7 +36,6 @@ window#waybar.chromium {
border: none;
}
/* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */
#workspaces button {
padding: 0 5px;
background-color: transparent;
@ -44,6 +43,13 @@ window#waybar.chromium {
border-bottom: 3px solid transparent;
}
/* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */
#workspaces button:hover {
background: rgba(0, 0, 0, 0.2);
box-shadow: inherit;
border-bottom: 3px solid #ffffff;
}
#workspaces button.focused {
background-color: #64727D;
border-bottom: 3px solid #ffffff;
@ -58,9 +64,20 @@ window#waybar.chromium {
border-bottom: 3px solid #ffffff;
}
#clock, #battery, #cpu, #memory, #temperature, #backlight, #network, #pulseaudio, #custom-media, #tray, #mode, #idle_inhibitor {
#clock,
#battery,
#cpu,
#memory,
#temperature,
#backlight,
#network,
#pulseaudio,
#custom-media,
#tray,
#mode,
#idle_inhibitor {
padding: 0 10px;
margin: 0 5px;
margin: 0 4px;
color: #ffffff;
}

View File

@ -2,9 +2,11 @@
#include <fmt/format.h>
#include <util/command.hpp>
waybar::ALabel::ALabel(const Json::Value& config, const std::string& name, const std::string& id,
const std::string& format, uint16_t interval)
: config_(config),
namespace waybar {
ALabel::ALabel(const Json::Value& config, const std::string& name, const std::string& id,
const std::string& format, uint16_t interval, bool ellipsize)
: AModule(config, name, id, config["format-alt"].isString()),
format_(config_["format"].isString() ? config_["format"].asString() : format),
interval_(config_["interval"] == "once"
? std::chrono::seconds(100000000)
@ -19,101 +21,20 @@ waybar::ALabel::ALabel(const Json::Value& config, const std::string& name, const
if (config_["max-length"].isUInt()) {
label_.set_max_width_chars(config_["max-length"].asUInt());
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END);
} else if (ellipsize && label_.get_max_width_chars() == -1) {
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END);
}
if (config_["rotate"].isUInt()) {
label_.set_angle(config["rotate"].asUInt());
}
if (config_["format-alt"].isString()) {
event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
event_box_.signal_button_press_event().connect(sigc::mem_fun(*this, &ALabel::handleToggle));
}
// configure events' user commands
if (config_["on-click"].isString() || config_["on-click-middle"].isString() ||
config_["on-click-backward"].isString() || config_["on-click-forward"].isString() ||
config_["on-click-right"].isString()) {
event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
event_box_.signal_button_press_event().connect(sigc::mem_fun(*this, &ALabel::handleToggle));
}
if (config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString()) {
event_box_.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
event_box_.signal_scroll_event().connect(sigc::mem_fun(*this, &ALabel::handleScroll));
}
}
waybar::ALabel::~ALabel() {
for (const auto& pid : pid_) {
if (pid != -1) {
kill(-pid, 9);
}
}
}
auto waybar::ALabel::update() -> void {
auto ALabel::update() -> void {
// Nothing here
}
bool waybar::ALabel::handleToggle(GdkEventButton* const& e) {
std::string format;
if (config_["on-click"].isString() && e->button == 1) {
format = config_["on-click"].asString();
} else if (config_["on-click-middle"].isString() && e->button == 2) {
format = config_["on-click-middle"].asString();
} else if (config_["on-click-right"].isString() && e->button == 3) {
format = config_["on-click-right"].asString();
} else if (config_["on-click-forward"].isString() && e->button == 8) {
format = config_["on-click-backward"].asString();
} else if (config_["on-click-backward"].isString() && e->button == 9) {
format = config_["on-click-forward"].asString();
}
if (!format.empty()) {
pid_.push_back(util::command::forkExec(fmt::format(format, fmt::arg("arg", click_param))));
}
if (config_["format-alt-click"].isUInt() && e->button == config_["format-alt-click"].asUInt()) {
alt_ = !alt_;
if (alt_ && config_["format-alt"].isString()) {
format_ = config_["format-alt"].asString();
} else {
format_ = default_format_;
}
}
dp.emit();
return true;
}
bool waybar::ALabel::handleScroll(GdkEventScroll* e) {
// Avoid concurrent scroll event
std::lock_guard<std::mutex> lock(mutex_);
bool direction_up = false;
if (e->direction == GDK_SCROLL_UP) {
direction_up = true;
}
if (e->direction == GDK_SCROLL_DOWN) {
direction_up = false;
}
if (e->direction == GDK_SCROLL_SMOOTH) {
gdouble delta_x, delta_y;
gdk_event_get_scroll_deltas(reinterpret_cast<const GdkEvent*>(e), &delta_x, &delta_y);
if (delta_y < 0) {
direction_up = true;
} else if (delta_y > 0) {
direction_up = false;
}
}
if (direction_up && config_["on-scroll-up"].isString()) {
pid_.push_back(util::command::forkExec(config_["on-scroll-up"].asString()));
} else if (config_["on-scroll-down"].isString()) {
pid_.push_back(util::command::forkExec(config_["on-scroll-down"].asString()));
}
dp.emit();
return true;
}
std::string waybar::ALabel::getIcon(uint16_t percentage, const std::string& alt, uint16_t max) {
std::string ALabel::getIcon(uint16_t percentage, const std::string& alt, uint16_t max) {
auto format_icons = config_["format-icons"];
if (format_icons.isObject()) {
if (!alt.empty() && (format_icons[alt].isString() || format_icons[alt].isArray())) {
@ -133,7 +54,19 @@ std::string waybar::ALabel::getIcon(uint16_t percentage, const std::string& alt,
return "";
}
std::string waybar::ALabel::getState(uint8_t value, bool lesser) {
bool waybar::ALabel::handleToggle(GdkEventButton* const& e) {
if (config_["format-alt-click"].isUInt() && e->button == config_["format-alt-click"].asUInt()) {
alt_ = !alt_;
if (alt_ && config_["format-alt"].isString()) {
format_ = config_["format-alt"].asString();
} else {
format_ = default_format_;
}
}
return AModule::handleToggle(e);
}
std::string ALabel::getState(uint8_t value, bool lesser) {
if (!config_["states"].isObject()) {
return "";
}
@ -162,8 +95,4 @@ std::string waybar::ALabel::getState(uint8_t value, bool lesser) {
return valid_state;
}
bool waybar::ALabel::tooltipEnabled() {
return config_["tooltip"].isBool() ? config_["tooltip"].asBool() : true;
}
waybar::ALabel::operator Gtk::Widget&() { return event_box_; }
} // namespace waybar

119
src/AModule.cpp Normal file
View File

@ -0,0 +1,119 @@
#include "AModule.hpp"
#include <fmt/format.h>
#include <util/command.hpp>
namespace waybar {
AModule::AModule(const Json::Value& config, const std::string& name, const std::string& id,
bool enable_click, bool enable_scroll)
: config_(std::move(config)) {
// configure events' user commands
if (config_["on-click"].isString() || config_["on-click-middle"].isString() ||
config_["on-click-backward"].isString() || config_["on-click-forward"].isString() ||
config_["on-click-right"].isString() || enable_click) {
event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
event_box_.signal_button_press_event().connect(sigc::mem_fun(*this, &AModule::handleToggle));
}
if (config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString() || enable_scroll) {
event_box_.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
event_box_.signal_scroll_event().connect(sigc::mem_fun(*this, &AModule::handleScroll));
}
}
AModule::~AModule() {
for (const auto& pid : pid_) {
if (pid != -1) {
kill(-pid, 9);
}
}
}
auto AModule::update() -> void {
// Nothing here
}
bool AModule::handleToggle(GdkEventButton* const& e) {
std::string format;
if (config_["on-click"].isString() && e->button == 1) {
format = config_["on-click"].asString();
} else if (config_["on-click-middle"].isString() && e->button == 2) {
format = config_["on-click-middle"].asString();
} else if (config_["on-click-right"].isString() && e->button == 3) {
format = config_["on-click-right"].asString();
} else if (config_["on-click-forward"].isString() && e->button == 8) {
format = config_["on-click-backward"].asString();
} else if (config_["on-click-backward"].isString() && e->button == 9) {
format = config_["on-click-forward"].asString();
}
if (!format.empty()) {
pid_.push_back(util::command::forkExec(fmt::format(format, fmt::arg("arg", click_param_))));
}
dp.emit();
return true;
}
AModule::SCROLL_DIR AModule::getScrollDir(GdkEventScroll* e) {
switch (e -> direction) {
case GDK_SCROLL_UP: return SCROLL_DIR::UP;
case GDK_SCROLL_DOWN: return SCROLL_DIR::DOWN;
case GDK_SCROLL_LEFT: return SCROLL_DIR::LEFT;
case GDK_SCROLL_RIGHT: return SCROLL_DIR::RIGHT;
case GDK_SCROLL_SMOOTH: {
SCROLL_DIR dir{SCROLL_DIR::NONE};
distance_scrolled_y_ += e->delta_y;
distance_scrolled_x_ += e->delta_x;
gdouble threshold = 0;
if (config_["smooth-scrolling-threshold"].isNumeric()) {
threshold = config_["smooth-scrolling-threshold"].asDouble();
}
if (distance_scrolled_y_ < -threshold) {
dir = SCROLL_DIR::UP;
} else if (distance_scrolled_y_ > threshold) {
dir = SCROLL_DIR::DOWN;
} else if (distance_scrolled_x_ > threshold) {
dir = SCROLL_DIR::RIGHT;
} else if (distance_scrolled_x_ < -threshold) {
dir = SCROLL_DIR::LEFT;
}
switch (dir) {
case SCROLL_DIR::UP:
case SCROLL_DIR::DOWN:
distance_scrolled_y_ = 0;
break;
case SCROLL_DIR::LEFT:
case SCROLL_DIR::RIGHT:
distance_scrolled_x_ = 0;
break;
case SCROLL_DIR::NONE:
break;
}
return dir;
}
// Silence -Wreturn-type:
default: return SCROLL_DIR::NONE;
}
}
bool AModule::handleScroll(GdkEventScroll* e) {
auto dir = getScrollDir(e);
if (dir == SCROLL_DIR::UP && config_["on-scroll-up"].isString()) {
pid_.push_back(util::command::forkExec(config_["on-scroll-up"].asString()));
} else if (dir == SCROLL_DIR::DOWN && config_["on-scroll-down"].isString()) {
pid_.push_back(util::command::forkExec(config_["on-scroll-down"].asString()));
}
dp.emit();
return true;
}
bool AModule::tooltipEnabled() {
return config_["tooltip"].isBool() ? config_["tooltip"].asBool() : true;
}
AModule::operator Gtk::Widget&() { return event_box_; }
} // namespace waybar

View File

@ -17,6 +17,9 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
window.set_title("waybar");
window.set_name("waybar");
window.set_decorated(false);
window.get_style_context()->add_class(output->name);
window.get_style_context()->add_class(config["name"].asString());
window.get_style_context()->add_class(config["position"].asString());
if (config["position"] == "right" || config["position"] == "left") {
height_ = 0;
@ -286,15 +289,12 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos) {
modules_right_.emplace_back(module);
}
module->dp.connect([module, &name] {
// Fix https://github.com/Alexays/Waybar/issues/320, proper way?
Glib::signal_idle().connect_once([module, &name] {
try {
module->update();
} catch (const std::exception& e) {
spdlog::error("{}: {}", name.asString(), e.what());
}
});
});
} catch (const std::exception& e) {
spdlog::warn("module {}: {}", name.asString(), e.what());
}
@ -304,9 +304,9 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos) {
auto waybar::Bar::setupWidgets() -> void {
window.add(box_);
box_.pack_start(left_, true, true);
box_.pack_start(left_, false, false);
box_.set_center_widget(center_);
box_.pack_end(right_, true, true);
box_.pack_end(right_, false, false);
// Convert to button code for every module that is used.
setupAltFormatKeyForModuleList("modules-left");
@ -318,13 +318,13 @@ auto waybar::Bar::setupWidgets() -> void {
getModules(factory, "modules-center");
getModules(factory, "modules-right");
for (auto const& module : modules_left_) {
left_.pack_start(*module, false, true, 0);
left_.pack_start(*module, false, false);
}
for (auto const& module : modules_center_) {
center_.pack_start(*module, true, true, 0);
center_.pack_start(*module, false, false);
}
std::reverse(modules_right_.begin(), modules_right_.end());
for (auto const& module : modules_right_) {
right_.pack_end(*module, false, false, 0);
right_.pack_end(*module, false, false);
}
}

View File

@ -2,7 +2,7 @@
waybar::Factory::Factory(const Bar& bar, const Json::Value& config) : bar_(bar), config_(config) {}
waybar::IModule* waybar::Factory::makeModule(const std::string& name) const {
waybar::AModule* waybar::Factory::makeModule(const std::string& name) const {
try {
auto hash_pos = name.find('#');
auto ref = name.substr(0, hash_pos);

View File

@ -11,6 +11,7 @@ waybar::modules::Memory::Memory(const std::string& id, const Json::Value& config
auto waybar::modules::Memory::update() -> void {
parseMeminfo();
if (memtotal_ > 0 && memfree_ >= 0) {
auto total_ram_gigabytes = memtotal_ / std::pow(1024, 2);
int used_ram_percentage = 100 * (memtotal_ - memfree_) / memtotal_;
auto used_ram_gigabytes = (memtotal_ - memfree_) / std::pow(1024, 2);
auto available_ram_gigabytes = memfree_ / std::pow(1024, 2);
@ -18,6 +19,7 @@ auto waybar::modules::Memory::update() -> void {
getState(used_ram_percentage);
label_.set_markup(fmt::format(format_,
used_ram_percentage,
fmt::arg("total", total_ram_gigabytes),
fmt::arg("percentage", used_ram_percentage),
fmt::arg("used", used_ram_gigabytes),
fmt::arg("avail", available_ram_gigabytes)));

View File

@ -546,8 +546,7 @@ int waybar::modules::Network::getPreferredIface(int skip_idx) const {
ifa = ifaddr;
ifid = -1;
while (ifa != nullptr) {
if (ifa->ifa_addr->sa_family == family_ &&
wildcardMatch(config_["interface"].asString(), ifa->ifa_name)) {
if (wildcardMatch(config_["interface"].asString(), ifa->ifa_name)) {
ifid = if_nametoindex(ifa->ifa_name);
break;
}

View File

@ -5,7 +5,6 @@ waybar::modules::Pulseaudio::Pulseaudio(const std::string &id, const Json::Value
mainloop_(nullptr),
mainloop_api_(nullptr),
context_(nullptr),
scrolling_(false),
sink_idx_(0),
volume_(0),
muted_(false),
@ -32,13 +31,8 @@ waybar::modules::Pulseaudio::Pulseaudio(const std::string &id, const Json::Value
throw std::runtime_error("pa_mainloop_run() failed.");
}
pa_threaded_mainloop_unlock(mainloop_);
// define the pulse scroll events only when no user provided
// events are configured
if (!config["on-scroll-up"].isString() && !config["on-scroll-down"].isString()) {
event_box_.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
event_box_.signal_scroll_event().connect(sigc::mem_fun(*this, &Pulseaudio::handleVolume));
}
event_box_.signal_scroll_event().connect(sigc::mem_fun(*this, &Pulseaudio::handleScroll));
}
waybar::modules::Pulseaudio::~Pulseaudio() {
@ -74,50 +68,33 @@ void waybar::modules::Pulseaudio::contextStateCb(pa_context *c, void *data) {
}
}
bool waybar::modules::Pulseaudio::handleVolume(GdkEventScroll *e) {
// Avoid concurrent scroll event
if (scrolling_) {
return false;
bool waybar::modules::Pulseaudio::handleScroll(GdkEventScroll *e) {
// change the pulse volume only when no user provided
// events are configured
if (config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString()) {
return AModule::handleScroll(e);
}
bool direction_up = false;
double volume_tick = (double)PA_VOLUME_NORM / 100;
auto dir = AModule::getScrollDir(e);
if (dir == SCROLL_DIR::NONE) {
return true;
}
double volume_tick = static_cast<double>(PA_VOLUME_NORM) / 100;
pa_volume_t change = volume_tick;
pa_cvolume pa_volume = pa_volume_;
scrolling_ = true;
if (e->direction == GDK_SCROLL_UP) {
direction_up = true;
}
if (e->direction == GDK_SCROLL_DOWN) {
direction_up = false;
}
if (e->direction == GDK_SCROLL_SMOOTH) {
gdouble delta_x, delta_y;
gdk_event_get_scroll_deltas(reinterpret_cast<const GdkEvent *>(e), &delta_x, &delta_y);
if (delta_y < 0) {
direction_up = true;
} else if (delta_y > 0) {
direction_up = false;
}
}
// isDouble returns true for integers as well, just in case
if (config_["scroll-step"].isDouble()) {
change = round(config_["scroll-step"].asDouble() * volume_tick);
}
if (direction_up) {
if (dir == SCROLL_DIR::UP) {
if (volume_ + 1 < 100) {
pa_cvolume_inc(&pa_volume, change);
}
} else {
} else if (dir == SCROLL_DIR::DOWN) {
if (volume_ - 1 >= 0) {
pa_cvolume_dec(&pa_volume, change);
}
}
pa_context_set_sink_volume_by_index(context_, sink_idx_, &pa_volume, volumeModifyCb, this);
return true;
}
@ -249,7 +226,4 @@ auto waybar::modules::Pulseaudio::update() -> void {
if (tooltipEnabled()) {
label_.set_tooltip_text(desc_);
}
if (scrolling_) {
scrolling_ = false;
}
}

View File

@ -1,6 +1,6 @@
#include "modules/sni/item.hpp"
#include <glibmm/main.h>
#include <spdlog/spdlog.h>
#include "modules/sni/item.hpp"
template <>
struct fmt::formatter<Glib::ustring> : formatter<std::string> {
@ -334,7 +334,7 @@ void Item::makeMenu(GdkEventButton* const& ev) {
bool Item::handleClick(GdkEventButton* const& ev) {
auto parameters = Glib::VariantContainerBase::create_tuple(
{Glib::Variant<int>::create(ev->x), Glib::Variant<int>::create(ev->y)});
if ((ev->button == 1 && item_is_menu) || ev->button == 3) {
if ((ev->button == 1 && (item_is_menu || !menu.empty())) || ev->button == 3) {
makeMenu(ev);
if (gtk_menu != nullptr) {
#if GTK_CHECK_VERSION(3, 22, 0)

View File

@ -4,15 +4,16 @@
namespace waybar::modules::SNI {
Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
: config_(config),
: AModule(config, "tray", id),
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0),
watcher_(nb_hosts_),
host_(nb_hosts_, config, std::bind(&Tray::onAdd, this, std::placeholders::_1),
std::bind(&Tray::onRemove, this, std::placeholders::_1)) {
box_.set_name("tray");
spdlog::warn(
"For a functionnal tray you must have libappindicator-* installed and export "
"XDG_CURRENT_DESKTOP=Unity");
box_.set_name("tray");
event_box_.add(box_);
if (!id.empty()) {
box_.get_style_context()->add_class(id);
}
@ -41,6 +42,4 @@ auto Tray::update() -> void {
}
}
Tray::operator Gtk::Widget&() { return box_; }
} // namespace waybar::modules::SNI

View File

@ -3,7 +3,8 @@
namespace waybar::modules::sway {
Mode::Mode(const std::string& id, const Json::Value& config) : ALabel(config, "mode", id, "{}") {
Mode::Mode(const std::string& id, const Json::Value& config)
: ALabel(config, "mode", id, "{}", 0, true) {
ipc_.subscribe(R"(["mode"])");
ipc_.signal_event.connect(sigc::mem_fun(*this, &Mode::onEvent));
// Launch worker
@ -13,6 +14,7 @@ Mode::Mode(const std::string& id, const Json::Value& config) : ALabel(config, "m
void Mode::onEvent(const struct Ipc::ipc_response& res) {
try {
std::lock_guard<std::mutex> lock(mutex_);
auto payload = parser_.parse(res.payload);
if (payload["change"] != "default") {
mode_ = Glib::Markup::escape_text(payload["change"].asString());

View File

@ -4,12 +4,8 @@
namespace waybar::modules::sway {
Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
: ALabel(config, "window", id, "{}"), bar_(bar), windowId_(-1) {
if (label_.get_max_width_chars() == -1) {
label_.set_hexpand(true);
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END);
}
ipc_.subscribe(R"(["window"])");
: ALabel(config, "window", id, "{}", 0, true), bar_(bar), windowId_(-1) {
ipc_.subscribe(R"(["window","workspace"])");
ipc_.signal_event.connect(sigc::mem_fun(*this, &Window::onEvent));
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Window::onCmd));
// Get Initial focused window
@ -24,7 +20,8 @@ void Window::onCmd(const struct Ipc::ipc_response& res) {
try {
std::lock_guard<std::mutex> lock(mutex_);
auto payload = parser_.parse(res.payload);
std::tie(app_nb_, windowId_, window_, app_id_) = getFocusedNode(payload);
auto output = payload["ouput"].isString() ? payload["output"].asString() : "";
std::tie(app_nb_, windowId_, window_, app_id_) = getFocusedNode(payload["nodes"], output);
dp.emit();
} catch (const std::exception& e) {
spdlog::error("Window: {}", e.what());
@ -70,20 +67,28 @@ auto Window::update() -> void {
}
std::tuple<std::size_t, int, std::string, std::string> Window::getFocusedNode(
const Json::Value& nodes) {
for (auto const& node : nodes["nodes"]) {
if (node["focused"].asBool() && node["type"] == "con") {
if ((!config_["all-outputs"].asBool() && nodes["output"] == bar_.output->name) ||
const Json::Value& nodes, std::string& output) {
for (auto const& node : nodes) {
if (node["output"].isString()) {
output = node["output"].asString();
}
if (node["focused"].asBool() && (node["type"] == "con" || node["type"] == "floating_con")) {
if ((!config_["all-outputs"].asBool() && output == bar_.output->name) ||
config_["all-outputs"].asBool()) {
auto app_id = node["app_id"].isString() ? node["app_id"].asString()
: node["window_properties"]["instance"].asString();
return {nodes["nodes"].size(),
return {nodes.size(),
node["id"].asInt(),
Glib::Markup::escape_text(node["name"].asString()),
app_id};
}
}
auto [nb, id, name, app_id] = getFocusedNode(node);
auto [nb, id, name, app_id] = getFocusedNode(node["nodes"], output);
if (id > -1 && !name.empty()) {
return {nb, id, name, app_id};
}
// Search for floating node
std::tie(nb, id, name, app_id) = getFocusedNode(node["floating_nodes"], output);
if (id > -1 && !name.empty()) {
return {nb, id, name, app_id};
}

View File

@ -4,14 +4,14 @@
namespace waybar::modules::sway {
Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config)
: bar_(bar),
config_(config),
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0),
scrolling_(false) {
: AModule(config, "workspaces", id, false, !config["disable-scroll"].asBool()),
bar_(bar),
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0) {
box_.set_name("workspaces");
if (!id.empty()) {
box_.get_style_context()->add_class(id);
}
event_box_.add(box_);
ipc_.subscribe(R"(["workspace"])");
ipc_.signal_event.connect(sigc::mem_fun(*this, &Workspaces::onEvent));
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Workspaces::onCmd));
@ -36,9 +36,9 @@ void Workspaces::onEvent(const struct Ipc::ipc_response &res) {
void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
if (res.type == IPC_GET_WORKSPACES) {
try {
auto payload = parser_.parse(res.payload);
if (payload.isArray()) {
{
std::lock_guard<std::mutex> lock(mutex_);
auto payload = parser_.parse(res.payload);
workspaces_.clear();
std::copy_if(payload.begin(),
payload.end(),
@ -80,6 +80,7 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
// Adding to all outputs
Json::Value v;
v["name"] = p_w_name;
v["target_output"] = "";
workspaces_.emplace_back(std::move(v));
}
}
@ -90,16 +91,11 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
return lhs["name"].asString() < rhs["name"].asString();
});
}
dp.emit();
}
dp.emit();
} catch (const std::exception &e) {
spdlog::error("Workspaces: {}", e.what());
}
} else {
if (scrolling_) {
scrolling_ = false;
}
}
}
@ -154,6 +150,11 @@ auto Workspaces::update() -> void {
} else {
button.get_style_context()->remove_class("urgent");
}
if ((*it)["target_output"].isString()) {
button.get_style_context()->add_class("persistant");
} else {
button.get_style_context()->remove_class("persistant");
}
if (needReorder) {
box_.reorder_child(button, it - workspaces_.begin());
}
@ -176,7 +177,7 @@ auto Workspaces::update() -> void {
Gtk::Button &Workspaces::addButton(const Json::Value &node) {
auto pair = buttons_.emplace(node["name"].asString(), node["name"].asString());
auto &button = pair.first->second;
auto &&button = pair.first->second;
box_.pack_start(button, false, false, 0);
button.set_relief(Gtk::RELIEF_NONE);
button.signal_clicked().connect([this, node] {
@ -195,10 +196,6 @@ Gtk::Button &Workspaces::addButton(const Json::Value &node) {
spdlog::error("Workspaces: {}", e.what());
}
});
if (!config_["disable-scroll"].asBool()) {
button.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
button.signal_scroll_event().connect(sigc::mem_fun(*this, &Workspaces::handleScroll));
}
return button;
}
@ -217,45 +214,28 @@ std::string Workspaces::getIcon(const std::string &name, const Json::Value &node
}
bool Workspaces::handleScroll(GdkEventScroll *e) {
// Avoid concurrent scroll event
if (scrolling_) {
return false;
auto dir = AModule::getScrollDir(e);
if (dir == SCROLL_DIR::NONE) {
return true;
}
std::string name;
scrolling_ = true;
{
std::lock_guard<std::mutex> lock(mutex_);
auto it = std::find_if(workspaces_.begin(), workspaces_.end(), [](const auto &workspace) {
return workspace["focused"].asBool();
});
if (it == workspaces_.end()) {
scrolling_ = false;
return false;
return true;
}
switch (e->direction) {
case GDK_SCROLL_DOWN:
case GDK_SCROLL_RIGHT:
if (dir == SCROLL_DIR::DOWN || dir == SCROLL_DIR::RIGHT) {
name = getCycleWorkspace(it, false);
break;
case GDK_SCROLL_UP:
case GDK_SCROLL_LEFT:
} else if (dir == SCROLL_DIR::UP || dir == SCROLL_DIR::LEFT) {
name = getCycleWorkspace(it, true);
break;
case GDK_SCROLL_SMOOTH:
gdouble delta_x, delta_y;
gdk_event_get_scroll_deltas(reinterpret_cast<const GdkEvent *>(e), &delta_x, &delta_y);
if (delta_y < 0) {
name = getCycleWorkspace(it, true);
} else if (delta_y > 0) {
name = getCycleWorkspace(it, false);
} else {
return true;
}
break;
default:
break;
}
if (name.empty() || name == (*it)["name"].asString()) {
scrolling_ = false;
return false;
if (name == (*it)["name"].asString()) {
return true;
}
}
try {
@ -305,6 +285,4 @@ void Workspaces::onButtonReady(const Json::Value &node, Gtk::Button &button) {
}
}
Workspaces::operator Gtk::Widget &() { return box_; }
} // namespace waybar::modules::sway