🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Event handling in X11
Hi
I wrote xlib program ,and use below code for event handling
//******************
while (1)
{
if(XPending(dis))
{
XNextEvent(dis, &ev);
switch(ev.type)
{
case KeyPress:
{
cout<<"key press"<<endl;
exit(0);
break;
}
}
}
}
//******************
when set window attribute
//*****
att.override_redirect=True;
XChangeWindowAttributes( dis, win, CWOverrideRedirect, &att );
//*****
event handling don't work ,but when comment this code ,event handling is correct so when press any key program exit
please guide me
thank you
Why are you using xlib? xlib isn't really intended for application programmers, there are plenty of higher level, less ugly, and even cross platform libraries that can do whatever it is you need. Need input? SDL is your lib. GUI? gtk/gtkmm (AND LIBGLADE FOR THE LOVE OF GOD!) is for you.
etc etc etc.
You'd need a pretty strong reason to use xlib.
(sorry i know that wasn't very constructive, but it needed to be said)
cheers
-Dan
etc etc etc.
You'd need a pretty strong reason to use xlib.
(sorry i know that wasn't very constructive, but it needed to be said)
cheers
-Dan
What are you trying to do with it? I'm there are very few cases in which you should be using xlib.
In your idea why this problem occur ....
i couldn't event handling when i use below attribute for my window
//***************
att.override_redirect=True;
XChangeWindowAttributes( dis, win, CWOverrideRedirect, &att );
//***************
You don't need the override thingie for input, but events:
Check out the source code for the Quake games, they got a lot of useful stuff on X.
att.event_mask = KeyPressMask;XChangeWindowAttributes( dis, win, CWEventMask, &att );
Check out the source code for the Quake games, they got a lot of useful stuff on X.
when i using below code
att.event_mask = KeyPressMask;
XChangeWindowAttributes( dis, win, CWEventMask, &att );
my program limit to keyboard event only ,......
i need both event handling (keyboard and mouse in program)
any way....
when i set below attribute for window
att.override_redirect=True;
XChangeWindowAttributes( dis, win, CWOverrideRedirect, &att );
(i use this attribute for full screen window)
event handling don't work ....
It's all handled with bitmasks:
/* Enable redirection override. */att.override_redirect = True;/* Mask all wanted event bits together. */att.event_mask = KeyPressMask | KeyReleaseMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | etc...;/* Tell window to take care of both override redirection and input events. */XChangeWindowAttributes( dis, win, CWOverrideRedirect | CWEventMask, &att );
thanks coelurus
but when set below attibute for window
att.override_redirect=True;
and
att.event_mask =KeyReleaseMask | PointerMotionMask | ButtonPressMask| KeyPressMask ;
and
XChangeWindowAttributes( dis, win, CWOverrideRedirect | CWEventMask, &att );
//*****************event handling****************
while (1)
{
if(XPending(dis))
{
XNextEvent(dis, &(ev));
switch(ev.type)
{
case KeyPress:
exit(0);
break;
case ButtonPress:
exit(0);
break;
}
}
}
//***************************
only when i press mouse button ,program exit ,but pressing any key don't effect program :(
i think when window override ,can't take keyboard event ....... ,any idea?
but when set below attibute for window
att.override_redirect=True;
and
att.event_mask =KeyReleaseMask | PointerMotionMask | ButtonPressMask| KeyPressMask ;
and
XChangeWindowAttributes( dis, win, CWOverrideRedirect | CWEventMask, &att );
//*****************event handling****************
while (1)
{
if(XPending(dis))
{
XNextEvent(dis, &(ev));
switch(ev.type)
{
case KeyPress:
exit(0);
break;
case ButtonPress:
exit(0);
break;
}
}
}
//***************************
only when i press mouse button ,program exit ,but pressing any key don't effect program :(
i think when window override ,can't take keyboard event ....... ,any idea?
Don't remember what happens to keyboard input when you do the override thingy, but what you say sounds reasonable. Grabbing the keyboard will fix it:
Make sure to ungrab and regrab whenever you should.
I would strongly suggest you take a look at some existing source code, X has a rather steep learning curve. The simplest sources are games, but they still cover the most important parts.
XGrabKeyboard(dis, win, true, GrabModeAsync, GrabModeAsync, CurrentTime);
Make sure to ungrab and regrab whenever you should.
I would strongly suggest you take a look at some existing source code, X has a rather steep learning curve. The simplest sources are games, but they still cover the most important parts.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement