Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi, how's it going.
So I'm loving programming under Xlib so
far, but I need to know a few things.
OK. I find it really disturbing that
when I run a program I've written for X, X
suddenly takes up 20% of CPU function!
Also, I would like to know how to get it
so that the user can't resize, maximize or
close the window.
I would also like to know what XEvent
value is sent when the user clicks the
close box of the window.
Finally, I would like to know how to find
out the position of the mouse within the
window when the user clicks on it. I
already know the event sent when this
happens.
Thanks

It shouldn't use any CPU if your code isn't doing anything ie if your code has just called XNextEvent() or something similar and you're not playing with things in the window.
Not sure about fixed size windows, I'd guess you should just set size_hints->max_* and size_hints->min_* equal in pairs.
DestroyWindow (Xlib.h) for closing actions (I think) and since you already know the event sent for clicking - RTFM - 'man XButtonEvent' or whatever it is ;-)

For making fixed size windows, 'man XSetWMNormalHints' and/or 'man XSetWMProperties'
http://standards.freedesktop.org/wm-spec/1.3/ar01s07.html#NORESIZE

Thanks a lot for the help Wolfbone. I did
get working the fixed border with XSetWMNormalHints() (first doing
XAllocSizeHints()).
I got rid of the CPU% problem by using
XWindowEvent() instead of XNextEvent(). Also, I had a timer regulate the event loop so that the event was checked every 50ms. For some reason, this has the same effect alone as using XWindowEvent alone, so I combined them.
I also got the mouse location working, by
using (x_event.xbutton.x) and
(x_event.xbutton.y).
DestroyWindow doesn't seem to exist
according to my compiler, but I'm OK
without closebox stuff this for my
purposes. Yeah, this stuff's pretty neat.
Thanks.

Yeah, sorry - it's DestroyNotify (X.h) not DestroyWindow.
"Yeah, this stuff's pretty neat."
It sure is - there's nothing remotely comparable to the X standards framework, it's extensions and all the toolkits and WMs etc. that have been built on top of it. It may be complex and hard to work with raw X like you are doing, but you can end up with stuff like this:
http://enlightenment.org/data/vid/e17_video.avi

Cool video. I kinda figured, after
searching the web, that it would be
DestroyNotify. For some reason, even when
I included StructureNotifyMask in the event
mask, it didn't seem to pick up. So I
found an alternative way using
WM_DELETE_WINDOW, which you can get the
window manager to send to the window. I
just wanted to stop the user from quitting
the program in the middle without giving me
a chance to free allocated stuff.

Yes, using WM protocols is the right way to do what you want to do when top level windows are closed.

![]() |
Shared memory in C
|
ASP:Textbox Behaviour
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |