Advertisement
Guest User

The Linux Cast's Qtile Config

a guest
May 30th, 2023
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 13.80 KB | None | 0 0
  1. #pywal1 config
  2. from typing import List  # noqa: F401
  3. import os
  4. import subprocess
  5. from os import path
  6.  
  7. from libqtile import bar, layout, widget, hook, qtile, backend
  8. from libqtile.config import Click, Drag, Group, ScratchPad, DropDown, Key, Match, Screen
  9. from libqtile.lazy import lazy
  10. from settings.path import qtile_path
  11.  
  12. from qtile_extras import widget
  13. from qtile_extras.widget.decorations import PowerLineDecoration
  14.  
  15. mod = "mod4"
  16. terminal = "kitty"
  17.  
  18. ########## Powerline from extras ########
  19.  
  20. arrow_powerlineRight = {
  21.     "decorations": [
  22.         PowerLineDecoration(
  23.             path="arrow_right",
  24.             size=11,
  25.         )
  26.     ]
  27. }
  28. arrow_powerlineLeft = {
  29.     "decorations": [
  30.         PowerLineDecoration(
  31.             path="arrow_left",
  32.             size=11,
  33.         )
  34.     ]
  35. }
  36. rounded_powerlineRight = {
  37.     "decorations": [
  38.         PowerLineDecoration(
  39.             path="rounded_right",
  40.             size=11,
  41.         )
  42.     ]
  43. }
  44. rounded_powerlineLeft = {
  45.     "decorations": [
  46.         PowerLineDecoration(
  47.             path="rouded_left",
  48.             size=11,
  49.         )
  50.     ]
  51. }
  52. slash_powerlineRight = {
  53.     "decorations": [
  54.         PowerLineDecoration(
  55.             path="forward_slash",
  56.             size=11,
  57.         )
  58.     ]
  59. }
  60. slash_powerlineLeft = {
  61.     "decorations": [
  62.         PowerLineDecoration(
  63.             path="back_slash",
  64.             size=11,
  65.         )
  66.     ]
  67. }
  68.  
  69. keys = [
  70. # Open terminal
  71.     Key([mod], "Return", lazy.spawn(terminal)),
  72. # Qtile System Actions
  73.     Key([mod, "shift"], "r", lazy.restart()),
  74.     Key([mod, "shift"], "x", lazy.shutdown()),
  75. # Active Window Actions
  76.     Key([mod], "f", lazy.window.toggle_fullscreen()),
  77.     Key([mod], "q", lazy.window.kill()),
  78.     Key([mod, "control"], "h",
  79.         lazy.layout.grow_right(),
  80.         lazy.layout.grow(),
  81.         lazy.layout.increase_ratio(),
  82.         lazy.layout.delete()
  83.         ),
  84.     Key([mod, "control"], "Right",
  85.         lazy.layout.grow_right(),
  86.         lazy.layout.grow(),
  87.         lazy.layout.increase_ratio(),
  88.         lazy.layout.delete()
  89.         ),
  90.     Key([mod, "control"], "l",
  91.         lazy.layout.grow_left(),
  92.         lazy.layout.shrink(),
  93.         lazy.layout.decrease_ratio(),
  94.         lazy.layout.add()
  95.         ),
  96.     Key([mod, "control"], "Left",
  97.         lazy.layout.grow_left(),
  98.         lazy.layout.shrink(),
  99.         lazy.layout.decrease_ratio(),
  100.         lazy.layout.add()
  101.         ),
  102.     Key([mod, "control"], "k",
  103.         lazy.layout.grow_up(),
  104.         lazy.layout.grow(),
  105.         lazy.layout.decrease_nmaster()
  106.         ),
  107.     Key([mod, "control"], "Up",
  108.         lazy.layout.grow_up(),
  109.         lazy.layout.grow(),
  110.         lazy.layout.decrease_nmaster()
  111.         ),
  112.     Key([mod, "control"], "j",
  113.         lazy.layout.grow_down(),
  114.         lazy.layout.shrink(),
  115.         lazy.layout.increase_nmaster()
  116.         ),
  117.     Key([mod, "control"], "Down",
  118.         lazy.layout.grow_down(),
  119.         lazy.layout.shrink(),
  120.         lazy.layout.increase_nmaster()
  121.         ),
  122.  
  123. # Window Focus (Arrows and Vim keys)
  124.     Key([mod], "Up", lazy.layout.up()),
  125.     Key([mod], "Down", lazy.layout.down()),
  126.     Key([mod], "Left", lazy.layout.left()),
  127.     Key([mod], "Right", lazy.layout.right()),
  128.     Key([mod], "k", lazy.layout.up()),
  129.     Key([mod], "j", lazy.layout.down()),
  130.     Key([mod], "h", lazy.layout.left()),
  131.     Key([mod], "l", lazy.layout.right()),
  132.  
  133. # Qtile Layout Actions
  134.     Key([mod], "r", lazy.layout.reset()),
  135.     Key([mod], "Tab", lazy.next_layout()),
  136.     Key([mod, "shift"], "f", lazy.layout.flip()),
  137.     Key([mod, "shift"], "space", lazy.window.toggle_floating()),
  138.  
  139. # Move windows around MonadTall/MonadWide Layouts
  140.     Key([mod, "shift"], "Up", lazy.layout.shuffle_up()),
  141.     Key([mod, "shift"], "Down", lazy.layout.shuffle_down()),
  142.     Key([mod, "shift"], "Left", lazy.layout.swap_left()),
  143.     Key([mod, "shift"], "Right", lazy.layout.swap_right()),
  144.     Key([mod, "shift"], "k", lazy.layout.shuffle_up()),
  145.     Key([mod, "shift"], "j", lazy.layout.shuffle_down()),
  146.     Key([mod, "shift"], "h", lazy.layout.swap_left()),
  147.     Key([mod, "shift"], "l", lazy.layout.swap_right()),
  148.    
  149. # Switch focus to specific monitor (out of three)
  150.     Key([mod], "i", lazy.to_screen(0)),
  151.     Key([mod], "o", lazy.to_screen(1)),
  152.  
  153. # Switch focus of monitors
  154.     Key([mod], "period", lazy.next_screen()),
  155.     Key([mod], "comma", lazy.prev_screen()),
  156. ]
  157.  
  158. # Create labels for groups and assign them a default layout.
  159. groups = []
  160.  
  161.  
  162. group_names = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "minus", "equal", "F1", "F2", "F3", "F4", "F5"]
  163.  
  164. group_labels = [" ", " ", " ", " ", " ", " ", " ", " ", "ﭮ" , " ", " ", "﨣 ", "F1", "F2", "F3", "F4", "F5"]
  165. #group_labels = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]
  166.  
  167. group_layouts = ["monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall"]
  168.  
  169. # Add group names, labels, and default layouts to the groups object.
  170. for i in range(len(group_names)):
  171.     groups.append(
  172.         Group(
  173.             name=group_names[i],
  174.             layout=group_layouts[i].lower(),
  175.             label=group_labels[i],
  176.         ))
  177.  
  178. # Add group specific keybindings
  179. for i in groups:
  180.     keys.extend([
  181.         Key([mod], i.name, lazy.group[i.name].toscreen(), desc="Mod + number to move to that group."),
  182.         Key(["mod1"], "Tab", lazy.screen.next_group(), desc="Move to next group."),
  183.         Key(["mod1", "shift"], "Tab", lazy.screen.prev_group(), desc="Move to previous group."),
  184.         Key([mod, "shift"], i.name, lazy.window.togroup(i.name), desc="Move focused window to new group."),
  185.     ])
  186.  
  187. # Define scratchpads
  188. groups.append(ScratchPad("scratchpad", [
  189.     DropDown("term", "kitty --class=scratch", width=0.8, height=0.8, x=0.1, y=0.1, opacity=1),
  190.     DropDown("term2", "kitty --class=scratch", width=0.8, height=0.8, x=0.1, y=0.1, opacity=1),
  191.     DropDown("ranger", "kitty --class=ranger -e ranger", width=0.8, height=0.8, x=0.1, y=0.1, opacity=0.9),
  192.     DropDown("volume", "kitty --class=volume -e pulsemixer", width=0.8, height=0.8, x=0.1, y=0.1, opacity=0.9),
  193.     DropDown("mus", "kitty --class=mus -e ncmpcpp", width=0.8, height=0.8, x=0.1, y=0.1, opacity=0.9),
  194.     DropDown("news", "kitty --class=news -e newsboat", width=0.8, height=0.8, x=0.1, y=0.1, opacity=0.9),
  195.  
  196. ]))
  197.  
  198. # Scratchpad keybindings
  199. keys.extend([
  200.     Key([mod], "n", lazy.group['scratchpad'].dropdown_toggle('term')),
  201.     Key([mod], "c", lazy.group['scratchpad'].dropdown_toggle('ranger')),
  202.     Key([mod], "v", lazy.group['scratchpad'].dropdown_toggle('volume')),
  203.     Key([mod], "m", lazy.group['scratchpad'].dropdown_toggle('mus')),
  204.     Key([mod], "b", lazy.group['scratchpad'].dropdown_toggle('news')),
  205.     Key([mod, "shift"], "n", lazy.group['scratchpad'].dropdown_toggle('term2')),
  206. ])
  207.  
  208. colors = []
  209. cache='/home/matt/.cache/wal/colors'
  210. def load_colors(cache):
  211.     with open(cache, 'r') as file:
  212.         for i in range(8):
  213.             colors.append(file.readline().strip())
  214.     colors.append('#ffffff')
  215.     lazy.reload()
  216. load_colors(cache)
  217.  
  218. # Define layouts and layout themes
  219. layout_theme = {
  220.         "margin":5,
  221.         "border_width": 4,
  222.         "border_focus": colors[1],
  223.         "border_normal": colors[3]
  224.     }
  225.  
  226. layouts = [
  227.     layout.MonadTall(**layout_theme),
  228.     layout.MonadWide(**layout_theme),
  229.     layout.MonadThreeCol(**layout_theme),
  230.     layout.MonadWide(**layout_theme),
  231.     layout.Floating(**layout_theme),
  232.     layout.Spiral(**layout_theme),
  233.     layout.RatioTile(**layout_theme),
  234.     layout.Max(**layout_theme)
  235. ]
  236.  
  237. # Mouse callback functions
  238. def launch_menu():
  239.     qtile.cmd_spawn("rofi -show drun -show-icons")
  240.  
  241.  
  242. # Define Widgets
  243. widget_defaults = dict(
  244.     font="JetBrainsMono Nerd Font",
  245.     fontsize = 13,
  246.     padding = 3,
  247.     background=colors[0]
  248. )
  249.  
  250. extension_defaults = widget_defaults.copy()
  251.  
  252. def init_widgets_list(monitor_num):
  253.     widgets_list = [
  254.                 widget.Image(
  255.                     filename="~/.config/qtile/imgs/arch.png",
  256.                     background=colors[4],
  257.                     margin=3,
  258.                 ),
  259.                 widget.Spacer(
  260.                     length=1,
  261.                     background=colors[4],
  262.                     **arrow_powerlineLeft,
  263.                 ),
  264.                 widget.GroupBox(
  265.                     fontsize=20,
  266.                     padding_x=5,
  267.                     padding_y=5,
  268.                     rounded=False,
  269.                     center_aligned=True,
  270.                     disable_drag=True,
  271.                     borderwidth=1,
  272.                     highlight_method="line",
  273.                     hide_unused = True,
  274.                     active=colors[3],
  275.                     inactive=colors[5],
  276.                     highlight_color=colors[0],
  277.                     this_current_screen_border=colors[4],
  278.                     this_screen_border=colors[7],
  279.                     other_screen_border=colors[4],
  280.                     other_current_screen_border=colors[3],
  281.                     background=colors[0],
  282.                     foreground=colors[2],
  283.                     **arrow_powerlineLeft,
  284.                 ),
  285.                 widget.Spacer(
  286.                     length=1,
  287.                     background=colors[0],
  288.                     **arrow_powerlineLeft,
  289.                 ),
  290.                 widget.TaskList(
  291.                     margin=0,
  292.                     padding=6,
  293.                     icon_size=0,
  294.                     fontsize=14,
  295.                     borderwidth=1,
  296.                     rounded=False,
  297.                     highlight_method="block",
  298.                     title_width_method="uniform",
  299.                     urgent_alert_methond="border",
  300.                     foreground=colors[3],
  301.                     background=colors[3],
  302.                     border=colors[3],
  303.                     urgent_border=colors[3],
  304.                     txt_floating=" ",
  305.                     txt_maximized=" ",
  306.                     txt_minimized=" ",
  307.                 ),
  308.                 widget.Spacer(
  309.                     length=1,
  310.                     background=colors[0],
  311.                     **rounded_powerlineRight,
  312.                 ),
  313.                 widget.Spacer(
  314.                     length=1,
  315.                     background=colors[0],
  316.                     **arrow_powerlineRight,
  317.                 ),
  318.                 widget.CPU(
  319.                     padding=5,
  320.                     format="  {freq_current}GHz {load_percent}%",
  321.                     foreground=colors[2],
  322.                     background=colors[0],
  323.                     **slash_powerlineRight,
  324.                 ),
  325.                 widget.ThermalSensor(
  326.                     padding=5,
  327.                     update_interval=1,
  328.                     format="󰔐 {temp:.0f}{unit}",
  329.                     tag_sensor="Tctl",
  330.                     foreground=colors[3],
  331.                     background=colors[0],
  332.                     **slash_powerlineRight,
  333.                 ),
  334.                 widget.Memory(
  335.                     padding=5,
  336.                     format="󰈀 {MemUsed:.0f}{mm}",
  337.                     background=colors[2],
  338.                     foreground=colors[0],
  339.                     **slash_powerlineRight,
  340.                 ),
  341.                 widget.Clock(
  342.                     padding=5,
  343.                     format="  %a %d %b %H:%M:%S",
  344.                     foreground=colors[5],
  345.                     background=colors[3],
  346.                     **slash_powerlineRight,
  347.                 ),
  348.                 widget.PulseVolume(
  349.                     fmt="󰕾 {}",
  350.                     foreground=colors[1],
  351.                     background=colors[4],
  352.                     padding=10,
  353.                     **slash_powerlineRight,
  354.                 ),
  355.                 widget.Systray(
  356.                     padding=7,
  357.                     icon_size=15,
  358.                 ),
  359.                 widget.CurrentLayoutIcon(
  360.                     padding=5,
  361.                     scale=0.5,
  362.                 ),
  363.             ]
  364.  
  365.     return widgets_list
  366.  
  367. def init_secondary_widgets_list(monitor_num):
  368.     secondary_widgets_list = init_widgets_list(monitor_num)
  369.     del secondary_widgets_list[16:17]
  370.     return secondary_widgets_list
  371.  
  372. widgets_list = init_widgets_list("1")
  373. secondary_widgets_list = init_secondary_widgets_list("2")
  374.  
  375. screens = [
  376.     Screen(top=bar.Bar(widgets=widgets_list, size=30, background=colors[0], margin=[9, 19, 6,19],border_width=[0, 0, 0, 0], opacity=0.8),),
  377.     Screen(top=bar.Bar(widgets=secondary_widgets_list, size=30, background=colors[0], mmargin=[9, 19, 6,19],border_width=[0, 0, 0, 0], opacity=0.8),),
  378.     ]
  379.  
  380. # Drag floating layouts.
  381. mouse = [
  382.     Drag([mod], "Button1", lazy.window.set_position_floating(),
  383.          start=lazy.window.get_position()),
  384.     Drag([mod], "Button3", lazy.window.set_size_floating(),
  385.          start=lazy.window.get_size()),
  386.     Click([mod], "Button2", lazy.window.bring_to_front())
  387. ]
  388.  
  389. @hook.subscribe.startup_once
  390. def autostart():
  391.    home = os.path.expanduser('~/.config/qtile/scripts/autostart.sh')
  392.    subprocess.run([home])
  393.  
  394. dgroups_key_binder = None
  395. dgroups_app_rules = []  # type: List
  396. follow_mouse_focus = True
  397. bring_front_click = False
  398. cursor_warp = False
  399. floating_layout = layout.Floating(float_rules=[
  400.     *layout.Floating.default_float_rules,
  401.     Match(wm_class='confirmreset'),  # gitk
  402.     Match(wm_class='makebranch'),  # gitk
  403.     Match(wm_class='maketag'),  # gitk
  404.     Match(wm_class='ssh-askpass'),  # ssh-askpass
  405.     Match(title='branchdialog'),  # gitk
  406.     Match(title='pinentry'),  # GPG key password entry
  407. ], fullscreen_border_width = 0, border_width = 0)
  408. auto_fullscreen = True
  409. focus_on_window_activation = "smart"
  410. reconfigure_screens = True
  411.  
  412. auto_minimize = True
  413. wmname = "Qtile 0.21.0"
  414.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement