Dynamically changing window icons and mouseover [solved]

[color=blue][size=75]Edit: Dynamically changing window icons is solvable with FvwmEvent (see cstorm’s and my posts below for two methods). Mouseover highlight seems impossible … and I’d like to find out more :slight_smile:[/size][/color]

Hi All,

I have two n00b questions :slight_smile:

I usually use only console based applications. I start Vim, mutt, man, w3m etc from an xterm. Thus in my usual X session, I have about 10 xterms open, and a few firefox windows (sometimes an xdvi too). I’d like to change the icon on my xterm to reflect the application, and wondering how I can do that.

The Style vim* miniicon vim.png command will change the icon of any new window with title “Vim …” . However starting vim from an xterm window will have no effect. If the icon was xterm.png, then it still stays xterm.png even if the title of the window has changed to “Vim …”.

I guess I’d like to detect title changes, and install my favourite icon then :slight_smile:. Is this easy? Is this even possible?

Finally, I have another n00b question: Can I get the window buttons to “highlight” when the mouse moves over them? Most other WM’s have this feature. Did I just miss a config option, or is this not at all possible?

Thanks in advance,

GI

From what I understand, you could use xterm -name mutt etc. to get the icon right. I think it isn’t possible to get highlights on button “mouse-overs”.

Unfortunately that doesn’t help me. xterm -e mutt will have the correct icon. But I’d like to quit mutt, and then startup a vim in the same xterm, and have the icon reflect it …

Just wistfull thinking. I’ll see if I can dig something up. And it’s too bad about the mouse over things :frowning:

Thanks,

GI

not hugely satisfactory, perhaps, but you could write alias/scripts/shell funcs for your command line apps and use xprop or similar to change the title on the way in and the way back out again. Or xterm control codes as well

I use the xterm control codes to change the window title. I guess instead of only a control code to change the title, I can use FvwmCommand to set the desired icon too. This has the added irritation of slowing down my user of the shell (cause every time I type something, I’ll have to call some perl script to match the name with my icon style file etc)

I have been reading the FvwmEvent man page recently. I can’t seem to understand the events there. Maybe someone can tell me where to look. Is there a “title change” event? The man page doesn’t list all the events there … argh. Any help would be greatly appriciated,

Thanks agian,

GI

The events are documented on the fvwm module devleopers page. There’s a window_name/M_WINDOW_NAME event that should do what you want. Set the PassID option in FvwmEvent, and you’ll be set, I reckon

i wrote this to accomplish the changing icon according to the xterm title:

SetEnv fvwm_state_termtitle      4
DestroyFunc ChangeWindowNameHandler
AddToFunc ChangeWindowNameHandler
# check if XTerm, else break
+ I Current (!"XTerm") Nop
+ I TestRc (Match) Break
# handle mc
+ I Current ("mc*", "XTerm", !State $[fvwm_state_termtitle]) WindowStyle Icon kfm.png, MiniIcon kfm.png, IconOverride, NoIcon
+ I Current ("mc*", "XTerm", !State $[fvwm_state_termtitle]) State $[fvwm_state_termtitle] True
+ I TestRc (Match) Break
+ I Current ("mc*", "XTerm", State $[fvwm_state_termtitle]) Break

[... repeat the above 4 lines for every termtitle you want to match]

# reset Xterm icon to standard
+ I Current ("XTerm") WindowStyle Icon konsole2.png, MiniIcon konsole2.png, IconOverride, NoIcon
+ I Current ("XTerm") State $[fvwm_state_termtitle] False
DestroyModuleConfig FvwmEvent: *
*FvwmEvent: Cmd Function
*FvwmEvent: window_name ChangeWindowNameHandler
[... some other listeners]
*FvwmEvent: PassID

[size=75](some typos & copy/paste errors fixed)[/size]
[size=75](comments & one very important line added :wink: )[/size]

Ooh. WINDOW_NAME. Here I am grepping the source tree for “WINDOW_TITLE”. No wonder :blush:

Thanks for your script cstorm. I will probably modify it a little. since for instance vim changes the window title often. Thus setting the window icon to vim.png every time the title is changed causes a flicker (and a redraw). A simple bash script should avoid this:) Will post it when I’m done, in case anyone else is interested in something similar :slight_smile:

Thanks again,

GI

So… there isn’t any Hover/MouseOver style option?

Well, I guess you could achieve such an effect, but my guess is that it would be TRICKY(!) :wink:
Say, FvwmEvent combined with pointer.x/y -variables combined with … I dunno, sounds impossible.

What would you expect it to do if it existed?

no problem. feel free to improve it. i’m interested in an improved version :wink:

flickering also happens in mc if you change the pane. therefore the State is used. if the window is mc an has already the icon set (State true), then abort and don’t set the icon, which avoids flickering. if i quit mc and the termtitle becomes, say “Konsole”, the last 2 actions are taken and the term-icon is set to its original icon.
advantage: no flickering
disadvantage: while say mc is running, the icon remains mc, even if another prog is launched from within mc, say vim, in which case the icon should change to vim-icon

obviously i’m not able to correctly paste my code into my browser :confused:
i forgot one important line. for a full working one, see my old post.

OK, cstorm and anyone else interested. Here’s what I did to dynamically set the window icon –

First add the following to your ~/.fvwm/config:

# Dynamically set window Titles *FvwmEvent: Cmd *FvwmEvent: window_name "Exec ~/.fvwm/seticon.sh $[w.id] $[w.class] $[w.miniiconfile] '$[w.name]'"
Now make a script called seticon.sh in your ~/.fvwm directory. (Don’t forget to chmod a+x ~/.fvwm/seticon.sh). Put the following in the script:

[code]#! /bin/bash

seticon.sh win-id class iconfile title

seticon () {
# Don’t change the icon unnecessarily
if [[ $iconfile != $1 ]]; then
FvwmCommand “WindowId $winid WindowStyle MiniIcon $1”
fi
exit
}

winid=$1
class=$2
iconfile=${3##*/}
progname=${4%% }
progname=${progname##
/}

Iconfile now contains the name of the icon (with the path stripped), and

progname contains the name of the program (with path and arguments

stripped).

Don’t change the icon on root consoles, or anything other than xterm

if [[ $iconfile == “tux.png” || $class != “XTerm” ]]; then exit; fi

case $progname in
vim) seticon vim.png;;
mutt) seticon mutt.png;;
man) seticon man.png;;
w3m) seticon elinks.png;;
# su) seticon tux.png;;
# add other icons here. for example

*)		seticon xterm.png;;

esac

vim: set ft=sh:[/code]

Finally you might want to add the line

+ I Module FvwmEvent

somewhere to your StartFunction.

The advantage of this script is that it avoids changing the icon when not necessary (avoids the fliker). Also if you launch a vim from mutt, say then the icon is changed :slight_smile: Further the script can easily be modified so that you can set the icon depending on the file you’re editing in Vim say :slight_smile:.

HTH, and thanks for the help all.

GI

[color=blue][size=75]Edit: In keeping with cstorm’s example, I made a few copy paste errors. I fixed them.[/size][/color]

I would like to thank you guys for this excellent idea!
(I didn’t get gi1242’s version to work, but cstorm’s works almost flawlessly)

And to contribute something to this thread, I have something for all you zsh-users out there. :slight_smile:

.zshrc:
autoload -U promptinit
autoload -U compinit
promptinit
compinit
case $TERM in
        xterm*)
        precmd() { print -Pn "\e]0;%~\a" }
        preexec () { print -Pn "\e]0;$1\a" }
        ;;
esac

With that, you will get the running process in the title of xterm, or, if no running process, the current working path in the title.
So you can basically have different icons for home directory, editor, filemanager, you name it!

So I found out that the above methods sometime cause some trouble. The problem is that in older versions of Fvwm (before 2.5.17), the $[w.name] variable is not quoted. Thus when you pass it to a shell command via Exec, it could mess things up, even if you quote it manually.

In Fvwm-2.5.18, the $[w.name] variable IS quoted with SINGLE quotes. Further, any containing single quote is backslashed. While this soulds just dandy, it doesn’t work with bash! Bash forbids single quoted strings to contain a single quote, wether backslashed or not.

Enter FvwmPerl: Perl doesn’t mind single quoted strings that contain a backslashed single quote. Plus perl’s regexps are far better for matching window titles than simple shell style glob patterns. As an added bonus, it performs better :slight_smile:.

The link http://materm.sourceforge.net/wiki/Tips/FvwmMiniicon tells you how to do this using FvwmPerl.

The problem lies much deeper than this. Please, search the fvwm-workers mailing list from a few months ago to see why.

Well, yes, of course. Nothing inside of single quotes is ever interpolated.

Oh, BTW, you should look at ‘visible_name’ event to FvwmEvent, as has been so often discussed on these forums of late. Seems we’re getting a spate of them.

– Thomas Adam