svn update: 48958 (latest:48959)
[framework/uifw/ecore.git] / src / lib / ecore_fb / ecore_fb.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4
5 #ifdef HAVE_CONFIG_H
6 # include <config.h>
7 #endif
8
9 #include "Ecore_Fb.h"
10 #include "ecore_fb_private.h"
11
12 static void _ecore_fb_size_get(int *w, int *h);
13
14 EAPI int ECORE_FB_EVENT_KEY_DOWN = 0;
15 EAPI int ECORE_FB_EVENT_KEY_UP = 0;
16 EAPI int ECORE_FB_EVENT_MOUSE_BUTTON_DOWN = 0;
17 EAPI int ECORE_FB_EVENT_MOUSE_BUTTON_UP = 0;
18 EAPI int ECORE_FB_EVENT_MOUSE_MOVE = 0;
19 EAPI int ECORE_FB_EVENT_MOUSE_WHEEL = 0;
20
21 static int _ecore_fb_init_count = 0;
22 static int _ecore_fb_console_w = 0;
23 static int _ecore_fb_console_h = 0;
24
25 static double _ecore_fb_double_click_time = 0.25;
26
27
28 /**
29  * @defgroup Ecore_FB_Library_Group Framebuffer Library Functions
30  *
31  * Functions used to set up and shut down the Ecore_Framebuffer functions.
32  */
33
34 /**
35  * Sets up the Ecore_Fb library.
36  * @param   name device target name
37  * @return  @c 0 on failure.  Otherwise, the number of times the library has
38  *          been initialised without being shut down.
39  * @ingroup Ecore_FB_Library_Group
40  */
41 EAPI int
42 ecore_fb_init(const char *name __UNUSED__)
43 {
44    if (++_ecore_fb_init_count != 1)
45      return _ecore_fb_init_count;
46
47    if (!ecore_fb_vt_init())
48      return --_ecore_fb_init_count;
49
50    ECORE_FB_EVENT_KEY_DOWN          = ecore_event_type_new();
51    ECORE_FB_EVENT_KEY_UP            = ecore_event_type_new();
52    ECORE_FB_EVENT_MOUSE_BUTTON_DOWN = ecore_event_type_new();
53    ECORE_FB_EVENT_MOUSE_BUTTON_UP   = ecore_event_type_new();
54    ECORE_FB_EVENT_MOUSE_MOVE        = ecore_event_type_new();
55    ECORE_FB_EVENT_MOUSE_WHEEL       = ecore_event_type_new();
56    _ecore_fb_size_get(&_ecore_fb_console_w, &_ecore_fb_console_h);
57
58    return _ecore_fb_init_count;
59 }
60
61 /**
62  * Shuts down the Ecore_Fb library. 
63  * @return  @c The number of times the system has been initialised without
64  *             being shut down.
65  * @ingroup Ecore_FB_Library_Group
66  */
67 EAPI int
68 ecore_fb_shutdown(void)
69 {    
70    if (--_ecore_fb_init_count != 0)
71      return _ecore_fb_init_count;
72
73    ecore_fb_vt_shutdown();
74
75    return _ecore_fb_init_count;
76 }
77
78
79 /**
80  * Retrieves the width and height of the current frame buffer in pixels.
81  * @param w Pointer to an integer in which to store the width.
82  * @param h Pointer to an interge in which to store the height.
83  */
84 EAPI void
85 ecore_fb_size_get(int *w, int *h)
86 {
87    if (w) *w = _ecore_fb_console_w;
88    if (h) *h = _ecore_fb_console_h;
89 }
90
91 static void
92 _ecore_fb_size_get(int *w, int *h)
93 {
94    struct fb_var_screeninfo fb_var;
95    int fb;
96    
97    fb = open("/dev/fb0", O_RDWR);
98    if (fb < 0)
99      {
100         if (w) *w = 0;
101         if (h) *h = 0;
102         return;
103      }
104    if (ioctl(fb, FBIOGET_VSCREENINFO, &fb_var) == -1)
105      {
106         if (w) *w = 0;
107         if (h) *h = 0;
108         return;
109      }
110    close(fb);
111    if (w) *w = fb_var.xres;
112    if (h) *h = fb_var.yres;
113 }