mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Compare commits
45 Commits
Author | SHA1 | Date | |
---|---|---|---|
9c8e39c30c | |||
5b270dae0d | |||
c621afb0c4 | |||
bcf4725349 | |||
12b30ca25f | |||
86d6668ed4 | |||
7c85aec8e0 | |||
2c038d1977 | |||
ff9d598c16 | |||
71a9a75aad | |||
05f796158b | |||
1d2dd953e7 | |||
527144a440 | |||
cda6282277 | |||
7f13478396 | |||
90a9c0e25f | |||
340ec7be91 | |||
e7eef6b493 | |||
1b7068e61d | |||
dabe2bebbb | |||
486b5a5d38 | |||
11bbc3b24d | |||
7f74de977c | |||
028b184f7b | |||
564fdcb369 | |||
396f7d4525 | |||
3c9b533997 | |||
ae397c8fa2 | |||
ec75be0bc3 | |||
ed4521d113 | |||
c2e9ed6091 | |||
a37b4687ff | |||
ee29a35aa5 | |||
0be8e200ce | |||
46e5dd93d4 | |||
2ee4a51546 | |||
91996a85c1 | |||
460d25ac45 | |||
648eecdd83 | |||
f04ff38567 | |||
d20a586734 | |||
1962caf144 | |||
9dbf057f58 | |||
918146c16b | |||
0b01b35c76 |
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
> Highly customizable Wayland bar for Sway and Wlroots based compositors.<br>
|
> 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
|
> 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**
|
**Current features**
|
||||||
- Sway (Workspaces, Binding mode, Focused window name)
|
- Sway (Workspaces, Binding mode, Focused window name)
|
||||||
@ -42,6 +43,7 @@ $ waybar
|
|||||||
gtkmm3
|
gtkmm3
|
||||||
jsoncpp
|
jsoncpp
|
||||||
libinput
|
libinput
|
||||||
|
|
||||||
libsigc++
|
libsigc++
|
||||||
fmt
|
fmt
|
||||||
wayland
|
wayland
|
||||||
|
@ -1,41 +1,30 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glibmm/markup.h>
|
#include <glibmm/markup.h>
|
||||||
#include <gtkmm/eventbox.h>
|
|
||||||
#include <gtkmm/label.h>
|
#include <gtkmm/label.h>
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
#include "IModule.hpp"
|
#include "AModule.hpp"
|
||||||
|
|
||||||
namespace waybar {
|
namespace waybar {
|
||||||
|
|
||||||
class ALabel : public IModule {
|
class ALabel : public AModule {
|
||||||
public:
|
public:
|
||||||
ALabel(const Json::Value &, const std::string &, const std::string &, const std::string &format,
|
ALabel(const Json::Value &, const std::string &, const std::string &, const std::string &format,
|
||||||
uint16_t interval = 0);
|
uint16_t interval = 0);
|
||||||
virtual ~ALabel();
|
virtual ~ALabel() = default;
|
||||||
virtual auto update() -> void;
|
virtual auto update() -> void;
|
||||||
virtual std::string getIcon(uint16_t, const std::string &alt = "", uint16_t max = 0);
|
virtual std::string getIcon(uint16_t, const std::string &alt = "", uint16_t max = 0);
|
||||||
virtual operator Gtk::Widget &();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool tooltipEnabled();
|
|
||||||
|
|
||||||
Gtk::EventBox event_box_;
|
|
||||||
Gtk::Label label_;
|
Gtk::Label label_;
|
||||||
const Json::Value & config_;
|
|
||||||
std::string format_;
|
std::string format_;
|
||||||
std::string click_param;
|
std::string click_param;
|
||||||
std::mutex mutex_;
|
|
||||||
const std::chrono::seconds interval_;
|
const std::chrono::seconds interval_;
|
||||||
bool alt_ = false;
|
bool alt_ = false;
|
||||||
std::string default_format_;
|
std::string default_format_;
|
||||||
|
|
||||||
virtual bool handleToggle(GdkEventButton *const &ev);
|
virtual bool handleToggle(GdkEventButton *const &e);
|
||||||
virtual bool handleScroll(GdkEventScroll *);
|
|
||||||
virtual std::string getState(uint8_t value, bool lesser = false);
|
virtual std::string getState(uint8_t value, bool lesser = false);
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<int> pid_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar
|
} // namespace waybar
|
||||||
|
40
include/AModule.hpp
Normal file
40
include/AModule.hpp
Normal 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
|
@ -1,7 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glibmm/dispatcher.h>
|
|
||||||
#include <gtkmm/box.h>
|
|
||||||
#include <gtkmm/widget.h>
|
#include <gtkmm/widget.h>
|
||||||
|
|
||||||
namespace waybar {
|
namespace waybar {
|
||||||
@ -11,7 +9,6 @@ class IModule {
|
|||||||
virtual ~IModule() = default;
|
virtual ~IModule() = default;
|
||||||
virtual auto update() -> void = 0;
|
virtual auto update() -> void = 0;
|
||||||
virtual operator Gtk::Widget &() = 0;
|
virtual operator Gtk::Widget &() = 0;
|
||||||
Glib::Dispatcher dp; // Hmmm Maybe I should create an abstract class ?
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar
|
} // namespace waybar
|
||||||
|
@ -4,8 +4,9 @@
|
|||||||
#include <gtkmm/cssprovider.h>
|
#include <gtkmm/cssprovider.h>
|
||||||
#include <gtkmm/main.h>
|
#include <gtkmm/main.h>
|
||||||
#include <gtkmm/window.h>
|
#include <gtkmm/window.h>
|
||||||
|
#include <gtkmm/box.h>
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
#include "IModule.hpp"
|
#include "AModule.hpp"
|
||||||
#include "idle-inhibit-unstable-v1-client-protocol.h"
|
#include "idle-inhibit-unstable-v1-client-protocol.h"
|
||||||
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
||||||
#include "xdg-output-unstable-v1-client-protocol.h"
|
#include "xdg-output-unstable-v1-client-protocol.h"
|
||||||
@ -73,9 +74,9 @@ class Bar {
|
|||||||
Gtk::Box center_;
|
Gtk::Box center_;
|
||||||
Gtk::Box right_;
|
Gtk::Box right_;
|
||||||
Gtk::Box box_;
|
Gtk::Box box_;
|
||||||
std::vector<std::unique_ptr<waybar::IModule>> modules_left_;
|
std::vector<std::unique_ptr<waybar::AModule>> modules_left_;
|
||||||
std::vector<std::unique_ptr<waybar::IModule>> modules_center_;
|
std::vector<std::unique_ptr<waybar::AModule>> modules_center_;
|
||||||
std::vector<std::unique_ptr<waybar::IModule>> modules_right_;
|
std::vector<std::unique_ptr<waybar::AModule>> modules_right_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar
|
} // namespace waybar
|
||||||
|
@ -37,7 +37,7 @@ namespace waybar {
|
|||||||
class Factory {
|
class Factory {
|
||||||
public:
|
public:
|
||||||
Factory(const Bar& bar, const Json::Value& config);
|
Factory(const Bar& bar, const Json::Value& config);
|
||||||
IModule* makeModule(const std::string& name) const;
|
AModule* makeModule(const std::string& name) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Bar& bar_;
|
const Bar& bar_;
|
||||||
|
@ -21,14 +21,13 @@ class Pulseaudio : public ALabel {
|
|||||||
static void sourceInfoCb(pa_context*, const pa_source_info* i, int, void* data);
|
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 serverInfoCb(pa_context*, const pa_server_info*, void*);
|
||||||
static void volumeModifyCb(pa_context*, int, void*);
|
static void volumeModifyCb(pa_context*, int, void*);
|
||||||
bool handleVolume(GdkEventScroll* e);
|
|
||||||
|
|
||||||
|
bool handleScroll(GdkEventScroll* e);
|
||||||
const std::string getPortIcon() const;
|
const std::string getPortIcon() const;
|
||||||
|
|
||||||
pa_threaded_mainloop* mainloop_;
|
pa_threaded_mainloop* mainloop_;
|
||||||
pa_mainloop_api* mainloop_api_;
|
pa_mainloop_api* mainloop_api_;
|
||||||
pa_context* context_;
|
pa_context* context_;
|
||||||
bool scrolling_;
|
|
||||||
// SINK
|
// SINK
|
||||||
uint32_t sink_idx_{0};
|
uint32_t sink_idx_{0};
|
||||||
uint16_t volume_;
|
uint16_t volume_;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#include "IModule.hpp"
|
#include "AModule.hpp"
|
||||||
#include "bar.hpp"
|
#include "bar.hpp"
|
||||||
#include "modules/sni/host.hpp"
|
#include "modules/sni/host.hpp"
|
||||||
#include "modules/sni/watcher.hpp"
|
#include "modules/sni/watcher.hpp"
|
||||||
@ -9,19 +9,17 @@
|
|||||||
|
|
||||||
namespace waybar::modules::SNI {
|
namespace waybar::modules::SNI {
|
||||||
|
|
||||||
class Tray : public IModule {
|
class Tray : public AModule {
|
||||||
public:
|
public:
|
||||||
Tray(const std::string&, const Bar&, const Json::Value&);
|
Tray(const std::string&, const Bar&, const Json::Value&);
|
||||||
~Tray() = default;
|
~Tray() = default;
|
||||||
auto update() -> void;
|
auto update() -> void;
|
||||||
operator Gtk::Widget&();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onAdd(std::unique_ptr<Item>& item);
|
void onAdd(std::unique_ptr<Item>& item);
|
||||||
void onRemove(std::unique_ptr<Item>& item);
|
void onRemove(std::unique_ptr<Item>& item);
|
||||||
|
|
||||||
static inline std::size_t nb_hosts_ = 0;
|
static inline std::size_t nb_hosts_ = 0;
|
||||||
const Json::Value& config_;
|
|
||||||
Gtk::Box box_;
|
Gtk::Box box_;
|
||||||
SNI::Watcher watcher_;
|
SNI::Watcher watcher_;
|
||||||
SNI::Host host_;
|
SNI::Host host_;
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include "ipc.hpp"
|
#include "ipc.hpp"
|
||||||
|
@ -22,6 +22,7 @@ class Mode : public ALabel, public sigc::trackable {
|
|||||||
|
|
||||||
std::string mode_;
|
std::string mode_;
|
||||||
util::JsonParser parser_;
|
util::JsonParser parser_;
|
||||||
|
std::mutex mutex_;
|
||||||
|
|
||||||
util::SleeperThread thread_;
|
util::SleeperThread thread_;
|
||||||
Ipc ipc_;
|
Ipc ipc_;
|
||||||
|
@ -21,15 +21,18 @@ class Window : public ALabel, public sigc::trackable {
|
|||||||
void onEvent(const struct Ipc::ipc_response&);
|
void onEvent(const struct Ipc::ipc_response&);
|
||||||
void onCmd(const struct Ipc::ipc_response&);
|
void onCmd(const struct Ipc::ipc_response&);
|
||||||
void worker();
|
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();
|
void getTree();
|
||||||
|
|
||||||
const Bar& bar_;
|
const Bar& bar_;
|
||||||
std::mutex mutex_;
|
|
||||||
std::string window_;
|
std::string window_;
|
||||||
int windowId_;
|
int windowId_;
|
||||||
std::string app_id_;
|
std::string app_id_;
|
||||||
|
std::string old_app_id_;
|
||||||
|
std::size_t app_nb_;
|
||||||
util::JsonParser parser_;
|
util::JsonParser parser_;
|
||||||
|
std::mutex mutex_;
|
||||||
|
|
||||||
util::SleeperThread thread_;
|
util::SleeperThread thread_;
|
||||||
Ipc ipc_;
|
Ipc ipc_;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#include <gtkmm/button.h>
|
#include <gtkmm/button.h>
|
||||||
#include <gtkmm/label.h>
|
#include <gtkmm/label.h>
|
||||||
#include "IModule.hpp"
|
#include "AModule.hpp"
|
||||||
#include "bar.hpp"
|
#include "bar.hpp"
|
||||||
#include "client.hpp"
|
#include "client.hpp"
|
||||||
#include "modules/sway/ipc/client.hpp"
|
#include "modules/sway/ipc/client.hpp"
|
||||||
@ -12,12 +12,11 @@
|
|||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
class Workspaces : public IModule, public sigc::trackable {
|
class Workspaces : public AModule, public sigc::trackable {
|
||||||
public:
|
public:
|
||||||
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
|
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||||
~Workspaces() = default;
|
~Workspaces() = default;
|
||||||
auto update() -> void;
|
auto update() -> void;
|
||||||
operator Gtk::Widget&();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onCmd(const struct Ipc::ipc_response&);
|
void onCmd(const struct Ipc::ipc_response&);
|
||||||
@ -33,14 +32,12 @@ class Workspaces : public IModule, public sigc::trackable {
|
|||||||
bool handleScroll(GdkEventScroll*);
|
bool handleScroll(GdkEventScroll*);
|
||||||
|
|
||||||
const Bar& bar_;
|
const Bar& bar_;
|
||||||
const Json::Value& config_;
|
|
||||||
std::vector<Json::Value> workspaces_;
|
std::vector<Json::Value> workspaces_;
|
||||||
std::vector<std::string> workspaces_order_;
|
std::vector<std::string> workspaces_order_;
|
||||||
std::mutex mutex_;
|
|
||||||
Gtk::Box box_;
|
Gtk::Box box_;
|
||||||
util::JsonParser parser_;
|
util::JsonParser parser_;
|
||||||
bool scrolling_;
|
|
||||||
std::unordered_map<std::string, Gtk::Button> buttons_;
|
std::unordered_map<std::string, Gtk::Button> buttons_;
|
||||||
|
std::mutex mutex_;
|
||||||
|
|
||||||
util::SleeperThread thread_;
|
util::SleeperThread thread_;
|
||||||
Ipc ipc_;
|
Ipc ipc_;
|
||||||
|
@ -33,7 +33,7 @@ inline int close(FILE* fp, pid_t pid) {
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
while (waitpid(pid, &stat, 0) == -1) {
|
while (waitpid(pid, &stat, 0) == -1) {
|
||||||
if (errno != EINTR) {
|
if (errno != EINTR) {
|
||||||
stat = -1;
|
stat = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,6 +90,8 @@ inline int32_t forkExec(std::string cmd) {
|
|||||||
setpgid(pid, pid);
|
setpgid(pid, pid);
|
||||||
execl("/bin/sh", "sh", "-c", cmd.c_str(), (char*)0);
|
execl("/bin/sh", "sh", "-c", cmd.c_str(), (char*)0);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
} else {
|
||||||
|
signal(SIGCHLD,SIG_IGN);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pid;
|
return pid;
|
||||||
|
@ -14,7 +14,10 @@ class SleeperThread {
|
|||||||
|
|
||||||
SleeperThread(std::function<void()> func)
|
SleeperThread(std::function<void()> func)
|
||||||
: thread_{[this, func] {
|
: thread_{[this, func] {
|
||||||
while (do_run_) func();
|
while (do_run_) {
|
||||||
|
signal_ = false;
|
||||||
|
func();
|
||||||
|
}
|
||||||
}} {}
|
}} {}
|
||||||
|
|
||||||
SleeperThread& operator=(std::function<void()> func) {
|
SleeperThread& operator=(std::function<void()> func) {
|
||||||
@ -42,7 +45,10 @@ class SleeperThread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto wake_up() {
|
auto wake_up() {
|
||||||
signal_ = true;
|
{
|
||||||
|
std::lock_guard<std::mutex> lck(mutex_);
|
||||||
|
signal_ = true;
|
||||||
|
}
|
||||||
condvar_.notify_all();
|
condvar_.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
project(
|
project(
|
||||||
'waybar', 'cpp', 'c',
|
'waybar', 'cpp', 'c',
|
||||||
version: '0.6.7',
|
version: '0.7.0',
|
||||||
license: 'MIT',
|
license: 'MIT',
|
||||||
default_options : [
|
default_options : [
|
||||||
'cpp_std=c++17',
|
'cpp_std=c++17',
|
||||||
@ -65,6 +65,7 @@ libmpdclient = dependency('libmpdclient', required: get_option('mpd'))
|
|||||||
|
|
||||||
src_files = files(
|
src_files = files(
|
||||||
'src/factory.cpp',
|
'src/factory.cpp',
|
||||||
|
'src/AModule.cpp',
|
||||||
'src/ALabel.cpp',
|
'src/ALabel.cpp',
|
||||||
'src/modules/memory.cpp',
|
'src/modules/memory.cpp',
|
||||||
'src/modules/battery.cpp',
|
'src/modules/battery.cpp',
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
window#waybar {
|
window#waybar {
|
||||||
background: rgba(43, 48, 59, 0.5);
|
background-color: rgba(43, 48, 59, 0.5);
|
||||||
border-bottom: 3px solid rgba(100, 114, 125, 0.5);
|
border-bottom: 3px solid rgba(100, 114, 125, 0.5);
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
transition-property: background, background-color;
|
transition-property: background-color;
|
||||||
transition-duration: .5s;
|
transition-duration: .5s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,10 +20,10 @@ window#waybar.hidden {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
window#waybar.empty {
|
window#waybar.empty {
|
||||||
background: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
window#waybar.solo {
|
window#waybar.solo {
|
||||||
background: #FFFFFF;
|
background-color: #FFFFFF;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -39,13 +39,13 @@ window#waybar.chromium {
|
|||||||
/* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */
|
/* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */
|
||||||
#workspaces button {
|
#workspaces button {
|
||||||
padding: 0 5px;
|
padding: 0 5px;
|
||||||
background: transparent;
|
background-color: transparent;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
border-bottom: 3px solid transparent;
|
border-bottom: 3px solid transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
#workspaces button.focused {
|
#workspaces button.focused {
|
||||||
background: #64727D;
|
background-color: #64727D;
|
||||||
border-bottom: 3px solid #ffffff;
|
border-bottom: 3px solid #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,13 +54,24 @@ window#waybar.chromium {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#mode {
|
#mode {
|
||||||
background: #64727D;
|
background-color: #64727D;
|
||||||
border-bottom: 3px solid #ffffff;
|
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;
|
padding: 0 10px;
|
||||||
margin: 0 5px;
|
margin: 0 4px;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +97,7 @@ window#waybar.chromium {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#battery.critical:not(.charging) {
|
#battery.critical:not(.charging) {
|
||||||
background: #f53c3c;
|
background-color: #f53c3c;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
animation-name: blink;
|
animation-name: blink;
|
||||||
animation-duration: 0.5s;
|
animation-duration: 0.5s;
|
||||||
@ -100,56 +111,56 @@ label:focus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#cpu {
|
#cpu {
|
||||||
background: #2ecc71;
|
background-color: #2ecc71;
|
||||||
color: #000000;
|
color: #000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
#memory {
|
#memory {
|
||||||
background: #9b59b6;
|
background-color: #9b59b6;
|
||||||
}
|
}
|
||||||
|
|
||||||
#backlight {
|
#backlight {
|
||||||
background: #90b1b1;
|
background-color: #90b1b1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#network {
|
#network {
|
||||||
background: #2980b9;
|
background-color: #2980b9;
|
||||||
}
|
}
|
||||||
|
|
||||||
#network.disconnected {
|
#network.disconnected {
|
||||||
background: #f53c3c;
|
background-color: #f53c3c;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pulseaudio {
|
#pulseaudio {
|
||||||
background: #f1c40f;
|
background-color: #f1c40f;
|
||||||
color: #000000;
|
color: #000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pulseaudio.muted {
|
#pulseaudio.muted {
|
||||||
background: #90b1b1;
|
background-color: #90b1b1;
|
||||||
color: #2a5c45;
|
color: #2a5c45;
|
||||||
}
|
}
|
||||||
|
|
||||||
#custom-media {
|
#custom-media {
|
||||||
background: #66cc99;
|
background-color: #66cc99;
|
||||||
color: #2a5c45;
|
color: #2a5c45;
|
||||||
min-width: 100px;
|
min-width: 100px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom-spotify {
|
#custom-media.custom-spotify {
|
||||||
background: #66cc99;
|
background-color: #66cc99;
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom-vlc {
|
#custom-media.custom-vlc {
|
||||||
background: #ffa000;
|
background-color: #ffa000;
|
||||||
}
|
}
|
||||||
|
|
||||||
#temperature {
|
#temperature {
|
||||||
background: #f0932b;
|
background-color: #f0932b;
|
||||||
}
|
}
|
||||||
|
|
||||||
#temperature.critical {
|
#temperature.critical {
|
||||||
background: #eb4d4b;
|
background-color: #eb4d4b;
|
||||||
}
|
}
|
||||||
|
|
||||||
#tray {
|
#tray {
|
||||||
@ -166,18 +177,18 @@ label:focus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#mpd {
|
#mpd {
|
||||||
background: #66cc99;
|
background-color: #66cc99;
|
||||||
color: #2a5c45;
|
color: #2a5c45;
|
||||||
}
|
}
|
||||||
|
|
||||||
#mpd.disconnected {
|
#mpd.disconnected {
|
||||||
background: #f53c3c;
|
background-color: #f53c3c;
|
||||||
}
|
}
|
||||||
|
|
||||||
#mpd.stopped {
|
#mpd.stopped {
|
||||||
background: #90b1b1;
|
background-color: #90b1b1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#mpd.paused {
|
#mpd.paused {
|
||||||
background: #51a37a;
|
background-color: #51a37a;
|
||||||
}
|
}
|
||||||
|
115
src/ALabel.cpp
115
src/ALabel.cpp
@ -2,9 +2,11 @@
|
|||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#include <util/command.hpp>
|
#include <util/command.hpp>
|
||||||
|
|
||||||
waybar::ALabel::ALabel(const Json::Value& config, const std::string& name, const std::string& id,
|
namespace waybar {
|
||||||
const std::string& format, uint16_t interval)
|
|
||||||
: config_(config),
|
ALabel::ALabel(const Json::Value& config, const std::string& name, const std::string& id,
|
||||||
|
const std::string& format, uint16_t interval)
|
||||||
|
: AModule(config, name, id, config["format-alt"].isString()),
|
||||||
format_(config_["format"].isString() ? config_["format"].asString() : format),
|
format_(config_["format"].isString() ? config_["format"].asString() : format),
|
||||||
interval_(config_["interval"] == "once"
|
interval_(config_["interval"] == "once"
|
||||||
? std::chrono::seconds(100000000)
|
? std::chrono::seconds(100000000)
|
||||||
@ -24,96 +26,13 @@ waybar::ALabel::ALabel(const Json::Value& config, const std::string& name, const
|
|||||||
if (config_["rotate"].isUInt()) {
|
if (config_["rotate"].isUInt()) {
|
||||||
label_.set_angle(config["rotate"].asUInt());
|
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() {
|
auto ALabel::update() -> void {
|
||||||
for (const auto& pid : pid_) {
|
|
||||||
if (pid != -1) {
|
|
||||||
kill(-pid, 9);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto waybar::ALabel::update() -> void {
|
|
||||||
// Nothing here
|
// Nothing here
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waybar::ALabel::handleToggle(GdkEventButton* const& e) {
|
std::string ALabel::getIcon(uint16_t percentage, const std::string& alt, uint16_t max) {
|
||||||
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) {
|
|
||||||
auto format_icons = config_["format-icons"];
|
auto format_icons = config_["format-icons"];
|
||||||
if (format_icons.isObject()) {
|
if (format_icons.isObject()) {
|
||||||
if (!alt.empty() && (format_icons[alt].isString() || format_icons[alt].isArray())) {
|
if (!alt.empty() && (format_icons[alt].isString() || format_icons[alt].isArray())) {
|
||||||
@ -133,7 +52,19 @@ std::string waybar::ALabel::getIcon(uint16_t percentage, const std::string& alt,
|
|||||||
return "";
|
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()) {
|
if (!config_["states"].isObject()) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -162,8 +93,4 @@ std::string waybar::ALabel::getState(uint8_t value, bool lesser) {
|
|||||||
return valid_state;
|
return valid_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waybar::ALabel::tooltipEnabled() {
|
} // namespace waybar
|
||||||
return config_["tooltip"].isBool() ? config_["tooltip"].asBool() : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
waybar::ALabel::operator Gtk::Widget&() { return event_box_; }
|
|
||||||
|
119
src/AModule.cpp
Normal file
119
src/AModule.cpp
Normal 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
|
14
src/bar.cpp
14
src/bar.cpp
@ -17,6 +17,7 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
|
|||||||
window.set_title("waybar");
|
window.set_title("waybar");
|
||||||
window.set_name("waybar");
|
window.set_name("waybar");
|
||||||
window.set_decorated(false);
|
window.set_decorated(false);
|
||||||
|
window.get_style_context()->add_class(output->name);
|
||||||
|
|
||||||
if (config["position"] == "right" || config["position"] == "left") {
|
if (config["position"] == "right" || config["position"] == "left") {
|
||||||
height_ = 0;
|
height_ = 0;
|
||||||
@ -286,14 +287,11 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos) {
|
|||||||
modules_right_.emplace_back(module);
|
modules_right_.emplace_back(module);
|
||||||
}
|
}
|
||||||
module->dp.connect([module, &name] {
|
module->dp.connect([module, &name] {
|
||||||
// Fix https://github.com/Alexays/Waybar/issues/320, proper way?
|
try {
|
||||||
Glib::signal_idle().connect_once([module, &name] {
|
module->update();
|
||||||
try {
|
} catch (const std::exception& e) {
|
||||||
module->update();
|
spdlog::error("{}: {}", name.asString(), e.what());
|
||||||
} catch (const std::exception& e) {
|
}
|
||||||
spdlog::error("{}: {}", name.asString(), e.what());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
spdlog::warn("module {}: {}", name.asString(), e.what());
|
spdlog::warn("module {}: {}", name.asString(), e.what());
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
waybar::Factory::Factory(const Bar& bar, const Json::Value& config) : bar_(bar), config_(config) {}
|
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 {
|
try {
|
||||||
auto hash_pos = name.find('#');
|
auto hash_pos = name.find('#');
|
||||||
auto ref = name.substr(0, hash_pos);
|
auto ref = name.substr(0, hash_pos);
|
||||||
|
@ -102,14 +102,14 @@ auto waybar::modules::Custom::update() -> void {
|
|||||||
} else {
|
} else {
|
||||||
parseOutputRaw();
|
parseOutputRaw();
|
||||||
}
|
}
|
||||||
if (text_.empty()) {
|
auto str = fmt::format(format_,
|
||||||
|
text_,
|
||||||
|
fmt::arg("alt", alt_),
|
||||||
|
fmt::arg("icon", getIcon(percentage_, alt_)),
|
||||||
|
fmt::arg("percentage", percentage_));
|
||||||
|
if (str.empty()) {
|
||||||
event_box_.hide();
|
event_box_.hide();
|
||||||
} else {
|
} else {
|
||||||
auto str = fmt::format(format_,
|
|
||||||
text_,
|
|
||||||
fmt::arg("alt", alt_),
|
|
||||||
fmt::arg("icon", getIcon(percentage_, alt_)),
|
|
||||||
fmt::arg("percentage", percentage_));
|
|
||||||
label_.set_markup(str);
|
label_.set_markup(str);
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
if (text_ == tooltip_) {
|
if (text_ == tooltip_) {
|
||||||
|
@ -11,6 +11,7 @@ waybar::modules::Memory::Memory(const std::string& id, const Json::Value& config
|
|||||||
auto waybar::modules::Memory::update() -> void {
|
auto waybar::modules::Memory::update() -> void {
|
||||||
parseMeminfo();
|
parseMeminfo();
|
||||||
if (memtotal_ > 0 && memfree_ >= 0) {
|
if (memtotal_ > 0 && memfree_ >= 0) {
|
||||||
|
auto total_ram_gigabytes = memtotal_ / std::pow(1024, 2);
|
||||||
int used_ram_percentage = 100 * (memtotal_ - memfree_) / memtotal_;
|
int used_ram_percentage = 100 * (memtotal_ - memfree_) / memtotal_;
|
||||||
auto used_ram_gigabytes = (memtotal_ - memfree_) / std::pow(1024, 2);
|
auto used_ram_gigabytes = (memtotal_ - memfree_) / std::pow(1024, 2);
|
||||||
auto available_ram_gigabytes = 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);
|
getState(used_ram_percentage);
|
||||||
label_.set_markup(fmt::format(format_,
|
label_.set_markup(fmt::format(format_,
|
||||||
used_ram_percentage,
|
used_ram_percentage,
|
||||||
|
fmt::arg("total", total_ram_gigabytes),
|
||||||
fmt::arg("percentage", used_ram_percentage),
|
fmt::arg("percentage", used_ram_percentage),
|
||||||
fmt::arg("used", used_ram_gigabytes),
|
fmt::arg("used", used_ram_gigabytes),
|
||||||
fmt::arg("avail", available_ram_gigabytes)));
|
fmt::arg("avail", available_ram_gigabytes)));
|
||||||
|
@ -5,7 +5,6 @@ waybar::modules::Pulseaudio::Pulseaudio(const std::string &id, const Json::Value
|
|||||||
mainloop_(nullptr),
|
mainloop_(nullptr),
|
||||||
mainloop_api_(nullptr),
|
mainloop_api_(nullptr),
|
||||||
context_(nullptr),
|
context_(nullptr),
|
||||||
scrolling_(false),
|
|
||||||
sink_idx_(0),
|
sink_idx_(0),
|
||||||
volume_(0),
|
volume_(0),
|
||||||
muted_(false),
|
muted_(false),
|
||||||
@ -32,13 +31,6 @@ waybar::modules::Pulseaudio::Pulseaudio(const std::string &id, const Json::Value
|
|||||||
throw std::runtime_error("pa_mainloop_run() failed.");
|
throw std::runtime_error("pa_mainloop_run() failed.");
|
||||||
}
|
}
|
||||||
pa_threaded_mainloop_unlock(mainloop_);
|
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
waybar::modules::Pulseaudio::~Pulseaudio() {
|
waybar::modules::Pulseaudio::~Pulseaudio() {
|
||||||
@ -74,50 +66,33 @@ void waybar::modules::Pulseaudio::contextStateCb(pa_context *c, void *data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waybar::modules::Pulseaudio::handleVolume(GdkEventScroll *e) {
|
bool waybar::modules::Pulseaudio::handleScroll(GdkEventScroll *e) {
|
||||||
// Avoid concurrent scroll event
|
// change the pulse volume only when no user provided
|
||||||
if (scrolling_) {
|
// events are configured
|
||||||
return false;
|
if (config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString()) {
|
||||||
|
return AModule::handleScroll(e);
|
||||||
}
|
}
|
||||||
bool direction_up = false;
|
auto dir = AModule::getScrollDir(e);
|
||||||
double volume_tick = (double)PA_VOLUME_NORM / 100;
|
if (dir == SCROLL_DIR::NONE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
double volume_tick = static_cast<double>(PA_VOLUME_NORM) / 100;
|
||||||
pa_volume_t change = volume_tick;
|
pa_volume_t change = volume_tick;
|
||||||
pa_cvolume pa_volume = pa_volume_;
|
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
|
// isDouble returns true for integers as well, just in case
|
||||||
if (config_["scroll-step"].isDouble()) {
|
if (config_["scroll-step"].isDouble()) {
|
||||||
change = round(config_["scroll-step"].asDouble() * volume_tick);
|
change = round(config_["scroll-step"].asDouble() * volume_tick);
|
||||||
}
|
}
|
||||||
|
if (dir == SCROLL_DIR::UP) {
|
||||||
if (direction_up) {
|
|
||||||
if (volume_ + 1 < 100) {
|
if (volume_ + 1 < 100) {
|
||||||
pa_cvolume_inc(&pa_volume, change);
|
pa_cvolume_inc(&pa_volume, change);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (dir == SCROLL_DIR::DOWN) {
|
||||||
if (volume_ - 1 >= 0) {
|
if (volume_ - 1 >= 0) {
|
||||||
pa_cvolume_dec(&pa_volume, change);
|
pa_cvolume_dec(&pa_volume, change);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_context_set_sink_volume_by_index(context_, sink_idx_, &pa_volume, volumeModifyCb, this);
|
pa_context_set_sink_volume_by_index(context_, sink_idx_, &pa_volume, volumeModifyCb, this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,6 +103,10 @@ void waybar::modules::Pulseaudio::subscribeCb(pa_context * conte
|
|||||||
pa_subscription_event_type_t type, uint32_t idx,
|
pa_subscription_event_type_t type, uint32_t idx,
|
||||||
void *data) {
|
void *data) {
|
||||||
unsigned facility = type & PA_SUBSCRIPTION_EVENT_FACILITY_MASK;
|
unsigned facility = type & PA_SUBSCRIPTION_EVENT_FACILITY_MASK;
|
||||||
|
unsigned operation = type & PA_SUBSCRIPTION_EVENT_TYPE_MASK;
|
||||||
|
if (operation != PA_SUBSCRIPTION_EVENT_CHANGE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (facility == PA_SUBSCRIPTION_EVENT_SINK) {
|
if (facility == PA_SUBSCRIPTION_EVENT_SINK) {
|
||||||
pa_context_get_sink_info_by_index(context, idx, sinkInfoCb, data);
|
pa_context_get_sink_info_by_index(context, idx, sinkInfoCb, data);
|
||||||
} else if (facility == PA_SUBSCRIPTION_EVENT_SOURCE) {
|
} else if (facility == PA_SUBSCRIPTION_EVENT_SOURCE) {
|
||||||
@ -245,7 +224,4 @@ auto waybar::modules::Pulseaudio::update() -> void {
|
|||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
label_.set_tooltip_text(desc_);
|
label_.set_tooltip_text(desc_);
|
||||||
}
|
}
|
||||||
if (scrolling_) {
|
|
||||||
scrolling_ = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
#include "modules/sni/item.hpp"
|
||||||
#include <glibmm/main.h>
|
#include <glibmm/main.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include "modules/sni/item.hpp"
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct fmt::formatter<Glib::ustring> : formatter<std::string> {
|
struct fmt::formatter<Glib::ustring> : formatter<std::string> {
|
||||||
@ -334,7 +334,7 @@ void Item::makeMenu(GdkEventButton* const& ev) {
|
|||||||
bool Item::handleClick(GdkEventButton* const& ev) {
|
bool Item::handleClick(GdkEventButton* const& ev) {
|
||||||
auto parameters = Glib::VariantContainerBase::create_tuple(
|
auto parameters = Glib::VariantContainerBase::create_tuple(
|
||||||
{Glib::Variant<int>::create(ev->x), Glib::Variant<int>::create(ev->y)});
|
{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);
|
makeMenu(ev);
|
||||||
if (gtk_menu != nullptr) {
|
if (gtk_menu != nullptr) {
|
||||||
#if GTK_CHECK_VERSION(3, 22, 0)
|
#if GTK_CHECK_VERSION(3, 22, 0)
|
||||||
|
@ -4,15 +4,16 @@
|
|||||||
namespace waybar::modules::SNI {
|
namespace waybar::modules::SNI {
|
||||||
|
|
||||||
Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
|
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),
|
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0),
|
||||||
watcher_(nb_hosts_),
|
watcher_(nb_hosts_),
|
||||||
host_(nb_hosts_, config, std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
host_(nb_hosts_, config, std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
||||||
std::bind(&Tray::onRemove, this, std::placeholders::_1)) {
|
std::bind(&Tray::onRemove, this, std::placeholders::_1)) {
|
||||||
box_.set_name("tray");
|
|
||||||
spdlog::warn(
|
spdlog::warn(
|
||||||
"For a functionnal tray you must have libappindicator-* installed and export "
|
"For a functionnal tray you must have libappindicator-* installed and export "
|
||||||
"XDG_CURRENT_DESKTOP=Unity");
|
"XDG_CURRENT_DESKTOP=Unity");
|
||||||
|
box_.set_name("tray");
|
||||||
|
event_box_.add(box_);
|
||||||
if (!id.empty()) {
|
if (!id.empty()) {
|
||||||
box_.get_style_context()->add_class(id);
|
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
|
} // namespace waybar::modules::SNI
|
||||||
|
@ -142,4 +142,4 @@ void Ipc::handleEvent() {
|
|||||||
signal_event.emit(res);
|
signal_event.emit(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace waybar::modules::sway
|
} // namespace waybar::modules::sway
|
||||||
|
@ -13,6 +13,7 @@ Mode::Mode(const std::string& id, const Json::Value& config) : ALabel(config, "m
|
|||||||
|
|
||||||
void Mode::onEvent(const struct Ipc::ipc_response& res) {
|
void Mode::onEvent(const struct Ipc::ipc_response& res) {
|
||||||
try {
|
try {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
auto payload = parser_.parse(res.payload);
|
auto payload = parser_.parse(res.payload);
|
||||||
if (payload["change"] != "default") {
|
if (payload["change"] != "default") {
|
||||||
mode_ = Glib::Markup::escape_text(payload["change"].asString());
|
mode_ = Glib::Markup::escape_text(payload["change"].asString());
|
||||||
|
@ -6,7 +6,6 @@ namespace waybar::modules::sway {
|
|||||||
Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
|
Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||||
: ALabel(config, "window", id, "{}"), bar_(bar), windowId_(-1) {
|
: ALabel(config, "window", id, "{}"), bar_(bar), windowId_(-1) {
|
||||||
if (label_.get_max_width_chars() == -1) {
|
if (label_.get_max_width_chars() == -1) {
|
||||||
label_.set_hexpand(true);
|
|
||||||
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END);
|
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END);
|
||||||
}
|
}
|
||||||
ipc_.subscribe(R"(["window","workspace"])");
|
ipc_.subscribe(R"(["window","workspace"])");
|
||||||
@ -24,33 +23,9 @@ void Window::onCmd(const struct Ipc::ipc_response& res) {
|
|||||||
try {
|
try {
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
auto payload = parser_.parse(res.payload);
|
auto payload = parser_.parse(res.payload);
|
||||||
auto [nb, id, name, app_id] = getFocusedNode(payload);
|
auto output = payload["ouput"].isString() ? payload["output"].asString() : "";
|
||||||
if (!app_id_.empty()) {
|
std::tie(app_nb_, windowId_, window_, app_id_) = getFocusedNode(payload["nodes"], output);
|
||||||
bar_.window.get_style_context()->remove_class(app_id_);
|
dp.emit();
|
||||||
}
|
|
||||||
if (nb == 0) {
|
|
||||||
bar_.window.get_style_context()->remove_class("solo");
|
|
||||||
if (!bar_.window.get_style_context()->has_class("empty")) {
|
|
||||||
bar_.window.get_style_context()->add_class("empty");
|
|
||||||
}
|
|
||||||
} else if (nb == 1) {
|
|
||||||
bar_.window.get_style_context()->remove_class("empty");
|
|
||||||
if (!bar_.window.get_style_context()->has_class("solo")) {
|
|
||||||
bar_.window.get_style_context()->add_class("solo");
|
|
||||||
}
|
|
||||||
if (!app_id.empty() && !bar_.window.get_style_context()->has_class(app_id)) {
|
|
||||||
bar_.window.get_style_context()->add_class(app_id);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
bar_.window.get_style_context()->remove_class("solo");
|
|
||||||
bar_.window.get_style_context()->remove_class("empty");
|
|
||||||
}
|
|
||||||
app_id_ = app_id;
|
|
||||||
if (windowId_ != id || window_ != name) {
|
|
||||||
windowId_ = id;
|
|
||||||
window_ = name;
|
|
||||||
dp.emit();
|
|
||||||
}
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
spdlog::error("Window: {}", e.what());
|
spdlog::error("Window: {}", e.what());
|
||||||
}
|
}
|
||||||
@ -67,6 +42,27 @@ void Window::worker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto Window::update() -> void {
|
auto Window::update() -> void {
|
||||||
|
if (!old_app_id_.empty()) {
|
||||||
|
bar_.window.get_style_context()->remove_class(old_app_id_);
|
||||||
|
}
|
||||||
|
if (app_nb_ == 0) {
|
||||||
|
bar_.window.get_style_context()->remove_class("solo");
|
||||||
|
if (!bar_.window.get_style_context()->has_class("empty")) {
|
||||||
|
bar_.window.get_style_context()->add_class("empty");
|
||||||
|
}
|
||||||
|
} else if (app_nb_ == 1) {
|
||||||
|
bar_.window.get_style_context()->remove_class("empty");
|
||||||
|
if (!bar_.window.get_style_context()->has_class("solo")) {
|
||||||
|
bar_.window.get_style_context()->add_class("solo");
|
||||||
|
}
|
||||||
|
if (!app_id_.empty() && !bar_.window.get_style_context()->has_class(app_id_)) {
|
||||||
|
bar_.window.get_style_context()->add_class(app_id_);
|
||||||
|
old_app_id_ = app_id_;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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_, window_));
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
label_.set_tooltip_text(window_);
|
label_.set_tooltip_text(window_);
|
||||||
@ -74,20 +70,28 @@ auto Window::update() -> void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<std::size_t, int, std::string, std::string> Window::getFocusedNode(
|
std::tuple<std::size_t, int, std::string, std::string> Window::getFocusedNode(
|
||||||
const Json::Value& nodes) {
|
const Json::Value& nodes, std::string& output) {
|
||||||
for (auto const& node : nodes["nodes"]) {
|
for (auto const& node : nodes) {
|
||||||
if (node["focused"].asBool() && node["type"] == "con") {
|
if (node["output"].isString()) {
|
||||||
if ((!config_["all-outputs"].asBool() && nodes["output"] == bar_.output->name) ||
|
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()) {
|
config_["all-outputs"].asBool()) {
|
||||||
auto app_id = node["app_id"].isString() ? node["app_id"].asString()
|
auto app_id = node["app_id"].isString() ? node["app_id"].asString()
|
||||||
: node["window_properties"]["instance"].asString();
|
: node["window_properties"]["instance"].asString();
|
||||||
return {nodes["nodes"].size(),
|
return {nodes.size(),
|
||||||
node["id"].asInt(),
|
node["id"].asInt(),
|
||||||
Glib::Markup::escape_text(node["name"].asString()),
|
Glib::Markup::escape_text(node["name"].asString()),
|
||||||
app_id};
|
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()) {
|
if (id > -1 && !name.empty()) {
|
||||||
return {nb, id, name, app_id};
|
return {nb, id, name, app_id};
|
||||||
}
|
}
|
||||||
|
@ -4,14 +4,14 @@
|
|||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config)
|
Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config)
|
||||||
: bar_(bar),
|
: AModule(config, "workspaces", id, false, !config["disable-scroll"].asBool()),
|
||||||
config_(config),
|
bar_(bar),
|
||||||
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0),
|
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0) {
|
||||||
scrolling_(false) {
|
|
||||||
box_.set_name("workspaces");
|
box_.set_name("workspaces");
|
||||||
if (!id.empty()) {
|
if (!id.empty()) {
|
||||||
box_.get_style_context()->add_class(id);
|
box_.get_style_context()->add_class(id);
|
||||||
}
|
}
|
||||||
|
event_box_.add(box_);
|
||||||
ipc_.subscribe(R"(["workspace"])");
|
ipc_.subscribe(R"(["workspace"])");
|
||||||
ipc_.signal_event.connect(sigc::mem_fun(*this, &Workspaces::onEvent));
|
ipc_.signal_event.connect(sigc::mem_fun(*this, &Workspaces::onEvent));
|
||||||
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Workspaces::onCmd));
|
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) {
|
void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
||||||
if (res.type == IPC_GET_WORKSPACES) {
|
if (res.type == IPC_GET_WORKSPACES) {
|
||||||
try {
|
try {
|
||||||
auto payload = parser_.parse(res.payload);
|
{
|
||||||
if (payload.isArray()) {
|
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
auto payload = parser_.parse(res.payload);
|
||||||
workspaces_.clear();
|
workspaces_.clear();
|
||||||
std::copy_if(payload.begin(),
|
std::copy_if(payload.begin(),
|
||||||
payload.end(),
|
payload.end(),
|
||||||
@ -80,6 +80,7 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
|||||||
// Adding to all outputs
|
// Adding to all outputs
|
||||||
Json::Value v;
|
Json::Value v;
|
||||||
v["name"] = p_w_name;
|
v["name"] = p_w_name;
|
||||||
|
v["target_output"] = "";
|
||||||
workspaces_.emplace_back(std::move(v));
|
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();
|
return lhs["name"].asString() < rhs["name"].asString();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
dp.emit();
|
|
||||||
}
|
}
|
||||||
|
dp.emit();
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
spdlog::error("Workspaces: {}", e.what());
|
spdlog::error("Workspaces: {}", e.what());
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (scrolling_) {
|
|
||||||
scrolling_ = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,6 +150,11 @@ auto Workspaces::update() -> void {
|
|||||||
} else {
|
} else {
|
||||||
button.get_style_context()->remove_class("urgent");
|
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) {
|
if (needReorder) {
|
||||||
box_.reorder_child(button, it - workspaces_.begin());
|
box_.reorder_child(button, it - workspaces_.begin());
|
||||||
}
|
}
|
||||||
@ -175,8 +176,8 @@ auto Workspaces::update() -> void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Gtk::Button &Workspaces::addButton(const Json::Value &node) {
|
Gtk::Button &Workspaces::addButton(const Json::Value &node) {
|
||||||
auto pair = buttons_.emplace(node["name"].asString(), node["name"].asString());
|
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);
|
box_.pack_start(button, false, false, 0);
|
||||||
button.set_relief(Gtk::RELIEF_NONE);
|
button.set_relief(Gtk::RELIEF_NONE);
|
||||||
button.signal_clicked().connect([this, node] {
|
button.signal_clicked().connect([this, node] {
|
||||||
@ -195,10 +196,6 @@ Gtk::Button &Workspaces::addButton(const Json::Value &node) {
|
|||||||
spdlog::error("Workspaces: {}", e.what());
|
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;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,46 +214,27 @@ std::string Workspaces::getIcon(const std::string &name, const Json::Value &node
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Workspaces::handleScroll(GdkEventScroll *e) {
|
bool Workspaces::handleScroll(GdkEventScroll *e) {
|
||||||
// Avoid concurrent scroll event
|
auto dir = AModule::getScrollDir(e);
|
||||||
if (scrolling_) {
|
if (dir == SCROLL_DIR::NONE) {
|
||||||
return false;
|
return 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()) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
std::string name;
|
std::string name;
|
||||||
scrolling_ = true;
|
if (dir == SCROLL_DIR::DOWN || dir == SCROLL_DIR::RIGHT) {
|
||||||
{
|
name = getCycleWorkspace(it, false);
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
} else if (dir == SCROLL_DIR::UP || dir == SCROLL_DIR::LEFT) {
|
||||||
auto it = std::find_if(workspaces_.begin(), workspaces_.end(), [](const auto &workspace) {
|
name = getCycleWorkspace(it, true);
|
||||||
return workspace["focused"].asBool();
|
} else {
|
||||||
});
|
return true;
|
||||||
if (it == workspaces_.end()) {
|
}
|
||||||
scrolling_ = false;
|
if (name == (*it)["name"].asString()) {
|
||||||
return false;
|
return true;
|
||||||
}
|
|
||||||
switch (e->direction) {
|
|
||||||
case GDK_SCROLL_DOWN:
|
|
||||||
case GDK_SCROLL_RIGHT:
|
|
||||||
name = getCycleWorkspace(it, false);
|
|
||||||
break;
|
|
||||||
case GDK_SCROLL_UP:
|
|
||||||
case GDK_SCROLL_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);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (name.empty() || name == (*it)["name"].asString()) {
|
|
||||||
scrolling_ = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ipc_.sendCmd(IPC_COMMAND, fmt::format("workspace \"{}\"", name));
|
ipc_.sendCmd(IPC_COMMAND, fmt::format("workspace \"{}\"", name));
|
||||||
@ -305,6 +283,4 @@ void Workspaces::onButtonReady(const Json::Value &node, Gtk::Button &button) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Workspaces::operator Gtk::Widget &() { return box_; }
|
|
||||||
|
|
||||||
} // namespace waybar::modules::sway
|
} // namespace waybar::modules::sway
|
||||||
|
Reference in New Issue
Block a user