--- uae/src/xwin.c 2018/04/24 16:42:01 1.1.1.5 +++ uae/src/xwin.c 2018/04/24 16:54:40 1.1.1.10 @@ -26,10 +26,11 @@ #include "threaddep/penguin.h" #include "uae.h" #include "memory.h" +#include "xwin.h" #include "custom.h" +#include "drawing.h" #include "readcpu.h" #include "newcpu.h" -#include "xwin.h" #include "keyboard.h" #include "keybuf.h" #include "gui.h" @@ -64,7 +65,7 @@ #define DO_PUTIMAGE(IMG, SRCX, SRCY, DSTX, DSTY, WIDTH, HEIGHT) \ do { \ - if (currprefs.use_mitshm) \ + if (currprefs.x11_use_mitshm) \ XShmPutImage (display, mywin, mygc, (IMG), (SRCX), (SRCY), (DSTX), (DSTY), (WIDTH), (HEIGHT), 0); \ else \ XPutImage (display, mywin, mygc, (IMG), (SRCX), (SRCY), (DSTX), (DSTY), (WIDTH), (HEIGHT)); \ @@ -114,6 +115,7 @@ struct disp_info { static Display *display; static int screen; static Window rootwin, mywin; +static Atom delete_win; static GC mygc; static XColor black, white; @@ -149,7 +151,7 @@ static int x11_init_ok; static int dgaavail = 0, vidmodeavail = 0, shmavail = 0; static int dgamode; - /* Keyboard and mouse */ +/* Keyboard and mouse */ static int keystate[256]; @@ -163,21 +165,26 @@ struct uae_hotkeys { int mask; }; +static void handle_modeswitch (void); static void handle_mousegrab (void); static void handle_inhibit (void); static void framerate_up (void); static void framerate_down (void); - +static void handle_interpol (void); static struct uae_hotkeys hotkeys[] = { - {{ XK_F12, XK_q, 0 }, uae_quit, -1 }, - {{ XK_F12, XK_m, 0 }, togglemouse, -1 }, - {{ XK_F12, XK_g, 0 }, handle_mousegrab, -1 }, - {{ XK_F12, XK_i, 0 }, handle_inhibit, -1 }, - {{ XK_F12, XK_KP_Add, 0 }, framerate_up, -1 }, - {{ XK_F12, XK_KP_Subtract, 0 }, framerate_down, -1 }, - {{ XK_Scroll_Lock, 0 }, handle_inhibit, -1 }, - {{ 0 }, NULL, -1 } /* List must be terminated */ +#ifdef USE_DGA_EXTENSION + {{ XK_F12, XK_s, 0 }, handle_modeswitch, -1, 0 }, +#endif + {{ XK_F12, XK_q, 0 }, uae_quit, -1, 0 }, + {{ XK_F12, XK_m, 0 }, togglemouse, -1, 0 }, + {{ XK_F12, XK_g, 0 }, handle_mousegrab, -1, 0 }, + {{ XK_F12, XK_i, 0 }, handle_inhibit, -1, 0 }, + {{ XK_F12, XK_p, 0 }, handle_interpol, -1, 0 }, + {{ XK_F12, XK_KP_Add, 0 }, framerate_up, -1, 0 }, + {{ XK_F12, XK_KP_Subtract, 0 }, framerate_down, -1, 0 }, + {{ XK_Scroll_Lock, 0 }, handle_inhibit, -1, 0 }, + {{ 0 }, NULL, -1, 0 } /* List must be terminated */ }; static int inwindow; @@ -210,7 +217,7 @@ static void get_image (int w, int h, str char *p; #if SHM_SUPPORT_LINKS == 1 - if (currprefs.use_mitshm && shmavail) { + if (currprefs.x11_use_mitshm && shmavail) { XShmSegmentInfo *shminfo = &dispi->shminfo; new_img = XShmCreateImage (display, vis, bitdepth, ZPixmap, 0, shminfo, w, h); @@ -358,7 +365,7 @@ void flush_line (int y) xs = 0; xe = gfxvidinfo.width - 1; - if (currprefs.use_low_bandwidth) { + if (currprefs.x11_use_low_bandwidth) { char *src, *dst; switch (gfxvidinfo.pixbytes) { case 4: @@ -437,12 +444,12 @@ void flush_screen (int ystart, int ystop return; #if SHM_SUPPORT_LINKS == 1 - if (currprefs.use_mitshm) + if (currprefs.x11_use_mitshm) XSync (display, 0); #endif } -static __inline__ int bitsInMask (unsigned long mask) +STATIC_INLINE int bitsInMask (unsigned long mask) { /* count bits in mask */ int n = 0; @@ -453,7 +460,7 @@ static __inline__ int bitsInMask (unsign return n; } -static __inline__ int maskShift (unsigned long mask) +STATIC_INLINE int maskShift (unsigned long mask) { /* determine how far mask is shifted */ int n = 0; @@ -710,7 +717,10 @@ static void init_dispinfo (struct disp_i static void graphics_subinit (void) { + int i, j; XSetWindowAttributes wattr; + XClassHint classhint; + XWMHints *hints; unsigned long valuemask; dgamode = screen_is_picasso ? currprefs.gfx_pfullscreen : currprefs.gfx_afullscreen; @@ -733,11 +743,29 @@ static void graphics_subinit (void) wattr.event_mask = EVENTMASK; XSync (display, 0); + delete_win = XInternAtom(display, "WM_DELETE_WINDOW", False); mywin = XCreateWindow (display, rootwin, 0, 0, current_width, current_height, 0, bitdepth, InputOutput, vis, valuemask, &wattr); + XSetWMProtocols (display, mywin, &delete_win, 1); XSync (display, 0); XStoreName (display, mywin, "UAE"); + XSetIconName (display, mywin, "UAE Screen"); + + /* set class hint */ + classhint.res_name = "UAE"; + classhint.res_class = "UAEScreen"; + XSetClassHint(display, mywin, &classhint); + + hints = XAllocWMHints(); + /* Set window group leader to self to become an application + * that can be hidden by e.g. WindowMaker. + * Would be more useful if we could find out what the + * (optional) GTK+ window ID is :-/ */ + hints->window_group = mywin; + hints->flags = WindowGroupHint; + XSetWMHints(display, mywin, hints); + XMapRaised (display, mywin); XSync (display, 0); mygc = XCreateGC (display, mywin, 0, 0); @@ -767,7 +795,7 @@ static void graphics_subinit (void) gfxvidinfo.linemem = 0; gfxvidinfo.bufmem = ami_dinfo.image_mem; gfxvidinfo.rowbytes = ami_dinfo.ximg->bytes_per_line; - if (currprefs.use_low_bandwidth) { + if (currprefs.x11_use_low_bandwidth) { gfxvidinfo.maxblocklines = 0; gfxvidinfo.rowbytes = ami_dinfo.ximg->bytes_per_line; gfxvidinfo.linemem = (char *)malloc (gfxvidinfo.rowbytes); @@ -791,7 +819,7 @@ static void graphics_subinit (void) #endif if (! dgamode) { - if (! currprefs.no_xhair) + if (! currprefs.x11_hide_cursor) XDefineCursor (display, mywin, xhairCursor); else XDefineCursor (display, mywin, blankCursor); @@ -804,6 +832,15 @@ static void graphics_subinit (void) picasso_invalid_stop = -1; memset (picasso_invalid_lines, 0, sizeof picasso_invalid_lines); } + + lastmx = lastmy = 0; + newmousecounters = 0; + inwindow = 0; + for (i = 0; hotkeys[i].syms[0] != 0; i++) { + hotkeys[i].mask = 0; + for (j = 0; hotkeys[i].syms[j] != 0; j++) + hotkeys[i].mask |= (1 << j); + } } int graphics_init (void) @@ -811,7 +848,7 @@ int graphics_init (void) int i,j; XPixmapFormatValues *xpfvs; - if (currprefs.use_mitshm && ! shmavail) { + if (currprefs.x11_use_mitshm && ! shmavail) { fprintf (stderr, "MIT-SHM extension not supported by X server.\n"); } if (currprefs.color_mode > 5) @@ -879,7 +916,7 @@ int graphics_init (void) if (bitdepth < 8 || (bitdepth == 8 && currprefs.color_mode == 3)) { gfxvidinfo.pixbytes = 2; - currprefs.use_low_bandwidth = 0; + currprefs.x11_use_low_bandwidth = 0; need_dither = 1; } else { gfxvidinfo.pixbytes = bit_unit >> 3; @@ -899,15 +936,6 @@ int graphics_init (void) buttonstate[0] = buttonstate[1] = buttonstate[2] = 0; for (i = 0; i < 256; i++) keystate[i] = 0; - - lastmx = lastmy = 0; - newmousecounters = 0; - inwindow = 0; - for (i = 0; hotkeys[i].syms[0] != 0; i++) { - hotkeys[i].mask = 0; - for (j = 0; hotkeys[i].syms[j] != 0; j++) - hotkeys[i].mask |= (1 << j); - } grabbed = 0; return x11_init_ok = 1; @@ -1070,7 +1098,11 @@ static int kc_decode (KeySym ks) case XK_Left: return AK_LF; case XK_Right: return AK_RT; +#if 0 case XK_F11: return AK_BACKSLASH; +#else + case XK_F11: frametime = 0; timeframes = 0; bogusframe = 1; break; +#endif #ifdef XK_Page_Up /* These are missing occasionally */ case XK_Page_Up: return AK_RAMI; /* PgUp mapped to right amiga */ case XK_Page_Down: return AK_LAMI; /* PgDn mapped to left amiga */ @@ -1088,6 +1120,7 @@ static int decode_fr (KeySym ks) case XK_Y: case XK_y: return AK_Y; case XK_W: case XK_w: return AK_Z; case XK_Z: case XK_z: return AK_W; +#if 0 case XK_bracketleft: return AK_LBRACKET; case XK_bracketright: return AK_RBRACKET; case XK_comma: return AK_M; @@ -1099,6 +1132,31 @@ static int decode_fr (KeySym ks) case XK_slash: return AK_PERIOD; case XK_minus: return AK_EQUAL; case XK_backslash: return AK_BACKSLASH; +#else + /* not sure for this one: my X 3.3 server doesn't handle this key always + * correctly... But anyway, on new french keyboards, no more bracket key + * at this place. + */ + case XK_dead_circumflex: + case XK_dead_diaeresis: return AK_LBRACKET; + case XK_dollar: + case XK_sterling: return AK_RBRACKET; + case XK_comma: case XK_question: return AK_M; + case XK_less: case XK_greater: return AK_LTGT; + case XK_semicolon: case XK_period: return AK_COMMA; + case XK_parenright: case XK_degree: return AK_MINUS; + case XK_equal: case XK_plus: return AK_SLASH; + case XK_numbersign: return AK_NUMBERSIGN; + case XK_colon: case XK_slash: return AK_PERIOD; + case XK_minus: case XK_6: return AK_6; + case XK_ugrave: case XK_percent: return AK_QUOTE; + /* found a spare key - I hope it deserves this place. */ + case XK_asterisk: case XK_mu: return AK_BACKSLASH; + case XK_exclam: case XK_section: return AK_EQUAL; + case XK_twosuperior: case XK_asciitilde: return AK_BACKQUOTE; + case XK_Multi_key: return AK_RAMI; + case XK_Mode_switch: return AK_RALT; +#endif } return -1; @@ -1413,7 +1471,7 @@ void handle_events (void) } else if (inwindow) { lastmx = ((XMotionEvent *)&event)->x; lastmy = ((XMotionEvent *)&event)->y; - if (! cursorOn && !currprefs.no_xhair) { + if (! cursorOn && !currprefs.x11_hide_cursor) { XDefineCursor(display, mywin, xhairCursor); cursorOn = 1; } @@ -1453,6 +1511,11 @@ void handle_events (void) case Expose: refresh_necessary = 1; break; + case ClientMessage: + if (event.xclient.data.l[0]==delete_win) { + uae_quit (); + } + break; } } @@ -1496,7 +1559,7 @@ void handle_events (void) DO_PUTIMAGE (ami_dinfo.ximg, 0, 0, 0, 0, currprefs.gfx_width, currprefs.gfx_height); refresh_necessary = 0; } - if (cursorOn && !currprefs.no_xhair) { + if (cursorOn && !currprefs.x11_hide_cursor) { struct timeval now; int diff; gettimeofday(&now, NULL); @@ -1509,7 +1572,7 @@ void handle_events (void) } } /* "Affengriff" */ - if (keystate[AK_CTRL] && keystate[AK_LAMI] && keystate[AK_RAMI]) + if ((keystate[AK_CTRL] || keystate[AK_RCTRL]) && keystate[AK_LAMI] && keystate[AK_RAMI]) uae_reset (); } @@ -1529,7 +1592,30 @@ int check_prefs_changed_gfx (void) && changed_prefs.gfx_afullscreen == currprefs.gfx_afullscreen && changed_prefs.gfx_pfullscreen == currprefs.gfx_pfullscreen) return 0; - + + graphics_subshutdown (); + currprefs.gfx_width = changed_prefs.gfx_width; + currprefs.gfx_height = changed_prefs.gfx_height; + currprefs.gfx_lores = changed_prefs.gfx_lores; + currprefs.gfx_linedbl = changed_prefs.gfx_linedbl; + currprefs.gfx_correct_aspect = changed_prefs.gfx_correct_aspect; + currprefs.gfx_xcenter = changed_prefs.gfx_xcenter; + currprefs.gfx_ycenter = changed_prefs.gfx_ycenter; + currprefs.gfx_afullscreen = changed_prefs.gfx_afullscreen; + currprefs.gfx_pfullscreen = changed_prefs.gfx_pfullscreen; + + gui_update_gfx (); + + graphics_subinit (); + + if (! inwindow) + XWarpPointer (display, None, mywin, 0, 0, 0, 0, + current_width / 2, current_height / 2); + + notice_screen_contents_lost (); + init_row_map (); + if (screen_is_picasso) + picasso_enablescreen (1); return 0; } @@ -1771,17 +1857,57 @@ static void handle_mousegrab (void) static void handle_inhibit (void) { - toggle_inhibit_frame (0); + toggle_inhibit_frame (IHF_SCROLLLOCK); +} + +#include "gensound.h" +#include "sounddep/sound.h" +#include "events.h" +#include "audio.h" + +static void handle_interpol (void) +{ + if (currprefs.sound_interpol == 0) { + currprefs.sound_interpol = 1; + printf ("Interpol on: rh\n"); + } + else if (currprefs.sound_interpol == 1) { + currprefs.sound_interpol = 2; + printf ("Interpol on: crux\n"); + } + else { + currprefs.sound_interpol = 0; + printf ("Interpol off\n"); + } } static void framerate_up (void) { - if (currprefs.framerate < 20) - changed_prefs.framerate = currprefs.framerate + 1; + if (currprefs.gfx_framerate < 20) + changed_prefs.gfx_framerate = currprefs.gfx_framerate + 1; } static void framerate_down (void) { - if (currprefs.framerate > 1) - changed_prefs.framerate = currprefs.framerate - 1; + if (currprefs.gfx_framerate > 1) + changed_prefs.gfx_framerate = currprefs.gfx_framerate - 1; +} + +static void handle_modeswitch (void) +{ + changed_prefs.gfx_afullscreen = changed_prefs.gfx_pfullscreen = !dgamode; +} + +void target_save_options (FILE *f, struct uae_prefs *p) +{ + fprintf (f, "x11.low_bandwidth=%s\n", p->x11_use_low_bandwidth ? "true" : "false"); + fprintf (f, "x11.use_mitshm=%s\n", p->x11_use_mitshm ? "true" : "false"); + fprintf (f, "x11.hide_cursor=%s\n", p->x11_hide_cursor ? "true" : "false"); +} + +int target_parse_option (struct uae_prefs *p, char *option, char *value) +{ + return (cfgfile_yesno (option, value, "low_bandwidth", &p->x11_use_low_bandwidth) + || cfgfile_yesno (option, value, "use_mitshm", &p->x11_use_mitshm) + || cfgfile_yesno (option, value, "hide_cursor", &p->x11_hide_cursor)); }