exampleCompositor: enable a DSTextInput
[platform/core/uifw/libds.git] / samples / exampleCompositor.cpp
1 /*
2 * Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include <DSCompositor.h>
25 #include <IDSOutput.h>
26 #include <DSInput.h>
27 #include <DSCanvas.h>
28 #include <DSSeat.h>
29 #include <DSPolicyArea.h>
30 #include <DSDisplayArea.h>
31 #include <DSTextInput.h>
32 #include "DSDebugLog.h"
33
34 using namespace display_server;
35
36 // MyCompositor has to inherit DSCompositor.
37 class MyCompositor : public DSCompositor
38 {
39 public:
40         MyCompositor()
41                 : __canvas{nullptr},
42                   __seat{nullptr},
43                   __policyArea{nullptr},
44                   __displayArea{nullptr}
45         {}
46
47         virtual ~MyCompositor()
48         {}
49
50         // The _onInitialized is called when the DSCompositor is ready to run.
51         // Make a seat and a policy area. Attach the seat to the policy area.
52         // Attach the policy area and the display area to canvas and return it.
53         std::shared_ptr<DSCanvas> _onInitialized() override
54         {
55                 int width = __displayArea->getWidth();
56                 int height = __displayArea->getHeight();
57
58                 /* create a seat */
59                 __seat = std::make_shared<DSSeat>(this, "default");
60
61                 __policyArea = std::make_shared<DSPolicyArea>();
62                 __policyArea->setPosition(0, 0);
63                 __policyArea->setSize(width, height);
64                 __policyArea->attachSeat(__seat);
65
66                 __canvas = std::make_shared<DSCanvas>();
67
68                 __canvas->attachPolicyArea(__policyArea);
69                 __canvas->attachDisplayArea(__displayArea);
70
71                 __textInput = std::make_shared<DSTextInput>();
72
73                 return __canvas;
74         }
75
76         // The _onOutputAdded is called when the IDSOutput is added.
77         void _onOutputAdded(std::shared_ptr<IDSOutput> output) override
78         {
79                 // set the resolution.
80                 output->applyResolutionAuto();
81
82                 // make a display area.
83                 __displayArea = std::make_shared<DSDisplayArea>(output);
84         }
85
86         // The _onOutputAdded is called when the IDSOutput is removed.
87         void _onOutputRemoved(std::shared_ptr<IDSOutput> output) override
88         {
89                 __displayArea.reset(); // delete shared_ptr
90         }
91
92         // TODO:
93         void _onInputAdded(std::shared_ptr<DSInput> input) override
94         {}
95
96         // TODO:
97         void _onInputRemoved(std::shared_ptr<DSInput> input) override
98         {}
99
100 private:
101         std::shared_ptr<DSCanvas> __canvas;
102         std::shared_ptr<DSSeat> __seat;
103         std::shared_ptr<DSPolicyArea> __policyArea;
104         std::shared_ptr<DSDisplayArea> __displayArea;
105         std::shared_ptr<DSTextInput> __textInput;
106 };
107
108 int main() {
109         DSCompositor *compositor = new MyCompositor();
110
111         compositor->run();
112
113         delete compositor;
114 }