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.
31 * (c) Copyright 1987, 1988, 1989, 1990 HEWLETT-PACKARD COMPANY */
39 #include <Dt/UserMsg.h>
43 * Function Declarations:
49 #define E_MAJOR_CODE 0
50 #define E_MINOR_CODE 1
51 #define E_RESOURCE_ID 2
52 #define E_ERROR_SERIAL 3
53 #define E_CURRENT_SERIAL 4
55 #define NUM_E_STRINGS 5
57 static char *pchErrorFormatNames [NUM_E_STRINGS] = {
65 static char *pchDefaultErrorFormat [NUM_E_STRINGS] = {
73 static char *pchErrorFormat [NUM_E_STRINGS];
80 /*************************************<->*************************************
82 * WmInitErrorHandler (display)
87 * This function initializes the window manager error handler.
92 * display = display we're talking about
95 *************************************<->***********************************/
98 WmInitErrorHandler (Display *display)
105 * Fetch the X error format strings from XErrorDB
107 for (i = 0; i< NUM_E_STRINGS; i++)
109 XGetErrorDatabaseText (display, "XlibMessage",
110 pchErrorFormatNames[i],
111 pchDefaultErrorFormat[i], buffer, BUFSIZ);
113 if ((pchErrorFormat[i] = (char *) XtMalloc (1+strlen(buffer))) == NULL)
115 Warning ("Insufficient memory for error message initialization.");
119 strcpy(pchErrorFormat[i], buffer);
124 XSetErrorHandler (WmXErrorHandler);
125 XSetIOErrorHandler (WmXIOErrorHandler);
127 XtSetWarningHandler (WmXtWarningHandler);
128 XtSetErrorHandler (WmXtErrorHandler);
130 } /* END OF FUNCTION WmInitErrorHandler */
133 /*************************************<->*************************************
135 * WmXErrorHandler (display, errorEvent)
140 * This function is the X error handler that is registered with X to
141 * handle X errors resulting from window management activities.
146 * display = display on which X error occurred
148 * errorEvent = pointer to a block of information describing the error
153 * wmGD.errorFlag = set to True
157 *************************************<->***********************************/
160 WmXErrorHandler (Display *display, XErrorEvent *errorEvent)
166 char message[BUFSIZ];
168 XGetErrorText (display, errorEvent->error_code, buffer, BUFSIZ);
169 Warning ("X error occurred during window management operation");
170 fprintf (stderr, "Description = '%s'\n ", buffer);
172 fprintf (stderr, pchErrorFormat[E_MAJOR_CODE], errorEvent->request_code);
173 sprintf(message, "%d", errorEvent->request_code);
174 XGetErrorDatabaseText (display, "XRequest", message,
175 " ", buffer, BUFSIZ);
176 fprintf (stderr, " (%s)\n ", buffer);
177 fprintf (stderr, pchErrorFormat[E_MINOR_CODE], errorEvent->minor_code);
178 fprintf (stderr, "\n ");
179 fprintf (stderr, pchErrorFormat[E_RESOURCE_ID], errorEvent->resourceid);
180 fprintf (stderr, "\n ");
181 fprintf (stderr, pchErrorFormat[E_ERROR_SERIAL], errorEvent->serial);
182 fprintf (stderr, "\n ");
183 fprintf (stderr, pchErrorFormat[E_CURRENT_SERIAL],
184 LastKnownRequestProcessed(display));
185 fprintf (stderr, "\n");
189 * Check for a BadWindow error for a managed window. If this error
190 * is detected indicate in the client data that the window no longer
194 if ((errorEvent->error_code == BadWindow) &&
195 !XFindContext (DISPLAY, errorEvent->resourceid, wmGD.windowContextType,
198 if (errorEvent->resourceid == pCD->client)
200 pCD->clientFlags |= CLIENT_DESTROYED;
204 wmGD.errorFlag = True;
205 wmGD.errorResource = errorEvent->resourceid;
206 wmGD.errorRequestCode = errorEvent->request_code;
210 } /* END OF FUNCTION WmXErrorHandler */
214 /*************************************<->*************************************
216 * WmXIOErrorHandler (display)
221 * This function is the X IO error handler that is registered with X to
222 * handle X IO errors. This function exits the window manager.
227 * display = X display on which the X IO error occurred
229 *************************************<->***********************************/
232 WmXIOErrorHandler (Display *display)
236 sprintf (err, "%s: %s\n", "I/O error on display:", XDisplayString(display));
239 ExitWM (WM_ERROR_EXIT_VALUE);
243 } /* END OF FUNCTIONS WmXIOErrorHandler */
247 /*************************************<->*************************************
249 * WmXtErrorHandler (message)
254 * This function is registered as the X Toolkit fatal error handler.
259 * message = pointer to an error message
261 *************************************<->***********************************/
264 WmXtErrorHandler (char *message)
268 ExitWM (WM_ERROR_EXIT_VALUE);
270 } /* END OF FUNCTION WmXtErrorHandler */
274 /*************************************<->*************************************
276 * WmXtWarningHandler (message)
281 * This function is registered as an X Toolkit warning handler.
286 * message = pointer to a warning message
288 *************************************<->***********************************/
291 WmXtWarningHandler (char *message)
298 } /* END OF FUNCTIONS WmXtWarningHandler */
301 /*************************************<->*************************************
308 * This function lists a message to stderr.
313 * message = pointer to a message string
315 *************************************<->***********************************/
318 Warning (char *message)
320 char pch[MAXWMPATH+1];
322 sprintf (pch, "%s: %s\n",
323 GETMESSAGE(20, 1, "Workspace Manager"), message);
325 _DtSimpleError (wmGD.mwmName, DtIgnore, NULL, pch, NULL);
327 } /* END OF FUNCTION Warning */
331 /******************************<->*************************************
333 * PrintFormatted (format, message, message, ...)
338 * This function lists several messages to stderr using fprintf()
339 * formatting capabilities.
343 * s0-s9 = pointers to message strings
347 * Caller must provide his/her own argv[0] to this function.
348 ******************************<->***********************************/
352 PrintFormatted(char *f, char *s0, char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, char *s7, char *s8, char *s9)
353 /* limit of ten args */
355 fprintf( stderr, f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
357 } /* END OF FUNCTION PrintFormatted */
359 /************************ eof **************************/
360 #endif /* DEBUGGER */