Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!snorkelwacker!bloom-beacon!LARRY.MCRCIM.MCGILL.EDU!mouse From: mouse@LARRY.MCRCIM.MCGILL.EDU (der Mouse) Newsgroups: comp.windows.x Subject: Re: GetWindowCursor Message-ID: <9006300651.AA12891@Larry.McRCIM.McGill.EDU> Date: 30 Jun 90 06:51:31 GMT Sender: daemon@athena.mit.edu (Mr Background) Organization: The Internet Lines: 57 > How do I find the Cursor ID for the current cursor in a window? > Basically what a want is to have my cursor disappear if I havn't > moved the mouse for a while, and then reappear when I move the mouse. Instead of bashing on the cursor for the window the mouse is in, how about when you see the mouse go idle, try grabbing the pointer with grab_window = see note 1 below owner_events = False event_mask = PointerMotionMask | ButtonPressMask | ButtonReleaseMask pointer_mode = GrabModeSync keyboard_mode = GrabModeAsync confine_to = None cursor = an invisible cursor time = see note 2 below Then call XAllowEvents with mode SyncPointer and wait for an event. If the event is a ButtonPress or ButtonRelease, call XAllowEvents in mode ReplayPointer (which releases your grab), and go back to waiting for the mouse to go idle. If the event is a MotionNotify, - Grab the server. - Freeze the pointer with XGrabPointer. - Sync with the server with XSync. - Scan the event queue for ButtonPress or ButtonRelease events. If there are none: - Release the pointer grab entirely with XUngrabPointer. If one is found: - Release the grab by using XAllowEvents in mode ReplayPointer. - Ungrab the server. Ideally, there should be something like XAllowEvents' SyncPointer mode, but for motion events as well as ButtonPress and ButtonRelease events. This would render the above kludge for the case of MotionNotify unnecessary. Note 1: about the grab_window for the initial grab. I would make this a window created expressly for this purpose. I would make it lie entirely outside the bounds of the root window (so the pointer cannot possibly actually be moved into it). It should perhaps be an override-redirect window, so the window manager doesn't try to second-guess its somewhat unusual placement. Note 2: about the time to pass to the initial grab. I would probably use CurrentTime here, though I know that's not entirely correct. The right way to do it would be to get a timestamp from the server with a zero-length append using XChangeProperty and use that (and of course if GrabInvalidTime is returned, get a fresh timestamp and try again). For timestamps for the other routines requiring them, pass either the time from the most recent event or the timestamp used for the first grab, whichever is applicable. der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu