convert all Imakefile LinuxDistribution to LinuxArchitecture.
[oweals/cde.git] / cde / programs / dtksh / examples / SessionTest.src
1 XCOMM! CDE_INSTALLATION_TOP/bin/dtksh
2 XCOMM $XConsortium: SessionTest.src /main/6 1996/04/23 20:18:46 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 the steps necessary for tying into
15 XCOMM  session management.  To run, simply run this script, and then save the
16 XCOMM  current session.  When the session is restored, this script should again
17 XCOMM  restore to its previous state.
18 XCOMM 
19
20
21 XCOMM  This function is invoked when the user attempts to save the current session.
22 XCOMM  It will save off its state information (whether it is iconified, and the
23 XCOMM  list of workspaces it occupies) into a session file, and then tell the
24 XCOMM  session manager how to reinvoke it when the session is restored.
25 SessionCallback()
26 {
27 XCOMM   Get the name of our session file
28    if DtSessionSavePath $TOPLEVEL PATH SAVEFILE; then
29       exec 9>$PATH
30
31 XCOMM      Save our iconification state
32       if DtShellIsIconified $TOPLEVEL ; then
33          print -u9 'Iconified'
34       else
35          print -u9 'Deiconified'
36       fi
37
38 XCOMM      Save the list of workspace we occupy
39       if DtWsmGetWorkspacesOccupied $(XtDisplay "-" $TOPLEVEL) \
40                                     $(XtWindow "-" $TOPLEVEL) \
41                                     CURRENT_WS_LIST ;
42       then
43          oldIFS=$IFS
44          IFS=","
45          for item in $CURRENT_WS_LIST; 
46          do
47             XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $item
48             print -u9 $NAME
49          done
50          IFS=$oldIFS
51       fi
52
53       exec 9<&-
54
55 XCOMM      Tell the session manager how to restart us
56       DtSetStartupCommand $TOPLEVEL \
57                    "/usr/dt/share/examples/dtksh/SessionTest $SAVEFILE"
58    else
59       echo "DtSessionSavePath FAILED!!"
60       exit -3
61    fi
62 }
63
64
65 XCOMM  This function is invoked when we are restarted at session restore time.
66 XCOMM  It is passed the name of the session file as $1.  It will extract our
67 XCOMM  session information from the session file, and will restore our state
68 XCOMM  accordingly.
69 RestoreSession()
70 {
71 XCOMM   Get the full path of our session file
72    if DtSessionRestorePath $TOPLEVEL PATH $1; then
73       exec 9<$PATH
74       read -u9 ICONIFY
75
76 XCOMM      Restore our iconification state
77       case $ICONIFY in
78          Iconified) DtSetIconifyHint $TOPLEVEL True;;
79          *)         DtSetIconifyHint $TOPLEVEL False;;
80       esac
81
82 XCOMM      Place us into the indicated set of workspaces
83       WS_LIST=""
84       while read -u9 NAME
85       do
86          XmInternAtom ATOM $(XtDisplay "-" $TOPLEVEL) $NAME False
87          if [ ${#WS_LIST} -gt 0 ]; then
88             WS_LIST=$WS_LIST,$ATOM
89          else
90             WS_LIST=$ATOM
91          fi
92       done
93
94       DtWsmSetWorkspacesOccupied $(XtDisplay "-" $TOPLEVEL) \
95                                  $(XtWindow "-" $TOPLEVEL) \
96                                  $WS_LIST
97
98       exec 9<&-
99    else
100       echo "DtSessionRestorePath FAILED!!"
101       exit -3
102    fi
103 }
104
105
106
107 XCOMM ###################### Create the Main UI ###############################
108
109 XtInitialize TOPLEVEL wmProtTest WmProtTest "$0" "$@"
110
111 XtCreateManagedWidget DA da XmDrawingArea $TOPLEVEL
112 XtSetValues $DA height:200 width:200
113
114 XmInternAtom SAVE_SESSION_ATOM $(XtDisplay "-" $TOPLEVEL) "WM_SAVE_YOURSELF" False
115
116
117 XCOMM  If we are invoked with any command line parameters, then we will assume
118 XCOMM  that it is the name of our session file, and will restore to the indicated
119 XCOMM  state.
120 if (( $# > 0))
121 then
122    XtSetValues $TOPLEVEL mappedWhenManaged:False
123    XtRealizeWidget $TOPLEVEL
124    XSync $(XtDisplay "-" $TOPLEVEL) False
125    RestoreSession $1
126    XtSetValues $TOPLEVEL mappedWhenManaged:True
127    XtPopup $TOPLEVEL GrabNone
128 else
129    XtRealizeWidget $TOPLEVEL
130    XSync $(XtDisplay "-" $TOPLEVEL) False
131 fi
132
133 XCOMM  Register our interest in participating in session management.
134 XmAddWMProtocols $TOPLEVEL $SAVE_SESSION_ATOM
135 XmAddWMProtocolCallback $TOPLEVEL $SAVE_SESSION_ATOM SessionCallback
136
137 XtMainLoop