Browse Source

Use SVG icons for JWM menus

Apparently JWM supports SVG icons, so use them when they are available.
Also provide a --no-svg command line option to disable their use.

Fixes #13
pull/10/merge
George Vlahavas 7 years ago
parent
commit
7bde503afc
  1. 34
      src/xdgmenumaker

34
src/xdgmenumaker

@ -32,6 +32,7 @@ import gtk
seticon = False seticon = False
iconsize = 16 iconsize = 16
nosvg = False
desktop = False desktop = False
submenu = True submenu = True
pekwmdynamic = False pekwmdynamic = False
@ -167,6 +168,7 @@ def main(argv):
global desktop global desktop
global seticon global seticon
global iconsize global iconsize
global nosvg
global submenu global submenu
global pekwmdynamic global pekwmdynamic
global twmtitles global twmtitles
@ -177,6 +179,7 @@ def main(argv):
"pekwm-dynamic", "pekwm-dynamic",
"twm-titles", "twm-titles",
"max-icon-size", "max-icon-size",
"no-svg",
"size=", "size=",
"format="]) "format="])
except getopt.GetoptError: except getopt.GetoptError:
@ -214,6 +217,8 @@ def main(argv):
except ImportError: except ImportError:
usage() usage()
sys.exit('ERROR: --max-icon-size requires Pillow') sys.exit('ERROR: --max-icon-size requires Pillow')
elif opt == "--no-svg":
nosvg = True
elif opt in ("-f", "--format"): elif opt in ("-f", "--format"):
desktop = arg desktop = arg
if not desktop: if not desktop:
@ -252,6 +257,7 @@ def usage():
print(' fvwm, twm, icewm, jwm, windowmaker and pekwm') print(' fvwm, twm, icewm, jwm, windowmaker and pekwm')
print(' -i, --icons enable support for icons in the') print(' -i, --icons enable support for icons in the')
print(' menus. Does not work with windowmaker') print(' menus. Does not work with windowmaker')
print(' --no-svg Do not use SVG icons even for WMs that support it')
print(' -s, --size preferred icon size in pixels (default: 16)') print(' -s, --size preferred icon size in pixels (default: 16)')
print(' -n, --no-submenu do not create a submenu. Does not work with') print(' -n, --no-submenu do not create a submenu. Does not work with')
print(' windowmaker') print(' windowmaker')
@ -294,24 +300,34 @@ def icon_full_path(icon):
# If the icon path is absolute and exists, leave it alone. # If the icon path is absolute and exists, leave it alone.
# This takes care of software that has its own icons stored # This takes care of software that has its own icons stored
# in non-standard directories. # in non-standard directories.
# But we don't want to do this for svg icons, since none of the WMs
# supports them. In that case, just fall back to looking for the icon
# elsewhere in the system.
ext = os.path.splitext(icon)[1].lower() ext = os.path.splitext(icon)[1].lower()
if os.path.exists(icon) and ext != ".svg" and ext != ".svgz": if os.path.exists(icon):
if max_icon_size: if ext == ".svg" or ext == ".svgz":
return icon_max_size(icon) # only jwm supports svg icons
if desktop == "jwm" and not nosvg:
return icon
else: else:
return icon # icon is not svg
if max_icon_size:
return icon_max_size(icon)
else:
return icon
# fall back to looking for the icon elsewhere in the system
icon = icon_strip(icon) icon = icon_strip(icon)
icon_theme = gtk.icon_theme_get_default() icon_theme = gtk.icon_theme_get_default()
try: try:
icon = icon_theme.lookup_icon(icon, iconsize, gtk.ICON_LOOKUP_NO_SVG) # JWM supports svg icons
if desktop == "jwm" and not nosvg:
icon = icon_theme.lookup_icon(icon, iconsize, gtk.ICON_LOOKUP_FORCE_SVG)
# but none of the other WMs does
else:
icon = icon_theme.lookup_icon(icon, iconsize, gtk.ICON_LOOKUP_NO_SVG)
except AttributeError: except AttributeError:
sys.exit('ERROR: You need to run xdgmenumaker inside an X session.') sys.exit('ERROR: You need to run xdgmenumaker inside an X session.')
if icon: if icon:
icon = icon.get_filename() icon = icon.get_filename()
if max_icon_size: # icon size only matters for non-SVG icons
if icon and max_icon_size and (ext != ".svg" or ext != ".svgz"):
icon = icon_max_size(icon) icon = icon_max_size(icon)
return icon return icon

Loading…
Cancel
Save