Add gitlab issue/merge request templates
[apps/agl-service-windowmanager.git] / src / wm_layer_control.hpp
1 /*
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3  * Copyright (c) 2019 Konsulko Group
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <string>
19 #include <memory>
20 #include <vector>
21 #include <unordered_map>
22 #include <functional>
23 #include <ilm/ilm_control.h>
24 #include "wm_error.hpp"
25 #include "util.hpp"
26
27 namespace wm {
28
29 class Screen {
30   public:
31     Screen(unsigned w, unsigned h) : _width(w), _height(h){}
32     unsigned width() { return _width; }
33     unsigned height() { return _height; }
34   private:
35     unsigned _width;
36     unsigned _height;
37     unsigned _pysical_width = 0;
38     unsigned _pysical_height = 0;
39 };
40
41 class LayerControlCallbacks {
42   public:
43     LayerControlCallbacks() {};
44     ~LayerControlCallbacks() = default;
45     LayerControlCallbacks(const LayerControlCallbacks &obj) = default;
46
47     // callback functions
48     std::function<void(unsigned, unsigned)> surfaceCreated;
49     std::function<void(unsigned)> surfaceDestroyed;
50     /*
51     std::function<void(unsigned)> layerCreated;
52     std::function<void(unsigned)> layerDestroyed;
53     */
54 };
55
56 class WMLayer;
57 class LayerState;
58 class WMAction;
59 class WMClient;
60
61 class LayerControl
62 {
63   public:
64     explicit LayerControl(const std::string& root);
65     ~LayerControl() = default;
66     WMError init(const LayerControlCallbacks& cb);
67     void createNewLayer(unsigned id, bool remote = false);
68     unsigned getNewLayerID(const std::string& role, std::string* layer_name = nullptr);
69     std::shared_ptr<WMLayer> getWMLayer(unsigned layer);
70     std::shared_ptr<WMLayer> getWMLayer(std::string layer_name);
71     struct rect getAreaSize(const std::string& area);
72     void setupArea(const rectangle& base_rct, double scaling);
73     Screen getScreenInfo();
74     double scale();
75     WMError renderLayers();
76     WMError setXDGSurfaceOriginSize(unsigned surface);
77     void undoUpdate();
78     WMError layoutChange(const WMAction& action);
79     WMError visibilityChange(const WMAction &action);
80     const std::unordered_map<std::string, struct rect>& getAreaList() {return this->area2size;}
81     WMError updateAreaList(const ChangeAreaReq& req);
82     WMError getUpdateAreaList(ChangeAreaReq* req);
83     WMError changeAreaSize(std::shared_ptr<WMClient> client, const std::string& area);
84     void appTerminated(const std::shared_ptr<WMClient> client);
85
86     // Don't use this function.
87     void dispatchCreateEvent(ilmObjectType object, unsigned id, bool created);
88     void dispatchSurfacePropChangeEvent(unsigned id, struct ilmSurfaceProperties*, t_ilm_notification_mask);
89     void dispatchLayerPropChangeEvent(unsigned id, struct ilmLayerProperties*, t_ilm_notification_mask);
90
91   private:
92     WMError makeVisible(const std::shared_ptr<WMClient> client);
93     WMError makeInvisible(const std::shared_ptr<WMClient> client);
94     bool moveForeGround(const std::shared_ptr<WMClient> client);
95     bool moveBackGround(const std::shared_ptr<WMClient> client);
96     WMError loadLayerSetting(const std::string& path);
97     WMError loadAreaDb(const std::string& path);
98
99     std::vector<std::shared_ptr<WMLayer>> wm_layers;
100     std::unordered_map<unsigned, unsigned> lid2wmlid;
101     std::unordered_map<std::string, struct rect> area2size;
102     unsigned screenID;
103     signed remoteScreenID;
104     struct ilmScreenProperties screen_prop;
105     double scaling;
106     int offset_x;
107     int offset_y;
108     LayerControlCallbacks cb;
109 };
110
111 } // namespace wm