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