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
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
12 $(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
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
17 - * QEMU SDL display driver
19 - * Copyright (c) 2003 Fabrice Bellard
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:
28 - * The above copyright notice and this permission notice shall be included in
29 - * all copies or substantial portions of the Software.
30 + * Xlib interface for QEMU System Emulator
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
41 + * Copyright (c) 2004 Vladimit Oleynik <dzo@simtreas.ru>
42 + * Used ideas from Bochs, SDL, PCEmu.
46 +#include <X11/Xlib.h>
47 +#include <X11/Xutil.h>
48 +#include <X11/keysym.h>
53 +/* hack, special for qemu */
54 +#define X_display_init sdl_display_init
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,
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];
106 -static void sdl_update(DisplayState *ds, int x, int y, int w, int h)
107 +static Display *qx_display;
108 +static int q_x_screen_num;
111 +static XImage *ximage = NULL;
112 +static int default_depth;
113 +static Visual *default_visual;
114 +static int width, height;
116 +static void x_update(DisplayState *ds, int x, int y, int w, int h)
118 - // printf("updating x=%d y=%d w=%d h=%d\n", x, y, w, h);
119 - SDL_UpdateRect(screen, x, y, w, h);
120 + XPutImage(qx_display, win, gc, ximage, x, y, x, y, w, h);
121 + XFlush(qx_display);
124 -static void sdl_resize(DisplayState *ds, int w, int h)
125 +static int prev_x, prev_y;
126 +static int current_x, current_y;
128 +/* Move the cursor to a center window place */
129 +static void qXWarpPointer(void)
135 - // printf("resizing to %d %d\n", w, h);
136 + prev_x = current_x = x;
137 + prev_y = current_y = y;
138 + XWarpPointer(qx_display, None, win, 0, 0, 0, 0, x, y);
141 - flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
142 - if (gui_fullscreen)
143 - flags |= SDL_FULLSCREEN;
144 - screen = SDL_SetVideoMode(w, h, 0, flags);
146 - fprintf(stderr, "Could not open SDL display\n");
148 +static void x_resize(DisplayState *ds, int w, int h)
151 + long supplied_return;
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);
159 - ds->data = screen->pixels;
160 - ds->linesize = screen->pitch;
161 - ds->depth = screen->format->BitsPerPixel;
165 + XDestroyImage(ximage);
167 + XResizeWindow(qx_display, win, w, h);
169 + ximage = XCreateImage(qx_display, default_visual,
170 + default_depth, // depth of image (bitplanes)
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
178 + fprintf(stderr, "Could not XCreateImage()\n");
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) );
187 + fprintf(stderr, "Could not malloc Image data\n");
190 + ximage->data = ds->data;
192 + XFlush(qx_display);
195 -/* generic keyboard conversion */
196 +static int gui_grab;
198 -#include "sdl_keysym.h"
199 -#include "keymaps.c"
200 +static void x_SetCaption(void)
202 + char *title, *icon;
203 + XTextProperty titleprop, iconprop;
205 -static kbd_layout_t *kbd_layout = NULL;
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";
214 -static uint8_t sdl_keyevent_to_keycode_generic(const SDL_KeyboardEvent *ev)
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);
222 + XStringListToTextProperty(&title, 1, &titleprop);
223 + XSetWMName(qx_display, win, &titleprop);
224 + XFree(titleprop.value);
226 + XStringListToTextProperty(&icon, 1, &iconprop);
227 + XSetWMIconName(qx_display, win, &iconprop);
228 + XFree(iconprop.value);
229 + XSync(qx_display, /* no discard */ 0);
232 -/* specific keyboard conversions from scan codes */
233 +static void trigger_mouse_grab(void)
237 + /* disable cursor */
238 + static Cursor cursor;
239 + static int cursor_created;
242 +#define shape_width 16
243 +#define shape_height 16
244 +#define mask_width 16
245 +#define mask_height 16
247 -static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
249 - return ev->keysym.scancode;
251 + static unsigned int shape_bits[(16*16)/32];
252 + static unsigned int mask_bits[(16*16)/32];
255 + if (!cursor_created) {
256 + Pixmap shape, mask;
257 + XColor white, black;
258 + Colormap default_cmap;
260 -static const uint8_t x_keycode_to_pc_keycode[61] = {
261 - 0xc7, /* 97 Home */
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 */
284 - 0x70, /* 120 Hiragana_Katakana */
287 - 0x73, /* 123 backslash */
293 - 0x79, /* 129 Henkan */
295 - 0x7b, /* 131 Muhenkan */
297 - 0x7d, /* 133 Yen */
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 */
323 + default_cmap = DefaultColormap(qx_display, q_x_screen_num);
325 -static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
328 + shape = XCreatePixmapFromBitmapData(qx_display,
329 + RootWindow(qx_display,q_x_screen_num),
331 + shape_width, shape_height,
333 + mask = XCreatePixmapFromBitmapData(qx_display,
334 + RootWindow(qx_display,q_x_screen_num),
336 + mask_width, mask_height,
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;
344 + XDefineCursor(qx_display, win, cursor);
346 - keycode = ev->keysym.scancode;
347 + /* grab pointer and keyboard */
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];
360 +// if ( flags & FULLSCREEN ) {
361 +// /* Unbind the mouse from the fullscreen window */
362 +// XUngrabPointer(qx_display, CurrentTime);
364 + /* Try to grab the mouse */
366 + int result = XGrabPointer(qx_display, win, True, 0,
367 + GrabModeAsync, GrabModeAsync,
368 + win, None, CurrentTime);
369 + if (result == GrabSuccess)
372 + /* Now grab the keyboard */
373 + XGrabKeyboard(qx_display, win, True,
374 + GrabModeAsync, GrabModeAsync, CurrentTime);
376 + /* Raise the window if we grab the mouse */
377 +// if ( !(flags & FULLSCREEN) )
378 + XRaiseWindow(qx_display, win);
381 + /* enable cursor */
382 + XUndefineCursor(qx_display, win);
383 + /* ungrab pointer and keyboard */
384 + XUngrabPointer(qx_display, CurrentTime);
385 + XUngrabKeyboard(qx_display, CurrentTime);
391 +static unsigned mouse_button_state;
393 -static void reset_keys(void)
394 +static void send_keyboard_mouse_status(void)
397 - for(i = 0; i < 256; i++) {
398 - if (modifiers_state[i]) {
400 - kbd_put_keycode(0xe0);
401 - kbd_put_keycode(i | 0x80);
402 - modifiers_state[i] = 0;
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)) {
412 + prev_x = current_x;
413 + prev_y = current_y;
417 -static void sdl_process_key(SDL_KeyboardEvent *ev)
418 +static const unsigned char scan_table1[] =
422 +#ifdef KBUK /* double quotes, hash symbol */
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 */
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 */
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 */
456 - if (ev->keysym.sym == SDLK_PAUSE) {
457 - /* specific case */
459 - if (ev->type == SDL_KEYUP)
461 - kbd_put_keycode(0xe1);
462 - kbd_put_keycode(0x1d | v);
463 - kbd_put_keycode(0x45 | v);
469 - keycode = sdl_keyevent_to_keycode_generic(ev);
471 - keycode = sdl_keyevent_to_keycode(ev);
473 +#ifdef KBUK /* tilde */
482 - /* sent when leaving window: reset the modifiers state */
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;
494 - modifiers_state[keycode] = 1;
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);
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);
510 - kbd_put_keycode(keycode & 0x7f);
512 +static const struct {
514 + unsigned scan_code;
516 + { XK_BackSpace, 0x0e },
518 + { XK_Return, 0x1c },
519 + { XK_Escape, 0x01 },
520 + { XK_Delete, 0x53e0 },
522 -static void sdl_update_caption(void)
525 - strcpy(buf, "QEMU");
527 - strcat(buf, " [Stopped]");
530 - strcat(buf, " - Press Ctrl-Alt to exit grab");
532 - SDL_WM_SetCaption(buf, "QEMU");
534 + { XK_Home, 0x47e0 },
535 + { XK_Left, 0x4be0 },
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 },
545 -static void sdl_grab_start(void)
548 - SDL_WM_GrabInput(SDL_GRAB_ON);
549 - /* dummy read to avoid moving the mouse */
550 - SDL_GetRelativeMouseState(NULL, NULL);
552 - sdl_update_caption();
554 +/* This block of codes is for Sun Type 4 keyboards... */
556 -static void sdl_grab_end(void)
558 - SDL_WM_GrabInput(SDL_GRAB_OFF);
561 - sdl_update_caption();
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 */
568 -static void sdl_send_mouse_event(int dz)
570 - int dx, dy, state, buttons;
571 - state = SDL_GetRelativeMouseState(&dx, &dy);
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);
581 + { XK_F25, 0x36e0 }, /* Keypad divide/R5/F25 */
582 + { XK_F26, 0x37 }, /* Keypad multiply/R6/F26 */
584 -static void toggle_full_screen(DisplayState *ds)
586 - gui_fullscreen = !gui_fullscreen;
587 - sdl_resize(ds, screen->w, screen->h);
588 - if (gui_fullscreen) {
589 - gui_saved_grab = gui_grab;
592 - if (!gui_saved_grab)
595 - vga_invalidate_display();
596 - vga_update_display();
598 + { XK_F23, 0x46 }, /* Scroll lock/R3/F23 */
600 -static void sdl_refresh(DisplayState *ds)
601 + { XK_F31, 0x4c }, /* Keypad 5/R11/F31 */
603 +/* End of Sun type 4 codes */
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 },
624 + { XK_Help, 0x3b }, /* openwin mapped */
629 + { XK_F19, 0x3c }, /* openwin mapped */
630 + { XK_F20, 0x3d }, /* openwin mapped */
631 + { XK_F16, 0x3e }, /* openwin mapped */
632 + { XK_F18, 0x3f }, /* openwin mapped */
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 },
650 + { XK_Scroll_Lock, 0x46 },
651 + { XK_Caps_Lock, 0xba3a }
654 +static void x_refresh(DisplayState *ds)
656 - SDL_Event ev1, *ev = &ev1;
659 - if (last_vm_running != vm_running) {
660 - last_vm_running = vm_running;
661 - sdl_update_caption();
665 + int mouse_update = 0;
667 + XButtonEvent *button_event;
668 + XExposeEvent *expose_event;
670 + static int gui_key_modifier_pressed;
672 - if (is_active_console(vga_console))
673 - vga_update_display();
674 + if (last_vm_running != vm_running) {
675 + last_vm_running = vm_running;
679 - while (SDL_PollEvent(ev)) {
680 - switch (ev->type) {
681 - case SDL_VIDEOEXPOSE:
682 - sdl_update(ds, 0, 0, screen->w, screen->h);
686 - if (ev->type == SDL_KEYDOWN) {
687 - mod_state = (SDL_GetModState() & gui_grab_code) ==
689 - gui_key_modifier_pressed = mod_state;
690 - if (gui_key_modifier_pressed) {
692 - keycode = sdl_keyevent_to_keycode(&ev->key);
694 - case 0x21: /* 'f' key on US keyboard */
695 - toggle_full_screen(ds);
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();
704 - /* display grab if going to a text console */
713 - } else if (!is_active_console(vga_console)) {
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;
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;
743 - kbd_put_keysym(keysym);
744 - } else if (ev->key.keysym.unicode != 0) {
745 - kbd_put_keysym(ev->key.keysym.unicode);
748 - } else if (ev->type == SDL_KEYUP) {
749 - mod_state = (ev->key.keysym.mod & gui_grab_code);
751 - if (gui_key_modifier_pressed) {
752 - if (gui_keysym == 0) {
753 - /* exit/enter grab if pressing Ctrl-Alt */
758 - /* SDL does not send back all the
759 - modifiers key, so we must correct it */
763 - gui_key_modifier_pressed = 0;
768 - if (is_active_console(vga_console))
769 - sdl_process_key(&ev->key);
772 - qemu_system_shutdown_request();
774 - case SDL_MOUSEMOTION:
776 - sdl_send_mouse_event(0);
779 - case SDL_MOUSEBUTTONDOWN:
780 - case SDL_MOUSEBUTTONUP:
782 - SDL_MouseButtonEvent *bev = &ev->button;
784 - if (ev->type == SDL_MOUSEBUTTONDOWN &&
785 - (bev->state & SDL_BUTTON_LMASK)) {
786 - /* start grabbing all events */
792 -#ifdef SDL_BUTTON_WHEELUP
793 - if (bev->button == SDL_BUTTON_WHEELUP) {
795 - } else if (bev->button == SDL_BUTTON_WHEELDOWN) {
799 - sdl_send_mouse_event(dz);
803 - case SDL_ACTIVEEVENT:
804 - if (gui_grab && (ev->active.gain & SDL_ACTIVEEVENTMASK) == 0 &&
805 - !gui_fullscreen_initial_grab) {
812 + if (is_active_console(vga_console))
813 + vga_update_display();
815 + while (XPending(qx_display) > 0) {
816 + XNextEvent(qx_display, &report);
818 + switch (report.type) {
821 + expose_event = &report.xexpose;
822 + x_update(ds, expose_event->x, expose_event->y, expose_event->width, expose_event->height);
826 + button_event = (XButtonEvent *) &report;
827 + current_x = button_event->x;
828 + current_y = button_event->y;
829 + switch (button_event->button) {
832 + /* start grabbing all events */
833 + trigger_mouse_grab();
836 + mouse_button_state |= 0x01;
840 + mouse_button_state |= 0x04;
844 + mouse_button_state |= 0x02;
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) {
856 + mouse_button_state &= ~0x01;
860 + mouse_button_state &= ~0x04;
864 + mouse_button_state &= ~0x02;
872 + key = XLookupKeysym(&report.xkey, 0);
874 + if(key == XK_Shift_L) {
875 + if(report.type == KeyPress)
876 + gui_key_modifier_pressed |= 5;
878 + gui_key_modifier_pressed &= ~1;
879 + } else if(key == XK_Control_L) {
880 + if(report.type == KeyPress)
881 + gui_key_modifier_pressed |= 6;
883 + gui_key_modifier_pressed &= ~2;
885 + if((gui_key_modifier_pressed & 7) == 7) {
886 + trigger_mouse_grab();
887 + gui_key_modifier_pressed &= ~4;
891 + /* XK_F21 is for sun type 4 keyboards.. */
892 + if (key == XK_Break || key == XK_F21)
895 + if (key == XK_Pause) {
896 + if (report.xkey.state & ControlMask)
900 + } /* XK_F22 is sun type 4 PrtScr */
901 + else if (key == XK_Print || key == XK_F22) {
902 + if (report.xkey.state & Mod1Mask)
908 + else if ((key == XK_numbersign) && (report.xkey.state & ShiftMask))
911 + else if (key == XK_sterling)
914 + if (key >= 0x20 && key <= 0x20+sizeof(scan_table1))
915 + scan = scan_table1[key - 0x20];
918 + for (count = 0; count <
919 + (sizeof(scan_table2)/sizeof(scan_table2[0]));
921 + if (scan_table2[count].key == key) {
922 + scan = scan_table2[count].scan_code;
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));
934 + kbd_put_keycode(scan & 0xff);
941 + current_x = report.xmotion.x;
942 + current_y = report.xmotion.y;
950 + if (mouse_update && gui_grab) {
951 + send_keyboard_mouse_status();
957 -static void sdl_cleanup(void)
958 +void X_display_init(DisplayState *ds, int full_screen)
962 + Pixmap icon_pixmap;
963 + XSizeHints size_hints;
965 + XClassHint class_hints;
966 + XSetWindowAttributes attr;
967 + unsigned long valuemask = 0; /* ignore XGCvalues and use defaults */
969 + char *progname = "qemu";
972 -void sdl_display_init(DisplayState *ds, int full_screen)
975 + if ( (qx_display=XOpenDisplay(NULL)) == NULL ) {
976 + fprintf(stderr, "Could not open X display\n");
979 + /* get screen size from display structure macro */
980 + q_x_screen_num = DefaultScreen(qx_display);
982 -#if defined(__APPLE__)
983 - /* always use generic keymaps */
984 - if (!keyboard_layout)
985 - keyboard_layout = "en-us";
987 - if(keyboard_layout) {
988 - kbd_layout = init_keyboard_layout(keyboard_layout);
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 */
997 + 4, /* border_width four pixels */
998 + BlackPixel(qx_display, q_x_screen_num),
999 + BlackPixel(qx_display, q_x_screen_num));
1001 - flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE;
1002 - if (SDL_Init (flags)) {
1003 - fprintf(stderr, "Could not initialize SDL - exiting\n");
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);
1011 + default_depth = DefaultDepth(qx_display, q_x_screen_num);
1012 + default_visual = DefaultVisual(qx_display, q_x_screen_num);
1014 - ds->dpy_update = sdl_update;
1015 - ds->dpy_resize = sdl_resize;
1016 - ds->dpy_refresh = sdl_refresh;
1017 + icon_pixmap = XCreateBitmapFromData(qx_display, win, icon_bits,
1018 + icon_width, icon_height);
1020 - sdl_resize(ds, 640, 400);
1021 - sdl_update_caption();
1022 - SDL_EnableKeyRepeat(250, 50);
1023 - SDL_EnableUNICODE(1);
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;
1029 - atexit(sdl_cleanup);
1030 - if (full_screen) {
1031 - gui_fullscreen = 1;
1032 - gui_fullscreen_initial_grab = 1;
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;
1040 + class_hints.res_name = "qemu";
1041 + class_hints.res_class = "Qemu";
1043 + XSetWMProperties(qx_display, win,
1044 + NULL, NULL, // windowName iconName, set from x_SetCaption
1045 + &progname, 1, &size_hints, &wm_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);
1052 + XSelectInput(qx_display, win,
1053 + KeyPressMask | KeyReleaseMask |
1054 + ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
1055 + ExposureMask| StructureNotifyMask);
1057 + gc = XCreateGC(qx_display, win, valuemask, &values);
1059 + XSetForeground(qx_display, gc, WhitePixel(qx_display, q_x_screen_num));
1060 + XSetBackground(qx_display, gc, BlackPixel(qx_display, q_x_screen_num));
1062 + /* Display window */
1063 + XMapWindow(qx_display, win);
1064 + XSync(qx_display, /* no discard */ 0);
1067 + XNextEvent(qx_display, &report);
1068 + if (report.type == MapNotify) break;
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();