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