What is the status of the "gs process hangs" bug ?

ghostscript-5.50-9mdk, xforms 0.88

I noticed Lars' comment in spellchecker.C (!). I have a good way to
reproduce at least one of the symptoms :

1) find a big, slow eps and add it to a lyx file.  
2) whilst it is loading (quickly now ;) click on Help->Version, and wait 
3) After a while, close trhe dial, and it will hang

You need to be quick enough to reach Help->Version before it finishes
displaying.

moz src 116 ps alx | grep gs 
000   500   933   931   9   0  5332 3036 d_path S    ttyp1      0:00 /usr/bin/gs
                                         ^^^^^^ ^

d_path() seems an odd place to be waiting to me, I can't see any obvious
sleeping points.  Possibly this is the wrong symbol ... (d_path() is
used in the kernel to return a string pathname "/like/this/file").

Now, having found a testcase, I was intrigued if it could be narrowed
down at all.  Of course I ended up baffled :) My first thought was that
figinset.C:BrowseFile() was responsible. I was right - commenting out
BrowseFile() on line 1756 removed the bug.

This confused me as BrowseFile() looked utterly harmless, so I thought
maybe it's XForms being funny.

We use a "figinset_canvas" to communicate with the ghostscript process,
and install a handler "GhostscriptMsg" for that FL_OBJECT. This handler
looks out for ClientMessages that signify gs is done. I don't have
any docs for the property change stuff, but it looks to me that we do
something like :

1) wait until the properties are unused (i.e. wait for gs processes to finish) 
2) add the relevant gs info to the window properties 
3) set up an environment with the window id containing the properties 
4) run gs

And gs will read off the properties and notify eventually via a
ClientMessage (which xforms will pass on to the figinset canvas).

So I added a load of debugging gubbins, and discovered that, yes, the
difference between the two cases are in fact that this client message
never arrives in the broken case. At this point I suspected xforms
strongly of being buggy (ha !) and installed a "pre" event handler for
this window. Confusingly, nothing of interest ever comes through this
pre handler (and indeed, trying an xev -id <window id of canvas> comes
up blank too) in EITHER case.

At the very least I would expect to see ClientMessages being shown (I
checked, it is definitely that window ID that the ClientMessages are
generated for).

I really don't understand this bit at all - it doesn't make any sense
for a ClientMessage to be delivered, but not reported by xev OR the pre
handler !

For a while I thought I was on to a winner, when I noticed that
all the dialogs that seem to make a difference were encompassed by
Prohibit/AllowInput(). However, commenting out the *Input() didn't fix
the bug, but commenting out the fl_show_message() or whatever did.

So like many before me I'm sure :), I have reached an impasse. It seems
that when you open certain forms, (and which ones seem to be arbitrary,
despite the Prohibit/Allow input stuff), then xforms will trash the
ClientMessage.

Interestingly, if you open a guilty dialog (say Version) then close it
again before the rendering is done, then it *still* won't render. This
implies that the dialog opening is resetting something about which events
are being delivered to the X event loop inside xforms. A theory backed up
by the fact that, after it breaks, it stays broken, and no ClientMessages
ever get through.

This is either a matter of XSelectInput() or XMaskEvent() and friends
and some internal state.  It all depends on what xforms inner event loop
does. Experiments with sending ClientMessages myself directly before
fl_show_message("Version message") didn't help much :

SendEvent 
ProhibitInput 
SendEvent 
SendEvent 
fl_show_message() 
SendEvent
AllowInput 
SendEvent

produced two delivered ClientMessages. Interestingly it showed that a
"pre" handler, contrary to the documentation, does not get invoked prior
to xforms getting its mitts on the event - I got a "GhostscriptMsg"
from the Canvas handler *before* the pre handler message ! Yet another
xforms bug I suppose. Even more bizarrely, it is invoked for *other*
FL_OBJECTs. e.g.

fl_set_object_prehandler(figinset_canvas, GSPreHandler); // figinset_canvas id = 
0x3800098 
will output a win of say 0x3800074, which is a totally different window !

Also, experiments proved it wasn't an issue with the figinset_canvas -
I changed figinset to temporarily use the WorkArea window to communicate,
and still the ClientMessages of interest got dropped. However, I was also
delivering ClientMessages when WorkArea::setScrollBar() was invoked -
these got through !  Maybe xforms is dropping all ClientMessages of a
certain ev.xclient.message_type ? (My scrollbar one used 404040 decimal,
whereas gs ClientMessages get delivered with a value of "503").

My questions :

1) is there docs for the ghostscript stuff ? has anyone looked at the relevant
part of the gs source or asked the developers ? I couldn't find anything
useful at wisc.edu

2) has this been taken / should I take this to the xforms bug^Wmailing list ?  

3) is there perhaps some way of communicating with gs without
having to use the X server and ClientMessages ?  

4) is it possible to install a filter into xforms that will get ALL events 
from the real X event queue *before* xforms gets to it ?
 
5) or is it possible to observe the X event queue externally ?  

6) What now ? Should I implement one of the previously mentioned gross
hacks ? Namely a delayed clean-up process...

7) Can someone apply the figinset patch which adds some debugging and
cleans up the code a bit ?

8) is anybody still reading this ;)

thanks
john
Index: ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/ChangeLog,v
retrieving revision 1.691
diff -u -p -r1.691 ChangeLog
--- ChangeLog   2000/11/19 16:07:18     1.691
+++ ChangeLog   2000/11/20 08:41:48
@@ -1,3 +1,12 @@
+2000-11-20  John Levon  <[EMAIL PROTECTED]>
+
+       * src/debug.h:
+       * src/debug.C: added GS debugging option
+
+       * src/insets/figinset.C: clean up a little, add debugging
+
+       * src/spellchecker.C: added comment
+
 2000-11-19  Juergen Vigna  <[EMAIL PROTECTED]>
 
        * src/insets/insettabular.C (draw): fixed text border redraw problem.
Index: src/debug.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/debug.C,v
retrieving revision 1.13
diff -u -p -r1.13 debug.C
--- src/debug.C 2000/11/14 02:01:55     1.13
+++ src/debug.C 2000/11/20 08:41:48
@@ -49,6 +49,7 @@ static error_item errorTags[] = {
        { Debug::DEPEND,    "depend",    N_("Dependency information")},
        { Debug::INSETS,    "insets",    N_("LyX Insets")},
        { Debug::FILES,     "files",     N_("Files used by LyX")},
+       { Debug::GS,        "gs",        N_("Ghostscript interaction")},
         { Debug::ANY,       "any",       N_("All debugging messages")}
 };
 
@@ -61,7 +62,7 @@ Debug::type const Debug::ANY = Debug::ty
        Debug::PARSER | Debug::LYXRC | Debug::KBMAP | Debug::LATEX |
        Debug::MATHED | Debug::FONT | Debug::TCLASS | Debug::LYXVC |
        Debug::LYXSERVER | Debug::ROFF | Debug::ACTION | Debug::LYXLEX |
-       Debug::DEPEND | Debug::INSETS | Debug::FILES);
+       Debug::DEPEND | Debug::INSETS | Debug::FILES | Debug::GS);
 
 
 Debug::type Debug::value(string const & val) 
Index: src/debug.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/debug.h,v
retrieving revision 1.20
diff -u -p -r1.20 debug.h
--- src/debug.h 2000/11/14 02:01:55     1.20
+++ src/debug.h 2000/11/20 08:41:48
@@ -67,7 +67,9 @@ struct Debug {
                ///
                INSETS     = (1 << 17),
                ///
-               FILES      = (1 << 18)
+               FILES      = (1 << 18),
+               /// ghostscript handling (figures)
+               GS         = (1 << 19)
        };
        ///
 //     static const type ANY = type(INFO | INIT | KEY | GUI |
Index: src/insets/figinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/figinset.C,v
retrieving revision 1.92
diff -u -p -r1.92 figinset.C
--- src/insets/figinset.C       2000/11/08 09:39:46     1.92
+++ src/insets/figinset.C       2000/11/20 08:41:48
@@ -134,13 +134,14 @@ static
 void addpidwait(int pid)
 {
        // adds pid to pid wait list
+       lyxerr[Debug::GS] << "Adding wait for pid " << pid << endl;
        pidwaitlist.push_back(pid);
 
        if (lyxerr.debugging()) {
-               lyxerr << "Pids to wait for: \n";
+               lyxerr[Debug::GS] << "Pids to wait for: \n";
                copy(pidwaitlist.begin(), pidwaitlist.end(),
-                    std::ostream_iterator<int>(lyxerr, "\n"));
-               lyxerr << flush;
+                    std::ostream_iterator<int>(lyxerr[Debug::GS], "\n"));
+               lyxerr[Debug::GS] << flush;
        }
 }
 
@@ -148,6 +149,7 @@ void addpidwait(int pid)
 static
 string make_tmp(int pid)
 {
+       // FIXME: is this secure ?
        return system_tempdir + "/~lyxgs" + tostr(pid) + ".ps";
 }
 
@@ -155,143 +157,180 @@ string make_tmp(int pid)
 static
 void kill_gs(int pid, int sig)
 {
-       if (lyxerr.debugging()) 
-               lyxerr << "Killing gs " << pid << endl;
-       lyx::kill(pid, sig);
-       lyx::unlink(make_tmp(pid));
+       lyxerr[Debug::GS] << "Killing ghostscript, pid : " << pid << endl; 
+       if (lyx::kill(pid, sig))
+               lyxerr[Debug::GS] << "Failed, reason : " << strerror(errno) << endl;
+
+       string tmpfile = make_tmp(pid); 
+       lyxerr[Debug::GS] << "Removing gs temporary file " << tmpfile << endl;
+       if (lyx::unlink(tmpfile))
+               lyxerr[Debug::GS] << "Failed, reason : " << strerror(errno) << endl;
 }
 
+extern "C"
+int GSPreHandler(FL_OBJECT *, int xformsev, FL_Coord, FL_Coord, int, void *ev)
+{
+       lyxerr[Debug::GS] << "GSPre: Event " << xformsev << endl;
+
+       XEvent * e = reinterpret_cast<XEvent *>(ev);
+
+       if (!e) {
+               lyxerr[Debug::GS] << "GSPre: Empty X event struct" << endl;
+               return !FL_PREEMPT;
+       }
+
+       lyxerr[Debug::GS] << "GSPre: Raw event " << e->type << endl;
+       
+       if (e->type == ClientMessage) {
+               XClientMessageEvent *cme = reinterpret_cast<XClientMessageEvent *>(e);
+               lyxerr[Debug::GS] << "ClientMessage, win:[0x" << hex << cme->window << 
+dec << "] gs:[" 
+                       << cme->data.l[0] << "] pm:[" << cme->data.l[1] << "]" << 
+endl;
+       }
+
+       return !FL_PREEMPT;
+}
 
 extern "C" // static
 int GhostscriptMsg(FL_OBJECT *, Window, int, int,
                   XEvent * ev, void *)
 {
+       lyxerr[Debug::GS] << "Received a GhostscriptMsg" << endl;
+
        XClientMessageEvent * e = reinterpret_cast<XClientMessageEvent*>(ev);
 
        if (lyxerr.debugging()) {
-               lyxerr << "ClientMessage, win:[xx] gs:[" << e->data.l[0]
-                      << "] pm:[" << e->data.l[1] << "]" << endl;
+               lyxerr[Debug::GS] << "ClientMessage, win:[0x" << hex << e->window << 
+dec << "] gs:[" 
+                       << e->data.l[0] << "] pm:[" << e->data.l[1] << "]"
+                       << " type " << e->message_type << endl;
        }
 
        // just kill gs, that way it will work for sure
-       // This loop looks like S**T so it probably is...
-       for (bitmaps_type::iterator it = bitmaps.begin();
-            it != bitmaps.end(); ++it)
-               if (static_cast<long>((*it)->bitmap) ==
-                   static_cast<long>(e->data.l[1])) {
-                       // found the one
-                       figdata * p = (*it);
-                       p->gsdone = true;
+       for (bitmaps_type::iterator it = bitmaps.begin(); 
+               it != bitmaps.end(); ++it) {
 
-                       // first update p->bitmap, if necessary
-                       if (p->bitmap != None
-                           && p->flags > (1|8) && gs_color && p->wid) {
-                               // query current colormap and re-render
-                               // the pixmap with proper colors
-                               XWindowAttributes wa;
-                               register XImage * im;
-                               int i;
-                               int y;
-                               int spc1 = gs_spc - 1;
-                               int spc2 = gs_spc * gs_spc;
-                               int wid = p->wid;
-                               int forkstat;
-                               Display * tmpdisp;
-                               GC gc = local_gc_copy;
-
-                               XGetWindowAttributes(fl_get_display(),
-                                                    fl_get_canvas_id(
-                                                            figinset_canvas),
-                                                    &wa);
-                               XFlush(fl_get_display());
-                               if (lyxerr.debugging()) {
-                                       lyxerr << "Starting image translation "
-                                              << p->bitmap << " "
-                                              << p->flags << " "
-                                              << p->wid << "x" << p->hgh
-                                              << " " << wa.depth
-                                              << " " << XYPixmap << endl;
-                               }
-                               // now fork rendering process
-                               forkstat = fork();
-                               if (forkstat == -1) {
-                                       lyxerr.debug()
-                                               << "Cannot fork, using slow "
-                                               "method for pixmap translation." << 
endl;
-                                       tmpdisp = fl_get_display();
-                               } else if (forkstat > 0) { // parent
-                                       // register child
-                                       if (lyxerr.debugging()) {
-                                               lyxerr << "Spawned child "
-                                                      << forkstat << endl;
-                                       }
-                                       addpidwait(forkstat);
-                                       break;
-                               } else {  // child
-                                       tmpdisp = 
XOpenDisplay(DisplayString(fl_get_display()));
-                                       XFlush(tmpdisp);
-                               }
-                               im = XGetImage(tmpdisp, p->bitmap, 0, 0,
-                                              p->wid, p->hgh, (1<<wa.depth)-1, 
XYPixmap);
+               // don't you just love X ;)
+               if (static_cast<long>((*it)->bitmap) != 
+static_cast<long>(e->data.l[1]))
+                       continue;
+
+               figdata * p = (*it);
+               p->gsdone = true;
+
+               // FIXME: why SIGHUP rather than SIGTERM ?
+               if (p->bitmap == None) {
+                       lyxerr[Debug::GS] << "Killing ghostscript pid " << p->gspid <<
+                               ", bitmap == None" << endl;
+                       kill_gs(p->gspid, SIGHUP);
+                       break;
+               }
+
+               // Someone should enter IOCCC - what's with flags here ?
+               if (!(p->flags > (1|8) && gs_color && p->wid)) {
+                       lyxerr[Debug::GS] << "Killing ghostscript pid " << p->gspid <<
+                               ", (!(p->flags > (1|8) && gs_color && p->wid))" << 
+endl;
+                       kill_gs(p->gspid, SIGHUP);
+                       break;
+               
+               }
+
+               // so here, we update bitmap 
+                
+               // query current colormap and re-render
+               // the pixmap with proper colors
+               XWindowAttributes wa;
+               register XImage * im;
+               int i;
+               int spc1 = gs_spc - 1;
+               int spc2 = gs_spc * gs_spc;
+               int wid = p->wid;
+               int forkstat;
+               Display * tmpdisp;
+               GC gc = local_gc_copy;
+
+               XGetWindowAttributes(fl_get_display(), 
+fl_get_canvas_id(figinset_canvas), &wa);
+               XFlush(fl_get_display());
+                
+               if (lyxerr.debugging()) {
+                       lyxerr << "Starting image translation "
+                              << p->bitmap << " "
+                              << p->flags << " "
+                              << p->wid << "x" << p->hgh
+                              << " " << wa.depth
+                              << " " << XYPixmap << endl;
+               }
+                
+               // now fork rendering process
+               forkstat = fork();
+               if (forkstat == -1) {
+                       lyxerr[Debug::GS] << 
+                               "Cannot fork, using slow method for pixmap 
+translation." << endl;
+                               tmpdisp = fl_get_display();
+               } else if (forkstat > 0) { // parent
+                       lyxerr[Debug::GS] << "Spawned child " << forkstat << endl;
+                       // register child
+                       addpidwait(forkstat);
+                       break;
+               } else { // child
+                       tmpdisp = XOpenDisplay(DisplayString(fl_get_display()));
+                       XFlush(tmpdisp);
+               }
+
+               // now we are either the young child, or we didn't fork at all 
+
+               im = XGetImage(tmpdisp, p->bitmap, 0, 0,
+                              p->wid, p->hgh, (1<<wa.depth)-1, XYPixmap);
+               XFlush(tmpdisp);
+
+               if (!im) {
+                       lyxerr[Debug::GS] << "Child: Error getting the image" << endl;
+                       goto noim;
+               }
+               lyxerr[Debug::GS] << "Child: got the image" << endl;
+
+               { // mother always told you goto was bad 
+               // query current colormap
+               XColor * cmap = new XColor[gs_allcolors];
+                
+               for (i = 0; i < gs_allcolors; ++i) 
+                       cmap[i].pixel = i;
+                        
+               XQueryColors(tmpdisp, fl_state[fl_get_vclass()].colormap, cmap, 
+gs_allcolors);
+               XFlush(tmpdisp);
+
+               // now we process all the image
+               for (int y = 0; y < p->hgh; ++y) {
+                       for (int x = 0; x < wid; ++x) {
+                               XColor * pc = cmap + XGetPixel(im, x, y);
                                XFlush(tmpdisp);
-                               if (lyxerr.debugging()) {
-                                       lyxerr << "Got the image" << endl;
-                               }
-                               if (!im) {
-                                       if (lyxerr.debugging()) {
-                                               lyxerr << "Error getting the image" << 
endl;
-                                       }
-                                       goto noim;
-                               }
-                               {
-                               // query current colormap
-                                       XColor * cmap = new XColor[gs_allcolors];
-                                       for (i = 0; i < gs_allcolors; ++i) 
cmap[i].pixel = i;
-                                       XQueryColors(tmpdisp,
-                                                    fl_state[fl_get_vclass()]
-                                                    .colormap, cmap,
-                                                    gs_allcolors);
-                                       XFlush(tmpdisp);
-                               // now we process all the image
-                                       for (y = 0; y < p->hgh; ++y) {
-                                               for (int x = 0; x < wid; ++x) {
-                                                       XColor * pc = cmap +
-                                                               XGetPixel(im, x, y);
-                                                       XFlush(tmpdisp);
-                                                       XPutPixel(im, x, y,
-                                                                 
gs_pixels[((pc->red+6553)*
-                                                                            
spc1/65535)*spc2+((pc->green+6553)*
-                                                                                      
        spc1/65535)*gs_spc+((pc->blue+6553)*
-                                                                                      
                            spc1/65535)]);
-                                                       XFlush(tmpdisp);
-                                               }
-                                       }
-                               // This must be correct.
-                                       delete [] cmap;
-                                       if (lyxerr.debugging()) {
-                                               lyxerr << "Putting image back"
-                                                      << endl;
-                                       }
-                                       XPutImage(tmpdisp, p->bitmap,
-                                                 gc, im, 0, 0,
-                                                 0, 0, p->wid, p->hgh);
-                                       XDestroyImage(im);
-                                       if (lyxerr.debugging()) {
-                                               lyxerr << "Done translation"
-                                                      << endl;
-                                       }
-                               }
-                         noim:
-                               kill_gs(p->gspid, SIGHUP);
-                               if (forkstat == 0) {
-                                       XCloseDisplay(tmpdisp);
-                                       _exit(0);
-                               }
-                       } else {
-                               kill_gs(p->gspid, SIGHUP);
+                               XPutPixel(im, x, y,
+                                       gs_pixels[
+                                               ((pc->red+6553)*spc1/65535)*spc2
+                                               + (pc->green+6553 * spc1/65535)*gs_spc
+                                               + (pc->blue+6553 * spc1/65535)
+                                       ]);
+                               XFlush(tmpdisp);
                        }
-                       break;
                }
+
+               // This must be correct.
+               delete [] cmap;
+                
+               lyxerr[Debug::GS] << "Putting image back" << endl;
+                
+               XPutImage(tmpdisp, p->bitmap, gc, im, 0, 0, 0, 0, p->wid, p->hgh);
+               XDestroyImage(im);
+               lyxerr[Debug::GS] << "Done translation" << endl;
+               } // end goto allowance 
+
+         noim:
+               lyxerr[Debug::GS] << "Killing ghostscript " << p->gspid << endl;
+               kill_gs(p->gspid, SIGHUP);
+
+               if (forkstat == 0) {
+                       // we were a child, clean up 
+                       XCloseDisplay(tmpdisp);
+                       _exit(0);
+               }
+       }
        return 0;
 }
 
@@ -340,10 +379,7 @@ void AllocColors(int num)
 static
 void AllocGrays(int num)
 {
-       if (lyxerr.debugging()) {
-               lyxerr << "Allocating grayscale colormap "
-                      << num << endl;
-       }
+       lyxerr.debug() << "Allocating grayscale colormap " << num << endl;
 
        if (num < 4) {
                lyxerr << "Error allocating grayscale colormap." << endl;
@@ -360,10 +396,7 @@ void AllocGrays(int num)
                        if (i) XFreeColors(fl_get_display(),
                                           fl_state[fl_get_vclass()].colormap,
                                           gs_pixels, i, 0);
-                       if (lyxerr.debugging()) {
-                               lyxerr << "Cannot allocate grayscale " 
-                                      << num << endl;
-                       }
+                       lyxerr.debug() << "Cannot allocate grayscale " << num << endl;
                        AllocGrays(num / 2);
                        return;
                }
@@ -384,6 +417,10 @@ void InitFigures()
        // first get visual
        gs_color = false;
        if (lyxrc.use_gui) {
+               lyxerr[Debug::GS] << "fig Canvas ID : " 
+                       << hex << fl_get_canvas_id(figinset_canvas) << dec << endl;
+               if (lyxerr.debugging(Debug::GS))
+                       fl_set_object_prehandler(figinset_canvas, GSPreHandler);
                fl_add_canvas_handler(figinset_canvas, ClientMessage,
                                      GhostscriptMsg,
                                      current_view->owner()->getForm());
@@ -439,8 +476,9 @@ void freefigdata(figdata * tmpdata)
 
        if (tmpdata->gspid > 0) {
                int pid = tmpdata->gspid;
-               // kill ghostscript and unlink it's files
+               // kill ghostscript and unlink its files
                tmpdata->gspid = -1;
+               lyxerr[Debug::GS] << "Killing ghostscript from freefigdata(), pid " << 
+pid << endl;
                kill_gs(pid, SIGKILL);
        }
 
@@ -449,7 +487,185 @@ void freefigdata(figdata * tmpdata)
        delete tmpdata;
 }
 
+static
+void gs_child(unsigned long bg_pixel, queue_element *p)
+{
+       Display * tempdisp = XOpenDisplay(DisplayString(fl_get_display()));
 
+       lyxerr[Debug::GS] << "Started GS child." << endl;
+
+       // create translation file
+       ofstream ofs;
+       // FIXME: not secure ?
+       ofs.open(make_tmp(getpid()).c_str());
+       ofs << "gsave clippath pathbbox grestore\n4 dict begin\n"
+           << "/ury exch def /urx exch def /lly exch def /llx exch def\n"
+           << p->data->wid / 2.0 << " "
+           << p->data->hgh / 2.0 << " translate\n"
+           << p->data->angle << " rotate\n"
+           << -(p->data->raw_wid / 2.0) << " "
+           << -(p->data->raw_hgh / 2.0) << " translate\n"
+           << p->rx / 72.0 << " " << p->ry / 72.0
+           << " scale\n"
+           << -p->ofsx << " " << -p->ofsy << " translate\n"
+           << "end" << endl;
+       ofs.close(); // Don't remove this.
+
+       // gs process - set ghostview environment first
+       ostringstream t2;
+       t2 << "GHOSTVIEW=" << fl_get_canvas_id(figinset_canvas)
+          << ' ' << p->data->bitmap;
+
+       // now set up ghostview property on a window
+       // #warning BUG seems that the only bug here
+       // might be the hardcoded dpi.. Bummer!
+       ostringstream t1;
+       t1 << "0 0 0 0 " << p->data->wid << ' '
+          << p->data->hgh << " 72 72 0 0 0 0";
+       
+       lyxerr[Debug::GS] << "GSChild: Will set GHOSTVIEW property to [" << t1.str() 
+<< "]" << endl;
+
+       // grab server to prevent other child
+       // interfering with setting GHOSTVIEW property
+       lyxerr[Debug::GS] << "GSChild: Grabbing the server" << endl;
+       XGrabServer(tempdisp);
+
+       // wait until property is deleted if executing multiple
+       // ghostscripts
+       for (;;) {
+               int nprop;
+               Atom * prop = XListProperties(tempdisp, 
+fl_get_canvas_id(figinset_canvas), &nprop);
+               if (!prop) {
+                       lyxerr[Debug::GS] << "GSChild: No properties found for window 
+id " 
+                               << hex << fl_get_canvas_id(figinset_canvas) << dec << 
+endl;
+                       break;
+               } 
+
+               bool err = true;
+               for (int i = 0; i < nprop; ++i) {
+                       char * p = XGetAtomName(tempdisp, prop[i]);
+                       lyxerr[Debug::GS] << "GSChild: Atom " << p << " for window id 
+"
+                               << hex << fl_get_canvas_id(figinset_canvas) << dec << 
+endl;
+                       if (strcmp(p, "GHOSTVIEW") == 0) {
+                               err = false;
+                               // We free it when we leave so we don't leak.
+                               XFree(p);
+                               break;
+                       }
+                       XFree(p);
+               }
+
+               XFree(reinterpret_cast<char *>(prop)); // jc:
+               if (err) 
+                       break;
+
+               // ok, property found, we must wait until ghostscript deletes it
+               lyxerr[Debug::GS] << "GSChild: Releasing the server\n[" << getpid() << 
+"] GHOSTVIEW property"
+                               " found. Waiting." << endl;
+
+               lyxerr[Debug::GS] << "GSChild: Ungrabbing the server" << endl;
+               XUngrabServer(tempdisp);
+               XFlush(tempdisp);
+               ::sleep(1);
+               lyxerr[Debug::GS] << "GSChild: Grabbing the server" << endl;
+               XGrabServer(tempdisp);
+       }
+
+       lyxerr[Debug::GS] << "GSChild: changing property GHOSTVIEW to "
+               << t1.str() << " in window id " << hex << 
+fl_get_canvas_id(figinset_canvas) << dec << endl;
+
+       XChangeProperty(tempdisp, 
+               fl_get_canvas_id(figinset_canvas),
+               XInternAtom(tempdisp, "GHOSTVIEW", false),
+               XInternAtom(tempdisp, "STRING", false),
+               8, PropModeAppend, 
+               reinterpret_cast<unsigned char*>(const_cast<char*>(t1.str().c_str())),
+               int(t1.str().size()));
+
+       lyxerr[Debug::GS] << "GSChild: Ungrabbing the server" << endl;
+       XUngrabServer(tempdisp);
+       XFlush(tempdisp);
+
+       ostringstream t3;
+
+       switch (p->data->flags & 3) {
+               case 0: t3 << 'H'; break; // Hidden
+               case 1: t3 << 'M'; break; // Mono
+               case 2: t3 << 'G'; break; // Gray
+               case 3: 
+                       (color_visual) ?  (t3 << 'C') : (t3 << 'G'); 
+                       break;
+       }
+
+       t3 << ' ' << BlackPixelOfScreen(DefaultScreenOfDisplay(tempdisp))
+          << ' ' << bg_pixel;
+
+       lyxerr[Debug::GS] << "GSChild: Grabbing the server" << endl;
+       XGrabServer(tempdisp); // doesn't XChangeProperty do its own locking ???
+       XChangeProperty(tempdisp, 
+                       fl_get_canvas_id(figinset_canvas),
+                       XInternAtom(tempdisp,
+                                   "GHOSTVIEW_COLORS", false),
+                       XInternAtom(tempdisp, "STRING", false),
+                       8, PropModeReplace, 
+                       reinterpret_cast<unsigned 
+char*>(const_cast<char*>(t3.str().c_str())),
+                       int(t3.str().size()));
+       lyxerr[Debug::GS] << "GSChild: Ungrabbing the server" << endl;
+       XUngrabServer(tempdisp);
+       XFlush(tempdisp);
+ 
+       lyxerr[Debug::GS] << "GSChild: Releasing the server" << endl;
+       XCloseDisplay(tempdisp);
+
+       // set up environment
+       int ne = 0;
+       while (environ[ne])
+               ++ne;
+       typedef char * char_p;
+       char **env = new char_p[ne + 2];
+       string tmp = t2.str().c_str();
+       env[0] = new char[tmp.size() + 1];
+       std::copy(tmp.begin(), tmp.end(), env[0]);
+       env[0][tmp.size()] = '\0';
+       ::memcpy(&env[1], environ, sizeof(char*) * (ne + 1));
+       environ = env;
+
+       // now make gs command
+       // close(0);
+       // close(1); do NOT close. If GS writes out
+       // errors it would hang. (Matthias 290596) 
+
+       string rbuf = "-r" + tostr(p->rx) + "x" + tostr(p->ry);
+       string gbuf = "-g" + tostr(p->data->wid) + "x" + tostr(p->data->hgh);
+
+       // now chdir into dir with .eps file, to be on the safe
+       // side
+       lyx::chdir(OnlyPath(p->data->fname));
+       // make temp file name
+       string tmpf = make_tmp(getpid());
+       lyxerr[Debug::GS] << "starting gs " << tmpf << " "
+                      << p->data->fname
+                      << ", pid: " << getpid() << endl;
+
+       int err = ::execlp(lyxrc.ps_command.c_str(), 
+                        lyxrc.ps_command.c_str(), 
+                        "-sDEVICE=x11",
+                        "-dNOPAUSE", "-dQUIET",
+                        "-dSAFER", 
+                        rbuf.c_str(), gbuf.c_str(), tmpf.c_str(), 
+                        p->data->fname.c_str(), 
+                        "showpage.ps", "quit.ps", "-", 0);
+
+       // if we are still there, an error occurred.
+       lyxerr[Debug::GS] << "Error executing ghostscript. " << "Code: " << err << 
+endl;
+       lyxerr.debug() << "Cmd: " 
+                      << lyxrc.ps_command
+                      << " -sDEVICE=x11 -dNOPAUSE -dQUIET -DSAFER"
+                      << rbuf << " " << gbuf << " " << tmpf << " "
+                      << p->data->fname << "showpage.ps quit.ps - " << endl;
+       _exit(0);       // no gs?
+}
+
 static
 void runqueue()
 {
@@ -458,6 +674,7 @@ void runqueue()
                lyxColorHandler->colorPixel(LColor::background);
        
        // run queued requests for ghostscript, if any
+
        if (!gsrunning && gs_color && !gs_xcolor) {
                // here alloc all colors, so that gs will use only
                // those we allocated for it
@@ -466,20 +683,20 @@ void runqueue()
        }
        
        while (gsrunning < MAXGS) {
-               //char tbuf[384]; //, tbuf2[80];
-               Atom * prop;
-               int nprop, i;
-
                if (gsqueue.empty()) {
                        if (!gsrunning && gs_xcolor) {
                                // de-allocate rest of colors
                                // *****
                                gs_xcolor = false;
                        }
+                       lyxerr[Debug::GS] << "GS Runqueue empty, doing nothing." << 
+endl;
                        return;
                }
+
                queue_element * p = &gsqueue.front();
+
                if (!p->data) {
+                       lyxerr[Debug::GS] << "GS Runqueue entry with NULL data !" << 
+endl;
                        gsqueue.pop();
                        continue;
                }
@@ -487,195 +704,17 @@ void runqueue()
                int pid = ::fork();
                
                if (pid == -1) {
-                       if (lyxerr.debugging()) {
-                               lyxerr << "GS start error! Cannot fork."
-                                      << endl;
-                       }
+                       lyxerr[Debug::GS] << "GS start error! Cannot fork." << endl;
                        p->data->broken = true;
                        p->data->reading = false;
                        return;
+               } else if (pid == 0) { // child
+                       gs_child(background_pixel, p);
+                       /* NOTREACHED */
                }
-               if (pid == 0) { // child
-                       char ** env;
-                       int ne = 0;
-                       Display * tempdisp = 
XOpenDisplay(DisplayString(fl_get_display()));
-
-                       // create translation file
-                       ofstream ofs;
-                       ofs.open(make_tmp(getpid()).c_str());
-                       ofs << "gsave clippath pathbbox grestore\n"
-                           << "4 dict begin\n"
-                           << "/ury exch def /urx exch def /lly exch def "
-                               "/llx exch def\n"
-                           << p->data->wid / 2.0 << " "
-                           << p->data->hgh / 2.0 << " translate\n"
-                           << p->data->angle << " rotate\n"
-                           << -(p->data->raw_wid / 2.0) << " "
-                           << -(p->data->raw_hgh / 2.0) << " translate\n"
-                           << p->rx / 72.0 << " " << p->ry / 72.0
-                           << " scale\n"
-                           << -p->ofsx << " " << -p->ofsy << " translate\n"
-                           << "end" << endl;
-                       ofs.close(); // Don't remove this.
-
-                       // gs process - set ghostview environment first
-                       ostringstream t2;
-                       t2 << "GHOSTVIEW=" << fl_get_canvas_id(figinset_canvas)
-                          << ' ' << p->data->bitmap;
-                       // now set up ghostview property on a window
-                       // #warning BUG seems that the only bug here
-                       // might be the hardcoded dpi.. Bummer!
-                       ostringstream t1;
-                       t1 << "0 0 0 0 " << p->data->wid << ' '
-                          << p->data->hgh << " 72 72 0 0 0 0";
-                       
-                       if (lyxerr.debugging()) {
-                               lyxerr << "Will set GHOSTVIEW property to ["
-                                      << t1.str() << "]" << endl;
-                       }
-                       // wait until property is deleted if executing multiple
-                       // ghostscripts
-                       XGrabServer(tempdisp);
-                       for (;;) {
-                               // grab server to prevent other child
-                               // interfering with setting GHOSTVIEW property
-                               // The grabbing goes on for too long, is it
-                               // really needed? (Lgb)
-                               // I moved most of the grabs... (Lgb)
-                               if (lyxerr.debugging()) {
-                                       lyxerr << "Grabbing the server"
-                                              << endl;
-                               }
-                               prop = XListProperties(tempdisp,
-                                                      fl_get_canvas_id(
-                                       figinset_canvas), &nprop);
-                               if (!prop) break;
-
-                               bool err = true;
-                               for (i = 0; i < nprop; ++i) {
-                                       char * p = XGetAtomName(tempdisp,
-                                                               prop[i]);
-                                       if (strcmp(p, "GHOSTVIEW") == 0) {
-                                               err = false;
-                                               // We free it when we leave so we 
don't leak.
-                                               XFree(p);
-                                               break;
-                                       }
-                                       XFree(p);
-                               }
-                               XFree(reinterpret_cast<char *>(prop)); // jc:
-                               if (err) break;
-                               // ok, property found, we must wait until
-                               // ghostscript deletes it
-                               if (lyxerr.debugging()) {
-                                       lyxerr << "Releasing the server\n["
-                                              << getpid()
-                                              << "] GHOSTVIEW property"
-                                               " found. Waiting." << endl;
-                               }
-                               XUngrabServer(tempdisp);
-                               XFlush(tempdisp);
-                               ::sleep(1);
-                               XGrabServer(tempdisp);
-                       }
-                       XChangeProperty(tempdisp, 
-                                       fl_get_canvas_id(figinset_canvas),
-                                       XInternAtom(tempdisp, "GHOSTVIEW", false),
-                                       XInternAtom(tempdisp, "STRING", false),
-                                       8, PropModeAppend, 
-                                       reinterpret_cast<unsigned 
char*>(const_cast<char*>(t1.str().c_str())),
-                                       int(t1.str().size()));
-                       XUngrabServer(tempdisp);
-                       XFlush(tempdisp);
-
-                       ostringstream t3;
-
-                       switch (p->data->flags & 3) {
-                       case 0: t3 << 'H'; break; // Hidden
-                       case 1: t3 << 'M'; break; // Mono
-                       case 2: t3 << 'G'; break; // Gray
-                       case 3:
-                               if (color_visual) 
-                                       t3 << 'C'; // Color
-                               else 
-                                       t3 << 'G'; // Gray
-                               break;
-                       }
-       
-                       t3 << ' ' << 
BlackPixelOfScreen(DefaultScreenOfDisplay(tempdisp))
-                          << ' ' << background_pixel;
 
-                       XGrabServer(tempdisp);
-                       XChangeProperty(tempdisp, 
-                                       fl_get_canvas_id(figinset_canvas),
-                                       XInternAtom(tempdisp,
-                                                   "GHOSTVIEW_COLORS", false),
-                                       XInternAtom(tempdisp, "STRING", false),
-                                       8, PropModeReplace, 
-                                       reinterpret_cast<unsigned 
char*>(const_cast<char*>(t3.str().c_str())),
-                                       int(t3.str().size()));
-                       XUngrabServer(tempdisp);
-                       XFlush(tempdisp);
-                       
-                       if (lyxerr.debugging()) {
-                               lyxerr << "Releasing the server" << endl;
-                       }
-                       XCloseDisplay(tempdisp);
-
-                       // set up environment
-                       while (environ[ne])
-                               ++ne;
-                       typedef char * char_p;
-                       env = new char_p[ne + 2];
-                       string tmp = t2.str().c_str();
-                       env[0] = new char[tmp.size() + 1];
-                       std::copy(tmp.begin(), tmp.end(), env[0]);
-                       env[0][tmp.size()] = '\0';
-                       ::memcpy(&env[1], environ, sizeof(char*) * (ne + 1));
-                       environ = env;
-
-                       // now make gs command
-                       // close(0);
-                       // close(1); do NOT close. If GS writes out
-                       // errors it would hang. (Matthias 290596) 
-
-                       string rbuf = "-r" + tostr(p->rx) + "x" + tostr(p->ry);
-                       string gbuf = "-g" + tostr(p->data->wid) + "x" + 
tostr(p->data->hgh);
-
-                       // now chdir into dir with .eps file, to be on the safe
-                       // side
-                       lyx::chdir(OnlyPath(p->data->fname));
-                       // make temp file name
-                       string tmpf = make_tmp(getpid());
-                       if (lyxerr.debugging()) {
-                               lyxerr << "starting gs " << tmpf << " "
-                                      << p->data->fname
-                                      << ", pid: " << getpid() << endl;
-                       }
-
-                       int err = ::execlp(lyxrc.ps_command.c_str(), 
-                                        lyxrc.ps_command.c_str(), 
-                                        "-sDEVICE=x11",
-                                        "-dNOPAUSE", "-dQUIET",
-                                        "-dSAFER", 
-                                        rbuf.c_str(), gbuf.c_str(), tmpf.c_str(), 
-                                        p->data->fname.c_str(), 
-                                        "showpage.ps", "quit.ps", "-", 0);
-                       // if we are still there, an error occurred.
-                       lyxerr << "Error executing ghostscript. "
-                              << "Code: " << err << endl;
-                       lyxerr.debug() << "Cmd: " 
-                                      << lyxrc.ps_command
-                                      << " -sDEVICE=x11 "
-                                      << tmpf << ' '
-                                      << p->data->fname << endl;
-                       _exit(0);       // no gs?
-               }
-               // normal process (parent)
-               if (lyxerr.debugging()) {
-                       lyxerr << "GS ["  << pid << "] started" << endl;
-               }
-
+               // parent
+               lyxerr[Debug::GS] << "Parent: GS ["  << pid << "] started" << endl;
                p->data->gspid = pid;
                ++gsrunning;
                gsqueue.pop();
@@ -695,6 +734,7 @@ void addwait(int psx, int psy, int pswid
 
        p.data = data;
 
+       lyxerr[Debug::GS] << "Adding process to gsqueue" << endl;
        gsqueue.push(p);
 
        // if possible, run the queue
@@ -731,8 +771,8 @@ figdata * getfigdata(int wid, int hgh, s
        p->flags = flags;
        bitmaps.push_back(p);
        XWindowAttributes wa;
-       XGetWindowAttributes(fl_get_display(), fl_get_canvas_id(
-               figinset_canvas), &wa);
+       XGetWindowAttributes(fl_get_display(), 
+               fl_get_canvas_id(figinset_canvas), &wa);
 
        if (lyxerr.debugging()) {
                lyxerr << "Create pixmap disp:" << fl_get_display()
@@ -747,15 +787,17 @@ figdata * getfigdata(int wid, int hgh, s
        p->broken = false;
        p->gspid = -1;
        if (flags) {
-               p->bitmap = XCreatePixmap(fl_get_display(), fl_get_canvas_id(
-                       figinset_canvas), wid, hgh, wa.depth);
+               p->bitmap = XCreatePixmap(fl_get_display(), 
+                       fl_get_canvas_id(figinset_canvas), wid, hgh, wa.depth);
                p->gsdone = false;
                // initialize reading of .eps file with correct sizes and stuff
                addwait(psx, psy, pswid, pshgh, p);
                p->reading = true;
+               lyxerr[Debug::GS] << "Initialising new figdata, waiting for bitmap" << 
+endl; 
        } else {
                p->bitmap = None;
                p->gsdone = true;
+               lyxerr[Debug::GS] << "Initialising new figdata, empty bitmap" << endl; 
+
        }
 
        return p;
@@ -765,6 +807,7 @@ figdata * getfigdata(int wid, int hgh, s
 static
 void getbitmap(figdata * p)
 {
+       lyxerr[Debug::GS] << "getbitmap: settings gspid to -1" << endl;
        p->gspid = -1;
 }
 
@@ -775,11 +818,7 @@ void makeupdatelist(figdata * p)
        for (figures_type::iterator it = figures.begin();
            it != figures.end(); ++it)
                if ((*it)->data == p) {
-                       if (lyxerr.debugging()) {
-                               lyxerr << "Updating inset "
-                                      << (*it)->inset
-                                      << endl;
-                       }
+                       lyxerr.debug() << "Updating inset " << (*it)->inset << endl;
                        // add inset figures[i]->inset into to_update list
                        current_view->pushIntoUpdateList((*it)->inset);
                }
@@ -789,31 +828,28 @@ void makeupdatelist(figdata * p)
 // this func is only "called" in spellchecker.C
 void sigchldchecker(pid_t pid, int * status)
 {
-       lyxerr.debug() << "Got pid = " << pid << endl;
+       lyxerr[Debug::GS] << "chldchecker: Looking for pid = " << pid << endl;
        bool pid_handled = false;
        for (bitmaps_type::iterator it = bitmaps.begin();
             it != bitmaps.end(); ++it) {
                if ((*it)->reading && pid == (*it)->gspid) {
-                       lyxerr.debug() << "Found pid in bitmaps" << endl;
+                       lyxerr[Debug::GS] << "chldchecker: Found pid in bitmaps" << 
+endl;
                        // now read the file and remove it from disk
                        figdata * p = (*it);
                        p->reading = false;
                        if ((*it)->gsdone) *status = 0;
                        if (*status == 0) {
-                               lyxerr.debug() << "GS [" << pid
-                                              << "] exit OK." << endl;
+                               lyxerr[Debug::GS] << "GS [" << pid << "] exit OK." << 
+endl;
+                               bitmap_waiting = true;
+                               p->broken = false;
                        } else {
-                               lyxerr << "GS [" << pid  << "] error "
+                               lyxerr[Debug::GS] << "GS [" << pid  << "] error "
                                       << *status << " E:"
                                       << WIFEXITED(*status)
                                       << " " << WEXITSTATUS(*status)
                                       << " S:" << WIFSIGNALED(*status)
                                       << " " << WTERMSIG(*status) << endl;
-                       }
-                       if (*status == 0) {
-                               bitmap_waiting = true;
-                               p->broken = false;
-                       } else {
+
                                // remove temporary files
                                lyx::unlink(make_tmp(p->gspid));
                                p->gspid = -1;
@@ -821,10 +857,14 @@ void sigchldchecker(pid_t pid, int * sta
                        }
                        makeupdatelist((*it));
                        --gsrunning;
+                       lyxerr[Debug::GS] << "gsrunning now " << gsrunning << endl; 
                        runqueue();
                        pid_handled = true;
                }
        }
+
+       // FIXME: non figinset stuff, should be moved !
+
        if (!pid_handled) {
                lyxerr.debug() << "Checking pid in pidwait" << endl;
                list<int>::iterator it = find(pidwaitlist.begin(),
@@ -871,9 +911,12 @@ void getbitmaps()
 {
        bitmap_waiting = false;
        for (bitmaps_type::iterator it = bitmaps.begin();
-            it != bitmaps.end(); ++it)
+            it != bitmaps.end(); ++it) {
+            lyxerr[Debug::GS] << "getbitmaps, gspid " << (*it)->gspid
+               << " reading " << (*it)->reading << endl; 
                if ((*it)->gspid > 0 && !(*it)->reading)
                        getbitmap((*it));
+       } 
 }
 
 
@@ -911,7 +954,7 @@ void UnregisterFigure(InsetFig * fi)
                        fl_hide_form(tmpfig->inset->form->Figure);
                }
 #if FL_REVISION == 89
-               // CHECK Reactivate this free_form calls
+#warning Reactivate this free_form call, what about 0.90 ?
 #else
                fl_free_form(tmpfig->inset->form->Figure);
                free(tmpfig->inset->form); // Why free?
@@ -946,9 +989,7 @@ InsetFig::InsetFig(int tmpx, int tmpy, B
 
 InsetFig::~InsetFig()
 {
-       if (lyxerr.debugging()) {
-               lyxerr << "Figure destructor called" << endl;
-       }
+       lyxerr.debug() << "Figure destructor called" << endl;
        UnregisterFigure(this);
 }
 
@@ -979,6 +1020,20 @@ void InsetFig::draw(BufferView * bv, LyX
        
        if (bitmap_waiting) getbitmaps();
        
+       lyxerr[Debug::GS] << "Drawing a figure: ";
+       if (!figure)
+               lyxerr[Debug::GS] << "figure NULL ";
+       else if (!figure->data)
+               lyxerr[Debug::GS] << ", figure->data NULL ";
+       else {
+               if (!figure->data->bitmap)
+                       lyxerr[Debug::GS] << ", figure->data->bitmap NULL ";
+
+               lyxerr[Debug::GS] << "reading " << figure->data->reading
+                       << ", broken " << figure->data->broken;
+       }
+       lyxerr[Debug::GS] << endl; 
+
        // I wish that I didn't have to use this
        // but the figinset code is so complicated so
        // I don't want to fiddle with it now.
@@ -1004,7 +1059,7 @@ void InsetFig::draw(BufferView * bv, LyX
                if (figure && figure->data) {
                        if (figure->data->broken)  msg = _("[render error]");
                        else if (figure->data->reading) msg = _("[rendering ... ]");
-               } 
+               }
                else if (fname.empty()) 
                        msg = _("[no file]");
                else if (!IsFileReadable(lfname))
@@ -1143,6 +1198,7 @@ int InsetFig::Latex(Buffer const *, ostr
 
 int InsetFig::Ascii(Buffer const *, ostream &, int) const
 {
+       // why not aalib ;)
        return 0;
 }
 
@@ -1224,11 +1280,8 @@ Inset * InsetFig::Clone(Buffer const & b
 {
        InsetFig * tmp = new InsetFig(100, 100, buffer);
 
-       if (lyxerr.debugging()) {
-               lyxerr << "Clone Figure: buffer:["
-                      << &buffer
-                      << "], cbuffer:[xx]" << endl;
-       }
+       lyxerr.debug() << "Clone Figure: buffer:["
+              << &buffer << "], cbuffer:[xx]" << endl;
 
        tmp->wid = wid;
        tmp->hgh = hgh;
@@ -1407,6 +1460,8 @@ void InsetFig::TempRegenerate()
                cmdbuf = string("\\subfigure{") + tsubcap
                        + string("}{") + cmdbuf + "}";
        }
+       // FIXME: what's the point in all this if cmdbuf doesn't
+       // get put anywhere ?
 }
 
 
@@ -1418,6 +1473,8 @@ void InsetFig::Recompute()
        bool changed = changedfname;
        int newx, newy, nraw_x, nraw_y;
 
+       lyxerr[Debug::GS] << "Recomputing" << endl;
+
        if (changed) GetPSSizes();
 
        float sin_a = sin (angle / DEG2PI);  /* rotation; H. Zeller 021296 */
@@ -1510,6 +1567,8 @@ void InsetFig::Recompute()
        if (changed) {
                figdata * pf = figure->data;
 
+               lyxerr[Debug::GS] << "Figure changed, re-get data" << endl;
+
                // get new data
                if (!lfname.empty() && IsFileReadable(lfname) && (flags & 3)
                    && !lyxrc.ps_command.empty()) {
@@ -1597,9 +1656,7 @@ void InsetFig::CallbackFig(long arg)
        bool regen = false;
        char const * p;
 
-       if (lyxerr.debugging()) {
-               lyxerr << "Figure callback, arg " << arg << endl;
-       }
+       lyxerr.debug() << "Figure callback, arg " << arg << endl;
 
        switch (arg) {
        case 10:
@@ -1726,16 +1783,13 @@ void InsetFig::CallbackFig(long arg)
                        Regenerate();
                        Recompute();
                        /* now update inset */
-                       if (lyxerr.debugging()) {
-                               lyxerr << "Update: ["
-                                      << wid << 'x' << hgh << ']' << endl;
-                       }
+                       lyxerr.debug() << "Update: [" << wid << 'x' << hgh << ']' << 
+endl;
                        current_view->updateInset(this, true);
                        if (arg == 8) {
                                fl_set_focus_object(form->Figure, form->OkBtn);
                                fl_hide_form(form->Figure);
 #if FL_REVISION == 89
-                               // CHECK Reactivate this free_form calls
+#warning CHECK Reactivate this free_form calls
 #else
                                fl_free_form(form->Figure);
                                free(form); // Why free?
@@ -1752,7 +1806,7 @@ void InsetFig::CallbackFig(long arg)
                fl_set_focus_object(form->Figure, form->OkBtn);
                fl_hide_form(form->Figure);
 #if FL_REVISION == 89
-               // CHECK Reactivate this free_form calls
+#warning CHECK Reactivate this free_form calls
                // Jug, is this still a problem?
 #else
                fl_free_form(form->Figure);
@@ -1913,10 +1967,8 @@ void InsetFig::BrowseFile()
        static int once = 0;
        LyXFileDlg fileDlg;
 
-       if (lyxerr.debugging()) {
-               lyxerr << "Filename: "
-                      << owner->fileName() << endl;
-       }
+       lyxerr.debug() << "Filename: " << owner->fileName() << endl;
+
        string p = fl_get_input(form->EpsFile);
 
        string buf = MakeAbsPath(owner->fileName());
@@ -1976,19 +2028,14 @@ void GraphicsCB(FL_OBJECT * obj, long ar
 {
        /* obj->form contains the form */
 
-       if (lyxerr.debugging()) {
-               lyxerr << "GraphicsCB callback: " << arg << endl;
-       }
+       lyxerr.debug() << "GraphicsCB callback: " << arg << endl;
 
        /* find inset we were reacting to */
        for (figures_type::iterator it = figures.begin();
             it != figures.end(); ++it)
                if ((*it)->inset->form && (*it)->inset->form->Figure
                    == obj->form) {
-                       if (lyxerr.debugging()) {
-                               lyxerr << "Calling back figure "
-                                      << (*it) << endl;
-                       }
+                       lyxerr[Debug::GS] << "Calling back figure " << (*it) << endl;
                        (*it)->inset->CallbackFig(arg);
                        return;
                }

Reply via email to