Author Topic: Why is it so hard to write a gui script for multiple DE?  (Read 2966 times)

Offline MBantz

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 1317
Why is it so hard to write a gui script for multiple DE?
« on: December 03, 2010, 05:53:13 AM »
I'm bringing this up again because often it is needed to ask for root access in a script. Now, almost all DE's have their own su - kdesu, gtksu and the way of logging a user out is different too,

how is it possible to determine what DE is currently -running- and then call the necessary su and logoff commands?

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Why is it so hard to write a gui script for multiple DE?
« Reply #1 on: December 03, 2010, 07:24:47 AM »
It is possible to script a check for which is used.

From ezswitch:
Quote
# Check if gksu exists, if not, use kdesu.
#=================================================
GUI_SU=`which gksu 2>/dev/null` || GUI_SU=`which kdesu 2>/dev/null`


Offline MBantz

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 1317
Re: Why is it so hard to write a gui script for multiple DE?
« Reply #2 on: December 04, 2010, 05:02:42 AM »
It is possible to script a check for which is used.

From ezswitch:
Quote
# Check if gksu exists, if not, use kdesu.
#=================================================
GUI_SU=`which gksu 2>/dev/null` || GUI_SU=`which kdesu 2>/dev/null`



Hi Neal, thanks :-)

but this merely examines what su types are available - not if you are -running- the gnome or kde desktop. I think that the gksu can be run in kde without problems, but the more difficult issue is for instance when logging out - then it is important to know what de is actually running to give the proper logout command,

if there is a generic command that gives a graphical su and a command to logout all de's this would also work for now - but I wonder a bit why it's so difficult to determine what de is actually running

We could implement a weasel file that simply contain the name of the running de. This means each de when starting up is simply doing a echo "KDE" > /etc/weasel or perhaps just export ACTIVE_DE=KDE for the KDE desktop

Offline Village Idiot

  • Hero Member
  • *****
  • Posts: 2345
  • Have A Nice Day.
Re: Why is it so hard to write a gui script for multiple DE?
« Reply #3 on: December 04, 2010, 08:38:21 AM »
+1

I've always reckoned that. Why can't we have a simple desktop "I'm here" file. Make life simpler.

However, it is trivial to make a standard script to detect desktops and what is installed by querying apt.

You could find out if Zenity is installed or something other. But I feel there should be agreement on what a script dev should expect by running a script in any PClinuxOS flavor.

Perhaps it's time for a PCLinuxOSwhatsinstalled lib and/or file so a program would know what's going on with the system at that moment. What do other distros do? Is there something we could steal er I mean borrow?

Who'd of thought 5 years ago this would be an issue?  :)

 


$ fortune
No Microsoft products were used in any way for the creation of this message.
If you are using a Microsoft product to view it, BEWARE! - I'm not
responsible for any harm you might encounter as a result.

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Why is it so hard to write a gui script for multiple DE?
« Reply #4 on: December 04, 2010, 10:01:15 AM »
Martin,
I hadn't meant that that was the only way to script it. Sorry I wasn't more clear on that.

This would be a more complete script:
Quote
# check for kdesu or gksu and setup/or run XUFOO
#=================================================
if [ ! -e $XUFOO ];then
  if [ -r /usr/bin/gksu ]; then WMSUDO=/usr/bin/gksu; fi
  if [ -r /usr/lib/kde4/libexec/kdesu ]; then WMSUDO=/usr/lib/kde4/libexec/kdesu; fi
  # setup XUFOO
  echo "#"'!/bin/bash' > $XUFOO
  if [ "$UID" != "0" ]; then echo $WMSUDO foo-me >> $XUFOO; else echo foo-me >> $XUFOO; fi
  chmod a+x $XUFOO
  $XUFOO &
  exit 0
fi

Note the check for gksu or kdesu establishes whether the environment is kde or another.

As an example, a check to discover whether LXDE is the DE and therefore to use lxde-logout would be something like:
Quote
if [ ! -e $XUFOO ];then
  if [ -r /usr/bin/lxde-logout ]; then WMSUDO=/usr/bin/lxde-logout; fi


To write a script to discover whether a DE is installed, you would need to run a simple script that would check for something specific to that DE. As in the above example, you discover the the DE is LXDE and follow that with the command to use lxde-logout.

Remember, these are only examples. You can use the basic structure to create your own checks.



Offline MBantz

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 1317
Re: Why is it so hard to write a gui script for multiple DE?
« Reply #5 on: December 04, 2010, 11:50:27 AM »
Hi Neal,

I'm not quite convinced, what if you have both gnome and kde installed - you will have both su systems, gksu and kdesu, available.

I don't think the check determines which DE is actually running at the time the script is executed - if you have gnome and kde installed, both checks will be true and WMSUDO will in this script always end up being kdesu

Online muungwana

  • Hero Member
  • *****
  • Posts: 6253
Re: Why is it so hard to write a gui script for multiple DE?
« Reply #6 on: December 04, 2010, 12:20:37 PM »
open the terminal and type "cat ~/.desktop", what are you getting?

I am logged in using kde and it returned "DESKTOP=KDE", i assume it will return a different result on different desktops, can anybody confirm?

while on the terminal, type "env" and all defined global variables will be displayed, i am sure you can check for one or two to determine what desktop environment a user is using
« Last Edit: December 04, 2010, 12:28:03 PM by muungwana »
.. 3 things are certain in life : death, taxes and software bloat ..
.. tell me something i don't know, something i can use as i struggle to reason with the world around me ..

Offline MBantz

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 1317
Re: Why is it so hard to write a gui script for multiple DE?
« Reply #7 on: December 04, 2010, 12:36:14 PM »
Sounds interesting!

I get:

[mbz@localhost ~]$ cat ~/.desktop
cat: /home/mbz/.desktop: Ingen sådan fil eller filkatalog
[mbz@localhost ~]$

translates to "No such file or filecatalogue" - this is Zen




Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6852
  • MLU
Re: Why is it so hard to write a gui script for multiple DE?
« Reply #8 on: December 04, 2010, 12:36:24 PM »
Code: [Select]
[user@localhost ~]$ cat ~/.desktop
cat: /home/user/.desktop: No such file or directory

Using KDE

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Why is it so hard to write a gui script for multiple DE?
« Reply #9 on: December 04, 2010, 01:01:34 PM »
Martin,
Those examples I posted were only intended as examples;they were intended to be templates for creating a script, not the script for your use.

Another possible use of the if / then --
Quote
if [ -r ~/.desktop=lxde ]; then WM*=/usr/bin/lxde-logout; fi

I have not tested this script. You will possibly need to tweak it to get it to work.


Offline MBantz

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 1317
Re: Why is it so hard to write a gui script for multiple DE?
« Reply #10 on: December 04, 2010, 01:14:44 PM »
Neal, I fully understand.

It is the methods I'm interested in - your scripts show one way of implementing it - but I'm not sure this is the solution. When we have found a means of determining the flavor of the -running- DE I throw some new scripts on the table,

cheers,
MBantz

Offline pinoc

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2848
    • other projects...
Re: Why is it so hard to write a gui script for multiple DE?
« Reply #11 on: December 04, 2010, 01:38:40 PM »
Hi Martin,

you could get the running WM session from the terminal output of the command: wmctrl -m. Below the output from my multiDE install:

Afterstep:
==============
Name: AfterStep
Class: N/A
PID: N/A
Window manager's "showing the desktop" mode: N/A

Enlightenment:
==============
Name: Enlightenment
Class: N/A
PID: 5843
Window manager's "showing the desktop" mode: N/A

FluxBox:
===============
Name: Fluxbox
Class: N/A
PID: N/A
Window manager's "showing the desktop" mode: N/A

Gnome:
===========
Name: Metacity
Class: N/A
PID: N/A
Window manager's "showing the desktop" mode: N/A

ICEWM:
==============
Name: IceWM 1.3.7pre2 (Linux 2.6.33.6-pclos1.bfs/i686)
Class: N/A
PID: 6588
Window manager's "showing the desktop" mode: N/A

KDE:
=======
Name: KWin
Class: kwin
PID: 8514
Window manager's "showing the desktop" mode: OFF

LXDE:
===========
Name: Openbox
Class:
PID: N/A
Window manager's "showing the desktop" mode: OFF

OpenBox:
=============
Name: Openbox
Class:
PID: N/A
Window manager's "showing the desktop" mode: OFF

PekWM:
=========
Name: pekwm
Class:
PID: N/A
Window manager's "showing the desktop" mode: N/A

XFCE:
==============
Name: Xfwm4
Class: xfwm4
PID: 5390
Window manager's "showing the desktop" mode: N/A

so you could do something like:
Code: [Select]
WM=`wmctrl -m|grep Name|awk '{print$2}'` This should work fine for all DEs mentioned above besides LXDE and OpenBox. I don't know much about LXDE or OpenBox but probably Neal (Melodie) knows what is running in LXDE (OpenBox) exclusively, so one should do an additional test for that application to distinguish between LXDE and OpenBox.
hope that helps, all the best,
-pinoc

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Why is it so hard to write a gui script for multiple DE?
« Reply #12 on: December 04, 2010, 01:52:47 PM »
I think I see what you mean, Martin.

Adding to pinoc's info, using the command wmctrl -m in LXDE returns --
Quote
Name: Openbox
Class:
PID: N/A
Window manager's "showing the desktop" mode: OFF

As you can see, there are some differences.

I do not have an openbox install at the moment so cannot test it now. It may be similar, but I do not know how similar.

Offline pinoc

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2848
    • other projects...
Re: Why is it so hard to write a gui script for multiple DE?
« Reply #13 on: December 04, 2010, 02:03:16 PM »
I think I see what you mean, Martin.

Adding to pinoc's info, using the command wmctrl -m in LXDE returns --
Quote
Name: Openbox
Class:
PID: N/A
Window manager's "showing the desktop" mode: OFF

As you can see, there are some differences.

I do not have an openbox install at the moment so cannot test it now. It may be similar, but I do not know how similar.


Neal, what are the differences you refer to?  From my previous post you can see the output from running the command on a LXDE and a OpenBox session, they are identical.  Is there something running in LXDE which is exclusive to LXDE, so one could test for this to distinguish to OpenBox?
best,
-p.

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Why is it so hard to write a gui script for multiple DE?
« Reply #14 on: December 04, 2010, 02:20:52 PM »
pinoc,
I should have said "some slight differences," I think. The differences I was referring to are those in the other DEs.

In LXDE, lxde-logout is available. (Not used in Melodie's openbox, I think.) I posted it previously, but Martin appears to have had an objection to it. So perhaps lxsession? Hmm... ~/.config/lxsession/LXDE/desktop.conf shows window_manager=openbox-lxde. So perhaps a test for openbox-lxde?