Page 1 of 1

How to find current desktop session?

Posted: 11 Oct 2011, 03:37
by brokenman
This would be nice to know. I have struggled with it for some time now and would like to find a native Porteus way to find the current desktop session. Once discovered we could add this to the porteus-livedbg file for reference.

The best i could come up with was to search the environment variables 'env' for the global $DESKTOP_SESSION which gives a nice answer if you are running as guest. If you are running as root (which alot of apps require) then $DESKTOP_SESSION gives you nothing. I feel the best way would be to check out the running process and through a process of elimination, work out what desktop your are using.

Anybody have some ideas? Keep in mind a user could have LXDE and KDE moduels loaded, but only using one desktop. They could also be logging out and switching to another desktop. The ideal solution would cover all scenarios.

Posted after 48 minutes 52 seconds:
Ok after busting my nut for a while here is what i came up with.

Code: Select all

# Get dekstop session

[ `pidof ksmserver` -a "`uname -m|grep i*86`" ] && dsession=kde3
[ `pidof ksmserver` -a "`uname -m|grep 64`" ] && dsession=kde4
[ `pidof lxsession` ] && dsession=lxde

case $dsession in
kde3 )
  if [ -f /usr/bin/konqueror ]; then
    ln -s /usr/bin/konqueror /tmp/.wmanager
      else
    if [ /usr/bin/pcmanfm ]; then
      ln -s /usr/bin/pcmanfm /tmp/.wmanager
    fi
  fi
  ;;
kde4 )
ln -s /usr/bin/dolphin  /tmp/.wmanager
;;
lxde )
ln -s /usr/bin/pcmanfm  /tmp/.wmanager 
  ;;
esac
The above script should generate a symlink in /tmp/.wmanager that you can use to start your window manager. Anybody got anything more elegant?

Re: How to find current desktop session?

Posted: 11 Oct 2011, 13:34
by Hamza
Very Useful, Thank you :)

Re: How to find current desktop session?

Posted: 14 Oct 2011, 13:49
by brokenman
Nope. Not very useful at all.

Guest doesn't have access to 'pidof'. Back to the drawing board.

Re: How to find current desktop session?

Posted: 14 Oct 2011, 15:14
by Hamza
We can define a global variable at boot-up to find out the desktop or we can write a script to use your method and set a variable as $MYDESKTOP ??

Re: How to find current desktop session?

Posted: 14 Oct 2011, 23:24
by fanthom
this code should cover all scenarios:
a) single desktop/multiple desktops (switch user function opens second X instance on vt08)
b) GUI started from init 4, directly called by lxdm/kdm or startx

Code: Select all

#!/bin/sh

cat > /tmp/env$$ << "EOF"
lxde=`ps aux | sed '/ DISPLAY /,$ !d' | sed '1,/X / !d' | grep -v grep | grep -c /usr/bin/lxsession`
kde=`ps aux | sed '/ DISPLAY /,$ !d' | sed '1,/X / !d' | grep -v grep | grep -c /usr/bin/startkde`
[ "$lxde" = 1 ] && echo "running LXDE"
[ "$kde" = 1 ] && echo "running KDE"
EOF

sed -i /tmp/env$$ -e s/DISPLAY/$DISPLAY/g
. /tmp/env$$ && rm /tmp/env$$
i'm not happy with /tmp/env$$ workaround but couldnt force sed to work with $DESKTOP variable directly:

Code: Select all

sed '/$DISPLAY/,$ !d'
Cheers

EDIT:
updated to simpler version

Re: How to find current desktop session?

Posted: 15 Oct 2011, 17:53
by brokenman
Smashing! I was going down the path of 'ps' also ... i think i like your code better though. Thanks very much.

Try this:

Code: Select all

sed '/ '$DISPLAY' /,$ !d'