Dinamic right click menus to select player/viewer

I dont know if this is “complex” enough to fit here but since it isn’t either a basic question and I did not know where to drop it I figured that I’d better put it here. So, whoever reads this first, feel free to move it anywhere that seems a better location, and in the case, forgive me it this wasn’t the right place. :slight_smile:

I had an idea today, and since I implemented it sucessfully and seems like a usefull thing to me I thought that I would better share it, in case someone has ever thought of this but did not know how to make it real. The thing is a right click menu that can be used to administer players/viewers/wharever-thing-you-want. The posibilites are so much.

First the screenie, this is my new child, a right click menu that I did. What’s so special about it? More below…

The thing works much like the rox-filer system to manage the “Open with” (or whatever it was called) menu, from where I took the idea (though I don’t like rox nor the system itself for a file manager, but I thought it would be cool for a device applet).

All the links are saved into a folder, and you can put new links in that folder, and they will automatically become availabe in the menu. The menu is generated by reading all the files in that directory, so, if you want, you can also put shell scripts or whatever you want, instead of just links (just make sure that you have execution permissions on that file).

Aditionally, if a png icon file is found it is used into the generated menu. I store the png’s for this menu under $[fvwm_iconsets]/.iconset/menu/players, you might need to modify that into the function below. For example, if you put a file called GXine into the directory, that file will be displayed in the players list, and if there is a file called GXine.png in the relevant directory then it will be used as its icon. As I said, GXine can be a proper link, but also a script. One parameter can be passed to the link, that, usually, will be a path.

For example, you can use this in a FvwmPanel button:

*FvwmTaskbar: (3x1, Padding 0 0, \
    Icon panel/cdwriter_mount.png, ActiveIcon panel/cdwriter_mount-bright.png, PressIcon panel/cdwriter_mount-bright-pushed.png, \
    Action (Mouse 1) `Exec $[filer] /mnt/cdrw`, \
    Action (Mouse 2) `Exec urxvt -e mc /mnt/cdrw $HOME`, \
    Action (Mouse 3) `PlayersBrowser /mnt/dvd`)

PlayersBrowser is a function (I will post below, don’t worry), and we pass to the function the parameter “/mnt/dvd”, we can do a lot of things with that into a menu.

I for example have these players for now:

lrwxrwxrwx  1 i92guboj users 15 nov 22 22:35 gMPlayer.png -> ../kaffeine.png
lrwxrwxrwx  1 i92guboj users 13 nov 22 22:33 GQview.png -> ../viewer.png
lrwxrwxrwx  1 i92guboj users 15 nov 22 22:35 XMMS.png -> ../kaffeine.png

GQview, for example, is just a link, while gMPlayer is a script, that holds this:

gmplayer `mount | grep $1 | sed -e 's/ .*//'`

Wich is a way to obtain the device out of the mount point and then play it (in this case a dvd player :) ). As I already said, the posibilities are soooo much. You could always do a static menu for that, though, but this is prettier, and, as you can see you have also a nice option to open the links folder in rox, so you can use the same system that you use in rox to add new links and icons. An advise: you can use symlinks to the icons in your menus, so if you change them (via a theme or manually, does not matter) then all the icons in this menu will also be updated).

And finally, the function:

SetEnv fvwm_iconsets $[FVWM_USER]/iconsets
SetEnv fvwm_players $[FVWM_USER]/players

# You need to addapt the path for the icons, I store them into
# $[fvwm_iconsets]/.iconset/menu/players

DestroyFunc PlayersBrowser
AddToFunc PlayersBrowser
+ I DestroyMenu PlayersBrowser
+ I AddToMenu PlayersBrowser
+ I + DynamicPopDownAction DestroyMenu PlayersBrowser
+ I PipeRead 'cd ${fvwm_players}; for i in *; \
	do echo "+ \"$i\%$[fvwm_iconsets]/.iconset/menu/players/$i.png%\" Exec $[fvwm_players]/$i $0"; done'
+ I + "Edit players list%$[fvwm_iconsets]/.iconset/menu/settings.png%" Exec rox $[fvwm_players]
+ I Popup PlayersBrowser Rectangle +$[pointer.x]+$[pointer.y] +0 0m

I plan to make it a bit nicer, to cut out the path out of the menu should not be too hard. Hope you like it. For any doubt, improvement or flame here I am. Beers are also wellcome.

EDIT: Ugly paths removed from the menu. Looking on how to remove the .link extension…
EDIT: Done. And added another option to open the icons folder.

  • Cheers. :slight_smile: