Hi Xperts,
Can anyone help me how to grab all key events and send
them to a single window. Also when i do any mouse operations
it should take only those operations done on that window.
Like say i opened a dialog box. Until i close the window the focus
shouldn't go to any other window. Any key i press should be directed
to the dialog
I tried something and i have attached. but the window couldn't
get the key and mouse input
Can somebody give me clear picture!
Thanks,
Jeyasudha.
#include
#include
#include
#include
#include
#include
#include
Display *dis;
Window win;
XEvent report;
int i=0;
int main()
{
XWindowChanges windowChanges;
Window screeninput;
XSetWindowAttributes windowAttributes;
dis = XOpenDisplay(NULL);
win = XCreateSimpleWindow(dis, RootWindow(dis, 0), \
1,1,300,300,0, BlackPixel(dis,0), BlackPixel(dis,0));
XMapWindow(dis,win);
fprintf(stdout, "The display is %d \n", dis);
XFlush(dis);
XSync(dis, False);
XSelectInput(dis,win, EnterWindowMask| LeaveWindowMask| ExposureMask|
KeyPressMask| ButtonPressMask| StructureNotifyMask| ResizeRedirectMask
|StructureNotifyMask | SubstructureNotifyMask | PropertyChangeMask );
if (XGrabPointer(dis,
win,
False, /* owner_events */
PointerMotionMask | PointerMotionHintMask | ButtonPressMask |
ButtonReleaseMask, /* event mask */
GrabModeAsync, /* pointer_mode */
GrabModeAsync, /* keyboard_mode */
None, /* confine_to window */
None, /* cursor */
CurrentTime) == GrabSuccess)
{
printf("Grabbed the mouse pointer");
if (XGrabKeyboard(dis,
win,
False, /* owner_events */
GrabModeAsync, /* pointer_mode */
GrabModeAsync, /* keyboard_mode */
CurrentTime) == GrabFrozen)
{
printf("Grabbed the keyboard\n");
}
else
{
printf("Failed Grabbing the keyboard first time \n");
XUngrabKeyboard (dis, CurrentTime);
if (XGrabKeyboard(dis,
RootWindow(dis,0),
False, /* owner_events */
GrabModeAsync, /* pointer_mode */
GrabModeAsync, /* keyboard_mode */
CurrentTime) == GrabFrozen)
{
printf("Grabbed the keyboard second time\n");
}
else
{
printf("Failed grabbing keyboard second time");
}
}
}
else
{
printf("Cannot Grab the mouse pointer");
XUngrabPointer (dis, CurrentTime);
if (XGrabPointer(dis,
RootWindow(dis,0),
False, /* owner_events */
PointerMotionMask | PointerMotionHintMask | ButtonPressMask |
ButtonReleaseMask, /* event mask */
GrabModeAsync, /* pointer_mode */
GrabModeAsync, /* keyboard_mode */
None, /* confine_to window */
None, /* cursor */
CurrentTime) == GrabSuccess)
printf ("Grabbed the mouse pointer second time \n");
else
printf ("Failed the mouse pointer second time \n");
}
/*
windowAttributes.event_mask = ButtonPressMask | EnterWindowMask;
windowAttributes.override_redirect = True;
screeninput = XCreateWindow (dis, RootWindow(dis,0), 0, 0,
DisplayWidth (dis, XDefaultScreen(dis)),
DisplayHeight (dis, XDefaultScreen(dis)),
0,
0,
InputOnly,
CopyFromParent,
CWEventMask | CWOverrideRedirect | CWCursor,
&windowAttributes);
windowChanges.sibling = win;
windowChanges.stack_mode = Below;
XConfigureWindow (dis,screeninput,
CWSibling | CWStackMode, &windowChanges);
*/
while(1)
{
XNextEvent(dis, &report);
fprintf(stdout, "Event type is %d", report.type);
switch(report.type)
{
case EnterNotify:
i++;
fprintf(stdout, "U have entered the window %d", i);
break;