SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2014-03-30 14:59:52

ohnonot
...again
Registered: 2012-05-22
Posts: 1,526
Website

Change Your Application's (ugly) Taskbar Icon Programmatically!

Hello,
every now and then there's an application that will not use icons from your icon theme, or even (oh horrors of horrors!) no icon at all, so all you see is some default generic app icon in your taskbar, window title etc.
For example xterm, urxvt, sublime text... It's a small but constant annoyance.
You probably heard of xseticon, but it fails when you don't know the exact name or window id of the applications window.
in other words, you can't do something like "xseticon $(pidof some_app)".

just now i hacked a script that is doing exactly that!

Warning: The script works on the assumption that xseticon will do no harm when it tries to assign icons to windows that are not visible.
[usually every application opens more than one window, even if it looks as one to the user. some of them aren't even visible, even though the window manager still treats them as windows.]

anyhow, here's the script:

#!/bin/bash
##################################################
#
# Usage:
#	seticon <command> <path/to/icon.png>
#
#	Input:
#		$1: application's process name/command
#	Output:
#	 	$2: icon path
#
# adapted from this:
# http://blog.chewearn.com/2010/01/18/find-window-id-of-a-process-id-in-bash-script/
# (i had to change this: xwininfo -root -children -tree -int)

APP="$1"
PID=$(pidof "$APP" | awk '{print $1}')
#~ if you write a wrapper around this that has the same name as the application it's 
#~ assigning an icon to, you have to {print $2} here!

echo "APP is now" "$APP"
echo "PID is now" $PID

# Loop windows with application's executable name
while read WID; do

	WID=`echo $WID | awk '{print $1}'`
	echo "WID is now" $WID

	#~ # hex to dec
	#~ WID=$((WID))
	#~ echo "Line 31: WID is now " $WID

	# Check window's PID is matching application's PID
	if [ `xprop -id $WID _NET_WM_PID | awk '{print $3}'` -eq $PID ]
	then
		echo "Yes it equals! Window" $WID "belongs to" "$APP"
		
		#~ hack: simply set icons for all matching windows, visible or not.
		xseticon -id "$WID" "$2"
		echo "assigned icon" "$2" "to WINID" "$WID"
	
		#~ # Check is actual visible window
		#~ if [ "`xwininfo -id $WID | grep 'IsViewable'`" != '' ] ; then
			#~ echo "this should be the final result: " $WID
			#~ return 0
		#~ fi
	fi

done < <( xwininfo -root -children -tree -int 2>/dev/null | grep -i "$APP" )

So now you can write a wrapper to start the offending application, example for sublime text:

#!/bin/bash

icon="$HOME/.icons/subl.png"

/usr/bin/subl "$@" &
sleep 1
seticon "sublime_text" "$icon"

this is a good example for the kind of problems you might experience: /usr/bin/subl is only a wrapper that starts /opt/bin/sublime_text, so that is what seticon has to look for.
the script is not very flexible, and i have not tested all scenarios nor have i included user input safety.
but only xseticon actively does anything here, and i consider it harmless. hopefully i'm right.
Please let us know if something doesn't work as expected.
known limitations: xseticon works with .png only.

PS admin: I searched "xseticon" before posting and got no results. is the search function broken? i'm 99% sure xseticon has been discussed before.

Last edited by ohnonot (2014-03-30 19:55:25)

Offline

Be excellent to each other!

#2 2014-03-30 20:33:29

porkpiehat
#! Die Hard
Registered: 2012-10-02
Posts: 823

Re: Change Your Application's (ugly) Taskbar Icon Programmatically!

ohnonot wrote:

PS admin: I searched "xseticon" before posting and got no results. is the search function broken? i'm 99% sure xseticon has been discussed before.

http://crunchbang.org/forums/viewtopic.php?id=22741


# echo 0.0.0.0 crunchbang.org >> /etc/hosts

Offline

#3 2014-10-28 18:07:27

ohnonot
...again
Registered: 2012-05-22
Posts: 1,526
Website

Re: Change Your Application's (ugly) Taskbar Icon Programmatically!

when i wrote this, i missed the fact that xseticon is not in the repos.
fortunately its maker has created debian packages, to be found here:
http://packages.leonerd.org.uk/pool/main/x/xseticon/
a quick test shows that it works ok.

Last edited by ohnonot (2014-10-28 18:08:40)

Offline

#4 2014-10-28 18:10:37

damo
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 3,706

Re: Change Your Application's (ugly) Taskbar Icon Programmatically!

^ I didn't find that link. Everything I found pointed to a source archive which needed to be compiled. Even the website page for xseticon just has

Download source in tarball from:
xseticon-0.1+bzr13.tar.gz

Last edited by damo (2014-10-28 18:18:42)


Artwork at deviantArt;  Iceweasel Personas;  SLiM #! Themes;  Openbox themes

Offline

#5 2014-10-29 04:01:01

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,988
Website

Re: Change Your Application's (ugly) Taskbar Icon Programmatically!

Ohnonot thank you for this, it scratches an itch I'd been leaving undealtwith for a while.

The offender for me was dillo, the minimal browser. Even after putting icons in all the approved freedesktop places I got the default icon only. xseticon was the fix.  cool

In my particular case the wrapper could be reduced to this:

#!/bin/bash
icon='/usr/share/pixmaps/dillo.png'
(sleep 0.1;xseticon -id $(xdotool search --name dillo)  "$icon") &
/usr/local/bin/dillo

But it only works for a single instance. neutral


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#6 2014-10-29 04:27:58

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,988
Website

Re: Change Your Application's (ugly) Taskbar Icon Programmatically!

PS Unfortunately dillo doesn't disclose its PID to these x-manipulator utilities which seemed to break seticon. sad

Still, the combination of xdotool and xseticon alone seems to do it for multiple windows, with dillo at least:

#!/bin/bash
icon='/usr/share/pixmaps/dillo.png'
(sleep 0.3;for i in $(xdotool search --name dillo);do xseticon -id $i "$icon";done) &
exec /usr/local/bin/dillo "$@"

Maybe there would be issues in other cases?

Last edited by johnraff (2014-10-30 02:42:04)


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#7 2014-10-29 19:26:56

ohnonot
...again
Registered: 2012-05-22
Posts: 1,526
Website

Re: Change Your Application's (ugly) Taskbar Icon Programmatically!

i haven't used this script in a while (but i guess it still works).

but recently i discovered that fbpanel has an

fbpanel wrote:

'icons' plugin lets you customize window icons.
these changes apply to entire desktop

so the functionality is the same as with my script - and i'll say it again, it changes the icon of an app not only in the panel, but also on window decorations. it seems to accept only 2 identifiers: ClassName and AppName. let me know if there's more.
fbpanel is truly lightweight, gtk themeable but also customizable. like an lxpanel/tint2 hybrid. only the pager (desktop switcher) is rather rudimentary.

Offline

#8 2014-10-30 02:39:14

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,988
Website

Re: Change Your Application's (ugly) Taskbar Icon Programmatically!

Hi ohnonot, I've been playing around with this a bit, and googling a bit. Can I make a couple of comments/suggestions? I've only used this with dillo so far, so forgive me if there are major snags in other situations.

1) Getting the PID of the app. The wrapper script has it in $!, which is 100% reliable while $(pidof "$APP" | awk '{print $1}') may not be in all cases. The wrapper could pass the PID to seticon as an argument.

icon="$HOME/.icons/subl.png"

/usr/bin/subl "$@" &
PID=$1
sleep 1
seticon "sublime_text" "$icon" "$PID"

2) This is incompatible with 1) unfortunately, but if you keep the main app at the end of the script, and fork off the icon-setting in a subshell with sleep, then you can launch command with exec. This means fewer processes remain, and in particular the wrapper script with the same name as command disappears, simplifying searching for ids.

icon="$HOME/.icons/subl.png"

(sleep 1;seticon "sublime_text" "$icon") &
exec /usr/bin/subl "$@"

3) After looking here I checked xdotool and it will give you a list of window ids matching a given name. You can use xseticon on each of those with a simple for loop, which seems to accomplish the same thing as the seticon script with rather less code. Timewise, as someone on that page mentioned, it may actually be slower but with a sleep of 1s, an extra 50ms might not matter too much.

for i in $(xdotool search --name $name);do xseticon -id $i "$icon";done

4) Unfortunately, not all apps report their PID to the window manager, as I found with dillo. (That was why seticon broke on line 35.) It might be better to give up on checking PIDs altogether, and just use names or classes to pin the app windows down?


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo