Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add support for better thumbnail creation

  • Loading branch information...
commit 96f8560b4d2e577ea18822aeb575edd1a1c7522b 1 parent e6815a0
@ThomasFunk ThomasFunk authored
Showing with 152 additions and 5 deletions.
  1. +4 −0 ChangeLog
  2. +4 −2 README
  3. +139 −0 bin/fns-find-icon
  4. +5 −3 fvwm-nightshade/config
View
4 ChangeLog
@@ -1,5 +1,9 @@
History:
+09/23/2012 V 0.5.7
+- add bin/fns-find-icon and change Thumbnail/DeThumbnail functions
+ to create thumbs with better and correct mini icons
+
09/22/2012 V 0.5.6
- add governor-tool FvwmScript-CPU-Performance
- add icon for governor-tool artwork/icons/GovernorLogo.png
View
6 README
@@ -76,13 +76,15 @@ Featurelist of Fvwm Nightshade:
- Print messages for needed apps for full config functionality in
.xsessions-error
- Governor-tool FvwmScript-CPU-Performance to handle cpufreq
+- Create thumbs with mini icon and name for iconified applications
+ instead of their icon
Requirements:
=============
Required: Fvwm >= 2.6.6 (compiled with all features), python-xdg,
- xterm, conky, xscreensaver, eterm, imagemagick,
- stalonetray, wm-icons, cpufreq.
+ xterm, conky, xscreensaver, eterm, imagemagick, librsvg2-bin
+ stalonetray, wm-icons, cpufreq
Recommended: gnomes network manager, Volume Icon
View
139 bin/fns-find-icon
@@ -0,0 +1,139 @@
+#!/usr/bin/python
+#-----------------------------------------------------------------------
+# File: fns-find-icon
+# Version: 1.0.0
+# Licence: GPL 2
+#
+# Description: find the needed iconpath for thumbnail function
+# Parameters: -n name of the application
+# -i window id of the application
+# -p more search path(s). Seperated with ':'
+# -s source icon size. Default is 48
+#
+# Author: Thomas Funk <t.funk@web.de>
+# Created: 09/22/2012
+# Changed:
+#-----------------------------------------------------------------------
+
+import os, sys, string, time
+import commands
+import fnmatch
+import argparse
+
+def search_file(filename, search_path, pathsep=os.pathsep):
+ """ Given a search path, find file with requested name """
+ for path in string.split(search_path, pathsep):
+ if os.path.exists(path):
+ file_list = os.listdir(path)
+ #pattern = filename+'.*'
+ pattern = '*'+filename+'*'
+ filenames = fnmatch.filter(file_list, pattern)
+ if len(filenames) == 0:
+ continue
+ else:
+ return os.path.join(path, filenames[0])
+ return ''
+
+def get_default_theme ():
+ desktop_config = os.path.join(os.environ['FVWM_USERDIR'], '.FvwmForm-Desktop-Config')
+ out = commands.getoutput("awk '$2 ~ \"Theme\" { print $3 }' "+desktop_config)
+ if out == '':
+ return 'gnome'
+ else:
+ return out
+
+def get_menu_icon_path(app_name):
+ menu_path = os.path.join(os.environ['FVWM_USERDIR'], '.menu')
+ icon_path = commands.getoutput("grep -m1 "+app_name+" "+menu_path+" |cut -d'%' -f2")
+ return icon_path
+
+def get_dektop_icon_path(app_name):
+ search_paths = '/usr/share/applications' + os.pathsep \
+ + os.path.join(os.environ['HOME'], '.local/share/applications')
+ desktop_file_path = search_file(app_name, search_paths)
+
+ if desktop_file_path:
+ icon_path = commands.getoutput("grep '[Ii]con' "+desktop_file_path)
+ icon_path = icon_path.replace(' ', '').split('=')[1]
+ return icon_path
+ else:
+ return ''
+
+def check_convert(iconpath, iconsize):
+ if os.path.splitext(iconpath)[1] == '.svg':
+ basename = os.path.basename(iconpath)
+ new_iconpath = os.path.join(os.environ['FVWM_USERDIR']+'/temp', basename.replace('.svg', '.png'))
+ os.system('convert '+iconpath+' -resize '+iconsize+' '+new_iconpath)
+ return new_iconpath
+ else:
+ return iconpath
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description='get the iconpath of an application')
+ parser.add_argument('-n', action="store", dest="name", help='name of the application')
+ parser.add_argument('-i', action="store", dest="w_id", help='window id of the application')
+ parser.add_argument('-p', action="store", dest="extend_path", help='more search path(s). Seperated with \':\'')
+ parser.add_argument('-s', action="store", dest="icon_size", help='source icon size. Default is 48', default='48')
+
+ args = parser.parse_args()
+
+ app_name = args.name
+ window_id = args.w_id
+ extend_path = args.extend_path
+ icon_size = args.icon_size
+
+ if app_name and window_id:
+ print "Use either '-n' or '-i'. Exiting."
+ sys.exit(1)
+
+ ts = time.time()
+
+ # get the used theme in fvwm-menu-desktop-config
+ theme = get_default_theme()
+
+ i_size = icon_size+'x'+icon_size
+ search_path = '/usr/share/icons/'+theme+'/'+i_size+'/apps' + os.pathsep \
+ + '/usr/share/icons/'+theme+'/apps/'+i_size + os.pathsep \
+ + '/usr/share/icons/'+theme+'/apps/'+icon_size + os.pathsep \
+ + '/usr/share/icons/hicolor/'+i_size+'/apps' + os.pathsep \
+ + '/usr/share/pixmaps'
+
+ # extend search path if given
+ if extend_path:
+ search_path = search_path + os.pathsep + extend_path
+
+ # make app name lower if given
+ if app_name:
+ app_name = app_name.lower()
+
+ # get app name if window id is given
+ if window_id:
+ app_name = commands.getoutput("xprop -id "+window_id+" WM_CLASS |cut -d',' -f2 |cut -d'\"' -f2")
+ app_name = app_name.lower()
+ # reduce it for better finding
+ app_name = app_name.split('-')[0]
+ app_name = app_name.split('.')[0]
+
+
+ # first find app's desktop file and get the icon path
+ icon_path = get_dektop_icon_path(app_name)
+ if os.path.isabs(icon_path):
+ # if icon is a svg, convert it
+ icon_path = check_convert(icon_path, i_size)
+ print icon_path
+ else:
+ # check, if icon path is found in the search paths
+ icon_path = search_file(icon_path, search_path)
+ if os.path.isabs(icon_path):
+ print icon_path
+ else:
+ # get icon path from .menu
+ icon_path = get_menu_icon_path(app_name)
+ print icon_path
+
+ #print "duration: " + str(time.time()-ts)
+ sys.exit()
+
+
+
View
8 fvwm-nightshade/config
@@ -15,7 +15,7 @@
#
#
# Fvwm Nightshade Configuration
-InfoStoreAdd ns_version 0.5.6
+InfoStoreAdd ns_version 0.5.7
# Copyright (C) 2012
#
# Authors:
@@ -1622,10 +1622,10 @@ DestroyFunc Thumbnail
AddToFunc Thumbnail
+ I Raise
+ I ThisWindow (!Iconic) PipeRead "echo SetEnv app_name `xprop -id $[w.id] WM_CLASS |cut -d',' -f2 |cut -d'\"' -f2`"
-+ I PipeRead "echo SetEnv Icon-$[w.id] `grep -i -m1 \"$[app_name]\" ${FVWM_USERDIR}/.menu |cut -d'%' -f2`"
++ I PipeRead "echo SetEnv Icon-$[w.id] `fns-find-icon -i $[w.id]`"
+ I PipeRead 'test ! -d "${FVWM_USERDIR}/temp" && mkdir "${FVWM_USERDIR}/temp"'
+ I ThisWindow (!Shaded, Iconifiable, !Iconic) PipeRead \
- "xwd -silent -id $[w.id] | convert -scale 128x72! -frame 1x1 \
+ "sleep 0.001; xwd -silent -id $[w.id] | convert -scale 128x72! -frame 1x1 \
-mattecolor black -quality 0 xwd:- png:$[FVWM_USERDIR]/temp/icon.tmp.$[w.id].png \
&& echo WindowStyle IconOverride, Icon $[FVWM_USERDIR]/temp/icon.tmp.$[w.id].png \
|| echo Nop"
@@ -1645,7 +1645,9 @@ AddToFunc DeThumbnail
+ I TestRc (NoMatch) WindowStyle NoIconOverride, Icon
+ I Exec rm -f $[FVWM_USERDIR]/temp/icon.tmp.$[w.id].png
+ I All (Iconic, CurrentPage) PlaceAgain icon
++ I PipeRead 'if [ -O $[Icon-$[w.id]] ]; then rm -f $[Icon-$[w.id]];fi'
+ I UnsetEnv Icon-$[w.id]
++ I UnsetEnv app_name
#-----------------------------------------------------------------------
# Suspend the machine
Please sign in to comment.
Something went wrong with that request. Please try again.