input context attribute "XNFocusWindow"

Lucien Gentis lucien.gentis at
Thu Apr 28 12:40:38 UTC 2016

Hi to all,

My system : Linux - Ubuntu 14.04

I am developing an application which relies on Xlib Library and I try to 
internationalize it.

In order to be able to type in accented character, some of them with 
dead keys, I use XmbLookupString function and a unique Input Context.

Since my app has several X windows, each time one of them gets input 
focus, I must set "XNFocusWindow" attribute  to it through XSetICValues 
function, but it doesn't seem to work:

If "w" is the X window I want to set as "XNFocusWindow" attribute of the 
IC, when I reread this attribute through XGetICValues function, I don't 
obtain the same value:

Window winicfocus;
printf ("Window w id : %ld - IC focus window : %ld\n",w,winicfocus);

I get:

Window w id : 77594625 - IC focus window : 0

To illustrate that, I have joined a little programme you should compile 
through this command:
gcc -g -Wall -o prog-1 -lX11

Centre de Ressources Informatiques
5, Rue Paul Richard

Tél. 03 72 74 13 28
Email : lucien.gentis at

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>
-------------- next part --------------
// Written by Ch. Tronche (
// Copyright by the author. This is unmaintained, no-warranty free software. 
// Please use freely. It is appreciated (but by no means mandatory) to
// acknowledge the author's contribution. Thank you.
// Started on Thu Jun 26 23:29:03 1997

// Xlib tutorial: 1st program
// Make a window appear on the screen.

#include <X11/Xlib.h> // Every Xlib program must include this
#include <locale.h>
#include <stdlib.h>
#include <stdio.h>

#define NIL (0)       // A name for the void pointer

int main()
	// Opening the display
        Display *dpy = XOpenDisplay(NIL);
        // Creating a new window
	Window w = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, 
			       200, 100, 0, 
			       CopyFromParent, CopyFromParent, CopyFromParent,
			       NIL, 0);

	// Setting locale : mine is fr_FR.UTF-8
    	if (setlocale(LC_ALL, "") == NULL) {
    	    printf("cannot set locale.\n");
	// is my locale supported ?
    	if (!XSupportsLocale()) {
    	    printf("X does not support locale %s.\n",setlocale(LC_ALL, NULL));
	// setting modifiers
  	if (XSetLocaleModifiers("") == NULL) {
  	    printf("Warning: cannot set locale modifiers.\n");

	// opening input method
	XIM im = XOpenIM(dpy, NULL, NULL, NULL);
	if (im == NULL) {
        	printf("Couldn't open input method.\n");
	// creating input context
	XIC ic=XCreateIC(im,XNInputStyle,XIMPreeditNothing|XIMStatusNothing,NULL);
	if (ic == NULL) {
        	printf("Couldn't create input context.\n");

	// newly created IC gains focus

	// set window focus for the IC

	// rereads window focus for the IC
	Window winicfocus;

	// Here comes the problem:
	// I have set XNFocusWindow attribute to "w"
	// So, if I reread it through XGetICValues function into winicfocus variable,
	// winicfocus should contain window "w" 's id, but it's not the case :

	// shows there's something wrong . . .
      	printf ("Window w id : %ld - IC focus window : %ld\n",w,winicfocus);

	return 0;

More information about the xorg mailing list