summaryrefslogtreecommitdiff
path: root/src/util_wayland.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util_wayland.c')
-rw-r--r--src/util_wayland.c92
1 files changed, 78 insertions, 14 deletions
diff --git a/src/util_wayland.c b/src/util_wayland.c
index 62aa894..db02498 100644
--- a/src/util_wayland.c
+++ b/src/util_wayland.c
@@ -12,8 +12,20 @@
#include "widget_service.h"
#include "debug.h"
+#define CONF_PATH_FORMAT "/usr/share/data-provider-master/%dx%d/resolution.ini"
+
int errno;
+static struct {
+ unsigned int w;
+ unsigned int h;
+ int res_resolved;
+} s_info = {
+ .w = 0,
+ .h = 0,
+ .res_resolved = 0,
+};
+
static int update_info(struct supported_size_list *SIZE_LIST, int width_type, int height_type, int width, int height)
{
int idx;
@@ -208,25 +220,39 @@ static inline int update_from_file(struct service_info *info, struct supported_s
return WIDGET_NR_OF_SIZE_LIST - updated;
}
-int util_update_resolution(struct service_info *info, struct supported_size_list *SIZE_LIST)
+/*
+ * Find proper configuration and install(link) it to conf path.
+ */
+static char *conf_path(void)
{
- unsigned int width;
- unsigned int height;
- unsigned int border;
- unsigned int depth;
- register int i;
- static int res_resolved = 0;
-
- if (res_resolved) {
- return WIDGET_ERROR_NONE;
+ char *path;
+ int length;
+
+ length = strlen(CONF_PATH_FORMAT) + 12; // 12 == RESERVED SPACE
+ path = calloc(1, length);
+ if (!path) {
+ ErrPrint("calloc: %s\n", strerror(errno));
+ return NULL;
}
- if (update_from_file(info, SIZE_LIST) == 0) {
- DbgPrint("Resolution info is all updated by file\n");
+ if (s_info.w == 0 || s_info.h == 0) {
+ /* Try to update resolution first if it is not initialized */
+ util_screen_size_get(NULL, NULL);
}
- res_resolved = 1;
- return WIDGET_ERROR_NONE;
+ snprintf(path, length, CONF_PATH_FORMAT, s_info.w, s_info.h);
+ DbgPrint("Selected conf file: %s\n", path);
+ if (access(path, F_OK) != 0) {
+ ErrPrint("Fallback to default, access: %s\n", strerror(errno));
+ strncpy(path, RESOLUTION_FILE, length);
+ if (access(path, F_OK) != 0) {
+ ErrPrint("Serious error - there is no conf file, use default setting: %s\n", strerror(errno));
+ free(path);
+ path = NULL;
+ }
+ }
+
+ return path;
}
int util_screen_size_get(unsigned int *width, unsigned int *height)
@@ -234,4 +260,42 @@ int util_screen_size_get(unsigned int *width, unsigned int *height)
return WIDGET_ERROR_NONE;
}
+int util_update_resolution(struct service_info *info, struct supported_size_list *SIZE_LIST)
+{
+ if (s_info.res_resolved) {
+ return WIDGET_ERROR_NONE;
+ }
+
+ if (!info->conf_file) {
+ info->conf_file = conf_path();
+ }
+
+ if (info->conf_file) {
+ register int i;
+ unsigned int width;
+ unsigned int height;
+
+ i = util_screen_size_get(&width, &height);
+ if (i != WIDGET_ERROR_NONE) {
+ return i;
+ }
+
+ if (update_from_file(info, SIZE_LIST) == 0) {
+ DbgPrint("Resolution info is all updated by file\n");
+ }
+
+ if (width != info->base_w) {
+ for (i = 0; i < WIDGET_NR_OF_SIZE_LIST; i++) {
+ SIZE_LIST[i].w = (unsigned int)((double)SIZE_LIST[i].w * (double)width / (double)info->base_w);
+ SIZE_LIST[i].h = (unsigned int)((double)SIZE_LIST[i].h * (double)width / (double)info->base_w);
+ }
+ }
+ } else {
+ DbgPrint("Conf file is not loaded\n");
+ }
+
+ s_infos_info..res_resolved = 1;
+ return WIDGET_ERROR_NONE;
+}
+
/* End of a file */