On 24/05/11 07:34, Tom wrote:
> Thank you for your help! I got a lot further, but still not completely there. 
> I now have a window coming up. When it comes up, it has the "hello world" 
> widget inside, but when I close the window using the window-manager's close 
> button (X decoration), the console produces "X I/O error".
>

The problem here is that, by not letting FLTK manage your window, you 
have to do *everything* yourself. In this case, the issue is as follows:

You create this X window, and tell FLTK that a window exists, and to use 
it. However, in doing so, you've also told FLTK that the window is 
*yours*. Thus, FLTK does no initialisation on it whatsoever. This means 
that, currently, the window doesn't generate an event when you click the 
close button. It also means that it won't be receptive to drag-n-drop 
events and it doesn't set an icon, but this is inconsequential to your 
error. In fact, here, FLTK does *nothing*. It only places widgets into 
your window, if you so choose.

When you click the X button, X closes the display. It doesn't, by 
default, send an event. X kills the display and then (in a nutshell) the 
server does a quick check and goes "Hey, this window has no display!". 
FLTK then intercepts the error, posts "X I/O error" and X calls exit(1) 
-- you'll see the return code of 1 under gdb.

To fix it, you need to take proper control of the window. This means 
you'll want to send a WM_DELETE_WINDOW event; FLTK's run() loop checks 
for a ClientMessage event, looks for the data being WM_DELETE_WINDOW and 
if it's there, calls the window's callback.
For reference, this is why pressing the Esc key wouldn't generate an 
error; this gracefully closes the window and then destroys the display.

Unless you specifically need to manage the window yourself because you 
intend to use X extensions or you're a hardcore X programmer, I strongly 
suggest just using the fltk::Window structure. It's far less of a 
headache and Just Works.

If you still want to run with the fltk::CreatedWindow setup, make sure 
you set (at minimum) the WM_DELETE_WINDOW event. FLTK uses 
"XChangeProperty(xdisplay, x->xid, WM_PROTOCOLS, XA_ATOM, 32, 0, 
(uchar*)&WM_DELETE_WINDOW, 1);", but of course you'll have to define 
your own version of WM_PROTOCOLS and the WM_DELETE_WINDOW atom. I 
suggest the code in src/x11/run.cxx from lines 614 onwards 
(fltk::open_display()) as a good starting point.
If you can't be bothered managing it yourself, for whatever reason, you 
can also add that line to the last line of the set_xid() function (also 
in src/x11/run.cxx).

I don't recommend the latter approach though - if you're going to do 
that, just let FLTK manage the window, like it should.

I *may* need to publicly expose FLTK's WM_DELETE_WINDOW atom though, 
because by the looks of it FLTK just checks for its own static version 
of this atom, though I'm not certain and not enough of an X guru to know 
for sure.

Regards,
Ben

_______________________________________________
fltk-dev mailing list
fltk-dev@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to