How to find current desktop session?

Post here if you are a new Porteus member and you're looking for some help.
User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

How to find current desktop session?

Post#1 by brokenman » 11 Oct 2011, 03:37

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?
How do i become super user?
Wear your underpants on the outside and put on a cape.

User avatar
Hamza
Warlord
Warlord
Posts: 1908
Joined: 28 Dec 2010, 07:41
Distribution: Porteus
Location: France

Re: How to find current desktop session?

Post#2 by Hamza » 11 Oct 2011, 13:34

Very Useful, Thank you :)
NjVFQzY2Rg==

User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

Re: How to find current desktop session?

Post#3 by brokenman » 14 Oct 2011, 13:49

Nope. Not very useful at all.

Guest doesn't have access to 'pidof'. Back to the drawing board.
How do i become super user?
Wear your underpants on the outside and put on a cape.

User avatar
Hamza
Warlord
Warlord
Posts: 1908
Joined: 28 Dec 2010, 07:41
Distribution: Porteus
Location: France

Re: How to find current desktop session?

Post#4 by Hamza » 14 Oct 2011, 15:14

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 ??
NjVFQzY2Rg==

User avatar
fanthom
Moderator Team
Moderator Team
Posts: 5666
Joined: 28 Dec 2010, 02:42
Distribution: Porteus Kiosk
Location: Poland
Contact:

Re: How to find current desktop session?

Post#5 by fanthom » 14 Oct 2011, 23:24

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
Please add [Solved] to your thread title if the solution was found.

User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

Re: How to find current desktop session?

Post#6 by brokenman » 15 Oct 2011, 17:53

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'
How do i become super user?
Wear your underpants on the outside and put on a cape.

Post Reply