X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=vid_glx.c;h=e1b4bc72ec5686afb868402091c1dd40fdd7a3d5;hb=4ac44fe8bfceff11a0ff0bd8ccb8d095ad9c873b;hp=4fbb2d83592a81039c3bb56b82d05a2263a873ce;hpb=779192f83f5c0e6ef6c692f7c116afaa55b51c93;p=xonotic%2Fdarkplaces.git diff --git a/vid_glx.c b/vid_glx.c index 4fbb2d83..e1b4bc72 100644 --- a/vid_glx.c +++ b/vid_glx.c @@ -39,6 +39,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #endif #include +// get the Uchar type +#include "utf8lib.h" + #include "nexuiz.xpm" #include "darkplaces.xpm" @@ -122,16 +125,57 @@ static Visual *vidx11_visual; static Colormap vidx11_colormap; /*-----------------------------------------------------------------------*/ +// -static int XLateKey(XKeyEvent *ev, char *ascii) +long keysym2ucs(KeySym keysym); +void DP_Xutf8LookupString(XKeyEvent * ev, + Uchar *uch, + KeySym * keysym_return, + Status * status_return) +{ + int rc; + KeySym keysym; + int codepoint; + char buffer[64]; + int nbytes = sizeof(buffer); + + rc = XLookupString(ev, buffer, nbytes, &keysym, NULL); + + if (rc > 0) { + codepoint = buffer[0] & 0xFF; + } else { + codepoint = keysym2ucs(keysym); + } + + if (codepoint < 0) { + if (keysym == None) { + *status_return = XLookupNone; + } else { + *status_return = XLookupKeySym; + *keysym_return = keysym; + } + *uch = 0; + return; + } + + *uch = codepoint; + + if (keysym != None) { + *keysym_return = keysym; + *status_return = XLookupBoth; + } else { + *status_return = XLookupChars; + } +} +static int XLateKey(XKeyEvent *ev, Uchar *ascii) { int key = 0; - char buf[64]; + //char buf[64]; KeySym keysym, shifted; + Status status; keysym = XLookupKeysym (ev, 0); - XLookupString(ev, buf, sizeof buf, &shifted, 0); - *ascii = buf[0]; + DP_Xutf8LookupString(ev, ascii, &shifted, &status); switch(keysym) { @@ -398,7 +442,7 @@ static void HandleEvents(void) { XEvent event; int key; - char ascii; + Uchar unicode; qboolean dowarp = false; if (!vidx11_display) @@ -412,14 +456,14 @@ static void HandleEvents(void) { case KeyPress: // key pressed - key = XLateKey (&event.xkey, &ascii); - Key_Event(key, ascii, true); + key = XLateKey (&event.xkey, &unicode); + Key_Event(key, unicode, true); break; case KeyRelease: // key released - key = XLateKey (&event.xkey, &ascii); - Key_Event(key, ascii, false); + key = XLateKey (&event.xkey, &unicode); + Key_Event(key, unicode, false); break; case MotionNotify: @@ -689,8 +733,8 @@ void InitSig(void) void VID_Finish (void) { - vid_usevsync = vid_vsync.integer && !cls.timedemo && gl_videosyncavailable; - if (vid_usingvsync != vid_usevsync && gl_videosyncavailable) + vid_usevsync = vid_vsync.integer && !cls.timedemo && qglXSwapIntervalSGI; + if (vid_usingvsync != vid_usevsync) { vid_usingvsync = vid_usevsync; if (qglXSwapIntervalSGI (vid_usevsync)) @@ -771,6 +815,8 @@ qboolean VID_InitMode(viddef_mode_t *mode) XVisualInfo *visinfo; int MajorVersion, MinorVersion; const char *drivername; + char *xpm; + char **idata; vid_isfullscreen = false; vid_isnetwmfullscreen = false; @@ -953,12 +999,22 @@ qboolean VID_InitMode(viddef_mode_t *mode) win = XCreateWindow(vidx11_display, root, 0, 0, mode->width, mode->height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr); + xpm = (char *) FS_LoadFile("darkplaces-icon.xpm", tempmempool, false, NULL); + idata = NULL; + if(xpm) + idata = XPM_DecodeString(xpm); + if(!idata) + idata = ENGINE_ICON; + wmhints = XAllocWMHints(); if(XpmCreatePixmapFromData(vidx11_display, win, - (gamemode == GAME_NEXUIZ) ? nexuiz_xpm : darkplaces_xpm, + idata, &wmhints->icon_pixmap, &wmhints->icon_mask, NULL) == XpmSuccess) wmhints->flags |= IconPixmapHint | IconMaskHint; + if(xpm) + Mem_Free(xpm); + clshints = XAllocClassHint(); clshints->res_name = strdup(gamename); clshints->res_class = strdup("DarkPlaces"); @@ -972,6 +1028,9 @@ qboolean VID_InitMode(viddef_mode_t *mode) } XmbSetWMProperties(vidx11_display, win, gamename, gamename, (char **) com_argv, com_argc, szhints, wmhints, clshints); + // strdup() allocates using malloc(), should be freed with free() + free(clshints->res_name); + free(clshints->res_class); XFree(clshints); XFree(wmhints); XFree(szhints); @@ -998,6 +1057,7 @@ qboolean VID_InitMode(viddef_mode_t *mode) //XSync(vidx11_display, False); ctx = qglXCreateContext(vidx11_display, visinfo, NULL, True); + XFree(visinfo); // glXChooseVisual man page says to use XFree to free visinfo if (!ctx) { Con_Printf ("glXCreateContext failed\n"); @@ -1029,7 +1089,7 @@ qboolean VID_InitMode(viddef_mode_t *mode) // COMMANDLINEOPTION: Linux GLX: -novideosync disables GLX_SGI_swap_control // COMMANDLINEOPTION: BSD GLX: -novideosync disables GLX_SGI_swap_control // COMMANDLINEOPTION: MacOSX GLX: -novideosync disables GLX_SGI_swap_control - gl_videosyncavailable = GL_CheckExtension("GLX_SGI_swap_control", swapcontrolfuncs, "-novideosync", false); + GL_CheckExtension("GLX_SGI_swap_control", swapcontrolfuncs, "-novideosync", false); vid_usingmousegrab = false; vid_usingmouse = false; @@ -1109,6 +1169,8 @@ size_t VID_ListModes(vid_mode_t *modes, size_t maxcount) ++k; } } + // manpage of XF86VidModeGetAllModeLines says it should be freed by the caller + XFree(vidmodes); return k; } return 0; // FIXME implement this