My Qtile window manager configuration
git clone https://github.com/m-col/qtile-config
Files | Refs | Readme

-rw-r--r-- tags.py


      1 """
      2 Tags
      3 ====
      4 
      5 This workflow replaces groups. There is only one group defined per (possible) screen. No
      6 keybindings are defined to switch between groups or to move windows between groups. If
      7 only one monitor is connected then only the first group is ever used, etc.
      8 
      9 """
     10 
     11 from __future__ import annotations
     12 
     13 import os
     14 from collections import defaultdict
     15 from typing import TYPE_CHECKING
     16 
     17 from libqtile import hook, qtile
     18 from libqtile.backend.base import Window
     19 from libqtile.config import Group, Match
     20 from libqtile.lazy import lazy
     21 from libqtile.log_utils import logger
     22 
     23 if TYPE_CHECKING:
     24     from typing import List, Tuple
     25 
     26 
     27 groups: List[Group] = [Group("")]
     28 
     29 tags: List[Tuple[str, Match, List[Window]]] = [
     30     ("terms", Match(wm_class="foot"), []),
     31     ("firefox", Match(wm_class="firefox"), []),
     32     ("thunar", Match(wm_class="thunar"), []),
     33 ]
     34 
     35 
     36 @hook.subscribe.client_new
     37 def _(window):
     38     """
     39     This adds windows to any tags that match it.
     40     """
     41     if isinstance(window, Window):  # Static windows ignored
     42         for name, match, windows in tags:
     43             if match.compare(window):
     44                 windows.append(window)
     45                 tag_hidden = windows[0].minimized
     46                 window.minimized = tag_hidden
     47                 qtile.current_screen.group.add(
     48                     window, focus=window.can_steal_focus and tag_hidden
     49                 )
     50 
     51 
     52 def _toggle_tag(_qtile, to_toggle: str):
     53     """
     54     This is bound to keys to show/hide all windows of a given tag. It toggles their
     55     minimized state.
     56     """
     57     for name, match, windows in tags:
     58         if name == to_toggle:
     59             for window in windows:
     60                 window.toggle_minimize()
     61             return
     62 
     63 
     64 mod = "mod1" if int(os.environ.get("QTILE_XEPHYR", 0)) else "mod4"
     65 
     66 keys_group: Tuple[List[str], str, Any, str] = []
     67 
     68 for i, (name, _, _) in enumerate(tags):
     69     keys_group.extend(
     70         [
     71             ([mod], str(i + 1), lazy.function(_toggle_tag, name), f"Toggle tag {name}"),
     72         ]
     73     )
     74