sway: make icons work with sway

This commit is contained in:
Sijmen 2019-10-17 10:06:38 +02:00
parent 7b85e76805
commit bc10869bca

View file

@ -21,36 +21,39 @@ import re
# (WM_CLASS) names and the icons can be any text you want to display. However # (WM_CLASS) names and the icons can be any text you want to display. However
# most of these are character codes for font awesome: # most of these are character codes for font awesome:
# http://fortawesome.github.io/Font-Awesome/icons/ # http://fortawesome.github.io/Font-Awesome/icons/
FA_CHROME = "\uf268" FA_CHROME = "\uF268"
FA_CODE = "\uf121" FA_CODE = "\uF121"
FA_DOWNLOAD = "\uf019" FA_DOWNLOAD = "\uF019"
FA_FILE_PDF_O = "\uf1c1" FA_FILE_PDF_O = "\uF1C1"
FA_FILE_TEXT_O = "\uf0f6" FA_FILE_TEXT_O = "\uF0F6"
FA_FILES_O = "\uf0c5" FA_FILES_O = "\uF0C5"
FA_FIREFOX = "\uf269" FA_FIREFOX = "\uF269"
FA_PICTURE_O = "\uf03e" FA_PICTURE_O = "\uF03E"
FA_SPOTIFY = "\uf1bc" FA_SPOTIFY = "\uF1BC"
FA_TERMINAL = "\uf120" FA_TERMINAL = "\uF120"
FA_TELEGRAM = "\uf3fe" FA_TELEGRAM = "\uF3FE"
FA_CUBE = "\uf1b2" FA_CUBE = "\uF1B2"
FA_PAINT_BRUSH = "\uf1fc" FA_PAINT_BRUSH = "\uF1FC"
FA_BOOK = "\uf02d" FA_BOOK = "\uF02D"
FA_FOLDER = "\uf07c" FA_FOLDER = "\uF07C"
FA_CALENDAR = "\uf133" FA_CALENDAR = "\uF133"
FA_BEZIER_CURVE = "\uf55b" FA_BEZIER_CURVE = "\uF55B"
FA_VECTOR_SQUARE = "\uf5cb" FA_VECTOR_SQUARE = "\uF5CB"
FA_VOLUME_UP = "\uf028" FA_VOLUME_UP = "\uF028"
FA_STEAM = "\uF1B6"
WINDOW_ICONS = { WINDOW_ICONS = {
"Firefox": FA_FIREFOX, "Blender": FA_CUBE,
"Gnome-terminal": FA_TERMINAL,
"chromium": FA_CHROME, "chromium": FA_CHROME,
"code": FA_CODE, "code": FA_CODE,
"code-oss": FA_CODE,
"emacs": FA_CODE, "emacs": FA_CODE,
"evince": FA_FILE_PDF_O, "evince": FA_FILE_PDF_O,
"feh": FA_PICTURE_O, "feh": FA_PICTURE_O,
"Firefox": FA_FIREFOX,
"gimp-2.10": FA_PAINT_BRUSH, "gimp-2.10": FA_PAINT_BRUSH,
"gnome-calendar": FA_CALENDAR, "gnome-calendar": FA_CALENDAR,
"Gnome-terminal": FA_TERMINAL,
"google-chrome": FA_CHROME, "google-chrome": FA_CHROME,
"inkscape": FA_PAINT_BRUSH, "inkscape": FA_PAINT_BRUSH,
"jetbrains-pycharm": FA_CODE, "jetbrains-pycharm": FA_CODE,
@ -59,15 +62,56 @@ WINDOW_ICONS = {
"mupdf": FA_FILE_PDF_O, "mupdf": FA_FILE_PDF_O,
"nautilus": FA_FOLDER, "nautilus": FA_FOLDER,
"notion-nativefier-102b2f": FA_BOOK, "notion-nativefier-102b2f": FA_BOOK,
"org.gnome.Nautilus": FA_FOLDER,
"pulseeffects": FA_VOLUME_UP, "pulseeffects": FA_VOLUME_UP,
"slic3r-gui": FA_CUBE,
"slic3r-prusa3d": FA_CUBE, "slic3r-prusa3d": FA_CUBE,
"spotify": FA_SPOTIFY, "spotify": FA_SPOTIFY,
"Steam": FA_STEAM,
"subl": FA_CODE, "subl": FA_CODE,
"subl3": FA_CODE, "subl3": FA_CODE,
"telegram-desktop": FA_TELEGRAM, "telegram-desktop": FA_TELEGRAM,
"transmission-gtk": FA_DOWNLOAD, "Thunar": FA_FOLDER,
"thunar": FA_FOLDER, "thunar": FA_FOLDER,
"transmission-gtk": FA_DOWNLOAD,
"urxvt": FA_TERMINAL, "urxvt": FA_TERMINAL,
"xfce4-terminal": FA_TERMINAL,
}
WAYLAND_ICONS = {
"Blender": FA_CUBE,
"chromium": FA_CHROME,
"code": FA_CODE,
"code-oss": FA_CODE,
"emacs": FA_CODE,
"evince": FA_FILE_PDF_O,
"feh": FA_PICTURE_O,
"firefox": FA_FIREFOX,
"gimp-2.10": FA_PAINT_BRUSH,
"gnome-calendar": FA_CALENDAR,
"Gnome-terminal": FA_TERMINAL,
"google-chrome": FA_CHROME,
"inkscape": FA_PAINT_BRUSH,
"jetbrains-pycharm": FA_CODE,
"jetbrains-webstorm": FA_CODE,
"libreoffice": FA_FILE_TEXT_O,
"mupdf": FA_FILE_PDF_O,
"nautilus": FA_FOLDER,
"notion-nativefier-102b2f": FA_BOOK,
"org.gnome.Nautilus": FA_FOLDER,
"pulseeffects": FA_VOLUME_UP,
"slic3r-gui": FA_CUBE,
"slic3r-prusa3d": FA_CUBE,
"spotify": FA_SPOTIFY,
"Steam": FA_STEAM,
"subl": FA_CODE,
"subl3": FA_CODE,
"telegram-desktop": FA_TELEGRAM,
"Thunar": FA_FOLDER,
"thunar": FA_FOLDER,
"transmission-gtk": FA_DOWNLOAD,
"urxvt": FA_TERMINAL,
"xfce4-terminal": FA_TERMINAL,
} }
@ -81,9 +125,10 @@ def xprop(win_id, property):
Requires xorg-xprop to be installed. Requires xorg-xprop to be installed.
""" """
try: try:
prop = proc.check_output(['xprop', '-id', str(win_id), property], prop = proc.check_output(
stderr=proc.DEVNULL) ["xprop", "-id", str(win_id), property], stderr=proc.DEVNULL
prop = prop.decode('utf-8') )
prop = prop.decode("utf-8")
return re.findall('"([^"]+)"', prop) return re.findall('"([^"]+)"', prop)
except proc.CalledProcessError: except proc.CalledProcessError:
print(f"Unable to get property for window '{win_id}'") print(f"Unable to get property for window '{win_id}'")
@ -91,13 +136,21 @@ def xprop(win_id, property):
def icon_for_window(window): def icon_for_window(window):
classes = xprop(window.window, 'WM_CLASS') if window.app_id:
# Wayland
if window.app_id in WAYLAND_ICONS:
return WAYLAND_ICONS[window.app_id]
else:
print(f"No icon available for app ID '{window.app_id}'")
return "*"
classes = xprop(window.window, "WM_CLASS")
if classes: if classes:
for cls in classes: for cls in classes:
if cls in WINDOW_ICONS: if cls in WINDOW_ICONS:
return WINDOW_ICONS[cls] return WINDOW_ICONS[cls]
print('No icon available for window with classes: %s' % str(classes)) print("No icon available for window with classes: %s" % str(classes))
return '*' return "*"
def rename(): def rename():
@ -115,17 +168,16 @@ def rename():
def on_change(i3, e): def on_change(i3, e):
"""Call rename() on relevant window events.""" """Call rename() on relevant window events."""
print(f"{e.change}") print(f"{e.change}")
if e.change in ['new', 'close', 'move']: if e.change in ["new", "close", "move"]:
rename() rename()
def main(): def main():
rename() rename()
i3.on('window', on_change) i3.on("window", on_change)
i3.main() i3.main()
if __name__ == "__main__": if __name__ == "__main__":
main() main()