File: x11cntrl.c

package info (click to toggle)
netmaze 0.81+jpg0.82-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,188 kB
  • ctags: 911
  • sloc: ansic: 8,277; tcl: 1,223; makefile: 58; sh: 16
file content (229 lines) | stat: -rw-r--r-- 6,971 bytes parent folder | download | duplicates (10)
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
/*
 * X11: (event) - control
 */

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>

#include "netmaze.h"

extern struct shared_struct *sm;

extern void run_game(MAZE*,PLAYER*);
extern void draw_info(void);


void x11_flush(void)
{
  XFlush(sm->grafix.display);
}

void x11_cntrl(void)
{
  int i;
  XEvent event1;
  KeySym key;
  char text[10];

#ifdef USE_IPC
  for(;;)
  {
    if(sm->sologame)
      if(!(XEventsQueued (sm->grafix.display1,QueuedAfterReading) > 0))
/*      if(!(XEventsQueued (sm->grafix.display1,QueuedAlready) > 0)) */
        break;
#else
  while(XEventsQueued (sm->grafix.display1,QueuedAfterReading) > 0)
/*  while(XEventsQueued (sm->grafix.display1,QueuedAlready) > 0) */
  {
#endif
  /*      x11_flush(); */
        XNextEvent(sm->grafix.display1,&event1);
        switch(event1.type)
        {
          case Expose:
	    if(event1.xexpose.window == sm->grafix.gamefg)
            {
              sm->bgdraw  = TRUE;
              sm->redraw  = TRUE;
            }
            else if(event1.xexpose.window == sm->grafix.statusfg)
            {
              sm->redraw   = TRUE;
              sm->statchg2 = sm->statchg1 = TRUE;
            }
            else if(event1.xexpose.window == sm->grafix.killfg)
            {
              sm->redraw  = TRUE;
              sm->killchg = TRUE;
            }
            break;
          case ButtonPress:
            switch (event1.xbutton.button)
            {
              case Button1:
                sm->ownstick |= JOY_LEFT;    /* Left */
                break;
              case Button2:
                sm->ownstick &= ~JOY_HIDE;
                if (event1.xbutton.state & (ShiftMask | ControlMask))
                  sm->ownstick |= JOY_DOWN;  /* Down */
                else
                  sm->ownstick |= JOY_UP;    /* Up */
                break;
              case Button3:
                sm->ownstick |= JOY_RIGHT;   /* Right */
                break;
             }
             break;
           case ButtonRelease:
             switch (event1.xbutton.button)
             {
               case Button1:
                 sm->ownstick &= ~JOY_LEFT;     /* Left */
                 break;
               case Button2:
                 if (event1.xbutton.state & (ShiftMask | ControlMask))
                   sm->ownstick &= ~JOY_DOWN; /* Down */
                 else
                   sm->ownstick &= ~JOY_UP; /* Up */
                 break;
               case Button3:
                 sm->ownstick &= ~JOY_RIGHT;     /* Right */
                 break;
             }
             break;
          case KeyPress:
            i = XLookupString( (XKeyEvent*) &event1,text,10,&key,0);
            switch(key)
            {
              case XK_Up:
                sm->ownstick |= JOY_UP;
                sm->ownstick &= ~JOY_HIDE;
                break;
              case XK_Down:
                sm->ownstick &= ~JOY_HIDE;
                sm->ownstick |= JOY_DOWN;
                break;
              case XK_Right:
                sm->ownstick |= JOY_RIGHT;
                break;
              case XK_Left:
                sm->ownstick |= JOY_LEFT;
                break;
              case XK_Shift_L:
              case XK_Shift_R:
              case XK_Control_L:
              case XK_Control_R:
                sm->ownstick |= JOY_SLOW;
                break ;
              case XK_Return:
                if (sm->ownstick & JOY_RADAR)
                  sm->ownstick &= ~JOY_RADAR;	/* RADAR */
                else
                  sm->ownstick |= JOY_RADAR;
                break;
              case 'c':
                if (sm->ownstick & JOY_HIDE)
                  sm->ownstick &= ~JOY_HIDE;	/* HIDE */
                else
                  sm->ownstick |= JOY_HIDE;
                break;
              case ' ':
                sm->ownstick &= ~JOY_HIDE;
                sm->ownstick |= JOY_BUTTON;
                break;
              case 'm':
                if(sm->newmap)
                  sm->newmap = FALSE;
                else
                  sm->newmap = TRUE;
              case 'l':
                if(sm->locator)
                  sm->locator = FALSE;
                else
                  sm->locator = TRUE;
              case '1':
                if((!sm->gameflag) && sm->sologame)
                {
                  run_game(&(sm->std_maze),sm->playfeld);
                  sm->gameflag = TRUE;
                }
                break;
              case 'p':
                if(TRUE)
                {
                  sm->shownumbertmp++;
                  if (sm->shownumbertmp == sm->anzplayers) sm->shownumbertmp = 0;
                  sm->statchg1 = TRUE; sm->killchg = TRUE;
                }
                break;
              case 'j':
                if(sm->sologame)
                {
                  sm->joynumber++;
                  if (sm->joynumber == sm->anzplayers) sm->joynumber = 0;
                }
                break;
              case 's':
                sm->debug = TRUE;
                break;
              case 'Q':
                sm->exitprg = 1;
                break;
            }
            break;
          case KeyRelease:
            i = XLookupString( (XKeyEvent*) &event1,text,10,&key,0);
            switch(key)
            {
              case XK_Up:
                sm->ownstick &= ~JOY_UP;
                break;
              case XK_Down:
                sm->ownstick &= ~JOY_DOWN;
                break;
              case XK_Right:
                sm->ownstick &= ~JOY_RIGHT;
                break;
              case XK_Left:
                sm->ownstick &= ~JOY_LEFT;
                break;
              case XK_Shift_L:
              case XK_Shift_R:
              case XK_Control_L:
              case XK_Control_R:
                sm->ownstick &= ~JOY_SLOW;
                break;
              case ' ':
                sm->ownstick &= ~JOY_BUTTON;
                break;
            }
            break;
          case ConfigureNotify:
	    if(event1.xconfigure.window == sm->grafix.gamefg)
            {
              if(event1.xconfigure.width != sm->grafix.shint.width)
                sm->bgdraw=TRUE;
              sm->grafix.shint.width = event1.xconfigure.width;
              if(event1.xconfigure.height != sm->grafix.shint.height)
                sm->bgdraw=TRUE;
              sm->grafix.shint.height = event1.xconfigure.height;
              if(sm->bgdraw)
                sm->redraw = TRUE;
            }
	    else if(event1.xconfigure.window == sm->grafix.statusfg)
            {
              sm->grafix.sthint.width = event1.xconfigure.width;
              sm->grafix.sthint.height = event1.xconfigure.height;
              sm->statchg1 = sm->statchg2 = TRUE;
            }
	    else if(event1.xconfigure.window == sm->grafix.killfg)
            {
              sm->killchg = TRUE;
            }
            break;
        }
  }
}