home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!hal.com!decwrl!sdd.hp.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!organ!ware
- From: ware@organ.cis.ohio-state.edu (Peter Ware)
- Newsgroups: comp.windows.x
- Subject: Re: Trapping BadWindow Errors?
- Message-ID: <WARE.92Jul27181525@organ.cis.ohio-state.edu>
- Date: 27 Jul 92 23:15:25 GMT
- References: <brself.712270104@hal>
- Sender: news@cis.ohio-state.edu (NETnews )
- Organization: Ohio State Computer Science
- Lines: 92
- In-Reply-To: brself@hal.gnu.ai.mit.edu's message of Mon, 27 Jul 1992 20: 48:24 GMT
- Originator: ware@organ.cis.ohio-state.edu
-
- Here is how I deal with setting the input focus. This temporarily installs a
- handler that ignores any BaMatch errors generated by SetInputFocuse requests.
- A global flag is used to inform the caller if there was a problem.
- This could be generalized but I've not seen any reason to.
-
- --pete
- ----------------------------------------------------------------------
-
- static int (*oldHandler) (); /* the previous error handler */
- static Boolean xoInputFailed; /* set if SetInputFocus error */
-
- /*
- * An error handler that is briefly installed as we are changing the
- * keyboard input focus. It ignores BadMatch errors from SetInputFocus
- * protocol requests.
- */
-
- static int
- xoIgnoreFocusError (display, err)
- Display *display;
- XErrorEvent *err;
- {
- DBUG_ENTER ("xoIgnoreFocusError");
- if (!err)
- DBUG_RETURN (0);
- if (err->error_code == BadMatch &&
- err->request_code == X_SetInputFocus)
- {
- DBUG_PRINT ("focus", ("SetInputFocus error"));
- xoInputFailed = True;
- }
- else
- {
- (*oldHandler) (display, err);
- }
- DBUG_RETURN (0);
- }
-
- /*
- * Determine if we'll accept the keyboard focus. We accept it only if
- * the window is visible.
- */
-
- Boolean
- XoFocusAccept (gw, t)
- Widget gw;
- Time *t;
- {
- DBUG_ENTER ("xoAcceptFocus");
- if (!gw || !t)
- DBUG_RETURN (False);
- if (!XtIsRealized (gw))
- {
- DBUG_PRINT ("focus", ("Widget %s not realized", XoName (gw)));
- DBUG_RETURN (False);
- }
- /*
- * We want to install a new error handler that ignores any
- * SetInputFocus errors. So we first make sure we've sent and
- * received all messages -- just in case there is a lingering error.
- * We install the handler, call the focus change, then Sync again to
- * make sure this request has gone out and the reply come back. We
- * the restore the error handler.
- */
- XSync (XtDisplay (gw), False);
- oldHandler = XSetErrorHandler (xoIgnoreFocusError);
- xoInputFailed = False;
- XSetInputFocus (XtDisplay (gw), XtWindow (gw),
- RevertToPointerRoot, *t);
- XSync (XtDisplay (gw), False);
- (void) XSetErrorHandler (oldHandler);
-
- if (xoInputFailed)
- {
- DBUG_PRINT ("focus", ("Error setting focus to %s", XoName (gw)));
- /*
- * (void) XoFocusAccept (XoFocusWidgetGet (XoShellGet (gw)),
- * t);
- */
- DBUG_RETURN (False);
- }
- else
- {
- XoFocusWidgetSet (XoShellGet (gw), gw);
- DBUG_RETURN (True);
- }
- }
- --
- Pete Ware / Ohio State University /
- ware@cis.ohio-state.edu
- (614) 538-0965
- Too bad the Nike slogan isn't "Just Do It Right" instead of "Just Do It"
-