Handle screens disconnection (#29)

This commit is contained in:
Alex 2018-08-19 13:39:57 +02:00 committed by GitHub
parent ce50a627be
commit 6705134034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 205 additions and 133 deletions

View File

@ -4,17 +4,18 @@
#include <gtkmm.h>
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "xdg-output-unstable-v1-client-protocol.h"
#include "IModule.hpp"
namespace waybar {
class Client;
class Factory;
class Bar {
public:
Bar(Client&, std::unique_ptr<struct wl_output *>&&);
Bar(Client&, std::unique_ptr<struct wl_output *>&&, uint32_t wl_name);
Bar(const Bar&) = delete;
auto setWidth(uint32_t) -> void;
auto toggle() -> void;
Client& client;
@ -22,7 +23,8 @@ class Bar {
struct wl_surface *surface;
struct zwlr_layer_surface_v1 *layer_surface;
std::unique_ptr<struct wl_output *> output;
std::string outputName;
std::string output_name;
uint32_t wl_name;
bool visible = true;
private:
static void handleLogicalPosition(void *, struct zxdg_output_v1 *, int32_t,
@ -41,6 +43,7 @@ class Bar {
auto setupConfig() -> void;
auto setupWidgets() -> void;
auto setupCss() -> void;
void getModules(Factory factory, const std::string& pos);
uint32_t width_ = 0;
uint32_t height_ = 30;
@ -48,6 +51,9 @@ class Bar {
Glib::RefPtr<Gtk::StyleContext> style_context_;
Glib::RefPtr<Gtk::CssProvider> css_provider_;
struct zxdg_output_v1 *xdg_output_;
std::vector<std::unique_ptr<waybar::IModule>> modules_left_;
std::vector<std::unique_ptr<waybar::IModule>> modules_center_;
std::vector<std::unique_ptr<waybar::IModule>> modules_right_;
};
}

View File

@ -19,7 +19,7 @@ class Client {
Client(int argc, char *argv[]);
int main(int argc, char *argv[]);
Gtk::Main gtk_main;
Glib::RefPtr<Gtk::Application> gtk_app;
std::string css_file;
std::string config_file;
Glib::RefPtr<Gdk::Display> gdk_display;

View File

@ -16,6 +16,7 @@ namespace fs = std::filesystem;
class Battery : public ALabel {
public:
Battery(Json::Value);
~Battery();
auto update() -> void;
private:
std::string getIcon(uint16_t percentage);
@ -24,6 +25,7 @@ class Battery : public ALabel {
util::SleeperThread thread_;
std::vector<fs::path> batteries_;
int fd_;
};
}

View File

@ -14,6 +14,7 @@ namespace waybar::modules {
class Network : public ALabel {
public:
Network(Json::Value);
~Network();
auto update() -> void;
private:
static uint64_t netlinkRequest(int, void*, uint32_t, uint32_t groups = 0);

View File

@ -10,6 +10,7 @@ namespace waybar::modules {
class Pulseaudio : public ALabel {
public:
Pulseaudio(Json::Value);
~Pulseaudio();
auto update() -> void;
private:
static void subscribeCb(pa_context*, pa_subscription_event_type_t,

View File

@ -12,6 +12,7 @@ namespace waybar::modules::sway {
class Window : public ALabel {
public:
Window(waybar::Bar&, Json::Value);
~Window();
auto update() -> void;
private:
std::string getFocusedNode(Json::Value nodes);

View File

@ -12,6 +12,7 @@ namespace waybar::modules::sway {
class Workspaces : public IModule {
public:
Workspaces(waybar::Bar&, Json::Value);
~Workspaces();
auto update() -> void;
operator Gtk::Widget &();
private:

View File

@ -5,6 +5,7 @@
#include <functional>
#include <condition_variable>
#include <thread>
#include <gtkmm.h>
namespace waybar::chrono {
@ -14,18 +15,6 @@ using clock = std::chrono::system_clock;
using duration = clock::duration;
using time_point = std::chrono::time_point<clock, duration>;
inline struct timespec to_timespec(time_point t) noexcept
{
long secs = duration_cast<seconds>(t.time_since_epoch()).count();
long nsc = duration_cast<nanoseconds>(t.time_since_epoch() % seconds(1)).count();
return {secs, nsc};
}
inline time_point to_time_point(struct timespec t) noexcept
{
return time_point(duration_cast<duration>(seconds(t.tv_sec) + nanoseconds(t.tv_nsec)));
}
}
namespace waybar::util {
@ -34,59 +23,71 @@ struct SleeperThread {
SleeperThread() = default;
SleeperThread(std::function<void()> func)
: thread{[this, func] {
do {
func();
} while (do_run);
}}
: thread_{[this, func] {
while(true) {
{
defined = true;
std::lock_guard<std::mutex> lock(mutex_);
if (!do_run_) {
break;
}
}
func();
}
}}
{}
SleeperThread& operator=(std::function<void()> func)
{
thread = std::thread([this, func] {
do {
thread_ = std::thread([this, func] {
while(true) {
{
std::lock_guard<std::mutex> lock(mutex_);
if (!do_run_) {
break;
}
}
func();
} while (do_run);
}
});
defined = true;
return *this;
}
auto sleep_for(chrono::duration dur)
{
auto lock = std::unique_lock(mutex);
return condvar.wait_for(lock, dur);
auto lock = std::unique_lock(mutex_);
return condvar_.wait_for(lock, dur);
}
auto sleep_until(chrono::time_point time)
{
auto lock = std::unique_lock(mutex);
return condvar.wait_until(lock, time);
auto lock = std::unique_lock(mutex_);
return condvar_.wait_until(lock, time);
}
auto wake_up()
{
condvar.notify_all();
condvar_.notify_all();
}
~SleeperThread()
{
do_run = false;
if (defined) {
condvar.notify_all();
thread.join();
do_run_ = false;
condvar_.notify_all();
auto native_handle = thread_.native_handle();
pthread_cancel(native_handle);
if (thread_.joinable()) {
thread_.join();
}
}
sigc::signal<void> sig_update;
private:
std::thread thread;
std::condition_variable condvar;
std::mutex mutex;
bool defined = false;
bool do_run = true;
std::thread thread_;
std::condition_variable condvar_;
std::mutex mutex_;
bool do_run_ = true;
};
}

View File

@ -14,6 +14,9 @@ struct JsonParser {
{
Json::Value root;
std::string err;
if (_reader == nullptr) {
throw std::runtime_error("Unable to parse");
}
bool res =
_reader->parse(data.c_str(), data.c_str() + data.size(), &root, &err);
if (!res)
@ -24,6 +27,7 @@ struct JsonParser {
~JsonParser()
{
delete _reader;
_reader = nullptr;
}
private:

View File

@ -6,7 +6,7 @@ project(
)
cpp_args = []
cpp_link_args = []
cpp_link_args = ['-g']
if false # libc++
cpp_args += ['-stdlib=libc++']

View File

@ -3,9 +3,10 @@
#include "factory.hpp"
#include "util/json.hpp"
waybar::Bar::Bar(Client &client, std::unique_ptr<struct wl_output *> &&p_output)
waybar::Bar::Bar(Client &client,
std::unique_ptr<struct wl_output *> &&p_output, uint32_t p_wl_name)
: client(client), window{Gtk::WindowType::WINDOW_TOPLEVEL},
output(std::move(p_output))
output(std::move(p_output)), wl_name(std::move(p_wl_name))
{
static const struct zxdg_output_v1_listener xdgOutputListener = {
.logical_position = handleLogicalPosition,
@ -22,29 +23,39 @@ waybar::Bar::Bar(Client &client, std::unique_ptr<struct wl_output *> &&p_output)
setupConfig();
setupCss();
setupWidgets();
if (config_["height"]) {
height_ = config_["height"].asUInt();
}
Gtk::Widget& wrap(window);
gtk_widget_realize(wrap.gobj());
GdkWindow *gdk_window = gtk_widget_get_window(wrap.gobj());
gdk_wayland_window_set_use_custom_surface(gdk_window);
surface = gdk_wayland_window_get_wl_surface(gdk_window);
std::size_t layer_top = config_["layer"] == "top"
? ZWLR_LAYER_SHELL_V1_LAYER_TOP : ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
layer_surface = zwlr_layer_shell_v1_get_layer_surface(
client.layer_shell, surface, *output, layer_top, "waybar");
std::size_t position_bottom = config_["position"] == "bottom"
? ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM : ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
zwlr_layer_surface_v1_set_anchor(layer_surface, position_bottom
| ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT);
zwlr_layer_surface_v1_set_size(layer_surface, width_, height_);
static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
.configure = layerSurfaceHandleConfigure,
.closed = layerSurfaceHandleClosed,
};
zwlr_layer_surface_v1_add_listener(layer_surface,
&layer_surface_listener, this);
std::size_t anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
if (config_["position"] == "bottom") {
anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
} else {
anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
}
auto height = config_["height"] ? config_["height"].asUInt() : height_;
auto width = config_["width"] ? config_["width"].asUInt() : width_;
zwlr_layer_surface_v1_set_anchor(layer_surface, anchor);
zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, height);
zwlr_layer_surface_v1_set_size(layer_surface, width, height);
wl_surface_commit(surface);
}
@ -71,7 +82,7 @@ void waybar::Bar::handleName(void* data, struct zxdg_output_v1* /*xdg_output*/,
const char* name)
{
auto o = static_cast<waybar::Bar *>(data);
o->outputName = name;
o->output_name = name;
}
void waybar::Bar::handleDescription(void* /*data*/,
@ -86,13 +97,17 @@ void waybar::Bar::layerSurfaceHandleConfigure(void* data,
{
auto o = static_cast<waybar::Bar *>(data);
o->window.show_all();
o->setWidth(o->config_["width"] ? o->config_["width"].asUInt() : width);
zwlr_layer_surface_v1_ack_configure(surface, serial);
if (o->height_ != height) {
height = o->height_;
std::cout << fmt::format("New Height: {}", height) << std::endl;
zwlr_layer_surface_v1_set_size(surface, o->width_, height);
zwlr_layer_surface_v1_set_exclusive_zone(surface, o->visible ? height : 0);
if (width != o->width_ || height != o->height_) {
o->width_ = width;
o->height_ = height;
std::cout << fmt::format(
"Bar configured (width: {}, height: {}) for output: {}",
o->width_, o->height_, o->output_name) << std::endl;
o->window.set_size_request(o->width_, o->height_);
o->window.resize(o->width_, o->height_);
zwlr_layer_surface_v1_set_exclusive_zone(surface, o->height_);
zwlr_layer_surface_v1_set_size(surface, o->width_, o->height_);
wl_surface_commit(o->surface);
}
}
@ -101,24 +116,13 @@ void waybar::Bar::layerSurfaceHandleClosed(void* data,
struct zwlr_layer_surface_v1* /*surface*/)
{
auto o = static_cast<waybar::Bar *>(data);
std::cout << "Bar removed from output: " + o->output_name << std::endl;
zwlr_layer_surface_v1_destroy(o->layer_surface);
o->layer_surface = nullptr;
wl_surface_destroy(o->surface);
o->surface = nullptr;
o->window.close();
}
auto waybar::Bar::setWidth(uint32_t width) -> void
{
if (width == width_) {
return;
}
std::cout << fmt::format("Bar width configured: {}", width) << std::endl;
width_ = width;
window.set_size_request(width);
window.resize(width, height_);
zwlr_layer_surface_v1_set_size(layer_surface, width, height_ + 1);
wl_surface_commit(surface);
wl_output_destroy(*o->output);
zxdg_output_v1_destroy(o->xdg_output_);
o->modules_left_.clear();
o->modules_center_.clear();
o->modules_right_.clear();
}
auto waybar::Bar::toggle() -> void
@ -154,6 +158,27 @@ auto waybar::Bar::setupCss() -> void
}
}
void waybar::Bar::getModules(Factory factory, const std::string& pos)
{
if (config_[pos]) {
for (const auto &name : config_[pos]) {
try {
if (pos == "modules-left") {
modules_left_.emplace_back(factory.makeModule(name.asString()));
}
if (pos == "modules-center") {
modules_center_.emplace_back(factory.makeModule(name.asString()));
}
if (pos == "modules-right") {
modules_right_.emplace_back(factory.makeModule(name.asString()));
}
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
}
}
}
}
auto waybar::Bar::setupWidgets() -> void
{
auto &left = *Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, 0));
@ -167,30 +192,17 @@ auto waybar::Bar::setupWidgets() -> void
box.pack_end(right, true, true);
Factory factory(*this, config_);
if (config_["modules-left"]) {
for (const auto &name : config_["modules-left"]) {
auto module = factory.makeModule(name.asString());
if (module != nullptr) {
getModules(factory, "modules-left");
getModules(factory, "modules-center");
getModules(factory, "modules-right");
for (auto& module : modules_left_) {
left.pack_start(*module, false, true, 0);
}
for (auto& module : modules_center_) {
center.pack_start(*module, true, true, 0);
}
}
if (config_["modules-center"]) {
for (const auto &name : config_["modules-center"]) {
auto module = factory.makeModule(name.asString());
if (module != nullptr) {
center.pack_start(*module, true, false, 0);
}
}
}
if (config_["modules-right"]) {
std::reverse(config_["modules-right"].begin(), config_["modules-right"].end());
for (const auto &name : config_["modules-right"]) {
auto module = factory.makeModule(name.asString());
if (module != nullptr) {
std::reverse(modules_right_.begin(), modules_right_.end());
for (auto& module : modules_right_) {
right.pack_end(*module, false, false, 0);
}
}
}
}

View File

@ -1,7 +1,8 @@
#include "client.hpp"
waybar::Client::Client(int argc, char* argv[])
: gtk_main(argc, argv), gdk_display(Gdk::Display::get_default()),
: gtk_app(Gtk::Application::create(argc, argv, "org.alexays.waybar")),
gdk_display(Gdk::Display::get_default()),
wl_display(gdk_wayland_display_get_wl_display(gdk_display->gobj()))
{
auto getFirstValidPath = [] (std::vector<std::string> possiblePaths) {
@ -48,7 +49,7 @@ void waybar::Client::handleGlobal(void *data, struct wl_registry *registry,
*output = static_cast<struct wl_output *>(wl_registry_bind(registry, name,
&wl_output_interface, version));
if (o->xdg_output_manager != nullptr) {
o->bars.emplace_back(std::make_unique<Bar>(*o, std::move(output)));
o->bars.emplace_back(std::make_unique<Bar>(*o, std::move(output), name));
}
} else if (strcmp(interface, wl_seat_interface.name) == 0) {
o->seat = static_cast<struct wl_seat *>(wl_registry_bind(registry, name,
@ -61,10 +62,16 @@ void waybar::Client::handleGlobal(void *data, struct wl_registry *registry,
}
}
void waybar::Client::handleGlobalRemove(void* /*data*/,
struct wl_registry* /*registry*/, uint32_t /*name*/)
void waybar::Client::handleGlobalRemove(void* data,
struct wl_registry* /*registry*/, uint32_t name)
{
// TODO(someone)
auto o = static_cast<waybar::Client *>(data);
for (auto it = o->bars.begin(); it != o->bars.end(); ++it) {
if ((**it).wl_name == name) {
o->bars.erase(it);
break;
}
}
}
void waybar::Client::bindInterfaces()
@ -81,7 +88,8 @@ void waybar::Client::bindInterfaces()
int waybar::Client::main(int /*argc*/, char* /*argv*/[])
{
bindInterfaces();
Gtk::Main::run();
gtk_app->hold();
gtk_app->run();
bars.clear();
zxdg_output_manager_v1_destroy(xdg_output_manager);
zwlr_layer_shell_v1_destroy(layer_shell);

View File

@ -34,13 +34,12 @@ waybar::IModule *waybar::Factory::makeModule(const std::string &name)
if (name.compare(0, 7, "custom/") == 0 && name.size() > 7) {
return new waybar::modules::Custom(name.substr(7), _config[name]);
}
std::cerr << "Unknown module: " + name << std::endl;
} catch (const std::exception& e) {
auto err = fmt::format("Disabling module \"{}\", {}", name, e.what());
std::cerr << err << std::endl;
throw std::runtime_error(err);
} catch (...) {
auto err = fmt::format("Disabling module \"{}\", Unknown reason", name);
std::cerr << err << std::endl;
throw std::runtime_error(err);
}
return nullptr;
throw std::runtime_error("Unknown module: " + name);
}

View File

@ -16,26 +16,32 @@ waybar::modules::Battery::Battery(Json::Value config)
if (batteries_.empty()) {
throw std::runtime_error("No batteries.");
}
auto fd = inotify_init1(IN_CLOEXEC);
if (fd == -1) {
fd_ = inotify_init1(IN_CLOEXEC);
if (fd_ == -1) {
throw std::runtime_error("Unable to listen batteries.");
}
for (auto &bat : batteries_) {
inotify_add_watch(fd, (bat / "uevent").c_str(), IN_ACCESS);
inotify_add_watch(fd_, (bat / "uevent").c_str(), IN_ACCESS);
}
// Trigger first value
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Battery::update));
// Trigger first values
update();
label_.set_name("battery");
thread_ = [this, fd] {
thread_.sig_update.connect(sigc::mem_fun(*this, &Battery::update));
thread_ = [this] {
struct inotify_event event = {0};
int nbytes = read(fd, &event, sizeof(event));
int nbytes = read(fd_, &event, sizeof(event));
if (nbytes != sizeof(event)) {
return;
}
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Battery::update));
thread_.sig_update.emit();
};
}
waybar::modules::Battery::~Battery()
{
close(fd_);
}
auto waybar::modules::Battery::update() -> void
{
try {

View File

@ -5,9 +5,10 @@ waybar::modules::Clock::Clock(Json::Value config)
{
label_.set_name("clock");
uint32_t interval = config_["interval"] ? config_["inveral"].asUInt() : 60;
thread_.sig_update.connect(sigc::mem_fun(*this, &Clock::update));
thread_ = [this, interval] {
auto now = waybar::chrono::clock::now();
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Clock::update));
thread_.sig_update.emit();
auto timeout = std::chrono::floor<std::chrono::seconds>(now
+ std::chrono::seconds(interval));
thread_.sleep_until(timeout);

View File

@ -5,8 +5,9 @@ waybar::modules::Cpu::Cpu(Json::Value config)
{
label_.set_name("cpu");
uint32_t interval = config_["interval"] ? config_["inveral"].asUInt() : 10;
thread_.sig_update.connect(sigc::mem_fun(*this, &Cpu::update));
thread_ = [this, interval] {
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Cpu::update));
thread_.sig_update.emit();
thread_.sleep_for(chrono::seconds(interval));
};
}

View File

@ -16,10 +16,11 @@ waybar::modules::Custom::Custom(std::string name, Json::Value config)
}
}
if (can_update) {
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Custom::update));
thread_.sig_update.emit();
}
thread_.sleep_for(chrono::seconds(interval));
};
thread_.sig_update.connect(sigc::mem_fun(*this, &Custom::update));
}
auto waybar::modules::Custom::update() -> void

View File

@ -5,8 +5,9 @@ waybar::modules::Memory::Memory(Json::Value config)
{
label_.set_name("memory");
uint32_t interval = config_["interval"] ? config_["inveral"].asUInt() : 30;
thread_.sig_update.connect(sigc::mem_fun(*this, &Memory::update));
thread_ = [this, interval] {
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Memory::update));
thread_.sig_update.emit();
thread_.sleep_for(chrono::seconds(interval));
};
}

View File

@ -29,8 +29,10 @@ waybar::modules::Network::Network(Json::Value config)
}
}
label_.set_name("network");
// Trigger first values
getInfo();
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Network::update));
update();
thread_.sig_update.connect(sigc::mem_fun(*this, &Network::update));
thread_ = [this] {
char buf[4096];
uint64_t len = netlinkResponse(sock_fd_, buf, sizeof(buf),
@ -67,11 +69,16 @@ waybar::modules::Network::Network(Json::Value config)
}
if (need_update) {
getInfo();
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Network::update));
thread_.sig_update.emit();
}
};
}
waybar::modules::Network::~Network()
{
close(sock_fd_);
}
auto waybar::modules::Network::update() -> void
{
auto format = config_["format"] ? config_["format"].asString() : "{ifname}";

View File

@ -28,6 +28,13 @@ waybar::modules::Pulseaudio::Pulseaudio(Json::Value config)
pa_threaded_mainloop_unlock(mainloop_);
}
waybar::modules::Pulseaudio::~Pulseaudio()
{
mainloop_api_->quit(mainloop_api_, 0);
pa_threaded_mainloop_stop(mainloop_);
pa_threaded_mainloop_free(mainloop_);
}
void waybar::modules::Pulseaudio::contextStateCb(pa_context *c, void *data)
{
auto pa = static_cast<waybar::modules::Pulseaudio *>(data);

View File

@ -10,6 +10,7 @@ waybar::modules::sway::Window::Window(Bar &bar, Json::Value config)
ipc_eventfd_ = ipcOpenSocket(socketPath);
ipcSingleCommand(ipc_eventfd_, IPC_SUBSCRIBE, "[ \"window\" ]");
getFocusedWindow();
thread_.sig_update.connect(sigc::mem_fun(*this, &Window::update));
thread_ = [this] {
try {
auto res = ipcRecvResponse(ipc_eventfd_);
@ -17,7 +18,7 @@ waybar::modules::sway::Window::Window(Bar &bar, Json::Value config)
if ((parsed["change"] == "focus" || parsed["change"] == "title")
&& parsed["container"]["focused"].asBool()) {
window_ = parsed["container"]["name"].asString();
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Window::update));
thread_.sig_update.emit();
}
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
@ -25,6 +26,12 @@ waybar::modules::sway::Window::Window(Bar &bar, Json::Value config)
};
}
waybar::modules::sway::Window::~Window()
{
close(ipcfd_);
close(ipc_eventfd_);
}
auto waybar::modules::sway::Window::update() -> void
{
label_.set_text(window_);

View File

@ -9,30 +9,35 @@ waybar::modules::sway::Workspaces::Workspaces(Bar &bar, Json::Value config)
ipcfd_ = ipcOpenSocket(socketPath);
ipc_eventfd_ = ipcOpenSocket(socketPath);
ipcSingleCommand(ipc_eventfd_, IPC_SUBSCRIBE, "[ \"workspace\" ]");
thread_.sig_update.connect(sigc::mem_fun(*this, &Workspaces::update));
thread_ = [this] {
try {
// Wait for the name of the output
if (!config_["all-outputs"].asBool() && bar_.outputName.empty()) {
while (bar_.outputName.empty()) {
if (!config_["all-outputs"].asBool() && bar_.output_name.empty()) {
while (bar_.output_name.empty()) {
thread_.sleep_for(chrono::milliseconds(150));
}
} else if (!workspaces_.empty()) {
ipcRecvResponse(ipc_eventfd_);
}
std::lock_guard<std::mutex> lock(mutex_);
auto res = ipcSingleCommand(ipcfd_, IPC_GET_WORKSPACES, "");
workspaces_ = parser_.parse(res.payload);
Glib::signal_idle()
.connect_once(sigc::mem_fun(*this, &Workspaces::update));
thread_.sig_update.emit();
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
}
};
}
waybar::modules::sway::Workspaces::~Workspaces()
{
close(ipcfd_);
close(ipc_eventfd_);
}
auto waybar::modules::sway::Workspaces::update() -> void
{
std::lock_guard<std::mutex> lock(mutex_);
auto res = ipcSingleCommand(ipcfd_, IPC_GET_WORKSPACES, "");
workspaces_ = parser_.parse(res.payload);
bool needReorder = false;
for (auto it = buttons_.begin(); it != buttons_.end();) {
auto ws = std::find_if(workspaces_.begin(), workspaces_.end(),
@ -46,7 +51,7 @@ auto waybar::modules::sway::Workspaces::update() -> void
}
for (auto node : workspaces_) {
if (!config_["all-outputs"].asBool()
&& bar_.outputName != node["output"].asString()) {
&& bar_.output_name != node["output"].asString()) {
continue;
}
auto it = buttons_.find(node["num"].asInt());