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