mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
refactor(workspaces): listen ipc event
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
#include "bar.hpp"
|
||||
#include "client.hpp"
|
||||
#include "util/chrono.hpp"
|
||||
#include "util/json.hpp"
|
||||
#include "IModule.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
@ -15,13 +16,16 @@ namespace waybar::modules {
|
||||
operator Gtk::Widget &();
|
||||
private:
|
||||
void _addWorkspace(Json::Value node);
|
||||
Json::Value _getWorkspaces();
|
||||
Json::Value _getWorkspaces(const std::string data);
|
||||
Bar &_bar;
|
||||
waybar::util::SleeperThread _thread;
|
||||
Gtk::Box _box;
|
||||
util::JsonParser _parser;
|
||||
std::mutex _mutex;
|
||||
std::unordered_map<int, Gtk::Button> _buttons;
|
||||
int _ipcSocketfd;
|
||||
int _ipcEventSocketfd;
|
||||
Json::Value _workspaces;
|
||||
int _ipcfd;
|
||||
int _ipcEventfd;
|
||||
};
|
||||
|
||||
}
|
||||
|
34
include/util/json.hpp
Normal file
34
include/util/json.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <json/json.h>
|
||||
|
||||
namespace waybar::util {
|
||||
|
||||
struct JsonParser {
|
||||
|
||||
JsonParser()
|
||||
: _reader(_builder.newCharReader())
|
||||
{}
|
||||
|
||||
Json::Value parse(const std::string data)
|
||||
{
|
||||
Json::Value root;
|
||||
std::string err;
|
||||
bool res =
|
||||
_reader->parse(data.c_str(), data.c_str() + data.size(), &root, &err);
|
||||
if (!res)
|
||||
throw std::runtime_error(err);
|
||||
return root;
|
||||
}
|
||||
|
||||
~JsonParser()
|
||||
{
|
||||
delete _reader;
|
||||
}
|
||||
|
||||
private:
|
||||
Json::CharReaderBuilder _builder;
|
||||
Json::CharReader *_reader;
|
||||
};
|
||||
|
||||
}
|
Reference in New Issue
Block a user