DtWsTest1.src 5.4 KB

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