summaryrefslogtreecommitdiff
path: root/src/desktop/history/WorkspaceHistoryTracker.hpp
blob: e80a515243f24e1b4279b9138d08f9077b1e49fb (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
#pragma once

#include "../DesktopTypes.hpp"
#include "../../SharedDefs.hpp"
#include "../../macros.hpp"
#include "../../helpers/MiscFunctions.hpp"

#include <deque>

namespace Desktop::History {
    class CWorkspaceHistoryTracker {
      public:
        CWorkspaceHistoryTracker();
        ~CWorkspaceHistoryTracker() = default;

        CWorkspaceHistoryTracker(const CWorkspaceHistoryTracker&) = delete;
        CWorkspaceHistoryTracker(CWorkspaceHistoryTracker&)       = delete;
        CWorkspaceHistoryTracker(CWorkspaceHistoryTracker&&)      = delete;

        struct SHistoryEntry {
            PHLWORKSPACEREF workspace;
            PHLMONITORREF   monitor;
            std::string     name = "";
            WORKSPACEID     id   = WORKSPACE_INVALID;
        };

        const SHistoryEntry previousWorkspace(PHLWORKSPACE ws);
        SWorkspaceIDName    previousWorkspaceIDName(PHLWORKSPACE ws);

        const SHistoryEntry previousWorkspace(PHLWORKSPACE ws, PHLMONITOR restrict);
        SWorkspaceIDName    previousWorkspaceIDName(PHLWORKSPACE ws, PHLMONITOR restrict);

      private:
        struct SLastWorkspaceData {
            PHLMONITORREF   monitor;
            PHLWORKSPACEREF workspace;
            std::string     workspaceName = "";
            WORKSPACEID     workspaceID   = WORKSPACE_INVALID;
        } m_lastWorkspaceData;

        std::deque<SHistoryEntry> m_history;

        void                      track(PHLWORKSPACE w);
        void                      gc();
        void                      setLastWorkspaceData(PHLWORKSPACE w);
    };

    SP<CWorkspaceHistoryTracker> workspaceTracker();
};