daa1f37b45229778c31faa2d61db2602e380cccf

Author
Pavle Portic <git@theedgeofrage.com>
Committer
Pavle Portic <git@theedgeofrage.com>
Date

Message

Update i3 autoname script

Diff

This diff is truncated to protect this page.

  1diff --git a/dot_config/i3/i3-autoname-workspaces.py b/dot_config/i3/i3-autoname-workspaces.py
  2index deab332f60b50561a7ae2b9c153112b313e37f24..aa25d8f0085ad876b93f62449590c2974ff58cf9 100644
  3--- a/dot_config/i3/i3-autoname-workspaces.py
  4+++ b/dot_config/i3/i3-autoname-workspaces.py
  5@@ -1,7 +1,7 @@
  6 #!/usr/bin/env python3
  7 
  8 # This script listens for i3 events and updates workspace names to show icons
  9-# for running programs.  It contains icons for a few programs, but more can
 10+# for running programs. It contains icons for a few programs, but more can
 11 # easily be added by inserting them into WINDOW_ICONS below.
 12 #
 13 # Dependencies: xorg-xprop i3ipc fontawesome
 14@@ -12,8 +12,8 @@
 15 # Configuration:
 16 # The default i3 config's keybingings reference workspaces by name, which is an
 17 # issue when using this script because the "names" are constantaly changing to
 18-# show window icons.  Instead, you'll need to change the keybindings to
 19-# reference workspaces by number.  Change lines like:
 20+# show window icons. Instead, you'll need to change the keybindings to
 21+# reference workspaces by number. Change lines like:
 22 #   bindsym $mod+1 workspace 1
 23 # To:
 24 #   bindsym $mod+1 workspace number 1
 25@@ -21,18 +21,18 @@
 26 import re
 27 import signal
 28 import subprocess as proc
 29-from sys import exit
 30-from typing import Any, NoReturn
 31+from types import FrameType
 32+from typing import Any, Callable
 33 
 34-import nerdfonts as nf  # type: ignore
 35-import i3ipc  # type: ignore
 36+import nerdfonts as nf
 37+from i3ipc import Connection
 38 
 39-# Add icons here for common programs you use.  The keys are the X window class
 40+# Add icons here for common programs you use. The keys are the X window class
 41 # (WM_CLASS) names (lower-cased) and the icons can be any text you want to
 42 # display.
 43 #
 44-# Most of these are character codes for font awesome:
 45-#   http://fortawesome.github.io/Font-Awesome/icons/
 46+# These icons are from the Nerd Font patch set.
 47+# You can find a list of all here: https://www.nerdfonts.com/cheat-sheet
 48 #
 49 # If you're not sure what the WM_CLASS is for your application, you can use
 50 # xprop (https://linux.die.net/man/1/xprop). Run `xprop | grep WM_CLASS`
 51@@ -82,6 +82,7 @@ WINDOW_ICONS: dict[str, str] = {
 52     'nm-connection-editor': nf.icons['fa_wifi'],
 53     'obs': nf.icons['md_video'],
 54     'openlens': nf.icons['md_kubernetes'],
 55+    'org.gnome.nautilus': nf.icons['fa_folder'],
 56     'pavucontrol': nf.icons['fa_volume_up'],
 57     'picard': nf.icons['fa_music'],
 58     'qbittorrent': nf.icons['fa_download'],
 59@@ -112,29 +113,26 @@ DEFAULT_ICON = '*'
 60 # Used so that we can keep the workspace's name when we add icons to it.
 61 # Returns a dictionary with the 'num' and 'icons' keys
 62 # Any field that's missing in @name will be None in the returned dict
 63-def parse_workspace_name(name) -> dict[str, Any]:
 64+def parse_workspace_number(name: str) -> str | None:
 65     match = re.match(
 66         r'(?P<num>\d+):? ?(?P<icons>.+)?',
 67         name,
 68     )
 69     if match is None:
 70-        return {}
 71+        return None
 72 
 73-    return match.groupdict()
 74+    return match.groupdict()['num']
 75 
 76 
 77 # Given a dictionary with 'num', 'icons',
 78 # return the formatted name by concatenating them together.
 79-def construct_workspace_name(parts) -> str:
 80-    new_name: str = str(parts['num'])
 81-    if parts['icons']:
 82+def construct_workspace_name(num: str, icons: list[str] | None) -> str:
 83+    new_name: str = str(num)
 84+    if icons:
 85         new_name += ':'
 86-        for icon in parts['icons']:
 87+        for icon in icons:
 88             new_name += ' ' + icon
 89 
 90-    if len(new_name) > 1 and not new_name.endswith('*'):
 91-        new_name += ' '
 92-
 93     return new_name
 94 
 95 
 96@@ -162,10 +160,10 @@ def icon_for_window(window) -> str:
 97 
 98     for cls in map(lambda x: x.lower(), classes):
 99         if 'minecraft' in cls:
100-            return WINDOW_ICONS["minecraft"]
101+            return WINDOW_ICONS["minecraft"] + ' '
102 
103         if cls in WINDOW_ICONS:
104-            return WINDOW_ICONS[cls]