/[gxemul]/trunk/src/x11.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/x11.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 41 by dpavlin, Mon Oct 8 16:21:53 2007 UTC revision 42 by dpavlin, Mon Oct 8 16:22:32 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: x11.c,v 1.64 2007/03/29 06:52:19 debug Exp $   *  $Id: x11.c,v 1.65 2007/06/15 17:02:38 debug Exp $
29   *   *
30   *  X11-related functions.   *  X11-related functions.
31   */   */
# Line 74  void x11_redraw_cursor(struct machine *m Line 74  void x11_redraw_cursor(struct machine *m
74  {  {
75          int last_color_used = 0;          int last_color_used = 0;
76          int n_colors_used = 0;          int n_colors_used = 0;
77            struct fb_window *fbwin = m->x11_md.fb_windows[i];
78    
79          /*  Remove old cursor, if any:  */          /*  Remove old cursor, if any:  */
80          if (m->fb_windows[i]->x11_display != NULL &&          if (fbwin->x11_display != NULL && fbwin->OLD_cursor_on) {
81              m->fb_windows[i]->OLD_cursor_on) {                  XPutImage(fbwin->x11_display, fbwin->x11_fb_window,
82                  XPutImage(m->fb_windows[i]->x11_display,                      fbwin->x11_fb_gc, fbwin->fb_ximage,
83                      m->fb_windows[i]->x11_fb_window,                      fbwin->OLD_cursor_x/fbwin->scaledown,
84                      m->fb_windows[i]->x11_fb_gc, m->fb_windows[i]->fb_ximage,                      fbwin->OLD_cursor_y/fbwin->scaledown,
85                      m->fb_windows[i]->OLD_cursor_x/m->fb_windows[i]->scaledown,                      fbwin->OLD_cursor_x/fbwin->scaledown,
86                      m->fb_windows[i]->OLD_cursor_y/m->fb_windows[i]->scaledown,                      fbwin->OLD_cursor_y/fbwin->scaledown,
87                      m->fb_windows[i]->OLD_cursor_x/m->fb_windows[i]->scaledown,                      fbwin->OLD_cursor_xsize/fbwin->scaledown + 1,
88                      m->fb_windows[i]->OLD_cursor_y/m->fb_windows[i]->scaledown,                      fbwin->OLD_cursor_ysize/fbwin->scaledown + 1);
                     m->fb_windows[i]->OLD_cursor_xsize/  
                     m->fb_windows[i]->scaledown + 1,  
                     m->fb_windows[i]->OLD_cursor_ysize/  
                     m->fb_windows[i]->scaledown + 1);  
89          }          }
90    
91          if (m->fb_windows[i]->x11_display != NULL &&          if (fbwin->x11_display != NULL && fbwin->cursor_on) {
             m->fb_windows[i]->cursor_on) {  
92                  int x, y, subx, suby;                  int x, y, subx, suby;
93                  XImage *xtmp;                  XImage *xtmp;
94    
95                  xtmp = XSubImage(m->fb_windows[i]->fb_ximage,                  CHECK_ALLOCATION(xtmp = XSubImage(fbwin->fb_ximage,
96                      m->fb_windows[i]->cursor_x/m->fb_windows[i]->scaledown,                      fbwin->cursor_x/fbwin->scaledown,
97                      m->fb_windows[i]->cursor_y/m->fb_windows[i]->scaledown,                      fbwin->cursor_y/fbwin->scaledown,
98                      m->fb_windows[i]->cursor_xsize/                      fbwin->cursor_xsize/fbwin->scaledown + 1,
99                      m->fb_windows[i]->scaledown + 1,                      fbwin->cursor_ysize/fbwin->scaledown + 1));
100                      m->fb_windows[i]->cursor_ysize/  
101                      m->fb_windows[i]->scaledown + 1);                  for (y=0; y<fbwin->cursor_ysize;
102                  if (xtmp == NULL) {                      y+=fbwin->scaledown)
103                          fatal("out of memory in x11_redraw_cursor()\n");                          for (x=0; x<fbwin->cursor_xsize;
104                          return;                              x+=fbwin->scaledown) {
105                  }                                  int px = x/fbwin->scaledown;
106                                    int py = y/fbwin->scaledown;
                 for (y=0; y<m->fb_windows[i]->cursor_ysize;  
                     y+=m->fb_windows[i]->scaledown)  
                         for (x=0; x<m->fb_windows[i]->cursor_xsize;  
                             x+=m->fb_windows[i]->scaledown) {  
                                 int px = x/m->fb_windows[i]->scaledown;  
                                 int py = y/m->fb_windows[i]->scaledown;  
107                                  int p = 0, n = 0, c = 0;                                  int p = 0, n = 0, c = 0;
108                                  unsigned long oldcol;                                  unsigned long oldcol;
109    
110                                  for (suby=0; suby<m->fb_windows[i]->scaledown;                                  for (suby=0; suby<fbwin->scaledown;
111                                      suby++)                                      suby++)
112                                          for (subx=0; subx<m->fb_windows[i]->                                          for (subx=0; subx<fbwin->
113                                              scaledown; subx++) {                                              scaledown; subx++) {
114                                                  c = m->fb_windows[i]->                                                  c = fbwin->
115                                                      cursor_pixels[y+suby]                                                      cursor_pixels[y+suby]
116                                                      [x+subx];                                                      [x+subx];
117                                                  if (c >= 0) {                                                  if (c >= 0) {
# Line 146  void x11_redraw_cursor(struct machine *m Line 136  void x11_redraw_cursor(struct machine *m
136                                          break;                                          break;
137                                  case CURSOR_COLOR_INVERT:                                  case CURSOR_COLOR_INVERT:
138                                          oldcol = XGetPixel(xtmp, px, py);                                          oldcol = XGetPixel(xtmp, px, py);
139                                          if (oldcol != m->fb_windows[i]->                                          if (oldcol != fbwin->
140                                              x11_graycolor[N_GRAYCOLORS-1].pixel)                                              x11_graycolor[N_GRAYCOLORS-1].pixel)
141                                                  oldcol = m->fb_windows[i]->                                                  oldcol = fbwin->
142                                                      x11_graycolor[N_GRAYCOLORS                                                      x11_graycolor[N_GRAYCOLORS
143                                                      -1].pixel;                                                      -1].pixel;
144                                          else                                          else
145                                                  oldcol = m->fb_windows[i]->                                                  oldcol = fbwin->
146                                                      x11_graycolor[0].pixel;                                                      x11_graycolor[0].pixel;
147                                          XPutPixel(xtmp, px, py, oldcol);                                          XPutPixel(xtmp, px, py, oldcol);
148                                          break;                                          break;
149                                  default:        /*  Normal grayscale:  */                                  default:        /*  Normal grayscale:  */
150                                          XPutPixel(xtmp, px, py, m->fb_windows[                                          XPutPixel(xtmp, px, py, fbwin->
151                                              i]->x11_graycolor[p].pixel);                                              x11_graycolor[p].pixel);
152                                  }                                  }
153                          }                          }
154    
155                  XPutImage(m->fb_windows[i]->x11_display,                  XPutImage(fbwin->x11_display,
156                      m->fb_windows[i]->x11_fb_window,                      fbwin->x11_fb_window,
157                      m->fb_windows[i]->x11_fb_gc,                      fbwin->x11_fb_gc,
158                      xtmp, 0, 0,                      xtmp, 0, 0,
159                      m->fb_windows[i]->cursor_x/m->fb_windows[i]->scaledown,                      fbwin->cursor_x/fbwin->scaledown,
160                      m->fb_windows[i]->cursor_y/m->fb_windows[i]->scaledown,                      fbwin->cursor_y/fbwin->scaledown,
161                      m->fb_windows[i]->cursor_xsize/m->fb_windows[i]->scaledown,                      fbwin->cursor_xsize/fbwin->scaledown,
162                      m->fb_windows[i]->cursor_ysize/m->fb_windows[i]->scaledown);                      fbwin->cursor_ysize/fbwin->scaledown);
163    
164                  XDestroyImage(xtmp);                  XDestroyImage(xtmp);
165    
166                  m->fb_windows[i]->OLD_cursor_on = m->fb_windows[i]->cursor_on;                  fbwin->OLD_cursor_on = fbwin->cursor_on;
167                  m->fb_windows[i]->OLD_cursor_x = m->fb_windows[i]->cursor_x;                  fbwin->OLD_cursor_x = fbwin->cursor_x;
168                  m->fb_windows[i]->OLD_cursor_y = m->fb_windows[i]->cursor_y;                  fbwin->OLD_cursor_y = fbwin->cursor_y;
169                  m->fb_windows[i]->OLD_cursor_xsize =                  fbwin->OLD_cursor_xsize =
170                      m->fb_windows[i]->cursor_xsize;                      fbwin->cursor_xsize;
171                  m->fb_windows[i]->OLD_cursor_ysize =                  fbwin->OLD_cursor_ysize =
172                      m->fb_windows[i]->cursor_ysize;                      fbwin->cursor_ysize;
173          }          }
174    
175          /*  printf("n_colors_used = %i\n", n_colors_used);  */          /*  printf("n_colors_used = %i\n", n_colors_used);  */
176    
177          if (m->fb_windows[i]->host_cursor != 0 && n_colors_used < 2) {          if (fbwin->host_cursor != 0 && n_colors_used < 2) {
178                  /*  Remove the old X11 host cursor:  */                  /*  Remove the old X11 host cursor:  */
179                  XUndefineCursor(m->fb_windows[i]->x11_display,                  XUndefineCursor(fbwin->x11_display,
180                      m->fb_windows[i]->x11_fb_window);                      fbwin->x11_fb_window);
181                  XFreeCursor(m->fb_windows[i]->x11_display,                  XFreeCursor(fbwin->x11_display,
182                      m->fb_windows[i]->host_cursor);                      fbwin->host_cursor);
183                  m->fb_windows[i]->host_cursor = 0;                  fbwin->host_cursor = 0;
184          }          }
185    
186          if (n_colors_used >= 2 && m->fb_windows[i]->host_cursor == 0) {          if (n_colors_used >= 2 && fbwin->host_cursor == 0) {
187                  GC tmpgc;                  GC tmpgc;
188    
189                  /*  Create a new X11 host cursor:  */                  /*  Create a new X11 host cursor:  */
190                  /*  cursor = XCreateFontCursor(m->fb_windows[i]->x11_display,                  /*  cursor = XCreateFontCursor(fbwin->x11_display,
191                      XC_coffee_mug);  :-)  */                      XC_coffee_mug);  :-)  */
192                  if (m->fb_windows[i]->host_cursor_pixmap != 0) {                  if (fbwin->host_cursor_pixmap != 0) {
193                          XFreePixmap(m->fb_windows[i]->x11_display,                          XFreePixmap(fbwin->x11_display,
194                              m->fb_windows[i]->host_cursor_pixmap);                              fbwin->host_cursor_pixmap);
195                          m->fb_windows[i]->host_cursor_pixmap = 0;                          fbwin->host_cursor_pixmap = 0;
196                  }                  }
197                  m->fb_windows[i]->host_cursor_pixmap =                  fbwin->host_cursor_pixmap =
198                      XCreatePixmap(m->fb_windows[i]->x11_display,                      XCreatePixmap(fbwin->x11_display,
199                      m->fb_windows[i]->x11_fb_window, 1, 1, 1);                      fbwin->x11_fb_window, 1, 1, 1);
200                  XSetForeground(m->fb_windows[i]->x11_display,                  XSetForeground(fbwin->x11_display,
201                      m->fb_windows[i]->x11_fb_gc,                      fbwin->x11_fb_gc,
202                      m->fb_windows[i]->x11_graycolor[0].pixel);                      fbwin->x11_graycolor[0].pixel);
203    
204                  tmpgc = XCreateGC(m->fb_windows[i]->x11_display,                  tmpgc = XCreateGC(fbwin->x11_display,
205                      m->fb_windows[i]->host_cursor_pixmap, 0,0);                      fbwin->host_cursor_pixmap, 0,0);
206    
207                  XDrawPoint(m->fb_windows[i]->x11_display,                  XDrawPoint(fbwin->x11_display,
208                      m->fb_windows[i]->host_cursor_pixmap,                      fbwin->host_cursor_pixmap,
209                      tmpgc, 0, 0);                      tmpgc, 0, 0);
210    
211                  XFreeGC(m->fb_windows[i]->x11_display, tmpgc);                  XFreeGC(fbwin->x11_display, tmpgc);
212    
213                  m->fb_windows[i]->host_cursor =                  fbwin->host_cursor =
214                      XCreatePixmapCursor(m->fb_windows[i]->x11_display,                      XCreatePixmapCursor(fbwin->x11_display,
215                      m->fb_windows[i]->host_cursor_pixmap,                      fbwin->host_cursor_pixmap,
216                      m->fb_windows[i]->host_cursor_pixmap,                      fbwin->host_cursor_pixmap,
217                      &m->fb_windows[i]->x11_graycolor[N_GRAYCOLORS-1],                      &fbwin->x11_graycolor[N_GRAYCOLORS-1],
218                      &m->fb_windows[i]->x11_graycolor[N_GRAYCOLORS-1],                      &fbwin->x11_graycolor[N_GRAYCOLORS-1],
219                      0, 0);                      0, 0);
220                  if (m->fb_windows[i]->host_cursor != 0) {                  if (fbwin->host_cursor != 0) {
221                          XDefineCursor(m->fb_windows[i]->x11_display,                          XDefineCursor(fbwin->x11_display,
222                              m->fb_windows[i]->x11_fb_window,                              fbwin->x11_fb_window,
223                              m->fb_windows[i]->host_cursor);                              fbwin->host_cursor);
224                  }                  }
225          }          }
226  }  }
# Line 243  void x11_redraw_cursor(struct machine *m Line 233  void x11_redraw_cursor(struct machine *m
233   */   */
234  void x11_redraw(struct machine *m, int i)  void x11_redraw(struct machine *m, int i)
235  {  {
236          if (i < 0 || i >= m->n_fb_windows ||          if (i < 0 || i >= m->x11_md.n_fb_windows ||
237              m->fb_windows[i]->x11_fb_winxsize <= 0)              m->x11_md.fb_windows[i]->x11_fb_winxsize <= 0)
238                  return;                  return;
239    
240          x11_putimage_fb(m, i);          x11_putimage_fb(m, i);
241          x11_redraw_cursor(m, i);          x11_redraw_cursor(m, i);
242          XFlush(m->fb_windows[i]->x11_display);          XFlush(m->x11_md.fb_windows[i]->x11_display);
243  }  }
244    
245    
# Line 260  void x11_redraw(struct machine *m, int i Line 250  void x11_redraw(struct machine *m, int i
250   */   */
251  void x11_putpixel_fb(struct machine *m, int i, int x, int y, int color)  void x11_putpixel_fb(struct machine *m, int i, int x, int y, int color)
252  {  {
253          if (i < 0 || i >= m->n_fb_windows ||          struct fb_window *fbwin;
254              m->fb_windows[i]->x11_fb_winxsize <= 0)          if (i < 0 || i >= m->x11_md.n_fb_windows)
255                    return;
256    
257            fbwin = m->x11_md.fb_windows[i];
258    
259            if (fbwin->x11_fb_winxsize <= 0)
260                  return;                  return;
261    
262          if (color)          if (color)
263                  XSetForeground(m->fb_windows[i]->x11_display,                  XSetForeground(fbwin->x11_display,
264                      m->fb_windows[i]->x11_fb_gc, m->fb_windows[i]->fg_color);                      fbwin->x11_fb_gc, fbwin->fg_color);
265          else          else
266                  XSetForeground(m->fb_windows[i]->x11_display,                  XSetForeground(fbwin->x11_display,
267                      m->fb_windows[i]->x11_fb_gc, m->fb_windows[i]->bg_color);                      fbwin->x11_fb_gc, fbwin->bg_color);
268    
269          XDrawPoint(m->fb_windows[i]->x11_display,          XDrawPoint(fbwin->x11_display,
270              m->fb_windows[i]->x11_fb_window, m->fb_windows[i]->x11_fb_gc, x, y);              fbwin->x11_fb_window, fbwin->x11_fb_gc, x, y);
271    
272          XFlush(m->fb_windows[i]->x11_display);          XFlush(fbwin->x11_display);
273  }  }
274    
275    
# Line 286  void x11_putpixel_fb(struct machine *m, Line 281  void x11_putpixel_fb(struct machine *m,
281   */   */
282  void x11_putimage_fb(struct machine *m, int i)  void x11_putimage_fb(struct machine *m, int i)
283  {  {
284          if (i < 0 || i >= m->n_fb_windows ||          struct fb_window *fbwin;
285              m->fb_windows[i]->x11_fb_winxsize <= 0)          if (i < 0 || i >= m->x11_md.n_fb_windows)
286                  return;                  return;
287    
288          XPutImage(m->fb_windows[i]->x11_display,          fbwin = m->x11_md.fb_windows[i];
289              m->fb_windows[i]->x11_fb_window,  
290              m->fb_windows[i]->x11_fb_gc, m->fb_windows[i]->fb_ximage, 0,0, 0,0,          if (fbwin->x11_fb_winxsize <= 0)
291              m->fb_windows[i]->x11_fb_winxsize,                  return;
292              m->fb_windows[i]->x11_fb_winysize);  
293          XFlush(m->fb_windows[i]->x11_display);          XPutImage(fbwin->x11_display,
294                fbwin->x11_fb_window,
295                fbwin->x11_fb_gc, fbwin->fb_ximage, 0,0, 0,0,
296                fbwin->x11_fb_winxsize,
297                fbwin->x11_fb_winysize);
298            XFlush(fbwin->x11_display);
299  }  }
300    
301    
# Line 309  void x11_putimage_fb(struct machine *m, Line 309  void x11_putimage_fb(struct machine *m,
309   */   */
310  void x11_init(struct machine *m)  void x11_init(struct machine *m)
311  {  {
312          m->n_fb_windows = 0;          m->x11_md.n_fb_windows = 0;
313    
314          if (m->x11_n_display_names > 0) {          if (m->x11_md.n_display_names > 0) {
315                  int i;                  int i;
316                  for (i=0; i<m->x11_n_display_names; i++)                  for (i=0; i<m->x11_md.n_display_names; i++)
317                          fatal("Using X11 display: %s\n",                          fatal("Using X11 display: %s\n",
318                              m->x11_display_names[i]);                              m->x11_md.display_names[i]);
319          }          }
320    
321          m->x11_current_display_name_nr = 0;          m->x11_md.current_display_name_nr = 0;
322  }  }
323    
324    
# Line 350  void x11_fb_resize(struct fb_window *win Line 350  void x11_fb_resize(struct fb_window *win
350          /*  Note: ximage_data seems to be freed by XDestroyImage below.  */          /*  Note: ximage_data seems to be freed by XDestroyImage below.  */
351          /*  if (win->ximage_data != NULL)          /*  if (win->ximage_data != NULL)
352                  free(win->ximage_data);  */                  free(win->ximage_data);  */
353          win->ximage_data = malloc(new_xsize * new_ysize * alloc_depth / 8);          CHECK_ALLOCATION(win->ximage_data = malloc(
354          if (win->ximage_data == NULL) {              new_xsize * new_ysize * alloc_depth / 8));
                 fprintf(stderr, "x11_fb_resize(): out of memory "  
                     "allocating ximage_data\n");  
                 exit(1);  
         }  
355    
356          /*  TODO: clear for non-truecolor modes  */          /*  TODO: clear for non-truecolor modes  */
357          memset(win->ximage_data, 0, new_xsize * new_ysize * alloc_depth / 8);          memset(win->ximage_data, 0, new_xsize * new_ysize * alloc_depth / 8);
# Line 365  void x11_fb_resize(struct fb_window *win Line 361  void x11_fb_resize(struct fb_window *win
361          win->fb_ximage = XCreateImage(win->x11_display, CopyFromParent,          win->fb_ximage = XCreateImage(win->x11_display, CopyFromParent,
362              win->x11_screen_depth, ZPixmap, 0, (char *)win->ximage_data,              win->x11_screen_depth, ZPixmap, 0, (char *)win->ximage_data,
363              new_xsize, new_ysize, 8, new_xsize * alloc_depth / 8);              new_xsize, new_ysize, 8, new_xsize * alloc_depth / 8);
364          if (win->fb_ximage == NULL) {          CHECK_ALLOCATION(win->fb_ximage);
                 fprintf(stderr, "x11_fb_resize(): out of memory "  
                     "allocating fb_ximage\n");  
                 exit(1);  
         }  
365    
366          XResizeWindow(win->x11_display, win->x11_fb_window,          XResizeWindow(win->x11_display, win->x11_fb_window,
367              new_xsize, new_ysize);              new_xsize, new_ysize);
# Line 406  struct fb_window *x11_fb_init(int xsize, Line 398  struct fb_window *x11_fb_init(int xsize,
398          int x, y, fb_number = 0;          int x, y, fb_number = 0;
399          size_t alloclen, alloc_depth;          size_t alloclen, alloc_depth;
400          XColor tmpcolor;          XColor tmpcolor;
401            struct fb_window *fbwin;
402          int i;          int i;
403          char fg[80], bg[80];          char fg[80], bg[80];
404          char *display_name;          char *display_name;
405    
406          fb_number = m->n_fb_windows;          fb_number = m->x11_md.n_fb_windows;
407    
408          m->fb_windows = realloc(m->fb_windows,          CHECK_ALLOCATION(m->x11_md.fb_windows = realloc(m->x11_md.fb_windows,
409              sizeof(struct fb_window *) * (m->n_fb_windows + 1));              sizeof(struct fb_window *) * (m->x11_md.n_fb_windows + 1)));
410          if (m->fb_windows == NULL) {          CHECK_ALLOCATION(fbwin = m->x11_md.fb_windows[fb_number] =
411                  fprintf(stderr, "x11_fb_init(): out of memory\n");              malloc(sizeof(struct fb_window)));
                 exit(1);  
         }  
         m->fb_windows[fb_number] = malloc(sizeof(struct fb_window));  
         if (m->fb_windows[fb_number] == NULL) {  
                 fprintf(stderr, "x11_fb_init(): out of memory\n");  
                 exit(1);  
         }  
412    
413          m->n_fb_windows ++;          m->x11_md.n_fb_windows ++;
414    
415          memset(m->fb_windows[fb_number], 0, sizeof(struct fb_window));          memset(fbwin, 0, sizeof(struct fb_window));
416    
417          m->fb_windows[fb_number]->x11_fb_winxsize = xsize;          fbwin->x11_fb_winxsize = xsize;
418          m->fb_windows[fb_number]->x11_fb_winysize = ysize;          fbwin->x11_fb_winysize = ysize;
419    
420          /*  Which display name?  */          /*  Which display name?  */
421          display_name = NULL;          display_name = NULL;
422          if (m->x11_n_display_names > 0) {          if (m->x11_md.n_display_names > 0) {
423                  display_name = m->x11_display_names[                  display_name = m->x11_md.display_names[
424                      m->x11_current_display_name_nr];                      m->x11_md.current_display_name_nr];
425                  m->x11_current_display_name_nr ++;                  m->x11_md.current_display_name_nr ++;
426                  m->x11_current_display_name_nr %= m->x11_n_display_names;                  m->x11_md.current_display_name_nr %= m->x11_md.n_display_names;
427          }          }
428    
429          if (display_name != NULL)          if (display_name != NULL)
# Line 453  struct fb_window *x11_fb_init(int xsize, Line 439  struct fb_window *x11_fb_init(int xsize,
439                  exit(1);                  exit(1);
440          }          }
441    
442          m->fb_windows[fb_number]->x11_screen = DefaultScreen(x11_display);          fbwin->x11_screen =
443          m->fb_windows[fb_number]->x11_screen_depth = DefaultDepth(x11_display,              DefaultScreen(x11_display);
444              m->fb_windows[fb_number]->x11_screen);          fbwin->x11_screen_depth =
445                DefaultDepth(x11_display,
446          if (m->fb_windows[fb_number]->x11_screen_depth != 8 &&              fbwin->x11_screen);
447              m->fb_windows[fb_number]->x11_screen_depth != 15 &&  
448              m->fb_windows[fb_number]->x11_screen_depth != 16 &&          if (fbwin->x11_screen_depth != 8 &&
449              m->fb_windows[fb_number]->x11_screen_depth != 24) {              fbwin->x11_screen_depth != 15 &&
450                fbwin->x11_screen_depth != 16 &&
451                fbwin->x11_screen_depth != 24) {
452                  fatal("\n***\n***  WARNING! Your X server is running %i-bit "                  fatal("\n***\n***  WARNING! Your X server is running %i-bit "
453                      "color mode. This is not really\n",                      "color mode. This is not really\n",
454                      m->fb_windows[fb_number]->x11_screen_depth);                      fbwin->x11_screen_depth);
455                  fatal("***  supported yet.  8, 15, 16, and 24 bits should "                  fatal("***  supported yet.  8, 15, 16, and 24 bits should "
456                      "work.\n***  24-bit server gives color.  Any other bit "                      "work.\n***  24-bit server gives color.  Any other bit "
457                      "depth gives undefined result!\n***\n\n");                      "depth gives undefined result!\n***\n\n");
458          }          }
459    
460          if (m->fb_windows[fb_number]->x11_screen_depth <= 8)          if (fbwin->x11_screen_depth <= 8)
461                  debug("WARNING! X11 screen depth is not enough for color; "                  debug("WARNING! X11 screen depth is not enough for color; "
462                      "using only 16 grayscales instead\n");                      "using only 16 grayscales instead\n");
463    
# Line 477  struct fb_window *x11_fb_init(int xsize, Line 465  struct fb_window *x11_fb_init(int xsize,
465          strlcpy(fg, "White", sizeof(fg));          strlcpy(fg, "White", sizeof(fg));
466    
467          XParseColor(x11_display, DefaultColormap(x11_display,          XParseColor(x11_display, DefaultColormap(x11_display,
468              m->fb_windows[fb_number]->x11_screen), fg, &tmpcolor);              fbwin->x11_screen), fg, &tmpcolor);
469          XAllocColor(x11_display, DefaultColormap(x11_display,          XAllocColor(x11_display, DefaultColormap(x11_display,
470              m->fb_windows[fb_number]->x11_screen), &tmpcolor);              fbwin->x11_screen), &tmpcolor);
471          m->fb_windows[fb_number]->fg_color = tmpcolor.pixel;          fbwin->fg_color = tmpcolor.pixel;
472          XParseColor(x11_display, DefaultColormap(x11_display,          XParseColor(x11_display, DefaultColormap(x11_display,
473              m->fb_windows[fb_number]->x11_screen), bg, &tmpcolor);              fbwin->x11_screen), bg, &tmpcolor);
474          XAllocColor(x11_display, DefaultColormap(x11_display,          XAllocColor(x11_display, DefaultColormap(x11_display,
475              m->fb_windows[fb_number]->x11_screen), &tmpcolor);              fbwin->x11_screen), &tmpcolor);
476          m->fb_windows[fb_number]->bg_color = tmpcolor.pixel;          fbwin->bg_color = tmpcolor.pixel;
477    
478          for (i=0; i<N_GRAYCOLORS; i++) {          for (i=0; i<N_GRAYCOLORS; i++) {
479                  char cname[8];                  char cname[8];
# Line 495  struct fb_window *x11_fb_init(int xsize, Line 483  struct fb_window *x11_fb_init(int xsize,
483                      "0123456789ABCDEF"[i];                      "0123456789ABCDEF"[i];
484                  cname[7] = '\0';                  cname[7] = '\0';
485                  XParseColor(x11_display, DefaultColormap(x11_display,                  XParseColor(x11_display, DefaultColormap(x11_display,
486                      m->fb_windows[fb_number]->x11_screen), cname,                      fbwin->x11_screen), cname,
487                      &m->fb_windows[fb_number]->x11_graycolor[i]);                      &fbwin->x11_graycolor[i]);
488                  XAllocColor(x11_display, DefaultColormap(x11_display,                  XAllocColor(x11_display, DefaultColormap(x11_display,
489                      m->fb_windows[fb_number]->x11_screen),                      fbwin->x11_screen),
490                      &m->fb_windows[fb_number]->x11_graycolor[i]);                      &fbwin->x11_graycolor[i]);
491          }          }
492    
493          XFlush(x11_display);          XFlush(x11_display);
494    
495          alloc_depth = m->fb_windows[fb_number]->x11_screen_depth;          alloc_depth = fbwin->x11_screen_depth;
496    
497          if (alloc_depth == 24)          if (alloc_depth == 24)
498                  alloc_depth = 32;                  alloc_depth = 32;
499          if (alloc_depth == 15)          if (alloc_depth == 15)
500                  alloc_depth = 16;                  alloc_depth = 16;
501    
502          m->fb_windows[fb_number]->x11_fb_window = XCreateWindow(          fbwin->x11_fb_window = XCreateWindow(
503              x11_display, DefaultRootWindow(x11_display),              x11_display, DefaultRootWindow(x11_display),
504              0, 0, m->fb_windows[fb_number]->x11_fb_winxsize,              0, 0, fbwin->x11_fb_winxsize,
505              m->fb_windows[fb_number]->x11_fb_winysize,              fbwin->x11_fb_winysize,
506              0, CopyFromParent, InputOutput, CopyFromParent, 0,0);              0, CopyFromParent, InputOutput, CopyFromParent, 0,0);
507    
508          m->fb_windows[fb_number]->x11_display = x11_display;          fbwin->x11_display = x11_display;
509    
510          x11_set_standard_properties(m->fb_windows[fb_number], name);          x11_set_standard_properties(fbwin, name);
511    
512          XSelectInput(x11_display, m->fb_windows[fb_number]->x11_fb_window,          XSelectInput(x11_display,
513                fbwin->x11_fb_window,
514              StructureNotifyMask | ExposureMask | ButtonPressMask |              StructureNotifyMask | ExposureMask | ButtonPressMask |
515              ButtonReleaseMask | PointerMotionMask | KeyPressMask);              ButtonReleaseMask | PointerMotionMask | KeyPressMask);
516          m->fb_windows[fb_number]->x11_fb_gc = XCreateGC(x11_display,          fbwin->x11_fb_gc = XCreateGC(x11_display,
517              m->fb_windows[fb_number]->x11_fb_window, 0,0);              fbwin->x11_fb_window, 0,0);
518    
519          /*  Make sure the window is mapped:  */          /*  Make sure the window is mapped:  */
520          XMapRaised(x11_display, m->fb_windows[fb_number]->x11_fb_window);          XMapRaised(x11_display, fbwin->x11_fb_window);
521    
522          XSetBackground(x11_display, m->fb_windows[fb_number]->x11_fb_gc,          XSetBackground(x11_display, fbwin->x11_fb_gc, fbwin->bg_color);
523              m->fb_windows[fb_number]->bg_color);          XSetForeground(x11_display, fbwin->x11_fb_gc, fbwin->bg_color);
524          XSetForeground(x11_display, m->fb_windows[fb_number]->x11_fb_gc,          XFillRectangle(x11_display, fbwin->x11_fb_window, fbwin->x11_fb_gc, 0,0,
525              m->fb_windows[fb_number]->bg_color);              fbwin->x11_fb_winxsize, fbwin->x11_fb_winysize);
         XFillRectangle(x11_display, m->fb_windows[fb_number]->x11_fb_window,  
             m->fb_windows[fb_number]->x11_fb_gc, 0,0,  
             m->fb_windows[fb_number]->x11_fb_winxsize,  
             m->fb_windows[fb_number]->x11_fb_winysize);  
526    
527          m->fb_windows[fb_number]->scaledown   = scaledown;          fbwin->scaledown   = scaledown;
528    
529          m->fb_windows[fb_number]->fb_number = fb_number;          fbwin->fb_number = fb_number;
530    
531          alloclen = xsize * ysize * alloc_depth / 8;          alloclen = xsize * ysize * alloc_depth / 8;
532          m->fb_windows[fb_number]->ximage_data = malloc(alloclen);          CHECK_ALLOCATION(fbwin->ximage_data = malloc(alloclen));
         if (m->fb_windows[fb_number]->ximage_data == NULL) {  
                 fprintf(stderr, "out of memory allocating ximage_data\n");  
                 exit(1);  
         }  
533    
534          m->fb_windows[fb_number]->fb_ximage = XCreateImage(          fbwin->fb_ximage = XCreateImage(fbwin->x11_display, CopyFromParent,
535              m->fb_windows[fb_number]->x11_display, CopyFromParent,              fbwin->x11_screen_depth, ZPixmap, 0, (char *)fbwin->ximage_data,
             m->fb_windows[fb_number]->x11_screen_depth, ZPixmap, 0,  
             (char *)m->fb_windows[fb_number]->ximage_data,  
536              xsize, ysize, 8, xsize * alloc_depth / 8);              xsize, ysize, 8, xsize * alloc_depth / 8);
537          if (m->fb_windows[fb_number]->fb_ximage == NULL) {          CHECK_ALLOCATION(fbwin->fb_ximage);
                 fprintf(stderr, "out of memory allocating ximage\n");  
                 exit(1);  
         }  
538    
539          /*  Fill the ximage with black pixels:  */          /*  Fill the ximage with black pixels:  */
540          if (m->fb_windows[fb_number]->x11_screen_depth > 8)          if (fbwin->x11_screen_depth > 8)
541                  memset(m->fb_windows[fb_number]->ximage_data, 0, alloclen);                  memset(fbwin->ximage_data, 0, alloclen);
542          else {          else {
543                  debug("x11_fb_init(): clearing the XImage\n");                  debug("x11_fb_init(): clearing the XImage\n");
544                  for (y=0; y<ysize; y++)                  for (y=0; y<ysize; y++)
545                          for (x=0; x<xsize; x++)                          for (x=0; x<xsize; x++)
546                                  XPutPixel(m->fb_windows[fb_number]->fb_ximage,                                  XPutPixel(fbwin->fb_ximage, x, y,
547                                      x, y, m->fb_windows[fb_number]->                                      fbwin->x11_graycolor[0].pixel);
                                     x11_graycolor[0].pixel);  
548          }          }
549    
550          x11_putimage_fb(m, fb_number);          x11_putimage_fb(m, fb_number);
# Line 580  struct fb_window *x11_fb_init(int xsize, Line 555  struct fb_window *x11_fb_init(int xsize,
555          /*  Fill the cursor ximage with white pixels:  */          /*  Fill the cursor ximage with white pixels:  */
556          for (y=0; y<ysize; y++)          for (y=0; y<ysize; y++)
557                  for (x=0; x<xsize; x++)                  for (x=0; x<xsize; x++)
558                          m->fb_windows[fb_number]->cursor_pixels[y][x] =                          fbwin->cursor_pixels[y][x] = N_GRAYCOLORS-1;
                             N_GRAYCOLORS-1;  
559    
560          return m->fb_windows[fb_number];          return fbwin;
561  }  }
562    
563    
# Line 601  static void x11_check_events_machine(str Line 575  static void x11_check_events_machine(str
575  {  {
576          int fb_nr;          int fb_nr;
577    
578          for (fb_nr=0; fb_nr<m->n_fb_windows; fb_nr++) {          for (fb_nr = 0; fb_nr < m->x11_md.n_fb_windows; fb_nr ++) {
579                    struct fb_window *fbwin = m->x11_md.fb_windows[fb_nr];
580                  XEvent event;                  XEvent event;
581                  int need_redraw = 0, found, i, j, k;                  int need_redraw = 0, found, i, j, k;
582    
583                  while (XPending(m->fb_windows[fb_nr]->x11_display)) {                  while (XPending(fbwin->x11_display)) {
584                          XNextEvent(m->fb_windows[fb_nr]->x11_display, &event);                          XNextEvent(fbwin->x11_display, &event);
585    
586                          if (event.type==ConfigureNotify) {                          if (event.type==ConfigureNotify) {
587                                  need_redraw = 1;                                  need_redraw = 1;
# Line 636  static void x11_check_events_machine(str Line 611  static void x11_check_events_machine(str
611                                          for (j=0; j<emuls[k]->n_machines; j++) {                                          for (j=0; j<emuls[k]->n_machines; j++) {
612                                                  struct machine *m2 = emuls[k]->                                                  struct machine *m2 = emuls[k]->
613                                                      machines[j];                                                      machines[j];
614                                                  for (i=0; i<m2->n_fb_windows;                                                  for (i=0; i<m2->x11_md.
615                                                      i++)                                                      n_fb_windows; i++)
616                                                          if (m->fb_windows[                                                          if (m->x11_md.
617                                                              fb_nr]->                                                              fb_windows[fb_nr]->
618                                                              x11_display == m2->                                                              x11_display == m2->
619                                                                x11_md.
620                                                              fb_windows[i]->                                                              fb_windows[i]->
621                                                              x11_display &&                                                              x11_display &&
622                                                              event.xmotion.                                                              event.xmotion.
623                                                              window == m2->                                                              window == m2->
624                                                                x11_md.
625                                                              fb_windows[i]->                                                              fb_windows[i]->
626                                                              x11_fb_window)                                                              x11_fb_window)
627                                                                  found = i;                                                                  found = i;
# Line 654  static void x11_check_events_machine(str Line 631  static void x11_check_events_machine(str
631                                          exit(1);                                          exit(1);
632                                  }                                  }
633                                  console_mouse_coordinates(event.xmotion.x *                                  console_mouse_coordinates(event.xmotion.x *
634                                      m->fb_windows[found]->scaledown,                                      m->x11_md.fb_windows[found]->scaledown,
635                                      event.xmotion.y * m->fb_windows[found]->                                      event.xmotion.y * m->x11_md.fb_windows[
636                                      scaledown, found);                                      found]->scaledown, found);
637                          }                          }
638    
639                          if (event.type == ButtonPress) {                          if (event.type == ButtonPress) {

Legend:
Removed from v.41  
changed lines
  Added in v.42

  ViewVC Help
Powered by ViewVC 1.1.26