2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * (c) Copyright 1989, 1990, 1991, 1992, 1993, 1994 OPEN SOFTWARE FOUNDATION, INC.
32 static char rcsid[] = "$XConsortium: WmError.c /main/6 1996/10/07 14:27:34 drk $"
36 * (c) Copyright 1987, 1988, 1989, 1990 HEWLETT-PACKARD COMPANY */
45 #include <Dt/UserMsg.h>
50 * Function Declarations:
56 #define E_MAJOR_CODE 0
57 #define E_MINOR_CODE 1
58 #define E_RESOURCE_ID 2
59 #define E_ERROR_SERIAL 3
60 #define E_CURRENT_SERIAL 4
62 #define NUM_E_STRINGS 5
64 static char *pchErrorFormatNames [NUM_E_STRINGS] = {
72 static char *pchDefaultErrorFormat [NUM_E_STRINGS] = {
80 static char *pchErrorFormat [NUM_E_STRINGS];
87 /*************************************<->*************************************
89 * WmInitErrorHandler (display)
94 * This function initializes the window manager error handler.
99 * display = display we're talking about
102 *************************************<->***********************************/
105 WmInitErrorHandler (Display *display)
112 * Fetch the X error format strings from XErrorDB
114 for (i = 0; i< NUM_E_STRINGS; i++)
116 XGetErrorDatabaseText (display, "XlibMessage",
117 pchErrorFormatNames[i],
118 pchDefaultErrorFormat[i], buffer, BUFSIZ);
120 if ((pchErrorFormat[i] = (char *) XtMalloc (1+strlen(buffer))) == NULL)
122 Warning ("Insufficient memory for error message initialization.");
126 strcpy(pchErrorFormat[i], buffer);
131 XSetErrorHandler (WmXErrorHandler);
132 XSetIOErrorHandler (WmXIOErrorHandler);
134 XtSetWarningHandler (WmXtWarningHandler);
135 XtSetErrorHandler (WmXtErrorHandler);
137 } /* END OF FUNCTION WmInitErrorHandler */
140 /*************************************<->*************************************
142 * WmXErrorHandler (display, errorEvent)
147 * This function is the X error handler that is registered with X to
148 * handle X errors resulting from window management activities.
153 * display = display on which X error occurred
155 * errorEvent = pointer to a block of information describing the error
160 * wmGD.errorFlag = set to True
164 *************************************<->***********************************/
167 WmXErrorHandler (Display *display, XErrorEvent *errorEvent)
173 char message[BUFSIZ];
175 XGetErrorText (display, errorEvent->error_code, buffer, BUFSIZ);
176 Warning ("X error occurred during window management operation");
177 fprintf (stderr, "Description = '%s'\n ", buffer);
179 fprintf (stderr, pchErrorFormat[E_MAJOR_CODE], errorEvent->request_code);
180 sprintf(message, "%d", errorEvent->request_code);
181 XGetErrorDatabaseText (display, "XRequest", message,
182 " ", buffer, BUFSIZ);
183 fprintf (stderr, " (%s)\n ", buffer);
184 fprintf (stderr, pchErrorFormat[E_MINOR_CODE], errorEvent->minor_code);
185 fprintf (stderr, "\n ");
186 fprintf (stderr, pchErrorFormat[E_RESOURCE_ID], errorEvent->resourceid);
187 fprintf (stderr, "\n ");
188 fprintf (stderr, pchErrorFormat[E_ERROR_SERIAL], errorEvent->serial);
189 fprintf (stderr, "\n ");
190 fprintf (stderr, pchErrorFormat[E_CURRENT_SERIAL],
191 LastKnownRequestProcessed(display));
192 fprintf (stderr, "\n");
196 * Check for a BadWindow error for a managed window. If this error
197 * is detected indicate in the client data that the window no longer
201 if ((errorEvent->error_code == BadWindow) &&
202 !XFindContext (DISPLAY, errorEvent->resourceid, wmGD.windowContextType,
205 if (errorEvent->resourceid == pCD->client)
207 pCD->clientFlags |= CLIENT_DESTROYED;
211 wmGD.errorFlag = True;
212 wmGD.errorResource = errorEvent->resourceid;
213 wmGD.errorRequestCode = errorEvent->request_code;
217 } /* END OF FUNCTION WmXErrorHandler */
221 /*************************************<->*************************************
223 * WmXIOErrorHandler (display)
228 * This function is the X IO error handler that is registered with X to
229 * handle X IO errors. This function exits the window manager.
234 * display = X display on which the X IO error occurred
236 *************************************<->***********************************/
239 WmXIOErrorHandler (Display *display)
243 sprintf (err, "%s: %s\n", "I/O error on display:", XDisplayString(display));
246 ExitWM (WM_ERROR_EXIT_VALUE);
250 } /* END OF FUNCTIONS WmXIOErrorHandler */
254 /*************************************<->*************************************
256 * WmXtErrorHandler (message)
261 * This function is registered as the X Toolkit fatal error handler.
266 * message = pointer to an error message
268 *************************************<->***********************************/
271 WmXtErrorHandler (char *message)
275 ExitWM (WM_ERROR_EXIT_VALUE);
277 } /* END OF FUNCTION WmXtErrorHandler */
281 /*************************************<->*************************************
283 * WmXtWarningHandler (message)
288 * This function is registered as an X Toolkit warning handler.
293 * message = pointer to a warning message
295 *************************************<->***********************************/
298 WmXtWarningHandler (char *message)
305 } /* END OF FUNCTIONS WmXtWarningHandler */
308 /*************************************<->*************************************
315 * This function lists a message to stderr.
320 * message = pointer to a message string
322 *************************************<->***********************************/
325 Warning (char *message)
328 char pch[MAXWMPATH+1];
330 sprintf (pch, "%s: %s\n",
331 GETMESSAGE(20, 1, "Workspace Manager"), message);
333 _DtSimpleError (wmGD.mwmName, DtIgnore, NULL, pch, NULL);
335 fprintf (stderr, "%s: %s\n", wmGD.mwmName, message);
339 } /* END OF FUNCTION Warning */
344 /******************************<->*************************************
346 * PrintFormatted (format, message, message, ...)
351 * This function lists several messages to stderr using fprintf()
352 * formatting capabilities.
356 * s0-s9 = pointers to message strings
360 * Caller must provide his/her own argv[0] to this function.
361 ******************************<->***********************************/
365 PrintFormatted(char *f, char *s0, char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8, char *s9)
366 /* limit of ten args */
368 fprintf( stderr, f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
370 } /* END OF FUNCTION PrintFormatted */
372 /************************ eof **************************/
373 #endif /* DEBUGGER */