summaryrefslogtreecommitdiff
path: root/src/debug/HyprCtl.hpp
blob: a6fa372171200ecc564b06b0d5d2f5f79282f831 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once

#include <fstream>
#include "../helpers/MiscFunctions.hpp"
#include "../helpers/defer/Promise.hpp"
#include "../desktop/view/Window.hpp"
#include <functional>
#include <sys/types.h>
#include <hyprutils/os/FileDescriptor.hpp>

// exposed for main.cpp
std::string systemInfoRequest(eHyprCtlOutputFormat format, std::string request);
std::string versionRequest(eHyprCtlOutputFormat format, std::string request);

class CHyprCtl {
  public:
    CHyprCtl();
    ~CHyprCtl();

    std::string                    makeDynamicCall(const std::string& input);
    SP<SHyprCtlCommand>            registerCommand(SHyprCtlCommand cmd);
    void                           unregisterCommand(const SP<SHyprCtlCommand>& cmd);
    std::string                    getReply(std::string);

    Hyprutils::OS::CFileDescriptor m_socketFD;

    struct {
        bool                      all              = false;
        bool                      sysInfoConfig    = false;
        bool                      isDynamicKeyword = false;
        pid_t                     pid              = 0;
        SP<CPromise<std::string>> pendingPromise;
    } m_currentRequestParams;

    static std::string getWindowData(PHLWINDOW w, eHyprCtlOutputFormat format);
    static std::string getWorkspaceData(PHLWORKSPACE w, eHyprCtlOutputFormat format);
    static std::string getSolitaryBlockedReason(Hyprutils::Memory::CSharedPointer<CMonitor> m, eHyprCtlOutputFormat format);
    static std::string getDSBlockedReason(Hyprutils::Memory::CSharedPointer<CMonitor> m, eHyprCtlOutputFormat format);
    static std::string getTearingBlockedReason(Hyprutils::Memory::CSharedPointer<CMonitor> m, eHyprCtlOutputFormat format);
    static std::string getMonitorData(Hyprutils::Memory::CSharedPointer<CMonitor> m, eHyprCtlOutputFormat format);

  private:
    void                             startHyprCtlSocket();

    std::vector<SP<SHyprCtlCommand>> m_commands;
    wl_event_source*                 m_eventSource = nullptr;
    std::string                      m_socketPath;
};

inline UP<CHyprCtl> g_pHyprCtl;