/[gxemul]/upstream/0.4.1/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 /upstream/0.4.1/src/x11.c

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

revision 2 by dpavlin, Mon Oct 8 16:17:48 2007 UTC revision 28 by dpavlin, Mon Oct 8 16:20:26 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-2006  Anders Gavare.  All rights reserved.
3   *   *
4   *  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
5   *  modification, are permitted provided that the following conditions are met:   *  modification, are permitted provided that the following conditions are met:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: x11.c,v 1.56 2005/03/05 12:17:53 debug Exp $   *  $Id: x11.c,v 1.62 2006/07/08 12:30:02 debug Exp $
29   *   *
30   *  X11-related functions.   *  X11-related functions.
31   */   */
# Line 67  void x11_check_event(struct emul **emuls Line 67  void x11_check_event(struct emul **emuls
67   *  x11_redraw_cursor():   *  x11_redraw_cursor():
68   *   *
69   *  Redraw a framebuffer's X11 cursor.   *  Redraw a framebuffer's X11 cursor.
70     *
71     *  NOTE: It is up to the caller to call XFlush.
72   */   */
73  void x11_redraw_cursor(struct machine *m, int i)  void x11_redraw_cursor(struct machine *m, int i)
74  {  {
# Line 178  void x11_redraw_cursor(struct machine *m Line 180  void x11_redraw_cursor(struct machine *m
180                      m->fb_windows[i]->cursor_xsize;                      m->fb_windows[i]->cursor_xsize;
181                  m->fb_windows[i]->OLD_cursor_ysize =                  m->fb_windows[i]->OLD_cursor_ysize =
182                      m->fb_windows[i]->cursor_ysize;                      m->fb_windows[i]->cursor_ysize;
                 XFlush(m->fb_windows[i]->x11_display);  
183          }          }
184    
185          /*  printf("n_colors_used = %i\n", n_colors_used);  */          /*  printf("n_colors_used = %i\n", n_colors_used);  */
# Line 187  void x11_redraw_cursor(struct machine *m Line 188  void x11_redraw_cursor(struct machine *m
188                  /*  Remove the old X11 host cursor:  */                  /*  Remove the old X11 host cursor:  */
189                  XUndefineCursor(m->fb_windows[i]->x11_display,                  XUndefineCursor(m->fb_windows[i]->x11_display,
190                      m->fb_windows[i]->x11_fb_window);                      m->fb_windows[i]->x11_fb_window);
                 XFlush(m->fb_windows[i]->x11_display);  
191                  XFreeCursor(m->fb_windows[i]->x11_display,                  XFreeCursor(m->fb_windows[i]->x11_display,
192                      m->fb_windows[i]->host_cursor);                      m->fb_windows[i]->host_cursor);
193                  m->fb_windows[i]->host_cursor = 0;                  m->fb_windows[i]->host_cursor = 0;
# Line 231  void x11_redraw_cursor(struct machine *m Line 231  void x11_redraw_cursor(struct machine *m
231                          XDefineCursor(m->fb_windows[i]->x11_display,                          XDefineCursor(m->fb_windows[i]->x11_display,
232                              m->fb_windows[i]->x11_fb_window,                              m->fb_windows[i]->x11_fb_window,
233                              m->fb_windows[i]->host_cursor);                              m->fb_windows[i]->host_cursor);
                         XFlush(m->fb_windows[i]->x11_display);  
234                  }                  }
235          }          }
236  }  }
# Line 324  void x11_init(struct machine *m) Line 323  void x11_init(struct machine *m)
323    
324    
325  /*  /*
326     *  x11_fb_resize():
327     *
328     *  Set a new size for an X11 framebuffer window.  (NOTE: I didn't think of
329     *  this kind of functionality during the initial design, so it is probably
330     *  buggy. It also needs some refactoring.)
331     */
332    void x11_fb_resize(struct fb_window *win, int new_xsize, int new_ysize)
333    {
334            int alloc_depth;
335    
336            if (win == NULL) {
337                    fatal("x11_fb_resize(): win == NULL\n");
338                    return;
339            }
340    
341            win->x11_fb_winxsize = new_xsize;
342            win->x11_fb_winysize = new_ysize;
343    
344            alloc_depth = win->x11_screen_depth;
345            if (alloc_depth == 24)
346                    alloc_depth = 32;
347            if (alloc_depth == 15)
348                    alloc_depth = 16;
349    
350            /*  Note: ximage_data seems to be freed by XDestroyImage below.  */
351            /*  if (win->ximage_data != NULL)
352                    free(win->ximage_data);  */
353            win->ximage_data = malloc(new_xsize * new_ysize * alloc_depth / 8);
354            if (win->ximage_data == NULL) {
355                    fprintf(stderr, "x11_fb_resize(): out of memory "
356                        "allocating ximage_data\n");
357                    exit(1);
358            }
359    
360            /*  TODO: clear for non-truecolor modes  */
361            memset(win->ximage_data, 0, new_xsize * new_ysize * alloc_depth / 8);
362    
363            if (win->fb_ximage != NULL)
364                    XDestroyImage(win->fb_ximage);
365            win->fb_ximage = XCreateImage(win->x11_display, CopyFromParent,
366                win->x11_screen_depth, ZPixmap, 0, (char *)win->ximage_data,
367                new_xsize, new_ysize, 8, new_xsize * alloc_depth / 8);
368            if (win->fb_ximage == NULL) {
369                    fprintf(stderr, "x11_fb_resize(): out of memory "
370                        "allocating fb_ximage\n");
371                    exit(1);
372            }
373    
374            XResizeWindow(win->x11_display, win->x11_fb_window,
375                new_xsize, new_ysize);
376    }
377    
378    
379    /*
380     *  x11_set_standard_properties():
381     *
382     *  Right now, this only sets the title of a window.
383     */
384    void x11_set_standard_properties(struct fb_window *fb_window, char *name)
385    {
386            XSetStandardProperties(fb_window->x11_display,
387                fb_window->x11_fb_window, name,
388    #ifdef VERSION
389                "GXemul-" VERSION,
390    #else
391                "GXemul",
392    #endif
393                None, NULL, 0, NULL);
394    }
395    
396    
397    /*
398   *  x11_fb_init():   *  x11_fb_init():
399   *   *
400   *  Initialize a framebuffer window.   *  Initialize a framebuffer window.
# Line 402  struct fb_window *x11_fb_init(int xsize, Line 473  struct fb_window *x11_fb_init(int xsize,
473                  debug("WARNING! X11 screen depth is not enough for color; "                  debug("WARNING! X11 screen depth is not enough for color; "
474                      "using only 16 grayscales instead\n");                      "using only 16 grayscales instead\n");
475    
476          strcpy(bg, "Black");          strlcpy(bg, "Black", sizeof(bg));
477          strcpy(fg, "White");          strlcpy(fg, "White", sizeof(fg));
478    
479          XParseColor(x11_display, DefaultColormap(x11_display,          XParseColor(x11_display, DefaultColormap(x11_display,
480              m->fb_windows[fb_number]->x11_screen), fg, &tmpcolor);              m->fb_windows[fb_number]->x11_screen), fg, &tmpcolor);
# Line 446  struct fb_window *x11_fb_init(int xsize, Line 517  struct fb_window *x11_fb_init(int xsize,
517              m->fb_windows[fb_number]->x11_fb_winysize,              m->fb_windows[fb_number]->x11_fb_winysize,
518              0, CopyFromParent, InputOutput, CopyFromParent, 0,0);              0, CopyFromParent, InputOutput, CopyFromParent, 0,0);
519    
520          XSetStandardProperties(x11_display,          m->fb_windows[fb_number]->x11_display = x11_display;
521              m->fb_windows[fb_number]->x11_fb_window, name,  
522  #ifdef VERSION          x11_set_standard_properties(m->fb_windows[fb_number], name);
523              "GXemul-" VERSION,  
 #else  
             "GXemul",  
 #endif  
             None, NULL, 0, NULL);  
524          XSelectInput(x11_display, m->fb_windows[fb_number]->x11_fb_window,          XSelectInput(x11_display, m->fb_windows[fb_number]->x11_fb_window,
525              StructureNotifyMask | ExposureMask | ButtonPressMask |              StructureNotifyMask | ExposureMask | ButtonPressMask |
526              ButtonReleaseMask | PointerMotionMask | KeyPressMask);              ButtonReleaseMask | PointerMotionMask | KeyPressMask);
# Line 472  struct fb_window *x11_fb_init(int xsize, Line 539  struct fb_window *x11_fb_init(int xsize,
539              m->fb_windows[fb_number]->x11_fb_winxsize,              m->fb_windows[fb_number]->x11_fb_winxsize,
540              m->fb_windows[fb_number]->x11_fb_winysize);              m->fb_windows[fb_number]->x11_fb_winysize);
541    
         m->fb_windows[fb_number]->x11_display = x11_display;  
542          m->fb_windows[fb_number]->scaledown   = scaledown;          m->fb_windows[fb_number]->scaledown   = scaledown;
543    
544          m->fb_windows[fb_number]->fb_number = fb_number;          m->fb_windows[fb_number]->fb_number = fb_number;

Legend:
Removed from v.2  
changed lines
  Added in v.28

  ViewVC Help
Powered by ViewVC 1.1.26