1 | #ifndef GLX_DISPLAY_H |
---|
2 | #define GLX_DISPLAY_H |
---|
3 | |
---|
4 | /* #define GLX_DISPLAY_SINGLESTATE */ |
---|
5 | |
---|
6 | #include <GL/glx.h> |
---|
7 | #include <X11/keysym.h> |
---|
8 | #include <X11/extensions/shape.h> |
---|
9 | |
---|
10 | #include "keycodes.h" |
---|
11 | |
---|
12 | /* |
---|
13 | typedef enum |
---|
14 | { |
---|
15 | K_BACKSPACE = 8, |
---|
16 | K_TAB = 9, |
---|
17 | K_ENTER = 13, |
---|
18 | K_ESCAPE = 27, |
---|
19 | |
---|
20 | K_SPACE = 32, |
---|
21 | K_EXCLAM, |
---|
22 | K_DOUBLE_QUOTE, |
---|
23 | K_NUMBER_SIGNE, |
---|
24 | K_DOLLAR, |
---|
25 | K_PERCENT, |
---|
26 | K_AMPERSAND, |
---|
27 | K_APOSTROPHE, |
---|
28 | K_LEFT_PAREN, |
---|
29 | K_RIGHT_PAREN, |
---|
30 | K_ASTERISK, |
---|
31 | K_PLUS, |
---|
32 | K_COMMA, |
---|
33 | K_MINUS, |
---|
34 | K_PERIOD, |
---|
35 | K_SLASH, |
---|
36 | K_0, |
---|
37 | K_1, |
---|
38 | K_2, |
---|
39 | K_3, |
---|
40 | K_4, |
---|
41 | K_5, |
---|
42 | K_6, |
---|
43 | K_7, |
---|
44 | K_8, |
---|
45 | K_9, |
---|
46 | K_COLON, |
---|
47 | K_SEMICOLON, |
---|
48 | K_LESS, |
---|
49 | K_EQUAL, |
---|
50 | K_GREATER, |
---|
51 | K_QUESTION, |
---|
52 | K_AT, |
---|
53 | K_A, |
---|
54 | K_B, |
---|
55 | K_C, |
---|
56 | K_D, |
---|
57 | K_E, |
---|
58 | K_F, |
---|
59 | K_G, |
---|
60 | K_H, |
---|
61 | K_I, |
---|
62 | K_J, |
---|
63 | K_K, |
---|
64 | K_L, |
---|
65 | K_M, |
---|
66 | K_N, |
---|
67 | K_O, |
---|
68 | K_P, |
---|
69 | K_Q, |
---|
70 | K_R, |
---|
71 | K_S, |
---|
72 | K_T, |
---|
73 | K_U, |
---|
74 | K_V, |
---|
75 | K_W, |
---|
76 | K_X, |
---|
77 | K_Y, |
---|
78 | K_Z, |
---|
79 | K_LEFT_BRACKET, |
---|
80 | K_BACKSLASH, |
---|
81 | K_RIGHT_BRACKET, |
---|
82 | K_ASCII_CIRCUM, |
---|
83 | K_UNDERSCORE, |
---|
84 | K_GRAVE, |
---|
85 | K_a, |
---|
86 | K_b, |
---|
87 | K_c, |
---|
88 | K_d, |
---|
89 | K_e, |
---|
90 | K_f, |
---|
91 | K_g, |
---|
92 | K_h, |
---|
93 | K_i, |
---|
94 | K_j, |
---|
95 | K_k, |
---|
96 | K_l, |
---|
97 | K_m, |
---|
98 | K_n, |
---|
99 | K_o, |
---|
100 | K_p, |
---|
101 | K_q, |
---|
102 | K_r, |
---|
103 | K_s, |
---|
104 | K_t, |
---|
105 | K_u, |
---|
106 | K_v, |
---|
107 | K_w, |
---|
108 | K_x, |
---|
109 | K_y, |
---|
110 | K_z, |
---|
111 | K_LEFT_BRACE, |
---|
112 | K_BAR, |
---|
113 | K_RIGHT_BRACE, |
---|
114 | K_ASCII_TILDE, |
---|
115 | |
---|
116 | K_COMMAND = 128, |
---|
117 | K_CAPSLOCK, |
---|
118 | K_POWER, |
---|
119 | K_PAUSE, |
---|
120 | |
---|
121 | K_UP_ARROW, |
---|
122 | K_DOWN_ARROW, |
---|
123 | K_LEFT_ARROW, |
---|
124 | K_RIGHT_ARROW, |
---|
125 | |
---|
126 | K_LEFT_ALT, |
---|
127 | K_RIGHT_ALT, |
---|
128 | K_LEFT_CONTROL, |
---|
129 | K_RIGHT_CONTROL, |
---|
130 | K_LEFT_SHIFT, |
---|
131 | K_RIGHT_SHIFT, |
---|
132 | K_INSERT, |
---|
133 | K_DELETE, |
---|
134 | K_PAGE_DOWN, |
---|
135 | K_PAGE_UP, |
---|
136 | K_HOME, |
---|
137 | K_END, |
---|
138 | |
---|
139 | K_F1, |
---|
140 | K_F2, |
---|
141 | K_F3, |
---|
142 | K_F4, |
---|
143 | K_F5, |
---|
144 | K_F6, |
---|
145 | K_F7, |
---|
146 | K_F8, |
---|
147 | K_F9, |
---|
148 | K_F10, |
---|
149 | K_F11, |
---|
150 | K_F12, |
---|
151 | K_F13, |
---|
152 | K_F14, |
---|
153 | K_F15, |
---|
154 | |
---|
155 | K_KP_HOME, |
---|
156 | K_KP_UP_ARROW, |
---|
157 | K_KP_PAGE_UP, |
---|
158 | K_KP_LEFT_ARROW, |
---|
159 | K_KP_5, |
---|
160 | K_KP_RIGHT_ARROW, |
---|
161 | K_KP_END, |
---|
162 | K_KP_DOWN_ARROW, |
---|
163 | K_KP_PAGE_DOWN, |
---|
164 | K_KP_ENTER, |
---|
165 | K_KP_INSERT, |
---|
166 | K_KP_DELETE, |
---|
167 | K_KP_SLASH, |
---|
168 | K_KP_MINUS, |
---|
169 | K_KP_PLUS, |
---|
170 | K_KP_NUMLOCK, |
---|
171 | K_KP_STAR, |
---|
172 | K_KP_EQUALS, |
---|
173 | |
---|
174 | K_MOUSE1, |
---|
175 | K_MOUSE2, |
---|
176 | K_MOUSE3, |
---|
177 | K_MOUSE4, |
---|
178 | K_MOUSE5, |
---|
179 | |
---|
180 | K_WHEEL_DOWN, |
---|
181 | K_WHEEL_UP, |
---|
182 | |
---|
183 | K_LAST_KEY |
---|
184 | } keycode_t; |
---|
185 | */ |
---|
186 | |
---|
187 | /* TODO change some ints into chars. */ |
---|
188 | |
---|
189 | typedef struct gl_window_s |
---|
190 | { |
---|
191 | Display * display; |
---|
192 | Window window; |
---|
193 | int screen; |
---|
194 | GLXWindow glx_window; |
---|
195 | GLXContext glx_context; |
---|
196 | XSetWindowAttributes attributes; |
---|
197 | int fullscreen_flag; |
---|
198 | int double_buffered_flag; |
---|
199 | int mouse_flag; /* used? */ |
---|
200 | int cycling_cursor_flag; |
---|
201 | int center_cursor_flag; |
---|
202 | int autorepeat_flag; |
---|
203 | /* XF86VidModeModeInfo original_mode; *//* i.e. desktop mode */ |
---|
204 | int x; |
---|
205 | int y; |
---|
206 | |
---|
207 | /*unsigned*/ int width; |
---|
208 | /*unsigned*/ int height; |
---|
209 | unsigned int depth; |
---|
210 | unsigned int screen_width; |
---|
211 | unsigned int screen_height; |
---|
212 | |
---|
213 | XEvent e; |
---|
214 | int pending; |
---|
215 | /* Variables to hold deltas in x and y coordinates. |
---|
216 | * They complement a XMotionEvent structure to support |
---|
217 | * relative cursor movements, not only absolute cursor |
---|
218 | * position. |
---|
219 | */ |
---|
220 | int last_x; |
---|
221 | int last_y; |
---|
222 | int motion_dx; |
---|
223 | int motion_dy; |
---|
224 | } gl_window_t; |
---|
225 | |
---|
226 | #ifdef GLX_DISPLAY_SINGLESTATE |
---|
227 | unsigned int get_width(); |
---|
228 | unsigned int get_height(); |
---|
229 | unsigned int get_screen_width(); |
---|
230 | unsigned int get_screen_height(); |
---|
231 | #else |
---|
232 | unsigned int get_width( gl_window_t * gl_window ); |
---|
233 | unsigned int get_height( gl_window_t * gl_window ); |
---|
234 | unsigned int get_screen_width( gl_window_t * gl_window ); |
---|
235 | unsigned int get_screen_height( gl_window_t * gl_window ); |
---|
236 | #endif |
---|
237 | |
---|
238 | void |
---|
239 | enable_autorepeat ( |
---|
240 | #ifndef GLX_DISPLAY_SINGLESTATE |
---|
241 | gl_window_t * gl_window |
---|
242 | #endif |
---|
243 | ); |
---|
244 | |
---|
245 | void |
---|
246 | disable_autorepeat ( |
---|
247 | #ifndef GLX_DISPLAY_SINGLESTATE |
---|
248 | gl_window_t * gl_window |
---|
249 | #endif |
---|
250 | ); |
---|
251 | |
---|
252 | void destroy_gl_window ( |
---|
253 | #ifndef GLX_DISPLAY_SINGLESTATE |
---|
254 | gl_window_t * gl_window |
---|
255 | #endif |
---|
256 | ); |
---|
257 | |
---|
258 | #ifndef GLX_DISPLAY_SINGLESTATE |
---|
259 | gl_window_t * |
---|
260 | #else |
---|
261 | void |
---|
262 | #endif |
---|
263 | create_gl_window ( |
---|
264 | /* const char * title, */ |
---|
265 | unsigned int width, |
---|
266 | unsigned int height, |
---|
267 | int double_buffered, |
---|
268 | int fullscreen, |
---|
269 | int no_border, |
---|
270 | int use_shape_extension); |
---|
271 | |
---|
272 | void swap_buffers ( |
---|
273 | #ifndef GLX_DISPLAY_SINGLESTATE |
---|
274 | gl_window_t * gl_window |
---|
275 | #endif |
---|
276 | ); |
---|
277 | |
---|
278 | int event_type( XEvent * e ); |
---|
279 | int event_x( XButtonEvent * e ); |
---|
280 | int event_y( XButtonEvent * e ); |
---|
281 | int event_button( XButtonEvent * e ); |
---|
282 | int event_xkeycode( XEvent * e ); |
---|
283 | |
---|
284 | XEvent * |
---|
285 | receive_event ( |
---|
286 | #ifndef GLX_DISPLAY_SINGLESTATE |
---|
287 | gl_window_t * gl_window |
---|
288 | #endif |
---|
289 | ); |
---|
290 | |
---|
291 | int time_milliseconds( void ); |
---|
292 | |
---|
293 | unsigned int event_keycode( XKeyEvent * e ); |
---|
294 | |
---|
295 | #endif /* GLX_DISPLAY_H */ |
---|
296 | |
---|