]>
Commit | Line | Data |
---|---|---|
a4a14ad6 | 1 | diff -Nur qemu-0.7.0.orig/Makefile.target qemu-0.7.0.chng/Makefile.target |
2 | --- qemu-0.7.0.orig/Makefile.target 2005-07-06 23:38:02.000000000 +0000 | |
3 | +++ qemu-0.7.0.chng/Makefile.target 2005-07-06 23:42:48.000000000 +0000 | |
4 | @@ -392,7 +392,7 @@ | |
5 | endif | |
6 | ||
7 | $(QEMU_SYSTEM): $(VL_OBJS) libqemu.a | |
8 | - $(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(VL_LIBS) | |
9 | + $(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(VL_LIBS) -L/usr/X11R6/lib -lX11 -lpthread | |
10 | ||
11 | cocoa.o: cocoa.m | |
12 | $(CC) $(CFLAGS) $(DEFINES) -c -o $@ $< | |
6a0ad43d KK |
13 | --- qemu-0.7.1/sdl.c.orig 2005-07-24 20:52:08.000000000 +0200 |
14 | +++ qemu-0.7.1/sdl.c 2005-08-23 01:47:48.000000000 +0200 | |
15 | @@ -1,506 +1,614 @@ | |
a4a14ad6 | 16 | /* |
17 | - * QEMU SDL display driver | |
18 | - * | |
19 | - * Copyright (c) 2003 Fabrice Bellard | |
20 | - * | |
21 | - * Permission is hereby granted, free of charge, to any person obtaining a copy | |
22 | - * of this software and associated documentation files (the "Software"), to deal | |
23 | - * in the Software without restriction, including without limitation the rights | |
24 | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
25 | - * copies of the Software, and to permit persons to whom the Software is | |
26 | - * furnished to do so, subject to the following conditions: | |
6a0ad43d | 27 | - * |
a4a14ad6 | 28 | - * The above copyright notice and this permission notice shall be included in |
29 | - * all copies or substantial portions of the Software. | |
6a0ad43d KK |
30 | + * Xlib interface for QEMU System Emulator |
31 | * | |
a4a14ad6 | 32 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
33 | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
34 | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
35 | - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
36 | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
37 | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
38 | - * THE SOFTWARE. | |
39 | - */ | |
40 | -#include "vl.h" | |
a4a14ad6 | 41 | + * Copyright (c) 2004 Vladimit Oleynik <dzo@simtreas.ru> |
42 | + * Used ideas from Bochs, SDL, PCEmu. | |
43 | +*/ | |
6a0ad43d KK |
44 | |
45 | -#include <SDL.h> | |
a4a14ad6 | 46 | +#include <X11/Xlib.h> |
47 | +#include <X11/Xutil.h> | |
48 | +#include <X11/keysym.h> | |
6a0ad43d KK |
49 | |
50 | -#ifndef _WIN32 | |
51 | -#include <signal.h> | |
52 | -#endif | |
a4a14ad6 | 53 | +/* hack, special for qemu */ |
54 | +#define X_display_init sdl_display_init | |
55 | + | |
56 | +#define icon_width 40 | |
57 | +#define icon_height 32 | |
58 | +static unsigned char icon_bits[] = { | |
59 | + 0x3e, 0x26, 0x00, 0x00, 0x00, | |
60 | + 0x24, 0x04, 0x01, 0x00, 0x00, | |
61 | + 0x04, 0x04, 0x01, 0x00, 0x00, | |
62 | + 0x14, 0xb7, 0xb3, 0x06, 0x00, | |
63 | + 0x9c, 0x24, 0x49, 0x05, 0x00, | |
64 | + 0x94, 0x24, 0x49, 0x01, 0x00, | |
65 | + 0x84, 0x24, 0x49, 0x01, 0x00, | |
66 | + 0xa4, 0x24, 0x49, 0x01, 0x00, | |
67 | + 0x3e, 0x27, 0x32, 0x03, 0x00, | |
68 | + 0x00, 0x00, 0x00, 0x00, 0x00, | |
69 | + 0x00, 0x00, 0x00, 0x00, 0x00, | |
70 | + 0x00, 0x00, 0x00, 0x00, 0x00, | |
71 | + 0x08, 0x00, 0x77, 0x00, 0x00, | |
72 | + 0x04, 0x00, 0x22, 0x00, 0x00, | |
73 | + 0x04, 0x00, 0x14, 0x00, 0x00, | |
74 | + 0xce, 0x1a, 0x14, 0x00, 0x00, | |
75 | + 0x24, 0x15, 0x08, 0x00, 0x00, | |
76 | + 0x24, 0x05, 0x14, 0x00, 0x00, | |
77 | + 0x24, 0x05, 0x14, 0x00, 0x00, | |
78 | + 0x24, 0x05, 0x22, 0x00, 0x00, | |
79 | + 0xcc, 0x0c, 0x07, 0x00, 0x00, | |
80 | + 0x00, 0x00, 0x00, 0x00, 0x00, | |
81 | + 0x00, 0x00, 0x00, 0x00, 0x00, | |
82 | + 0x00, 0x00, 0x00, 0x00, 0x00, | |
83 | + 0x04, 0x00, 0x01, 0x00, 0x00, | |
84 | + 0x04, 0x00, 0x01, 0x00, 0x00, | |
85 | + 0xce, 0xb6, 0xb3, 0xb6, 0x0d, | |
86 | + 0x24, 0x15, 0x49, 0x49, 0x09, | |
87 | + 0xe4, 0x09, 0x79, 0x49, 0x09, | |
88 | + 0x24, 0x08, 0x09, 0x49, 0x09, | |
89 | + 0x24, 0x15, 0x49, 0x49, 0x09, | |
90 | + 0xc8, 0x36, 0x32, 0x49, 0x0e, | |
91 | +}; | |
6a0ad43d | 92 | + |
a4a14ad6 | 93 | +#include "vl.h" |
94 | ||
95 | -static SDL_Surface *screen; | |
96 | -static int gui_grab; /* if true, all keyboard/mouse events are grabbed */ | |
97 | static int last_vm_running; | |
98 | -static int gui_saved_grab; | |
99 | -static int gui_fullscreen; | |
100 | -static int gui_key_modifier_pressed; | |
101 | -static int gui_keysym; | |
102 | -static int gui_fullscreen_initial_grab; | |
103 | -static int gui_grab_code = KMOD_LALT | KMOD_LCTRL; | |
104 | -static uint8_t modifiers_state[256]; | |
a4a14ad6 | 105 | |
6a0ad43d | 106 | -static void sdl_update(DisplayState *ds, int x, int y, int w, int h) |
a4a14ad6 | 107 | +static Display *qx_display; |
108 | +static int q_x_screen_num; | |
109 | +static Window win; | |
110 | +static GC gc; | |
111 | +static XImage *ximage = NULL; | |
112 | +static int default_depth; | |
113 | +static Visual *default_visual; | |
114 | +static int width, height; | |
115 | + | |
116 | +static void x_update(DisplayState *ds, int x, int y, int w, int h) | |
6a0ad43d KK |
117 | { |
118 | - // printf("updating x=%d y=%d w=%d h=%d\n", x, y, w, h); | |
119 | - SDL_UpdateRect(screen, x, y, w, h); | |
a4a14ad6 | 120 | + XPutImage(qx_display, win, gc, ximage, x, y, x, y, w, h); |
121 | + XFlush(qx_display); | |
6a0ad43d KK |
122 | } |
123 | ||
124 | -static void sdl_resize(DisplayState *ds, int w, int h) | |
a4a14ad6 | 125 | +static int prev_x, prev_y; |
126 | +static int current_x, current_y; | |
127 | + | |
128 | +/* Move the cursor to a center window place */ | |
129 | +static void qXWarpPointer(void) | |
6a0ad43d KK |
130 | { |
131 | - int flags; | |
a4a14ad6 | 132 | + int x = width/2; |
133 | + int y = height/2; | |
6a0ad43d KK |
134 | |
135 | - // printf("resizing to %d %d\n", w, h); | |
a4a14ad6 | 136 | + prev_x = current_x = x; |
137 | + prev_y = current_y = y; | |
138 | + XWarpPointer(qx_display, None, win, 0, 0, 0, 0, x, y); | |
139 | +} | |
6a0ad43d KK |
140 | |
141 | - flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL; | |
142 | - if (gui_fullscreen) | |
143 | - flags |= SDL_FULLSCREEN; | |
144 | - screen = SDL_SetVideoMode(w, h, 0, flags); | |
145 | - if (!screen) { | |
146 | - fprintf(stderr, "Could not open SDL display\n"); | |
147 | - exit(1); | |
a4a14ad6 | 148 | +static void x_resize(DisplayState *ds, int w, int h) |
149 | +{ | |
150 | + XSizeHints hints; | |
151 | + long supplied_return; | |
152 | + | |
153 | + if ( XGetWMNormalHints(qx_display, win, &hints, &supplied_return) && | |
154 | + supplied_return & PMaxSize ) { | |
155 | + hints.max_width = hints.min_width = w; | |
156 | + hints.max_height = hints.min_height = h; | |
157 | + XSetWMNormalHints(qx_display, win, &hints); | |
6a0ad43d KK |
158 | } |
159 | - ds->data = screen->pixels; | |
160 | - ds->linesize = screen->pitch; | |
161 | - ds->depth = screen->format->BitsPerPixel; | |
162 | - ds->width = w; | |
163 | - ds->height = h; | |
a4a14ad6 | 164 | + if(ximage) { |
165 | + XDestroyImage(ximage); | |
166 | +// free(ds->data); | |
167 | + XResizeWindow(qx_display, win, w, h); | |
168 | + } | |
169 | + ximage = XCreateImage(qx_display, default_visual, | |
170 | + default_depth, // depth of image (bitplanes) | |
171 | + ZPixmap, | |
172 | + 0, // offset | |
173 | + NULL, // malloc() space after | |
174 | + w, h, // x & y size of image | |
175 | + 32, // # bits of padding | |
176 | + 0 ); // bytes_per_line, let X11 calculate | |
177 | + if (!ximage) { | |
178 | + fprintf(stderr, "Could not XCreateImage()\n"); | |
179 | + exit(1); | |
180 | + } | |
181 | + width = ds->width = w; | |
182 | + height = ds->height = h; | |
183 | + ds->depth = ximage->bits_per_pixel; | |
184 | + ds->linesize = ximage->bytes_per_line; | |
185 | + ds->data = (char *) malloc( (size_t) (ximage->bytes_per_line * h) ); | |
186 | + if (!ds->data) { | |
187 | + fprintf(stderr, "Could not malloc Image data\n"); | |
188 | + exit(1); | |
189 | + } | |
190 | + ximage->data = ds->data; | |
191 | + qXWarpPointer(); | |
192 | + XFlush(qx_display); | |
6a0ad43d KK |
193 | } |
194 | ||
195 | -/* generic keyboard conversion */ | |
a4a14ad6 | 196 | +static int gui_grab; |
6a0ad43d KK |
197 | |
198 | -#include "sdl_keysym.h" | |
199 | -#include "keymaps.c" | |
a4a14ad6 | 200 | +static void x_SetCaption(void) |
201 | +{ | |
202 | + char *title, *icon; | |
203 | + XTextProperty titleprop, iconprop; | |
6a0ad43d KK |
204 | |
205 | -static kbd_layout_t *kbd_layout = NULL; | |
a4a14ad6 | 206 | + title = icon = "QEMU"; |
207 | + if (!vm_running && !gui_grab) | |
208 | + title = "QEMU [Stopped]"; | |
209 | + if (vm_running && gui_grab) | |
210 | + title = "QEMU - Press Ctrl-Shift to exit grab"; | |
211 | + if (!vm_running && gui_grab) | |
212 | + title = "QEMU [Stopped] - Press Ctrl-Shift to exit grab"; | |
6a0ad43d KK |
213 | |
214 | -static uint8_t sdl_keyevent_to_keycode_generic(const SDL_KeyboardEvent *ev) | |
215 | -{ | |
216 | - int keysym; | |
217 | - /* workaround for X11+SDL bug with AltGR */ | |
218 | - keysym = ev->keysym.sym; | |
219 | - if (keysym == 0 && ev->keysym.scancode == 113) | |
220 | - keysym = SDLK_MODE; | |
221 | - return keysym2scancode(kbd_layout, keysym); | |
a4a14ad6 | 222 | + XStringListToTextProperty(&title, 1, &titleprop); |
223 | + XSetWMName(qx_display, win, &titleprop); | |
224 | + XFree(titleprop.value); | |
225 | + | |
226 | + XStringListToTextProperty(&icon, 1, &iconprop); | |
227 | + XSetWMIconName(qx_display, win, &iconprop); | |
228 | + XFree(iconprop.value); | |
229 | + XSync(qx_display, /* no discard */ 0); | |
6a0ad43d KK |
230 | } |
231 | ||
232 | -/* specific keyboard conversions from scan codes */ | |
a4a14ad6 | 233 | +static void trigger_mouse_grab(void) |
234 | +{ | |
235 | + gui_grab ^= 1; | |
236 | + if (gui_grab) { | |
237 | + /* disable cursor */ | |
238 | + static Cursor cursor; | |
239 | + static int cursor_created; | |
6a0ad43d KK |
240 | |
241 | -#if defined(_WIN32) | |
a4a14ad6 | 242 | +#define shape_width 16 |
243 | +#define shape_height 16 | |
244 | +#define mask_width 16 | |
245 | +#define mask_height 16 | |
6a0ad43d KK |
246 | |
247 | -static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev) | |
248 | -{ | |
249 | - return ev->keysym.scancode; | |
250 | -} | |
a4a14ad6 | 251 | + static unsigned int shape_bits[(16*16)/32]; |
252 | + static unsigned int mask_bits[(16*16)/32]; | |
6a0ad43d KK |
253 | |
254 | -#else | |
a4a14ad6 | 255 | + if (!cursor_created) { |
256 | + Pixmap shape, mask; | |
257 | + XColor white, black; | |
258 | + Colormap default_cmap; | |
a4a14ad6 | 259 | |
a4a14ad6 | 260 | -static const uint8_t x_keycode_to_pc_keycode[61] = { |
261 | - 0xc7, /* 97 Home */ | |
262 | - 0xc8, /* 98 Up */ | |
263 | - 0xc9, /* 99 PgUp */ | |
264 | - 0xcb, /* 100 Left */ | |
265 | - 0x4c, /* 101 KP-5 */ | |
266 | - 0xcd, /* 102 Right */ | |
267 | - 0xcf, /* 103 End */ | |
268 | - 0xd0, /* 104 Down */ | |
269 | - 0xd1, /* 105 PgDn */ | |
270 | - 0xd2, /* 106 Ins */ | |
271 | - 0xd3, /* 107 Del */ | |
272 | - 0x9c, /* 108 Enter */ | |
273 | - 0x9d, /* 109 Ctrl-R */ | |
274 | - 0x0, /* 110 Pause */ | |
275 | - 0xb7, /* 111 Print */ | |
276 | - 0xb5, /* 112 Divide */ | |
277 | - 0xb8, /* 113 Alt-R */ | |
278 | - 0xc6, /* 114 Break */ | |
279 | - 0x0, /* 115 */ | |
280 | - 0x0, /* 116 */ | |
281 | - 0x0, /* 117 */ | |
282 | - 0x0, /* 118 */ | |
283 | - 0x0, /* 119 */ | |
284 | - 0x70, /* 120 Hiragana_Katakana */ | |
285 | - 0x0, /* 121 */ | |
286 | - 0x0, /* 122 */ | |
287 | - 0x73, /* 123 backslash */ | |
288 | - 0x0, /* 124 */ | |
289 | - 0x0, /* 125 */ | |
290 | - 0x0, /* 126 */ | |
291 | - 0x0, /* 127 */ | |
292 | - 0x0, /* 128 */ | |
293 | - 0x79, /* 129 Henkan */ | |
294 | - 0x0, /* 130 */ | |
295 | - 0x7b, /* 131 Muhenkan */ | |
296 | - 0x0, /* 132 */ | |
297 | - 0x7d, /* 133 Yen */ | |
298 | - 0x0, /* 134 */ | |
299 | - 0x0, /* 135 */ | |
300 | - 0x47, /* 136 KP_7 */ | |
301 | - 0x48, /* 137 KP_8 */ | |
302 | - 0x49, /* 138 KP_9 */ | |
303 | - 0x4b, /* 139 KP_4 */ | |
304 | - 0x4c, /* 140 KP_5 */ | |
305 | - 0x4d, /* 141 KP_6 */ | |
306 | - 0x4f, /* 142 KP_1 */ | |
307 | - 0x50, /* 143 KP_2 */ | |
308 | - 0x51, /* 144 KP_3 */ | |
309 | - 0x52, /* 145 KP_0 */ | |
310 | - 0x53, /* 146 KP_. */ | |
311 | - 0x47, /* 147 KP_HOME */ | |
312 | - 0x48, /* 148 KP_UP */ | |
313 | - 0x49, /* 149 KP_PgUp */ | |
314 | - 0x4b, /* 150 KP_Left */ | |
315 | - 0x4c, /* 151 KP_ */ | |
316 | - 0x4d, /* 152 KP_Right */ | |
317 | - 0x4f, /* 153 KP_End */ | |
318 | - 0x50, /* 154 KP_Down */ | |
319 | - 0x51, /* 155 KP_PgDn */ | |
320 | - 0x52, /* 156 KP_Ins */ | |
321 | - 0x53, /* 157 KP_Del */ | |
322 | -}; | |
6a0ad43d KK |
323 | + default_cmap = DefaultColormap(qx_display, q_x_screen_num); |
324 | ||
a4a14ad6 | 325 | -static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev) |
326 | -{ | |
327 | - int keycode; | |
6a0ad43d KK |
328 | + shape = XCreatePixmapFromBitmapData(qx_display, |
329 | + RootWindow(qx_display,q_x_screen_num), | |
330 | + (char*)shape_bits, | |
331 | + shape_width, shape_height, | |
332 | + 1, 0, 1); | |
333 | + mask = XCreatePixmapFromBitmapData(qx_display, | |
334 | + RootWindow(qx_display,q_x_screen_num), | |
335 | + (char*)mask_bits, | |
336 | + mask_width, mask_height, | |
337 | + 1, 0, 1); | |
338 | + XParseColor(qx_display, default_cmap, "black", &black); | |
339 | + XParseColor(qx_display, default_cmap, "white", &white); | |
340 | + cursor = XCreatePixmapCursor(qx_display, shape, mask, | |
341 | + &white, &black, 1, 1); | |
342 | + cursor_created = 1; | |
343 | + } | |
344 | + XDefineCursor(qx_display, win, cursor); | |
345 | ||
a4a14ad6 | 346 | - keycode = ev->keysym.scancode; |
6a0ad43d KK |
347 | + /* grab pointer and keyboard */ |
348 | ||
a4a14ad6 | 349 | - if (keycode < 9) { |
350 | - keycode = 0; | |
351 | - } else if (keycode < 97) { | |
352 | - keycode -= 8; /* just an offset */ | |
353 | - } else if (keycode < 158) { | |
354 | - /* use conversion table */ | |
355 | - keycode = x_keycode_to_pc_keycode[keycode - 97]; | |
356 | - } else { | |
357 | - keycode = 0; | |
358 | - } | |
359 | - return keycode; | |
6a0ad43d KK |
360 | +// if ( flags & FULLSCREEN ) { |
361 | +// /* Unbind the mouse from the fullscreen window */ | |
362 | +// XUngrabPointer(qx_display, CurrentTime); | |
363 | +// } | |
364 | + /* Try to grab the mouse */ | |
365 | + while ( 1 ) { | |
366 | + int result = XGrabPointer(qx_display, win, True, 0, | |
367 | + GrabModeAsync, GrabModeAsync, | |
368 | + win, None, CurrentTime); | |
369 | + if (result == GrabSuccess) | |
370 | + break; | |
371 | + } | |
372 | + /* Now grab the keyboard */ | |
373 | + XGrabKeyboard(qx_display, win, True, | |
374 | + GrabModeAsync, GrabModeAsync, CurrentTime); | |
375 | + | |
376 | + /* Raise the window if we grab the mouse */ | |
377 | +// if ( !(flags & FULLSCREEN) ) | |
378 | + XRaiseWindow(qx_display, win); | |
379 | + qXWarpPointer(); | |
380 | + } else { | |
381 | + /* enable cursor */ | |
382 | + XUndefineCursor(qx_display, win); | |
383 | + /* ungrab pointer and keyboard */ | |
384 | + XUngrabPointer(qx_display, CurrentTime); | |
385 | + XUngrabKeyboard(qx_display, CurrentTime); | |
386 | + } | |
387 | + x_SetCaption(); | |
388 | } | |
389 | ||
390 | -#endif | |
391 | +static unsigned mouse_button_state; | |
392 | ||
393 | -static void reset_keys(void) | |
394 | +static void send_keyboard_mouse_status(void) | |
395 | { | |
396 | - int i; | |
397 | - for(i = 0; i < 256; i++) { | |
398 | - if (modifiers_state[i]) { | |
399 | - if (i & 0x80) | |
400 | - kbd_put_keycode(0xe0); | |
401 | - kbd_put_keycode(i | 0x80); | |
402 | - modifiers_state[i] = 0; | |
403 | - } | |
404 | + int dx, dy; | |
405 | + | |
406 | + dx = current_x - prev_x; | |
407 | + dy = -(current_y - prev_y); | |
408 | + kbd_mouse_event(dx, -dy, 0, mouse_button_state); | |
409 | + if(current_x <= 1 || current_x >= (width-1) || current_y <= 1 || current_y >= (height-1)) { | |
410 | + qXWarpPointer(); | |
411 | + } else { | |
412 | + prev_x = current_x; | |
413 | + prev_y = current_y; | |
414 | } | |
415 | } | |
416 | ||
417 | -static void sdl_process_key(SDL_KeyboardEvent *ev) | |
418 | +static const unsigned char scan_table1[] = | |
419 | { | |
420 | - int keycode, v; | |
421 | + 0x39, 0x02, | |
422 | +#ifdef KBUK /* double quotes, hash symbol */ | |
423 | + 0x03, 0x2b, | |
424 | +#else | |
a4a14ad6 | 425 | + 0x28, 0x04, |
426 | +#endif | |
427 | + 0x05, 0x06, 0x08, 0x28, | |
428 | + 0x0a, 0x0b, 0x09, 0x0d, 0x33, 0x0c, 0x34, 0x35, | |
429 | + 0x0b, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, | |
430 | + 0x09, 0x0a, 0x27, 0x27, 0x33, 0x0d, 0x34, 0x35, | |
431 | +#ifdef KBUK /* at symbol */ | |
432 | + 0x28, | |
433 | +#else | |
434 | + 0x03, | |
435 | +#endif | |
436 | + 0x1e, 0x30, 0x2e, 0x20, 0x12, 0x21, 0x22, | |
437 | + 0x23, 0x17, 0x24, 0x25, 0x26, 0x32, 0x31, 0x18, | |
438 | + 0x19, 0x10, 0x13, 0x1f, 0x14, 0x16, 0x2f, 0x11, | |
439 | + 0x2d, 0x15, 0x2c, 0x1a, | |
440 | +#ifdef KBUK /* backslash */ | |
441 | + 0x56, | |
442 | +#else | |
443 | + 0x2b, | |
444 | +#endif | |
445 | + 0x1b, 0x07, 0x0c, | |
446 | + 0x29, 0x1e, 0x30, 0x2e, 0x20, 0x12, 0x21, 0x22, | |
447 | + 0x23, 0x17, 0x24, 0x25, 0x26, 0x32, 0x31, 0x18, | |
448 | + 0x19, 0x10, 0x13, 0x1f, 0x14, 0x16, 0x2f, 0x11, | |
449 | + 0x2d, 0x15, 0x2c, 0x1a, | |
450 | +#ifdef KBUK /* vertical bar */ | |
451 | + 0x56, | |
452 | +#else | |
453 | + 0x2b, | |
6a0ad43d | 454 | +#endif |
a4a14ad6 | 455 | |
a4a14ad6 | 456 | - if (ev->keysym.sym == SDLK_PAUSE) { |
457 | - /* specific case */ | |
458 | - v = 0; | |
459 | - if (ev->type == SDL_KEYUP) | |
460 | - v |= 0x80; | |
461 | - kbd_put_keycode(0xe1); | |
462 | - kbd_put_keycode(0x1d | v); | |
463 | - kbd_put_keycode(0x45 | v); | |
464 | - return; | |
465 | - } | |
6a0ad43d KK |
466 | + 0x1b, |
467 | ||
a4a14ad6 | 468 | - if (kbd_layout) { |
469 | - keycode = sdl_keyevent_to_keycode_generic(ev); | |
470 | - } else { | |
471 | - keycode = sdl_keyevent_to_keycode(ev); | |
472 | - } | |
6a0ad43d KK |
473 | +#ifdef KBUK /* tilde */ |
474 | + 0x2b, | |
475 | +#else | |
476 | + 0x29, | |
477 | +#endif | |
478 | +}; | |
479 | ||
a4a14ad6 | 480 | - switch(keycode) { |
481 | - case 0x00: | |
482 | - /* sent when leaving window: reset the modifiers state */ | |
483 | - reset_keys(); | |
484 | - return; | |
485 | - case 0x2a: /* Left Shift */ | |
486 | - case 0x36: /* Right Shift */ | |
487 | - case 0x1d: /* Left CTRL */ | |
488 | - case 0x9d: /* Right CTRL */ | |
489 | - case 0x38: /* Left ALT */ | |
490 | - case 0xb8: /* Right ALT */ | |
491 | - if (ev->type == SDL_KEYUP) | |
492 | - modifiers_state[keycode] = 0; | |
493 | - else | |
494 | - modifiers_state[keycode] = 1; | |
495 | - break; | |
496 | - case 0x45: /* num lock */ | |
497 | - case 0x3a: /* caps lock */ | |
498 | - /* SDL does not send the key up event, so we generate it */ | |
499 | - kbd_put_keycode(keycode); | |
500 | - kbd_put_keycode(keycode | 0x80); | |
501 | - return; | |
502 | - } | |
6a0ad43d | 503 | |
a4a14ad6 | 504 | - /* now send the key code */ |
505 | - if (keycode & 0x80) | |
506 | - kbd_put_keycode(0xe0); | |
507 | - if (ev->type == SDL_KEYUP) | |
508 | - kbd_put_keycode(keycode | 0x80); | |
509 | - else | |
510 | - kbd_put_keycode(keycode & 0x7f); | |
511 | -} | |
6a0ad43d KK |
512 | +static const struct { |
513 | + KeySym key; | |
514 | + unsigned scan_code; | |
515 | +} scan_table2[] = { | |
516 | + { XK_BackSpace, 0x0e }, | |
517 | + { XK_Tab, 0x0f }, | |
518 | + { XK_Return, 0x1c }, | |
519 | + { XK_Escape, 0x01 }, | |
520 | + { XK_Delete, 0x53e0 }, | |
521 | ||
a4a14ad6 | 522 | -static void sdl_update_caption(void) |
523 | -{ | |
524 | - char buf[1024]; | |
525 | - strcpy(buf, "QEMU"); | |
526 | - if (!vm_running) { | |
527 | - strcat(buf, " [Stopped]"); | |
528 | - } | |
529 | - if (gui_grab) { | |
530 | - strcat(buf, " - Press Ctrl-Alt to exit grab"); | |
531 | - } | |
532 | - SDL_WM_SetCaption(buf, "QEMU"); | |
533 | -} | |
6a0ad43d KK |
534 | + { XK_Home, 0x47e0 }, |
535 | + { XK_Left, 0x4be0 }, | |
536 | + { XK_Up, 0x48e0 }, | |
537 | + { XK_Right, 0x4de0 }, | |
538 | + { XK_Down, 0x50e0 }, | |
539 | + { XK_Prior, 0x49e0 }, | |
540 | + { XK_Next, 0x51e0 }, | |
541 | + { XK_End, 0x4fe0 }, | |
542 | + { XK_Insert, 0x52e0 }, | |
543 | + { XK_Num_Lock, 0x45 }, | |
544 | ||
a4a14ad6 | 545 | -static void sdl_grab_start(void) |
546 | -{ | |
547 | - SDL_ShowCursor(0); | |
548 | - SDL_WM_GrabInput(SDL_GRAB_ON); | |
549 | - /* dummy read to avoid moving the mouse */ | |
550 | - SDL_GetRelativeMouseState(NULL, NULL); | |
551 | - gui_grab = 1; | |
552 | - sdl_update_caption(); | |
553 | -} | |
6a0ad43d KK |
554 | +/* This block of codes is for Sun Type 4 keyboards... */ |
555 | ||
a4a14ad6 | 556 | -static void sdl_grab_end(void) |
557 | -{ | |
558 | - SDL_WM_GrabInput(SDL_GRAB_OFF); | |
559 | - SDL_ShowCursor(1); | |
560 | - gui_grab = 0; | |
561 | - sdl_update_caption(); | |
562 | -} | |
6a0ad43d KK |
563 | + { XK_F27, 0x47e0 }, /* Home/R7/F27 */ |
564 | + { XK_F29, 0x49e0 }, /* Prior/R9/F29 */ | |
565 | + { XK_F35, 0x51e0 }, /* Next/R15/F35 */ | |
566 | + { XK_F33, 0x4fe0 }, /* End/R13/F33 */ | |
567 | ||
a4a14ad6 | 568 | -static void sdl_send_mouse_event(int dz) |
569 | -{ | |
570 | - int dx, dy, state, buttons; | |
571 | - state = SDL_GetRelativeMouseState(&dx, &dy); | |
572 | - buttons = 0; | |
573 | - if (state & SDL_BUTTON(SDL_BUTTON_LEFT)) | |
574 | - buttons |= MOUSE_EVENT_LBUTTON; | |
575 | - if (state & SDL_BUTTON(SDL_BUTTON_RIGHT)) | |
576 | - buttons |= MOUSE_EVENT_RBUTTON; | |
577 | - if (state & SDL_BUTTON(SDL_BUTTON_MIDDLE)) | |
578 | - buttons |= MOUSE_EVENT_MBUTTON; | |
579 | - kbd_mouse_event(dx, dy, dz, buttons); | |
580 | -} | |
6a0ad43d KK |
581 | + { XK_F25, 0x36e0 }, /* Keypad divide/R5/F25 */ |
582 | + { XK_F26, 0x37 }, /* Keypad multiply/R6/F26 */ | |
583 | ||
a4a14ad6 | 584 | -static void toggle_full_screen(DisplayState *ds) |
585 | -{ | |
586 | - gui_fullscreen = !gui_fullscreen; | |
587 | - sdl_resize(ds, screen->w, screen->h); | |
588 | - if (gui_fullscreen) { | |
589 | - gui_saved_grab = gui_grab; | |
590 | - sdl_grab_start(); | |
591 | - } else { | |
592 | - if (!gui_saved_grab) | |
593 | - sdl_grab_end(); | |
594 | - } | |
595 | - vga_invalidate_display(); | |
596 | - vga_update_display(); | |
597 | -} | |
6a0ad43d | 598 | + { XK_F23, 0x46 }, /* Scroll lock/R3/F23 */ |
a4a14ad6 | 599 | |
600 | -static void sdl_refresh(DisplayState *ds) | |
6a0ad43d KK |
601 | + { XK_F31, 0x4c }, /* Keypad 5/R11/F31 */ |
602 | + | |
603 | +/* End of Sun type 4 codes */ | |
604 | + | |
605 | + { XK_KP_Enter, 0x1ce0 }, | |
606 | + { XK_KP_Multiply, 0x37 }, | |
607 | + { XK_KP_Add, 0x4e }, | |
608 | + { XK_KP_Subtract, 0x4a }, | |
609 | + { XK_KP_Divide, 0x36e0 }, | |
610 | + { XK_KP_Decimal, 0x53 }, | |
611 | + | |
612 | + { XK_KP_0, 0x52 }, | |
613 | + { XK_KP_1, 0x4f }, | |
614 | + { XK_KP_2, 0x50 }, | |
615 | + { XK_KP_3, 0x51 }, | |
616 | + { XK_KP_4, 0x4b }, | |
617 | + { XK_KP_5, 0x4c }, | |
618 | + { XK_KP_6, 0x4d }, | |
619 | + { XK_KP_7, 0x47 }, | |
620 | + { XK_KP_8, 0x48 }, | |
621 | + { XK_KP_9, 0x49 }, | |
622 | + | |
623 | + { XK_F1, 0x3b }, | |
624 | + { XK_Help, 0x3b }, /* openwin mapped */ | |
625 | + { XK_F2, 0x3c }, | |
626 | + { XK_F3, 0x3d }, | |
627 | + { XK_F4, 0x3e }, | |
628 | + { XK_F5, 0x3f }, | |
629 | + { XK_F19, 0x3c }, /* openwin mapped */ | |
630 | + { XK_F20, 0x3d }, /* openwin mapped */ | |
631 | + { XK_F16, 0x3e }, /* openwin mapped */ | |
632 | + { XK_F18, 0x3f }, /* openwin mapped */ | |
633 | + { XK_F6, 0x40 }, | |
634 | + { XK_F7, 0x41 }, | |
635 | + { XK_F8, 0x42 }, | |
636 | + { XK_F9, 0x43 }, | |
637 | + { XK_F10, 0x44 }, | |
638 | + { XK_F11, 0x57 }, | |
639 | + { XK_F12, 0x58 }, | |
640 | + | |
641 | + { XK_Shift_L, 0x2a }, | |
642 | + { XK_Shift_R, 0x36 }, | |
643 | + { XK_Control_L, 0x1d }, | |
644 | + { XK_Control_R, 0x1de0 }, | |
645 | + { XK_Meta_L, 0x38 }, | |
646 | + { XK_Alt_L, 0x38 }, | |
647 | + { XK_Meta_R, 0x38e0 }, | |
648 | + { XK_Alt_R, 0x38e0 }, | |
649 | + | |
650 | + { XK_Scroll_Lock, 0x46 }, | |
651 | + { XK_Caps_Lock, 0xba3a } | |
652 | +}; | |
653 | + | |
654 | +static void x_refresh(DisplayState *ds) | |
655 | { | |
a4a14ad6 | 656 | - SDL_Event ev1, *ev = &ev1; |
657 | - int mod_state; | |
658 | - | |
659 | - if (last_vm_running != vm_running) { | |
660 | - last_vm_running = vm_running; | |
661 | - sdl_update_caption(); | |
662 | - } | |
6a0ad43d KK |
663 | + XEvent report; |
664 | + KeySym key; | |
665 | + int mouse_update = 0; | |
666 | + unsigned scan; | |
667 | + XButtonEvent *button_event; | |
668 | + XExposeEvent *expose_event; | |
669 | + int count; | |
670 | + static int gui_key_modifier_pressed; | |
a4a14ad6 | 671 | |
672 | - if (is_active_console(vga_console)) | |
673 | - vga_update_display(); | |
6a0ad43d KK |
674 | + if (last_vm_running != vm_running) { |
675 | + last_vm_running = vm_running; | |
676 | + x_SetCaption(); | |
677 | + } | |
a4a14ad6 | 678 | |
679 | - while (SDL_PollEvent(ev)) { | |
680 | - switch (ev->type) { | |
681 | - case SDL_VIDEOEXPOSE: | |
682 | - sdl_update(ds, 0, 0, screen->w, screen->h); | |
683 | - break; | |
684 | - case SDL_KEYDOWN: | |
685 | - case SDL_KEYUP: | |
686 | - if (ev->type == SDL_KEYDOWN) { | |
687 | - mod_state = (SDL_GetModState() & gui_grab_code) == | |
688 | - gui_grab_code; | |
689 | - gui_key_modifier_pressed = mod_state; | |
690 | - if (gui_key_modifier_pressed) { | |
691 | - int keycode; | |
692 | - keycode = sdl_keyevent_to_keycode(&ev->key); | |
693 | - switch(keycode) { | |
694 | - case 0x21: /* 'f' key on US keyboard */ | |
695 | - toggle_full_screen(ds); | |
696 | - gui_keysym = 1; | |
697 | - break; | |
698 | - case 0x02 ... 0x0a: /* '1' to '9' keys */ | |
699 | - console_select(keycode - 0x02); | |
700 | - if (is_active_console(vga_console)) { | |
701 | - /* tell the vga console to redisplay itself */ | |
702 | - vga_invalidate_display(); | |
703 | - } else { | |
704 | - /* display grab if going to a text console */ | |
705 | - if (gui_grab) | |
706 | - sdl_grab_end(); | |
707 | - } | |
708 | - gui_keysym = 1; | |
709 | - break; | |
710 | - default: | |
711 | - break; | |
712 | - } | |
713 | - } else if (!is_active_console(vga_console)) { | |
714 | - int keysym; | |
715 | - keysym = 0; | |
716 | - if (ev->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) { | |
717 | - switch(ev->key.keysym.sym) { | |
718 | - case SDLK_UP: keysym = QEMU_KEY_CTRL_UP; break; | |
719 | - case SDLK_DOWN: keysym = QEMU_KEY_CTRL_DOWN; break; | |
720 | - case SDLK_LEFT: keysym = QEMU_KEY_CTRL_LEFT; break; | |
721 | - case SDLK_RIGHT: keysym = QEMU_KEY_CTRL_RIGHT; break; | |
722 | - case SDLK_HOME: keysym = QEMU_KEY_CTRL_HOME; break; | |
723 | - case SDLK_END: keysym = QEMU_KEY_CTRL_END; break; | |
724 | - case SDLK_PAGEUP: keysym = QEMU_KEY_CTRL_PAGEUP; break; | |
725 | - case SDLK_PAGEDOWN: keysym = QEMU_KEY_CTRL_PAGEDOWN; break; | |
726 | - default: break; | |
727 | - } | |
728 | - } else { | |
729 | - switch(ev->key.keysym.sym) { | |
730 | - case SDLK_UP: keysym = QEMU_KEY_UP; break; | |
731 | - case SDLK_DOWN: keysym = QEMU_KEY_DOWN; break; | |
732 | - case SDLK_LEFT: keysym = QEMU_KEY_LEFT; break; | |
733 | - case SDLK_RIGHT: keysym = QEMU_KEY_RIGHT; break; | |
734 | - case SDLK_HOME: keysym = QEMU_KEY_HOME; break; | |
735 | - case SDLK_END: keysym = QEMU_KEY_END; break; | |
736 | - case SDLK_PAGEUP: keysym = QEMU_KEY_PAGEUP; break; | |
737 | - case SDLK_PAGEDOWN: keysym = QEMU_KEY_PAGEDOWN; break; | |
738 | - case SDLK_BACKSPACE: keysym = QEMU_KEY_BACKSPACE; break; case SDLK_DELETE: keysym = QEMU_KEY_DELETE; break; | |
739 | - default: break; | |
740 | - } | |
741 | - } | |
742 | - if (keysym) { | |
743 | - kbd_put_keysym(keysym); | |
744 | - } else if (ev->key.keysym.unicode != 0) { | |
745 | - kbd_put_keysym(ev->key.keysym.unicode); | |
746 | - } | |
747 | - } | |
748 | - } else if (ev->type == SDL_KEYUP) { | |
749 | - mod_state = (ev->key.keysym.mod & gui_grab_code); | |
750 | - if (!mod_state) { | |
751 | - if (gui_key_modifier_pressed) { | |
752 | - if (gui_keysym == 0) { | |
753 | - /* exit/enter grab if pressing Ctrl-Alt */ | |
754 | - if (!gui_grab) | |
755 | - sdl_grab_start(); | |
756 | - else | |
757 | - sdl_grab_end(); | |
758 | - /* SDL does not send back all the | |
759 | - modifiers key, so we must correct it */ | |
760 | - reset_keys(); | |
761 | - break; | |
762 | - } | |
763 | - gui_key_modifier_pressed = 0; | |
764 | - gui_keysym = 0; | |
765 | - } | |
766 | - } | |
767 | - } | |
768 | - if (is_active_console(vga_console)) | |
769 | - sdl_process_key(&ev->key); | |
770 | - break; | |
771 | - case SDL_QUIT: | |
772 | - qemu_system_shutdown_request(); | |
773 | - break; | |
774 | - case SDL_MOUSEMOTION: | |
775 | - if (gui_grab) { | |
776 | - sdl_send_mouse_event(0); | |
777 | - } | |
778 | - break; | |
779 | - case SDL_MOUSEBUTTONDOWN: | |
780 | - case SDL_MOUSEBUTTONUP: | |
781 | - { | |
782 | - SDL_MouseButtonEvent *bev = &ev->button; | |
783 | - if (!gui_grab) { | |
784 | - if (ev->type == SDL_MOUSEBUTTONDOWN && | |
785 | - (bev->state & SDL_BUTTON_LMASK)) { | |
786 | - /* start grabbing all events */ | |
787 | - sdl_grab_start(); | |
788 | - } | |
789 | - } else { | |
790 | - int dz; | |
791 | - dz = 0; | |
792 | -#ifdef SDL_BUTTON_WHEELUP | |
793 | - if (bev->button == SDL_BUTTON_WHEELUP) { | |
794 | - dz = -1; | |
795 | - } else if (bev->button == SDL_BUTTON_WHEELDOWN) { | |
796 | - dz = 1; | |
797 | - } | |
798 | -#endif | |
799 | - sdl_send_mouse_event(dz); | |
800 | - } | |
801 | - } | |
802 | - break; | |
803 | - case SDL_ACTIVEEVENT: | |
804 | - if (gui_grab && (ev->active.gain & SDL_ACTIVEEVENTMASK) == 0 && | |
805 | - !gui_fullscreen_initial_grab) { | |
806 | - sdl_grab_end(); | |
807 | - } | |
808 | - break; | |
809 | - default: | |
810 | - break; | |
811 | - } | |
a4a14ad6 | 812 | + if (is_active_console(vga_console)) |
813 | + vga_update_display(); | |
814 | + | |
815 | + while (XPending(qx_display) > 0) { | |
816 | + XNextEvent(qx_display, &report); | |
817 | + | |
818 | + switch (report.type) { | |
819 | + | |
820 | + case Expose: | |
821 | + expose_event = &report.xexpose; | |
822 | + x_update(ds, expose_event->x, expose_event->y, expose_event->width, expose_event->height); | |
823 | + break; | |
824 | + | |
825 | + case ButtonPress: | |
826 | + button_event = (XButtonEvent *) &report; | |
827 | + current_x = button_event->x; | |
828 | + current_y = button_event->y; | |
829 | + switch (button_event->button) { | |
830 | + case Button1: | |
831 | + if(!gui_grab) { | |
832 | + /* start grabbing all events */ | |
833 | + trigger_mouse_grab(); | |
834 | + break; | |
835 | + } | |
836 | + mouse_button_state |= 0x01; | |
837 | + mouse_update = 1; | |
838 | + break; | |
839 | + case Button2: | |
840 | + mouse_button_state |= 0x04; | |
841 | + mouse_update = 1; | |
842 | + break; | |
843 | + case Button3: | |
844 | + mouse_button_state |= 0x02; | |
845 | + mouse_update = 1; | |
846 | + break; | |
847 | + } | |
848 | + break; | |
849 | + | |
850 | + case ButtonRelease: | |
851 | + button_event = (XButtonEvent *) &report; | |
852 | + current_x = button_event->x; | |
853 | + current_y = button_event->y; | |
854 | + switch (button_event->button) { | |
855 | + case Button1: | |
856 | + mouse_button_state &= ~0x01; | |
857 | + mouse_update = 1; | |
858 | + break; | |
859 | + case Button2: | |
860 | + mouse_button_state &= ~0x04; | |
861 | + mouse_update = 1; | |
862 | + break; | |
863 | + case Button3: | |
864 | + mouse_button_state &= ~0x02; | |
865 | + mouse_update = 1; | |
866 | + break; | |
867 | + } | |
868 | + break; | |
869 | + | |
870 | + case KeyPress: | |
871 | + case KeyRelease: | |
872 | + key = XLookupKeysym(&report.xkey, 0); | |
873 | + | |
874 | + if(key == XK_Shift_L) { | |
875 | + if(report.type == KeyPress) | |
876 | + gui_key_modifier_pressed |= 5; | |
877 | + else | |
878 | + gui_key_modifier_pressed &= ~1; | |
879 | + } else if(key == XK_Control_L) { | |
880 | + if(report.type == KeyPress) | |
881 | + gui_key_modifier_pressed |= 6; | |
882 | + else | |
883 | + gui_key_modifier_pressed &= ~2; | |
884 | + } | |
885 | + if((gui_key_modifier_pressed & 7) == 7) { | |
886 | + trigger_mouse_grab(); | |
887 | + gui_key_modifier_pressed &= ~4; | |
888 | + break; | |
889 | + } | |
890 | + | |
891 | + /* XK_F21 is for sun type 4 keyboards.. */ | |
892 | + if (key == XK_Break || key == XK_F21) | |
893 | + key = XK_Pause; | |
894 | + | |
895 | + if (key == XK_Pause) { | |
896 | + if (report.xkey.state & ControlMask) | |
897 | + scan = 0xc6e046e0; | |
898 | + else | |
899 | + scan = 0x451de1; | |
900 | + } /* XK_F22 is sun type 4 PrtScr */ | |
901 | + else if (key == XK_Print || key == XK_F22) { | |
902 | + if (report.xkey.state & Mod1Mask) | |
903 | + scan = 0x54; | |
904 | + else | |
905 | + scan = 0x37e02ae0; | |
906 | + } | |
907 | +#ifdef KBUK | |
908 | + else if ((key == XK_numbersign) && (report.xkey.state & ShiftMask)) | |
909 | + scan = 0x4; | |
6a0ad43d | 910 | +#endif |
a4a14ad6 | 911 | + else if (key == XK_sterling) |
912 | + scan = 0x4; | |
913 | + else { | |
914 | + if (key >= 0x20 && key <= 0x20+sizeof(scan_table1)) | |
915 | + scan = scan_table1[key - 0x20]; | |
916 | + else { | |
917 | + scan = 0; | |
918 | + for (count = 0; count < | |
919 | + (sizeof(scan_table2)/sizeof(scan_table2[0])); | |
920 | + count++) | |
921 | + if (scan_table2[count].key == key) { | |
922 | + scan = scan_table2[count].scan_code; | |
923 | + break; | |
924 | + } | |
925 | + } | |
926 | + if (scan == 0) | |
927 | + break; | |
928 | + } | |
929 | + if (is_active_console(vga_console)) | |
930 | + for (count = 0; scan; count++) { | |
931 | + if (key != XK_Caps_Lock && report.type == KeyRelease) | |
932 | + kbd_put_keycode(0x80 | (scan & 0xff)); | |
933 | + else | |
934 | + kbd_put_keycode(scan & 0xff); | |
935 | + | |
936 | + scan >>= 8; | |
937 | + } | |
938 | + break; | |
939 | + | |
940 | + case MotionNotify: | |
941 | + current_x = report.xmotion.x; | |
942 | + current_y = report.xmotion.y; | |
943 | + mouse_update = 1; | |
944 | + break; | |
945 | + | |
946 | + default: | |
947 | + break; | |
948 | + } /* end switch */ | |
949 | + | |
950 | + if (mouse_update && gui_grab) { | |
951 | + send_keyboard_mouse_status(); | |
952 | + mouse_update = 0; | |
6a0ad43d | 953 | } |
a4a14ad6 | 954 | + } /* end while */ |
6a0ad43d KK |
955 | } |
956 | ||
957 | -static void sdl_cleanup(void) | |
a4a14ad6 | 958 | +void X_display_init(DisplayState *ds, int full_screen) |
6a0ad43d KK |
959 | { |
960 | - SDL_Quit(); | |
961 | -} | |
a4a14ad6 | 962 | + Pixmap icon_pixmap; |
963 | + XSizeHints size_hints; | |
964 | + XWMHints wm_hints; | |
965 | + XClassHint class_hints; | |
966 | + XSetWindowAttributes attr; | |
967 | + unsigned long valuemask = 0; /* ignore XGCvalues and use defaults */ | |
968 | + XGCValues values; | |
969 | + char *progname = "qemu"; | |
970 | + XEvent report; | |
6a0ad43d KK |
971 | |
972 | -void sdl_display_init(DisplayState *ds, int full_screen) | |
973 | -{ | |
974 | - int flags; | |
a4a14ad6 | 975 | + if ( (qx_display=XOpenDisplay(NULL)) == NULL ) { |
976 | + fprintf(stderr, "Could not open X display\n"); | |
977 | + exit(1); | |
978 | + } | |
979 | + /* get screen size from display structure macro */ | |
980 | + q_x_screen_num = DefaultScreen(qx_display); | |
6a0ad43d KK |
981 | |
982 | -#if defined(__APPLE__) | |
983 | - /* always use generic keymaps */ | |
984 | - if (!keyboard_layout) | |
985 | - keyboard_layout = "en-us"; | |
986 | -#endif | |
987 | - if(keyboard_layout) { | |
988 | - kbd_layout = init_keyboard_layout(keyboard_layout); | |
989 | - if (!kbd_layout) | |
990 | - exit(1); | |
991 | - } | |
a4a14ad6 | 992 | + /* create opaque window */ |
993 | + win = XCreateSimpleWindow(qx_display, RootWindow(qx_display, q_x_screen_num), | |
994 | + 0, 0, /* x y would be settable from the command line or resource database. */ | |
995 | + 720, /* initial vga 80*25 9x16 */ | |
996 | + 400, | |
997 | + 4, /* border_width four pixels */ | |
998 | + BlackPixel(qx_display, q_x_screen_num), | |
999 | + BlackPixel(qx_display, q_x_screen_num)); | |
6a0ad43d KK |
1000 | |
1001 | - flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE; | |
1002 | - if (SDL_Init (flags)) { | |
1003 | - fprintf(stderr, "Could not initialize SDL - exiting\n"); | |
1004 | - exit(1); | |
1005 | - } | |
1006 | -#ifndef _WIN32 | |
1007 | - /* NOTE: we still want Ctrl-C to work, so we undo the SDL redirections */ | |
1008 | - signal(SIGINT, SIG_DFL); | |
1009 | - signal(SIGQUIT, SIG_DFL); | |
1010 | -#endif | |
a4a14ad6 | 1011 | + default_depth = DefaultDepth(qx_display, q_x_screen_num); |
1012 | + default_visual = DefaultVisual(qx_display, q_x_screen_num); | |
6a0ad43d KK |
1013 | |
1014 | - ds->dpy_update = sdl_update; | |
1015 | - ds->dpy_resize = sdl_resize; | |
1016 | - ds->dpy_refresh = sdl_refresh; | |
a4a14ad6 | 1017 | + icon_pixmap = XCreateBitmapFromData(qx_display, win, icon_bits, |
1018 | + icon_width, icon_height); | |
6a0ad43d KK |
1019 | |
1020 | - sdl_resize(ds, 640, 400); | |
1021 | - sdl_update_caption(); | |
1022 | - SDL_EnableKeyRepeat(250, 50); | |
1023 | - SDL_EnableUNICODE(1); | |
1024 | - gui_grab = 0; | |
a4a14ad6 | 1025 | + size_hints.flags = PSize | PMinSize | PMaxSize; |
1026 | + size_hints.max_width = size_hints.min_width = 720; | |
1027 | + size_hints.max_height = size_hints.min_height = 400; | |
6a0ad43d KK |
1028 | |
1029 | - atexit(sdl_cleanup); | |
1030 | - if (full_screen) { | |
1031 | - gui_fullscreen = 1; | |
1032 | - gui_fullscreen_initial_grab = 1; | |
1033 | - sdl_grab_start(); | |
1034 | - } | |
a4a14ad6 | 1035 | + wm_hints.initial_state = NormalState; |
1036 | + wm_hints.input = True; | |
1037 | + wm_hints.icon_pixmap = icon_pixmap; | |
1038 | + wm_hints.flags = StateHint | IconPixmapHint | InputHint; | |
1039 | + | |
1040 | + class_hints.res_name = "qemu"; | |
1041 | + class_hints.res_class = "Qemu"; | |
1042 | + | |
1043 | + XSetWMProperties(qx_display, win, | |
1044 | + NULL, NULL, // windowName iconName, set from x_SetCaption | |
1045 | + &progname, 1, &size_hints, &wm_hints, | |
1046 | + &class_hints); | |
1047 | + // (attempt to) enable backing store | |
1048 | + attr.save_under=1; | |
1049 | + attr.backing_store=Always; | |
1050 | + XChangeWindowAttributes(qx_display, win, CWSaveUnder|CWBackingStore, &attr); | |
1051 | + | |
1052 | + XSelectInput(qx_display, win, | |
1053 | + KeyPressMask | KeyReleaseMask | | |
1054 | + ButtonPressMask | ButtonReleaseMask | PointerMotionMask | | |
1055 | + ExposureMask| StructureNotifyMask); | |
1056 | + | |
1057 | + gc = XCreateGC(qx_display, win, valuemask, &values); | |
1058 | + | |
1059 | + XSetForeground(qx_display, gc, WhitePixel(qx_display, q_x_screen_num)); | |
1060 | + XSetBackground(qx_display, gc, BlackPixel(qx_display, q_x_screen_num)); | |
1061 | + | |
1062 | + /* Display window */ | |
1063 | + XMapWindow(qx_display, win); | |
1064 | + XSync(qx_display, /* no discard */ 0); | |
1065 | + | |
1066 | + while (1) { | |
1067 | + XNextEvent(qx_display, &report); | |
1068 | + if (report.type == MapNotify) break; | |
1069 | + } | |
1070 | + ds->dpy_update = x_update; | |
1071 | + ds->dpy_resize = x_resize; | |
1072 | + ds->dpy_refresh = x_refresh; | |
1073 | + x_resize(ds, 720, 400); | |
1074 | +// trigger_mouse_grab(); | |
1075 | } |