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 diff -Nur qemu-0.7.0.orig/sdl.c qemu-0.7.0.chng/sdl.c
14 --- qemu-0.7.0.orig/sdl.c 2005-04-27 20:52:05.000000000 +0000
15 +++ qemu-0.7.0.chng/sdl.c 2005-07-06 22:28:55.000000000 +0000
18 - * QEMU SDL display driver
20 - * Copyright (c) 2003 Fabrice Bellard
22 - * Permission is hereby granted, free of charge, to any person obtaining a copy
23 - * of this software and associated documentation files (the "Software"), to deal
24 - * in the Software without restriction, including without limitation the rights
25 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26 - * copies of the Software, and to permit persons to whom the Software is
27 - * furnished to do so, subject to the following conditions:
28 + * Xlib interface for QEMU System Emulator
30 - * The above copyright notice and this permission notice shall be included in
31 - * all copies or substantial portions of the Software.
33 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
36 - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
44 + * Copyright (c) 2004 Vladimit Oleynik <dzo@simtreas.ru>
45 + * Used ideas from Bochs, SDL, PCEmu.
48 +#include <X11/Xlib.h>
49 +#include <X11/Xutil.h>
50 +#include <X11/keysym.h>
52 +/* hack, special for qemu */
53 +#define X_display_init sdl_display_init
55 +#define icon_width 40
56 +#define icon_height 32
57 +static unsigned char icon_bits[] = {
58 + 0x3e, 0x26, 0x00, 0x00, 0x00,
59 + 0x24, 0x04, 0x01, 0x00, 0x00,
60 + 0x04, 0x04, 0x01, 0x00, 0x00,
61 + 0x14, 0xb7, 0xb3, 0x06, 0x00,
62 + 0x9c, 0x24, 0x49, 0x05, 0x00,
63 + 0x94, 0x24, 0x49, 0x01, 0x00,
64 + 0x84, 0x24, 0x49, 0x01, 0x00,
65 + 0xa4, 0x24, 0x49, 0x01, 0x00,
66 + 0x3e, 0x27, 0x32, 0x03, 0x00,
67 + 0x00, 0x00, 0x00, 0x00, 0x00,
68 + 0x00, 0x00, 0x00, 0x00, 0x00,
69 + 0x00, 0x00, 0x00, 0x00, 0x00,
70 + 0x08, 0x00, 0x77, 0x00, 0x00,
71 + 0x04, 0x00, 0x22, 0x00, 0x00,
72 + 0x04, 0x00, 0x14, 0x00, 0x00,
73 + 0xce, 0x1a, 0x14, 0x00, 0x00,
74 + 0x24, 0x15, 0x08, 0x00, 0x00,
75 + 0x24, 0x05, 0x14, 0x00, 0x00,
76 + 0x24, 0x05, 0x14, 0x00, 0x00,
77 + 0x24, 0x05, 0x22, 0x00, 0x00,
78 + 0xcc, 0x0c, 0x07, 0x00, 0x00,
79 + 0x00, 0x00, 0x00, 0x00, 0x00,
80 + 0x00, 0x00, 0x00, 0x00, 0x00,
81 + 0x00, 0x00, 0x00, 0x00, 0x00,
82 + 0x04, 0x00, 0x01, 0x00, 0x00,
83 + 0x04, 0x00, 0x01, 0x00, 0x00,
84 + 0xce, 0xb6, 0xb3, 0xb6, 0x0d,
85 + 0x24, 0x15, 0x49, 0x49, 0x09,
86 + 0xe4, 0x09, 0x79, 0x49, 0x09,
87 + 0x24, 0x08, 0x09, 0x49, 0x09,
88 + 0x24, 0x15, 0x49, 0x49, 0x09,
89 + 0xc8, 0x36, 0x32, 0x49, 0x0e,
97 -static SDL_Surface *screen;
98 -static int gui_grab; /* if true, all keyboard/mouse events are grabbed */
99 static int last_vm_running;
100 -static int gui_saved_grab;
101 -static int gui_fullscreen;
102 -static int gui_key_modifier_pressed;
103 -static int gui_keysym;
104 -static int gui_fullscreen_initial_grab;
105 -static int gui_grab_code = KMOD_LALT | KMOD_LCTRL;
106 -static uint8_t modifiers_state[256];
108 -static void sdl_update(DisplayState *ds, int x, int y, int w, int h)
110 - // printf("updating x=%d y=%d w=%d h=%d\n", x, y, w, h);
111 - SDL_UpdateRect(screen, x, y, w, h);
114 -static void sdl_resize(DisplayState *ds, int w, int h)
118 - // printf("resizing to %d %d\n", w, h);
120 - flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
121 - flags |= SDL_RESIZABLE;
122 - if (gui_fullscreen)
123 - flags |= SDL_FULLSCREEN;
124 - screen = SDL_SetVideoMode(w, h, 0, flags);
126 - fprintf(stderr, "Could not open SDL display\n");
128 +static Display *qx_display;
129 +static int q_x_screen_num;
132 +static XImage *ximage = NULL;
133 +static int default_depth;
134 +static Visual *default_visual;
135 +static int width, height;
137 +static void x_update(DisplayState *ds, int x, int y, int w, int h)
139 + XPutImage(qx_display, win, gc, ximage, x, y, x, y, w, h);
140 + XFlush(qx_display);
143 +static int prev_x, prev_y;
144 +static int current_x, current_y;
146 +/* Move the cursor to a center window place */
147 +static void qXWarpPointer(void)
152 + prev_x = current_x = x;
153 + prev_y = current_y = y;
154 + XWarpPointer(qx_display, None, win, 0, 0, 0, 0, x, y);
157 +static void x_resize(DisplayState *ds, int w, int h)
160 + long supplied_return;
162 + if ( XGetWMNormalHints(qx_display, win, &hints, &supplied_return) &&
163 + supplied_return & PMaxSize ) {
164 + hints.max_width = hints.min_width = w;
165 + hints.max_height = hints.min_height = h;
166 + XSetWMNormalHints(qx_display, win, &hints);
169 + XDestroyImage(ximage);
171 + XResizeWindow(qx_display, win, w, h);
173 + ximage = XCreateImage(qx_display, default_visual,
174 + default_depth, // depth of image (bitplanes)
177 + NULL, // malloc() space after
178 + w, h, // x & y size of image
179 + 32, // # bits of padding
180 + 0 ); // bytes_per_line, let X11 calculate
182 + fprintf(stderr, "Could not XCreateImage()\n");
185 + width = ds->width = w;
186 + height = ds->height = h;
187 + ds->depth = ximage->bits_per_pixel;
188 + ds->linesize = ximage->bytes_per_line;
189 + ds->data = (char *) malloc( (size_t) (ximage->bytes_per_line * h) );
191 + fprintf(stderr, "Could not malloc Image data\n");
194 + ximage->data = ds->data;
196 + XFlush(qx_display);
199 +static int gui_grab;
201 +static void x_SetCaption(void)
203 + char *title, *icon;
204 + XTextProperty titleprop, iconprop;
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 + XStringListToTextProperty(&title, 1, &titleprop);
215 + XSetWMName(qx_display, win, &titleprop);
216 + XFree(titleprop.value);
218 + XStringListToTextProperty(&icon, 1, &iconprop);
219 + XSetWMIconName(qx_display, win, &iconprop);
220 + XFree(iconprop.value);
221 + XSync(qx_display, /* no discard */ 0);
224 +static void trigger_mouse_grab(void)
228 + /* disable cursor */
229 + static Cursor cursor;
230 + static int cursor_created;
232 +#define shape_width 16
233 +#define shape_height 16
234 +#define mask_width 16
235 +#define mask_height 16
237 + static unsigned int shape_bits[(16*16)/32];
238 + static unsigned int mask_bits[(16*16)/32];
240 + if (!cursor_created) {
241 + Pixmap shape, mask;
242 + XColor white, black;
243 + Colormap default_cmap;
245 + default_cmap = DefaultColormap(qx_display, q_x_screen_num);
247 + shape = XCreatePixmapFromBitmapData(qx_display,
248 + RootWindow(qx_display,q_x_screen_num),
250 + shape_width, shape_height,
252 + mask = XCreatePixmapFromBitmapData(qx_display,
253 + RootWindow(qx_display,q_x_screen_num),
255 + mask_width, mask_height,
257 + XParseColor(qx_display, default_cmap, "black", &black);
258 + XParseColor(qx_display, default_cmap, "white", &white);
259 + cursor = XCreatePixmapCursor(qx_display, shape, mask,
260 + &white, &black, 1, 1);
261 + cursor_created = 1;
263 + XDefineCursor(qx_display, win, cursor);
265 + /* grab pointer and keyboard */
267 +// if ( flags & FULLSCREEN ) {
268 +// /* Unbind the mouse from the fullscreen window */
269 +// XUngrabPointer(qx_display, CurrentTime);
271 + /* Try to grab the mouse */
273 + int result = XGrabPointer(qx_display, win, True, 0,
274 + GrabModeAsync, GrabModeAsync,
275 + win, None, CurrentTime);
276 + if (result == GrabSuccess)
279 + /* Now grab the keyboard */
280 + XGrabKeyboard(qx_display, win, True,
281 + GrabModeAsync, GrabModeAsync, CurrentTime);
283 + /* Raise the window if we grab the mouse */
284 +// if ( !(flags & FULLSCREEN) )
285 + XRaiseWindow(qx_display, win);
288 + /* enable cursor */
289 + XUndefineCursor(qx_display, win);
290 + /* ungrab pointer and keyboard */
291 + XUngrabPointer(qx_display, CurrentTime);
292 + XUngrabKeyboard(qx_display, CurrentTime);
297 +static unsigned mouse_button_state;
299 +static void send_keyboard_mouse_status(void)
303 + dx = current_x - prev_x;
304 + dy = -(current_y - prev_y);
305 + kbd_mouse_event(dx, -dy, 0, mouse_button_state);
306 + if(current_x <= 1 || current_x >= (width-1) || current_y <= 1 || current_y >= (height-1)) {
309 + prev_x = current_x;
310 + prev_y = current_y;
312 - ds->data = screen->pixels;
313 - ds->linesize = screen->pitch;
314 - ds->depth = screen->format->BitsPerPixel;
319 -/* generic keyboard conversion */
321 -#include "sdl_keysym.h"
322 -#include "keymaps.c"
324 -static kbd_layout_t *kbd_layout = NULL;
326 -static uint8_t sdl_keyevent_to_keycode_generic(const SDL_KeyboardEvent *ev)
327 +static const unsigned char scan_table1[] =
330 - /* workaround for X11+SDL bug with AltGR */
331 - keysym = ev->keysym.sym;
332 - if (keysym == 0 && ev->keysym.scancode == 113)
333 - keysym = SDLK_MODE;
334 - return keysym2scancode(kbd_layout, keysym);
337 -/* specific keyboard conversions from scan codes */
341 -static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
343 - return ev->keysym.scancode;
347 +#ifdef KBUK /* double quotes, hash symbol */
351 -static const uint8_t x_keycode_to_pc_keycode[61] = {
352 - 0xc7, /* 97 Home */
354 - 0xc9, /* 99 PgUp */
355 - 0xcb, /* 100 Left */
356 - 0x4c, /* 101 KP-5 */
357 - 0xcd, /* 102 Right */
358 - 0xcf, /* 103 End */
359 - 0xd0, /* 104 Down */
360 - 0xd1, /* 105 PgDn */
361 - 0xd2, /* 106 Ins */
362 - 0xd3, /* 107 Del */
363 - 0x9c, /* 108 Enter */
364 - 0x9d, /* 109 Ctrl-R */
365 - 0x0, /* 110 Pause */
366 - 0xb7, /* 111 Print */
367 - 0xb5, /* 112 Divide */
368 - 0xb8, /* 113 Alt-R */
369 - 0xc6, /* 114 Break */
375 - 0x70, /* 120 Hiragana_Katakana */
378 - 0x73, /* 123 backslash */
384 - 0x79, /* 129 Henkan */
386 - 0x7b, /* 131 Muhenkan */
388 - 0x7d, /* 133 Yen */
391 - 0x47, /* 136 KP_7 */
392 - 0x48, /* 137 KP_8 */
393 - 0x49, /* 138 KP_9 */
394 - 0x4b, /* 139 KP_4 */
395 - 0x4c, /* 140 KP_5 */
396 - 0x4d, /* 141 KP_6 */
397 - 0x4f, /* 142 KP_1 */
398 - 0x50, /* 143 KP_2 */
399 - 0x51, /* 144 KP_3 */
400 - 0x52, /* 145 KP_0 */
401 - 0x53, /* 146 KP_. */
402 - 0x47, /* 147 KP_HOME */
403 - 0x48, /* 148 KP_UP */
404 - 0x49, /* 149 KP_PgUp */
405 - 0x4b, /* 150 KP_Left */
406 - 0x4c, /* 151 KP_ */
407 - 0x4d, /* 152 KP_Right */
408 - 0x4f, /* 153 KP_End */
409 - 0x50, /* 154 KP_Down */
410 - 0x51, /* 155 KP_PgDn */
411 - 0x52, /* 156 KP_Ins */
412 - 0x53, /* 157 KP_Del */
415 -static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
419 - keycode = ev->keysym.scancode;
423 - } else if (keycode < 97) {
424 - keycode -= 8; /* just an offset */
425 - } else if (keycode < 158) {
426 - /* use conversion table */
427 - keycode = x_keycode_to_pc_keycode[keycode - 97];
436 + 0x05, 0x06, 0x08, 0x28,
437 + 0x0a, 0x0b, 0x09, 0x0d, 0x33, 0x0c, 0x34, 0x35,
438 + 0x0b, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
439 + 0x09, 0x0a, 0x27, 0x27, 0x33, 0x0d, 0x34, 0x35,
440 +#ifdef KBUK /* at symbol */
445 + 0x1e, 0x30, 0x2e, 0x20, 0x12, 0x21, 0x22,
446 + 0x23, 0x17, 0x24, 0x25, 0x26, 0x32, 0x31, 0x18,
447 + 0x19, 0x10, 0x13, 0x1f, 0x14, 0x16, 0x2f, 0x11,
448 + 0x2d, 0x15, 0x2c, 0x1a,
449 +#ifdef KBUK /* backslash */
455 + 0x29, 0x1e, 0x30, 0x2e, 0x20, 0x12, 0x21, 0x22,
456 + 0x23, 0x17, 0x24, 0x25, 0x26, 0x32, 0x31, 0x18,
457 + 0x19, 0x10, 0x13, 0x1f, 0x14, 0x16, 0x2f, 0x11,
458 + 0x2d, 0x15, 0x2c, 0x1a,
459 +#ifdef KBUK /* vertical bar */
465 -static void reset_keys(void)
468 - for(i = 0; i < 256; i++) {
469 - if (modifiers_state[i]) {
471 - kbd_put_keycode(0xe0);
472 - kbd_put_keycode(i | 0x80);
473 - modifiers_state[i] = 0;
478 -static void sdl_process_key(SDL_KeyboardEvent *ev)
482 - if (ev->keysym.sym == SDLK_PAUSE) {
483 - /* specific case */
485 - if (ev->type == SDL_KEYUP)
487 - kbd_put_keycode(0xe1);
488 - kbd_put_keycode(0x1d | v);
489 - kbd_put_keycode(0x45 | v);
494 - keycode = sdl_keyevent_to_keycode_generic(ev);
496 - keycode = sdl_keyevent_to_keycode(ev);
501 - /* sent when leaving window: reset the modifiers state */
504 - case 0x2a: /* Left Shift */
505 - case 0x36: /* Right Shift */
506 - case 0x1d: /* Left CTRL */
507 - case 0x9d: /* Right CTRL */
508 - case 0x38: /* Left ALT */
509 - case 0xb8: /* Right ALT */
510 - if (ev->type == SDL_KEYUP)
511 - modifiers_state[keycode] = 0;
513 - modifiers_state[keycode] = 1;
515 - case 0x45: /* num lock */
516 - case 0x3a: /* caps lock */
517 - /* SDL does not send the key up event, so we generate it */
518 - kbd_put_keycode(keycode);
519 - kbd_put_keycode(keycode | 0x80);
523 - /* now send the key code */
524 - if (keycode & 0x80)
525 - kbd_put_keycode(0xe0);
526 - if (ev->type == SDL_KEYUP)
527 - kbd_put_keycode(keycode | 0x80);
529 - kbd_put_keycode(keycode & 0x7f);
532 -static void sdl_update_caption(void)
535 - strcpy(buf, "QEMU");
537 - strcat(buf, " [Stopped]");
540 - strcat(buf, " - Press Ctrl-Alt to exit grab");
542 - SDL_WM_SetCaption(buf, "QEMU");
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();
555 -static void sdl_grab_end(void)
557 - SDL_WM_GrabInput(SDL_GRAB_OFF);
560 - sdl_update_caption();
563 -static void sdl_send_mouse_event(int dz)
565 - int dx, dy, state, buttons;
566 - state = SDL_GetRelativeMouseState(&dx, &dy);
568 - if (state & SDL_BUTTON(SDL_BUTTON_LEFT))
569 - buttons |= MOUSE_EVENT_LBUTTON;
570 - if (state & SDL_BUTTON(SDL_BUTTON_RIGHT))
571 - buttons |= MOUSE_EVENT_RBUTTON;
572 - if (state & SDL_BUTTON(SDL_BUTTON_MIDDLE))
573 - buttons |= MOUSE_EVENT_MBUTTON;
574 - kbd_mouse_event(dx, dy, dz, buttons);
577 -static void toggle_full_screen(DisplayState *ds)
579 - gui_fullscreen = !gui_fullscreen;
580 - sdl_resize(ds, screen->w, screen->h);
581 - if (gui_fullscreen) {
582 - gui_saved_grab = gui_grab;
585 - if (!gui_saved_grab)
588 - vga_invalidate_display();
589 - vga_update_display();
593 -static void sdl_refresh(DisplayState *ds)
595 - SDL_Event ev1, *ev = &ev1;
598 - if (last_vm_running != vm_running) {
599 - last_vm_running = vm_running;
600 - sdl_update_caption();
602 +#ifdef KBUK /* tilde */
609 - if (is_active_console(vga_console))
610 - vga_update_display();
612 - while (SDL_PollEvent(ev)) {
613 - switch (ev->type) {
614 - case SDL_VIDEOEXPOSE:
615 - sdl_update(ds, 0, 0, screen->w, screen->h);
619 - if (ev->type == SDL_KEYDOWN) {
620 - mod_state = (SDL_GetModState() & gui_grab_code) ==
622 - gui_key_modifier_pressed = mod_state;
623 - if (gui_key_modifier_pressed) {
625 - keycode = sdl_keyevent_to_keycode(&ev->key);
627 - case 0x21: /* 'f' key on US keyboard */
628 - toggle_full_screen(ds);
631 - case 0x02 ... 0x0a: /* '1' to '9' keys */
632 - console_select(keycode - 0x02);
633 - if (is_active_console(vga_console)) {
634 - /* tell the vga console to redisplay itself */
635 - vga_invalidate_display();
637 - /* display grab if going to a text console */
646 - } else if (!is_active_console(vga_console)) {
649 - if (ev->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
650 - switch(ev->key.keysym.sym) {
651 - case SDLK_UP: keysym = QEMU_KEY_CTRL_UP; break;
652 - case SDLK_DOWN: keysym = QEMU_KEY_CTRL_DOWN; break;
653 - case SDLK_LEFT: keysym = QEMU_KEY_CTRL_LEFT; break;
654 - case SDLK_RIGHT: keysym = QEMU_KEY_CTRL_RIGHT; break;
655 - case SDLK_HOME: keysym = QEMU_KEY_CTRL_HOME; break;
656 - case SDLK_END: keysym = QEMU_KEY_CTRL_END; break;
657 - case SDLK_PAGEUP: keysym = QEMU_KEY_CTRL_PAGEUP; break;
658 - case SDLK_PAGEDOWN: keysym = QEMU_KEY_CTRL_PAGEDOWN; break;
662 - switch(ev->key.keysym.sym) {
663 - case SDLK_UP: keysym = QEMU_KEY_UP; break;
664 - case SDLK_DOWN: keysym = QEMU_KEY_DOWN; break;
665 - case SDLK_LEFT: keysym = QEMU_KEY_LEFT; break;
666 - case SDLK_RIGHT: keysym = QEMU_KEY_RIGHT; break;
667 - case SDLK_HOME: keysym = QEMU_KEY_HOME; break;
668 - case SDLK_END: keysym = QEMU_KEY_END; break;
669 - case SDLK_PAGEUP: keysym = QEMU_KEY_PAGEUP; break;
670 - case SDLK_PAGEDOWN: keysym = QEMU_KEY_PAGEDOWN; break;
671 - case SDLK_BACKSPACE: keysym = QEMU_KEY_BACKSPACE; break; case SDLK_DELETE: keysym = QEMU_KEY_DELETE; break;
676 - kbd_put_keysym(keysym);
677 - } else if (ev->key.keysym.unicode != 0) {
678 - kbd_put_keysym(ev->key.keysym.unicode);
681 - } else if (ev->type == SDL_KEYUP) {
682 - mod_state = (ev->key.keysym.mod & gui_grab_code);
684 - if (gui_key_modifier_pressed) {
685 - if (gui_keysym == 0) {
686 - /* exit/enter grab if pressing Ctrl-Alt */
691 - /* SDL does not send back all the
692 - modifiers key, so we must correct it */
696 - gui_key_modifier_pressed = 0;
701 - if (is_active_console(vga_console))
702 - sdl_process_key(&ev->key);
705 - qemu_system_shutdown_request();
707 - case SDL_MOUSEMOTION:
709 - sdl_send_mouse_event(0);
712 - case SDL_MOUSEBUTTONDOWN:
713 - case SDL_MOUSEBUTTONUP:
715 - SDL_MouseButtonEvent *bev = &ev->button;
717 - if (ev->type == SDL_MOUSEBUTTONDOWN &&
718 - (bev->state & SDL_BUTTON_LMASK)) {
719 - /* start grabbing all events */
725 -#ifdef SDL_BUTTON_WHEELUP
726 - if (bev->button == SDL_BUTTON_WHEELUP) {
728 - } else if (bev->button == SDL_BUTTON_WHEELDOWN) {
732 - sdl_send_mouse_event(dz);
736 - case SDL_ACTIVEEVENT:
737 - if (gui_grab && (ev->active.gain & SDL_ACTIVEEVENTMASK) == 0 &&
738 - !gui_fullscreen_initial_grab) {
747 +static const struct {
749 + unsigned scan_code;
751 + { XK_BackSpace, 0x0e },
753 + { XK_Return, 0x1c },
754 + { XK_Escape, 0x01 },
755 + { XK_Delete, 0x53e0 },
757 + { XK_Home, 0x47e0 },
758 + { XK_Left, 0x4be0 },
760 + { XK_Right, 0x4de0 },
761 + { XK_Down, 0x50e0 },
762 + { XK_Prior, 0x49e0 },
763 + { XK_Next, 0x51e0 },
764 + { XK_End, 0x4fe0 },
765 + { XK_Insert, 0x52e0 },
766 + { XK_Num_Lock, 0x45 },
768 +/* This block of codes is for Sun Type 4 keyboards... */
770 + { XK_F27, 0x47e0 }, /* Home/R7/F27 */
771 + { XK_F29, 0x49e0 }, /* Prior/R9/F29 */
772 + { XK_F35, 0x51e0 }, /* Next/R15/F35 */
773 + { XK_F33, 0x4fe0 }, /* End/R13/F33 */
775 + { XK_F25, 0x36e0 }, /* Keypad divide/R5/F25 */
776 + { XK_F26, 0x37 }, /* Keypad multiply/R6/F26 */
778 + { XK_F23, 0x46 }, /* Scroll lock/R3/F23 */
780 + { XK_F31, 0x4c }, /* Keypad 5/R11/F31 */
782 +/* End of Sun type 4 codes */
784 + { XK_KP_Enter, 0x1ce0 },
785 + { XK_KP_Multiply, 0x37 },
786 + { XK_KP_Add, 0x4e },
787 + { XK_KP_Subtract, 0x4a },
788 + { XK_KP_Divide, 0x36e0 },
789 + { XK_KP_Decimal, 0x53 },
803 + { XK_Help, 0x3b }, /* openwin mapped */
808 + { XK_F19, 0x3c }, /* openwin mapped */
809 + { XK_F20, 0x3d }, /* openwin mapped */
810 + { XK_F16, 0x3e }, /* openwin mapped */
811 + { XK_F18, 0x3f }, /* openwin mapped */
820 + { XK_Shift_L, 0x2a },
821 + { XK_Shift_R, 0x36 },
822 + { XK_Control_L, 0x1d },
823 + { XK_Control_R, 0x1de0 },
824 + { XK_Meta_L, 0x38 },
825 + { XK_Alt_L, 0x38 },
826 + { XK_Meta_R, 0x38e0 },
827 + { XK_Alt_R, 0x38e0 },
829 -static void sdl_cleanup(void)
833 + { XK_Scroll_Lock, 0x46 },
834 + { XK_Caps_Lock, 0xba3a }
837 -void sdl_display_init(DisplayState *ds, int full_screen)
838 +static void x_refresh(DisplayState *ds)
842 -#if defined(__APPLE__)
843 - /* always use generic keymaps */
844 - if (!keyboard_layout)
845 - keyboard_layout = "en-us";
848 + int mouse_update = 0;
850 + XButtonEvent *button_event;
851 + XExposeEvent *expose_event;
853 + static int gui_key_modifier_pressed;
855 + if (last_vm_running != vm_running) {
856 + last_vm_running = vm_running;
860 + if (is_active_console(vga_console))
861 + vga_update_display();
863 + while (XPending(qx_display) > 0) {
864 + XNextEvent(qx_display, &report);
866 + switch (report.type) {
869 + expose_event = &report.xexpose;
870 + x_update(ds, expose_event->x, expose_event->y, expose_event->width, expose_event->height);
874 + button_event = (XButtonEvent *) &report;
875 + current_x = button_event->x;
876 + current_y = button_event->y;
877 + switch (button_event->button) {
880 + /* start grabbing all events */
881 + trigger_mouse_grab();
884 + mouse_button_state |= 0x01;
888 + mouse_button_state |= 0x04;
892 + mouse_button_state |= 0x02;
898 + case ButtonRelease:
899 + button_event = (XButtonEvent *) &report;
900 + current_x = button_event->x;
901 + current_y = button_event->y;
902 + switch (button_event->button) {
904 + mouse_button_state &= ~0x01;
908 + mouse_button_state &= ~0x04;
912 + mouse_button_state &= ~0x02;
920 + key = XLookupKeysym(&report.xkey, 0);
922 + if(key == XK_Shift_L) {
923 + if(report.type == KeyPress)
924 + gui_key_modifier_pressed |= 5;
926 + gui_key_modifier_pressed &= ~1;
927 + } else if(key == XK_Control_L) {
928 + if(report.type == KeyPress)
929 + gui_key_modifier_pressed |= 6;
931 + gui_key_modifier_pressed &= ~2;
933 + if((gui_key_modifier_pressed & 7) == 7) {
934 + trigger_mouse_grab();
935 + gui_key_modifier_pressed &= ~4;
939 + /* XK_F21 is for sun type 4 keyboards.. */
940 + if (key == XK_Break || key == XK_F21)
943 + if (key == XK_Pause) {
944 + if (report.xkey.state & ControlMask)
948 + } /* XK_F22 is sun type 4 PrtScr */
949 + else if (key == XK_Print || key == XK_F22) {
950 + if (report.xkey.state & Mod1Mask)
956 + else if ((key == XK_numbersign) && (report.xkey.state & ShiftMask))
959 - if(keyboard_layout) {
960 - kbd_layout = init_keyboard_layout(keyboard_layout);
965 - flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE;
966 - if (SDL_Init (flags)) {
967 - fprintf(stderr, "Could not initialize SDL - exiting\n");
971 - /* NOTE: we still want Ctrl-C to work, so we undo the SDL redirections */
972 - signal(SIGINT, SIG_DFL);
973 - signal(SIGQUIT, SIG_DFL);
976 - ds->dpy_update = sdl_update;
977 - ds->dpy_resize = sdl_resize;
978 - ds->dpy_refresh = sdl_refresh;
980 - sdl_resize(ds, 640, 400);
981 - sdl_update_caption();
982 - SDL_EnableKeyRepeat(250, 50);
983 - SDL_EnableUNICODE(1);
986 - atexit(sdl_cleanup);
988 - gui_fullscreen = 1;
989 - gui_fullscreen_initial_grab = 1;
992 + else if (key == XK_sterling)
995 + if (key >= 0x20 && key <= 0x20+sizeof(scan_table1))
996 + scan = scan_table1[key - 0x20];
999 + for (count = 0; count <
1000 + (sizeof(scan_table2)/sizeof(scan_table2[0]));
1002 + if (scan_table2[count].key == key) {
1003 + scan = scan_table2[count].scan_code;
1010 + if (is_active_console(vga_console))
1011 + for (count = 0; scan; count++) {
1012 + if (key != XK_Caps_Lock && report.type == KeyRelease)
1013 + kbd_put_keycode(0x80 | (scan & 0xff));
1015 + kbd_put_keycode(scan & 0xff);
1021 + case MotionNotify:
1022 + current_x = report.xmotion.x;
1023 + current_y = report.xmotion.y;
1029 + } /* end switch */
1031 + if (mouse_update && gui_grab) {
1032 + send_keyboard_mouse_status();
1038 +void X_display_init(DisplayState *ds, int full_screen)
1040 + Pixmap icon_pixmap;
1041 + XSizeHints size_hints;
1042 + XWMHints wm_hints;
1043 + XClassHint class_hints;
1044 + XSetWindowAttributes attr;
1045 + unsigned long valuemask = 0; /* ignore XGCvalues and use defaults */
1047 + char *progname = "qemu";
1050 + if ( (qx_display=XOpenDisplay(NULL)) == NULL ) {
1051 + fprintf(stderr, "Could not open X display\n");
1054 + /* get screen size from display structure macro */
1055 + q_x_screen_num = DefaultScreen(qx_display);
1057 + /* create opaque window */
1058 + win = XCreateSimpleWindow(qx_display, RootWindow(qx_display, q_x_screen_num),
1059 + 0, 0, /* x y would be settable from the command line or resource database. */
1060 + 720, /* initial vga 80*25 9x16 */
1062 + 4, /* border_width four pixels */
1063 + BlackPixel(qx_display, q_x_screen_num),
1064 + BlackPixel(qx_display, q_x_screen_num));
1066 + default_depth = DefaultDepth(qx_display, q_x_screen_num);
1067 + default_visual = DefaultVisual(qx_display, q_x_screen_num);
1069 + icon_pixmap = XCreateBitmapFromData(qx_display, win, icon_bits,
1070 + icon_width, icon_height);
1072 + size_hints.flags = PSize | PMinSize | PMaxSize;
1073 + size_hints.max_width = size_hints.min_width = 720;
1074 + size_hints.max_height = size_hints.min_height = 400;
1076 + wm_hints.initial_state = NormalState;
1077 + wm_hints.input = True;
1078 + wm_hints.icon_pixmap = icon_pixmap;
1079 + wm_hints.flags = StateHint | IconPixmapHint | InputHint;
1081 + class_hints.res_name = "qemu";
1082 + class_hints.res_class = "Qemu";
1084 + XSetWMProperties(qx_display, win,
1085 + NULL, NULL, // windowName iconName, set from x_SetCaption
1086 + &progname, 1, &size_hints, &wm_hints,
1088 + // (attempt to) enable backing store
1089 + attr.save_under=1;
1090 + attr.backing_store=Always;
1091 + XChangeWindowAttributes(qx_display, win, CWSaveUnder|CWBackingStore, &attr);
1093 + XSelectInput(qx_display, win,
1094 + KeyPressMask | KeyReleaseMask |
1095 + ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
1096 + ExposureMask| StructureNotifyMask);
1098 + gc = XCreateGC(qx_display, win, valuemask, &values);
1100 + XSetForeground(qx_display, gc, WhitePixel(qx_display, q_x_screen_num));
1101 + XSetBackground(qx_display, gc, BlackPixel(qx_display, q_x_screen_num));
1103 + /* Display window */
1104 + XMapWindow(qx_display, win);
1105 + XSync(qx_display, /* no discard */ 0);
1108 + XNextEvent(qx_display, &report);
1109 + if (report.type == MapNotify) break;
1111 + ds->dpy_update = x_update;
1112 + ds->dpy_resize = x_resize;
1113 + ds->dpy_refresh = x_refresh;
1114 + x_resize(ds, 720, 400);
1115 +// trigger_mouse_grab();