Tizen 2.1 base
[framework/uifw/ecore.git] / src / lib / ecore_wayland / ecore_wl_output.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
4
5 #include "ecore_wl_private.h"
6
7 /* local function prototypes */
8 static void _ecore_wl_output_cb_geometry(void *data, struct wl_output *wl_output __UNUSED__, int x, int y, int w, int h, int subpixel __UNUSED__, const char *make __UNUSED__, const char *model __UNUSED__, int transform __UNUSED__);
9 static void _ecore_wl_output_cb_mode(void *data, struct wl_output *wl_output __UNUSED__, unsigned int flags, int w, int h, int refresh __UNUSED__);
10
11 /* wayland listeners */
12 static const struct wl_output_listener _ecore_wl_output_listener = 
13 {
14    _ecore_wl_output_cb_geometry,
15    _ecore_wl_output_cb_mode
16 };
17
18 /* @since 1.2 */
19 EAPI struct wl_list 
20 ecore_wl_outputs_get(void)
21 {
22    return _ecore_wl_disp->outputs;
23 }
24
25 void 
26 _ecore_wl_output_add(Ecore_Wl_Display *ewd, unsigned int id)
27 {
28    Ecore_Wl_Output *output;
29
30    LOGFN(__FILE__, __LINE__, __FUNCTION__);
31
32    if (!(output = malloc(sizeof(Ecore_Wl_Output)))) return;
33
34    memset(output, 0, sizeof(Ecore_Wl_Output));
35
36    output->display = ewd;
37
38    output->output = wl_display_bind(ewd->wl.display, id, &wl_output_interface);
39    wl_list_insert(ewd->outputs.prev, &output->link);
40    wl_output_add_listener(output->output, &_ecore_wl_output_listener, output);
41 }
42
43 void 
44 _ecore_wl_output_del(Ecore_Wl_Output *output) 
45 {
46    if (!output) return;
47    if (output->destroy) (*output->destroy)(output, output->data);
48    if (output->output) wl_output_destroy(output->output);
49    wl_list_remove(&output->link);
50    free(output);
51 }
52
53 /* local functions */
54 static void 
55 _ecore_wl_output_cb_geometry(void *data, struct wl_output *wl_output __UNUSED__, int x, int y, int w, int h, int subpixel __UNUSED__, const char *make __UNUSED__, const char *model __UNUSED__, int transform __UNUSED__)
56 {
57    Ecore_Wl_Output *output;
58
59    LOGFN(__FILE__, __LINE__, __FUNCTION__);
60
61    output = data;
62    output->allocation.x = x;
63    output->allocation.y = y;
64    output->mw = w;
65    output->mh = h;
66 }
67
68 static void 
69 _ecore_wl_output_cb_mode(void *data, struct wl_output *wl_output __UNUSED__, unsigned int flags, int w, int h, int refresh __UNUSED__)
70 {
71    Ecore_Wl_Output *output;
72    Ecore_Wl_Display *ewd;
73
74    LOGFN(__FILE__, __LINE__, __FUNCTION__);
75
76    output = data;
77    ewd = output->display;
78    if (flags & WL_OUTPUT_MODE_CURRENT)
79      {
80         output->allocation.w = w;
81         output->allocation.h = h;
82         _ecore_wl_disp->output = output;
83         if (ewd->output_configure) (*ewd->output_configure)(output, ewd->data);
84      }
85 }