🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: slac.users.windows.x
Article #1

New X programmer doesn't understand...

#1
From: J. Scott Berg
Date: Sun, 09 Feb 1992 19:09
94 lines
3691 bytes
In the program below, note the commented out delay loop.  If I place
the loop in, my program behaves as expected.  If I remove the loop,
a black window pops up, but the two lines are not drawn.  What the
!@#$% is going on?  It seems that I am missing something fundamental
here...  Any help would be greatly appreciated.  By the way, I am
running X11R5 on under AIX, but the behavior was the same when I
compiled on a sun and put it on my IBM display.  Thanks

				-Scott Berg


#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

main() {

  char *display_name;
  Display *Jdisp;
  int Jdepth,Jdispht,Jdispwd,Jwinx0,Jwiny0;
  int x0,y0,x1,y1,i,im;
  double x;
  Screen *Jscreen;
  unsigned int Jwinwd,Jwinht,Jwinbdw;
  unsigned long Jbkpix,Jwtpix,Jwinbdpix,Jwinbkgd,Jgcvb;
  Window Jrootwin,Jwin1;
  GC Jgc;
  XGCValues Jgcv;

  display_name = NULL;
  Jdisp = XOpenDisplay(display_name);
  Jscreen = XDefaultScreenOfDisplay(Jdisp);
  Jbkpix = XBlackPixelOfScreen(Jscreen);
  Jwtpix = XWhitePixelOfScreen(Jscreen);
  Jdepth = XDefaultDepthOfScreen(Jscreen);
  Jrootwin = XRootWindowOfScreen(Jscreen);
  Jdispht = XHeightOfScreen(Jscreen);
  Jdispwd = XWidthOfScreen(Jscreen);

  printf("Black pixel: %d\nWhite pixel: %d\nDepth: %d\nHeight: %d\nWidth: %d\n"
                              ,Jbkpix,Jwtpix,Jdepth,Jdispht,Jdispwd);
  
  Jwinx0 = Jdispwd/10;
  Jwiny0 = Jdispht/10;
  Jwinwd = Jdispwd/2;
  Jwinht = Jdispht/2;
  Jwinbdw = 2;
  Jwinbdpix = Jwtpix;
  Jwinbkgd = Jbkpix;

/*  for (x = 0.0 ; x < 1.0 ; x += 1.0e-6); */
  Jwin1 = XCreateSimpleWindow(Jdisp,Jrootwin,Jwinx0,Jwiny0,Jwinwd,Jwinht,
			      Jwinbdw,Jwinbdpix,Jwinbkgd);
  XMapWindow(Jdisp,Jwin1);
  XFlush(Jdisp);

  Jgcvb = 0L;
  Jgc = XCreateGC(Jdisp,Jwin1,Jgcvb,&Jgcv);

  x0 = Jwinwd/3;
  x1 = 2*Jwinwd/3;
  y0 = Jwinht/4;
  y1 = Jwinwd/2;

  printf("Window width = %d, height = %d\n",Jwinwd,Jwinht);
  printf("x0 = %d, y0 = %d, x1 = %d, y1 = %d\n",x0,y0,x1,y1);

  XSetForeground(Jdisp,Jgc,Jwtpix);
  XSetBackground(Jdisp,Jgc,Jbkpix);

  XDrawLine(Jdisp,Jwin1,Jgc,x0,y0,x1,y1);

  y0 += 100; y1 += 100;

  XDrawLine(Jdisp,Jwin1,Jgc,x0,y0,x1,y1);

  XFlush(Jdisp);

  scanf("%d",&i);

  XCloseDisplay(Jdisp); }


-- 
-------------------------------------------------------------------------------
The opinions expressed here are, of course, my own and nobody else's.
-------------------------------------------------------------------------------
J. Scott Berg
email: alhy@unixhub.slac.stanford.edu
real mail: Varian Physics
           Stanford  CA  94305-4060
phone:	(415) 926-4732
	(415) 497-2998
-------------------------------------------------------------------------------
Technical Details
Message-ID: <3284@unixhub.SLAC.Stanford.EDU>
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!uwm.edu!linac!unixhub!unixhub.slac.stanford.edu!alhy

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10f48b,d56c1c47118411f,start
X-Google-Attributes: gid10f48b,public
X-Google-Thread: 10e286,d56c1c47118411f,start
X-Google-Attributes: gid10e286,public
X-Google-Thread: 103734,d56c1c47118411f,start
X-Google-Attributes: gid103734,public
X-Google-ArrivalTime: 1992-02-09 11:54:11 PST
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!uwm.edu!linac!unixhub!unixhub.slac.stanford.edu!alhy
From: alhy@unixhub.slac.stanford.edu (J. Scott Berg)
Newsgroups: slac.users.windows.x,comp.windows.x,ba.windows.x
Subject: New X programmer doesn't understand...
Message-ID: <3284@unixhub.SLAC.Stanford.EDU>
Date: 9 Feb 92 19:09:20 GMT
Article-I.D.: unixhub.3284
Sender: news@unixhub.SLAC.Stanford.EDU
Reply-To: alhy@unixhub.slac.stanford.edu
Followup-To: slac.users.windows.x
Organization: Stanford University, dept of Physics / SLAC
Lines: 94
Nntp-Posting-Host: courant.slac.stanford.edu