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 librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: wsinfo.c /main/3 1995/10/27 10:41:27 rswiston $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company
26 * (c) Copyright 1993, 1994 International Business Machines Corp.
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
28 * (c) Copyright 1993, 1994 Novell, Inc.
31 /* Demonstrate the CDE Workspace API. */
46 static void updateCB();
47 static void ShowCurrentWorkspaceInfo();
48 static DtWsmWsChangeProc wschangecb();
49 static void InstallXErrorHandler();
54 static Widget toplevel;
55 static Widget wChildren[20];
60 #define QUIT_BUTTON (wChildren[0])
61 #define UPDATE_BUTTON (wChildren[1])
62 #define SEPARATOR (wChildren[2])
63 #define WS_LABEL (wChildren[3])
64 #define WS_VALUE (wChildren[4])
65 #define TITLE_LABEL (wChildren[5])
66 #define TITLE_VALUE (wChildren[6])
67 #define BACKDROP_LABEL (wChildren[7])
68 #define BACKDROP_VALUE (wChildren[8])
69 #define COLORSET_LABEL (wChildren[9])
70 #define COLORSET_VALUE (wChildren[10])
71 #define SEPARATOR2 (wChildren[11])
72 #define NUM_CHILDREN 12
75 * main - main logic for program
84 XtAppContext app_context;
88 XmString xms, xmsBlank;
94 XtSetArg (args[n], XmNallowShellResize, True); n++;
95 toplevel = XtAppInitialize (&app_context, "Dtwsinfo", NULL, 0, &argc, argv,
99 * Set up X error handling
101 InstallXErrorHandler ();
104 XtSetArg (args[n], XmNmarginWidth, 10); n++;
105 XtSetArg (args[n], XmNmarginHeight, 10); n++;
106 frame = XmCreateFrame (toplevel, "frame", args, n);
107 XtManageChild (frame);
113 form = XmCreateForm (frame, "form", args, n);
114 XtManageChild (form);
117 * create compound string for blank labels
119 xmsBlank = XmStringCreateLocalized(" ");
121 /*******************************************
123 ******************************************/
126 * create compound string for the button text
128 xms = XmStringCreateLocalized("Quit");
134 XtSetArg (args[n], XmNlabelType, XmSTRING); n++;
135 XtSetArg (args[n], XmNlabelString, xms); n++;
136 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
137 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
141 top = QUIT_BUTTON = XtCreateWidget ("button", xmPushButtonWidgetClass,
148 XtAddCallback (QUIT_BUTTON, XmNactivateCallback, quitCB, NULL);
150 /*******************************************
151 * UPDATE WORKSPACE INFO BUTTON
152 ******************************************/
155 * create compound string for the button text
157 xms = XmStringCreateLocalized("Get workspace info");
163 XtSetArg (args[n], XmNlabelType, XmSTRING); n++;
164 XtSetArg (args[n], XmNlabelString, xms); n++;
165 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
166 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
167 XtSetArg (args[n], XmNtopWidget, top); n++;
171 top = UPDATE_BUTTON = XtCreateWidget ("button", xmPushButtonWidgetClass,
178 XtAddCallback (UPDATE_BUTTON, XmNactivateCallback, updateCB, NULL);
180 /*******************************************
182 ******************************************/
188 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
189 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
190 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
191 XtSetArg (args[n], XmNtopWidget, top); n++;
195 top = SEPARATOR = (Widget)
196 XmCreateSeparatorGadget (form, "separator", args, n);
198 /*******************************************
199 * LABEL FOR CURRENT WORKSPACE
200 ******************************************/
203 * NOTE: We assume this is the longest label and lay out the
204 * other fields based on this assumption.
208 * create compound string for the label text
210 xms = XmStringCreateLocalized("Current workspace: ");
216 XtSetArg (args[n], XmNlabelType, XmSTRING); n++;
217 XtSetArg (args[n], XmNlabelString, xms); n++;
218 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
219 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
220 XtSetArg (args[n], XmNtopWidget, top); n++;
224 WS_LABEL = XtCreateWidget ("label", xmLabelWidgetClass,
228 /*******************************************
229 * VALUE FOR CURRENT WORKSPACE
230 ******************************************/
236 XtSetArg (args[n], XmNlabelType, XmSTRING); n++;
237 XtSetArg (args[n], XmNlabelString, xmsBlank); n++;
238 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
239 XtSetArg (args[n], XmNleftWidget, WS_LABEL); n++;
240 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
241 XtSetArg (args[n], XmNtopWidget, top); n++;
245 top = WS_VALUE = XtCreateWidget ("label", xmLabelWidgetClass,
248 /*******************************************
249 * LABEL FOR WORKSPACE TITLE
250 ******************************************/
253 * create compound string for the label text
255 xms = XmStringCreateLocalized(" title: ");
261 XtSetArg (args[n], XmNlabelType, XmSTRING); n++;
262 XtSetArg (args[n], XmNlabelString, xms); n++;
263 XtSetArg (args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
264 XtSetArg (args[n], XmNrightWidget, WS_LABEL); n++;
265 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
266 XtSetArg (args[n], XmNtopWidget, top); n++;
270 TITLE_LABEL = XtCreateWidget ("label", xmLabelWidgetClass,
274 /*******************************************
275 * VALUE FOR WORKSPACE TITLE
276 ******************************************/
282 XtSetArg (args[n], XmNlabelType, XmSTRING); n++;
283 XtSetArg (args[n], XmNlabelString, xmsBlank); n++;
284 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
285 XtSetArg (args[n], XmNleftWidget, TITLE_LABEL); n++;
286 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
287 XtSetArg (args[n], XmNtopWidget, top); n++;
291 top = TITLE_VALUE = XtCreateWidget ("label", xmLabelWidgetClass,
294 /*******************************************
295 * LABEL FOR WORKSPACE BACKDROP
296 ******************************************/
299 * create compound string for the label text
301 xms = XmStringCreateLocalized(" backdrop: ");
307 XtSetArg (args[n], XmNlabelType, XmSTRING); n++;
308 XtSetArg (args[n], XmNlabelString, xms); n++;
309 XtSetArg (args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
310 XtSetArg (args[n], XmNrightWidget, WS_LABEL); n++;
311 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
312 XtSetArg (args[n], XmNtopWidget, top); n++;
316 BACKDROP_LABEL = XtCreateWidget ("label", xmLabelWidgetClass,
320 /*******************************************
321 * VALUE FOR WORKSPACE BACKDROP
322 ******************************************/
328 XtSetArg (args[n], XmNlabelType, XmSTRING); n++;
329 XtSetArg (args[n], XmNlabelString, xmsBlank); n++;
330 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
331 XtSetArg (args[n], XmNleftWidget, BACKDROP_LABEL); n++;
332 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
333 XtSetArg (args[n], XmNtopWidget, top); n++;
337 top = BACKDROP_VALUE = XtCreateWidget ("label", xmLabelWidgetClass,
340 /*******************************************
341 * LABEL FOR WORKSPACE COLORSET ID
342 ******************************************/
345 * create compound string for the label text
347 xms = XmStringCreateLocalized(" color set id: ");
353 XtSetArg (args[n], XmNlabelType, XmSTRING); n++;
354 XtSetArg (args[n], XmNlabelString, xms); n++;
355 XtSetArg (args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
356 XtSetArg (args[n], XmNrightWidget, WS_LABEL); n++;
357 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
358 XtSetArg (args[n], XmNtopWidget, top); n++;
362 COLORSET_LABEL = XtCreateWidget ("label", xmLabelWidgetClass,
366 /*******************************************
367 * VALUE FOR WORKSPACE COLORSET ID
368 ******************************************/
374 XtSetArg (args[n], XmNlabelType, XmSTRING); n++;
375 XtSetArg (args[n], XmNlabelString, xmsBlank); n++;
376 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
377 XtSetArg (args[n], XmNleftWidget, COLORSET_LABEL); n++;
378 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
379 XtSetArg (args[n], XmNtopWidget, top); n++;
383 top = COLORSET_VALUE = XtCreateWidget ("label", xmLabelWidgetClass,
386 /*******************************************
388 ******************************************/
394 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
395 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
396 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
397 XtSetArg (args[n], XmNtopWidget, top); n++;
401 top = SEPARATOR2 = (Widget)
402 XmCreateSeparatorGadget (form, "separator", args, n);
407 XtManageChildren (wChildren, NUM_CHILDREN);
410 * Show info on current workspace
412 ShowCurrentWorkspaceInfo ();
417 XtRealizeWidget (toplevel);
420 * Do these calls after the shell is realized.
421 * They need a window created for the top level shell.
423 * HINT: See XtSetMappedWhenManaged(1) if you want to
424 * realize a widget to get a window, but need to
425 * control when the map of the window occurs.
427 (void) DtWsmAddCurrentWorkspaceCallback (toplevel,
428 (DtWsmWsChangeProc) wschangecb, NULL);
430 DtWsmOccupyAllWorkspaces (XtDisplay(toplevel), XtWindow(toplevel));
435 XtAppMainLoop (app_context);
439 /*-------------------------------------------------------------
440 * Update the information for the current workspace
442 static void ShowCurrentWorkspaceInfo ()
444 Arg args[10]; /* arg list */
445 register int n; /* arg count */
450 DtWsmWorkspaceInfo *pWsInfo;
455 dpy = XtDisplay(toplevel);
456 root = XDefaultRootWindow(dpy);
458 rval = DtWsmGetCurrentWorkspace(dpy, root, &aWs);
462 rval = DtWsmGetWorkspaceInfo (dpy, root, aWs, &pWsInfo);
467 pchName = XmGetAtomName (dpy, pWsInfo->workspace);
468 xms = XmStringCreateLocalized(pchName);
471 XtSetArg (args[n], XmNlabelString, xms); n++;
472 XtSetValues (WS_VALUE, args, n);
477 /* workspace title */
478 xms = XmStringCreateLocalized(pWsInfo->pchTitle);
481 XtSetArg (args[n], XmNlabelString, xms); n++;
482 XtSetValues (TITLE_VALUE, args, n);
486 /* workspace backdrop name */
487 if (pWsInfo->backdropName != None)
488 pchName = XmGetAtomName (dpy, pWsInfo->backdropName);
490 pchName = "<failed to load!>";
491 xms = XmStringCreateLocalized(pchName);
494 XtSetArg (args[n], XmNlabelString, xms); n++;
495 XtSetValues (BACKDROP_VALUE, args, n);
498 if (pWsInfo->backdropName != None)
501 /* workspace colorset id */
502 sprintf (pch, "%d", pWsInfo->colorSetId);
503 xms = XmStringCreateLocalized(pch);
506 XtSetArg (args[n], XmNlabelString, xms); n++;
507 XtSetValues (COLORSET_VALUE, args, n);
511 DtWsmFreeWorkspaceInfo (pWsInfo);
517 fprintf (stderr, "Failed to get workspace information.\n");
518 fprintf (stderr, "Is dtwm running?\n");
523 /*-------------------------------------------------------------
524 * quitCB - callback for button
526 static void quitCB (w, client_data, call_data)
527 Widget w; /* widget id */
528 XtPointer client_data; /* data from application */
529 XtPointer call_data; /* data from widget class */
535 /*-------------------------------------------------------------
536 * updateCB - callback for show current workspace info
538 static void updateCB (w, client_data, call_data)
539 Widget w; /* widget id */
540 XtPointer client_data; /* data from application */
541 XtPointer call_data; /* data from widget class */
544 ShowCurrentWorkspaceInfo ();
548 /*-------------------------------------------------------------
549 ** wschangecb - callback for workspace switch
551 static DtWsmWsChangeProc
552 wschangecb (w, atom, client_data)
555 XtPointer client_data;
557 ShowCurrentWorkspaceInfo ();
562 /*-------------------------------------------------------------
563 ** data for X error handler
565 #define E_MAJOR_CODE 0
566 #define E_MINOR_CODE 1
567 #define E_RESOURCE_ID 2
568 #define E_ERROR_SERIAL 3
569 #define E_CURRENT_SERIAL 4
571 #define NUM_E_STRINGS 5
573 static char *pchErrorFormatNames [NUM_E_STRINGS] = {
581 static char *pchErrorFormat [NUM_E_STRINGS];
584 /*-------------------------------------------------------------
585 ** HandleXErrors - catch X protocol errors
588 _HandleXErrors (display, errorEvent)
590 XErrorEvent *errorEvent;
593 char message[BUFSIZ];
595 XGetErrorText (display, errorEvent->error_code, buffer, BUFSIZ);
596 fprintf (stderr, "\n*** X error occurred ***\n");
597 fprintf (stderr, "Description = '%s'\n ", buffer);
599 fprintf (stderr, pchErrorFormat[E_MAJOR_CODE], errorEvent->request_code);
600 sprintf(message, "%d", errorEvent->request_code);
601 XGetErrorDatabaseText (display, "XRequest", message, " ", buffer, BUFSIZ);
602 fprintf (stderr, " (%s)\n ", buffer);
603 fprintf (stderr, pchErrorFormat[E_MINOR_CODE], errorEvent->minor_code);
604 fprintf (stderr, "\n ");
605 fprintf (stderr, pchErrorFormat[E_RESOURCE_ID], errorEvent->resourceid);
606 fprintf (stderr, "\n ");
607 fprintf (stderr, pchErrorFormat[E_ERROR_SERIAL], errorEvent->serial);
608 fprintf (stderr, "\n ");
609 fprintf (stderr, pchErrorFormat[E_CURRENT_SERIAL],
610 LastKnownRequestProcessed(display));
611 fprintf (stderr, "\n");
616 /*-------------------------------------------------------------
617 ** Setup the X error handler
620 InstallXErrorHandler ( display )
627 * Fetch the X error format strings from XErrorDB
629 for (i = 0; i< NUM_E_STRINGS; i++)
631 XGetErrorDatabaseText (display, "XlibMessage",
632 pchErrorFormatNames[i], " %d ", buffer, BUFSIZ);
634 pchErrorFormat[i] = (char *) XtMalloc (1+strlen(buffer));
636 strcpy(pchErrorFormat[i], buffer);
639 XSetErrorHandler (_HandleXErrors);