diff src/video/x11/SDL_x11video.c @ 1178:9867f3d86e44

Real Unicode support for X11. Based on updated version of this patch: http://lists.arabeyes.org/archives/developer/2004/June/msg00160.html --ryan.
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 21 Nov 2005 00:16:34 +0000
parents 045f186426e1
children 2bd4cec0de63
line wrap: on
line diff
--- a/src/video/x11/SDL_x11video.c	Sun Nov 20 23:59:26 2005 +0000
+++ b/src/video/x11/SDL_x11video.c	Mon Nov 21 00:16:34 2005 +0000
@@ -349,6 +349,7 @@
 		 FocusChangeMask | KeyPressMask | KeyReleaseMask
 		 | PropertyChangeMask | StructureNotifyMask | KeymapStateMask);
 
+    char * savedclassname = 0;
     /* Set the class hints so we can get an icon (AfterStep) */
     {
 	XClassHint *classhints;
@@ -358,6 +359,7 @@
             if ( ! classname ) {
                 classname = "SDL_App";
             }
+	    savedclassname = strdup(classname);
 	    classhints->res_name = classname;
 	    classhints->res_class = classname;
 	    pXSetClassHint(SDL_Display, WMwindow, classhints);
@@ -365,6 +367,33 @@
 	}
     }
 
+    /* Setup the communication with the IM server */
+    SDL_IM = NULL;
+    SDL_IC = NULL;
+
+    #ifdef X_HAVE_UTF8_STRING
+    SDL_IM = pXOpenIM(SDL_Display, NULL, savedclassname, savedclassname);
+    if (SDL_IM == NULL) {
+	SDL_SetError("no input method could be opened");
+    } else {
+	SDL_IC = pXCreateIC(SDL_IM,
+			XNClientWindow, WMwindow,
+			XNFocusWindow, WMwindow,
+			XNInputStyle, XIMPreeditNothing  | XIMStatusNothing,
+			XNResourceName, savedclassname,
+			XNResourceClass, savedclassname,
+			NULL);
+	if (SDL_IC == NULL) {
+		SDL_SetError("no input context could be created");
+		pXCloseIM(SDL_IM);
+		SDL_IM = NULL;
+	}
+    }
+    #endif
+
+    free(savedclassname);
+
+
     /* Allow the window to be deleted by the window manager */
     WM_DELETE_WINDOW = pXInternAtom(SDL_Display, "WM_DELETE_WINDOW", False);
     pXSetWMProtocols(SDL_Display, WMwindow, &WM_DELETE_WINDOW, 1);
@@ -808,7 +837,6 @@
 					| ButtonPressMask | ButtonReleaseMask
 					| PointerMotionMask | ExposureMask ));
 	}
-
 	/* Create the graphics context here, once we have a window */
 	if ( flags & SDL_OPENGL ) {
 		if ( X11_GL_CreateContext(this) < 0 ) {
@@ -854,7 +882,7 @@
 	}
 
 	/* Update the internal keyboard state */
-	X11_SetKeyboardState(SDL_Display, NULL);
+	X11_SetKeyboardState(SDL_Display, SDL_IC, NULL);
 
 	/* When the window is first mapped, ignore non-modifier keys */
 	{
@@ -892,6 +920,7 @@
 			screen->flags &= ~SDL_FULLSCREEN;
 		}
 	}
+	
 	return(0);
 }
 
@@ -1231,6 +1260,18 @@
 		/* Flush any delayed updates */
 		pXSync(GFX_Display, False);
 
+		/* Close the connection with the IM server */
+		#ifdef X_HAVE_UTF8_STRING
+		if (SDL_IC == NULL) {
+			pXDestroyIC(SDL_IC);
+			SDL_IC = NULL;
+		}
+		if (SDL_IM == NULL) {
+			pXCloseIM(SDL_IM);
+			SDL_IM = NULL;
+		}
+		#endif
+
 		/* Start shutting down the windows */
 		X11_DestroyImage(this, this->screen);
 		X11_DestroyWindow(this, this->screen);