]> git.pld-linux.org Git - packages/qemu.git/blob - qemu-nosdlgui.patch
- X11 gui patch
[packages/qemu.git] / qemu-nosdlgui.patch
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 $@ $<
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
16 @@ -1,507 +1,614 @@
17  /*
18 - * QEMU SDL display driver
19 - * 
20 - * Copyright (c) 2003 Fabrice Bellard
21 - * 
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
29   *
30 - * The above copyright notice and this permission notice shall be included in
31 - * all copies or substantial portions of the Software.
32 - *
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
39 - * THE SOFTWARE.
40 - */
41 -#include "vl.h"
42 -
43 -#include <SDL.h>
44 + * Copyright (c) 2004 Vladimit Oleynik <dzo@simtreas.ru>
45 + * Used ideas from Bochs, SDL, PCEmu.
46 +*/
47 +
48 +#include <X11/Xlib.h>
49 +#include <X11/Xutil.h>
50 +#include <X11/keysym.h>
51 +
52 +/* hack, special for qemu */
53 +#define X_display_init sdl_display_init
54 +
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,
90 +};
91  
92 -#ifndef _WIN32
93 -#include <signal.h>
94 -#endif
95 +#include "vl.h"
96  
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];
107 -
108 -static void sdl_update(DisplayState *ds, int x, int y, int w, int h)
109 -{
110 -    //    printf("updating x=%d y=%d w=%d h=%d\n", x, y, w, h);
111 -    SDL_UpdateRect(screen, x, y, w, h);
112 -}
113 -
114 -static void sdl_resize(DisplayState *ds, int w, int h)
115 -{
116 -    int flags;
117 -
118 -    //    printf("resizing to %d %d\n", w, h);
119  
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);
125 -    if (!screen) {
126 -        fprintf(stderr, "Could not open SDL display\n");
127 -        exit(1);
128 +static Display *qx_display;
129 +static int q_x_screen_num;
130 +static Window win;
131 +static GC gc;
132 +static XImage *ximage = NULL;
133 +static int     default_depth;
134 +static Visual  *default_visual;
135 +static int width, height;
136 +
137 +static void x_update(DisplayState *ds, int x, int y, int w, int h)
138 +{
139 +    XPutImage(qx_display, win, gc, ximage, x, y, x, y, w, h);
140 +    XFlush(qx_display);
141 +}
142 +
143 +static int prev_x, prev_y;
144 +static int current_x, current_y;
145 +
146 +/* Move the cursor to a center window place */
147 +static void qXWarpPointer(void)
148 +{
149 +       int x = width/2;
150 +       int y = height/2;
151 +
152 +       prev_x = current_x = x;
153 +       prev_y = current_y = y;
154 +       XWarpPointer(qx_display, None, win, 0, 0, 0, 0, x, y);
155 +}
156 +
157 +static void x_resize(DisplayState *ds, int w, int h)
158 +{
159 +    XSizeHints hints;
160 +    long supplied_return;
161 +
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);
167 +    }
168 +    if(ximage) {
169 +       XDestroyImage(ximage);
170 +//        free(ds->data);
171 +       XResizeWindow(qx_display, win, w, h);
172 +    }
173 +    ximage = XCreateImage(qx_display, default_visual,
174 +            default_depth,          // depth of image (bitplanes)
175 +            ZPixmap,
176 +            0,                      // offset
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
181 +    if (!ximage) {
182 +       fprintf(stderr, "Could not XCreateImage()\n");
183 +       exit(1);
184 +    }
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) );
190 +    if (!ds->data) {
191 +       fprintf(stderr, "Could not malloc Image data\n");
192 +       exit(1);
193 +    }
194 +    ximage->data = ds->data;
195 +    qXWarpPointer();
196 +    XFlush(qx_display);
197 +}
198 +
199 +static int gui_grab;
200 +
201 +static void x_SetCaption(void)
202 +{
203 +       char *title, *icon;
204 +       XTextProperty titleprop, iconprop;
205 +
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";
213 +
214 +       XStringListToTextProperty(&title, 1, &titleprop);
215 +       XSetWMName(qx_display, win, &titleprop);
216 +       XFree(titleprop.value);
217 +
218 +       XStringListToTextProperty(&icon, 1, &iconprop);
219 +       XSetWMIconName(qx_display, win, &iconprop);
220 +       XFree(iconprop.value);
221 +       XSync(qx_display, /* no discard */ 0);
222 +}
223 +
224 +static void trigger_mouse_grab(void)
225 +{
226 +  gui_grab ^= 1;
227 +  if (gui_grab) {
228 +      /* disable cursor */
229 +      static Cursor cursor;
230 +      static int cursor_created;
231 +
232 +#define shape_width 16
233 +#define shape_height 16
234 +#define mask_width 16
235 +#define mask_height 16
236 +
237 +      static unsigned int shape_bits[(16*16)/32];
238 +      static unsigned int mask_bits[(16*16)/32];
239 +
240 +      if (!cursor_created) {
241 +           Pixmap shape, mask;
242 +           XColor white, black;
243 +           Colormap default_cmap;
244 +
245 +           default_cmap = DefaultColormap(qx_display, q_x_screen_num);
246 +
247 +           shape = XCreatePixmapFromBitmapData(qx_display,
248 +                                               RootWindow(qx_display,q_x_screen_num),
249 +                                               (char*)shape_bits,
250 +                                               shape_width, shape_height,
251 +                                               1, 0, 1);
252 +           mask =  XCreatePixmapFromBitmapData(qx_display,
253 +                                               RootWindow(qx_display,q_x_screen_num),
254 +                                               (char*)mask_bits,
255 +                                               mask_width, mask_height,
256 +                                               1, 0, 1);
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;
262 +      }
263 +      XDefineCursor(qx_display, win, cursor);
264 +
265 +      /* grab pointer and keyboard */
266 +
267 +//    if ( flags & FULLSCREEN ) {
268 +//      /* Unbind the mouse from the fullscreen window */
269 +//      XUngrabPointer(qx_display, CurrentTime);
270 +//    }
271 +      /* Try to grab the mouse */
272 +      while ( 1 ) {
273 +       int result = XGrabPointer(qx_display, win, True, 0,
274 +                                       GrabModeAsync, GrabModeAsync,
275 +                                       win, None, CurrentTime);
276 +       if (result == GrabSuccess)
277 +               break;
278 +      }
279 +      /* Now grab the keyboard */
280 +      XGrabKeyboard(qx_display, win, True,
281 +                       GrabModeAsync, GrabModeAsync, CurrentTime);
282 +
283 +      /* Raise the window if we grab the mouse */
284 +//    if ( !(flags & FULLSCREEN) )
285 +       XRaiseWindow(qx_display, win);
286 +      qXWarpPointer();
287 +  } else {
288 +    /* enable cursor */
289 +    XUndefineCursor(qx_display, win);
290 +    /* ungrab pointer and keyboard */
291 +    XUngrabPointer(qx_display, CurrentTime);
292 +    XUngrabKeyboard(qx_display, CurrentTime);
293 +  }
294 +  x_SetCaption();
295 +}
296 +
297 +static unsigned mouse_button_state;
298 +
299 +static void send_keyboard_mouse_status(void)
300 +{
301 +    int dx, dy;
302 +
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)) {
307 +       qXWarpPointer();
308 +    } else {
309 +       prev_x = current_x;
310 +       prev_y = current_y;
311      }
312 -    ds->data = screen->pixels;
313 -    ds->linesize = screen->pitch;
314 -    ds->depth = screen->format->BitsPerPixel;
315 -    ds->width = w;
316 -    ds->height = h;
317  }
318  
319 -/* generic keyboard conversion */
320 -
321 -#include "sdl_keysym.h"
322 -#include "keymaps.c"
323 -
324 -static kbd_layout_t *kbd_layout = NULL;
325 -
326 -static uint8_t sdl_keyevent_to_keycode_generic(const SDL_KeyboardEvent *ev)
327 +static const unsigned char scan_table1[] =
328  {
329 -    int keysym;
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);
335 -}
336 -
337 -/* specific keyboard conversions from scan codes */
338 -
339 -#if defined(_WIN32)
340 -
341 -static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
342 -{
343 -    return ev->keysym.scancode;
344 -}
345 -
346 +    0x39, 0x02,
347 +#ifdef KBUK             /* double quotes, hash symbol */
348 +    0x03, 0x2b,
349  #else
350 -
351 -static const uint8_t x_keycode_to_pc_keycode[61] = {
352 -   0xc7,      /*  97  Home   */
353 -   0xc8,      /*  98  Up     */
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  */   
370 -   0x0,         /* 115 */
371 -   0x0,         /* 116 */
372 -   0x0,         /* 117 */
373 -   0x0,         /* 118 */
374 -   0x0,         /* 119 */
375 -   0x70,         /* 120 Hiragana_Katakana */
376 -   0x0,         /* 121 */
377 -   0x0,         /* 122 */
378 -   0x73,         /* 123 backslash */
379 -   0x0,         /* 124 */
380 -   0x0,         /* 125 */
381 -   0x0,         /* 126 */
382 -   0x0,         /* 127 */
383 -   0x0,         /* 128 */
384 -   0x79,         /* 129 Henkan */
385 -   0x0,         /* 130 */
386 -   0x7b,         /* 131 Muhenkan */
387 -   0x0,         /* 132 */
388 -   0x7d,         /* 133 Yen */
389 -   0x0,         /* 134 */
390 -   0x0,         /* 135 */
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 */
413 -};
414 -
415 -static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
416 -{
417 -    int keycode;
418 -
419 -    keycode = ev->keysym.scancode;
420 -
421 -    if (keycode < 9) {
422 -        keycode = 0;
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];
428 -    } else {
429 -        keycode = 0;
430 -    }
431 -    return keycode;
432 -}
433 -
434 +    0x28, 0x04,
435 +#endif
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 */
441 +    0x28,
442 +#else
443 +    0x03,
444 +#endif
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 */
450 +    0x56,
451 +#else
452 +    0x2b,
453 +#endif
454 +    0x1b, 0x07, 0x0c,
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 */
460 +    0x56,
461 +#else
462 +    0x2b,
463  #endif
464  
465 -static void reset_keys(void)
466 -{
467 -    int i;
468 -    for(i = 0; i < 256; i++) {
469 -        if (modifiers_state[i]) {
470 -            if (i & 0x80)
471 -                kbd_put_keycode(0xe0);
472 -            kbd_put_keycode(i | 0x80);
473 -            modifiers_state[i] = 0;
474 -        }
475 -    }
476 -}
477 -
478 -static void sdl_process_key(SDL_KeyboardEvent *ev)
479 -{
480 -    int keycode, v;
481 -
482 -    if (ev->keysym.sym == SDLK_PAUSE) {
483 -        /* specific case */
484 -        v = 0;
485 -        if (ev->type == SDL_KEYUP)
486 -            v |= 0x80;
487 -        kbd_put_keycode(0xe1);
488 -        kbd_put_keycode(0x1d | v);
489 -        kbd_put_keycode(0x45 | v);
490 -        return;
491 -    }
492 -
493 -    if (kbd_layout) {
494 -        keycode = sdl_keyevent_to_keycode_generic(ev);
495 -    } else {
496 -        keycode = sdl_keyevent_to_keycode(ev);
497 -    }
498 -
499 -    switch(keycode) {
500 -    case 0x00:
501 -        /* sent when leaving window: reset the modifiers state */
502 -        reset_keys();
503 -        return;
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;
512 -        else
513 -            modifiers_state[keycode] = 1;
514 -        break;
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);
520 -        return;
521 -    }
522 -
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);
528 -    else
529 -        kbd_put_keycode(keycode & 0x7f);
530 -}
531 -
532 -static void sdl_update_caption(void)
533 -{
534 -    char buf[1024];
535 -    strcpy(buf, "QEMU");
536 -    if (!vm_running) {
537 -        strcat(buf, " [Stopped]");
538 -    }
539 -    if (gui_grab) {
540 -        strcat(buf, " - Press Ctrl-Alt to exit grab");
541 -    }
542 -    SDL_WM_SetCaption(buf, "QEMU");
543 -}
544 -
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 -}
554 -
555 -static void sdl_grab_end(void)
556 -{
557 -    SDL_WM_GrabInput(SDL_GRAB_OFF);
558 -    SDL_ShowCursor(1);
559 -    gui_grab = 0;
560 -    sdl_update_caption();
561 -}
562 -
563 -static void sdl_send_mouse_event(int dz)
564 -{
565 -    int dx, dy, state, buttons;
566 -    state = SDL_GetRelativeMouseState(&dx, &dy);
567 -    buttons = 0;
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);
575 -}
576 -
577 -static void toggle_full_screen(DisplayState *ds)
578 -{
579 -    gui_fullscreen = !gui_fullscreen;
580 -    sdl_resize(ds, screen->w, screen->h);
581 -    if (gui_fullscreen) {
582 -        gui_saved_grab = gui_grab;
583 -        sdl_grab_start();
584 -    } else {
585 -        if (!gui_saved_grab)
586 -            sdl_grab_end();
587 -    }
588 -    vga_invalidate_display();
589 -    vga_update_display();
590 -}
591 +    0x1b,
592  
593 -static void sdl_refresh(DisplayState *ds)
594 -{
595 -    SDL_Event ev1, *ev = &ev1;
596 -    int mod_state;
597 -                     
598 -    if (last_vm_running != vm_running) {
599 -        last_vm_running = vm_running;
600 -        sdl_update_caption();
601 -    }
602 +#ifdef KBUK             /* tilde */
603 +    0x2b,
604 +#else
605 +    0x29,
606 +#endif
607 +};
608  
609 -    if (is_active_console(vga_console)) 
610 -        vga_update_display();
611  
612 -    while (SDL_PollEvent(ev)) {
613 -        switch (ev->type) {
614 -        case SDL_VIDEOEXPOSE:
615 -            sdl_update(ds, 0, 0, screen->w, screen->h);
616 -            break;
617 -        case SDL_KEYDOWN:
618 -        case SDL_KEYUP:
619 -            if (ev->type == SDL_KEYDOWN) {
620 -                mod_state = (SDL_GetModState() & gui_grab_code) ==
621 -                    gui_grab_code;
622 -                gui_key_modifier_pressed = mod_state;
623 -                if (gui_key_modifier_pressed) {
624 -                    int keycode;
625 -                    keycode = sdl_keyevent_to_keycode(&ev->key);
626 -                    switch(keycode) {
627 -                    case 0x21: /* 'f' key on US keyboard */
628 -                        toggle_full_screen(ds);
629 -                        gui_keysym = 1;
630 -                        break;
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();
636 -                        } else {
637 -                            /* display grab if going to a text console */
638 -                            if (gui_grab)
639 -                                sdl_grab_end();
640 -                        }
641 -                        gui_keysym = 1;
642 -                        break;
643 -                    default:
644 -                        break;
645 -                    }
646 -                } else if (!is_active_console(vga_console)) {
647 -                    int keysym;
648 -                    keysym = 0;
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;
659 -                        default: break;
660 -                        }
661 -                    } else {
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;
672 -                        default: break;
673 -                        }
674 -                    }
675 -                    if (keysym) {
676 -                        kbd_put_keysym(keysym);
677 -                    } else if (ev->key.keysym.unicode != 0) {
678 -                        kbd_put_keysym(ev->key.keysym.unicode);
679 -                    }
680 -                }
681 -            } else if (ev->type == SDL_KEYUP) {
682 -                mod_state = (ev->key.keysym.mod & gui_grab_code);
683 -                if (!mod_state) {
684 -                    if (gui_key_modifier_pressed) {
685 -                        if (gui_keysym == 0) {
686 -                            /* exit/enter grab if pressing Ctrl-Alt */
687 -                            if (!gui_grab)
688 -                                sdl_grab_start();
689 -                            else
690 -                                sdl_grab_end();
691 -                            /* SDL does not send back all the
692 -                               modifiers key, so we must correct it */
693 -                            reset_keys();
694 -                            break;
695 -                        }
696 -                        gui_key_modifier_pressed = 0;
697 -                        gui_keysym = 0;
698 -                    }
699 -                }
700 -            }
701 -            if (is_active_console(vga_console)) 
702 -                sdl_process_key(&ev->key);
703 -            break;
704 -        case SDL_QUIT:
705 -            qemu_system_shutdown_request();
706 -            break;
707 -        case SDL_MOUSEMOTION:
708 -            if (gui_grab) {
709 -                sdl_send_mouse_event(0);
710 -            }
711 -            break;
712 -        case SDL_MOUSEBUTTONDOWN:
713 -        case SDL_MOUSEBUTTONUP:
714 -            {
715 -                SDL_MouseButtonEvent *bev = &ev->button;
716 -                if (!gui_grab) {
717 -                    if (ev->type == SDL_MOUSEBUTTONDOWN &&
718 -                        (bev->state & SDL_BUTTON_LMASK)) {
719 -                        /* start grabbing all events */
720 -                        sdl_grab_start();
721 -                    }
722 -                } else {
723 -                    int dz;
724 -                    dz = 0;
725 -#ifdef SDL_BUTTON_WHEELUP
726 -                    if (bev->button == SDL_BUTTON_WHEELUP) {
727 -                        dz = -1;
728 -                    } else if (bev->button == SDL_BUTTON_WHEELDOWN) {
729 -                        dz = 1;
730 -                    }
731 -#endif               
732 -                    sdl_send_mouse_event(dz);
733 -                }
734 -            }
735 -            break;
736 -        case SDL_ACTIVEEVENT:
737 -            if (gui_grab && (ev->active.gain & SDL_ACTIVEEVENTMASK) == 0 &&
738 -                !gui_fullscreen_initial_grab) {
739 -                sdl_grab_end();
740 -            }
741 -            break;
742 -        default:
743 -            break;
744 -        }
745 -    }
746 -}
747 +static const struct {
748 +    KeySym key;
749 +    unsigned scan_code;
750 +} scan_table2[] = {
751 +    { XK_BackSpace,     0x0e },
752 +    { XK_Tab,           0x0f },
753 +    { XK_Return,        0x1c },
754 +    { XK_Escape,        0x01 },
755 +    { XK_Delete,        0x53e0 },
756 +
757 +    { XK_Home,          0x47e0 },
758 +    { XK_Left,          0x4be0 },
759 +    { XK_Up,            0x48e0 },
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 },
767 +
768 +/* This block of codes is for Sun Type 4 keyboards... */
769 +
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 */
774 +
775 +    { XK_F25,           0x36e0 },       /* Keypad divide/R5/F25 */
776 +    { XK_F26,           0x37 },         /* Keypad multiply/R6/F26 */
777 +
778 +    { XK_F23,           0x46 },         /* Scroll lock/R3/F23 */
779 +
780 +    { XK_F31,           0x4c },         /* Keypad 5/R11/F31 */
781 +
782 +/* End of Sun type 4 codes */
783 +
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 },
790 +
791 +    { XK_KP_0,          0x52 },
792 +    { XK_KP_1,          0x4f },
793 +    { XK_KP_2,          0x50 },
794 +    { XK_KP_3,          0x51 },
795 +    { XK_KP_4,          0x4b },
796 +    { XK_KP_5,          0x4c },
797 +    { XK_KP_6,          0x4d },
798 +    { XK_KP_7,          0x47 },
799 +    { XK_KP_8,          0x48 },
800 +    { XK_KP_9,          0x49 },
801 +
802 +    { XK_F1,            0x3b },
803 +    { XK_Help,          0x3b }, /* openwin mapped */
804 +    { XK_F2,            0x3c },
805 +    { XK_F3,            0x3d },
806 +    { XK_F4,            0x3e },
807 +    { XK_F5,            0x3f },
808 +    { XK_F19,           0x3c }, /* openwin mapped */
809 +    { XK_F20,           0x3d }, /* openwin mapped */
810 +    { XK_F16,           0x3e }, /* openwin mapped */
811 +    { XK_F18,           0x3f }, /* openwin mapped */
812 +    { XK_F6,            0x40 },
813 +    { XK_F7,            0x41 },
814 +    { XK_F8,            0x42 },
815 +    { XK_F9,            0x43 },
816 +    { XK_F10,           0x44 },
817 +    { XK_F11,           0x57 },
818 +    { XK_F12,           0x58 },
819 +
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 },
828  
829 -static void sdl_cleanup(void) 
830 -{
831 -    SDL_Quit();
832 -}
833 +    { XK_Scroll_Lock,   0x46 },
834 +    { XK_Caps_Lock,     0xba3a }
835 +};
836  
837 -void sdl_display_init(DisplayState *ds, int full_screen)
838 +static void x_refresh(DisplayState *ds)
839  {
840 -    int flags;
841 -
842 -#if defined(__APPLE__)
843 -    /* always use generic keymaps */
844 -    if (!keyboard_layout)
845 -        keyboard_layout = "en-us";
846 +  XEvent report;
847 +  KeySym key;
848 +  int mouse_update = 0;
849 +  unsigned scan;
850 +  XButtonEvent *button_event;
851 +  XExposeEvent *expose_event;
852 +  int count;
853 +  static int gui_key_modifier_pressed;
854 +
855 +  if (last_vm_running != vm_running) {
856 +      last_vm_running = vm_running;
857 +      x_SetCaption();
858 +  }
859 +
860 +  if (is_active_console(vga_console))
861 +       vga_update_display();
862 +
863 +  while (XPending(qx_display) > 0)  {
864 +    XNextEvent(qx_display, &report);
865 +
866 +    switch  (report.type) {
867 +
868 +    case Expose:
869 +      expose_event = &report.xexpose;
870 +      x_update(ds, expose_event->x, expose_event->y, expose_event->width, expose_event->height);
871 +      break;
872 +
873 +    case ButtonPress:
874 +      button_event = (XButtonEvent *) &report;
875 +      current_x = button_event->x;
876 +      current_y = button_event->y;
877 +      switch (button_event->button) {
878 +       case Button1:
879 +         if(!gui_grab) {
880 +               /* start grabbing all events */
881 +               trigger_mouse_grab();
882 +               break;
883 +         }
884 +         mouse_button_state |= 0x01;
885 +         mouse_update = 1;
886 +         break;
887 +       case Button2:
888 +         mouse_button_state |= 0x04;
889 +         mouse_update = 1;
890 +         break;
891 +       case Button3:
892 +         mouse_button_state |= 0x02;
893 +         mouse_update = 1;
894 +         break;
895 +       }
896 +      break;
897 +
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) {
903 +       case Button1:
904 +         mouse_button_state &= ~0x01;
905 +         mouse_update = 1;
906 +         break;
907 +       case Button2:
908 +         mouse_button_state &= ~0x04;
909 +         mouse_update = 1;
910 +         break;
911 +       case Button3:
912 +         mouse_button_state &= ~0x02;
913 +         mouse_update = 1;
914 +         break;
915 +       }
916 +      break;
917 +
918 +    case KeyPress:
919 +    case KeyRelease:
920 +      key = XLookupKeysym(&report.xkey, 0);
921 +
922 +      if(key == XK_Shift_L) {
923 +       if(report.type == KeyPress)
924 +               gui_key_modifier_pressed |= 5;
925 +       else
926 +               gui_key_modifier_pressed &= ~1;
927 +      } else if(key == XK_Control_L) {
928 +       if(report.type == KeyPress)
929 +               gui_key_modifier_pressed |= 6;
930 +       else
931 +               gui_key_modifier_pressed &= ~2;
932 +      }
933 +      if((gui_key_modifier_pressed & 7) == 7) {
934 +       trigger_mouse_grab();
935 +       gui_key_modifier_pressed &= ~4;
936 +       break;
937 +      }
938 +
939 +      /* XK_F21 is for sun type 4 keyboards.. */
940 +      if (key == XK_Break || key == XK_F21)
941 +         key = XK_Pause;
942 +
943 +      if (key == XK_Pause) {
944 +         if (report.xkey.state & ControlMask)
945 +             scan = 0xc6e046e0;
946 +         else
947 +             scan = 0x451de1;
948 +      }                   /* XK_F22 is sun type 4 PrtScr */
949 +      else if (key == XK_Print || key == XK_F22) {
950 +         if (report.xkey.state & Mod1Mask)
951 +             scan = 0x54;
952 +         else
953 +             scan = 0x37e02ae0;
954 +      }
955 +#ifdef KBUK
956 +      else if ((key == XK_numbersign) && (report.xkey.state & ShiftMask))
957 +         scan = 0x4;
958  #endif
959 -    if(keyboard_layout) {
960 -        kbd_layout = init_keyboard_layout(keyboard_layout);
961 -        if (!kbd_layout)
962 -            exit(1);
963 -    }
964 -
965 -    flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE;
966 -    if (SDL_Init (flags)) {
967 -        fprintf(stderr, "Could not initialize SDL - exiting\n");
968 -        exit(1);
969 -    }
970 -#ifndef _WIN32
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);
974 -#endif
975 -
976 -    ds->dpy_update = sdl_update;
977 -    ds->dpy_resize = sdl_resize;
978 -    ds->dpy_refresh = sdl_refresh;
979 -
980 -    sdl_resize(ds, 640, 400);
981 -    sdl_update_caption();
982 -    SDL_EnableKeyRepeat(250, 50);
983 -    SDL_EnableUNICODE(1);
984 -    gui_grab = 0;
985 -
986 -    atexit(sdl_cleanup);
987 -    if (full_screen) {
988 -        gui_fullscreen = 1;
989 -        gui_fullscreen_initial_grab = 1;
990 -        sdl_grab_start();
991 -    }
992 +      else if (key == XK_sterling)
993 +         scan = 0x4;
994 +      else {
995 +         if (key >= 0x20 && key <= 0x20+sizeof(scan_table1))
996 +                 scan = scan_table1[key - 0x20];
997 +          else   {
998 +                 scan = 0;
999 +                 for (count = 0; count <
1000 +                      (sizeof(scan_table2)/sizeof(scan_table2[0]));
1001 +                      count++)
1002 +                         if (scan_table2[count].key == key) {
1003 +                                 scan = scan_table2[count].scan_code;
1004 +                                 break;
1005 +                                 }
1006 +                 }
1007 +         if (scan == 0)
1008 +                 break;
1009 +         }
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));
1014 +         else
1015 +             kbd_put_keycode(scan & 0xff);
1016 +
1017 +         scan >>= 8;
1018 +       }
1019 +      break;
1020 +
1021 +    case MotionNotify:
1022 +      current_x = report.xmotion.x;
1023 +      current_y = report.xmotion.y;
1024 +      mouse_update = 1;
1025 +      break;
1026 +
1027 +    default:
1028 +      break;
1029 +    } /* end switch */
1030 +
1031 +    if (mouse_update && gui_grab) {
1032 +       send_keyboard_mouse_status();
1033 +       mouse_update = 0;
1034 +    }
1035 +  } /* end while */
1036 +}
1037 +
1038 +void X_display_init(DisplayState *ds, int full_screen)
1039 +{
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 */
1046 +  XGCValues values;
1047 +  char *progname = "qemu";
1048 +  XEvent report;
1049 +
1050 +  if ( (qx_display=XOpenDisplay(NULL)) == NULL ) {
1051 +       fprintf(stderr, "Could not open X display\n");
1052 +       exit(1);
1053 +  }
1054 +  /* get screen size from display structure macro */
1055 +  q_x_screen_num = DefaultScreen(qx_display);
1056 +
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 */
1061 +    400,
1062 +    4,        /* border_width four pixels */
1063 +    BlackPixel(qx_display, q_x_screen_num),
1064 +    BlackPixel(qx_display, q_x_screen_num));
1065 +
1066 +  default_depth  = DefaultDepth(qx_display, q_x_screen_num);
1067 +  default_visual = DefaultVisual(qx_display, q_x_screen_num);
1068 +
1069 +  icon_pixmap = XCreateBitmapFromData(qx_display, win, icon_bits,
1070 +                                       icon_width, icon_height);
1071 +
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;
1075 +
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;
1080 +
1081 +  class_hints.res_name = "qemu";
1082 +  class_hints.res_class = "Qemu";
1083 +
1084 +  XSetWMProperties(qx_display, win,
1085 +                    NULL, NULL, // windowName iconName, set from x_SetCaption
1086 +                    &progname, 1, &size_hints, &wm_hints,
1087 +                    &class_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);
1092 +
1093 +  XSelectInput(qx_display, win,
1094 +               KeyPressMask | KeyReleaseMask |
1095 +               ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
1096 +               ExposureMask| StructureNotifyMask);
1097 +
1098 +  gc = XCreateGC(qx_display, win, valuemask, &values);
1099 +
1100 +  XSetForeground(qx_display, gc, WhitePixel(qx_display, q_x_screen_num));
1101 +  XSetBackground(qx_display, gc, BlackPixel(qx_display, q_x_screen_num));
1102 +
1103 +  /* Display window */
1104 +  XMapWindow(qx_display, win);
1105 +  XSync(qx_display, /* no discard */ 0);
1106 +
1107 +  while (1) {
1108 +    XNextEvent(qx_display, &report);
1109 +    if (report.type == MapNotify) break;
1110 +  }
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();
1116  }
This page took 0.107783 seconds and 4 git commands to generate.