PARTIAL SUMMARY: which CDE workspace am I in ?

From: Lucio Chiappetti <lucio_at_mi.iasf.cnr.it>
Date: Fri, 04 Apr 2003 17:59:09 +0200 (MET DST)

On Fri, 4 Apr 2003, Lucio Chiappetti wrote:

> ... I'd like to have a better way to tell me which workspace I am in,
> with a name either as
>
> - a little icon with the workspace name
> - a script which could set an environment variable [...]

I have discovered the man pages and the online documentation for dtksh,
and learned quite a bit about X (but not enough ?!)

I have therefore solved the second problem above. The first script
enclosed essentially flashes a little useless widget, but in the process
of doing so returns the workspace number to the terminal. I could
therefore use an assignment like set myswp=`myworkspacefast` (the name of
the script) and use it in my standard script to set window banners in
addition to host, username and tty.

But you know the saying "appetite comes while eating".

During my exercises I discovered I could keep the workspace number
permanently up (e.g. in the widget title bar). I could even have the
widget occupy all workspaces, and define a callback which automatically
updates the title whenever I change workspace.

This is exemplified by the second script, which is a sort of solution to
my first problem.

It has a little imperfection. When I call it (myworkspace.standalone),
I cannot force the window to appear where I want. It always appears in the
top left corner. Looks a window manager issue, but other applications
behave differently.

Also more appetite comes. I now want the above widget to come out at
login. I did several tries, like updating the .dt/session/home/dt.session
by hand, or calling up the CDE control panel, with no result. In
particular using the control panel "set home session" did not alter the
above file !

After which a more careful reading of man dtksh and of the example script
contained therein (which I stripped a lot) taught me that applications
to be saved in the home session require to be aware of that (or the
session manager has to be aware of the application)

So I copied back in (third script) the code in man dtksh. This way a "set
home session" writes the correct commands. It also saves a "session file"
which in my case is useless/redundant (it contains "Deiconified" and the
list of the 4 ws0 ws1 ws2 ws3).

BUT STILL WHEN I LOGIN THE WIDGET IS RESTARTED not only in the top
left corner but also ONLY IN WORKSPACE 1. This irrespective of the fact
that both the session file and my code tell it to occupy all workspaces
(one at a turn or all in a go).

I tried also some variations simplifying the code, ignoring the session
file, or forcing occupation of one workspace at a time, but in all cases
when started from login it occupies only workspace 1 (if I manually occupy
all wsp's it works, and if I call it manually it occupies all wsp's)

What's wrong ?

----------------------------------------------------------------------------
Lucio Chiappetti - IASF/CNR - via Bassini 15 - I-20133 Milano (Italy)
----------------------------------------------------------------------------
L'Italia ripudia la guerra [...] come Italy repudiates war {...] as a
mezzo di risoluzione delle controversie way of resolution of international
internazionali controversies
                [Art. 11 Constitution of the Italian Republic]
----------------------------------------------------------------------------
For more info : http://www.mi.iasf.cnr.it/~lucio/personal.html
----------------------------------------------------------------------------

-------------------------------------------------------------------
Script 1 : This script returns the workspace number (1-4) to terminal
-------------------------------------------------------------------
#! /usr/dt/bin/dtksh
       XtInitialize TOPLEVEL wmProtTest Dtksh "$_at_"
       XtCreateManagedWidget DA da XmDrawingArea $TOPLEVEL
       XtSetValues $DA height:1 width:160
       XtSetValues $TOPLEVEL title:"prova"
       XtRealizeWidget $TOPLEVEL
       XtScreen MYSCREEN $DA
       XRootWindowOfScreen RW $MYSCREEN
       DtWsmGetCurrentWorkspace $(XtDisplay "-" $TOPLEVEL) $RW CURRENT_WS_LIST
       XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $CURRENT_WS_LIST
           NUMBER=${NAME##ws}
           NUMBER=$(($NUMBER+1))
           echo $NUMBER
       XtSetValues $TOPLEVEL title:"workspace $NUMBER"
       XSync $(XtDisplay "-" $TOPLEVEL) False
       exit

-------------------------------------------------------------------
Script 2 : This script returns the workspace number (1-4) in a widget
-------------------------------------------------------------------
#! /usr/dt/bin/dtksh
       MyCallBack()
       {
           XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $CB_CALL_DATA
           NUMBER=${NAME##ws}
           NUMBER=$(($NUMBER+1))
       XtSetValues $TOPLEVEL title:"workspace $NUMBER"
       XSync $(XtDisplay "-" $TOPLEVEL) False
       }
       XtInitialize TOPLEVEL wmProtTest Dtksh "$_at_"
       XtCreateManagedWidget DA da XmDrawingArea $TOPLEVEL
       XtSetValues $DA height:1 width:160
       XtSetValues $DA x:+1065 y:+332
       XtSetValues $TOPLEVEL title:"prova"
       XmInternAtom SAVE_SESSION_ATOM $(XtDisplay "-" $TOPLEVEL) "WM_SAVE_YOURSELF" True
       XtRealizeWidget $TOPLEVEL
       XmAddWMProtocols $TOPLEVEL $SAVE_SESSION_ATOM
       XtScreen MYSCREEN $DA
       XRootWindowOfScreen RW $MYSCREEN
       DtWsmGetCurrentWorkspace $(XtDisplay "-" $TOPLEVEL) $RW CURRENT_WS_LIST
       XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $CURRENT_WS_LIST
           NUMBER=${NAME##ws}
           NUMBER=$(($NUMBER+1))
       XtSetValues $TOPLEVEL title:"workspace $NUMBER"
       DtWsmOccupyAllWorkspaces $(XtDisplay "-" $TOPLEVEL) $(XtWindow "-" $TOPLEVEL)
       XSync $(XtDisplay "-" $TOPLEVEL) False
       DtWsmAddCurrentWorkspaceCallback NEW $DA MyCallBack
       XtMainLoop

-------------------------------------------------------------------
Script 3 : as script 2 but should be session management aware
-------------------------------------------------------------------
#! /usr/dt/bin/dtksh
#
# this call back acts at change of workspace
       MyCallBack()
       {
           XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $CB_CALL_DATA
           NUMBER=${NAME##ws}
           NUMBER=$(($NUMBER+1))
       XtSetValues $TOPLEVEL title:"workspace $NUMBER"
       XSync $(XtDisplay "-" $TOPLEVEL) False
       }
#
# this from the man page
       # Function invoked when the session is being ended by the user
       SessionCallback()
       {
         # Get the name of the file into which we should save our
         # session information
         if DtSessionSavePath $TOPLEVEL PATH SAVEFILE; then
           exec 9>$PATH
           # Save off whether we are currently in an iconified state
           if DtShellIsIconified $TOPLEVEL ; then
           print -u9 'Iconified'
           else
           print -u9 'Deiconified'
           fi
           # Save off the list of workspaces we currently reside in
           if DtWsmGetWorkspacesOccupied $(XtDisplay "-" $TOPLEVEL) $(XtWindow "-" $TOPLEVEL) CURRENT_WS_LIST ;
           then
           # Map the comma-separated list of atoms into
           # their string representation
           oldIFS=$IFS
           IFS=","
           for item in $CURRENT_WS_LIST;
           do
           XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $item
           print -u9 $NAME
           done
           IFS=$oldIFS
           fi
           exec 9<&-
           # Let the session manager know how to invoke us when
           # the session is restored
           DtSetStartupCommand $TOPLEVEL "/ouranos/cdeuser/myrealworkspace $SAVEFILE"
         else
           echo "DtSessionSavePath FAILED!!"
           exit -3
         fi
       }
       # Function invoked during a restore session; restores the
       # application to its previous state
       RestoreSession()
       {
         # Retrieve the path where our session file resides
         if DtSessionRestorePath $TOPLEVEL PATH $1; then
           exec 9<$PATH
           read -u9 ICONIFY
           # Extract and restore our iconified state
           case $ICONIFY in
           Iconified) DtSetIconifyHint $TOPLEVEL True;;
           *) DtSetIconifyHint $TOPLEVEL False;
            esac
           # Extract the list of workspaces we belong in, convert
           # them to atoms, and ask the workspace manager to relocate
           # us to those workspaces
           WS_LIST=""
           while read -u9 NAME
           do
           XmInternAtom ATOM $(XtDisplay "-" $TOPLEVEL) $NAME False
           if [ ${#WS_LIST} -gt 0 ]; then
           WS_LIST=$WS_LIST,$ATOM
           else
           WS_LIST=$ATOM
           fi
           done
           DtWsmSetWorkspacesOccupied $(XtDisplay "-" $TOPLEVEL) $(XtWindow "-" $TOPLEVEL) $WS_LIST
           exec 9<&-
          else
           echo "DtSessionRestorePath FAILED!!"
           exit -3
         fi
       }
#
#
# MAIN
#
       XtInitialize TOPLEVEL wmProtTest Dtksh "$_at_"
       XtCreateManagedWidget DA da XmDrawingArea $TOPLEVEL
# geometry, size is irrelevant, position is not honored ?
       XtSetValues $DA height:1 width:160
       XtSetValues $DA x:+1065 y:+332
# just a title, it will be owerwritten later
       XtSetValues $TOPLEVEL title:"prova"
# standard stuff from man page
       XmInternAtom SAVE_SESSION_ATOM $(XtDisplay "-" $TOPLEVEL) "WM_SAVE_YOURSELF" False
       # If a command-line argument was supplied, then treat it as the
       # name of the session file
       if (( $# > 0))
       then
         # Restore to the state specified in the passed-in session file
         XtSetValues $TOPLEVEL mappedWhenManaged:False
         XtRealizeWidget $TOPLEVEL
         XSync $(XtDisplay "-" $TOPLEVEL) False
         RestoreSession $1
         XtSetValues $TOPLEVEL mappedWhenManaged:True
         XtPopup $TOPLEVEL GrabNone
       else
         # This is not a session restore, so come up in the default state
         XtRealizeWidget $TOPLEVEL
         XSync $(XtDisplay "-" $TOPLEVEL) False
       fi
       # Register the fact that we are interested in participating in
       # session management
       XmAddWMProtocols $TOPLEVEL $SAVE_SESSION_ATOM
       XmAddWMProtocolCallback $TOPLEVEL $SAVE_SESSION_ATOM SessionCallback
# get the current workspace
       XtScreen MYSCREEN $DA
       XRootWindowOfScreen RW $MYSCREEN
       DtWsmGetCurrentWorkspace $(XtDisplay "-" $TOPLEVEL) $RW CURRENT_WS_LIST
           XmGetAtomName NAME $(XtDisplay "-" $TOPLEVEL) $CURRENT_WS_LIST
# change wsn in n+1 (ws0 is workspace 1 etc.)
           NUMBER=${NAME##ws}
           NUMBER=$(($NUMBER+1))
       XtSetValues $TOPLEVEL title:"workspace $NUMBER"
# occupy all wsp, display and install the call back
       DtWsmOccupyAllWorkspaces $(XtDisplay "-" $TOPLEVEL) $(XtWindow "-" $TOPLEVEL)
       XSync $(XtDisplay "-" $TOPLEVEL) False
       DtWsmAddCurrentWorkspaceCallback NEW $DA MyCallBack
       XtMainLoop
Received on Fri Apr 04 2003 - 16:02:35 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:44 NZDT