neopostmodern / Optimismus

GUI for MrMEEE's Bumblebee to work with Hybrid Graphics
5 stars 0 forks source link

Set the .desktop files for Ubuntu Unity #1

Open glyptostroboides opened 13 years ago

glyptostroboides commented 13 years ago

Hello all,

I have made a shell script (bumblebee-set-unity) that allow to configure the Unity desktop file from Ubuntu 11.04 with 3 options: -d : set the application as running by default with optirun (and have a context menu option on the launcher to run it without bumblebee) -o : set the application as running optionnaly with optirun (remove optirun from the desktop file when present and set the context menu option to launch with bumblebee) -r : remove all the settings in the desktop file (or remove those files when the desktop configuration file for this app has been created with bumblebee-set-unity).

Now, I am planning to make the same thinks using a gui with checkbox. And I think that I have to convert my script to python function in order to get it in the user interface you are building. Hope I will be able to help you to get this user interface working soon to configure apps that we want to be launched with optirun and set special configuration for VGL and for battery mode. Here is the script mostly using sed (this script is working but is still not perfect) fill free to improve it.

! /bin/bash

This is a test file

I hope to find a better way

This script is designed to modify desktop configuration in order to allow :

-to have a link on the launcher for selected app with this set

-to always run the selected applications

-later : to set this configuration for battery mode or not

Copy the selected .desktop file in local configuration if this configuration doesn't exist

function create_desktop_file { if [ ! -f $HOME/.local/share/applications/$1 ]; then cp /usr/share/applications/$1 ~/.local/share/applications chmod +x $HOME/.local/share/applications/$1 sed -i '1,/^Comment/ {s/^Comment.*/& (Bumblebee enabled)/}' ~/.local/share/applications/$1 fi }

Create ayatana shortcut if this configuration doesn't exist

function create_ayatana_shortcut { exec_without_optirun=$(sed -n '1,/^Exec=/ {/^Exec=optirun/! s/^Exec=(.)/\1/p ; s/^Exec=optirun (.)/\1/p }' ~/.local/share/applications/$1) grep -q "X-Ayatana-Desktop-Shortcuts" ~/.local/share/applications/$1 || sed -i '$a\X-Ayatana-Desktop-Shortcuts=BumblebeeEnable;' ~/.local/share/applications/$1 grep -q "BumblebeeDisable Shortcut Group" ~/.local/share/applications/$1 || sed -i '$a[BumblebeeDisable Shortcut Group]\nName=Launch without Bumblebee\nExec='$exec_without_optirun'\nTargetEnvironment=Unity' ~/.local/share/applications/$1 grep -q "BumblebeeEnable Shortcut Group" ~/.local/share/applications/$1 || sed -i '$a[BumblebeeEnable Shortcut Group]\nName=Launch with Bumblebee\nExec=optirun '$exec_without_optirun'\nTargetEnvironment=Unity' ~/.local/share/applications/$1 }

function default_launcher { create_desktop_file $1 create_ayatana_shortcut $1

Add optirun to first exec definition , Convert Ayatana Shortcut to BumblebeeDisable

sed -i -e '1,/^Exec=/ {/^Exec=optirun/! s/^Exec=(.)/Exec=optirun \1/}' -e '/OnlyShowIn=GNOME;Unity/! s/OnlyShowIn=GNOME/OnlyShowIn=GNOME;Unity/' -e 's/X-Ayatana-Desktop-Shortcuts=BumblebeeEnable(.)/X-Ayatana-Desktop-Shortcuts=BumblebeeDisable\1/' ~/.local/share/applications/$1

}

function optional_launcher { create_desktop_file $1 create_ayatana_shortcut $1

Remove optirun from first exec definition, Add OnlyShown if exists, Convert Ayatana Shortcut to BumblebeeEnable

sed -i -e '1,/^Exec=/ {s/^Exec=optirun (.)/Exec=\1/}' -e '/OnlyShowIn=GNOME;Unity/! s/OnlyShowIn=GNOME/OnlyShowIn=GNOME;Unity/' -e 's/X-Ayatana-Desktop-Shortcuts=BumblebeeDisable(.)/X-Ayatana-Desktop-Shortcuts=BumblebeeEnable\1/'  ~/.local/share/applications/$1

}

function remove_launcher { if [ -f $HOME/.local/share/applications/$1 ]; then grep -q " (Bumblebee enabled)" ~/.local/share/applications/$1 && rm ~/.local/share/applications/$1 && echo $HOME/.local/share/applications/$1" has been deleted" || sed -i -e 's/Exec=optirun (.)/Exec=\1/' -e '/X-Ayatana-Desktop-Shortcuts=/d' -e '/Bumblebee/,/TargetEnvironment/d' ~/.local/share/applications/$1 fi }

case $1 in -d) default_launcher $2 ;; -o) optional_launcher $2 ;; -r) remove_launcher $2 ;; *) echo "Usage : bumblebee-set-unity OPTION DESKTOP_FILE_NAME" echo "You must find a desktop file that already exists in /usr/share/application or in $HOME/.local/share/application or create one" exit 0 ;; esac

if [ -f $HOME/.local/share/applications/$2 ]; then cat $HOME/.local/share/applications/$2 fi

neopostmodern commented 13 years ago

First of all thanks a lot for your script, I now don't have the time to test it but it sounds quite useful. Don't worry too much about the python-transfer, I can easily run bash-scripts out of python, we just need to check how to pass the parameters.

neopostmodern commented 13 years ago

Tried it, great! Needed a restart though... This should definitely be included in Optimismus, right now something like this occurs to me: A list of all the Files in /usr/share/applications and behind each name should be a checkbox "run always with GPU". When clicking on the "save" button below, all desktops would get -o and the checked ones -d. How does that sound to you? Next step would be wrapping the "optirun64" command in "optimismus" command which should check for battery and battery-policy first and then pass to the actual optirun.

glyptostroboides commented 13 years ago

Hello, I'm sorry for the late answer but I was busy. I was building a maintainer script for bumblebee (if you want to try it you can test it, the configure script that it build gather all action that may be used in a rewriten configure/reconfigure script for bumblebee, i've post it in an issue in bumblebee git page). The user interface you're talking about is a good idea. I also try to document myself about python gtk but I'm not used to object oriented coding. I've just learn a bit of perl year's ago. I think the user interface must have this role : -set the default preference for optirun (etc/default/bumblebee) -select the app to run by default or optionally with optirun depending on powersave policy -inform the user that the nvidia card is in use -(eventually link to the nvidia settings box to set the nvidia card) According to what, i think we need to select apps that might be uses with optirun (and for the one a specific .desktop file is created in .local/share/application) and then set them for default or optionnally (in the desktop file created). Lists with checkboxes are as you wrote the best way for this configuration need. I hope you will manage to get this. Thanks for you're reply. Davy.

Message du 05/06/11 01:42 De : "mrssheep" A : davy.renaud@laposte.net Copie à : Objet : Re: [Optimismus] Set the .desktop files for Ubuntu Unity (#1)

Tried it, great! Needed a restart though... This should definitely be included in Optimismus, right now something like this occurs to me: A list of all the Files in /usr/share/applications and behind each name should be a checkbox "run always with GPU". When clicking on the "save" button below, all desktops would get -o and the checked ones -d. How does that sound to you? Next step would be wrapping the "optirun64" command in "optimismus" command which should check for battery and battery-policy first and then pass to the actual optirun.

Reply to this email directly or view it on GitHub: https://github.com/mrssheep/Optimismus/issues/1#comment_1303064

Une messagerie gratuite, garantie à vie et des services en plus, ça vous tente ? Je crée ma boîte mail www.laposte.net

neopostmodern commented 13 years ago

I am working on the interface, but i wanted to already report a bug in your script: I can't open the program through the "Run with bumblebee" option. The .desktop file ONLY says execute="optirun64"

Oh, that's another point we have to add. For me only optirun64 works, optirun itself fails, we have to give the option for that.

glyptostroboides commented 13 years ago

Hello,

Ok I will try to upgrade the script in order to check which optirun scripts are in the bash. But normally it must work with optirun as Bumblebee make a link for optirun32 or optirun64 to optirun depending on your configuration. Sadly, I have no time this week end to get this working, but as I see you're interested by this script so I will have a look to optimize this script. PS : I must say that I also experimented a few matter with the script : for some program there is no way to get the context menu option to appear. I will try also to manage to get my repository to work in order to maintain this script. Glyptostroboides

Message du 09/06/11 15:23 De : "mrssheep" A : davy.renaud@laposte.net Copie à : Objet : Re: [Optimismus] Set the .desktop files for Ubuntu Unity (#1)

I am working on the interface, but i wanted to already report a bug in your script: I can't open the program through the "Run with bumblebee" option. The .desktop file ONLY says execute="optirun64"

Oh, that's another point we have to add. For me only optirun64 works, optirun itself fails, we have to give the option for that.

Reply to this email directly or view it on GitHub: https://github.com/mrssheep/Optimismus/issues/1#comment_1334125

Une messagerie gratuite, garantie à vie et des services en plus, ça vous tente ? Je crée ma boîte mail www.laposte.net

glyptostroboides commented 13 years ago

Hello, I've converted the script in python and it's quiet easy as I discovered a fantastic library configparser which is really nice and clean to get and set configuration for desktop files. I'm also building an interface to select the file to configure and then set the application as optionally or by default runned with bumblebee. I will send the application when I will have finished to have a usable app. See You. PS: Please reply in order to know what you've planned from your side.

neopostmodern commented 13 years ago

Hey, I'm sorry i've been off so long -- there were just a bunch of other things going on and i couldn't keep up with this.

As the changes in Unity go on i thought that the only real purpose of the tray icon would be to turn on / off the GPU ad everything else should be inside a config-program. Thus, if you could create a GUI around your script i would update the tray icon and we'd see what else we need.

NOTE: I thought of dropping the idea of an tray icon. It's not the ideal of the new Unity. I see two options then: A normal program-icon similar to the DASH at the very bottom, right-click gives a menu feature and left-click could turn the GPU on/off. Second, integrating the GPU on/off in the dash. [I am running Ubuntu 11.10; with major Unity changes. If you don't this way wouldn't make much sense.]

glyptostroboides commented 13 years ago

I must say that you are far to know what happends since the last time i send you the script. There is no need to have a way to put on or off the nvidia card because optirun is actually doing it automatically.

And I ve build this interface for three month ago : called bumblebee-ui (you can get it on MrMEEE repository). There is also a newer version on Bumblebee-Project page and also a new rewrite with internationalization on the develop branch.

The interface consist of an indicator build with appindicator module from canonical. The icon color change if the card is on or off. But there is also an interface to configure the applications (this was the first work i made), and this is the one that will experiment significant change in few weeks (i ve reduce the size of the code of the half using better configuration files). Please get up to date by reading those codes (especially on the develop branch of Bumblebee-Project bumblebee-ui repository) and you can then help me to develop this UI to get it fully fonctionnal (a new install script would be nice first, but for this you first need to read the code).

Hope that i will hear from you soon again. Davy. Ps: sorry for my english

Message du 26/09/11 17:45 De : "mrssheep" A : "Davy Renaud" Copie à : Objet : Re: [Optimismus] Set the .desktop files for Ubuntu Unity (#1)

Hey, I'm sorry i've been off so long -- there were just a bunch of other things going on and i couldn't keep up with this.

As the changes in Unity go on i thought that the only real purpose of the tray icon would be to turn on / off the GPU ad everything else should be inside a config-program. Thus, if you could create a GUI around your script i would update the tray icon and we'd see what else we need.

NOTE: I thought of dropping the idea of an tray icon. It's not the ideal of the new Unity. I see two options then: A normal program-icon similar to the DASH at the very bottom, right-click gives a menu feature and left-click could turn the GPU on/off. Second, integrating the GPU on/off in the dash. [I am running Ubuntu 11.10; with major Unity changes. If you don't this way wouldn't make much sense.]

Reply to this email directly or view it on GitHub: https://github.com/mrssheep/Optimismus/issues/1#issuecomment-2199682

Une messagerie gratuite, garantie à vie et des services en plus, ça vous tente ? Je crée ma boîte mail www.laposte.net