mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Handle screens disconnection (#29)
This commit is contained in:
@ -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_;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -16,7 +16,7 @@ namespace waybar {
|
||||
class Factory {
|
||||
public:
|
||||
Factory(Bar &bar, Json::Value config);
|
||||
IModule *makeModule(const std::string &name);
|
||||
IModule* makeModule(const std::string &name);
|
||||
private:
|
||||
Bar &_bar;
|
||||
Json::Value _config;
|
||||
|
@ -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_;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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:
|
||||
|
@ -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 {
|
||||
: thread_{[this, func] {
|
||||
while(true) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!do_run_) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
func();
|
||||
} while (do_run);
|
||||
}
|
||||
}}
|
||||
{
|
||||
defined = true;
|
||||
}
|
||||
{}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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:
|
||||
|
Reference in New Issue
Block a user