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

Aryeh Friedman aryeh.friedman at gmail.com
Wed Dec 21 17:20:19 PST 2011


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;
	printf("dsi_win %p\n",win);

	// 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);
		XFlush(dpy);
	}

	XCloseDisplay(dpy);
}



More information about the xorg mailing list