Using the Tizen application manager to receive information about installed apps and...
[staging/HomeScreen.git] / WindowManager / src / windowmanager.cpp
1 /*
2  * Copyright (C) 2016 Mentor Graphics Development (Deutschland) GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "windowmanager.hpp"
18
19 //////////////////////////////////////////
20 // THIS IS STILL UNDER HEAVY DEVELOPMENT!
21 // DO NOT JUDGE THE SOURCE CODE :)
22 //////////////////////////////////////////
23
24
25 WindowManager::WindowManager(QObject *parent) :
26     QObject(parent)
27 {
28     qDebug("WindowManager");
29 #ifdef __arm__
30     ilmErrorTypes err;
31     if (true)//!ilm_isInitialized()) ...crashes...
32     {
33         err = ilm_init();
34         qDebug("ilm_init = %d", err);
35     }
36
37
38     t_ilm_uint screenID = 0;
39     t_ilm_uint width;
40     t_ilm_uint height;
41
42     err = ilm_getScreenResolution(screenID, &width, &height);
43     qDebug("ilm_getScreenResolution = %d", err);
44     qDebug("pWidth %d, pHeight %d", width, height);
45
46
47     t_ilm_layer layerId = 42; // does not matter
48     err = ilm_layerCreateWithDimension(&layerId, width, height);
49     qDebug("ilm_layerCreateWithDimension = %d", err);
50     qDebug("layerId = %d", layerId);
51
52     err = ilm_layerSetVisibility(layerId, true);
53     qDebug("ilm_layerSetVisibility = %d", err);
54
55     ilm_commitChanges();
56
57     err = ilm_displaySetRenderOrder(screenID, &layerId, 1);
58     qDebug("ilm_displaySetRenderOrder = %d", err);
59
60     ilm_commitChanges();
61
62     err =  ilm_layerSetSourceRectangle(layerId, 0, 0, width, height);
63     qDebug("ilm_layerSetSourceRectangle = %d", err);
64     err =  ilm_layerSetDestinationRectangle(layerId, 0, 0, width, height);
65     qDebug("layerSetDestinationRectangle = %d", err);
66
67     ilm_commitChanges();
68
69     t_ilm_float opacity = 1.0;
70
71     err =  ilm_layerSetOpacity(layerId, opacity);
72     qDebug("ilm_layerSetOpacity = %d", err);
73
74
75     t_ilm_int length;
76     t_ilm_surface* pArray;
77
78     err = ilm_getSurfaceIDs(&length, &pArray);
79     qDebug("ilm_getSurfaceIDs = %d", err);
80     qDebug("length %d pArray[0] %d", length, pArray[0]);
81
82     if (length > 0)
83     {
84         t_ilm_surface surfaceId = pArray[0];
85
86         err = ilm_layerAddSurface(layerId, surfaceId);
87         qDebug("ilm_layerAddSurface = %d", err);
88
89         t_ilm_bool visibility;
90         err = ilm_surfaceGetVisibility(surfaceId, &visibility);
91         qDebug("ilm_surfaceGetVisibility = %d", err);
92         qDebug("visibility %d", visibility);
93
94         err = ilm_surfaceSetVisibility(surfaceId, true);
95         qDebug("ilm_surfaceSetVisibility = %d", err);
96
97         err = ilm_surfaceSetOpacity(surfaceId, opacity);
98         qDebug("ilm_surfaceSetOpacity = %d", err);
99
100         err = ilm_surfaceSetSourceRectangle(surfaceId, 0, 0, 200, 200);
101         qDebug("ilm_surfaceSetSourceRectangle = %d", err);
102         err = ilm_surfaceSetDestinationRectangle(surfaceId, 0, 0, 200, 200);
103         qDebug("surfaceSetDestinationRectangle = %d", err);
104
105
106     }
107
108     ilm_commitChanges();
109
110     struct ilmScreenProperties screenProperties;
111     struct ilmLayerProperties layerProperties;
112     struct ilmSurfaceProperties surfaceProperties;
113
114     err =  ilm_getPropertiesOfScreen(0, &screenProperties);
115     qDebug("ilm_getPropertiesOfScreen = %d", err);
116     err =  ilm_getPropertiesOfLayer(layerId, &layerProperties);
117     qDebug("ilm_getPropertiesOfLayer = %d", err);
118     err =  ilm_getPropertiesOfSurface(pArray[0], &surfaceProperties);
119     qDebug("ilm_getPropertiesOfSurface = %d", err);
120
121
122     qDebug("screen");
123     qDebug("t_ilm_uint %d", screenProperties.layerCount);          /*!< number of layers displayed on the screen */
124     //qDebug("t_ilm_layer* %d", screenProperties.layerIds[0]);          /*!< array of layer ids */
125     qDebug("t_ilm_uint %d", screenProperties.harwareLayerCount);   /*!< number of hardware layers */
126     qDebug("t_ilm_uint %d", screenProperties.screenWidth);         /*!< width value of screen in pixels */
127     qDebug("t_ilm_uint %d", screenProperties.screenHeight);        /*!< height value of screen in pixels */
128
129     qDebug("layer");
130     qDebug("t_ilm_float %f", layerProperties.opacity);         /*!< opacity value of the layer */
131     qDebug("t_ilm_uint %d", layerProperties.sourceX);          /*!< x source position value of the layer */
132     qDebug("t_ilm_uint %d", layerProperties.sourceY);          /*!< y source position value of the layer */
133     qDebug("t_ilm_uint %d", layerProperties.sourceWidth);      /*!< source width value of the layer */
134     qDebug("t_ilm_uint %d", layerProperties.sourceHeight);     /*!< source height value of the layer */
135     qDebug("t_ilm_uint %d", layerProperties.origSourceWidth);  /*!< original source width value of the layer */
136     qDebug("t_ilm_uint %d", layerProperties.origSourceHeight); /*!< original source height value of the layer */
137     qDebug("t_ilm_uint %d", layerProperties.destX);            /*!< x destination position value of the layer */
138     qDebug("t_ilm_uint %d", layerProperties.destY);            /*!< y desitination position value of the layer */
139     qDebug("t_ilm_uint %d", layerProperties.destWidth);        /*!< destination width value of the layer */
140     qDebug("t_ilm_uint %d", layerProperties.destHeight);       /*!< destination height value of the layer */
141     qDebug("ilmOrientation%d",  layerProperties.orientation);  /*!< orientation value of the layer */
142     qDebug("t_ilm_bool %d", layerProperties.visibility);       /*!< visibility value of the layer */
143     qDebug("t_ilm_uint %d", layerProperties.type);             /*!< type of layer */
144     qDebug("t_ilm_int  %d", layerProperties.creatorPid);       /*!< process id of application that created this layer */
145
146     qDebug("surface");
147     qDebug("t_ilm_float %f", surfaceProperties.opacity);                    /*!< opacity value of the surface */
148     qDebug("t_ilm_uint %d", surfaceProperties.sourceX);                     /*!< x source position value of the surface */
149     qDebug("t_ilm_uint %d", surfaceProperties.sourceY);                     /*!< y source position value of the surface */
150     qDebug("t_ilm_uint %d", surfaceProperties.sourceWidth);                 /*!< source width value of the surface */
151     qDebug("t_ilm_uint %d", surfaceProperties.sourceHeight);                /*!< source height value of the surface */
152     qDebug("t_ilm_uint %d", surfaceProperties.origSourceWidth);             /*!< original source width value of the surface */
153     qDebug("t_ilm_uint %d", surfaceProperties.origSourceHeight);            /*!< original source height value of the surface */
154     qDebug("t_ilm_uint %d", surfaceProperties.destX);                       /*!< x destination position value of the surface */
155     qDebug("t_ilm_uint %d", surfaceProperties.destY);                       /*!< y desitination position value of the surface */
156     qDebug("t_ilm_uint %d", surfaceProperties.destWidth);                   /*!< destination width value of the surface */
157     qDebug("t_ilm_uint %d", surfaceProperties.destHeight);                  /*!< destination height value of the surface */
158     qDebug("ilmOrientation %d", surfaceProperties.orientation);             /*!< orientation value of the surface */
159     qDebug("t_ilm_bool %d", surfaceProperties.visibility);                  /*!< visibility value of the surface */
160     qDebug("t_ilm_uint %d", surfaceProperties.frameCounter);                /*!< already rendered frames of surface */
161     qDebug("t_ilm_uint %d", surfaceProperties.drawCounter);                 /*!< content updates of surface */
162     qDebug("t_ilm_uint %d", surfaceProperties.updateCounter);               /*!< content updates of surface */
163     qDebug("t_ilm_uint %d", surfaceProperties.pixelformat);                 /*!< pixel format of surface */
164     qDebug("t_ilm_uint %d", surfaceProperties.nativeSurface);               /*!< native surface handle of surface */
165     qDebug("t_ilm_int  %d", surfaceProperties.creatorPid);                  /*!< process id of application that created this surface */
166     qDebug("ilmInputDevice %d", surfaceProperties.focus);                   /*!< bitmask of every type of device that this surface has focus in */
167
168     err =  ilm_registerNotification(WindowManager::notificationFunc_static, this);
169 #endif
170 }
171
172 WindowManager::~WindowManager()
173 {
174 #ifdef __arm__
175     ilmErrorTypes err;
176     if (ilm_isInitialized())
177     {
178         err = ilm_destroy();
179         qDebug("ilm_destroy = %d", err);
180     }
181 #endif
182 }
183
184 #ifdef __arm__
185 void WindowManager::notificationFunc_non_static(ilmObjectType object,
186                                     t_ilm_uint id,
187                                     t_ilm_bool created)
188 {
189     qDebug("notificationFunc_non_static");
190     if (ILM_SURFACE == object)
191     {
192         struct ilmSurfaceProperties surfaceProperties;
193
194         if (created)
195         {
196             qDebug("Surface created, ID: %d", id);
197
198             ilm_layerAddSurface(42 /*always use layer 42 for now*/, id);
199             ilm_surfaceSetOpacity(id, 1.0);
200             ilm_surfaceSetVisibility(id, true);
201             ilm_getPropertiesOfSurface(id, &surfaceProperties);
202             ilm_surfaceSetSourceRectangle(id, 0, 0, surfaceProperties.origSourceWidth, surfaceProperties.origSourceHeight);
203
204             ilm_commitChanges();
205         }
206         else
207         {
208             qDebug("Surface destroyed, ID: %d", id);
209         }
210
211         t_ilm_uint screenID = 0;
212         t_ilm_uint width;
213         t_ilm_uint height;
214         ilm_getScreenResolution(screenID, &width, &height);
215
216         t_ilm_int length;
217         t_ilm_surface* pArray;
218
219         ilm_getSurfaceIDs(&length, &pArray);
220         qDebug("length %d", length);
221
222
223         for (int i = 0; i < length; ++i)
224         {
225             //ilm_getPropertiesOfSurface(pArray[i], &surfaceProperties);
226             qDebug("place surface %d at x: %f, y: %f, width: %f, height: %f",
227                    pArray[i],
228                    i * (width / (1.0 * length)),
229                    0,
230                    width / (1.0 * length),
231                    height);
232             ilm_surfaceSetDestinationRectangle(pArray[(int)i],
233                     i * (width / (1.0 * length)),
234                     0,
235                     width / (1.0 * length),
236                     height);
237         }
238
239         ilm_commitChanges();
240     }
241     if (ILM_LAYER == object)
242     {
243         qDebug("Layer.. we don't care...");
244     }
245 }
246
247 void WindowManager::notificationFunc_static(ilmObjectType object,
248                                             t_ilm_uint id,
249                                             t_ilm_bool created,
250                                             void* user_data)
251 {
252     qDebug("notificationFunc_static");
253     static_cast<WindowManager*>(user_data)->notificationFunc_non_static(object, id, created);
254 }
255 #endif