[comp.windows.x] proper way to get keypress events within override-redirect windows

jimf%saber@HARVARD.HARVARD.EDU (03/03/90)

I have an Xt application which wants an XtPopup window to be
override-redirect (XtNoverrideRedirect True) but still wants
KeyPress events.

This works fine as-is under twm, but fails under olwm (which is much
more stringent on the InputHint == True requirement).

If I try to use Xt to set XtNinput to True for the popup window, this
setting is ignored (ie the property is never set).  If I set the hint
directly via XLib, olwm recognizes that the window should receive
input, but the keypress events seem to get eaten by Xt (ie the popup
never sees them).

I think I'm missing something simple here.  What window manager hints
should be set for an override-redirect window which wants keyboard
input?  I've tried grabbing the keyboard which had the same results as
setting the input hint with XLib except that other clients could no
longer get keyboard events, something which I wish to avoid.  Is there
something special I should do with Xt?

Any help would be greatly appreciated as I am on a tight schedule and
really don't have time to fool around with this problem much longer.

Thanks in advance,

jim frost
saber software
jimf@saber.com

asente@decwrl.dec.com (Paul Asente) (03/03/90)

The input hint is a hint to the window manager.  Since window managers never
see override-redirect windows, the input hint is meaningless for them.

First of all, do you *really* want and override-redirect window for this?
Are there absolutely *no* circumstances where the user might want to move
this window?  Not even to consult other windows to figure out what to
enter?  Are you sure?

Window managers are in charge of the X input focus.  If the window manager
has assigned the focus somewhere, you will have to get involved to assign
it to your overr-de-redirect window.  If the user is using pointer-root
focus, you're probably ok, but if the user is using click-to-type, you're
hosed.

	-paul asente
	    asente@decwrl.dec.com	decwrl!asente

bjaspan@athena.mit.edu (Barr3y Jaspan) (03/05/90)

>> I have an Xt application which wants an XtPopup window to be
>> override-redirect (XtNoverrideRedirect True) but still wants
>> KeyPress events.

I solved this problem a couple months ago when I wrote a "synchronous
GetString"
Xt.  (ie: a function that you call that pops up a dialog box, gets a string
from the user, and returns it to the caller w/o mucking around with callbacks,
etc.)

My solution is sorta kludgy but it "does the right thing."  I pop up the
dialog as an override-redirect window.  The dialog has a translation table
that maps "EnterWindow" events to an action procedure called Focus that
does an XSetInputFocus to the text widget inside the dialog.  Thus, when
the mouse enters the dialog I can type into it, and when it leaves the dialog
and enters another window, and ICCCM window manager reassigns keyboard
focus, thus undoing the effect of the XSetInputFocus by GetString.

Note that this will NOT work with a non-ICCCM wm that does not actively
set keyboard focus.. an application that uses this method must have an option
to not do the SetInputFocus.

I'll send a copy of the code, but your mileage may vary.


Barry Jaspan, MIT-Project Athena
bjaspan@athena.mit.edu

kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) (03/06/90)

> I pop up the dialog as an override-redirect window.  The dialog has a...

An override-redirect dialog is almost always the wrong thing to do.  Make it
transient instead.  This will allow the user to move it or iconify it if he
wants to look at something else on his display.

Remember that you don't own the display, the user does.  Don't take away his
ability to move windows around unless there is a good reason for it.


						Chris D. Peterson     
						MIT X Consortium 

Net:	 kit@expo.lcs.mit.edu
Phone:   (617) 253 - 9608	
Address: MIT - Room NE43-213