Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!sdd.hp.com!ucsd!ames!ncar!gatech!bloom-beacon!LIGHTNING.MCRCIM.MCGILL.EDU!mouse From: mouse@LIGHTNING.MCRCIM.MCGILL.EDU Newsgroups: comp.windows.x Subject: Re: Questions about cursors (large crosshairs) Message-ID: <9012061108.AA17131@lightning.McRCIM.McGill.EDU> Date: 6 Dec 90 11:08:58 GMT Sender: daemon@athena.mit.edu (Mr Background) Organization: The Internet Lines: 76 > I have the need for a very large crosshair cursor. By "very large" I > mean a crosshair cursor whose crosshairs always extend to the edge of > the window no matter how large the window is. This crosshair cursor > must also be clipped at the window boundaries so that the crosshairs > never extend outside the window. You cannot get these semantics by setting the cursor in the XDefineCursor sense; the X cursor mechanisms are incompatible with the goals you state. In particular, cursors are never clipped by window boundaries (the root window boundaries might be an exception). I fear you'll have to do your own crosshair drawing.... That said, let's try to see why your code doesn't work. I added a little code to turn it into a whole program, and here's what I'd say is going wrong: > /* how to tell if Create fails? */ > pix_curs = XCreatePixmap(disp, window, width, width, 1); > pix_curs_mask = XCreatePixmap(disp, window, width, width, 1); > tmp_gc = XCreateGC(disp, pix_curs, 0, NULL); If XCreatePixmap fails, you will get an error event (probably BadAlloc) from the server. If you don't arrange otherwise, this will print a message and kill your program. I notice that you don't clear pix_curs and pix_curs_mask. The initial contents of pixmaps are unspecified, and most servers use whatever junk happens to be lying around in the newly-allocated memory. Let's clear them first: XSetForeground(disp,tmp_gc,0L); XFillRectangle(disp,pix_curs,tmp_gc,0,0,width,width); XFillRectangle(disp,pix_curs_mask,tmp_gc,0,0,width,width); Ah. That got rid of the garbage. Now we just have a solid rectangle of the background color as the cursor. > [...set crosshair_lines[]...] > XDrawSegments (disp, pix_curs, tmp_gc, crosshair_lines, 2); Ah yes, the XSetForeground above changed the GC's foreground from the default of 1. Let's set it back (insert this before the XDrawSegments call): XSetForeground(disp,tmp_gc,1L); Now we have a solid rectangle of background with a vertical slit in it through which we see whatever's behind the cursor. > XSetFunction(disp, tmp_gc, GXcopyInverted); > XCopyArea(disp, pix_curs, pix_curs_mask, tmp_gc, 0, 0, width, width, > 0, 0); You've got this backwards. You want the mask to have 1 where the picture is to be visible and 0 where it is supposed to let the window(s) underneath it show through. Let's change the XSetFunction to set it to GXcopy, or, since that's the default and we haven't changed it yet, just delete the XSetFunction altogether. Ah. Now we have a T cross. Presumably what you were after is more like a + sign. To get that, change > crosshair_lines[0].y1 = crosshair_lines[0].y2 = 0; into crosshair_lines[0].y1 = crosshair_lines[0].y2 = width / 2; This produces a very nice crosshair. However, as I indicated above, it will ignore window boundaries. der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu