SessionTest.src 4.2 KB

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