summaryrefslogtreecommitdiff
path: root/src/config/supplementary/executor/Executor.hpp
blob: cc5f94a2abc0b748cde83cc06aa1107fcde7916b (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
#pragma once

#include <string>
#include <vector>
#include <optional>
#include <cstdint>
#include "../../../helpers/signal/Signal.hpp"
#include "../../../helpers/memory/Memory.hpp"
#include "../../../desktop/DesktopTypes.hpp"

namespace Config::Supplementary {
    struct SExecRequest {
        std::string exec      = "";
        bool        withRules = false;
    };

    class CExecutor {
      public:
        CExecutor();
        ~CExecutor() = default;

        void                    addExecOnce(const SExecRequest& cmd);
        void                    addExecShutdown(const SExecRequest& cmd);

        std::optional<uint64_t> spawn(const std::string& args);
        std::optional<uint64_t> spawnRaw(const std::string& args);

        std::optional<uint64_t> spawnRawProc(const std::string&, PHLWORKSPACE pInitialWorkspace = nullptr, const std::string& execRuleToken = "");
        std::optional<uint64_t> spawnWithRules(std::string, PHLWORKSPACE pInitialWorkspace = nullptr);

      private:
        std::vector<SExecRequest> m_execOnce, m_execShutdown;

        struct {
            CHyprSignalListener init;
            CHyprSignalListener shutdown;
        } m_listeners;

        bool m_firstExecDispatched = false;
    };

    UP<CExecutor>& executor();
};