This commit is contained in:
Alex
2018-08-20 14:50:45 +02:00
committed by GitHub
parent b7e3d10fb7
commit 49232eed8d
30 changed files with 261 additions and 235 deletions

View File

@ -15,13 +15,14 @@ namespace fs = std::filesystem;
class Battery : public ALabel {
public:
Battery(Json::Value);
Battery(const Json::Value&);
~Battery();
auto update() -> void;
private:
std::string getIcon(uint16_t percentage);
static inline const fs::path data_dir_ = "/sys/class/power_supply/";
void worker();
std::string getIcon(uint16_t percentage);
util::SleeperThread thread_;
std::vector<fs::path> batteries_;

View File

@ -9,7 +9,7 @@ namespace waybar::modules {
class Clock : public ALabel {
public:
Clock(Json::Value);
Clock(const Json::Value&);
auto update() -> void;
private:
waybar::util::SleeperThread thread_;

View File

@ -9,7 +9,7 @@ namespace waybar::modules {
class Cpu : public ALabel {
public:
Cpu(Json::Value);
Cpu(const Json::Value&);
auto update() -> void;
private:
waybar::util::SleeperThread thread_;

View File

@ -10,10 +10,12 @@ namespace waybar::modules {
class Custom : public ALabel {
public:
Custom(std::string, Json::Value);
Custom(const std::string&, const Json::Value&);
auto update() -> void;
private:
std::string name_;
void worker();
const std::string& name_;
waybar::util::SleeperThread thread_;
};

View File

@ -9,7 +9,7 @@ namespace waybar::modules {
class Memory : public ALabel {
public:
Memory(Json::Value);
Memory(const Json::Value&);
auto update() -> void;
private:
waybar::util::SleeperThread thread_;

View File

@ -13,7 +13,7 @@ namespace waybar::modules {
class Network : public ALabel {
public:
Network(Json::Value);
Network(const Json::Value&);
~Network();
auto update() -> void;
private:

View File

@ -9,7 +9,7 @@ namespace waybar::modules {
class Pulseaudio : public ALabel {
public:
Pulseaudio(Json::Value);
Pulseaudio(const Json::Value&);
~Pulseaudio();
auto update() -> void;
private:

View File

@ -1,33 +1,41 @@
#pragma once
#include <iostream>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
#include "ipc.hpp"
/**
* IPC response including type of IPC response, size of payload and the json
* encoded payload string.
*/
struct ipc_response {
uint32_t size;
uint32_t type;
std::string payload;
namespace waybar::modules::sway {
class Ipc {
public:
Ipc();
~Ipc();
struct ipc_response {
uint32_t size;
uint32_t type;
std::string payload;
};
void connect();
struct ipc_response sendCmd(uint32_t type,
const std::string& payload = "") const;
void subscribe(const std::string& payload) const;
struct ipc_response handleEvent() const;
protected:
static inline const std::string ipc_magic_ = "i3-ipc";
static inline const size_t ipc_header_size_ = ipc_magic_.size() + 8;
const std::string getSocketPath() const;
int open(const std::string&) const;
struct ipc_response send(int fd, uint32_t type,
const std::string& payload = "") const;
struct ipc_response recv(int fd) const;
int fd_;
int fd_event_;
};
/**
* Gets the path to the IPC socket from sway.
*/
std::string getSocketPath(void);
/**
* Opens the sway socket.
*/
int ipcOpenSocket(const std::string &socketPath);
/**
* Issues a single IPC command and returns the buffer. len will be updated with
* the length of the buffer returned from sway.
*/
struct ipc_response ipcSingleCommand(int socketfd, uint32_t type,
const std::string& payload);
/**
* Receives a single IPC response and returns an ipc_response.
*/
struct ipc_response ipcRecvResponse(int socketfd);
}

View File

@ -1,6 +1,6 @@
#pragma once
#define event_mask(ev) (1 << (ev & 0x7F))
#define event_mask(ev) (1u << (ev & 0x7F))
enum ipc_command_type {
// i3 command types - see i3's I3_REPLY_TYPE constants

View File

@ -6,23 +6,23 @@
#include "util/chrono.hpp"
#include "util/json.hpp"
#include "ALabel.hpp"
#include "modules/sway/ipc/client.hpp"
namespace waybar::modules::sway {
class Window : public ALabel {
public:
Window(waybar::Bar&, Json::Value);
~Window();
Window(waybar::Bar&, const Json::Value&);
auto update() -> void;
private:
void worker();
std::string getFocusedNode(Json::Value nodes);
void getFocusedWindow();
Bar& bar_;
waybar::util::SleeperThread thread_;
util::JsonParser parser_;
int ipcfd_;
int ipc_eventfd_;
Ipc ipc_;
std::string window_;
};

View File

@ -6,16 +6,17 @@
#include "util/chrono.hpp"
#include "util/json.hpp"
#include "IModule.hpp"
#include "modules/sway/ipc/client.hpp"
namespace waybar::modules::sway {
class Workspaces : public IModule {
public:
Workspaces(waybar::Bar&, Json::Value);
~Workspaces();
Workspaces(waybar::Bar&, const Json::Value&);
auto update() -> void;
operator Gtk::Widget &();
private:
void worker();
void addWorkspace(Json::Value);
std::string getIcon(std::string);
bool handleScroll(GdkEventScroll*);
@ -23,7 +24,7 @@ class Workspaces : public IModule {
int getNextWorkspace();
Bar& bar_;
Json::Value config_;
const Json::Value& config_;
waybar::util::SleeperThread thread_;
Gtk::Box box_;
util::JsonParser parser_;
@ -31,8 +32,7 @@ class Workspaces : public IModule {
bool scrolling_;
std::unordered_map<int, Gtk::Button> buttons_;
Json::Value workspaces_;
int ipcfd_;
int ipc_eventfd_;
Ipc ipc_;
};
}