Looking for **PAID** help with calling XSendEvent correctly

Aryeh Friedman aryeh.friedman at gmail.com
Fri Dec 23 03:49:07 PST 2011


Thanks for the clue it was not exactly what you said but it gave me
the right idea (namely instead of rebroadcasting I use normal method
calling to make a callback in Java for the keystroke)

On Fri, Dec 23, 2011 at 4:58 AM, Sam Spilsbury <smspillaz at gmail.com> wrote:
> On Thu, Dec 22, 2011 at 9:20 AM, Aryeh Friedman
> <aryeh.friedman at gmail.com> wrote:
>> I have a Java program that calls the following code but somehow the
>> events are not rebroadcasted... from my very limited knowledge of X (I
>> have known C for years but never used it for GUI work) I highly
>> suspect I some how got the second arg wrong (it seems that the JAWT
>> window ID is not the same as the Xorg one)... since this is a high
>> priority project my client is willing to pay for 1 to 2 hours of
>> consulting on how to adjust the code to make it work... the final goal
>> is we want to block all keystrokes not meant for the actual app
>> (alt-f1:f9, ctl-alt-del, etc.)... namely the client is making a
>> application to apply standardized tests to distance learning students
>> and we need to enable a "kiosk" like mode (the user can not break out
>> the app [or as much as is possible]... the reason is we want to
>> prevent the test taker of using this as a work around the "closed
>> book" restriction on a "closed book" test)... I can either have no
>> event filtering (all events go their intended targets) or filtering
>> and no forwarding (namely if a invert the test of which process to
>> terminate on fork(2)).
>>
>> Note: I tried both InputFocus and PointerFocus for the target win of
>> the event but that doesn't work nor does key->win.   Also I can handle
>> all the coding except the actual XLib/XCB calls.
>>
>> // src/c/KioskJNI.c
>>
>> /**
>>  * Any C needed to make Kiosk Mode work as expected
>>  *
>>  * Copyright (C) 2010-2011. Friedman-Nixon-Wong Enterprises, LLC.
>>  *
>>  * @author aryeh
>>  * @version Mon Dec  5 03:47:46 2011
>>  */
>> #include <signal.h>
>> #include <X11/Xlib.h>
>> #include "jawt_md.h"
>> #include "client_kiosk_core_KioskJNI.h"
>>
>> /**
>>  * Block all OS signals (param's ignored)
>>  */
>> JNIEXPORT void JNICALL
>> Java_client_kiosk_core_KioskJNI_blockSigs(JNIEnv *env, jclass cls,
>> jobject comp)
>> {
>>        Display *dpy=XOpenDisplay(0);
>>        int i=0;
>>
>>        for(i=0;i<256;i++)
>>                signal(i,SIG_IGN);
>>
>>        JAWT awt;
>>
>>        printf("fart\n");
>>
>>        // Get the AWT
>>        awt.version = JAWT_VERSION_1_4;
>>        jboolean result = JAWT_GetAWT(env, &awt);
>>
>>        JAWT_DrawingSurface* ds=awt.GetDrawingSurface(env, comp);
>>        ds->Lock(ds);
>>        JAWT_DrawingSurfaceInfo* dsi=ds->GetDrawingSurfaceInfo(ds);
>>        JAWT_X11DrawingSurfaceInfo* dsi_win =
>> (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
>>
>>        printf("dsi %p\n",dsi);
>>        printf("ds %p\n",ds);
>>        jlong win=dsi_win->visualID;
>
> I don't know AWT very well, but I would assume that if it were using
> similar naming terminology to the rest of xlib, then I think that
> dsi_win->visualID; is probably not the correct
>
>>        printf("dsi_win %p\n",win);
>>
>
> Have you tried using the result of this in xwininfo -id ?
>
>>        // Free the drawing surface info
>>        ds->FreeDrawingSurfaceInfo(dsi);
>>
>>        // Unlock the drawing surface
>>        ds->Unlock(ds);
>>
>>        // Free the drawing surface
>>        awt.FreeDrawingSurface(ds);
>>
>>        XGrabKeyboard(dpy, DefaultRootWindow(dpy), True, GrabModeAsync,
>> GrabModeAsync, CurrentTime);
>>
>>        int pid=fork();
>>
>>        if(!pid) {
>>                return;
>>        }
>>
>>        printf("%d\n",pid);
>>
>>        XEvent ev;
>>
>>        while(1) {
>>                XNextEvent(dpy,&ev);
>>                XKeyEvent *key=(XKeyEvent *) &ev;
>>
>>                printf("You typed a %d\n",key->keycode);
>>
>>
>>                XSendEvent(dpy,win, True, (KeyPressMask | KeyReleaseMask), &ev);
>
> Have you ensured that the receiving client has selected for
> KeyPressMask and KeyReleaseMask ?
>
> Check with xwininfo -id client_id -all
>
>>                XFlush(dpy);
>>        }
>>
>>        XCloseDisplay(dpy);
>> }
>> _______________________________________________
>> xorg at lists.freedesktop.org: X.Org support
>> Archives: http://lists.freedesktop.org/archives/xorg
>> Info: http://lists.freedesktop.org/mailman/listinfo/xorg
>> Your subscription address: smspillaz at gmail.com
>
>
>
> --
> Sam Spilsbury



More information about the xorg mailing list