~aleteoryx/muditaos

ref: 6bbef804c0605b90a3aff579376e9ea940733238 muditaos/module-apps/messages/AppMessage.hpp -rw-r--r-- 5.5 KiB
6bbef804 — Michał Kamoń [EGD-4284] missing include added (#956) 5 years ago
                                                                                
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "Common.hpp"
#include "MessageType.hpp"
#include "Service/Message.hpp"
#include "SwitchData.hpp"
#include "gui/input/InputEvent.hpp"
#include <memory>
#include <string>

namespace app
{

    /*
     * @brief Template for all messages that go to application manager
     */
    class AppMessage : public sys::DataMessage
    {
      public:
        AppMessage(MessageType messageType) : sys::DataMessage(messageType){};
        AppMessage() : sys::DataMessage(MessageType::AppMessage){};
    };

    // this message is used to notify application about switching event. Application will gain or lose focus upon
    // receiving this message. Application gains focus when it was in init or active background state. Application loose
    // focus when it was in active foreground state. if no window is specified it is assumed that MainWindow is the
    // target
    class AppSwitchMessage : public AppMessage
    {
      protected:
        // name of the application to which switch is performed.
        std::string targetApplication;
        // name of the window to which switch should be performed.
        std::string targetWindow;
        // optional data for the target window.
        std::unique_ptr<gui::SwitchData> data;
        // name of the application to which switch should be performed after finishing tasks in target application and
        // window.
        std::string returnApplication;
        // name of the window to which switch should be performed after finishing tasks in target application and
        // window.
        std::string returnWindow;

      public:
        AppSwitchMessage(const std::string &targetApplication,
                         const std::string &targetWindow,
                         std::unique_ptr<gui::SwitchData> data,
                         const std::string &returnApplication = "",
                         const std::string &returnWindow      = "")
            : AppMessage(MessageType::AppSwitch), targetApplication{targetApplication}, targetWindow{targetWindow},
              data{std::move(data)}, returnApplication{returnApplication}, returnWindow{returnWindow} {};
        virtual ~AppSwitchMessage(){};

        std::string getTargetWindowName()
        {
            return targetWindow;
        };
        std::string getReturnWindowName()
        {
            return returnWindow;
        };
        std::unique_ptr<gui::SwitchData> &getData()
        {
            return data;
        };
        std::string getTargetApplicationName()
        {
            return targetApplication;
        };
        std::string getReturnApplicationName()
        {
            return returnApplication;
        };
    };

    class AppRefreshMessage : public AppMessage
    {
      protected:
        gui::RefreshModes mode;
        std::string window_name;

      public:
        AppRefreshMessage(gui::RefreshModes mode, std::string window_name)
            : mode{mode}, window_name(std::move(window_name)){};

        [[nodiscard]] const gui::RefreshModes &getMode() const
        {
            return mode;
        }

        [[nodiscard]] const std::string &getWindowName() const
        {
            return window_name;
        }
    };

    class AppSwitchWindowMessage : public AppMessage
    {
      protected:
        std::string window;
        std::string senderWindow;
        gui::ShowMode command;
        std::unique_ptr<gui::SwitchData> data;

      public:
        AppSwitchWindowMessage() = delete;

        AppSwitchWindowMessage(const std::string &window,
                               const std::string senderWindow,
                               std::unique_ptr<gui::SwitchData> data,
                               const gui::ShowMode command = gui::ShowMode::GUI_SHOW_INIT)
            : AppMessage(MessageType::AppSwitchWindow), window{window},
              senderWindow{senderWindow}, command{command}, data{std::move(data)} {};
        virtual ~AppSwitchWindowMessage() = default;

        const std::string &getWindowName() const
        {
            return window;
        };
        const std::string &getSenderWindowName() const
        {
            return senderWindow;
        };
        const gui::ShowMode &getCommand() const
        {
            return command;
        };
        std::unique_ptr<gui::SwitchData> &getData()
        {
            return data;
        };
    };

    class AppInputEventMessage : public AppMessage
    {
      protected:
        gui::InputEvent event;

      public:
        AppInputEventMessage(gui::InputEvent evt) : AppMessage(MessageType::AppInputEvent), event{evt} {};
        virtual ~AppInputEventMessage(){};

        const gui::InputEvent &getEvent()
        {
            return event;
        };

        operator std::string() const override
        {
            std::stringstream ss;
            ss << "{ ";
            ss << "state:   " << c_str(event.state) << ", ";
            ss << "RawKey:  " << c_str(event.key.key_code) << "}";
            ss << "t0: " << event.key.time_press << ", t1: " << event.key.time_release;
            ss << " }";
            return ss.str().c_str();
        }
    };

    class AppRebuildMessage : public AppMessage
    {
      public:
        AppRebuildMessage() : AppMessage(MessageType::AppRebuild){};
        virtual ~AppRebuildMessage(){};
    };

    class AppLostFocusMessage : public AppMessage
    {
      public:
        AppLostFocusMessage() : AppMessage{MessageType::AppFocusLost}
        {}
    };
};     // namespace app