Tizen 2.1 base
[platform/core/uifw/e17-extra-config-modules.git] / config-slp / src / e_mod_main.c
1 /*
2  * e17-extra-config-modules
3  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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 "e.h"
19 #include "e_mod_main.h"
20 #include "Elementary.h"
21
22 #define RESOLUTION_BASE         1
23 #define PI                      3.141592
24 #define BASE_LAYOUT_INCH        4.65
25 #define BASE_LAYOUT_WIDTH_PX    720
26 #define BASE_LAYOUT_HEIGHT_PX   1280
27 #define ROUND_DOUBLE(x)         (round(((double)x)*100)/100)
28 #define ELM_FINGER_SIZE         60
29
30 static int _e_elm_config_scale_update(void);
31
32 /* this is needed to advertise a label for the module IN the code (not just
33  * the .desktop file) but more specifically the api version it was compiled
34  * for so E can skip modules that are compiled for an incorrect API version
35  * safely) */
36
37 EAPI E_Module_Api e_modapi =
38 {
39    E_MODULE_API_VERSION, "Elementary Profile Module of Window Manager"
40 };
41
42 EAPI void*
43 e_modapi_init(E_Module* m)
44 {
45    _e_elm_config_scale_update();
46    return m;
47 }
48
49 EAPI int
50 e_modapi_shutdown(E_Module* m)
51 {
52    return 1;
53 }
54
55 EAPI int
56 e_modapi_save(E_Module* m)
57 {
58    /* Do Something */
59    return 1;
60 }
61
62 #ifndef RESOLUTION_BASE
63 static double
64 _e_elm_config_dpi_get(double d_inch, int w_px, int h_px)
65 {
66    double dpi;
67
68    dpi = (sqrt((w_px * w_px) + (h_px * h_px))) / d_inch;
69
70    return dpi;
71 }
72 #endif
73
74 static int
75 _e_mod_config_elm_profile_save(double scale)
76 {
77    elm_init(0, NULL);
78    elm_config_scale_set(scale);
79    elm_config_finger_size_set(scale * ELM_FINGER_SIZE);
80    elm_config_save();
81    elm_shutdown();
82
83    return 1;
84 }
85
86 static int
87 _e_elm_config_scale_update (void)
88 {
89    int target_width, target_height, target_width_mm, target_height_mm;
90    double scale;
91
92    target_width = 0;
93    target_height = 0;
94    target_width_mm = 0;
95    target_height_mm = 0;
96
97    ecore_x_randr_screen_current_size_get(ecore_x_window_root_first_get(), &target_width, &target_height, &target_width_mm, &target_height_mm);
98
99 #if RESOLUTION_BASE
100
101    scale = ROUND_DOUBLE(target_width / BASE_LAYOUT_WIDTH_PX);
102
103 #else // DPI BASE
104    double target_inch, target_dpi, base_dpi;
105
106    target_inch = ROUND_DOUBLE(sqrt(target_width_mm * target_width_mm + target_height_mm * target_height_mm) / 25.4);
107
108    // Calculate DPI
109    base_dpi = ROUND_DOUBLE(_e_elm_config_dpi_get(BASE_LAYOUT_INCH, BASE_LAYOUT_WIDTH_PX, BASE_LAYOUT_HEIGHT_PX));
110    target_dpi = ROUND_DOUBLE(_e_elm_config_dpi_get(target_inch, target_width, target_height));
111
112      // Calculate Scale factor
113    scale = ROUND_DOUBLE(target_dpi / base_dpi);
114
115 #endif
116    e_config->scale.factor = scale;
117
118    // calculate elementray scale factor
119    _e_mod_config_elm_profile_save(scale);
120
121    return 1;
122 }