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
#! Die Hard
Registered: 2012-05-22
Posts: 974
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

Help fund CrunchBang, donate to the project!

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

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

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


Sarcasm is often an appropriate response to stupidity.

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