sway: make icons work with sway
This commit is contained in:
parent
7b85e76805
commit
bc10869bca
1 changed files with 83 additions and 31 deletions
|
@ -21,36 +21,39 @@ import re
|
|||
# (WM_CLASS) names and the icons can be any text you want to display. However
|
||||
# most of these are character codes for font awesome:
|
||||
# http://fortawesome.github.io/Font-Awesome/icons/
|
||||
FA_CHROME = "\uf268"
|
||||
FA_CODE = "\uf121"
|
||||
FA_DOWNLOAD = "\uf019"
|
||||
FA_FILE_PDF_O = "\uf1c1"
|
||||
FA_FILE_TEXT_O = "\uf0f6"
|
||||
FA_FILES_O = "\uf0c5"
|
||||
FA_FIREFOX = "\uf269"
|
||||
FA_PICTURE_O = "\uf03e"
|
||||
FA_SPOTIFY = "\uf1bc"
|
||||
FA_TERMINAL = "\uf120"
|
||||
FA_TELEGRAM = "\uf3fe"
|
||||
FA_CUBE = "\uf1b2"
|
||||
FA_PAINT_BRUSH = "\uf1fc"
|
||||
FA_BOOK = "\uf02d"
|
||||
FA_FOLDER = "\uf07c"
|
||||
FA_CALENDAR = "\uf133"
|
||||
FA_BEZIER_CURVE = "\uf55b"
|
||||
FA_VECTOR_SQUARE = "\uf5cb"
|
||||
FA_VOLUME_UP = "\uf028"
|
||||
FA_CHROME = "\uF268"
|
||||
FA_CODE = "\uF121"
|
||||
FA_DOWNLOAD = "\uF019"
|
||||
FA_FILE_PDF_O = "\uF1C1"
|
||||
FA_FILE_TEXT_O = "\uF0F6"
|
||||
FA_FILES_O = "\uF0C5"
|
||||
FA_FIREFOX = "\uF269"
|
||||
FA_PICTURE_O = "\uF03E"
|
||||
FA_SPOTIFY = "\uF1BC"
|
||||
FA_TERMINAL = "\uF120"
|
||||
FA_TELEGRAM = "\uF3FE"
|
||||
FA_CUBE = "\uF1B2"
|
||||
FA_PAINT_BRUSH = "\uF1FC"
|
||||
FA_BOOK = "\uF02D"
|
||||
FA_FOLDER = "\uF07C"
|
||||
FA_CALENDAR = "\uF133"
|
||||
FA_BEZIER_CURVE = "\uF55B"
|
||||
FA_VECTOR_SQUARE = "\uF5CB"
|
||||
FA_VOLUME_UP = "\uF028"
|
||||
FA_STEAM = "\uF1B6"
|
||||
|
||||
WINDOW_ICONS = {
|
||||
"Firefox": FA_FIREFOX,
|
||||
"Gnome-terminal": FA_TERMINAL,
|
||||
"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,
|
||||
|
@ -59,15 +62,56 @@ WINDOW_ICONS = {
|
|||
"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,
|
||||
"transmission-gtk": FA_DOWNLOAD,
|
||||
"Thunar": FA_FOLDER,
|
||||
"thunar": FA_FOLDER,
|
||||
"transmission-gtk": FA_DOWNLOAD,
|
||||
"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.
|
||||
"""
|
||||
try:
|
||||
prop = proc.check_output(['xprop', '-id', str(win_id), property],
|
||||
stderr=proc.DEVNULL)
|
||||
prop = prop.decode('utf-8')
|
||||
prop = proc.check_output(
|
||||
["xprop", "-id", str(win_id), property], stderr=proc.DEVNULL
|
||||
)
|
||||
prop = prop.decode("utf-8")
|
||||
return re.findall('"([^"]+)"', prop)
|
||||
except proc.CalledProcessError:
|
||||
print(f"Unable to get property for window '{win_id}'")
|
||||
|
@ -91,13 +136,21 @@ def xprop(win_id, property):
|
|||
|
||||
|
||||
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:
|
||||
for cls in classes:
|
||||
if cls in WINDOW_ICONS:
|
||||
return WINDOW_ICONS[cls]
|
||||
print('No icon available for window with classes: %s' % str(classes))
|
||||
return '*'
|
||||
print("No icon available for window with classes: %s" % str(classes))
|
||||
return "*"
|
||||
|
||||
|
||||
def rename():
|
||||
|
@ -115,17 +168,16 @@ def rename():
|
|||
def on_change(i3, e):
|
||||
"""Call rename() on relevant window events."""
|
||||
print(f"{e.change}")
|
||||
if e.change in ['new', 'close', 'move']:
|
||||
if e.change in ["new", "close", "move"]:
|
||||
rename()
|
||||
|
||||
|
||||
def main():
|
||||
rename()
|
||||
|
||||
i3.on('window', on_change)
|
||||
i3.on("window", on_change)
|
||||
i3.main()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue