]> icculus.org git repositories - btb/d2x.git/blob - input/ggi_event.c
More header unification...
[btb/d2x.git] / input / ggi_event.c
1 #include <conf.h>
2
3 #ifdef GII_INPUT
4
5 #include <stdio.h>
6 #include <sys/time.h>
7 #include <ggi/gii.h>
8 #include <string.h>
9 #include "event.h"
10 #include "error.h"
11 #include "fix.h"
12
13 static int initialised=0;
14
15 #ifdef GGI_VIDEO
16 #include <ggi/ggi.h>
17 extern ggi_visual_t *screenvis;
18 #endif
19 gii_input_t inputs;
20
21 extern void keyboard_handler(int key, ubyte state);
22 extern void mouse_handler_button(int button, ubyte state);
23 extern void mouse_handler_relative(int x, int y);
24 extern void mouse_handler_absolute(int x, int y);
25
26 void event_poll()
27 {
28         int n;
29         struct timeval tv;
30         gii_event event;
31
32         if (!initialised)
33                 event_init();
34         if (inputs==NULL)
35                 return;
36 //              Error("GII error: no inputs (perhaps you need to set GII_INPUT env var)\n");
37
38         tv.tv_sec = 0;
39         tv.tv_usec = 0;
40
41         giiEventPoll(inputs, emAll, &tv);
42         
43         n = giiEventsQueued(inputs, emAll);
44         
45         while (n-- > 0) 
46         {
47                 giiEventRead(inputs, &event, emAll);
48                 switch (event.any.type)
49                 {
50                         case evKeyPress:
51                                 keyboard_handler(event.key.label, 1);
52                                 break;
53                         case evKeyRelease:
54                                 keyboard_handler(event.key.label, 0);
55                                 break;
56                         case evPtrAbsolute:
57                                 mouse_handler_absolute(event.pmove.x, event.pmove.y);
58                                 break;
59                         case evPtrRelative:
60                                 mouse_handler_relative(event.pmove.x, event.pmove.y);
61                                 break;
62                         case evPtrButtonPress:
63                                 mouse_handler_button(event.pbutton.button - 1, 1);
64                                 break;
65                         case evPtrButtonRelease:
66                                 mouse_handler_button(event.pbutton.button - 1, 0);
67                                 break;
68                 }
69         }
70 }
71
72 void event_close()
73 {
74 #ifndef GGI_VIDEO
75         if (inputs)
76                 giiClose(inputs);
77 #endif
78         giiExit();
79 }
80
81 #ifdef GII_XWIN
82 int gii_xwin_initialized=0;
83 #include <ggi/input/xwin.h>
84 //void lock_nothing(void){return;}
85 void init_gii_xwin(Display *disp,Window win){
86         printf("gii xwin %i %i\n",initialised,gii_xwin_initialized);
87         if (!initialised)
88                 event_init();
89         if (gii_xwin_initialized){
90                 gii_event ev;
91                 gii_xwin_cmddata_setparam *giiargs=(gii_xwin_cmddata_setparam *) &ev.cmd.data;
92                 memset(&ev,0,sizeof(gii_cmd_nodata_event)+sizeof(gii_xwin_cmddata_setparam));
93                 ev.cmd.code=GII_CMDCODE_XWINSETPARAM;
94                 ev.any.type = evCommand;
95                 ev.any.size=sizeof(gii_cmd_nodata_event)+sizeof(gii_xwin_cmddata_setparam);
96                 giiargs->win=win;
97                 giiargs->ptralwaysrel=1;
98                 giiEventSend(inputs,&ev);
99         }else{
100                 gii_input_t inputs2;
101                 gii_inputxwin_arg giiargs;
102                 memset(&giiargs,0,sizeof(giiargs));
103                 giiargs.disp=disp;
104                 giiargs.win=win;
105                 giiargs.ptralwaysrel=1;
106                 //giiargs.gglock=lock_nothing;
107                 inputs2=giiOpen("xwin",&giiargs,NULL);
108                 if (inputs2){
109                         gii_xwin_initialized=1;
110                         if (inputs)
111                                 inputs=giiJoinInputs(inputs,inputs2);
112                         else
113                                 inputs=inputs2;
114                 }
115         }
116 }
117 #endif
118
119 int event_init()
120 {
121         if (!initialised){
122                 giiInit();
123 #ifdef GGI_VIDEO
124                 inputs = ggiJoinInputs(screenvis, NULL);
125 #else
126                 inputs=giiOpen(NULL);
127 #endif
128                 initialised = 1;
129                 atexit(event_close);
130         }
131         return 0;
132 }
133
134 #endif /* GII_INPUT */