convert all Imakefile LinuxDistribution to LinuxArchitecture.
[oweals/cde.git] / cde / programs / dtksh / examples / DtWsTest1.src
1 XCOMM! CDE_INSTALLATION_TOP/bin/dtksh
2 XCOMM  $XConsortium: DtWsTest1.src /main/3 1996/04/23 20:18:06 drk $
3
4 XCOMM #########################################################################
5 XCOMM   (c) Copyright 1993, 1994 Hewlett-Packard Company        
6 XCOMM   (c) Copyright 1993, 1994 International Business Machines Corp.
7 XCOMM   (c) Copyright 1993, 1994 Sun Microsystems, Inc.
8 XCOMM   (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
9 XCOMM       Novell, Inc.
10 XCOMM #########################################################################
11
12
13 XCOMM 
14 XCOMM  This sample shell script demonstrates how to interact with the workspace
15 XCOMM  manager.  It demonstrates the following capabilities:
16 XCOMM 
17 XCOMM   1) How to query which workspaces the widgets currently reside it.
18 XCOMM   2) How to set the current workspace.
19 XCOMM   3) How to be notified when the current workspace changes.
20 XCOMM 
21
22
23 integer wsCount
24
25 XCOMM  Pushbutton Callback: This function asks the workspace manager to change
26 XCOMM                       to the workspace indicated by $1; $1 is an X atom
27 XCOMM                       which identifies the new workspace.  At some point
28 XCOMM                       after our request to the workspace manager, the
29 XCOMM                       workspace manager will activate our WsCB function,
30 XCOMM                       letting us know that the change has actually taken
31 XCOMM                       place.
32 SetWorkspace()
33 {
34    echo
35    if DtWsmSetCurrentWorkspace $TOPLEVEL $1; then
36       echo "Changing to new workspace"
37    else
38       XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $1
39       echo "Unable to Change to workspace " $NAME
40    fi
41 }
42
43 XCOMM  Workspace Changed Callback: This function is invoked whenever the workspace
44 XCOMM                              manager changes workspaces.  It will simply
45 XCOMM                              query the 'name' of the new workspace, and
46 XCOMM                              echo it outl
47 WsCB()
48 {
49    DtWsmGetCurrentWorkspace $(XtDisplay "-" $TOPLEVEL) \
50                        $(XRootWindowOfScreen "-" $(XtScreen "-" $TOPLEVEL)) \
51                        NEW_ATOM
52    XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $NEW_ATOM
53    echo "Change to workspace complete " $NAME  "("$NEW_ATOM")"
54 }
55
56 XCOMM ###################### Create the Main UI ###############################
57
58 XtInitialize TOPLEVEL dtWsTest DtWsTest "$0" "$@"
59 XtSetValues $TOPLEVEL allowShellResize:True
60
61 XtCreateManagedWidget DA da XmDrawingArea $TOPLEVEL
62 XtSetValues $DA height:200 width:200
63
64 XtRealizeWidget $TOPLEVEL
65 XSync $(XtDisplay "-" $TOPLEVEL) False
66
67 XtCreateApplicationShell TOPLEVEL2 DtWsTesta TopLevelShell
68
69 XtCreateManagedWidget RC rc XmRowColumn $TOPLEVEL2 \
70          orientation:HORIZONTAL \
71          packing:PACK_COLUMN 
72
73 XCOMM  Get a list of all of the workspaces, and create a pushbutton for each one.
74 XCOMM  When a pushbutton is activated, it will ask the workspace manager to
75 XCOMM  change to the indicated workspace.
76 oldIF=$IFS
77 if DtWsmGetWorkspaceList $(XtDisplay "-" $TOPLEVEL) \
78                           $(XRootWindowOfScreen "-" $(XtScreen "-" $TOPLEVEL)) \
79                           WS_LIST; 
80 then
81    IFS=,
82    wsCount=0
83    for item in $WS_LIST; 
84    do
85       XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $item
86       label="Set Current Workspace to "$NAME
87       XtCreateManagedWidget ITEM $item XmPushButton $RC \
88              labelString:$label
89       XtAddCallback $ITEM activateCallback "SetWorkspace $item"
90       wsCount=$wsCount+1
91    done
92    IFS=$oldIFS
93 else
94    echo "Unable to get workspace list"
95    exit -1
96 fi
97
98 XtSetValues $RC numColumns:$wsCount
99 XtRealizeWidget $TOPLEVEL2
100 XSync $(XtDisplay "-" $TOPLEVEL) False
101
102 XCOMM  The following block queries the initial set of workspaces occupied by
103 XCOMM  this shell script; this list is printed out.  Next, it will ask the
104 XCOMM  workspace manager to move the shell script windows into all workspaces.
105 XCOMM  Lastly, it will again ask the workspace manager for the list of
106 XCOMM  workspaces occupied by the shell script windows, and will again print
107 XCOMM  out the list.
108 if DtWsmGetWorkspacesOccupied $(XtDisplay "-" $TOPLEVEL) \
109                                $(XtWindow "-" $TOPLEVEL) \
110                                CURRENT_WS_LIST ;
111 then
112    echo "Initial workspaces occupied:"
113    for item in $CURRENT_WS_LIST; 
114    do
115       XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $item
116       echo "   "$NAME
117    done
118
119    DtWsmGetWorkspaceList $(XtDisplay "-" $TOPLEVEL) \
120                           $(XRootWindowOfScreen "-" $(XtScreen "-" $TOPLEVEL)) \
121                           WS_LIST
122
123    DtWsmSetWorkspacesOccupied $(XtDisplay "-" $TOPLEVEL) \
124                                $(XtWindow "-" $TOPLEVEL) \
125                                $WS_LIST
126
127    DtWsmSetWorkspacesOccupied $(XtDisplay "-" $TOPLEVEL2) \
128                                $(XtWindow "-" $TOPLEVEL2) \
129                                $WS_LIST
130 else
131    echo "Unable to get current list of occupied workspaces"
132    echo -2
133 fi
134
135 XSync $(XtDisplay "-" $TOPLEVEL) False
136
137 XCOMM  Print the new list of workspaces occupied
138 DtWsmGetWorkspacesOccupied $(XtDisplay "-" $TOPLEVEL) \
139                             $(XtWindow "-" $TOPLEVEL) \
140                             CURRENT_WS_LIST
141
142 echo "After modification, workspaces occupied:"
143 IFS=,
144 for item in $CURRENT_WS_LIST; 
145 do
146    XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $item
147    echo "   "$NAME
148 done
149 IFS=$oldIFS
150 echo ""
151
152 XCOMM  Add a callback to be notified whenever the workspace changes.
153 DtWsmAddCurrentWorkspaceCallback HANDLE1 $TOPLEVEL WsCB
154
155 XtMainLoop