x11.cc Source File

Back to the index.

x11.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2018 Anders Gavare. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  *
28  * X11-related functions.
29  */
30 
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 
35 #include "console.h"
36 #include "emul.h"
37 #include "machine.h"
38 #include "misc.h"
39 #include "x11.h"
40 
41 
42 #ifndef WITH_X11
43 
44 
45 /* Dummy functions: */
46 void x11_redraw_cursor(struct machine *m, int i) { }
47 void x11_redraw(struct machine *m, int x) { }
48 void x11_putpixel_fb(struct machine *m, int fb, int x, int y, int color) { }
49 void x11_init(struct machine *machine) { }
50 struct fb_window *x11_fb_init(int xsize, int ysize, char *name,
51  int scaledown, struct machine *machine)
52  { return NULL; }
53 void x11_check_event(struct emul *emul) { }
54 
55 
56 #else /* WITH_X11 */
57 
58 
59 #include <X11/Xlib.h>
60 #include <X11/Xutil.h>
61 #include <X11/cursorfont.h>
62 
63 
64 /*
65  * x11_redraw_cursor():
66  *
67  * Redraw a framebuffer's X11 cursor.
68  *
69  * NOTE: It is up to the caller to call XFlush.
70  */
71 void x11_redraw_cursor(struct machine *m, int i)
72 {
73  int last_color_used = 0;
74  int n_colors_used = 0;
75  struct fb_window *fbwin = m->x11_md.fb_windows[i];
76 
77  /* Remove old cursor, if any: */
78  if (fbwin->x11_display != NULL && fbwin->OLD_cursor_on) {
79  XPutImage(fbwin->x11_display, fbwin->x11_fb_window,
80  fbwin->x11_fb_gc, fbwin->fb_ximage,
81  fbwin->OLD_cursor_x/fbwin->scaledown,
82  fbwin->OLD_cursor_y/fbwin->scaledown,
83  fbwin->OLD_cursor_x/fbwin->scaledown,
84  fbwin->OLD_cursor_y/fbwin->scaledown,
85  fbwin->OLD_cursor_xsize/fbwin->scaledown + 1,
86  fbwin->OLD_cursor_ysize/fbwin->scaledown + 1);
87  }
88 
89  if (fbwin->x11_display != NULL && fbwin->cursor_on) {
90  int x, y, subx, suby;
91  XImage *xtmp;
92 
93  CHECK_ALLOCATION(xtmp = XSubImage(fbwin->fb_ximage,
94  fbwin->cursor_x/fbwin->scaledown,
95  fbwin->cursor_y/fbwin->scaledown,
96  fbwin->cursor_xsize/fbwin->scaledown + 1,
97  fbwin->cursor_ysize/fbwin->scaledown + 1));
98 
99  for (y=0; y<fbwin->cursor_ysize;
100  y+=fbwin->scaledown)
101  for (x=0; x<fbwin->cursor_xsize;
102  x+=fbwin->scaledown) {
103  int px = x/fbwin->scaledown;
104  int py = y/fbwin->scaledown;
105  int p = 0, n = 0, c = 0;
106  unsigned long oldcol;
107 
108  for (suby=0; suby<fbwin->scaledown;
109  suby++)
110  for (subx=0; subx<fbwin->
111  scaledown; subx++) {
112  c = fbwin->
113  cursor_pixels[y+suby]
114  [x+subx];
115  if (c >= 0) {
116  p += c;
117  n++;
118  }
119  }
120  if (n > 0)
121  p /= n;
122  else
123  p = c;
124 
125  if (n_colors_used == 0) {
126  last_color_used = p;
127  n_colors_used = 1;
128  } else
129  if (p != last_color_used)
130  n_colors_used = 2;
131 
132  switch (p) {
134  break;
135  case CURSOR_COLOR_INVERT:
136  oldcol = XGetPixel(xtmp, px, py);
137  if (oldcol != fbwin->
138  x11_graycolor[N_GRAYCOLORS-1].pixel)
139  oldcol = fbwin->
141  -1].pixel;
142  else
143  oldcol = fbwin->
144  x11_graycolor[0].pixel;
145  XPutPixel(xtmp, px, py, oldcol);
146  break;
147  default: /* Normal grayscale: */
148  XPutPixel(xtmp, px, py, fbwin->
149  x11_graycolor[p].pixel);
150  }
151  }
152 
153  XPutImage(fbwin->x11_display,
154  fbwin->x11_fb_window,
155  fbwin->x11_fb_gc,
156  xtmp, 0, 0,
157  fbwin->cursor_x/fbwin->scaledown,
158  fbwin->cursor_y/fbwin->scaledown,
159  fbwin->cursor_xsize/fbwin->scaledown,
160  fbwin->cursor_ysize/fbwin->scaledown);
161 
162  XDestroyImage(xtmp);
163 
164  fbwin->OLD_cursor_on = fbwin->cursor_on;
165  fbwin->OLD_cursor_x = fbwin->cursor_x;
166  fbwin->OLD_cursor_y = fbwin->cursor_y;
167  fbwin->OLD_cursor_xsize =
168  fbwin->cursor_xsize;
169  fbwin->OLD_cursor_ysize =
170  fbwin->cursor_ysize;
171  }
172 
173  /* printf("n_colors_used = %i\n", n_colors_used); */
174 
175  if (fbwin->host_cursor != 0 && n_colors_used < 2) {
176  /* Remove the old X11 host cursor: */
177  XUndefineCursor(fbwin->x11_display,
178  fbwin->x11_fb_window);
179  XFreeCursor(fbwin->x11_display,
180  fbwin->host_cursor);
181  fbwin->host_cursor = 0;
182  }
183 
184  if (n_colors_used >= 2 && fbwin->host_cursor == 0) {
185  GC tmpgc;
186 
187  /* Create a new X11 host cursor: */
188  /* cursor = XCreateFontCursor(fbwin->x11_display,
189  XC_coffee_mug); :-) */
190  if (fbwin->host_cursor_pixmap != 0) {
191  XFreePixmap(fbwin->x11_display,
192  fbwin->host_cursor_pixmap);
193  fbwin->host_cursor_pixmap = 0;
194  }
195  fbwin->host_cursor_pixmap =
196  XCreatePixmap(fbwin->x11_display,
197  fbwin->x11_fb_window, 1, 1, 1);
198  XSetForeground(fbwin->x11_display,
199  fbwin->x11_fb_gc,
200  fbwin->x11_graycolor[0].pixel);
201 
202  tmpgc = XCreateGC(fbwin->x11_display,
203  fbwin->host_cursor_pixmap, 0,0);
204 
205  XDrawPoint(fbwin->x11_display,
206  fbwin->host_cursor_pixmap,
207  tmpgc, 0, 0);
208 
209  XFreeGC(fbwin->x11_display, tmpgc);
210 
211  fbwin->host_cursor =
212  XCreatePixmapCursor(fbwin->x11_display,
213  fbwin->host_cursor_pixmap,
214  fbwin->host_cursor_pixmap,
215  &fbwin->x11_graycolor[N_GRAYCOLORS-1],
216  &fbwin->x11_graycolor[N_GRAYCOLORS-1],
217  0, 0);
218  if (fbwin->host_cursor != 0) {
219  XDefineCursor(fbwin->x11_display,
220  fbwin->x11_fb_window,
221  fbwin->host_cursor);
222  }
223  }
224 }
225 
226 
227 /*
228  * x11_redraw():
229  *
230  * Redraw X11 windows.
231  */
232 void x11_redraw(struct machine *m, int i)
233 {
234  if (i < 0 || i >= m->x11_md.n_fb_windows ||
235  m->x11_md.fb_windows[i]->x11_fb_winxsize <= 0)
236  return;
237 
238  x11_putimage_fb(m, i);
239  x11_redraw_cursor(m, i);
240  XFlush(m->x11_md.fb_windows[i]->x11_display);
241 }
242 
243 
244 /*
245  * x11_putpixel_fb():
246  *
247  * Output a framebuffer pixel. i is the framebuffer number.
248  */
249 void x11_putpixel_fb(struct machine *m, int i, int x, int y, int color)
250 {
251  struct fb_window *fbwin;
252  if (i < 0 || i >= m->x11_md.n_fb_windows)
253  return;
254 
255  fbwin = m->x11_md.fb_windows[i];
256 
257  if (fbwin->x11_fb_winxsize <= 0)
258  return;
259 
260  if (color)
261  XSetForeground(fbwin->x11_display,
262  fbwin->x11_fb_gc, fbwin->fg_color);
263  else
264  XSetForeground(fbwin->x11_display,
265  fbwin->x11_fb_gc, fbwin->bg_color);
266 
267  XDrawPoint(fbwin->x11_display,
268  fbwin->x11_fb_window, fbwin->x11_fb_gc, x, y);
269 
270  XFlush(fbwin->x11_display);
271 }
272 
273 
274 /*
275  * x11_putimage_fb():
276  *
277  * Output an entire XImage to a framebuffer window. i is the
278  * framebuffer number.
279  */
280 void x11_putimage_fb(struct machine *m, int i)
281 {
282  struct fb_window *fbwin;
283  if (i < 0 || i >= m->x11_md.n_fb_windows)
284  return;
285 
286  fbwin = m->x11_md.fb_windows[i];
287 
288  if (fbwin->x11_fb_winxsize <= 0)
289  return;
290 
291  XPutImage(fbwin->x11_display,
292  fbwin->x11_fb_window,
293  fbwin->x11_fb_gc, fbwin->fb_ximage, 0,0, 0,0,
294  fbwin->x11_fb_winxsize,
295  fbwin->x11_fb_winysize);
296  XFlush(fbwin->x11_display);
297 }
298 
299 
300 /*
301  * x11_init():
302  *
303  * Initialize X11 stuff (but doesn't create any windows).
304  *
305  * It is then up to individual drivers, for example framebuffer devices,
306  * to initialize their own windows.
307  */
308 void x11_init(struct machine *m)
309 {
310  m->x11_md.n_fb_windows = 0;
311 
312  if (m->x11_md.n_display_names > 0) {
313  int i;
314  for (i=0; i<m->x11_md.n_display_names; i++)
315  fatal("Using X11 display: %s\n",
316  m->x11_md.display_names[i]);
317  }
318 
320 }
321 
322 
323 /*
324  * x11_fb_resize():
325  *
326  * Set a new size for an X11 framebuffer window. (NOTE: I didn't think of
327  * this kind of functionality during the initial design, so it is probably
328  * buggy. It also needs some refactoring.)
329  */
330 void x11_fb_resize(struct fb_window *win, int new_xsize, int new_ysize)
331 {
332  int alloc_depth;
333 
334  if (win == NULL) {
335  fatal("x11_fb_resize(): win == NULL\n");
336  return;
337  }
338 
339  win->x11_fb_winxsize = new_xsize;
340  win->x11_fb_winysize = new_ysize;
341 
342  alloc_depth = win->x11_screen_depth;
343  if (alloc_depth == 24)
344  alloc_depth = 32;
345  if (alloc_depth == 15)
346  alloc_depth = 16;
347 
348  /* Note: ximage_data seems to be freed by XDestroyImage below. */
349  /* if (win->ximage_data != NULL)
350  free(win->ximage_data); */
351  CHECK_ALLOCATION(win->ximage_data = (unsigned char *) malloc(
352  new_xsize * new_ysize * alloc_depth / 8));
353 
354  /* TODO: clear for non-truecolor modes */
355  memset(win->ximage_data, 0, new_xsize * new_ysize * alloc_depth / 8);
356 
357  if (win->fb_ximage != NULL)
358  XDestroyImage(win->fb_ximage);
359  win->fb_ximage = XCreateImage(win->x11_display, CopyFromParent,
360  win->x11_screen_depth, ZPixmap, 0, (char *)win->ximage_data,
361  new_xsize, new_ysize, 8, new_xsize * alloc_depth / 8);
363 
364  XResizeWindow(win->x11_display, win->x11_fb_window,
365  new_xsize, new_ysize);
366 }
367 
368 
369 /*
370  * x11_set_standard_properties():
371  *
372  * Right now, this only sets the title of a window.
373  */
374 void x11_set_standard_properties(struct fb_window *fb_window, char *name)
375 {
376  XSetStandardProperties(fb_window->x11_display,
377  fb_window->x11_fb_window, name, "GXemul " VERSION,
378  None, NULL, 0, NULL);
379 }
380 
381 
382 /*
383  * x11_fb_init():
384  *
385  * Initialize a framebuffer window.
386  */
387 struct fb_window *x11_fb_init(int xsize, int ysize, char *name,
388  int scaledown, struct machine *m)
389 {
390  Display *x11_display;
391  int x, y, fb_number = 0;
392  size_t alloclen, alloc_depth;
393  XColor tmpcolor;
394  struct fb_window *fbwin;
395  int i;
396  char fg[80], bg[80];
397  char *display_name;
398 
400 
402  (struct fb_window **) realloc(m->x11_md.fb_windows,
403  sizeof(struct fb_window *) * (m->x11_md.n_fb_windows + 1)));
405  (struct fb_window *) malloc(sizeof(struct fb_window)));
406 
407  m->x11_md.n_fb_windows ++;
408 
409  memset(fbwin, 0, sizeof(struct fb_window));
410 
411  fbwin->x11_fb_winxsize = xsize;
412  fbwin->x11_fb_winysize = ysize;
413 
414  /* Which display name? */
415  display_name = NULL;
416  if (m->x11_md.n_display_names > 0) {
417  display_name = m->x11_md.display_names[
421  }
422 
423  if (display_name != NULL)
424  debug("[ x11_fb_init(): framebuffer window %i, %ix%i, DISPLAY"
425  "=%s ]\n", fb_number, xsize, ysize, display_name);
426 
427  x11_display = XOpenDisplay(display_name);
428 
429  if (x11_display == NULL) {
430  fatal("x11_fb_init(\"%s\"): couldn't open display\n", name);
431  if (display_name != NULL)
432  fatal("display_name = '%s'\n", display_name);
433  exit(1);
434  }
435 
436  fbwin->x11_screen =
437  DefaultScreen(x11_display);
438  fbwin->x11_screen_depth =
439  DefaultDepth(x11_display,
440  fbwin->x11_screen);
441 
442  if (fbwin->x11_screen_depth != 8 &&
443  fbwin->x11_screen_depth != 15 &&
444  fbwin->x11_screen_depth != 16 &&
445  fbwin->x11_screen_depth != 24) {
446  fatal("\n***\n*** WARNING! Your X server is running %i-bit "
447  "color mode. This is not really\n",
448  fbwin->x11_screen_depth);
449  fatal("*** supported yet. 8, 15, 16, and 24 bits should "
450  "work.\n*** 24-bit server gives color. Any other bit "
451  "depth gives undefined result!\n***\n\n");
452  }
453 
454  if (fbwin->x11_screen_depth <= 8)
455  debug("WARNING! X11 screen depth is not enough for color; "
456  "using only 16 grayscales instead\n");
457 
458  strlcpy(bg, "Black", sizeof(bg));
459  strlcpy(fg, "White", sizeof(fg));
460 
461  XParseColor(x11_display, DefaultColormap(x11_display,
462  fbwin->x11_screen), fg, &tmpcolor);
463  XAllocColor(x11_display, DefaultColormap(x11_display,
464  fbwin->x11_screen), &tmpcolor);
465  fbwin->fg_color = tmpcolor.pixel;
466  XParseColor(x11_display, DefaultColormap(x11_display,
467  fbwin->x11_screen), bg, &tmpcolor);
468  XAllocColor(x11_display, DefaultColormap(x11_display,
469  fbwin->x11_screen), &tmpcolor);
470  fbwin->bg_color = tmpcolor.pixel;
471 
472  for (i=0; i<N_GRAYCOLORS; i++) {
473  char cname[8];
474  cname[0] = '#';
475  cname[1] = cname[2] = cname[3] =
476  cname[4] = cname[5] = cname[6] =
477  "0123456789ABCDEF"[i];
478  cname[7] = '\0';
479  XParseColor(x11_display, DefaultColormap(x11_display,
480  fbwin->x11_screen), cname,
481  &fbwin->x11_graycolor[i]);
482  XAllocColor(x11_display, DefaultColormap(x11_display,
483  fbwin->x11_screen),
484  &fbwin->x11_graycolor[i]);
485  }
486 
487  XFlush(x11_display);
488 
489  alloc_depth = fbwin->x11_screen_depth;
490 
491  if (alloc_depth == 24)
492  alloc_depth = 32;
493  if (alloc_depth == 15)
494  alloc_depth = 16;
495 
496  fbwin->x11_fb_window = XCreateWindow(
497  x11_display, DefaultRootWindow(x11_display),
498  0, 0, fbwin->x11_fb_winxsize,
499  fbwin->x11_fb_winysize,
500  0, CopyFromParent, InputOutput, CopyFromParent, 0,0);
501 
502  fbwin->x11_display = x11_display;
503 
504  x11_set_standard_properties(fbwin, name);
505 
506  XSelectInput(x11_display,
507  fbwin->x11_fb_window,
508  StructureNotifyMask | ExposureMask | ButtonPressMask |
509  ButtonReleaseMask | PointerMotionMask | KeyPressMask);
510  fbwin->x11_fb_gc = XCreateGC(x11_display,
511  fbwin->x11_fb_window, 0,0);
512 
513  /* Make sure the window is mapped: */
514  XMapRaised(x11_display, fbwin->x11_fb_window);
515 
516  XSetBackground(x11_display, fbwin->x11_fb_gc, fbwin->bg_color);
517  XSetForeground(x11_display, fbwin->x11_fb_gc, fbwin->bg_color);
518  XFillRectangle(x11_display, fbwin->x11_fb_window, fbwin->x11_fb_gc, 0,0,
519  fbwin->x11_fb_winxsize, fbwin->x11_fb_winysize);
520 
521  fbwin->scaledown = scaledown;
522 
523  fbwin->fb_number = fb_number;
524 
525  alloclen = xsize * ysize * alloc_depth / 8;
526  CHECK_ALLOCATION(fbwin->ximage_data = (unsigned char *) malloc(alloclen));
527 
528  fbwin->fb_ximage = XCreateImage(fbwin->x11_display, CopyFromParent,
529  fbwin->x11_screen_depth, ZPixmap, 0, (char *)fbwin->ximage_data,
530  xsize, ysize, 8, xsize * alloc_depth / 8);
531  CHECK_ALLOCATION(fbwin->fb_ximage);
532 
533  /* Fill the ximage with black pixels: */
534  if (fbwin->x11_screen_depth > 8)
535  memset(fbwin->ximage_data, 0, alloclen);
536  else {
537  debug("x11_fb_init(): clearing the XImage\n");
538  for (y=0; y<ysize; y++)
539  for (x=0; x<xsize; x++)
540  XPutPixel(fbwin->fb_ximage, x, y,
541  fbwin->x11_graycolor[0].pixel);
542  }
543 
545 
546  /* Fill the 64x64 "hardware" cursor with white pixels: */
547  xsize = ysize = 64;
548 
549  /* Fill the cursor ximage with white pixels: */
550  for (y=0; y<ysize; y++)
551  for (x=0; x<xsize; x++)
552  fbwin->cursor_pixels[y][x] = N_GRAYCOLORS-1;
553 
554  return fbwin;
555 }
556 
557 
558 /*
559  * x11_check_events_machine():
560  *
561  * Check for X11 events on a specific machine.
562  *
563  * TODO: Yuck! This has to be rewritten. Each display should be checked,
564  * and _then_ only those windows that are actually exposed should
565  * be redrawn!
566  */
567 static void x11_check_events_machine(struct emul *emul, struct machine *m)
568 {
569  int fb_nr;
570 
571  for (fb_nr = 0; fb_nr < m->x11_md.n_fb_windows; fb_nr ++) {
572  struct fb_window *fbwin = m->x11_md.fb_windows[fb_nr];
573  XEvent event;
574  int need_redraw = 0, found, i, j;
575 
576  while (XPending(fbwin->x11_display)) {
577  XNextEvent(fbwin->x11_display, &event);
578 
579  if (event.type==ConfigureNotify) {
580  need_redraw = 1;
581  }
582 
583  if (event.type==Expose && event.xexpose.count==0) {
584  /*
585  * TODO: the xexpose struct has x,y,width,
586  * height. Those could be used to only redraw
587  * the part of the framebuffer that was
588  * exposed. Note that the (mouse) cursor must
589  * be redrawn too.
590  */
591  /* x11_winxsize = event.xexpose.width;
592  x11_winysize = event.xexpose.height; */
593  need_redraw = 1;
594  }
595 
596  if (event.type == MotionNotify) {
597  /* debug("[ X11 MotionNotify: %i,%i ]\n",
598  event.xmotion.x, event.xmotion.y); */
599 
600  /* Which window in which machine in
601  which emulation? */
602  found = -1;
603  for (j=0; j<emul->n_machines; j++) {
604  struct machine *m2 = emul->machines[j];
605  for (i=0; i<m2->x11_md.
606  n_fb_windows; i++)
607  if (m->x11_md.
608  fb_windows[fb_nr]->
609  x11_display == m2->
610  x11_md.
611  fb_windows[i]->
612  x11_display &&
613  event.xmotion.
614  window == m2->
615  x11_md.
616  fb_windows[i]->
617  x11_fb_window)
618  found = i;
619  }
620  if (found < 0) {
621  printf("Internal error in x11.c.\n");
622  exit(1);
623  }
624  console_mouse_coordinates(event.xmotion.x *
625  m->x11_md.fb_windows[found]->scaledown,
626  event.xmotion.y * m->x11_md.fb_windows[
627  found]->scaledown, found);
628  }
629 
630  if (event.type == ButtonPress) {
631  debug("[ X11 ButtonPress: %i ]\n",
632  event.xbutton.button);
633  /* button = 1,2,3 = left,middle,right */
634 
635  console_mouse_button(event.xbutton.button, 1);
636  }
637 
638  if (event.type == ButtonRelease) {
639  debug("[ X11 ButtonRelease: %i ]\n",
640  event.xbutton.button);
641  /* button = 1,2,3 = left,middle,right */
642 
643  console_mouse_button(event.xbutton.button, 0);
644  }
645 
646  if (event.type==KeyPress) {
647  char text[15];
648  KeySym key;
649  XKeyPressedEvent *ke = &event.xkey;
650 
651  memset(text, 0, sizeof(text));
652 
653  if (XLookupString(&event.xkey, text,
654  sizeof(text), &key, 0) == 1) {
656  m->main_console_handle, text[0]);
657  } else {
658  int x = ke->keycode;
659  /*
660  * Special key codes:
661  *
662  * NOTE/TODO: I'm hardcoding these to
663  * work with my key map. Maybe they
664  * should be read from some file...
665  *
666  * Important TODO 2: It would be MUCH
667  * better if these were converted into
668  * 'native scancodes', for example for
669  * the DECstation's keyboard or the
670  * PC-style 8042 controller.
671  */
672  switch (x) {
673  case 9: /* Escape */
675  main_console_handle, 27);
676  break;
677 #if 0
678  /* TODO */
679 
680  /* The numeric keypad: */
681  90=Ins('0') 91=Del(',')
682 
683  /* Above the cursor keys: */
684  106=Ins 107=Del
685 #endif
686  /* F1..F4: */
687  case 67: /* F1 */
688  case 68: /* F2 */
689  case 69: /* F3 */
690  case 70: /* F4 */
692  main_console_handle, 27);
694  main_console_handle, '[');
696  main_console_handle, 'O');
698  main_console_handle, 'P' +
699  x - 67);
700  break;
701  case 71: /* F5 */
703  main_console_handle, 27);
705  main_console_handle, '[');
707  main_console_handle, '1');
709  main_console_handle, '5');
710  break;
711  case 72: /* F6 */
712  case 73: /* F7 */
713  case 74: /* F8 */
715  main_console_handle, 27);
717  main_console_handle, '[');
719  main_console_handle, '1');
721  main_console_handle, '7' +
722  x - 72);
723  break;
724  case 75: /* F9 */
725  case 76: /* F10 */
727  main_console_handle, 27);
729  main_console_handle, '[');
731  main_console_handle, '2');
733  main_console_handle, '1' +
734  x - 68);
735  break;
736  case 95: /* F11 */
737  case 96: /* F12 */
739  main_console_handle, 27);
741  main_console_handle, '[');
743  main_console_handle, '2');
745  main_console_handle, '3' +
746  x - 95);
747  break;
748  /* Cursor keys: */
749  case 98: /* Up */
750  case 104: /* Down */
751  case 100: /* Left */
752  case 102: /* Right */
754  main_console_handle, 27);
756  main_console_handle, '[');
759  x == 98? 'A' : (
760  x == 104? 'B' : (
761  x == 102? 'C' : (
762  'D'))));
763  break;
764  /* Numeric keys: */
765  case 80: /* Up */
766  case 88: /* Down */
767  case 83: /* Left */
768  case 85: /* Right */
770  main_console_handle, 27);
772  main_console_handle, '[');
775  x == 80? 'A' : (
776  x == 88? 'B' : (
777  x == 85? 'C' : (
778  'D'))));
779  break;
780  case 97: /* Cursor Home */
781  case 79: /* Numeric Home */
783  main_console_handle, 27);
785  main_console_handle, '[');
787  main_console_handle, 'H');
788  break;
789  case 103: /* Cursor End */
790  case 87: /* Numeric End */
792  main_console_handle, 27);
794  main_console_handle, '[');
796  main_console_handle, 'F');
797  break;
798  case 99: /* Cursor PgUp */
799  case 81: /* Numeric PgUp */
801  main_console_handle, 27);
803  main_console_handle, '[');
805  main_console_handle, '5');
807  main_console_handle, '~');
808  break;
809  case 105: /* Cursor PgUp */
810  case 89: /* Numeric PgDn */
812  main_console_handle, 27);
814  main_console_handle, '[');
816  main_console_handle, '6');
818  main_console_handle, '~');
819  break;
820  default:
821  debug("[ unimplemented X11 "
822  "keycode %i ]\n", x);
823  }
824  }
825  }
826  }
827 
828  if (need_redraw)
829  x11_redraw(m, fb_nr);
830  }
831 }
832 
833 
834 /*
835  * x11_check_event():
836  *
837  * Check for X11 events.
838  */
839 void x11_check_event(struct emul *emul)
840 {
841  int i;
842 
843  for (i=0; i<emul->n_machines; i++)
844  x11_check_events_machine(emul, emul->machines[i]);
845 }
846 
847 #endif /* WITH_X11 */
fb_window::OLD_cursor_ysize
int OLD_cursor_ysize
Definition: x11.h:80
fb_window::x11_graycolor
XColor x11_graycolor[N_GRAYCOLORS]
Definition: x11.h:63
fb_window::scaledown
int scaledown
Definition: x11.h:56
fb_window::OLD_cursor_xsize
int OLD_cursor_xsize
Definition: x11.h:79
x11_init
void x11_init(struct machine *machine)
Definition: x11.cc:49
fb_window::cursor_on
int cursor_on
Definition: x11.h:76
console_makeavail
void console_makeavail(int handle, char ch)
Definition: console.cc:296
debug
#define debug
Definition: dev_adb.cc:57
x11_set_standard_properties
void x11_set_standard_properties(struct fb_window *fb_window, char *name)
fb_window::OLD_cursor_on
int OLD_cursor_on
Definition: x11.h:81
console_mouse_button
void console_mouse_button(int button, int pressed)
Definition: console.cc:480
x11_md
Definition: machine.h:80
fb_window::x11_screen
int x11_screen
Definition: x11.h:59
fb_window::x11_screen_depth
int x11_screen_depth
Definition: x11.h:60
emul::n_machines
int n_machines
Definition: emul.h:45
fb_window::cursor_xsize
int cursor_xsize
Definition: x11.h:74
x11_check_event
void x11_check_event(struct emul *emul)
Definition: x11.cc:53
x11_md::fb_windows
struct fb_window ** fb_windows
Definition: machine.h:90
fb_window::OLD_cursor_x
int OLD_cursor_x
Definition: x11.h:77
fb_window::fb_number
int fb_number
Definition: x11.h:51
console.h
fb_window::host_cursor_pixmap
Pixmap host_cursor_pixmap
Definition: x11.h:85
fb_window::x11_fb_winxsize
int x11_fb_winxsize
Definition: x11.h:55
fb_window::x11_fb_winysize
int x11_fb_winysize
Definition: x11.h:55
fb_window::x11_display
Display * x11_display
Definition: x11.h:57
fb_window::cursor_y
int cursor_y
Definition: x11.h:73
fb_window::x11_fb_gc
GC x11_fb_gc
Definition: x11.h:65
fatal
void fatal(const char *fmt,...)
Definition: main.cc:152
misc.h
fb_window::host_cursor
Cursor host_cursor
Definition: x11.h:84
CURSOR_COLOR_TRANSPARENT
#define CURSOR_COLOR_TRANSPARENT
Definition: x11.h:45
machine.h
x11_redraw
void x11_redraw(struct machine *m, int x)
Definition: x11.cc:47
machine
Definition: machine.h:97
machine::main_console_handle
int main_console_handle
Definition: machine.h:128
fb_window::cursor_x
int cursor_x
Definition: x11.h:72
emul.h
console_mouse_coordinates
void console_mouse_coordinates(int x, int y, int fb_nr)
Definition: console.cc:463
fb_window::fb_ximage
XImage * fb_ximage
Definition: x11.h:67
machine::x11_md
struct x11_md x11_md
Definition: machine.h:179
x11_md::display_names
char ** display_names
Definition: machine.h:86
x11_md::n_display_names
int n_display_names
Definition: machine.h:85
x11_putimage_fb
void x11_putimage_fb(struct machine *, int)
x11_md::n_fb_windows
int n_fb_windows
Definition: machine.h:89
fb_window::OLD_cursor_y
int OLD_cursor_y
Definition: x11.h:78
x11.h
x11_redraw_cursor
void x11_redraw_cursor(struct machine *m, int i)
Definition: x11.cc:46
N_GRAYCOLORS
#define N_GRAYCOLORS
Definition: x11.h:44
fb_window::cursor_ysize
int cursor_ysize
Definition: x11.h:75
x11_fb_init
struct fb_window * x11_fb_init(int xsize, int ysize, char *name, int scaledown, struct machine *machine)
Definition: x11.cc:50
fb_window::x11_fb_window
Window x11_fb_window
Definition: x11.h:64
emul
Definition: emul.h:37
fb_window::cursor_pixels
int cursor_pixels[CURSOR_MAXY][CURSOR_MAXX]
Definition: x11.h:71
fb_window
Definition: x11.h:50
fb_window::fg_color
unsigned long fg_color
Definition: x11.h:61
emul::machines
struct machine ** machines
Definition: emul.h:46
fb_window::ximage_data
unsigned char * ximage_data
Definition: x11.h:68
x11_putpixel_fb
void x11_putpixel_fb(struct machine *m, int fb, int x, int y, int color)
Definition: x11.cc:48
fb_window::bg_color
unsigned long bg_color
Definition: x11.h:62
x11_md::current_display_name_nr
int current_display_name_nr
Definition: machine.h:87
CURSOR_COLOR_INVERT
#define CURSOR_COLOR_INVERT
Definition: x11.h:46
x11_fb_resize
void x11_fb_resize(struct fb_window *win, int new_xsize, int new_ysize)
CHECK_ALLOCATION
#define CHECK_ALLOCATION(ptr)
Definition: misc.h:239

Generated on Tue Mar 24 2020 14:04:48 for GXemul by doxygen 1.8.17