aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/lib/ecore_directfb/ecore_directfb.c
blob: f45b3c373e7412da37d86f227e69c8f461fbf415 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* ifdef HAVE_CONFIG_H */

#include <stdio.h>
#include <string.h>

#include "Ecore_DirectFB.h"
#include "ecore_directfb_private.h"
#include "ecore_directfb_keys.h"
#include "Ecore.h"
#include "ecore_private.h"

/* ecore_directfb */
/******************/
/* About */
/* with this you can create windows of directfb and handle events through ecore
 * TODO:
 * - handle all event types
 * -
 * */
int _ecore_directfb_log_dom = -1;

static int _ecore_directfb_init_count = 0;

static int _window_event_fd = 0;
static int _input_event_fd = 0;

static int _ecore_directfb_fullscreen_window_id = 0;
static int _cursor_x = 0;
static int _cursor_y = 0;

EAPI int ECORE_DIRECTFB_EVENT_POSITION = 0;
EAPI int ECORE_DIRECTFB_EVENT_SIZE = 0;
EAPI int ECORE_DIRECTFB_EVENT_CLOSE = 0;
EAPI int ECORE_DIRECTFB_EVENT_DESTROYED = 0;
EAPI int ECORE_DIRECTFB_EVENT_GOT_FOCUS = 0;
EAPI int ECORE_DIRECTFB_EVENT_LOST_FOCUS = 0;
EAPI int ECORE_DIRECTFB_EVENT_KEY_DOWN = 0;
EAPI int ECORE_DIRECTFB_EVENT_KEY_UP = 0;
EAPI int ECORE_DIRECTFB_EVENT_BUTTON_DOWN = 0;
EAPI int ECORE_DIRECTFB_EVENT_BUTTON_UP = 0;
EAPI int ECORE_DIRECTFB_EVENT_MOTION = 0;
EAPI int ECORE_DIRECTFB_EVENT_ENTER = 0;
EAPI int ECORE_DIRECTFB_EVENT_LEAVE = 0;
EAPI int ECORE_DIRECTFB_EVENT_WHEEL = 0;

static Ecore_Fd_Handler *_window_event_fd_handler_handle = NULL;
static Ecore_Fd_Handler *_input_event_fd_handler_handle = NULL;

/* this hash is to store all the possible key names for fast lookup */
static Eina_Hash *_ecore_directfb_key_symbols_hash = NULL;

static IDirectFB *_dfb = NULL; // the main interface
static IDirectFBEventBuffer *_window_event;     // the main event buffer (all windows are attached to this)
static IDirectFBEventBuffer *_input_event; // the main event buffer (all windows are attached to this)
static IDirectFBDisplayLayer *_layer; // the main layer
static DFBResult _err; // useful for DFBCHECK

/*******************/
/* local functions */
/*******************/

/* free ecore directfb events functions */
/****************************************/

static void
_ecore_directfb_event_free_key_down(void *data __UNUSED__, void *ev)
{
   Ecore_DirectFB_Event_Key_Up *e;

   e = ev;
   if(e->name)
      free(e->name);

   if (e->string)
      free(e->string);

   if (e->key_compose)
      free(e->key_compose);

   free(e);
} /* _ecore_directfb_event_free_key_down */

static void
_ecore_directfb_event_free_key_up(void *data __UNUSED__, void *ev)
{
   Ecore_DirectFB_Event_Key_Up *e;

   e = ev;
   if(e->name)
      free(e->name);

   if (e->string)
      free(e->string);

   if (e->key_compose)
      free(e->key_compose);

   free(e);
} /* _ecore_directfb_event_free_key_up */

/* directfb window input events handler */
/****************************************/

static void
_ecore_directfb_event_handle_motion(DFBEvent *evt)
{
   Ecore_DirectFB_Event_Motion *e;
   e = calloc(1, sizeof(Ecore_DirectFB_Event_Motion));

   switch(evt->clazz)
     {
      case DFEC_INPUT:
         e->modifiers = 0;
         switch(evt->input.axis)
           {
            case DIAI_X:
               e->x = _cursor_x = evt->input.axisabs;
               e->y = _cursor_y;
               break;

            case DIAI_Y:
               e->y = _cursor_y = evt->input.axisabs;
               e->x = _cursor_x;
               break;

            case DIAI_Z:
               //_ecore_directfb_event_handle_wheel(evt);
               return;

            default:
               return;
           } /* switch */
         e->win = _ecore_directfb_fullscreen_window_id;
         e->time = 0;
         break;

      case DFEC_WINDOW:
         e->modifiers = 0;
         e->x = evt->window.x;
         e->y = evt->window.y;
         e->win = evt->window.window_id;
         e->time = 0;
         break;

      default:
         break;
     } /* switch */
   ecore_event_add(ECORE_DIRECTFB_EVENT_MOTION, e, NULL, NULL);
} /* _ecore_directfb_event_handle_motion */

static void
_ecore_directfb_event_handle_key_down(DFBEvent *evt)
{
   Ecore_DirectFB_Event_Key_Down *e;
   unsigned int key_symbol;
   struct keymap *k;

   e = calloc(1, sizeof(Ecore_DirectFB_Event_Key_Down));

   switch(evt->clazz)
     {
      case DFEC_INPUT:
         key_symbol = evt->input.key_symbol;
         k = eina_hash_find(_ecore_directfb_key_symbols_hash, &key_symbol);

         if(!k)
           {
              ERR("Symbol %0X of class DFEC_INPUT not found.", evt->input.key_symbol);
              return;
           }

         e->name = strdup(k->name);
         e->string = strdup(k->string);
         e->key_compose = NULL;
         e->win = _ecore_directfb_fullscreen_window_id;
         e->time = 0;
         break;

      case DFEC_WINDOW:
         key_symbol = evt->window.key_symbol;
         k = eina_hash_find(_ecore_directfb_key_symbols_hash, &key_symbol);

         if(!k)
           {
              ERR("Symbol %0X of class DFEC_WINDOW not found.", evt->window.key_symbol);
              return;
           }

         e->name = strdup(k->name);
         e->string = strdup(k->string);
         e->key_compose = NULL;
         e->win = evt->window.window_id;
         e->time = 0;
         break;

      default:
         break;
     } /* switch */

   ecore_event_add(ECORE_DIRECTFB_EVENT_KEY_DOWN, e, _ecore_directfb_event_free_key_down, NULL);
} /* _ecore_directfb_event_handle_key_down */

static void
_ecore_directfb_event_handle_key_up(DFBEvent *evt)
{
   Ecore_DirectFB_Event_Key_Up *e;
   unsigned int key_symbol;
   struct keymap *k;

   e = calloc(1, sizeof(Ecore_DirectFB_Event_Key_Up));

   switch(evt->clazz)
     {
      case DFEC_INPUT:
         key_symbol = evt->input.key_symbol;
         k = eina_hash_find(_ecore_directfb_key_symbols_hash, &key_symbol);

         if(!k)
           {
              ERR("Symbol %0X of class DFEC_INPUT not found.", evt->input.key_symbol);
              return;
           }

         e->name = strdup(k->name);
         e->string = strdup(k->string);
         e->key_compose = NULL;
         e->win = _ecore_directfb_fullscreen_window_id;
         e->time = 0;
         break;

      case DFEC_WINDOW:
         key_symbol = evt->window.key_symbol;
         k = eina_hash_find(_ecore_directfb_key_symbols_hash, &key_symbol);

         if(!k)
           {
              ERR("Symbol %0X of class DFEC_WINDOW not found.", evt->window.key_symbol);
              return;
           }

         e->name = strdup(k->name);
         e->string = strdup(k->string);
         e->key_compose = NULL;
         e->win = evt->window.window_id;
         e->time = 0;
         break;

      default:
         break;
     } /* switch */
   ecore_event_add(ECORE_DIRECTFB_EVENT_KEY_UP, e, _ecore_directfb_event_free_key_up, NULL);
} /* _ecore_directfb_event_handle_key_up */

static void
_ecore_directfb_event_handle_button_down(DFBEvent *evt)
{
   Ecore_DirectFB_Event_Button_Down *e;
   e = calloc(1, sizeof(Ecore_DirectFB_Event_Button_Down));

   switch(evt->clazz)
     {
      case DFEC_INPUT:
         e->button = evt->input.button + 1;
         e->modifiers = 0;
         DFBCHECK(_layer->GetCursorPosition(_layer,&e->x,&e->y));
         e->x = _cursor_x;
         e->y = _cursor_y;
         e->win = _ecore_directfb_fullscreen_window_id;
         e->time = 0;

         break;

      case DFEC_WINDOW:
         e->button = evt->window.button + 1;
         e->modifiers = 0;
         e->x = evt->window.x;
         e->y = evt->window.y;
         e->win = evt->window.window_id;
         e->time = 0;
         break;

      default:
         break;
     } /* switch */

   ecore_event_add(ECORE_DIRECTFB_EVENT_BUTTON_DOWN, e, NULL, NULL);
} /* _ecore_directfb_event_handle_button_down */

static void
_ecore_directfb_event_handle_button_up(DFBEvent *evt)
{
   Ecore_DirectFB_Event_Button_Up *e;
   e = calloc(1, sizeof(Ecore_DirectFB_Event_Button_Up));

   switch(evt->clazz)
     {
      case DFEC_INPUT:
         e->button = evt->input.button + 1;
         e->modifiers = 0;
         e->x = _cursor_x;
         e->y = _cursor_y;
         e->win = _ecore_directfb_fullscreen_window_id;
         e->time = 0;

         break;

      case DFEC_WINDOW:
         e->button = evt->window.button + 1;
         e->modifiers = 0;
         e->x = evt->window.x;
         e->y = evt->window.y;
         e->win = evt->window.window_id;
         e->time = 0;
         break;

      default:
         break;
     } /* switch */
   ecore_event_add(ECORE_DIRECTFB_EVENT_BUTTON_UP, e, NULL, NULL);
} /* _ecore_directfb_event_handle_button_up */

static void
_ecore_directfb_event_handle_enter(DFBWindowEvent *evt)
{
   Ecore_DirectFB_Event_Enter *e;
   e = calloc(1, sizeof(Ecore_DirectFB_Event_Enter));

   e->modifiers = 0;
   e->x = evt->x;
   e->y = evt->y;
   e->win = evt->window_id;
   e->time = 0;

   ecore_event_add(ECORE_DIRECTFB_EVENT_ENTER, e, NULL, NULL);
} /* _ecore_directfb_event_handle_enter */

static void
_ecore_directfb_event_handle_leave(DFBWindowEvent *evt)
{
   Ecore_DirectFB_Event_Leave *e;
   e = calloc(1, sizeof(Ecore_DirectFB_Event_Leave));

   e->modifiers = 0;
   e->x = evt->x;
   e->y = evt->y;
   e->win = evt->window_id;
   e->time = 0;

   ecore_event_add(ECORE_DIRECTFB_EVENT_LEAVE, e, NULL, NULL);
} /* _ecore_directfb_event_handle_leave */

static void
_ecore_directfb_event_handle_wheel(DFBWindowEvent *evt)
{
   Ecore_DirectFB_Event_Wheel *e;
   e = calloc(1, sizeof(Ecore_DirectFB_Event_Wheel));

   // currently there's no direction (only up/down);
   e->direction = 0;
   e->z = evt->step;
   e->modifiers = 0;
   e->win = evt->window_id;
   e->time = 0;

   ecore_event_add(ECORE_DIRECTFB_EVENT_WHEEL, e, NULL, NULL);
} /* _ecore_directfb_event_handle_wheel */

static void
_ecore_directfb_event_handle_got_focus(DFBWindowEvent *evt)
{
   Ecore_DirectFB_Event_Got_Focus *e;
   e = calloc(1, sizeof(Ecore_DirectFB_Event_Got_Focus));

   e->win = evt->window_id;
   e->time = 0;

   ecore_event_add(ECORE_DIRECTFB_EVENT_GOT_FOCUS, e, NULL, NULL);
} /* _ecore_directfb_event_handle_got_focus */

static void
_ecore_directfb_event_handle_lost_focus(DFBWindowEvent *evt)
{
   Ecore_DirectFB_Event_Lost_Focus *e;
   e = calloc(1, sizeof(Ecore_DirectFB_Event_Lost_Focus));

   e->win = evt->window_id;
   e->time = 0;

   ecore_event_add(ECORE_DIRECTFB_EVENT_LOST_FOCUS, e, NULL, NULL);
} /* _ecore_directfb_event_handle_lost_focus */

/* inputs and windows fds handlers */
/***********************************/
/* TODO fix this to handle windows and input events (fullscreen/window mode)
 * in fullscreen theres no window_id so get the id from a global var (only one fullscreen
 * window at a time */

static Eina_Bool
_ecore_directfb_input_event_fd_handler(void *data __UNUSED__,Ecore_Fd_Handler *fd_handler __UNUSED__)
{
   DFBEvent evt;
   int v = 0;

   v = read(_input_event_fd, &evt, sizeof(DFBEvent));
   if (v < 0)
      return EINA_TRUE;

   if (v < 1)
      return EINA_TRUE;

   /* we are getting duplicate events, only parse if we are in fullscreen */
   //if(_ecore_directfb_fullscreen_window_id == 0) break;
   if(evt.input.type == DIET_KEYPRESS)
      _ecore_directfb_event_handle_key_down(&evt);

   if(evt.input.type == DIET_KEYRELEASE)
      _ecore_directfb_event_handle_key_up(&evt);

   if(evt.input.type == DIET_BUTTONPRESS)
      _ecore_directfb_event_handle_button_down(&evt);

   if(evt.input.type == DIET_BUTTONRELEASE)
      _ecore_directfb_event_handle_button_up(&evt);

   if(evt.input.type == DIET_AXISMOTION)
      _ecore_directfb_event_handle_motion(&evt);

   return EINA_TRUE;
} /* _ecore_directfb_input_event_fd_handler */

static Eina_Bool
_ecore_directfb_window_event_fd_handler(void *data __UNUSED__,Ecore_Fd_Handler *fd_handler __UNUSED__)
{
   DFBEvent evt;
   int v = 0;

   v = read(_window_event_fd, &evt, sizeof(DFBEvent));
   if (v < 0)
      return EINA_TRUE;

   if (v < 1)
      return EINA_TRUE;

   if(evt.window.type & DWET_POSITION)
      INF("position");

   if(evt.window.type & DWET_SIZE)
      INF("size");

   if(evt.window.type & DWET_CLOSE)
      INF("close");

   if(evt.window.type & DWET_DESTROYED)
      INF("destroyed");

   if(evt.window.type & DWET_GOTFOCUS)
      _ecore_directfb_event_handle_got_focus(&evt.window);

   if(evt.window.type & DWET_LOSTFOCUS)
      _ecore_directfb_event_handle_lost_focus(&evt.window);

   if(evt.window.type & DWET_KEYDOWN)
      _ecore_directfb_event_handle_key_down(&evt);

   if(evt.window.type & DWET_KEYUP)
      _ecore_directfb_event_handle_key_up(&evt);

   if(evt.window.type & DWET_BUTTONDOWN)
      _ecore_directfb_event_handle_button_down(&evt);

   if(evt.window.type & DWET_BUTTONUP)
      _ecore_directfb_event_handle_button_up(&evt);

   if(evt.window.type & DWET_MOTION)
      _ecore_directfb_event_handle_motion(&evt);

   if(evt.window.type & DWET_ENTER)
      _ecore_directfb_event_handle_enter(&evt.window);

   if(evt.window.type & DWET_LEAVE)
      _ecore_directfb_event_handle_leave(&evt.window);

   if(evt.window.type & DWET_WHEEL)
      _ecore_directfb_event_handle_wheel(&evt.window);

   return EINA_TRUE;
} /* _ecore_directfb_window_event_fd_handler */

/* api functions */
/*****************/

EAPI IDirectFB *
ecore_directfb_interface_get(void)
{
   return _dfb;
} /* ecore_directfb_interface_get */

EAPI Ecore_DirectFB_Window *
ecore_directfb_window_new(int x, int y, int w, int h)
{
   Ecore_DirectFB_Window *window;
   IDirectFBWindow *dfb_window;
   IDirectFBSurface *dfb_surface = NULL;
   DFBWindowDescription desc;
   DFBWindowID id;

   memset(&desc, 0, sizeof(DFBWindowDescription));
   desc.flags = (DWDESC_POSX | DWDESC_POSY | DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS);
   desc.posx = x;
   desc.posy = y;
   desc.width = w;
   desc.height = h;
   desc.caps = DWCAPS_ALPHACHANNEL;

   DFBCHECK(_layer->CreateWindow(_layer, &desc, &dfb_window));

   dfb_window->AttachEventBuffer(dfb_window, _window_event);
   dfb_window->SetOptions(dfb_window,DWOP_NONE);
   dfb_window->SetOpacity(dfb_window, 0xFF);

   DFBCHECK(dfb_window->GetID(dfb_window, &id));
   DFBCHECK(dfb_window->GetSurface(dfb_window,&dfb_surface));

   window = malloc(sizeof(Ecore_DirectFB_Window));
   window->id = id;
   window->window = dfb_window;
   window->surface = dfb_surface;
   window->cursor = NULL;

   return window;
} /* ecore_directfb_window_new */

EAPI void
ecore_directfb_window_free(Ecore_DirectFB_Window *ecore_window)
{
   DFBCHECK(ecore_window->surface->Release(ecore_window->surface));
   DFBCHECK(ecore_window->window->Release(ecore_window->window));
   free(ecore_window);
} /* ecore_directfb_window_free */

EAPI void
ecore_directfb_window_move(Ecore_DirectFB_Window *ecore_window, int x, int y)
{
   DFBCHECK(ecore_window->window->MoveTo(ecore_window->window, x, y));
} /* ecore_directfb_window_move */

EAPI void
ecore_directfb_window_resize(Ecore_DirectFB_Window *ecore_window, int w, int h)
{
   DFBCHECK(ecore_window->window->Resize(ecore_window->window, w, h));
} /* ecore_directfb_window_resize */

EAPI void
ecore_directfb_window_focus(Ecore_DirectFB_Window *ecore_window)
{
   DFBCHECK(ecore_window->window->RequestFocus(ecore_window->window));
} /* ecore_directfb_window_focus */

EAPI void
ecore_directfb_window_hide(Ecore_DirectFB_Window *ecore_window)
{
   DFBCHECK(ecore_window->window->SetOpacity(ecore_window->window, 0));
} /* ecore_directfb_window_hide */

EAPI void
ecore_directfb_window_show(Ecore_DirectFB_Window *ecore_window)
{
   DFBCHECK(ecore_window->window->SetOpacity(ecore_window->window, 0xFF));
} /* ecore_directfb_window_show */

EAPI void
ecore_directfb_window_shaped_set(Ecore_DirectFB_Window *ecore_window, Eina_Bool set)
{
   DFBWindowOptions opts;

   DFBCHECK(ecore_window->window->GetOptions(ecore_window->window, &opts));
   if(set)
     {
        opts |= DWOP_SHAPED;
        opts |= DWOP_ALPHACHANNEL;
        DFBCHECK(ecore_window->window->SetOptions(ecore_window->window, opts));
     }
   else
     {
        opts &= ~DWOP_SHAPED;
        opts &= ~DWOP_ALPHACHANNEL;
        DFBCHECK(ecore_window->window->SetOptions(ecore_window->window, opts));
     }
} /* ecore_directfb_window_shaped_set */

EAPI void
ecore_directfb_window_cursor_show(Ecore_DirectFB_Window *ecore_window, Eina_Bool show)
{
   if(!show)
     {
        /* create an empty cursor and set it */
        IDirectFBSurface *cursor;
        DFBSurfaceDescription desc;

        memset(&desc, 0, sizeof(DFBSurfaceDescription));
        desc.flags = (DSDESC_HEIGHT | DSDESC_WIDTH | DSDESC_PIXELFORMAT);
        desc.width = 1;
        desc.height = 1;
        desc.pixelformat = DSPF_A1;

        DFBCHECK(_dfb->CreateSurface(_dfb,&desc,&cursor));
        DFBCHECK(cursor->Clear(cursor,0,0,0,0));
        DFBCHECK(ecore_window->window->SetCursorShape(ecore_window->window, cursor, 0, 0));
     }
   else
     {
        /* we already have a cursor surface so set it*/
        if(ecore_window->cursor)
          {
             DFBCHECK(ecore_window->window->SetCursorShape(ecore_window->window, ecore_window->cursor->surface, ecore_window->cursor->hot_x, ecore_window->cursor->hot_y));
          }
        /* or just set the default directfb cursor */
        else
          {
             DFBCHECK(ecore_window->window->SetCursorShape(ecore_window->window, NULL, 0, 0));
          }
     }
} /* ecore_directfb_window_cursor_show */

EAPI void
ecore_directfb_window_cursor_set(Ecore_DirectFB_Window *ecore_window, Ecore_DirectFB_Cursor *cursor)
{
   if((!cursor) && (ecore_window->cursor))
     {
        ecore_window->cursor = NULL;
        DFBCHECK(ecore_window->window->SetCursorShape(ecore_window->window, NULL, 0, 0));
        return;
     }

   if(cursor)
     {
        ecore_window->cursor = cursor;
        DFBCHECK(ecore_window->window->SetCursorShape(ecore_window->window, cursor->surface, cursor->hot_x, cursor->hot_y));
     }
} /* ecore_directfb_window_cursor_set */

EAPI void
ecore_directfb_window_fullscreen_set(Ecore_DirectFB_Window *ecore_window, Eina_Bool on)
{
   // always release the surface (we are going to get a new one in both cases)
   DFBCHECK(ecore_window->surface->Release(ecore_window->surface));
   if(on)
     {
        DFBCHECK(_layer->SetCooperativeLevel(_layer,DLSCL_EXCLUSIVE));
        DFBCHECK(_layer->GetSurface(_layer,&ecore_window->surface));
        DFBCHECK(_dfb->CreateInputEventBuffer(_dfb, DICAPS_ALL, DFB_FALSE, &_input_event));
        DFBCHECK(_input_event->CreateFileDescriptor(_input_event,&_input_event_fd));
        /* the event of axismove sends one axis at a time, so we must store both */
        DFBCHECK(_layer->GetCursorPosition(_layer,&_cursor_x,&_cursor_y));

        _input_event_fd_handler_handle = ecore_main_fd_handler_add(_input_event_fd,ECORE_FD_READ,_ecore_directfb_input_event_fd_handler, NULL,NULL,NULL);
        _ecore_directfb_fullscreen_window_id = ecore_window->id;
     }
   else
     {
        ecore_main_fd_handler_del(_input_event_fd_handler_handle);
        DFBCHECK(_input_event->Release(_input_event));
        DFBCHECK(_layer->SetCooperativeLevel(_layer,DLSCL_SHARED));
        DFBCHECK(ecore_window->window->GetSurface(ecore_window->window, &ecore_window->surface));
        _ecore_directfb_fullscreen_window_id = 0;
     }
} /* ecore_directfb_window_fullscreen_set */

EAPI void
ecore_directfb_window_size_get(Ecore_DirectFB_Window *ecore_window, int *w, int *h)
{
   DFBCHECK(ecore_window->surface->GetSize(ecore_window->surface,w,h));
   return;
} /* ecore_directfb_window_size_get */

EAPI int
ecore_directfb_init(const char *name __UNUSED__)
{
   int i = 0;

   if (++_ecore_directfb_init_count != 1)
      return _ecore_directfb_init_count;

   _ecore_directfb_log_dom = eina_log_domain_register
     ("ecore_directfb", ECORE_DIRECTFB_DEFAULT_LOG_COLOR);
   if(_ecore_directfb_log_dom < 0)
     {
        EINA_LOG_ERR("Impossible to create a log domain for the Ecore directFB module.");
        return _ecore_directfb_init_count--;
     }

   DFBCHECK(DirectFBInit(NULL,NULL));
   DFBCHECK(DirectFBCreate(&_dfb));

   DFBCHECK(_dfb->GetDisplayLayer(_dfb, DLID_PRIMARY, &_layer));
   DFBCHECK(_layer->SetCooperativeLevel(_layer, DLSCL_SHARED));

   /* window events and fd */
   DFBCHECK(_dfb->CreateEventBuffer(_dfb, &_window_event));
   DFBCHECK(_window_event->CreateFileDescriptor(_window_event,&_window_event_fd));
   _window_event_fd_handler_handle = ecore_main_fd_handler_add(_window_event_fd,ECORE_FD_READ,_ecore_directfb_window_event_fd_handler, NULL,NULL,NULL);

   /* register ecore directfb events */
   ECORE_DIRECTFB_EVENT_POSITION = ecore_event_type_new();
   ECORE_DIRECTFB_EVENT_SIZE = ecore_event_type_new();
   ECORE_DIRECTFB_EVENT_CLOSE = ecore_event_type_new();
   ECORE_DIRECTFB_EVENT_DESTROYED = ecore_event_type_new();
   ECORE_DIRECTFB_EVENT_GOT_FOCUS = ecore_event_type_new();
   ECORE_DIRECTFB_EVENT_LOST_FOCUS = ecore_event_type_new();
   ECORE_DIRECTFB_EVENT_KEY_DOWN = ecore_event_type_new();
   ECORE_DIRECTFB_EVENT_KEY_UP = ecore_event_type_new();
   ECORE_DIRECTFB_EVENT_BUTTON_DOWN = ecore_event_type_new();
   ECORE_DIRECTFB_EVENT_BUTTON_UP = ecore_event_type_new();
   ECORE_DIRECTFB_EVENT_MOTION = ecore_event_type_new();
   ECORE_DIRECTFB_EVENT_ENTER = ecore_event_type_new();
   ECORE_DIRECTFB_EVENT_LEAVE = ecore_event_type_new();
   ECORE_DIRECTFB_EVENT_WHEEL = ecore_event_type_new();

   /* create the hash table for the keynames */
   _ecore_directfb_key_symbols_hash = eina_hash_int32_new(free);
   for(i = 0; i < _ecore_directfb_key_symbols_count; i++)
     {
        struct keymap *k;
        k = malloc(sizeof(struct keymap));
        k->name = _ecore_directfb_key_symbols[i].name;
        k->string = _ecore_directfb_key_symbols[i].string;
        eina_hash_add(_ecore_directfb_key_symbols_hash, &_ecore_directfb_key_symbols[i].id, k);
     }
   /* create the hash for the windows(key = windowid, val = Ecore_DirectFB_Window struct) */
   return _ecore_directfb_init_count;
} /* ecore_directfb_init */

EAPI int
ecore_directfb_shutdown(void)
{
   if (--_ecore_directfb_init_count != 0)
      return _ecore_directfb_init_count;

   ecore_main_fd_handler_del(_window_event_fd_handler_handle);
   eina_hash_free(_ecore_directfb_key_symbols_hash);

   if(_ecore_directfb_fullscreen_window_id)
     {
        DFBCHECK(_input_event->Release(_input_event));
        ecore_main_fd_handler_del(_input_event_fd_handler_handle);
     }

   DFBCHECK(_window_event->Release(_window_event));
   DFBCHECK(_layer->Release(_layer));
   DFBCHECK(_dfb->Release(_dfb));
   eina_log_domain_unregister(_ecore_directfb_log_dom);
   _ecore_directfb_log_dom = -1;
   return _ecore_directfb_init_count;
} /* ecore_directfb_shutdown */