[comp.windows.open-look] Keyboard Input and olwm

frodek@forit.forut.no (Frode Kileng) (03/11/91)

I need som help with receiving keyboard input in a program running
under control of olwm.

I'm running Openwin 2.0 on a SS1+ width TWO SCREENS.  The program
is based on XLib.

I'm just able to receive keyboard input from the windows on one of the 
screens.  olwm is started width the option -follow (keyboard input follows the
mouse).

The program sets the KeyPressMask for the window and the window manager
is told that the window wants keyboard input  (input hint flag to the 
window manager).

When a key is pushed the window manager beeps so it seems that 
the windowmanager receives the input but will not send it to my
application. 

I would appreciate to receive a solution to this problem.

Frode Kileng
frode.kileng@fbt.tf.tele.no  (frodek@forit.forut.no)

ichida@pt1.ncl.omron.co.jp (ICHIDA.T) (03/13/91)

In article <1991Mar11.142805.16777@mack.uit.no> frodek@forit.forut.no (Frode Kileng) writes:

 > When a key is pushed the window manager beeps so it seems that 
 > the windowmanager receives the input but will not send it to my
 > application. 

I faced same problem. When  program needs key-input,  program must set
window manager hints defined in ICCCM.

I   created  following    example     program. Please  watch    marked
lines.(specified as '<-').

<<< test.c >>>
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

void
main()
{
	Display		*display;
	Window		window;
	GC		gc;
	int		screen;
	XEvent		event;
	XWMHints	wm_hints;			<- 

	display = XOpenDisplay(NULL);
	screen = XDefaultScreen(display);
	window = XCreateSimpleWindow(display, RootWindow(display, screen),
		100, 100, 500, 500, 5, 
		BlackPixel(display, screen), WhitePixel(display, screen));
	XSelectInput(display, window, KeyPressMask | ExposureMask);
	gc = DefaultGC(display, screen);

	wm_hints.flags = InputHint;			<-
	wm_hints.input = True;				<-
	XSetWMHints(display, window, &wm_hints);	<-

	XMapWindow(display, window);

	for (;;) {
		XNextEvent(display, &event);
		switch (event.type) {
		case KeyPress:
			puts("key pressed");
			break;		
		case Expose:
			XDrawRectangle(display, window, gc,
				10, 10, 480, 480);
			break;
		default:
			puts("other event");
			break;
		}
	}
}


---
OMRON Corporation
Toshihiko Ichida.
Mail: ichida@pt1.ncl.omron.co.jp