add basic workspace parsing
This commit is contained in:
28
include/helpers/systemHelper.hpp
Normal file
28
include/helpers/systemHelper.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class SystemHelper
|
||||
{
|
||||
public:
|
||||
static std::string get_command_output(const char *cmd)
|
||||
{
|
||||
std::array<char, 128> buffer;
|
||||
std::string result;
|
||||
std::unique_ptr<FILE, int (*)(FILE *)> pipe(popen(cmd, "r"), pclose);
|
||||
|
||||
if (!pipe)
|
||||
{
|
||||
throw std::runtime_error("popen() failed!");
|
||||
}
|
||||
|
||||
// Read the output a chunk at a time until the stream ends
|
||||
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
|
||||
{
|
||||
result += buffer.data();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
@@ -1,11 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <glibmm.h>
|
||||
#include <map>
|
||||
#include <sigc++/sigc++.h>
|
||||
#include <string>
|
||||
|
||||
class HyprlandService
|
||||
{
|
||||
typedef struct WorkspaceState
|
||||
{
|
||||
int id;
|
||||
bool active;
|
||||
bool focused;
|
||||
bool urgent;
|
||||
} WorkspaceState;
|
||||
|
||||
typedef struct Monitor
|
||||
{
|
||||
std::map<int, WorkspaceState> workspaceStates;
|
||||
std::string name;
|
||||
int x;
|
||||
int y;
|
||||
int id;
|
||||
int focusedWorkspaceId;
|
||||
} Monitor;
|
||||
|
||||
public:
|
||||
HyprlandService();
|
||||
~HyprlandService();
|
||||
@@ -18,6 +37,7 @@ class HyprlandService
|
||||
private:
|
||||
int m_fd = -1;
|
||||
std::string m_buffer;
|
||||
std::map<int, Monitor> monitors;
|
||||
|
||||
bool on_socket_read(Glib::IOCondition condition);
|
||||
void parse_message(const std::string &line);
|
||||
|
||||
Reference in New Issue
Block a user