From 499f4c3a57d76c2cc62a76da62ca66ee0abf3897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Av=C3=A9?= Date: Sat, 20 May 2023 15:35:11 +0200 Subject: [PATCH] Initial Qtile config --- qtile/config.py | 268 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 268 insertions(+) create mode 100644 qtile/config.py diff --git a/qtile/config.py b/qtile/config.py new file mode 100644 index 0000000..5c20197 --- /dev/null +++ b/qtile/config.py @@ -0,0 +1,268 @@ +from libqtile import bar +from libqtile import hook +from libqtile import layout +from libqtile import widget +from libqtile.command import lazy +from libqtile.config import Click +from libqtile.config import Drag +from libqtile.config import Group +from libqtile.config import Key +from libqtile.config import Screen +from libqtile.utils import guess_terminal + +# this import requires python-xlib to be installed +from Xlib import display as xdisplay + + +class Colors: + background = "#1f2430" + accent = "#002F5F" + + +panel_height = 27 +panel_font_size = 12 + +font = "Ubuntu" +widget_defaults = dict( + font=font, padding=0, fontsize=panel_font_size, borderwidth=0 +) + + +def get_num_monitors(): + try: + display = xdisplay.Display() + screen = display.screen() + resources = screen.root.xrandr_get_screen_resources() + return len(resources.outputs) + except Exception: + # always setup at least one monitor + return 1 + + +num_monitors = get_num_monitors() + +def powerline_arrow(direction, color1, color2): + if direction == "r": + return [ + widget.TextBox( + text=u"\ue0b0", + foreground=color1, + background=color2, + fontsize=panel_height, + font = "NovaMono for Powerline" + ), + widget.Sep(padding=5, linewidth=0, background=color2), + ] + else: + return [ + widget.Sep(padding=7, linewidth=0, background=color1), + widget.TextBox( + text=u"\ue0b2", + foreground=color2, + background=color1, + fontsize=panel_height, + font = "NovaMono for Powerline" + ), + ] + + +def get_panel(monitor_id): + widgets = [ + *powerline_arrow("r", Colors.accent, Colors.background), + widget.GroupBox( + rounded=False, + inactive="#ffffff", + background=Colors.background, + highlight_method="block", + highlight_color=Colors.accent, + this_current_screen_border=Colors.accent, + borderwidth=4, + font="Ubuntu", + ), + *powerline_arrow("r", Colors.background, None), + widget.WindowName(foreground="a0a0a0"), + *powerline_arrow("l", None, Colors.background), + ] + + if monitor_id == 0: + widgets.append( + widget.Systray(icon_size=24, background=Colors.background, padding=5) + ) + + widgets.extend( + [ + *powerline_arrow("l", Colors.background, Colors.accent), + *powerline_arrow("l", Colors.accent, Colors.background), + widget.Volume(borderwidth=0, background=Colors.background, emoji=True), + widget.Volume(borderwidth=0, background=Colors.background, emoji=False), + *powerline_arrow("l", Colors.background, Colors.accent), + widget.Clock( + foreground="#ffffff", + background=Colors.accent, + format="%Y-%m-%d %H:%M:%S ", + ), + widget.Sep(padding=10, linewidth=0, background=Colors.accent), + ] + ) + + return bar.Bar( + widgets, size=panel_height, background=Colors.background, opacity=0.9 + ) + + +screens = [] + +for m in range(num_monitors): + screens.append(Screen(top=get_panel(m))) + + +# @hook.subscribe.screen_change +# def restart_on_randr(ev): +# libqtile.qtile.cmd_restart() + + +@hook.subscribe.client_new +def dialogs(window): + if ( + window.window.get_wm_type() == "dialog" + or window.window.get_wm_transient_for() + ): + window.floating = True + + +@hook.subscribe.client_new +def float_steam(window): + wm_class = window.window.get_wm_class() + w_name = window.window.get_name() + if wm_class == ("Steam", "Steam") and ( + w_name != "Steam" + # w_name == "Friends List" + # or w_name == "Screenshot Uploader" + # or w_name.startswith("Steam - News") + or "PMaxSize" in window.window.get_wm_normal_hints().get("flags", ()) + ): + window.floating = True + + +@hook.subscribe.client_new +def float_firefox(window): + wm_class = window.window.get_wm_class() + w_name = window.window.get_name() + if wm_class == ("Places", "firefox") and w_name == "Library": + window.floating = True + + +@lazy.function +def float_to_front(qtile): + for group in qtile.groups: + for window in group.windows: + if window.floating: + window.cmd_bring_to_front() + + +mod = "mod4" +terminal = guess_terminal() +keys = [ + Key([mod], "h", lazy.layout.left(), desc="Move focus to left"), + Key([mod], "l", lazy.layout.right(), desc="Move focus to right"), + Key([mod], "j", lazy.layout.down(), desc="Move focus down"), + Key([mod], "k", lazy.layout.up(), desc="Move focus up"), + Key([mod], "space", lazy.layout.next(), desc="Move window focus to other window"), + # Move windows between left/right columns or move up/down in current stack. + # Moving out of range in Columns layout will create new column. + Key([mod, "shift"], "h", lazy.layout.shuffle_left(), desc="Move window to the left"), + Key([mod, "shift"], "l", lazy.layout.shuffle_right(), desc="Move window to the right"), + Key([mod, "shift"], "j", lazy.layout.shuffle_down(), desc="Move window down"), + Key([mod, "shift"], "k", lazy.layout.shuffle_up(), desc="Move window up"), + # Grow windows. If current window is on the edge of screen and direction + # will be to screen edge - window would shrink. + Key([mod, "control"], "h", lazy.layout.grow_left(), desc="Grow window to the left"), + Key([mod, "control"], "l", lazy.layout.grow_right(), desc="Grow window to the right"), + Key([mod, "control"], "j", lazy.layout.grow_down(), desc="Grow window down"), + Key([mod, "control"], "k", lazy.layout.grow_up(), desc="Grow window up"), + Key([mod], "n", lazy.layout.normalize(), desc="Reset all window sizes"), + # Toggle between split and unsplit sides of stack. + # Split = all windows displayed + # Unsplit = 1 window displayed, like Max layout, but still with + # multiple stack panes + Key( + [mod, "shift"], + "Return", + lazy.layout.toggle_split(), + desc="Toggle between split and unsplit sides of stack", + ), + Key([mod], "Return", lazy.spawn(terminal), desc="Launch terminal"), + # Toggle between different layouts as defined below + Key([mod], "Tab", lazy.next_layout(), desc="Toggle between layouts"), + Key([mod], "w", lazy.window.kill(), desc="Kill focused window"), + Key([mod, "control"], "r", lazy.reload_config(), desc="Reload the config"), + Key([mod, "control"], "q", lazy.shutdown(), desc="Shutdown Qtile"), + Key([mod], "r", lazy.spawncmd(), desc="Spawn a command using a prompt widget"), +] + + +mouse = [ + Drag( + [mod], + "Button1", + lazy.window.set_position_floating(), + start=lazy.window.get_position(), + ), + Drag( + [mod], + "Button3", + lazy.window.set_size_floating(), + start=lazy.window.get_size(), + ), + Click([mod], "Button2", lazy.window.bring_to_front()), +] + +groups = [Group(i) for i in "123456789"] + +border = dict( + border_width=6, margin=10, single_margin=200, border_focus=Colors.background +) + +layouts = [layout.MonadTall(**border), layout.Columns(**border)] + +main = None +follow_mouse_focus = False +bring_front_click = False +cursor_warp = False +floating_layout = layout.Floating( + float_rules=[ + {"wmclass": "confirm"}, + {"wmclass": "dialog"}, + {"wmclass": "download"}, + {"wmclass": "error"}, + {"wmclass": "file_progress"}, + {"wmclass": "notification"}, + {"wmclass": "splash"}, + {"wmclass": "toolbar"}, + {"wmclass": "confirmreset"}, # gitk + {"wmclass": "makebranch"}, # gitk + {"wmclass": "maketag"}, # gitk + {"wname": "branchdialog"}, # gitk + {"wname": "pinentry"}, # GPG key password entry + {"wmclass": "ssh-askpass"}, # ssh-askpass + ] +) +auto_fullscreen = True +focus_on_window_activation = "smart" + +wmname = "LG3D" + + +@hook.subscribe.startup_once +def startup(): + pass + + # import subprocess + # subprocess.Popen(["picom"]) + # subprocess.Popen(["systemctl", "--user", "import-environment", "DISPLAY"]) + # subprocess.Popen(["xsettingsd"]) + # subprocess.Popen(["nitrogen", "--restore"]) + # subprocess.Popen(["unclutter", "--root"]) + # subprocess.Popen(["nm-applet"]) + # subprocess.Popen(["xautolock", "-time", " 5", "-locker", "screenlock"]) + # subprocess.Popen(["dex", "-a", "-s", "/home/droccia/.config/autostart/"])