123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- #ifdef HAVE_WAITPID
- #ifdef HAVE_SYS_WAIT_H
- #define _POSIX_SOURCE
- #endif
- #endif
- #include "sys-defines.h"
- #include "extern.h"
- #ifdef HAVE_UNISTD_H
- #ifdef HAVE_SYS_TYPES_H
- #include <sys/types.h>
- #endif
- #include <unistd.h>
- #endif
- #ifdef HAVE_WAITPID
- #ifdef HAVE_SYS_WAIT_H
- #ifdef HAVE_SYS_TYPES_H
- #include <sys/types.h>
- #endif
- #include <sys/wait.h>
- #endif
- #endif
- bool
- _pl_y_end_page (S___(Plotter *_plotter))
- {
- plColorRecord *cptr;
- plXFontRecord *fptr;
- Pixmap bg_pixmap = (Pixmap)0;
- int window_width, window_height;
- pid_t forkval;
-
- window_width = (_plotter->data->imax - _plotter->data->imin) + 1;
- window_height = (_plotter->data->jmin - _plotter->data->jmax) + 1;
-
- if (_plotter->x_double_buffering == X_DBL_BUF_MBX
- || _plotter->x_double_buffering == X_DBL_BUF_DBE)
- {
- int screen;
- Screen *screen_struct;
- screen = DefaultScreen (_plotter->x_dpy);
- screen_struct = ScreenOfDisplay (_plotter->x_dpy, screen);
- bg_pixmap = XCreatePixmap(_plotter->x_dpy,
- _plotter->x_drawable2,
- (unsigned int)window_width,
- (unsigned int)window_height,
- (unsigned int)PlanesOfScreen(screen_struct));
-
- XCopyArea (_plotter->x_dpy, _plotter->x_drawable3, bg_pixmap,
- _plotter->drawstate->x_gc_bg,
- 0, 0,
- (unsigned int)window_width, (unsigned int)window_height,
- 0, 0);
-
- }
-
-
- #ifdef HAVE_X11_EXTENSIONS_XDBE_H
- #ifdef HAVE_DBE_SUPPORT
- if (_plotter->x_double_buffering == X_DBL_BUF_DBE)
-
- {
- XdbeSwapInfo info;
-
-
- info.swap_window = _plotter->x_drawable2;
- info.swap_action = XdbeUndefined;
- XdbeSwapBuffers (_plotter->x_dpy, &info, 1);
-
- XdbeDeallocateBackBufferName (_plotter->x_dpy, _plotter->x_drawable3);
- }
- #endif
- #endif
- #ifdef HAVE_X11_EXTENSIONS_MULTIBUF_H
- #ifdef HAVE_MBX_SUPPORT
- if (_plotter->x_double_buffering == X_DBL_BUF_MBX)
-
- {
-
- XmbufDisplayBuffers (_plotter->x_dpy, 1, &(_plotter->x_drawable3), 0, 0);
- }
- #endif
- #endif
-
- if (_plotter->x_double_buffering == X_DBL_BUF_MBX
- || _plotter->x_double_buffering == X_DBL_BUF_DBE)
- {
- Arg wargs[2];
-
- #ifdef USE_MOTIF
- XtSetArg (wargs[0], XmNlabelPixmap, (Pixmap)bg_pixmap);
- XtSetArg (wargs[1], XmNlabelType, XmPIXMAP);
- XtSetValues (_plotter->y_canvas, wargs, (Cardinal)2);
- #else
- XtSetArg (wargs[0], XtNbitmap, (Pixmap)bg_pixmap);
- XtSetValues (_plotter->y_canvas, wargs, (Cardinal)1);
- #endif
- }
-
- if (_plotter->x_double_buffering == X_DBL_BUF_BY_HAND)
-
- {
-
- XCopyArea (_plotter->x_dpy, _plotter->x_drawable3, _plotter->x_drawable2,
- _plotter->drawstate->x_gc_bg,
- 0, 0,
- (unsigned int)window_width, (unsigned int)window_height,
- 0, 0);
- }
-
- if (_plotter->x_double_buffering == X_DBL_BUF_NONE)
- XCopyArea (_plotter->x_dpy, _plotter->x_drawable1, _plotter->x_drawable2,
- _plotter->drawstate->x_gc_bg,
- 0, 0,
- (unsigned int)window_width, (unsigned int)window_height,
- 0, 0);
-
-
- fptr = _plotter->x_fontlist;
- _plotter->x_fontlist = NULL;
- while (fptr)
- {
- plXFontRecord *fptrnext;
- fptrnext = fptr->next;
- free (fptr->x_font_name);
- if (fptr->x_font_struct)
- XFreeFont (_plotter->x_dpy, fptr->x_font_struct);
- free (fptr);
- fptr = fptrnext;
- }
-
- cptr = _plotter->x_colorlist;
- _plotter->x_colorlist = NULL;
- while (cptr)
- {
- plColorRecord *cptrnext;
- cptrnext = cptr->next;
- free (cptr);
- cptr = cptrnext;
- }
-
- #ifdef HAVE_WAITPID
- #ifdef HAVE_SYS_WAIT_H
- #ifdef WNOHANG
- {
- int i;
-
-
- for (i = 0; i < _plotter->y_num_pids; i++)
- waitpid (_plotter->y_pids[i], (int *)NULL, WNOHANG);
- }
- #endif
- #endif
- #endif
-
- _maybe_handle_x_events (S___(_plotter));
-
- _pl_x_flush_output (S___(_plotter));
-
- _pl_g_flush_plotter_outstreams (S___(_plotter));
-
-
- forkval = fork ();
- if ((int)forkval > 0
- || (int)forkval < 0)
- {
- bool retval = true;
- if ((int)forkval < 0)
- _plotter->error (R___(_plotter) "the process could not be forked");
-
- if (close (ConnectionNumber (_plotter->x_dpy)) < 0
- && errno != EINTR)
-
- {
- _plotter->error (R___(_plotter) "the connection to the X display could not be closed");
- retval = false;
- }
- if ((int)forkval > 0)
-
- {
- if (_plotter->y_num_pids == 0)
- _plotter->y_pids = (pid_t *)_pl_xmalloc (sizeof (pid_t));
- else
- _plotter->y_pids =
- (pid_t *)_pl_xrealloc (_plotter->y_pids,
- ((_plotter->y_num_pids + 1)
- * sizeof (pid_t)));
- _plotter->y_pids[_plotter->y_num_pids] = forkval;
- _plotter->y_num_pids++;
- }
-
-
- _pl_x_delete_gcs_from_first_drawing_state (S___(_plotter));
-
- return retval;
- }
- else
- {
- bool need_redisplay = false;
- int i;
-
- _pl_y_set_data_for_quitting (S___(_plotter));
-
- for (i = 0; i < _xplotters_len; i++)
- if (_xplotters[i] != NULL
- && _xplotters[i] != _plotter
- && _xplotters[i]->data->opened
- && _xplotters[i]->data->open
- && close (ConnectionNumber (_xplotters[i]->x_dpy)) < 0
- && errno != EINTR)
-
- _plotter->error (R___(_plotter)
- "the connection to the X display could not be closed");
-
- if (_plotter->x_double_buffering != X_DBL_BUF_NONE)
- need_redisplay = true;
- else
- {
- Arg wargs[2];
- Dimension our_window_height, our_window_width;
- #ifdef USE_MOTIF
- XtSetArg (wargs[0], XmNwidth, &our_window_width);
- XtSetArg (wargs[1], XmNheight, &our_window_height);
- #else
- XtSetArg (wargs[0], XtNwidth, &our_window_width);
- XtSetArg (wargs[1], XtNheight, &our_window_height);
- #endif
- XtGetValues (_plotter->y_canvas, wargs, (Cardinal)2);
- if ((_plotter->data->imax + 1 != (int)our_window_width)
- || (_plotter->data->jmin + 1 != (int)our_window_height))
-
- need_redisplay = true;
- }
-
- {
- XSetWindowAttributes attributes;
- unsigned long value_mask;
-
- attributes.backing_store = NotUseful;
- value_mask = CWBackingStore;
- XChangeWindowAttributes (_plotter->x_dpy, (Window)_plotter->x_drawable2,
- value_mask, &attributes);
- }
- if (need_redisplay)
-
- XClearArea (_plotter->x_dpy,
- (Window)_plotter->x_drawable2,
- 0, 0,
- (unsigned int)0, (unsigned int)0,
- True);
-
- _plotter->data->open = false;
-
-
- XtAppMainLoop (_plotter->y_app_con);
-
- exit (EXIT_FAILURE);
- }
- }
|