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