import os import re import socket import subprocess from libqtile import bar, layout, widget, hook from libqtile.config import Click, Drag, Group, Key, Match, Screen, Rule from libqtile.command import lazy from libqtile.lazy import lazy from libqtile.widget import Spacer from libqtile import qtile from itertools import cycle from os.path import expanduser # Mod keys mod = "mod4" mod1 = "alt" mod2 = "control" myTerm = "urxvt" home = expanduser('~') + '/' # Workspace and Monitor Functions def window_to_prev_group(qtile): if qtile.currentWindow is not None: i = qtile.groups.index(qtile.currentGroup) qtile.currentWindow.togroup(qtile.groups[i - 1].name) def window_to_next_group(qtile): if qtile.currentWindow is not None: i = qtile.groups.index(qtile.currentGroup) qtile.currentWindow.togroup(qtile.groups[i + 1].name) def window_to_previous_screen(qtile): i = qtile.screens.index(qtile.current_screen) if i != 0: group = qtile.screens[i - 1].group.name qtile.current_window.togroup(group) def window_to_next_screen(qtile): i = qtile.screens.index(qtile.current_screen) if i + 1 != len(qtile.screens): group = qtile.screens[i + 1].group.name qtile.current_window.togroup(group) def switch_screens(qtile): i = qtile.screens.index(qtile.current_screen) group = qtile.screens[i - 1].group qtile.current_screen.set_group(group) # Fuction to start QTile with Xmodmap configuration @hook.subscribe.startup_once def startup_once(): startup_xmodmap = home + '.Xmodmap1' subprocess.Popen('setxkbmap -option caps:escape; xmodmap ' + startup_xmodmap, shell=True) # Keyboard Layer (Xmodmap) Functions my_xmodmaps = [".Xmodmap2", ".Xmodmap1"] xmm_cycle = cycle(my_xmodmaps) def toggle_xmodmap(qtile): current_xmodmap = home + next(xmm_cycle) qtile.cmd_spawn("setxkbmap -option caps:escape") qtile.cmd_spawn("xmodmap " + current_xmodmap) def restore_xmodmap(qtile): qtile.cmd_spawn("setxkbmap -option") keys = [ # Switch between windows Key([mod], "j", lazy.layout.down(), desc="Move focus down"), Key([mod], "k", lazy.layout.up(), desc="Move focus up"), # CHANGE FOCUS BETWEEK STACKS FOR STACK LAYOUT Key([mod, "shift"], "l", lazy.layout.next()), Key([mod, "shift"], "h", lazy.layout.previous()), # 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"], "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], "h", lazy.layout.grow_left(), lazy.layout.shrink(), lazy.layout.decrease_ratio(), lazy.layout.add(), desc="Grow window to the left"), Key([mod], "l", lazy.layout.grow_right(), lazy.layout.grow(), lazy.layout.increase_ratio(), lazy.layout.delete(), desc="Grow window to the right"), # Core Functions Key([mod], "Return", lazy.spawn(myTerm), desc="Launch terminal"), Key([mod], "x", lazy.spawn("shutdown now")), Key([mod, "shift"], "x", lazy.spawn("reboot")), Key([mod], "q", lazy.window.kill(), desc="Kill focused window"), Key([mod, "shift"], "r", lazy.restart(), desc="Restart Qtile"), Key([mod, "shift"], "q", lazy.shutdown(), desc="Shutdown Qtile"), # Toggle between different layouts as defined below Key([mod], "u", lazy.layout.flip()), Key([mod], "i", lazy.window.toggle_fullscreen()), Key([mod], "o", lazy.prev_layout(), desc="Toggle between layouts"), Key([mod], "p", lazy.next_layout()), # Dmenu Key([mod], "d", lazy.spawn("dmenu_run -i -nb '#2F343F' -nf '#6790eb' -sb '#6790eb' -sf '#2F343F' -fn 'NotoMonoRegular:bold:pixelsize=20'")), # General Use Key([mod], "e", lazy.spawn("thunderbird")), Key([mod, "shift"], "Return", lazy.spawn(myTerm + ' -e ranger')), Key([mod], "b", lazy.spawn("system-config-printer")), Key([mod], "n", lazy.spawn("pavucontrol")), Key([mod, "shift"], "m", lazy.spawn("waldl")), Key([mod], "m", lazy.spawn("setbg /home/user/Pictures/Wallpapers")), Key([mod, "shift"], "BackSpace", lazy.spawn("rm /home/user/.bash_history")), # Keyboard Layers Key([], "Alt_L", lazy.function(toggle_xmodmap)), Key([], "Alt_R", lazy.function(restore_xmodmap)), # Screenshots Key([], "Print", lazy.spawn("scrot Screenshot_%Y-%m-%d_%H-%M-%S.png -e 'mv $f ~/Pictures/Screenshots/'")), Key([mod], "a", lazy.spawn("scrot Screenshot_%Y-%m-%d_%H-%M-%S.png -e 'mv $f ~/Pictures/Screenshots/'")), Key([mod], "s", lazy.spawn("scrot -s Screenshot_%Y-%m-%d_%H-%M-%S.png -e 'mv $f ~/Pictures/Screenshots/'")), Key([mod], "z", lazy.spawn("xfce4-screenshooter")), # Toggle Volume Key([], "XF86AudioRaiseVolume", lazy.spawn("amixer set Master 10%+")), Key([], "XF86AudioLowerVolume", lazy.spawn("amixer set Master 10%-")), Key([], "XF86AudioMute", lazy.spawn("amixer set Master 1+ toggle")), Key([mod], "equal", lazy.spawn("amixer set Master 10%+")), Key([mod], "minus", lazy.spawn("amixer set Master 10%-")), Key([mod], "BackSpace", lazy.spawn("amixer set Master 1+ toggle")), # Multimedia Keyes Key([], "XF86AudioStop", lazy.spawn("playerctl stop")), Key([], "XF86AudioPlay", lazy.spawn("playerctl plaY-pause")), Key([], "XF86AudioNext", lazy.spawn("playerctl next")), Key([], "XF86AudioPrev", lazy.spawn("playerctl previous")), Key([mod], "Up", lazy.spawn("playerctl stop")), Key([mod], "Down", lazy.spawn("playerctl play-pause")), Key([mod], "Right", lazy.spawn("playerctl next")), Key([mod], "Left", lazy.spawn("playerctl previous")), # Toggle Backlight Key([], "XF86MonBrightnessUp", lazy.spawn("xbacklight -inc 10")), Key([], "XF86MonBrightnessDown", lazy.spawn("xbacklight -dec 10")), Key([mod, "shift"], "equal", lazy.spawn("xbacklight -inc 10")), Key([mod, "shift"], "minus", lazy.spawn("xbacklight -dec 10")), ] groups = [] # Allocate layouts and labels group_names = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0",] group_layouts = ["monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "modatall",] for i in range(len(group_names)): groups.append( Group( name=group_names[i], layout=group_layouts[i].lower(), )) for i in groups: keys.extend([ # mod1 + letter of group = switch to group Key([mod], i.name, lazy.group[i.name].toscreen(), desc="Switch to group {}".format(i.name)), # mod1 + shift + letter of group = switch to & move focused window to group Key([mod, "shift"], i.name, lazy.window.togroup(i.name, switch_group=True), desc="Switch to & move focused window to group {}".format(i.name)), # Or, use below if you prefer not to switch to that group. # # mod1 + shift + letter of group = move focused window to group Key([mod, "control"], i.name, lazy.window.togroup(i.name), desc="move focused window to group {}".format(i.name)), Key([mod, "shift"], "p", lazy.screen.next_group()), Key([mod, "shift"], "o", lazy.screen.prev_group()), ]) layouts = [ layout.MonadTall(margin=5, border_width=2, border_focus="#5e81ac", border_normal="#4c566a", ratio=0.5), layout.MonadWide(margin=5, border_width=2, border_focus="#5e81ac", border_normal="#4c566a", ratio=0.5), #layout.Matrix(margin=5, border_width=2, border_focus="#5e81ac", border_normal="#4c566a"), #layout.Bsp(margin=5, border_width=2, border_focus="#5e81ac", border_normal="#4c566a"), #layout.Floating(margin=5, border_width=2, border_focus="#5e81ac", border_normal="#4c566a"), layout.RatioTile(margin=5, border_width=2, border_focus="#5e81ac", border_normal="#4c566a"), layout.Max(), layout.Stack(margin=5, border_width=2, border_focus="#5e81ac", border_normal="#4c566a", num_stacks=2), #layout.Tile(margin=5, border_width=2, border_focus="#5e81ac", border_normal="#4c566a", shift_windows=True), #layout.VerticalTile(margin=5, border_width=2, border_focus="#5e81ac", border_normal="#4c566a"), #layout.Columns(margin=5, border_width=2, border_focus="#5e81ac", border_normal="#4c566a", split=True, num_columns=2), #layout.Zoomy(margin=5), ] # Bar colours def init_colors(): return [["#2E3440", "#2E3440"], # color 0 ["#2E3440", "#2E3440"], # color 1 ["#c0c5ce", "#c0c5ce"], # color 2 ["#fba922", "#fba922"], # color 3 ["#3384d0", "#3384d0"], # color 4 ["#f3f4f5", "#f3f4f5"], # color 5 ["#cd1f3f", "#cd1f3f"], # color 6 ["#62FF00", "#62FF00"], # color 7 ["#6790eb", "#6790eb"], # color 8 ["#a9a9a9", "#a9a9a9"]] # color 9 colors = init_colors() def init_widgets_defaults(): return dict(font="Noto Sans", fontsize = 12, padding = 2, background=colors[1]) widget_defaults = init_widgets_defaults() def init_widgets_list(): prompt = "{0}@{1}: ".format(os.environ["USER"], socket.gethostname()) widgets_list = [ widget.GroupBox( font="Noto Sans", fontsize = 12, margin_y = 3, margin_x = 0, padding_y = 5, padding_x = 4, borderwidth = 0, disable_drag = True, active = colors[9], inactive = colors[5], rounded = False, highlight_method = "text", this_current_screen_border = colors[8], foreground = colors[2], background = colors[1] ), widget.Sep( linewidth = 1, padding = 10, foreground = colors[2], background = colors[1], ), widget.CurrentLayoutIcon( foreground = colors[5], background = colors[1], padding = 0, scale = 0.7 ), widget.CurrentLayout( font = "Noto Sans Bold", foreground = colors[5], background = colors[1], padding = 1, ), widget.Sep( linewidth = 1, padding = 10, foreground = colors[2], background = colors[1], ), widget.WindowName(font="Noto Sans", fontsize = 12, foreground = colors[5], background = colors[1], ), widget.TextBox( text="✏️ ", foreground=colors[6], background=colors[1], mouse_callbacks = {'Button1': lambda: qtile.cmd_spawn(myTerm + ' -e vim /home/user/.config/qtile/config.py')}, padding = 0, fontsize=12, ), widget.Sep( linewidth = 1, padding = 10, foreground = colors[2], background = colors[1], ), widget.TextBox( font="FontAwesome", text="  ", foreground=colors[3], background=colors[1], padding = 0, fontsize=16, mouse_callbacks = {'Button1': lambda: qtile.cmd_spawn(myTerm + ' -e calcurse')}, ), widget.Clock( foreground = colors[5], background = colors[1], fontsize = 12, format="(%a) %Y-%m-%d %H:%M", update_interval = 60, padding = 1, mouse_callbacks = {'Button1': lambda: qtile.cmd_spawn(myTerm + ' -e calcurse')}, ), widget.Sep( linewidth = 1, padding = 10, foreground = colors[2], background = colors[1], ), widget.Battery( font="Noto Sans", update_interval = 5, fontsize = 12, foreground = colors[5], background = colors[1], format="{percent:2.0%}" ), widget.Systray( background=colors[1], icon_size=20, padding = 4, ), ] return widgets_list widgets_list = init_widgets_list() def init_widgets_screen1(): widgets_screen1 = init_widgets_list() return widgets_screen1 def init_widgets_screen2(): widgets_screen2 = init_widgets_list() return widgets_screen2 widgets_screen1 = init_widgets_screen1() widgets_screen2 = init_widgets_screen2() def init_screens(): return [Screen(top=bar.Bar(widgets=init_widgets_screen1(), size=26, opacity=0.8)), Screen(top=bar.Bar(widgets=init_widgets_screen2(), size=26, opacity=0.8))] screens = init_screens() # Drag floating layouts. 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()) ] dgroups_key_binder = None dgroups_app_rules = [] # type: List follow_mouse_focus = True bring_front_click = False cursor_warp = False floating_layout = layout.Floating(float_rules=[ # Run the utility of `xprop` to see the wm class and name of an X client. *layout.Floating.default_float_rules, Match(wm_class='confirmreset'), # gitk Match(wm_class='makebranch'), # gitk Match(wm_class='maketag'), # gitk Match(wm_class='ssh-askpass'), # ssh-askpass Match(title='branchdialog'), # gitk Match(title='pinentry'), # GPG key password entry ]) auto_fullscreen = True focus_on_window_activation = "smart" reconfigure_screens = True # If things like steam games want to auto-minimize themselves when losing # focus, should we respect this or not? auto_minimize = True # XXX: Gasp! We're lying here. In fact, nobody really uses or cares about this # string besides java UI toolkits; you can see several discussions on the # mailing lists, GitHub issues, and other WM documentation that suggest setting # this string if your java app doesn't work correctly. We may as well just lie # and say that we're a working one by default. # # We choose LG3D to maximize irony: it is a 3D non-reparenting WM written in # java that happens to be on java's whitelist. wmname = "LG3D"