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