[gnu.ghostscript.bug] two windows is too many

hrp@boring.cray.com (Hal Peterson) (07/29/89)

On startup under X, Ghostscript opens two windows; the first one stays
blank and the second one gets all of the graphics.  This is happening
because the X device is being initialized twice, once from the C code
in gs_set_device and once from the Ghostscript setup code in ghost.ps.
This is a fix in multiple steps:

1.  since ghost.ps will initialize and set the real device, I modified
    gs_state_alloc to initialize with the null device instead of with
    a real one.

2.  ghost.ps now needs a way to get the real default device, so I
    dropped defaultdevice into C code.

3.  and while I was at it I cleaned up a bunch of incorrect
    declarations at the beginning of gsdevice.c (they were missing
    ``private'' keywords and gcc yelled at me).

--
Hal Peterson			Domain:  hrp@cray.com
Cray Research			Old style:  hrp%cray.com@uc.msc.umn.edu
1440 Northland Dr.		UUCP:  uunet!cray!hrp
Mendota Hts, MN  55120  USA	Telephone:  +1 612 681 3145

========================================================================
*** ghost-DIST.ps	Tue Jun 20 06:31:52 1989
--- ghost.ps	Fri Jul 28 14:21:56 1989
***************
*** 39,47 ****
  /true 0 0 eq def
  /false 0 1 eq def
  
- % Acquire the default device.
- /defaultdevice currentdevice def
- 
  % Define the predefined procedures, in alphabetical order.
  /[	/mark load def
  /] 	{counttomark array astore exch pop} bind def
--- 39,44 ----
*** gsdevice-DIST.c	Tue Jun 20 07:38:22 1989
--- gsdevice.c	Fri Jul 28 14:36:28 1989
***************
*** 124,129 ****
--- 124,135 ----
  {	return pgs->device->info;
  }
  
+ /* Get the current device from the graphics state */
+ gx_device *
+ gs_defaultdevice(gs_state *pgs)
+ {	return gx_device_default_p;
+ }
+ 
  /* Read out the current device parameters */
  void
  gs_deviceparams(gx_device *dev, gs_matrix *pmat, int *pwidth, int *pheight)
***************
*** 220,237 ****
  #define rprocs (trace_find_procs(dev->procs))
  
  /* Procedure structure */
! int trace_open_device(P1(gx_device *));
! int trace_close_device(P1(gx_device *));
! int trace_sync_output(P1(gx_device *));
! gx_color_index trace_map_rgb_color(P4(gx_device *, ushort, ushort, ushort));
! int trace_map_color_rgb(P3(gx_device *, gx_color_index, ushort *));
! int trace_fill_rectangle(P6(gx_device *, int, int, int, int, gx_color_index));
! int trace_tile_rectangle(P8(gx_device *, gx_bitmap *, int, int, int, int, gx_color_index, gx_color_index));
! int trace_copy_mono(P10(gx_device *, byte *, int, int, int, int, int, int, gx_color_index, gx_color_index));
! int trace_copy_color(P8(gx_device *, byte *, int, int, int, int, int, int));
! int trace_draw_line(P6(gx_device *, int, int, int, int, gx_color_index));
! int trace_fill_trapezoid(P8(gx_device *, int, int, int, int, int, int, gx_color_index));
! int trace_tile_trapezoid(P10(gx_device *, gx_bitmap *, int, int, int, int, int, int, gx_color_index, gx_color_index));
  private gx_device_procs trace_procs = {
  	trace_open_device,
  	trace_close_device,
--- 226,243 ----
  #define rprocs (trace_find_procs(dev->procs))
  
  /* Procedure structure */
! private int trace_open_device(P1(gx_device *));
! private int trace_close_device(P1(gx_device *));
! private int trace_sync_output(P1(gx_device *));
! private gx_color_index trace_map_rgb_color(P4(gx_device *, ushort, ushort, ushort));
! private int trace_map_color_rgb(P3(gx_device *, gx_color_index, ushort *));
! private int trace_fill_rectangle(P6(gx_device *, int, int, int, int, gx_color_index));
! private int trace_tile_rectangle(P8(gx_device *, gx_bitmap *, int, int, int, int, gx_color_index, gx_color_index));
! private int trace_copy_mono(P10(gx_device *, byte *, int, int, int, int, int, int, gx_color_index, gx_color_index));
! private int trace_copy_color(P8(gx_device *, byte *, int, int, int, int, int, int));
! private int trace_draw_line(P6(gx_device *, int, int, int, int, gx_color_index));
! private int trace_fill_trapezoid(P8(gx_device *, int, int, int, int, int, int, gx_color_index));
! private int trace_tile_trapezoid(P10(gx_device *, gx_bitmap *, int, int, int, int, int, int, gx_color_index, gx_color_index));
  private gx_device_procs trace_procs = {
  	trace_open_device,
  	trace_close_device,
*** gsstate-DIST.h	Tue Jun 20 06:43:38 1989
--- gsstate.h	Fri Jul 28 14:26:29 1989
***************
*** 52,57 ****
--- 52,58 ----
  void	gs_nulldevice(P1(gs_state *));
  int	gs_setdevice(P2(gs_state *, gx_device *));
  gx_device *	gs_currentdevice(P1(gs_state *));
+ gx_device *	gs_defaultdevice(P1(gs_state *));
  void	gs_deviceparams(P4(gx_device *, gs_matrix *, int *, int *));
  
  /* Line parameters and quality */
*** zdevice-DIST.c	Tue Jun 20 07:19:22 1989
--- zdevice.c	Fri Jul 28 14:42:59 1989
***************
*** 44,49 ****
--- 44,58 ----
  	return 0;
  }
  
+ /* currentdevice */
+ int
+ zdefaultdevice(register ref *op)
+ {	gx_device *dev = gs_defaultdevice(igs);
+ 	push(1);
+ 	make_tv(op, t_device, pdevice, dev);
+ 	return 0;
+ }
+ 
  /* defaultdevicename */
  int
  zdefaultdevicename(register ref *op)
***************
*** 128,133 ****
--- 137,143 ----
  {	static op_def my_defs[] = {
  		{"0copypage", zcopypage},
  		{"0currentdevice", zcurrentdevice},
+ 		{"0defaultdevice", zdefaultdevice},
  		{"0defaultdevicename", zdefaultdevicename},
  		{"1deviceparams", zdeviceparams},
  		{"4makedevice", zmakedevice},

pniy@vax5.CIT.CORNELL.EDU (07/30/89)

I only just became aware of this newsgroup, though I've been
trying to run ghostscript (1.3) for about a week now. Anyway:

In article <8907282004.AA02231@rothko.cray.com> hrp@boring.cray.com (Hal Peterson) writes:
>On startup under X, Ghostscript opens two windows; the first one stays
>blank and the second one gets all of the graphics.  This is happening
>because the X device is being initialized twice, once from the C code
>in gs_set_device and once from the Ghostscript setup code in ghost.ps.
>This is a fix in multiple steps:

I worked out a fix to this problem by replacing the
makedevice call in ghost.ps by a new function "changedevice"
which just resets the default device according to
the parameters usually given to makedevice.

Wasn't anybody bothered by the fact that the image is not retained after
being hidden and re-exposed? (Or did nobody have this problem? I'm on
a Sun 3/50, runnning R3.) Anyway, I have a fix to that too, by
putting everything into a background pixmap as well as onto
the window.  This fix also does away with the ridiculous getchar()
statement, since it makes no difference when the window
receives its expose event.

However, the changes I have made are somewhat incompatible with
Hal Peterson's patches so I have sent them to "ghost@aladdin" instead
of posting them.

				Arthur Smith

internet: arthur@helios.tn.cornell.edu
bitnet:	  arthur@crnlassp

aida@porthos (Hitoshi Aida) (08/01/89)

In article <8907282004.AA02231@rothko.cray.com> hrp@boring.cray.com (Hal Peterson) writes:
>On startup under X, Ghostscript opens two windows; the first one stays
>blank and the second one gets all of the graphics.  This is happening
>because the X device is being initialized twice, once from the C code
>in gs_set_device and once from the Ghostscript setup code in ghost.ps.
>This is a fix in multiple steps:
>
>1.  since ghost.ps will initialize and set the real device, I modified
>    gs_state_alloc to initialize with the null device instead of with
>    a real one.
>
>2.  ghost.ps now needs a way to get the real default device, so I
>    dropped defaultdevice into C code.
>
>3.  and while I was at it I cleaned up a bunch of incorrect
>    declarations at the beginning of gsdevice.c (they were missing
>    ``private'' keywords and gcc yelled at me).
>
I had similar problem when I ported Ghostscript 1.3 to SunView environment.
My fix was more simple: sticking to defaultdevice all the way.  Doing this
in X requires a little modification of X driver, i.e. initializing matrix
within the driver.  I've never used Ghostscript in X, but I think following
patch would work.

Hitoshi AIDA (aida@csl.sri.com)
Computer Science Laboratory, SRI International
---------------- cut here ----------------
*** gdevx.c	Tue Jun 20 08:43:55 1989
--- gdevx.c.new	Tue Jul 25 12:49:06 1989
***************
*** 128,134 ****
  gx_device_X x_device = {
  	sizeof(gx_device_X),
  	&x_procs,
! 	identity_matrix_body,
  	640, 350,		/* x and y extent */
  		/* Following parameters are initialized for monochrome */
  	0,			/* has color */
--- 128,134 ----
  gx_device_X x_device = {
  	sizeof(gx_device_X),
  	&x_procs,
! 	1.0,0, 0.0,0, 0.0,0, -1.0,0, 0.0,0, 350.0,0,	/* initial matrix */
  	640, 350,		/* x and y extent */
  		/* Following parameters are initialized for monochrome */
  	0,			/* has color */
***************
*** 186,192 ****
  	/* Leave some space for a window manager's title bar */
  	winH = HeightOfScreen(xdev->scr) - 15;
  	winY = 0;
! 	xdev->height = winH;
  	xdev->black = BlackPixelOfScreen(xdev->scr);
  	xdev->white = WhitePixelOfScreen(xdev->scr);
  	xdev->back_color = xdev->fore_color = -1;	/* undefined */
--- 186,192 ----
  	/* Leave some space for a window manager's title bar */
  	winH = HeightOfScreen(xdev->scr) - 15;
  	winY = 0;
! 	xdev->initial_matrix.ty = xdev->height = winH;
  	xdev->black = BlackPixelOfScreen(xdev->scr);
  	xdev->white = WhitePixelOfScreen(xdev->scr);
  	xdev->back_color = xdev->fore_color = -1;	/* undefined */
*** ghost.ps.org	Tue Jun 20 04:31:52 1989
--- ghost.ps	Thu Jul 13 16:46:12 1989
***************
*** 309,317 ****
  % Map the screen height to an 11" page.
  % This is not necessarily the best compromise.
  DISPLAYING
!  { .device.height 72 11 mul div
!    [1 index .aspect.ratio mul 0 0 4 index neg 0 .device.height]
!    .device.width 8 idiv .device.height { } framedevice pop
   }
   { nulldevice
   } ifelse
--- 309,315 ----
  % Map the screen height to an 11" page.
  % This is not necessarily the best compromise.
  DISPLAYING
!  { defaultdevice setdevice
   }
   { nulldevice
   } ifelse

ghost@aladdin.com (L. Peter Deutsch) (08/01/89)

I've incorporated a slight variation of Hal Peterson's fix into the
development code for release 1.4.  One thing I am trying to get into 1.4
is a good deal more flexibility in terms of multiple devices, switching
devices, changing the size of windows, etc.

L. Peter Deutsch			ghost@aladdin.com
Aladdin Enterprises			...{uunet,parcplace}!aladdin!ghost
P. O. box 60264, Palo Alto, CA 94306