tizen 2.4 release
[framework/uifw/e17-mod-tizen-devicemgr.git] / src / e_mod_drv.c
1 #include "e.h"
2 #include "e_randr.h"
3 #include "e_mod_main.h"
4 #include "e_mod_drv.h"
5
6 #define STR_XRR_LVDS_FUNCTION "XRR_PROPERTY_LVDS_FUNCTION"
7
8 #ifdef  _MAKE_ATOM
9 # undef _MAKE_ATOM
10 #endif
11
12 #define _MAKE_ATOM(a, s)                              \
13    do {                                               \
14         a = ecore_x_atom_get (s);                      \
15         if (!a)                                       \
16           SLOG(LOG_DEBUG, "DEVICEMGR",                              \
17                    "[E-devmgr] ##s creation failed.\n"); \
18    } while (0)
19
20 /* lvds function */
21 typedef enum
22 {
23     XRR_OUTPUT_LVDS_FUNC_NULL,             /* null */
24     XRR_OUTPUT_LVDS_FUNC_INIT_VIRTUAL,     /* virutal output connect/disconnect */
25     XRR_OUTPUT_LVDS_FUNC_HIBERNATION,      /* hibernation on / off */
26     XRR_OUTPUT_LVDS_FUNC_ACCESSIBLILITY,   /* accessibility */
27 } XRROutputPropLvdsFunc;
28
29
30 void
31 e_mod_drv_virt_mon_set (int cmd)
32 {
33    SLOG(LOG_DEBUG, "DEVICEMGR", "[DeviceMgr]: set the virtual output connect/disconnect\n");
34
35    E_Randr_Output_Info *output_info = NULL;
36    Eina_List *l_output;
37    Eina_Bool found_output = EINA_FALSE;
38    Ecore_X_Randr_Output output_xid[1] = {0};
39    Ecore_X_Atom lvds_func;
40    int value[2];
41
42    EINA_LIST_FOREACH (e_randr_screen_info.rrvd_info.randr_info_12->outputs, l_output, output_info)
43      {
44         if (output_info == NULL)
45             continue;
46
47         if (!strcmp (output_info->name, "LVDS1"))
48           {
49              output_xid[0] = output_info->xid;
50              found_output = EINA_TRUE;
51           }
52      }
53
54    if (!found_output)
55      {
56         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr]: fail to initialize the virtual output\n");
57         goto set_fail;
58      }
59
60    ecore_x_grab ();
61
62    _MAKE_ATOM (lvds_func, STR_XRR_LVDS_FUNCTION);
63
64    value[0] = XRR_OUTPUT_LVDS_FUNC_INIT_VIRTUAL;
65    value[1] = cmd;
66
67    /* no ecore x API for XRRChangeOutputProperty */
68    XRRChangeOutputProperty (ecore_x_display_get (), output_xid[0], lvds_func, XA_INTEGER, 32,
69                            PropModeReplace, (unsigned char *)&value, 2);
70
71    /* replay through XSendMessage */
72
73    ecore_x_ungrab ();
74    ecore_x_sync ();
75    return;
76
77 set_fail:
78    ecore_x_ungrab ();
79 }
80
81 void
82 e_mod_drv_hib_set (int cmd)
83 {
84    SLOG(LOG_DEBUG, "DEVICEMGR", "[DeviceMgr]: set the hibernation on/off\n");
85
86    E_Randr_Output_Info *output_info = NULL;
87    Eina_List *l_output;
88    Eina_Bool found_output = EINA_FALSE;
89    Ecore_X_Randr_Output output_xid[1] = {0};
90    Ecore_X_Atom lvds_func;
91    int value[2];
92
93    EINA_LIST_FOREACH (e_randr_screen_info.rrvd_info.randr_info_12->outputs, l_output, output_info)
94      {
95         if (output_info == NULL)
96             continue;
97
98         if (!strcmp (output_info->name, "LVDS1"))
99           {
100              output_xid[0] = output_info->xid;
101              found_output = EINA_TRUE;
102           }
103      }
104
105    if (!found_output)
106      {
107         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr]: fail to initialize the virtual output\n");
108         goto set_fail;
109      }
110
111    ecore_x_grab ();
112
113    _MAKE_ATOM (lvds_func, STR_XRR_LVDS_FUNCTION);
114
115    value[0] = XRR_OUTPUT_LVDS_FUNC_HIBERNATION;
116    value[1] = cmd;
117
118    /* no ecore x API for XRRChangeOutputProperty */
119    XRRChangeOutputProperty (ecore_x_display_get (), output_xid[0], lvds_func, XA_INTEGER, 32,
120                            PropModeReplace, (unsigned char *)&value, 2);
121
122    /* replay through XSendMessage */
123
124    ecore_x_ungrab ();
125    ecore_x_sync ();
126    return;
127
128 set_fail:
129    ecore_x_ungrab ();
130 }
131