Tizen 2.1 release
[platform/core/uifw/e17.git] / src / bin / e_randr_serialization.c
1 #include "e_randr_private.h"
2 #include "e_randr.h"
3
4 #define ECORE_X_RANDR_1_1   ((1 << 16) | 1)
5 #define ECORE_X_RANDR_1_2   ((1 << 16) | 2)
6 #define ECORE_X_RANDR_1_3   ((1 << 16) | 3)
7
8 /**********************************************************************
9  *
10  * Storage/Restorage of setups
11  *
12  **********************************************************************
13  */
14
15 E_Randr_Serialized_Setup *
16 _new_serialized_setup(void)
17 {
18    return E_NEW(E_Randr_Serialized_Setup, 1);
19 }
20
21 EINTERN E_Randr_Serialized_Setup *
22 e_randr_serialized_setup_new(void)
23 {
24     return _new_serialized_setup();
25 }
26
27 EAPI void
28 e_randr_store_configuration(E_Randr_Configuration_Store_Modifier modifier)
29 {
30    if (!e_config->randr_serialized_setup)
31      e_config->randr_serialized_setup = _new_serialized_setup();
32
33    fprintf(stderr, "E_RANDR: Configuration shall be stored using the following modifier:%s\n%s%s%s%s",
34          ((!modifier) ? "NONE" : ""),
35          ((modifier & E_RANDR_CONFIGURATION_STORE_POLICIES) ? "\tPOLICIES\n" : ""),
36          ((modifier & E_RANDR_CONFIGURATION_STORE_RESOLUTIONS) ? "\tRESOLUTIONS\n" : ""),
37          ((modifier & E_RANDR_CONFIGURATION_STORE_ARRANGEMENT) ? "\tARRANGEMENTS\n" : ""),
38          ((modifier & E_RANDR_CONFIGURATION_STORE_ORIENTATIONS) ? "\tORIENTATIONS\n" : ""));
39
40    if (e_randr_screen_info.randr_version == ECORE_X_RANDR_1_1)
41      {
42         _11_store_configuration(modifier);
43      }
44    else if (e_randr_screen_info.randr_version >= ECORE_X_RANDR_1_2)
45      {
46         _12_store_configuration(modifier);
47      }
48    e_config_save_queue();
49 }
50
51 Eina_Bool
52 _try_restore_configuration(void)
53 {
54    EINA_SAFETY_ON_NULL_RETURN_VAL(e_config, EINA_FALSE);
55    if (!e_config->randr_serialized_setup) return EINA_FALSE;
56
57    if ((e_randr_screen_info.randr_version == ECORE_X_RANDR_1_1) ||
58        ((e_randr_screen_info.randr_version >= ECORE_X_RANDR_1_1) && e_config->randr_serialized_setup->serialized_setup_11 && !e_config->randr_serialized_setup->serialized_setups_12)) // either be 1.1 or maybe we have stored a resolution using the old conf_display dialog (which uses randr 1.1)
59      return _11_try_restore_configuration();
60    else if (e_randr_screen_info.randr_version >= ECORE_X_RANDR_1_2)
61      return _12_try_restore_configuration();
62
63    return EINA_FALSE;
64 }
65
66 EINTERN Eina_Bool e_randr_try_restore_configuration(void)
67 {
68    return _try_restore_configuration();
69 }
70
71 EINTERN void e_randr_serialized_setup_free(E_Randr_Serialized_Setup *ss)
72 {
73    E_Randr_Serialized_Setup_12 *serialized_setup_12 = NULL;
74    E_Randr_Serialized_Output_Policy *serialized_output_policy = NULL;
75
76    EINA_SAFETY_ON_NULL_RETURN(ss);
77
78    e_randr_11_serialized_setup_free(ss->serialized_setup_11);
79    if (ss->serialized_setups_12)
80      {
81         EINA_LIST_FREE(ss->serialized_setups_12, serialized_setup_12)
82           {
83              e_randr_12_serialized_setup_free(serialized_setup_12);
84           }
85      }
86    EINA_LIST_FREE(ss->outputs_policies, serialized_output_policy)
87      {
88         e_randr_12_serialized_output_policy_free(serialized_output_policy);
89      }
90    free(ss);
91 }