tizen 2.4 release
[framework/uifw/e17-mod-tizen-devicemgr.git] / src / e_mod_scrnconf.c
1 #include "e.h"
2 #include "e_randr.h"
3 #include "e_mod_main.h"
4 #include "e_mod_scrnconf.h"
5 #include "scrnconf_devicemgr.h"
6
7 #ifdef  _MAKE_ATOM
8 # undef _MAKE_ATOM
9 #endif
10
11 #define _MAKE_ATOM(a, s)                              \
12    do {                                               \
13         a = ecore_x_atom_get (s);                      \
14         if (!a)                                       \
15           SLOG(LOG_DEBUG, "DEVICEMGR",                              \
16                    "[E-devmgr] ##s creation failed.\n"); \
17    } while (0)
18
19 #define STR_XRR_DISPLAY_MODE_PROPERTY "XRR_PROPERTY_DISPLAY_MODE"
20
21 /* display mode */
22 typedef enum
23 {
24    XRR_OUTPUT_DISPLAY_MODE_NULL,           /* null */
25    XRR_OUTPUT_DISPLAY_MODE_WB_CLONE,       /* write-back */
26 } XRROutputPropDisplayMode;
27
28 /* screen conf dialog */
29 static E_Dialog *g_dia = NULL;
30
31 /* screen configuration info */
32 static struct
33 {
34    SC_EXT_OUTPUT           sc_output;
35    Utilx_Scrnconf_Dispmode sc_dispmode;
36    Utilx_Scrnconf_Status   sc_stat;
37    SC_EXT_RES              sc_res;
38 } sc_ext =
39 {
40    SC_EXT_OUTPUT_NULL,
41    UTILX_SCRNCONF_DISPMODE_NULL,
42    UTILX_SCRNCONF_STATUS_NULL,
43    SC_EXT_RES_NULL,
44 };
45
46 /* mode info */
47 static struct
48 {
49    int sc_res;
50    double refresh;
51    Ecore_X_Randr_Mode_Info * mode_info;
52 } sc_ext_mode [] =
53 {
54    {SC_EXT_RES_1920X1080, 0.0, NULL},
55    {SC_EXT_RES_1280X720, 0.0, NULL},
56    {SC_EXT_RES_720X480, 0.0, NULL},
57    {SC_EXT_RES_720X576, 0.0, NULL},
58 };
59
60 static char *str_output[3] = {
61     "null",
62     "HDMI1",
63     "Virtual1",
64 };
65
66 static char *str_dispmode[3] = {
67     "null",
68     "CLONE",
69     "EXTENDED",
70 };
71
72 static char *str_stat[3] = {
73     "null",
74     "CONNECT",
75     "ACTIVE",
76 };
77
78 static char *str_resolution[5] = {
79     "null",
80     "1920x1080",
81     "1280x720",
82     "720x480",
83     "720x576",
84 };
85
86 /* Calculates the vertical refresh rate of a mode. */
87 static double
88 _cal_vrefresh(Ecore_X_Randr_Mode_Info *mode_info)
89 {
90    double refresh = 0.0;
91    double dots = mode_info->hTotal * mode_info->vTotal;
92    if (!dots)
93        return 0;
94    refresh = (mode_info->dotClock + dots/2) / dots;
95
96    if (refresh > 0xffff)
97       refresh = 0xffff;
98
99     return refresh;
100 }
101
102 static char *
103 _get_str_output(int output)
104 {
105     char *str = NULL;
106
107     switch (output)
108     {
109     case SC_EXT_OUTPUT_HDMI:
110         str = str_output[1];
111         break;
112     case SC_EXT_OUTPUT_VIRTUAL:
113         str = str_output[2];
114         break;
115     default:
116         str = str_output[0];
117         break;
118     }
119
120     return str;
121 }
122
123 static char *
124 _get_str_dispmode(int dispmode)
125 {
126     char *str = NULL;
127
128     switch (dispmode)
129     {
130     case UTILX_SCRNCONF_DISPMODE_CLONE:
131         str = str_dispmode[1];
132         break;
133     case UTILX_SCRNCONF_DISPMODE_EXTENDED:
134         str = str_dispmode[2];
135         break;
136     default:
137         str = str_dispmode[0];
138         break;
139     }
140
141     return str;
142 }
143 static char *
144 _get_str_stat(int stat)
145 {
146     char *str = NULL;
147
148     switch (stat)
149     {
150     case UTILX_SCRNCONF_STATUS_CONNECT:
151         str = str_stat[1];
152         break;
153     case UTILX_SCRNCONF_STATUS_ACTIVE:
154         str = str_stat[2];
155         break;
156     case UTILX_SCRNCONF_STATUS_NULL:
157         str = str_stat[0];
158         break;
159     default:
160         str = str_stat[0];
161         break;
162     }
163
164     return str;
165 }
166
167 static char *
168 _get_str_resolution(int resolution)
169 {
170     char *str = NULL;
171
172     switch (resolution)
173     {
174     case SC_EXT_RES_1920X1080:
175         str = str_resolution[1];
176         break;
177     case SC_EXT_RES_1280X720:
178         str = str_resolution[2];
179         break;
180     case SC_EXT_RES_720X480:
181         str = str_resolution[3];
182         break;
183     case SC_EXT_RES_720X576:
184         str = str_resolution[4];
185         break;
186     default:
187         str = str_resolution[0];
188         break;
189     }
190
191     return str;
192 }
193
194 static int
195 _get_resolution_str (char *res_name)
196 {
197     int resolution = SC_EXT_RES_NULL;
198
199     if (!strcmp (res_name, str_resolution[1]))
200         resolution = SC_EXT_RES_1920X1080;
201     else if (!strcmp (res_name, str_resolution[2]))
202         resolution = SC_EXT_RES_1280X720;
203     else if (!strcmp (res_name, str_resolution[3]))
204         resolution = SC_EXT_RES_720X480;
205     else if (!strcmp (res_name, str_resolution[4]))
206         resolution = SC_EXT_RES_720X576;
207     else
208         resolution = SC_EXT_RES_NULL;
209
210     return resolution;
211 }
212
213
214 #if SCRN_CONF_DEBUG
215 static void
216 _debug_possible_crtc (E_Randr_Output_Info *output_info)
217 {
218    E_Randr_Crtc_Info *crtc_info = NULL;
219    E_Randr_Output_Info *t_o = NULL;
220    Ecore_X_Randr_Mode_Info *t_m = NULL;
221    Eina_List *t_l, *l_crtc;
222
223    EINA_LIST_FOREACH (output_info->possible_crtcs, l_crtc, crtc_info)
224      {
225         if (crtc_info == NULL)
226            continue;
227
228         SLOG(LOG_DEBUG, "DEVICEMGR", "[DeviceMgr]: possible crtc = %d\n", crtc_info->xid);
229
230         EINA_LIST_FOREACH (crtc_info->outputs, t_l, t_o)
231         {
232            SLOG(LOG_DEBUG, "DEVICEMGR", "    output : %s\n", t_o->name);
233         }
234
235         EINA_LIST_FOREACH (crtc_info->possible_outputs, t_l, t_o)
236           {
237              SLOG(LOG_DEBUG, "DEVICEMGR", "    possible output : %s\n", t_o->name);
238           }
239
240         EINA_LIST_FOREACH (crtc_info->outputs_common_modes, t_l, t_m)
241           {
242              if (!t_m->name)
243                 break;
244              SLOG(LOG_DEBUG, "DEVICEMGR", "    outputs common modes : %s\n", t_m->name);
245           }
246
247         if (!crtc_info->current_mode)
248           {
249              SLOG(LOG_DEBUG, "DEVICEMGR", "    no current mode \n");
250              crtc_xid = crtc_info->xid;
251              SLOG(LOG_DEBUG, "DEVICEMGR", "    crtc_id : %d\n", crtc_info->xid);
252           }
253         else
254           {
255              SLOG(LOG_DEBUG, "DEVICEMGR", "    current set mode : %s\n", crtc_info->current_mode->name);
256              SLOG(LOG_DEBUG, "DEVICEMGR", "    crtc_id : %d\n", crtc_info->xid);
257           }
258      }
259 }
260 #endif
261
262 static E_Randr_Output_Info *
263 _scrnconf_external_get_output_info_from_output_xid (Ecore_X_Randr_Output output_xid)
264 {
265    E_Randr_Output_Info *output_info = NULL;
266    Eina_List *iter;
267
268    EINA_LIST_FOREACH (e_randr_screen_info.rrvd_info.randr_info_12->outputs, iter, output_info)
269      {
270         if (output_info == NULL)
271            continue;
272
273         if (output_info->xid == output_xid)
274              return output_info;
275      }
276
277    return NULL;
278 }
279
280 static E_Randr_Output_Info *
281 _scrnconf_external_get_output_info_from_output (int output)
282 {
283    E_Randr_Output_Info *output_info = NULL;
284    Eina_List *iter;
285
286    EINA_LIST_FOREACH (e_randr_screen_info.rrvd_info.randr_info_12->outputs, iter, output_info)
287      {
288         if (output_info == NULL)
289            continue;
290
291         if (!strcmp(output_info->name, _get_str_output(output)))
292              return output_info;
293      }
294
295    return NULL;
296 }
297
298 static int
299 _scrnconf_external_get_output (E_Randr_Output_Info *output_info)
300 {
301    int output = SC_EXT_OUTPUT_NULL;
302
303    if (!strcmp (output_info->name, "HDMI1"))
304        output = SC_EXT_OUTPUT_HDMI;
305    else if (!strcmp (output_info->name, "Virtual1"))
306        output = SC_EXT_OUTPUT_VIRTUAL;
307    else
308        output = SC_EXT_OUTPUT_NULL;
309
310    return output;
311 }
312
313 static int
314 _scrnconf_external_set_modes (int sc_output, int num_res, int *resolutions)
315 {
316    E_Randr_Output_Info *output_info = NULL;
317    Ecore_X_Randr_Mode_Info *mode_info = NULL;
318    Eina_List *l_mode;
319    int res = SC_EXT_RES_NULL;
320    double refresh = 0.0;
321    int i;
322
323    output_info = _scrnconf_external_get_output_info_from_output (sc_output);
324    if (!output_info)
325      {
326         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : fail to find output_info from sc_output\n");
327         return 0;
328      }
329
330    EINA_LIST_FOREACH (output_info->monitor->modes, l_mode, mode_info)
331      {
332         if (mode_info == NULL)
333            continue;
334
335 #if 0 //debug
336         SLOG(LOG_DEBUG, "DEVICEMGR", "%s(%d): mode_info->name, %s, vrefresh, %f\n"
337                 , __func__, __LINE__, mode_info->name, _cal_vrefresh(mode_info));
338 #endif
339         res = _get_resolution_str (mode_info->name);
340         if (res == SC_EXT_RES_NULL)
341             continue;
342
343        for (i = 0; i < num_res; i++)
344          {
345             if (sc_ext_mode[i].sc_res == res)
346               {
347                  refresh = _cal_vrefresh (mode_info);
348                  if (refresh > sc_ext_mode[i].refresh)
349                    {
350                       sc_ext_mode[i].refresh = refresh;
351                       sc_ext_mode[i].mode_info = mode_info;
352                     }
353                }
354           }
355      }
356
357    for (i = 0; i < num_res; i++)
358      {
359         resolutions[i] = sc_ext_mode[i].sc_res;
360      }
361
362 #if 0 // debug
363    for (i = 0; i < num_res; i++)
364      {
365         SLOG(LOG_DEBUG, "DEVICEMGR", "[DeviceMgr]: res info:: (%d): %s, %f, %p\n"
366                 , i, _get_str_resolution(sc_ext_mode[i].sc_res), sc_ext_mode[i].refresh, sc_ext_mode[i].mode_info);
367
368      }
369 #endif
370
371    return 1;
372 }
373
374 static int
375 _scrnconf_external_get_setting_info (int output, int resolution, Ecore_X_Randr_Output *output_xid,
376         Ecore_X_Randr_Crtc *crtc_xid, Ecore_X_Randr_Mode *mode_xid, int *output_w, int *output_h)
377 {
378    E_Randr_Output_Info *output_info = NULL;
379    E_Randr_Crtc_Info *crtc_info = NULL;
380    Ecore_X_Randr_Mode_Info *mode_info = NULL;
381    Eina_List *l_crtc;
382    Eina_Bool found_output = EINA_FALSE;
383    int num_res = 0;
384    int i;
385
386    output_info = _scrnconf_external_get_output_info_from_output (output);
387    if (output_info == NULL)
388      {
389        SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr]: fail to get output_info from sc_output\n");
390        goto finish;
391      }
392
393    output_xid[0] = output_info->xid;
394
395    num_res = sizeof (sc_ext_mode) / sizeof (sc_ext_mode[0]);
396
397    /* find mode info */
398    for (i = 0; i < num_res; i++)
399      {
400         if (sc_ext_mode[i].sc_res == resolution)
401           {
402              mode_info = sc_ext_mode[i].mode_info;
403              break;
404           }
405      }
406
407    if (mode_info == NULL)
408      {
409         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr]: fail to get mode_info from sc_output\n");
410         goto finish;
411      }
412
413    *output_w = mode_info->width;
414    *output_h = mode_info->height;
415    *mode_xid = mode_info->xid;
416    found_output = EINA_TRUE;
417
418 #if SCRN_CONF_DEBUG
419    _debug_possible_crtc (output_info);
420 #endif
421
422    EINA_LIST_FOREACH (output_info->possible_crtcs, l_crtc, crtc_info)
423      {
424         if (crtc_info == NULL)
425            continue;
426
427         if (!crtc_info->current_mode)
428           {
429              *crtc_xid = crtc_info->xid;
430           }
431      }
432
433    if (output_info->crtc && (!*crtc_xid))
434       *crtc_xid = output_info->crtc->xid;
435    else
436       *crtc_xid = 0;
437
438 finish:
439
440    return found_output;
441 }
442
443 static int
444 _scrnconf_external_set_extended (int output, int resolution)
445 {
446    E_Randr_Output_Info *output_info = NULL;
447    Eina_List *l_output;
448    int lvds_x = 0, lvds_y = 0, lvds_w = 0, lvds_h = 0;
449    int output_x = 0, output_y = 0, output_w = 0, output_h = 0;
450    int resize_w = 0, resize_h = 0;
451    Ecore_X_Randr_Crtc crtc_xid = 0;
452    Ecore_X_Randr_Output output_xid[1] = {0};
453    Ecore_X_Randr_Mode mode_xid = 0;
454
455    /* get lvds information */
456    EINA_LIST_FOREACH (e_randr_screen_info.rrvd_info.randr_info_12->outputs, l_output, output_info)
457      {
458
459         if (output_info == NULL)
460            continue;
461
462         if (!strcmp (output_info->name, "LVDS1"))
463           {
464             lvds_x = output_info->crtc->geometry.x;
465             lvds_y = output_info->crtc->geometry.y;
466             lvds_w = output_info->crtc->current_mode->width;
467             lvds_h = output_info->crtc->current_mode->height;
468             break;
469           }
470      }
471
472    if (!_scrnconf_external_get_setting_info (output, resolution, output_xid, &crtc_xid, &mode_xid, &output_w, &output_h))
473        goto set_fail;
474
475    if (crtc_xid == 0)
476        goto set_fail;
477
478    /* set the output is right-of lvds output */
479    output_x = lvds_w;
480    output_y = 0;
481    resize_w = lvds_w + output_w;
482
483    if (lvds_h > output_h)
484       resize_h = lvds_h;
485    else
486       resize_h = output_h;
487
488    ecore_x_grab ();
489
490    SLOG(LOG_DEBUG, "DEVICEMGR", "[DeviceMgr]: set screen resize (%d,%d)\n", resize_w, resize_h);
491    if (!ecore_x_randr_screen_current_size_set (e_randr_screen_info.root, resize_w, resize_h, 0, 0))
492      {
493         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr]: fail to resize the screen\n");
494         goto set_fail;
495      }
496
497    SLOG(LOG_DEBUG, "DEVICEMGR", "[DeviceMgr]: set crtc_id, %d output_id, %d mode_id, %d)!\n", crtc_xid, output_xid[0], mode_xid);
498    if (!ecore_x_randr_crtc_settings_set (e_randr_screen_info.root, crtc_xid, output_xid, 1, output_x,
499                                        output_y, mode_xid, ECORE_X_RANDR_ORIENTATION_ROT_0))
500    {
501         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr]: fail to set x=%d, y=%d, w=%d, h=%d mode_id=%d, crtc_id=%d\n",
502                  output_x, output_y, output_w, output_h, mode_xid, crtc_xid);
503         goto set_fail;
504    }
505
506    e_mod_scrnconf_container_bg_canvas_visible_set(EINA_TRUE);
507
508    ecore_x_ungrab ();
509
510    return 1;
511
512 set_fail:
513    SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr]: %s fail to set the extended mode\n", _get_str_output(output));
514    ecore_x_ungrab ();
515
516    return 0;
517 }
518
519 static int
520 _scrnconf_external_set_clone (int output, int resolution)
521 {
522    E_Randr_Output_Info *output_info = NULL;
523    Eina_List *l_output;
524    int output_w = 0, output_h = 0;
525    int lvds_x = 0, lvds_y = 0, lvds_w = 0, lvds_h = 0;
526    int resize_w = 0, resize_h = 0;
527    Ecore_X_Randr_Crtc crtc_xid = 0;
528    Ecore_X_Randr_Output output_xid[1] = {0};
529    Ecore_X_Randr_Mode mode_xid = 0;
530    Ecore_X_Atom dispmode;
531    int value[2];
532
533    /* get lvds information */
534    EINA_LIST_FOREACH (e_randr_screen_info.rrvd_info.randr_info_12->outputs, l_output, output_info)
535      {
536
537         if (output_info == NULL)
538            continue;
539
540         if (!strcmp (output_info->name, "LVDS1"))
541           {
542             lvds_x = output_info->crtc->geometry.x;
543             lvds_y = output_info->crtc->geometry.y;
544             lvds_w = output_info->crtc->current_mode->width;
545             lvds_h = output_info->crtc->current_mode->height;
546             break;
547           }
548      }
549
550    resize_w = lvds_w;
551    resize_h = lvds_h;
552
553    if (!_scrnconf_external_get_setting_info (output, resolution, output_xid, &crtc_xid, &mode_xid, &output_w, &output_h))
554        goto set_fail;
555
556    ecore_x_grab ();
557
558    SLOG(LOG_DEBUG, "DEVICEMGR", "[DeviceMgr]: set screen resize (%d,%d)\n", resize_w, resize_h);
559    if (!ecore_x_randr_screen_current_size_set (e_randr_screen_info.root, resize_w, resize_h, 0, 0))
560      {
561         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr]: fail to resize the screen\n");
562         goto set_fail;
563      }
564
565    _MAKE_ATOM (dispmode, STR_XRR_DISPLAY_MODE_PROPERTY);
566
567    value[0] = XRR_OUTPUT_DISPLAY_MODE_WB_CLONE;
568    value[1] = mode_xid;
569
570    /* no ecore x API for XRRChangeOutputProperty */
571    XRRChangeOutputProperty (ecore_x_display_get (), output_xid[0], dispmode, XA_INTEGER, 32,
572                            PropModeReplace, (unsigned char *)&value, 2);
573
574    e_mod_scrnconf_container_bg_canvas_visible_set(EINA_FALSE);
575
576    ecore_x_sync ();
577
578    ecore_x_ungrab ();
579
580    return 1;
581
582 set_fail:
583    SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr]: %s fail to set the clone mode\n", _get_str_output(output));
584    ecore_x_ungrab ();
585
586    return 0;
587 }
588
589 static void
590 _dialog_extended_btn_cb (void *data, E_Dialog *g_dia)
591 {
592    E_Randr_Output_Info *output_info = (E_Randr_Output_Info *)data;
593    int sc_output = SC_EXT_OUTPUT_NULL;
594    int sc_res = SC_EXT_RES_NULL;
595    int num_res = 0;
596    int *resolutions  = NULL;
597
598    sc_output = _scrnconf_external_get_output (output_info);
599    if (sc_output == SC_EXT_OUTPUT_NULL)
600      {
601         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : fail to find sc_output from output_info\n");
602         goto set_fail;
603      }
604
605    num_res = sizeof (sc_ext_mode) / sizeof (sc_ext_mode[0]);
606
607    resolutions = calloc (num_res, sizeof (int));
608    if (!resolutions)
609      {
610         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : fail to allocate resolutions\n");
611         goto set_fail;
612      }
613
614    if (!_scrnconf_external_set_modes (sc_output, num_res, resolutions))
615      {
616         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : fail to set modes\n");
617         goto set_fail;
618      }
619
620    sc_res = resolutions[0];
621
622    if (!_scrnconf_external_set_extended (sc_output, sc_res))
623      {
624         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : fail to set modes\n");
625         goto set_fail;
626      }
627
628    /* set display mode */
629    sc_ext.sc_dispmode = UTILX_SCRNCONF_DISPMODE_EXTENDED;
630
631    e_mod_scrnconf_external_send_current_status ();
632
633    if (resolutions)
634        free (resolutions);
635
636    /* destroy dialog */
637    e_mod_scrnconf_external_dialog_free ();
638    return;
639
640 set_fail:
641    if (resolutions)
642        free (resolutions);
643
644    /* destroy dialog */
645    e_mod_scrnconf_external_dialog_free ();
646 }
647
648 static void
649 _dialog_clone_btn_cb (void *data, E_Dialog *g_dia)
650 {
651    E_Randr_Output_Info *output_info = (E_Randr_Output_Info *)data;
652    int sc_output = SC_EXT_OUTPUT_NULL;
653    int sc_res = SC_EXT_RES_NULL;
654    int num_res = 0;
655    int *resolutions  = NULL;
656
657    sc_output = _scrnconf_external_get_output (output_info);
658    if (sc_output == SC_EXT_OUTPUT_NULL)
659      {
660         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : fail to find sc_output from output_info\n");
661         goto set_fail;
662      }
663
664    num_res = sizeof (sc_ext_mode) / sizeof (sc_ext_mode[0]);
665
666    resolutions = calloc (num_res, sizeof (int));
667    if (!resolutions)
668      {
669         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : fail to allocate resolutions\n");
670         goto set_fail;
671      }
672
673    if (!_scrnconf_external_set_modes (sc_output, num_res, resolutions))
674      {
675         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : fail to set modes\n");
676         goto set_fail;
677      }
678
679    sc_res = resolutions[0];
680
681    if (!_scrnconf_external_set_clone (sc_output, sc_res))
682      {
683         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : fail to set clone\n");
684         goto set_fail;
685      }
686
687    /* set display mode */
688    sc_ext.sc_dispmode = UTILX_SCRNCONF_DISPMODE_EXTENDED;
689
690    e_mod_scrnconf_external_send_current_status ();
691
692    if (resolutions)
693        free (resolutions);
694
695    /* destroy dialog */
696    e_mod_scrnconf_external_dialog_free ();
697    return;
698
699 set_fail:
700    if (resolutions)
701        free (resolutions);
702
703    /* destroy dialog */
704    e_mod_scrnconf_external_dialog_free ();
705 }
706
707 static void
708 _dialog_cancle_btn_cb (void *data, E_Dialog *g_dia)
709 {
710    /* destroy dialog */
711    e_mod_scrnconf_external_dialog_free ();
712 }
713
714 void
715 e_mod_scrnconf_external_init ()
716 {
717    /* init scrn conf get property */
718    scrnconf_ext_update_get_perperty(ecore_x_display_get (), "null", "null", "null", "null");
719 }
720
721 void
722 e_mod_scrnconf_external_deinit ()
723 {}
724
725
726 void
727 e_mod_scrnconf_external_dialog_new (int output)
728 {
729    E_Manager *man;
730    E_Container *con;
731    E_Randr_Output_Info *output_info = NULL;
732
733    if (output == SC_EXT_OUTPUT_NULL)
734      {
735         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : Unknown output is not supported \n");
736         return;
737      }
738
739    output_info = _scrnconf_external_get_output_info_from_output (output);
740    if (!output_info)
741      {
742         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : fail to get output from xid\n");
743         return;
744      }
745
746    /* set to be null, if dialog already exists */
747    if (g_dia != NULL)
748       e_mod_scrnconf_external_dialog_free ();
749
750    man = e_manager_current_get ();
751    con = e_container_current_get (man);
752
753    if (output == SC_EXT_OUTPUT_HDMI)
754      {
755         g_dia = e_dialog_new (con, "E", "hdmi mode");
756         e_dialog_title_set (g_dia, "\nHDMI Connected !!\n");
757         e_dialog_text_set (g_dia, "<hilight>HDMI Connected<hilight><br>Select the screen configuration mode<br>");
758      }
759    else if (output == SC_EXT_OUTPUT_VIRTUAL)
760      {
761         g_dia = e_dialog_new (con, "E", "virtual mode");
762         e_dialog_title_set (g_dia, "\nVirtual Connected !!\n");
763         e_dialog_text_set (g_dia, "<hilight>Virtual Connected<hilight><br>Select the screen configuration mode<br>");
764      }
765
766    e_dialog_button_add (g_dia, "CLONE", NULL, _dialog_clone_btn_cb, (void *)output_info);
767    e_dialog_button_add (g_dia, "EXTENDED", NULL, _dialog_extended_btn_cb, (void *)output_info);
768    e_dialog_button_add (g_dia, "CANCLE", NULL, _dialog_cancle_btn_cb, (void *)output_info);
769
770    e_dialog_resizable_set (g_dia, 1);
771    e_win_centered_set (g_dia->win, 1);
772    e_dialog_show (g_dia);
773
774    ecore_x_sync ();
775 }
776
777 void
778 e_mod_scrnconf_external_dialog_free ()
779 {
780    if (g_dia != NULL)
781      {
782         e_util_defer_object_del (E_OBJECT (g_dia));
783         g_dia = NULL;
784      }
785
786    ecore_x_sync ();
787 }
788
789 int
790 e_mod_scrnconf_external_get_output_from_xid (Ecore_X_Randr_Output output_xid)
791 {
792    E_Randr_Output_Info *output_info = NULL;
793    int output = SC_EXT_OUTPUT_NULL;
794
795    output_info = _scrnconf_external_get_output_info_from_output_xid (output_xid);
796    if (!output_info)
797      {
798         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : fail to get output from xid\n");
799         return SC_EXT_OUTPUT_NULL;
800      }
801
802    output = _scrnconf_external_get_output (output_info);
803    if (output == SC_EXT_OUTPUT_NULL)
804      {
805         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : Unknown output is not supported \n");
806         return SC_EXT_OUTPUT_NULL;
807      }
808
809    return output;
810 }
811
812 int
813 e_mod_scrnconf_external_get_default_res (int sc_output, int preferred_w, int preferred_h)
814 {
815    int sc_res = SC_EXT_RES_NULL;
816    int num_res = 0;
817    int *resolutions  = NULL;
818    Ecore_X_Randr_Mode_Info * mode_info = NULL;
819    int i;
820
821    if (sc_output == SC_EXT_OUTPUT_NULL)
822      {
823         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : sc_output is unknown\n");
824         return 0;
825      }
826
827    num_res = sizeof (sc_ext_mode) / sizeof (sc_ext_mode[0]);
828
829    resolutions = calloc (num_res, sizeof (int));
830    if (!resolutions)
831      {
832         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : fail to allocate resolutions\n");
833         goto get_fail;
834      }
835
836    if (!_scrnconf_external_set_modes (sc_output, num_res, resolutions))
837      {
838         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : fail to set modes\n");
839         goto get_fail;
840      }
841
842    /* find the preferred resolution of the virtual output */
843    if (preferred_w > 0 && preferred_h > 0)
844      {
845         for (i = 0; i < num_res; i++)
846           {
847              mode_info = sc_ext_mode[i].mode_info;
848
849              if (!mode_info)
850                  continue;
851
852              if (sc_ext_mode[i].mode_info->width == preferred_w &&
853                  sc_ext_mode[i].mode_info->height == preferred_h)
854                {
855                   sc_res = sc_ext_mode[i].sc_res;
856                   break;
857                }
858           }
859      }
860    else
861      {
862         for (i = 0; i < num_res; i++)
863           {
864              mode_info = sc_ext_mode[i].mode_info;
865
866              if (!mode_info)
867                  continue;
868
869              sc_res = sc_ext_mode[i].sc_res;
870              break;
871           }
872      }
873
874    free (resolutions);
875
876    if (sc_res == SC_EXT_RES_NULL)
877       SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : default resolution is NULL\n");
878
879
880    if (sc_output == SC_EXT_OUTPUT_VIRTUAL)
881       sc_res = SC_EXT_RES_1280X720;
882
883    return sc_res;
884
885 get_fail:
886    if (resolutions)
887       free (resolutions);
888
889    return SC_EXT_RES_NULL;
890 }
891
892 int
893 e_mod_scrnconf_external_get_output (void)
894 {
895    return sc_ext.sc_output;
896 }
897
898 int
899 e_mod_scrnconf_external_set_output (int sc_output)
900 {
901    sc_ext.sc_output = sc_output;
902
903    return 1;
904 }
905
906 int
907 e_mod_scrnconf_external_get_res (void)
908 {
909   return sc_ext.sc_res;
910 }
911
912 int
913 e_mod_scrnconf_external_set_res (int sc_res)
914 {
915    sc_ext.sc_res = sc_res;
916
917    return 1;
918 }
919
920 int
921 e_mod_scrnconf_external_get_status (void)
922 {
923   return sc_ext.sc_stat;
924 }
925
926 int
927 e_mod_scrnconf_external_set_status (int sc_stat)
928 {
929    sc_ext.sc_stat = sc_stat;
930
931    return 1;
932 }
933
934 int
935 e_mod_scrnconf_external_set_dispmode (int sc_output, int sc_dispmode, int sc_res)
936 {
937    /* set display mode */
938    switch (sc_dispmode)
939      {
940         case UTILX_SCRNCONF_DISPMODE_CLONE:
941            if (!_scrnconf_external_set_clone (sc_output, sc_res))
942                 goto set_fail;
943            sc_ext.sc_dispmode = UTILX_SCRNCONF_DISPMODE_CLONE;
944            break;
945         case UTILX_SCRNCONF_DISPMODE_EXTENDED:
946            if (!_scrnconf_external_set_extended (sc_output, sc_res))
947                 goto set_fail;
948            sc_ext.sc_dispmode = UTILX_SCRNCONF_DISPMODE_EXTENDED;
949            break;
950         default:
951            break;
952      }
953
954    return 1;
955
956 set_fail:
957    SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : fail to set display mode (%d)\n", sc_dispmode);
958    return 0;
959 }
960
961 int
962 e_mod_scrnconf_external_get_dispmode (void)
963 {
964    return sc_ext.sc_dispmode;
965 }
966
967 int
968 e_mod_scrnconf_external_send_current_status (void)
969 {
970    char * str_output = _get_str_output (sc_ext.sc_output);
971    char * str_stat = _get_str_stat (sc_ext.sc_stat);
972    char * str_res = _get_str_resolution (sc_ext.sc_res);
973    char * str_dispmode = _get_str_dispmode (sc_ext.sc_dispmode);
974
975    if (!scrnconf_ext_update_get_perperty(ecore_x_display_get (), str_output, str_stat, str_res, str_dispmode))
976      {
977         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : fail to update get property \n");
978         return 0;
979      }
980
981    SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : SEND CLIENT MESSAGES..(%s,%s,%s,%s) \n", str_output, str_stat, str_res, str_dispmode);
982
983    if (!scrnconf_ext_send_status (ecore_x_display_get (), sc_ext.sc_stat, sc_ext.sc_dispmode))
984      {
985         SLOG(LOG_DEBUG, "DEVICEMGR",  "[DeviceMgr] : fail to send current status \n");
986         return 0;
987      }
988
989    return 1;
990 }
991
992 int
993 e_mod_scrnconf_external_reset (int sc_output)
994 {
995    int i;
996    int num_res = 0;
997
998    if (sc_output != sc_ext.sc_output ||
999        sc_ext.sc_output == SC_EXT_OUTPUT_NULL)
1000       return 1;
1001
1002    /* reset scrn conf of a external monitor */
1003    sc_ext.sc_output = SC_EXT_OUTPUT_NULL;
1004    sc_ext.sc_dispmode = UTILX_SCRNCONF_DISPMODE_NULL;
1005    sc_ext.sc_stat = UTILX_SCRNCONF_STATUS_NULL;
1006    sc_ext.sc_res = SC_EXT_RES_NULL;
1007
1008    num_res = sizeof (sc_ext_mode) / sizeof (sc_ext_mode[0]);
1009
1010    /* reset mode list of a external monitor */
1011    for (i = 0; i < num_res; i++)
1012      {
1013         sc_ext_mode[i].refresh = 0.0;
1014         sc_ext_mode[i].mode_info = NULL;
1015      }
1016    return 1;
1017 }
1018
1019 void
1020 e_mod_scrnconf_container_bg_canvas_visible_set(Eina_Bool visible)
1021 {
1022    E_Manager *man = NULL;
1023    E_Container *con = NULL;
1024    Eina_List *m, *c;
1025
1026    EINA_LIST_FOREACH(e_manager_list(), m, man)
1027      {
1028         EINA_LIST_FOREACH(man->containers, c, con)
1029           {
1030              if (visible)
1031                ecore_evas_show(con->bg_ecore_evas);
1032              else
1033                ecore_evas_hide(con->bg_ecore_evas);
1034           }
1035      }
1036 }