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: occupy.c /main/3 1995/10/27 10:41:19 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.
32 /* Demonstrate the DtWsm Workspace API. */
52 static void allWsCB();
53 static void SetupWorkspaceButtons ();
54 static void ShowWorkspaceOccupancy();
55 static void SetWorkspaceOccupancy();
62 static Widget toplevel;
63 static Widget wChildren [20];
65 static Atom *paWsSet = NULL;
66 static Boolean *pbOccupy;
67 static unsigned long numWorkspaces;
73 #define QUIT_BUTTON (wChildren[0])
74 #define SEPARATOR (wChildren[1])
75 #define SET_BUTTON (wChildren[2])
76 #define SHOW_BUTTON (wChildren[3])
77 #define ALL_WS_BUTTON (wChildren[4])
78 #define NUM_CHILDREN 5
81 * main - main logic for program
91 XtAppContext app_context;
100 XtSetArg (args[n], XmNallowShellResize, True); n++;
101 toplevel = XtAppInitialize (&app_context, "Dtoccupy", NULL, 0, &argc, argv,
105 XtSetArg (args[n], XmNmarginWidth, 10); n++;
106 XtSetArg (args[n], XmNmarginHeight, 10); n++;
107 frame = XmCreateFrame (toplevel, "frame", args, n);
108 XtManageChild (frame);
114 form = XmCreateForm (frame, "form", args, n);
115 XtManageChild (form);
118 * create compound string for the button text
120 xms = XmStringCreateLocalized("Quit");
126 XtSetArg (args[n], XmNlabelType, XmSTRING); n++;
127 XtSetArg (args[n], XmNlabelString, xms); n++;
128 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
129 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
134 top = QUIT_BUTTON = XtCreateWidget ("button", xmPushButtonWidgetClass,
141 XtAddCallback (QUIT_BUTTON, XmNactivateCallback, quitCB, NULL);
144 * create compound string for the button text
146 xms = XmStringCreateLocalized("Set Occupancy");
152 XtSetArg (args[n], XmNlabelType, XmSTRING); n++;
153 XtSetArg (args[n], XmNlabelString, xms); n++;
154 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
155 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
156 XtSetArg (args[n], XmNtopWidget, top); n++;
161 top = SET_BUTTON = XtCreateWidget ("button", xmPushButtonWidgetClass,
168 XtAddCallback (SET_BUTTON, XmNactivateCallback, setCB, NULL);
171 * create compound string for the button text
173 xms = XmStringCreateLocalized("Occupy All Workspaces");
179 XtSetArg (args[n], XmNlabelType, XmSTRING); n++;
180 XtSetArg (args[n], XmNlabelString, xms); n++;
181 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
182 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
183 XtSetArg (args[n], XmNtopWidget, top); n++;
187 top = ALL_WS_BUTTON = XtCreateWidget ("button", xmPushButtonWidgetClass,
195 XtAddCallback (ALL_WS_BUTTON, XmNactivateCallback, allWsCB, NULL);
198 * create compound string for the button text
200 xms = XmStringCreateLocalized("Show Occupancy");
206 XtSetArg (args[n], XmNlabelType, XmSTRING); n++;
207 XtSetArg (args[n], XmNlabelString, xms); n++;
208 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
209 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
210 XtSetArg (args[n], XmNtopWidget, top); n++;
214 top = SHOW_BUTTON = XtCreateWidget ("button", xmPushButtonWidgetClass,
221 XtAddCallback (SHOW_BUTTON, XmNactivateCallback, showCB, NULL);
227 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
228 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
229 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
230 XtSetArg (args[n], XmNtopWidget, top); n++;
234 top = SEPARATOR = (Widget)
235 XmCreateSeparatorGadget (form, "separator", args, n);
238 * set up workspace buttons
240 SetupWorkspaceButtons (form, top);
245 XtManageChildren (wChildren, NUM_CHILDREN);
246 XtManageChildren (wWs, numWorkspaces);
251 XtRealizeWidget (toplevel);
254 * set up initial workspace occupancy info
256 pbOccupy = (Boolean *) XtMalloc (numWorkspaces * sizeof (Boolean));
257 for (i=0; i<numWorkspaces; i++)
261 ShowWorkspaceOccupancy ();
266 XtAppMainLoop (app_context);
269 /*-------------------------------------------------------------
270 * Create a set of buttons for the current set of workspaces
272 static void SetupWorkspaceButtons (form, top)
277 Arg args[10]; /* arg list */
278 register int n; /* arg count */
280 DtWsmWorkspaceInfo *pWsInfo;
286 * get workspace information
288 root = XRootWindowOfScreen(XtScreen(form));
289 if (DtWsmGetWorkspaceList (XtDisplay(form), root,
290 &paWs, (int *)&numWorkspaces) == Success)
292 wWs = (Widget *) XtMalloc (numWorkspaces * sizeof (Widget));
294 for (i=0; i<numWorkspaces; i++, pWid++)
296 DtWsmGetWorkspaceInfo (XtDisplay(form), root, paWs[i],
299 pchWs = (char *) XmGetAtomName (XtDisplay(form),
302 * create compound string for the button text
304 xms = XmStringCreateLocalized(pchWs);
310 XtSetArg (args[n], XmNlabelType, XmSTRING); n++;
311 XtSetArg (args[n], XmNlabelString, xms); n++;
312 XtSetArg (args[n], XmNindicatorOn, True); n++;
313 XtSetArg (args[n], XmNindicatorType, XmN_OF_MANY); n++;
316 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
320 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
321 XtSetArg (args[n], XmNleftWidget, left); n++;
323 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
324 XtSetArg (args[n], XmNtopWidget, top); n++;
328 *pWid = XtCreateWidget ("button", xmToggleButtonWidgetClass,
335 XtAddCallback (*pWid, XmNvalueChangedCallback, wsCB,
342 fprintf(stderr, "Failed to get workspace info -- dtwm not running!\n");
347 /*-------------------------------------------------------------
348 * Update the workspace buttons with where we are now.
350 static void ShowWorkspaceOccupancy ()
352 Arg args[10]; /* arg list */
353 register int n; /* arg count */
356 unsigned long numWsIn;
359 rval = DtWsmGetWorkspacesOccupied(XtDisplay(toplevel),
360 XtWindow(toplevel), &paWsIn, &numWsIn );
365 for (i = 0; i<numWorkspaces; i++)
368 for (j=0; j<numWsIn; j++)
370 if (paWs[i] == paWsIn[j])
378 for (i = 0; i<numWorkspaces; i++)
383 XtSetArg (args[n], XmNset, True); n++;
387 XtSetArg (args[n], XmNset, False); n++;
389 XtSetValues (wWs[i], args, n);
392 if (paWsIn) XFree ((char *) paWsIn);
396 /*-------------------------------------------------------------
397 * quitCB - callback for button
399 static void quitCB (w, client_data, call_data)
400 Widget w; /* widget id */
401 XtPointer client_data; /* data from application */
402 XtPointer call_data; /* data from widget class */
408 /*-------------------------------------------------------------
409 * showCB - callback for show occupancy button
411 static void showCB (w, client_data, call_data)
412 Widget w; /* widget id */
413 XtPointer client_data; /* data from application */
414 XtPointer call_data; /* data from widget class */
417 ShowWorkspaceOccupancy();
421 /*-------------------------------------------------------------
422 * setCB - callback for set occupancy button
424 static void setCB (w, client_data, call_data)
425 Widget w; /* widget id */
426 XtPointer client_data; /* data from application */
427 XtPointer call_data; /* data from widget class */
434 paWsSet = (Atom *) XtMalloc (numWorkspaces * sizeof(Atom));
437 for (i=0, numSet=0; i<numWorkspaces; i++)
441 paWsSet[numSet++] = paWs[i];
445 DtWsmSetWorkspacesOccupied (XtDisplay(toplevel),
446 XtWindow(toplevel), paWsSet, numSet);
450 /*-------------------------------------------------------------
451 * wsCB - callback for set occupancy button
453 static void wsCB (w, client_data, call_data)
454 Widget w; /* widget id */
455 XtPointer client_data; /* data from application */
456 XtPointer call_data; /* data from widget class */
458 int i = (Atom) client_data; /* ws array index */
459 XmToggleButtonCallbackStruct *ptb =
460 (XmToggleButtonCallbackStruct *) call_data;
462 if (ptb->reason == XmCR_VALUE_CHANGED)
475 /*-------------------------------------------------------------
476 * allWsCB - callback for occupy all button
478 static void allWsCB (w, client_data, call_data)
479 Widget w; /* widget id */
480 XtPointer client_data; /* data from application */
481 XtPointer call_data; /* data from widget class */
483 DtWsmOccupyAllWorkspaces (XtDisplay(toplevel), XtWindow(toplevel));