2 #include "e_mod_main.h"
3 #include "Elementary.h"
6 #define BASE_LAYOUT_INCH 4.65
7 #define BASE_LAYOUT_WIDTH_PX 720
8 #define BASE_LAYOUT_HEIGHT_PX 1280
9 #define ROUND_DOUBLE(x) (round((x)*100)/100)
10 #define MOBILE_PROFILE "mobile"
12 static int _e_elm_config_scale_update(void);
13 static double _e_elm_config_dpi_get(double d_inch, int w_px, int h_px);
15 static char fullpath[1024];
17 /* this is needed to advertise a label for the module IN the code (not just
18 * the .desktop file) but more specifically the api version it was compiled
19 * for so E can skip modules that are compiled for an incorrect API version
21 EAPI E_Module_Api e_modapi =
23 E_MODULE_API_VERSION, "Elementary Profile Module of Window Manager"
27 e_modapi_init(E_Module* m)
29 _e_elm_config_scale_update();
34 e_modapi_shutdown(E_Module* m)
40 e_modapi_save(E_Module* m)
47 _e_elm_config_dpi_get(double d_inch, int w_px, int h_px)
51 dpi = (sqrt((w_px * w_px) + (h_px * h_px))) / d_inch;
57 _file_owner_change(uid_t uid, gid_t gid)
65 if (lstat(fullpath, &statbuf) < 0)
67 fprintf(stderr, "%s : stat error \n", fullpath);
70 if (S_ISDIR(statbuf.st_mode) == 0)
73 ptr = fullpath + strlen(fullpath);
77 if ((dp = opendir(fullpath)) == NULL)
79 fprintf(stderr, "can't read %s directory \n", fullpath);
83 while ((dirp = readdir(dp)) != NULL)
85 if (strcmp(dirp->d_name, ".") == 0 ||
86 strcmp(dirp->d_name, "..") == 0)
89 strcpy(ptr, dirp->d_name);
90 if ((chown(fullpath, uid, gid) == -1))
91 fprintf(stderr, "%s chown error \n", fullpath);
93 if ((ret = _file_owner_change(uid, gid)) != 0)
99 fprintf(stderr, "can't close directory %s", fullpath);
106 _e_mod_config_elm_profile_save(char *profile_name, double scale)
108 struct dirent *directory;
109 struct stat file_info;
114 setenv("HOME", "/home/app", 1);
117 elm_scale_set(scale);
118 elm_finger_size_set(scale * 60);
120 dp = opendir("/home/");
123 while((directory = readdir(dp)))
125 if ((!strcmp(directory->d_name, ".")) || (!strcmp(directory->d_name, ".."))) continue;
126 snprintf(buf, sizeof(buf), "/home/%s", directory->d_name);
127 if ((ret = lstat(buf, &file_info) == -1))
129 printf("error : can't get file stat \n");
132 if (S_ISDIR(file_info.st_mode))
134 setenv("HOME", buf, 1);
136 snprintf(buf, sizeof(buf), "/home/%s/.elementary", directory->d_name);
137 strcpy(fullpath, buf);
138 if ((chown(fullpath, file_info.st_uid, file_info.st_gid)) == -1)
139 fprintf(stderr, "%s chown error \n", fullpath);
140 _file_owner_change(file_info.st_uid, file_info.st_gid);
150 _e_elm_config_scale_update (void)
152 int target_width, target_height, target_width_mm, target_height_mm;
153 double target_inch, scale, target_dpi, base_dpi;
158 target_height_mm = 0;
160 ecore_x_randr_screen_current_size_get(ecore_x_window_root_first_get(), &target_width, &target_height, &target_width_mm, &target_height_mm);
161 target_inch = ROUND_DOUBLE(sqrt(target_width_mm * target_width_mm + target_height_mm * target_height_mm) / 25.4);
164 base_dpi = ROUND_DOUBLE(_e_elm_config_dpi_get(BASE_LAYOUT_INCH, BASE_LAYOUT_WIDTH_PX, BASE_LAYOUT_HEIGHT_PX));
165 target_dpi = ROUND_DOUBLE(_e_elm_config_dpi_get(target_inch, target_width, target_height));
167 // Calculate Scale factor
168 scale = ROUND_DOUBLE(target_dpi / base_dpi);
170 e_config->scale.factor = scale;
172 // calculate elementray scale factor
173 _e_mod_config_elm_profile_save(MOBILE_PROFILE, scale);
175 system ("/bin/touch /opt/etc/.profile_ready");