mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Compare commits
34 Commits
Author | SHA1 | Date | |
---|---|---|---|
3691d84543 | |||
b554094c7e | |||
66ad2864c2 | |||
c7b0639f32 | |||
0acc50264e | |||
1b13f9e38c | |||
7befd27059 | |||
2ec34e4adb | |||
812a7a9861 | |||
1d96d57b75 | |||
691fb88057 | |||
281bab4943 | |||
8e93fd3ae0 | |||
37c7e586d6 | |||
3a5a470d90 | |||
c051b517ca | |||
a0cdef569b | |||
a123711a8d | |||
391a7de94a | |||
952d877652 | |||
5356d25a9b | |||
65b9911df4 | |||
2aed121903 | |||
08bfdda4cb | |||
8f8ec3b999 | |||
a17220054d | |||
4cc48b3cfd | |||
087de4e956 | |||
2c2a0473f4 | |||
2e1f8b2fc5 | |||
686bc4828e | |||
f6c2a8d9b7 | |||
baa7f52e21 | |||
c4c0c01a2f |
@ -6,6 +6,7 @@ services:
|
||||
env:
|
||||
- distro: debian
|
||||
- distro: archlinux
|
||||
- distro: opensuse
|
||||
|
||||
before_install:
|
||||
- docker pull alexays/waybar:${distro}
|
||||
|
5
Dockerfiles/opensuse
Normal file
5
Dockerfiles/opensuse
Normal file
@ -0,0 +1,5 @@
|
||||
FROM opensuse/tumbleweed:latest
|
||||
|
||||
RUN zypper -n up && \
|
||||
zypper -n install -t pattern devel_C_C++ && \
|
||||
zypper -n install git meson clang libinput-devel libwayland-client0 libwayland-cursor0 wayland-protocols-devel wayland-devel Mesa-libEGL-devel Mesa-libGLESv2-devel libgbm-devel libxkbcommon-devel libudev-devel libpixman-1-0-devel gtkmm3-devel jsoncpp-devel
|
@ -26,7 +26,6 @@ class Bar {
|
||||
std::string output_name;
|
||||
uint32_t wl_name;
|
||||
bool visible = true;
|
||||
uint32_t nb_tray_hosts = 0;
|
||||
private:
|
||||
static void handleLogicalPosition(void *, struct zxdg_output_v1 *, int32_t,
|
||||
int32_t);
|
||||
|
@ -15,7 +15,7 @@ class Client {
|
||||
Client(int argc, char *argv[]);
|
||||
int main(int argc, char *argv[]);
|
||||
|
||||
Glib::RefPtr<Gtk::Application> gtk_app;
|
||||
Gtk::Main gtk_main;
|
||||
std::string css_file;
|
||||
std::string config_file;
|
||||
Glib::RefPtr<Gdk::Display> gdk_display;
|
||||
@ -27,8 +27,9 @@ class Client {
|
||||
std::vector<std::unique_ptr<Bar>> bars;
|
||||
|
||||
private:
|
||||
void setupConfigs(const std::string& config, const std::string& style);
|
||||
void bindInterfaces();
|
||||
auto setupCss();
|
||||
const std::string getValidPath(std::vector<std::string> paths);
|
||||
|
||||
static void handleGlobal(void *data, struct wl_registry *registry,
|
||||
uint32_t name, const char *interface, uint32_t version);
|
||||
|
@ -27,10 +27,10 @@ class Bar;
|
||||
|
||||
class Factory {
|
||||
public:
|
||||
Factory(Bar& bar, const Json::Value& config);
|
||||
Factory(const Bar& bar, const Json::Value& config);
|
||||
IModule* makeModule(const std::string &name) const;
|
||||
private:
|
||||
Bar& bar_;
|
||||
const Bar& bar_;
|
||||
const Json::Value& config_;
|
||||
};
|
||||
|
||||
|
@ -23,7 +23,7 @@ namespace fs = std::filesystem;
|
||||
|
||||
class Battery : public ALabel {
|
||||
public:
|
||||
Battery(const Json::Value&);
|
||||
Battery(const std::string&, const Json::Value&);
|
||||
~Battery();
|
||||
auto update() -> void;
|
||||
private:
|
||||
|
@ -9,7 +9,7 @@ namespace waybar::modules {
|
||||
|
||||
class Clock : public ALabel {
|
||||
public:
|
||||
Clock(const Json::Value&);
|
||||
Clock(const std::string&, const Json::Value&);
|
||||
auto update() -> void;
|
||||
private:
|
||||
waybar::util::SleeperThread thread_;
|
||||
|
@ -13,7 +13,7 @@ namespace waybar::modules {
|
||||
|
||||
class Cpu : public ALabel {
|
||||
public:
|
||||
Cpu(const Json::Value&);
|
||||
Cpu(const std::string&, const Json::Value&);
|
||||
auto update() -> void;
|
||||
private:
|
||||
static inline const std::string data_dir_ = "/proc/stat";
|
||||
|
@ -11,7 +11,8 @@ namespace waybar::modules {
|
||||
|
||||
class Custom : public ALabel {
|
||||
public:
|
||||
Custom(const std::string, const Json::Value&);
|
||||
Custom(const std::string&, const Json::Value&);
|
||||
~Custom();
|
||||
auto update() -> void;
|
||||
private:
|
||||
void delayWorker();
|
||||
@ -27,6 +28,7 @@ class Custom : public ALabel {
|
||||
waybar::util::SleeperThread thread_;
|
||||
waybar::util::command::res output_;
|
||||
waybar::util::JsonParser parser_;
|
||||
FILE* fp_;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace waybar::modules {
|
||||
|
||||
class Memory : public ALabel {
|
||||
public:
|
||||
Memory(const Json::Value&);
|
||||
Memory(const std::string&, const Json::Value&);
|
||||
auto update() -> void;
|
||||
private:
|
||||
static inline const std::string data_dir_ = "/proc/meminfo";
|
||||
|
@ -15,7 +15,7 @@ namespace waybar::modules {
|
||||
|
||||
class Network : public ALabel {
|
||||
public:
|
||||
Network(const Json::Value&);
|
||||
Network(const std::string&, const Json::Value&);
|
||||
~Network();
|
||||
auto update() -> void;
|
||||
private:
|
||||
|
@ -10,7 +10,7 @@ namespace waybar::modules {
|
||||
|
||||
class Pulseaudio : public ALabel {
|
||||
public:
|
||||
Pulseaudio(const Json::Value&);
|
||||
Pulseaudio(const std::string&, const Json::Value&);
|
||||
~Pulseaudio();
|
||||
auto update() -> void;
|
||||
private:
|
||||
|
@ -12,13 +12,14 @@ namespace waybar::modules::SNI {
|
||||
|
||||
class Tray : public IModule {
|
||||
public:
|
||||
Tray(Bar& bar, const Json::Value&);
|
||||
Tray(const std::string&, const Json::Value&);
|
||||
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;
|
||||
std::thread thread_;
|
||||
const Json::Value& config_;
|
||||
Gtk::Box box_;
|
||||
|
@ -12,12 +12,12 @@ namespace waybar::modules::sway {
|
||||
|
||||
class Mode : public ALabel {
|
||||
public:
|
||||
Mode(waybar::Bar&, const Json::Value&);
|
||||
Mode(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
auto update() -> void;
|
||||
private:
|
||||
void worker();
|
||||
|
||||
Bar& bar_;
|
||||
const Bar& bar_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
util::JsonParser parser_;
|
||||
Ipc ipc_;
|
||||
|
@ -13,14 +13,14 @@ namespace waybar::modules::sway {
|
||||
|
||||
class Window : public ALabel {
|
||||
public:
|
||||
Window(waybar::Bar&, const Json::Value&);
|
||||
Window(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
auto update() -> void;
|
||||
private:
|
||||
void worker();
|
||||
std::tuple<int, std::string> getFocusedNode(Json::Value nodes);
|
||||
void getFocusedWindow();
|
||||
|
||||
Bar& bar_;
|
||||
const Bar& bar_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
util::JsonParser parser_;
|
||||
Ipc ipc_;
|
||||
|
@ -12,7 +12,7 @@ namespace waybar::modules::sway {
|
||||
|
||||
class Workspaces : public IModule {
|
||||
public:
|
||||
Workspaces(waybar::Bar&, const Json::Value&);
|
||||
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
auto update() -> void;
|
||||
operator Gtk::Widget &();
|
||||
private:
|
||||
@ -23,7 +23,7 @@ class Workspaces : public IModule {
|
||||
std::string getPrevWorkspace();
|
||||
std::string getNextWorkspace();
|
||||
|
||||
Bar& bar_;
|
||||
const Bar& bar_;
|
||||
const Json::Value& config_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
Gtk::Box box_;
|
||||
|
@ -23,35 +23,24 @@ struct SleeperThread {
|
||||
SleeperThread() = default;
|
||||
|
||||
SleeperThread(std::function<void()> func)
|
||||
: thread_{[this, func] {
|
||||
while(true) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!do_run_) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
func();
|
||||
}
|
||||
: do_run_(true), thread_{[this, func] {
|
||||
while (do_run_) func();
|
||||
}}
|
||||
{}
|
||||
|
||||
SleeperThread& operator=(std::function<void()> func)
|
||||
{
|
||||
do_run_ = true;
|
||||
thread_ = std::thread([this, func] {
|
||||
while(true) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!do_run_) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
func();
|
||||
}
|
||||
while (do_run_) func();
|
||||
});
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool isRunnging() const
|
||||
{
|
||||
return do_run_;
|
||||
}
|
||||
|
||||
auto sleep_for(chrono::duration dur)
|
||||
{
|
||||
@ -74,21 +63,21 @@ struct SleeperThread {
|
||||
{
|
||||
do_run_ = false;
|
||||
condvar_.notify_all();
|
||||
if (thread_.joinable()) {
|
||||
thread_.detach();
|
||||
}
|
||||
}
|
||||
|
||||
~SleeperThread()
|
||||
{
|
||||
stop();
|
||||
if (thread_.joinable()) {
|
||||
thread_.detach();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool do_run_ = false;
|
||||
std::thread thread_;
|
||||
std::condition_variable condvar_;
|
||||
std::mutex mutex_;
|
||||
bool do_run_ = true;
|
||||
};
|
||||
|
||||
}
|
||||
|
1264
include/util/clara.hpp
Normal file
1264
include/util/clara.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
project(
|
||||
'waybar', 'cpp', 'c',
|
||||
version: '0.2.2',
|
||||
version: '0.2.3',
|
||||
license: 'MIT',
|
||||
default_options : [
|
||||
'cpp_std=c++17',
|
||||
@ -9,7 +9,7 @@ project(
|
||||
],
|
||||
)
|
||||
|
||||
cpp_args = []
|
||||
cpp_args = ['-DVERSION="@0@"'.format(meson.project_version())]
|
||||
cpp_link_args = []
|
||||
|
||||
if false # libc++
|
||||
|
@ -78,8 +78,6 @@
|
||||
"custom/spotify": {
|
||||
"format": " {}",
|
||||
"max-length": 40,
|
||||
"interval": 30, // Remove this if your script is endless and write in loop
|
||||
"exec": "$HOME/.config/waybar/mediaplayer.sh 2> /dev/null", // Script in resources folder
|
||||
"exec-if": "pgrep spotify"
|
||||
"exec": "$HOME/.config/waybar/mediaplayer.py 2> /dev/null" // Script in resources folder
|
||||
}
|
||||
}
|
||||
|
71
resources/custom_modules/mediaplayer.py
Executable file
71
resources/custom_modules/mediaplayer.py
Executable file
@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import signal
|
||||
import gi
|
||||
gi.require_version('Playerctl', '2.0')
|
||||
from gi.repository import Playerctl, GLib
|
||||
|
||||
manager = Playerctl.PlayerManager()
|
||||
loop = GLib.MainLoop()
|
||||
|
||||
|
||||
def on_play(player, status, manager):
|
||||
on_metadata(player, player.props.metadata, manager)
|
||||
|
||||
|
||||
def on_metadata(player, metadata, manager):
|
||||
track_info = ''
|
||||
|
||||
if player.props.player_name == 'spotify' and \
|
||||
'mpris:trackid' in metadata.keys() and \
|
||||
':ad:' in player.props.metadata['mpris:trackid']:
|
||||
track_info = 'AD PLAYING'
|
||||
elif player.get_artist() != '' and player.get_title() != '':
|
||||
track_info = '{artist} - {title}'.format(artist=player.get_artist(),
|
||||
title=player.get_title())
|
||||
else:
|
||||
sys.stdout.write('\n')
|
||||
sys.stdout.flush()
|
||||
return
|
||||
|
||||
if player.props.status == 'Playing':
|
||||
sys.stdout.write(track_info + '\n')
|
||||
else:
|
||||
sys.stdout.write(' ' + track_info + '\n')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def on_name_appeared(manager, name):
|
||||
init_player(name)
|
||||
|
||||
|
||||
def on_player_vanished(manager, player):
|
||||
sys.stdout.write("\n")
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def init_player(name):
|
||||
player = Playerctl.Player.new_from_name(name)
|
||||
player.connect('playback-status', on_play, manager)
|
||||
player.connect('metadata', on_metadata, manager)
|
||||
manager.manage_player(player)
|
||||
on_metadata(player, player.props.metadata, manager)
|
||||
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
sys.stdout.write("\n")
|
||||
sys.stdout.flush()
|
||||
loop.quit()
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
manager.connect('name-appeared', on_name_appeared)
|
||||
manager.connect('player-vanished', on_player_vanished)
|
||||
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
|
||||
for player in manager.props.player_names:
|
||||
init_player(player)
|
||||
|
||||
loop.run()
|
@ -1,7 +0,0 @@
|
||||
#!/bin/sh
|
||||
player_status=$(playerctl status 2> /dev/null)
|
||||
if [ "$player_status" = "Playing" ]; then
|
||||
echo "$(playerctl metadata artist) - $(playerctl metadata title)"
|
||||
elif [ "$player_status" = "Paused" ]; then
|
||||
echo " $(playerctl metadata artist) - $(playerctl metadata title)"
|
||||
fi
|
@ -21,17 +21,12 @@ waybar::ALabel::ALabel(const Json::Value& config, const std::string format, uint
|
||||
}
|
||||
|
||||
// configure events' user commands
|
||||
if (config_["on-click"].isString()) {
|
||||
if (config_["on-click"].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()) {
|
||||
event_box_.add_events(Gdk::SCROLL_MASK);
|
||||
event_box_.signal_scroll_event().connect(
|
||||
sigc::mem_fun(*this, &ALabel::handleScroll));
|
||||
}
|
||||
if (config_["on-scroll-down"].isString()) {
|
||||
if (config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString()) {
|
||||
event_box_.add_events(Gdk::SCROLL_MASK);
|
||||
event_box_.signal_scroll_event().connect(
|
||||
sigc::mem_fun(*this, &ALabel::handleScroll));
|
||||
@ -45,6 +40,8 @@ auto waybar::ALabel::update() -> void {
|
||||
bool waybar::ALabel::handleToggle(GdkEventButton* const& e) {
|
||||
if (config_["on-click"].isString() && e->button == 1) {
|
||||
waybar::util::command::forkExec(config_["on-click"].asString());
|
||||
} else if (config_["on-click-right"].isString() && e->button == 3) {
|
||||
waybar::util::command::forkExec(config_["on-click-right"].asString());
|
||||
} else {
|
||||
alt = !alt;
|
||||
if (alt) {
|
||||
|
@ -184,7 +184,13 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos)
|
||||
if (pos == "modules-right") {
|
||||
modules_right_.emplace_back(module);
|
||||
}
|
||||
module->dp.connect([module] { module->update(); });
|
||||
module->dp.connect([module, &name] {
|
||||
try {
|
||||
module->update();
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << name.asString() + ": " + e.what() << std::endl;
|
||||
}
|
||||
});
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include "client.hpp"
|
||||
#include "util/clara.hpp"
|
||||
#include <iostream>
|
||||
|
||||
waybar::Client::Client(int argc, char* argv[])
|
||||
: gtk_app(Gtk::Application::create(argc, argv, "fr.arouillard.waybar")),
|
||||
: gtk_main(argc, argv),
|
||||
gdk_display(Gdk::Display::get_default())
|
||||
{
|
||||
if (!gdk_display) {
|
||||
@ -12,10 +13,13 @@ waybar::Client::Client(int argc, char* argv[])
|
||||
throw std::runtime_error("Bar need to run under Wayland");
|
||||
}
|
||||
wl_display = gdk_wayland_display_get_wl_display(gdk_display->gobj());
|
||||
auto getFirstValidPath = [] (std::vector<std::string> possiblePaths) {
|
||||
}
|
||||
|
||||
const std::string waybar::Client::getValidPath(std::vector<std::string> paths)
|
||||
{
|
||||
wordexp_t p;
|
||||
|
||||
for (const std::string &path: possiblePaths) {
|
||||
for (const std::string &path: paths) {
|
||||
if (wordexp(path.c_str(), &p, 0) == 0) {
|
||||
if (access(*p.we_wordv, F_OK) == 0) {
|
||||
std::string result = *p.we_wordv;
|
||||
@ -27,21 +31,6 @@ waybar::Client::Client(int argc, char* argv[])
|
||||
}
|
||||
|
||||
return std::string();
|
||||
};
|
||||
|
||||
config_file = getFirstValidPath({
|
||||
"$XDG_CONFIG_HOME/waybar/config",
|
||||
"$HOME/waybar/config",
|
||||
"/etc/xdg/waybar/config",
|
||||
"./resources/config",
|
||||
});
|
||||
css_file = getFirstValidPath({
|
||||
"$XDG_CONFIG_HOME/waybar/style.css",
|
||||
"$HOME/waybar/style.css",
|
||||
"/etc/xdg/waybar/style.css",
|
||||
"./resources/style.css",
|
||||
});
|
||||
std::cout << "Resources files: " + config_file + ", " + css_file << std::endl;
|
||||
}
|
||||
|
||||
void waybar::Client::handleGlobal(void *data, struct wl_registry *registry,
|
||||
@ -81,6 +70,28 @@ void waybar::Client::handleGlobalRemove(void* data,
|
||||
}
|
||||
}
|
||||
|
||||
void waybar::Client::setupConfigs(const std::string& config, const std::string& style)
|
||||
{
|
||||
config_file = config.empty() ? getValidPath({
|
||||
"$XDG_CONFIG_HOME/waybar/config",
|
||||
"$HOME/.config/waybar/config",
|
||||
"$HOME/waybar/config",
|
||||
"/etc/xdg/waybar/config",
|
||||
"./resources/config",
|
||||
}) : config;
|
||||
css_file = style.empty() ? getValidPath({
|
||||
"$XDG_CONFIG_HOME/waybar/style.css",
|
||||
"$HOME/.config/waybar/style.css",
|
||||
"$HOME/waybar/style.css",
|
||||
"/etc/xdg/waybar/style.css",
|
||||
"./resources/style.css",
|
||||
}) : style;
|
||||
if (css_file.empty() || config_file.empty()) {
|
||||
throw std::runtime_error("Missing required resources files");
|
||||
}
|
||||
std::cout << "Resources files: " + config_file + ", " + css_file << std::endl;
|
||||
}
|
||||
|
||||
void waybar::Client::bindInterfaces()
|
||||
{
|
||||
registry = wl_display_get_registry(wl_display);
|
||||
@ -96,11 +107,32 @@ void waybar::Client::bindInterfaces()
|
||||
wl_display_roundtrip(wl_display);
|
||||
}
|
||||
|
||||
int waybar::Client::main(int /*argc*/, char* /*argv*/[])
|
||||
int waybar::Client::main(int argc, char* argv[])
|
||||
{
|
||||
bool show_help = false;
|
||||
bool show_version = false;
|
||||
std::string config;
|
||||
std::string style;
|
||||
auto cli = clara::detail::Help(show_help)
|
||||
| clara::detail::Opt(show_version)["-v"]["--version"]("Show version")
|
||||
| clara::detail::Opt(config, "config")["-c"]["--config"]("Config path")
|
||||
| clara::detail::Opt(style, "style")["-s"]["--style"]("Style path");
|
||||
auto res = cli.parse(clara::detail::Args(argc, argv));
|
||||
if (!res) {
|
||||
std::cerr << "Error in command line: " << res.errorMessage() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if (show_help) {
|
||||
std::cout << cli << std::endl;
|
||||
return 0;
|
||||
}
|
||||
if (show_version) {
|
||||
std::cout << "Waybar v" << VERSION << std::endl;
|
||||
return 0;
|
||||
}
|
||||
setupConfigs(config, style);
|
||||
bindInterfaces();
|
||||
gtk_app->hold();
|
||||
gtk_app->run();
|
||||
gtk_main.run();
|
||||
bars.clear();
|
||||
zxdg_output_manager_v1_destroy(xdg_output_manager);
|
||||
zwlr_layer_shell_v1_destroy(layer_shell);
|
||||
|
@ -1,49 +1,51 @@
|
||||
#include "factory.hpp"
|
||||
|
||||
waybar::Factory::Factory(Bar& bar, const Json::Value& 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
|
||||
{
|
||||
try {
|
||||
auto ref = name.substr(0, name.find("#"));
|
||||
auto hash_pos = name.find("#");
|
||||
auto ref = name.substr(0, hash_pos);
|
||||
auto id = hash_pos != std::string::npos ? name.substr(hash_pos + 1) : "";
|
||||
if (ref == "battery") {
|
||||
return new waybar::modules::Battery(config_[name]);
|
||||
return new waybar::modules::Battery(id, config_[name]);
|
||||
}
|
||||
#ifdef HAVE_SWAY
|
||||
if (ref == "sway/mode") {
|
||||
return new waybar::modules::sway::Mode(bar_, config_[name]);
|
||||
return new waybar::modules::sway::Mode(id, bar_, config_[name]);
|
||||
}
|
||||
if (ref == "sway/workspaces") {
|
||||
return new waybar::modules::sway::Workspaces(bar_, config_[name]);
|
||||
return new waybar::modules::sway::Workspaces(id, bar_, config_[name]);
|
||||
}
|
||||
if (ref == "sway/window") {
|
||||
return new waybar::modules::sway::Window(bar_, config_[name]);
|
||||
return new waybar::modules::sway::Window(id, bar_, config_[name]);
|
||||
}
|
||||
#endif
|
||||
if (ref == "memory") {
|
||||
return new waybar::modules::Memory(config_[name]);
|
||||
return new waybar::modules::Memory(id, config_[name]);
|
||||
}
|
||||
if (ref == "cpu") {
|
||||
return new waybar::modules::Cpu(config_[name]);
|
||||
return new waybar::modules::Cpu(id, config_[name]);
|
||||
}
|
||||
if (ref == "clock") {
|
||||
return new waybar::modules::Clock(config_[name]);
|
||||
return new waybar::modules::Clock(id, config_[name]);
|
||||
}
|
||||
#ifdef HAVE_DBUSMENU
|
||||
if (ref == "tray") {
|
||||
return new waybar::modules::SNI::Tray(bar_, config_[name]);
|
||||
return new waybar::modules::SNI::Tray(id, config_[name]);
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_LIBNL
|
||||
if (ref == "network") {
|
||||
return new waybar::modules::Network(config_[name]);
|
||||
return new waybar::modules::Network(id, config_[name]);
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_LIBPULSE
|
||||
if (ref == "pulseaudio") {
|
||||
return new waybar::modules::Pulseaudio(config_[name]);
|
||||
return new waybar::modules::Pulseaudio(id, config_[name]);
|
||||
}
|
||||
#endif
|
||||
if (ref.compare(0, 7, "custom/") == 0 && ref.size() > 7) {
|
||||
|
@ -15,7 +15,7 @@ int main(int argc, char* argv[])
|
||||
waybar::client = &c;
|
||||
std::signal(SIGUSR1, [] (int /*signal*/) {
|
||||
for (auto& bar : waybar::client->bars) {
|
||||
(*bar).toggle();
|
||||
bar->toggle();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1,8 +1,12 @@
|
||||
#include "modules/battery.hpp"
|
||||
|
||||
waybar::modules::Battery::Battery(const Json::Value& config)
|
||||
waybar::modules::Battery::Battery(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "{capacity}%", 60)
|
||||
{
|
||||
label_.set_name("battery");
|
||||
if (!id.empty()) {
|
||||
label_.get_style_context()->add_class(id);
|
||||
}
|
||||
try {
|
||||
if (config_["bat"].isString()) {
|
||||
auto dir = data_dir_ / config_["bat"].asString();
|
||||
@ -101,7 +105,7 @@ const std::string waybar::modules::Battery::getState(uint8_t capacity) const
|
||||
return a.second < b.second;
|
||||
});
|
||||
std::string valid_state;
|
||||
for (auto state : states) {
|
||||
for (auto const& state : states) {
|
||||
if (capacity <= state.second && valid_state.empty()) {
|
||||
label_.get_style_context()->add_class(state.first);
|
||||
valid_state = state.first;
|
||||
@ -131,10 +135,8 @@ auto waybar::modules::Battery::update() -> void
|
||||
}
|
||||
if (format.empty()) {
|
||||
event_box_.hide();
|
||||
label_.set_name("");
|
||||
} else {
|
||||
event_box_.show();
|
||||
label_.set_name("battery");
|
||||
label_.set_markup(fmt::format(format, fmt::arg("capacity", capacity),
|
||||
fmt::arg("icon", getIcon(capacity))));
|
||||
}
|
||||
|
@ -1,16 +1,19 @@
|
||||
#include "modules/clock.hpp"
|
||||
|
||||
waybar::modules::Clock::Clock(const Json::Value& config)
|
||||
waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "{:%H:%M}", 60)
|
||||
{
|
||||
label_.set_name("clock");
|
||||
if (!id.empty()) {
|
||||
label_.get_style_context()->add_class(id);
|
||||
}
|
||||
thread_ = [this] {
|
||||
auto now = waybar::chrono::clock::now();
|
||||
dp.emit();
|
||||
auto timeout = std::chrono::floor<std::chrono::seconds>(now + interval_);
|
||||
auto time_s = std::chrono::time_point_cast<std::chrono::seconds>(timeout);
|
||||
auto sub_m =
|
||||
std::chrono::duration_cast<std::chrono::seconds>(time_s.time_since_epoch()).count() % 60;
|
||||
std::chrono::duration_cast<std::chrono::seconds>(time_s.time_since_epoch()).count() % interval_.count();
|
||||
thread_.sleep_until(timeout - std::chrono::seconds(sub_m - 1));
|
||||
};
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
#include "modules/cpu.hpp"
|
||||
|
||||
waybar::modules::Cpu::Cpu(const Json::Value& config)
|
||||
waybar::modules::Cpu::Cpu(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "{usage}%", 10)
|
||||
{
|
||||
label_.set_name("cpu");
|
||||
if (!id.empty()) {
|
||||
label_.get_style_context()->add_class(id);
|
||||
}
|
||||
thread_ = [this] {
|
||||
dp.emit();
|
||||
thread_.sleep_for(interval_);
|
||||
@ -12,16 +15,12 @@ waybar::modules::Cpu::Cpu(const Json::Value& config)
|
||||
|
||||
auto waybar::modules::Cpu::update() -> void
|
||||
{
|
||||
try {
|
||||
// TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both
|
||||
auto cpu_load = getCpuLoad();
|
||||
auto [cpu_usage, tooltip] = getCpuUsage();
|
||||
label_.set_tooltip_text(tooltip);
|
||||
label_.set_markup(fmt::format(format_,
|
||||
fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage)));
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t waybar::modules::Cpu::getCpuLoad()
|
||||
|
@ -1,18 +1,27 @@
|
||||
#include "modules/custom.hpp"
|
||||
|
||||
waybar::modules::Custom::Custom(const std::string name,
|
||||
waybar::modules::Custom::Custom(const std::string& name,
|
||||
const Json::Value& config)
|
||||
: ALabel(config, "{}"), name_(name)
|
||||
: ALabel(config, "{}"), name_(name), fp_(nullptr)
|
||||
{
|
||||
if (!config_["exec"].isString()) {
|
||||
throw std::runtime_error(name_ + " has no exec path.");
|
||||
}
|
||||
label_.set_name("custom-" + name_);
|
||||
if (config_["exec"].isString()) {
|
||||
if (interval_.count() > 0) {
|
||||
delayWorker();
|
||||
} else {
|
||||
continuousWorker();
|
||||
}
|
||||
}
|
||||
dp.emit();
|
||||
}
|
||||
|
||||
waybar::modules::Custom::~Custom()
|
||||
{
|
||||
if (fp_) {
|
||||
pclose(fp_);
|
||||
fp_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void waybar::modules::Custom::delayWorker()
|
||||
{
|
||||
@ -22,8 +31,7 @@ void waybar::modules::Custom::delayWorker()
|
||||
auto res = waybar::util::command::exec(config_["exec-if"].asString());
|
||||
if (res.exit_code != 0) {
|
||||
can_update = false;
|
||||
label_.hide();
|
||||
label_.set_name("");
|
||||
event_box_.hide();
|
||||
}
|
||||
}
|
||||
if (can_update) {
|
||||
@ -37,17 +45,21 @@ void waybar::modules::Custom::delayWorker()
|
||||
void waybar::modules::Custom::continuousWorker()
|
||||
{
|
||||
auto cmd = config_["exec"].asString();
|
||||
FILE* fp(popen(cmd.c_str(), "r"));
|
||||
if (!fp) {
|
||||
fp_ = popen(cmd.c_str(), "r");
|
||||
if (!fp_) {
|
||||
throw std::runtime_error("Unable to open " + cmd);
|
||||
}
|
||||
thread_ = [this, fp] {
|
||||
thread_ = [this] {
|
||||
char* buff = nullptr;
|
||||
size_t len = 0;
|
||||
if (getline(&buff, &len, fp) == -1) {
|
||||
pclose(fp);
|
||||
if (getline(&buff, &len, fp_) == -1) {
|
||||
if (fp_) {
|
||||
pclose(fp_);
|
||||
fp_ = nullptr;
|
||||
}
|
||||
thread_.stop();
|
||||
output_ = { 1, "" };
|
||||
std::cerr << name_ + " just stopped, is it endless?" << std::endl;
|
||||
dp.emit();
|
||||
return;
|
||||
}
|
||||
@ -66,12 +78,9 @@ void waybar::modules::Custom::continuousWorker()
|
||||
auto waybar::modules::Custom::update() -> void
|
||||
{
|
||||
// Hide label if output is empty
|
||||
if (output_.out.empty() || output_.exit_code != 0) {
|
||||
label_.hide();
|
||||
label_.set_name("");
|
||||
if (config_["exec"].isString() && (output_.out.empty() || output_.exit_code != 0)) {
|
||||
event_box_.hide();
|
||||
} else {
|
||||
label_.set_name("custom-" + name_);
|
||||
|
||||
if (config_["return-type"].asString() == "json") {
|
||||
parseOutputJson();
|
||||
} else {
|
||||
@ -96,7 +105,7 @@ auto waybar::modules::Custom::update() -> void
|
||||
prevclass_ = "";
|
||||
}
|
||||
|
||||
label_.show();
|
||||
event_box_.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,12 @@
|
||||
#include "modules/memory.hpp"
|
||||
|
||||
waybar::modules::Memory::Memory(const Json::Value& config)
|
||||
waybar::modules::Memory::Memory(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "{}%", 30)
|
||||
{
|
||||
label_.set_name("memory");
|
||||
if (!id.empty()) {
|
||||
label_.get_style_context()->add_class(id);
|
||||
}
|
||||
thread_ = [this] {
|
||||
dp.emit();
|
||||
thread_.sleep_for(interval_);
|
||||
@ -17,11 +21,9 @@ auto waybar::modules::Memory::update() -> void
|
||||
label_.set_markup(fmt::format(format_, used_ram_percentage));
|
||||
auto used_ram_gigabytes = (memtotal_ - memfree_) / std::pow(1024, 2);
|
||||
label_.set_tooltip_text(fmt::format("{:.{}f}Gb used", used_ram_gigabytes, 1));
|
||||
label_.set_name("memory");
|
||||
label_.show();
|
||||
event_box_.show();
|
||||
} else {
|
||||
label_.set_name("");
|
||||
label_.hide();
|
||||
event_box_.hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,13 @@
|
||||
#include "modules/network.hpp"
|
||||
|
||||
waybar::modules::Network::Network(const Json::Value& config)
|
||||
waybar::modules::Network::Network(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "{ifname}", 60), family_(AF_INET),
|
||||
signal_strength_dbm_(0), signal_strength_(0)
|
||||
cidr_(-1), signal_strength_dbm_(0), signal_strength_(0)
|
||||
{
|
||||
label_.set_name("network");
|
||||
if (!id.empty()) {
|
||||
label_.get_style_context()->add_class(id);
|
||||
}
|
||||
sock_fd_ = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
|
||||
if (sock_fd_ < 0) {
|
||||
throw std::runtime_error("Can't open network socket");
|
||||
@ -26,14 +30,12 @@ waybar::modules::Network::Network(const Json::Value& config)
|
||||
char ifname[IF_NAMESIZE];
|
||||
if_indextoname(ifid_, ifname);
|
||||
ifname_ = ifname;
|
||||
getInterfaceAddress();
|
||||
}
|
||||
}
|
||||
initNL80211();
|
||||
label_.set_name("network");
|
||||
// Trigger first values
|
||||
getInfo();
|
||||
update();
|
||||
dp.emit();
|
||||
worker();
|
||||
}
|
||||
|
||||
@ -47,8 +49,10 @@ void waybar::modules::Network::worker()
|
||||
{
|
||||
thread_ = [this] {
|
||||
char buf[4096];
|
||||
uint64_t len = netlinkResponse(sock_fd_, buf, sizeof(buf),
|
||||
RTMGRP_LINK | RTMGRP_IPV4_IFADDR);
|
||||
auto len = netlinkResponse(sock_fd_, buf, sizeof(buf), RTMGRP_LINK | RTMGRP_IPV4_IFADDR);
|
||||
if (len == 0) {
|
||||
return;
|
||||
}
|
||||
bool need_update = false;
|
||||
for (auto nh = reinterpret_cast<struct nlmsghdr *>(buf); NLMSG_OK(nh, len);
|
||||
nh = NLMSG_NEXT(nh, len)) {
|
||||
@ -58,6 +62,9 @@ void waybar::modules::Network::worker()
|
||||
if (nh->nlmsg_type == NLMSG_ERROR) {
|
||||
continue;
|
||||
}
|
||||
if (nh->nlmsg_type == RTM_NEWADDR) {
|
||||
need_update = true;
|
||||
}
|
||||
if (nh->nlmsg_type < RTM_NEWADDR) {
|
||||
auto rtif = static_cast<struct ifinfomsg *>(NLMSG_DATA(nh));
|
||||
if (rtif->ifi_index == static_cast<int>(ifid_)) {
|
||||
@ -76,12 +83,13 @@ void waybar::modules::Network::worker()
|
||||
char ifname[IF_NAMESIZE];
|
||||
if_indextoname(ifid_, ifname);
|
||||
ifname_ = ifname;
|
||||
getInterfaceAddress();
|
||||
need_update = true;
|
||||
}
|
||||
}
|
||||
if (need_update) {
|
||||
if (ifid_ > 0) {
|
||||
getInfo();
|
||||
}
|
||||
dp.emit();
|
||||
}
|
||||
};
|
||||
@ -97,7 +105,7 @@ void waybar::modules::Network::worker()
|
||||
auto waybar::modules::Network::update() -> void
|
||||
{
|
||||
auto format = format_;
|
||||
if (ifid_ <= 0) {
|
||||
if (ifid_ <= 0 || ipaddr_.empty()) {
|
||||
format = config_["format-disconnected"].isString()
|
||||
? config_["format-disconnected"].asString() : format;
|
||||
label_.get_style_context()->add_class("disconnected");
|
||||
@ -130,9 +138,13 @@ void waybar::modules::Network::disconnected()
|
||||
ipaddr_.clear();
|
||||
netmask_.clear();
|
||||
cidr_ = 0;
|
||||
if (!config_["interface"].isString()) {
|
||||
ifname_.clear();
|
||||
ifid_ = -1;
|
||||
}
|
||||
// Need to wait otherwise we'll have the same information
|
||||
thread_.sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
|
||||
void waybar::modules::Network::initNL80211()
|
||||
{
|
||||
@ -319,13 +331,12 @@ int waybar::modules::Network::netlinkRequest(int fd, void *req,
|
||||
int waybar::modules::Network::netlinkResponse(int fd, void *resp,
|
||||
uint32_t resplen, uint32_t groups)
|
||||
{
|
||||
int ret;
|
||||
struct sockaddr_nl sa = {};
|
||||
sa.nl_family = AF_NETLINK;
|
||||
sa.nl_groups = groups;
|
||||
struct iovec iov = { resp, resplen };
|
||||
struct msghdr msg = { &sa, sizeof(sa), &iov, 1, nullptr, 0, 0 };
|
||||
ret = recvmsg(fd, &msg, 0);
|
||||
auto ret = recvmsg(fd, &msg, 0);
|
||||
if (msg.msg_flags & MSG_TRUNC) {
|
||||
return -1;
|
||||
}
|
||||
@ -418,9 +429,10 @@ bool waybar::modules::Network::associatedOrJoined(struct nlattr** bss)
|
||||
|
||||
auto waybar::modules::Network::getInfo() -> void
|
||||
{
|
||||
getInterfaceAddress();
|
||||
struct nl_msg* nl_msg = nlmsg_alloc();
|
||||
if (nl_msg == nullptr) {
|
||||
nl_socket_free(sk_);
|
||||
nlmsg_free(nl_msg);
|
||||
return;
|
||||
}
|
||||
if (genlmsg_put(nl_msg, NL_AUTO_PORT, NL_AUTO_SEQ, nl80211_id_, 0, NLM_F_DUMP,
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "modules/pulseaudio.hpp"
|
||||
|
||||
waybar::modules::Pulseaudio::Pulseaudio(const Json::Value &config)
|
||||
waybar::modules::Pulseaudio::Pulseaudio(const std::string& id, const Json::Value &config)
|
||||
: ALabel(config, "{volume}%"),
|
||||
mainloop_(nullptr),
|
||||
mainloop_api_(nullptr),
|
||||
@ -10,6 +10,9 @@ waybar::modules::Pulseaudio::Pulseaudio(const Json::Value &config)
|
||||
muted_(false),
|
||||
scrolling_(false) {
|
||||
label_.set_name("pulseaudio");
|
||||
if (!id.empty()) {
|
||||
label_.get_style_context()->add_class(id);
|
||||
}
|
||||
mainloop_ = pa_threaded_mainloop_new();
|
||||
if (mainloop_ == nullptr) {
|
||||
throw std::runtime_error("pa_mainloop_new() failed.");
|
||||
@ -207,7 +210,7 @@ auto waybar::modules::Pulseaudio::update() -> void
|
||||
label_.get_style_context()->remove_class("muted");
|
||||
label_.get_style_context()->add_class("bluetooth");
|
||||
}
|
||||
label_.set_label(
|
||||
label_.set_markup(
|
||||
fmt::format(format, fmt::arg("volume", volume_),
|
||||
fmt::arg("icon", getIcon(volume_, getPortIcon()))));
|
||||
label_.set_tooltip_text(desc_);
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
waybar::modules::SNI::Tray::Tray(Bar& bar, const Json::Value &config)
|
||||
: config_(config), watcher_(), host_(bar.nb_tray_hosts, config,
|
||||
waybar::modules::SNI::Tray::Tray(const std::string& id, const Json::Value &config)
|
||||
: config_(config), watcher_(), host_(nb_hosts_, config,
|
||||
std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
||||
std::bind(&Tray::onRemove, this, std::placeholders::_1))
|
||||
{
|
||||
@ -11,7 +11,7 @@ waybar::modules::SNI::Tray::Tray(Bar& bar, const Json::Value &config)
|
||||
if (config_["spacing"].isUInt()) {
|
||||
box_.set_spacing(config_["spacing"].asUInt());
|
||||
}
|
||||
bar.nb_tray_hosts += 1;
|
||||
nb_hosts_ += 1;
|
||||
}
|
||||
|
||||
void waybar::modules::SNI::Tray::onAdd(std::unique_ptr<Item>& item)
|
||||
|
@ -69,8 +69,7 @@ struct waybar::modules::sway::Ipc::ipc_response
|
||||
size_t total = 0;
|
||||
|
||||
while (total < ipc_header_size_) {
|
||||
ssize_t res =
|
||||
::recv(fd, header.data() + total, ipc_header_size_ - total, 0);
|
||||
auto res = ::recv(fd, header.data() + total, ipc_header_size_ - total, 0);
|
||||
if (res <= 0) {
|
||||
throw std::runtime_error("Unable to receive IPC response");
|
||||
}
|
||||
@ -81,8 +80,7 @@ struct waybar::modules::sway::Ipc::ipc_response
|
||||
std::string payload;
|
||||
payload.reserve(data32[0] + 1);
|
||||
while (total < data32[0]) {
|
||||
ssize_t res =
|
||||
::recv(fd, payload.data() + total, data32[0] - total, 0);
|
||||
auto res = ::recv(fd, payload.data() + total, data32[0] - total, 0);
|
||||
if (res < 0) {
|
||||
throw std::runtime_error("Unable to receive IPC response");
|
||||
}
|
||||
|
@ -1,12 +1,17 @@
|
||||
#include "modules/sway/mode.hpp"
|
||||
|
||||
waybar::modules::sway::Mode::Mode(Bar& bar, const Json::Value& config)
|
||||
waybar::modules::sway::Mode::Mode(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
: ALabel(config, "{}"), bar_(bar)
|
||||
{
|
||||
label_.set_name("mode");
|
||||
if (!id.empty()) {
|
||||
label_.get_style_context()->add_class(id);
|
||||
}
|
||||
ipc_.connect();
|
||||
ipc_.subscribe("[ \"mode\" ]");
|
||||
// Launch worker
|
||||
worker();
|
||||
dp.emit();
|
||||
}
|
||||
|
||||
void waybar::modules::sway::Mode::worker()
|
||||
@ -24,7 +29,7 @@ void waybar::modules::sway::Mode::worker()
|
||||
dp.emit();
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
std::cerr << "Mode: " << e.what() << std::endl;
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -32,12 +37,10 @@ void waybar::modules::sway::Mode::worker()
|
||||
auto waybar::modules::sway::Mode::update() -> void
|
||||
{
|
||||
if (mode_.empty()) {
|
||||
label_.set_name("");
|
||||
label_.hide();
|
||||
event_box_.hide();
|
||||
} else {
|
||||
label_.set_name("mode");
|
||||
label_.set_markup(fmt::format(format_, mode_));
|
||||
label_.set_tooltip_text(mode_);
|
||||
label_.show();
|
||||
event_box_.show();
|
||||
}
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
#include "modules/sway/window.hpp"
|
||||
|
||||
waybar::modules::sway::Window::Window(Bar &bar, const Json::Value& config)
|
||||
waybar::modules::sway::Window::Window(const std::string& id, const Bar &bar, const Json::Value& config)
|
||||
: ALabel(config, "{}"), bar_(bar), windowId_(-1)
|
||||
{
|
||||
label_.set_name("window");
|
||||
if (!id.empty()) {
|
||||
label_.get_style_context()->add_class(id);
|
||||
}
|
||||
if (label_.get_max_width_chars() == -1) {
|
||||
label_.set_hexpand(true);
|
||||
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END);
|
||||
@ -23,7 +26,7 @@ void waybar::modules::sway::Window::worker()
|
||||
auto parsed = parser_.parse(res.payload);
|
||||
if ((parsed["change"] == "focus" || parsed["change"] == "title")
|
||||
&& parsed["container"]["focused"].asBool()) {
|
||||
window_ = parsed["container"]["name"].asString();
|
||||
window_ = Glib::Markup::escape_text(parsed["container"]["name"].asString());
|
||||
windowId_ = parsed["container"]["id"].asInt();
|
||||
dp.emit();
|
||||
} else if ((parsed["change"] == "close"
|
||||
@ -36,7 +39,7 @@ void waybar::modules::sway::Window::worker()
|
||||
dp.emit();
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
std::cerr << "Window: " << e.what() << std::endl;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,10 +1,13 @@
|
||||
#include "modules/sway/workspaces.hpp"
|
||||
|
||||
waybar::modules::sway::Workspaces::Workspaces(Bar& bar,
|
||||
waybar::modules::sway::Workspaces::Workspaces(const std::string& id, const Bar& bar,
|
||||
const Json::Value& config)
|
||||
: bar_(bar), config_(config), scrolling_(false)
|
||||
{
|
||||
box_.set_name("workspaces");
|
||||
if (!id.empty()) {
|
||||
box_.get_style_context()->add_class(id);
|
||||
}
|
||||
ipc_.connect();
|
||||
ipc_.subscribe("[ \"workspace\" ]");
|
||||
// Launch worker
|
||||
@ -20,7 +23,7 @@ void waybar::modules::sway::Workspaces::worker()
|
||||
while (bar_.output_name.empty()) {
|
||||
thread_.sleep_for(chrono::milliseconds(150));
|
||||
}
|
||||
} else if (!workspaces_.empty()) {
|
||||
} else if (thread_.isRunnging() && !workspaces_.empty()) {
|
||||
ipc_.handleEvent();
|
||||
}
|
||||
{
|
||||
@ -30,7 +33,7 @@ void waybar::modules::sway::Workspaces::worker()
|
||||
}
|
||||
dp.emit();
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
std::cerr << "Workspaces: " << e.what() << std::endl;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user