input context attribute "XNFocusWindow"

Lucien Gentis lucien.gentis at univ-lorraine.fr
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:

XSetICValues(ic,XNFocusWindow,w,NULL);
Window winicfocus;
XGetICValues(ic,XNFocusWindow,&winicfocus,NULL);
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 prog-1.cc -o prog-1 -lX11

-- 
Lucien GENTIS
UNIVERSITE DE LORRAINE - ESPE
Centre de Ressources Informatiques
5, Rue Paul Richard
C.O. 3 - MAXEVILLE
54528 LAXOU-CEDEX

Tél. 03 72 74 13 28
Email : lucien.gentis at univ-lorraine.fr

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.x.org/archives/xorg/attachments/20160428/5f0349fd/attachment.html>
-------------- next part --------------
// Written by Ch. Tronche (http://tronche.lri.fr:8000/)
// 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");
	    exit(1);
    	}
	// is my locale supported ?
    	if (!XSupportsLocale()) {
    	    printf("X does not support locale %s.\n",setlocale(LC_ALL, NULL));
	    exit(1);
  	}
	// 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");
        	exit(1);
    	}
	
	// creating input context
	XIC ic=XCreateIC(im,XNInputStyle,XIMPreeditNothing|XIMStatusNothing,NULL);
	if (ic == NULL) {
        	printf("Couldn't create input context.\n");
        	exit(1);
	}

	// newly created IC gains focus
	XSetICFocus(ic);

	// set window focus for the IC
	XSetICValues(ic,XNFocusWindow,w,NULL);

	// rereads window focus for the IC
	Window winicfocus;
	XGetICValues(ic,XNFocusWindow,&winicfocus,NULL);

	// 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