Untitled

 avatar
unknown
plain_text
2 years ago
13 kB
53
Indexable
# Justin's Qtile Config
# Example: https://bitbucket.org/dinodroid/iplaytowin/src/master/.config/qtile/config.py
# Trackpad settings /usr/share/X11/xorg.conf.d/40-libinput.conf
import os
import re
import socket
import subprocess
from typing import List  # noqa: F401
from libqtile.command import lazy
from libqtile import bar, layout, widget, hook, qtile
from libqtile.config import Click, Drag, Group, Key
from libqtile.config import Match, Screen, KeyChord
from libqtile.lazy import lazy
from libqtile.utils import guess_terminal

mod = "mod4"
myConfig = "~/.config/qtile/config.py"
home=os.path.expanduser('~')

def backlight(action):
    def f(qtile):
        brightness = int(subprocess.run(['xbacklight', '-get'],
                                        stdout=subprocess.PIPE).stdout)
        if brightness != 1 or action != 'dec':
            if (brightness > 49 and action == 'dec') \
                                or (brightness > 39 and action == 'inc'):
                subprocess.run(['xbacklight', f'-{action}', '10',
                                '-fps', '10'])
            else:
                subprocess.run(['xbacklight', f'-{action}', '1'])
    return f



## Commands------------------------------------------------------------------

class command:
    terminal        = 'alacritty'
    editor          = 'emacs'
    explorer        = 'thunar'
    browser         = 'brave'
    windowmenu      = 'rofi -show window'
    runmenu         = 'rofi -show run'   # dmenu works too
    programmenu     = 'rofi -show drun'

    def script(scriptname):
        return os.path.join(home, '/.config/qtile/scripts/'+ scriptname)

## Colors-------------------------------------------------------------------

# COLORS FOR THE BAR
col =      [["#282828", "#282828"], # color 0 background
            ["#dfbf83", "#dfbf83"], # color 1 foreground
            ["#a9b665", "#a9b665"], # color 2 green-normal
            ["#7daea3", "#7daea3"], # color 3 blue-normal
            ["#d3869b", "#d3869b"], # color 4 magenta
            ["#89b482", "#89b482"], # color 5 cyan
            ["#dfbf8e", "#dfbf8e"], # color 6 white
            ["#ea6962", "#ea6962"], # color 7 red
            ["#e78a4e", "#e78a4e"], # color 8 yellow
            ["#666666", "#666666"],]# color 9 black

fonts = [
    #        "Roboto Mono Nerd Font Bold",   
            "Fantasque Sans Mono Bold",   
            "Iosevka Nerd Font Bold",
            "Font Awesome"
    ]



## Keybindings-------------------------------------------------------------

keys = [
    # Grow and Shrink 
    Key([mod], "h", 
        lazy.layout.grow(),
        lazy.layout.increase_nmaster(),
        desc="Expand Window"),
    Key([mod], "l", lazy.layout.shrink(),
        lazy.layout.decrease_nmaster(),
        desc="Shrink Window"),

    # Switch between windows
    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 or move up/down
    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"),

    # Screen
    Key([], 'F7', lazy.spawn('xset dpms force off')),
    Key([], 'XF86MonBrightnessUp',   lazy.spawn(command.script("brightnessup")), desc="Brightness Up"),
    Key([], 'XF86MonBrightnessDown', lazy.spawn(command.script("brightnessdown")), desc="Brightness Down"),
    Key([], 'XF86AudioMute', lazy.spawn(command.script("togglemute")), desc="Toggle Mute"),
    Key([], 'XF86AudioLowerVolume', lazy.spawn(command.script("volumedown")), desc="Volume Down"),
    Key([], 'XF86AudioRaiseVolume', lazy.spawn(command.script("volumeup")), desc="Volume Up"),
    Key([], 'Print', lazy.spawn(command.script("screenshotfull")), desc="Screenshot"),
    # Key([mod, "shift"], "Print", lazy.spawn(command.script("screenshotsel")), desc="Screenshot Select"),

    # Command Keymaps --------------------------------------------------
    Key([mod], "c", lazy.spawn(command.editor), desc="Launch Editor"),
    Key([mod], "e", lazy.spawn(command.explorer), desc="Launch Explorer"),

    Key([mod], "r", lazy.spawn(command.runmenu), desc="Launch Run"),
    Key([mod], "p", lazy.spawn(command.programmenu), desc="Launch Drun"),
    Key([mod], "b", lazy.spawn(command.browser), desc="Launch Firefox"),
    Key([mod], "w", lazy.spawn(command.windowmenu), desc="Switch Open Windows"),
   # Key([mod], "s", lazy.spawn(command.script("streamclipboard")), desc="Launch StreamClipboard"),
   # Key([mod], "z", lazy.spawn(command.script("wallpaper")), desc="Change Wallpaper"),
    Key([mod], "Return", lazy.spawn(command.terminal), desc="Launch terminal"),

    # Toggle between different layouts as defined below
    Key([mod], "Tab", lazy.next_layout(), desc="Toggle between layouts"),
    Key([mod, "shift"], "c", 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"),
]

# 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())
#]


group_names = [("爵 ", {'layout': 'monadtall'}),
               (" ", {'layout': 'monadtall'}),
               (" ", {'layout': 'monadtall'}),
               (" ", {'layout': 'monadtall'}),
               (" ", {'layout': 'monadtall'}),
               (" ", {'layout': 'monadtall'})]

groups = [Group(name, **kwargs) for name, kwargs in group_names]

for i, (name, kwargs) in enumerate(group_names, 1):
    keys.append(Key([mod], str(i), lazy.group[name].toscreen()))        
    keys.append(Key([mod, "shift"], str(i), lazy.window.togroup(name))) 


## Layouts---------------------------------------------------------------

    
layout_defaults = dict(margin=15, border_width=2, grow_amount=5, border_focus=col[1][0], border_normal=col[9][0])

layouts = [
    #  layout.Columns(**layout_defaults),
      layout.Max(),
    # Try more layouts by unleashing below layouts.
    # layout.Stack(num_stacks=2),
    # layout.Bsp(),i
    # layout.Matrix(),
      layout.MonadTall(**layout_defaults),
      layout.MonadWide(**layout_defaults),
    # layout.RatioTile(),
    # layout.Tile(**layout_defaults),
    # layout.TreeTab(),
    # layout.VerticalTile(),
    # layout.Zoomy(),
]
# What's this do??
# promp = "{0}@{1}: ".format(os.environ["USER"], socket.gethostname())


# Widgets----------------------------------------------------------------

widget_defaults = dict(font=fonts[1], fontsize=13, padding=5, background=col[0], forground = [1])

extension_defaults = widget_defaults.copy()
def icon_header(icon_text, color, backcolor):
    return widget.TextBox(font=fonts[1],text=icon_text,foreground=color,background=backcolor,padding = 0,fontsize=17)

def icon(icon_text, color, backcolor):
    return widget.TextBox(font=fonts[1],text=icon_text,foreground=color,background=backcolor,padding = 3,fontsize=20)

def powerline(color1, color2):
    return widget.TextBox(fontsize=45,padding=-4,text='',foreground=color1,background=color2)

def customscript(color1, color2, update, script, mousecallbacks):
    return widget.GenPollText(foreground=color1, background=color2, update_interval=update,
                              func=lambda:subprocess.check_output(command.script(script)).decode("utf-8"), mouse_callbacks=mousecallbacks)

# Mouse Callbacks Functions

def runscript(script):
    return lambda:qtile.cmd_spawn(script)

screens = [
    Screen(
        top=bar.Bar(
            [
                # Front Logo
                icon_header('  ', col[1], col[0]),
                widget.Sep(
                    linewidth = 0,
                    padding =5,
                    foreground = col[1],
                    background = col[0]),
             #   widget.Image(filename = "~/.config/qtile/icons/python.png", mouse_callbacks = {}),
                # Get Current Layout Icon
                # widget.CurrentLayoutIcon(scale=0.65, font=fonts[1] ),

                # Get Groups 
                powerline(col[1], col[0]),
                widget.GroupBox(disable_drag=False,active=col[0],inactive=col[9],highlight_method ="line", highlight_color = col[1], this_current_screen_border=col[0],foreground=col[0],background=col[1],fontsize=24,padding=0, margin_x=None, margin_y=3.5, spacing=0,padding_x=-5, padding_y=0),

                # Window Name
                powerline(col[0], col[1]),
                widget.WindowName(padding=5,font=fonts[0],fontsize=14,foreground = col[1],background = col[0]),

                powerline(col[1], col[0]), 
                icon(' ', col[0], col[1]), 
                customscript(col[0], col[1], 30, "pkgupdateavailable", {"Button1": runscript(command.terminal + ' -e htop')}),
                
                # Specs Indicators
                powerline(col[0], col[1]),
                
                icon('﬙ ', col[1], col[0]), 
                customscript(col[1], col[0], 1, "cpupercent", {"Button1": runscript(command.terminal + ' -e htop') }),

                icon(' ', col[1], col[0]), 
                customscript(col[1], col[0], 1, "memused", {"Button1": runscript(command.terminal + ' -e htop') }),

                # System Indicators
                powerline(col[1], col[0]), 
                customscript(col[0], col[1], 1, "volumestatus", {"Button1" : runscript('pavucontrol') } ),
                # widget.Battery(font = font[1], foreground = [4]),

     #           widget.TextBox(text = '',
     #                          background = col[4],
     #                          foreground = col[0],
     #                          padding = 0,
     #                          fontsize = 18
     #                          ),
     #           widget.Battery(
     #               foreground=col[1],
     #              # font=fonts[1],
     #               background=col[4],
     #               low_percentage = .2,
     #               notify_below = .2,
     #               show_short_text = False,
     #               format = '{percent:2.0%}'),
                customscript(col[0], col[1], 1, "batterystatus", {"Button1" : runscript('batterystatus')} ),
                
                # Temperature and Date
                powerline(col[0], col[1]),
                icon('﨎', col[1], col[0]),
                customscript(col[1], col[0], 1000, "temperature", {"Button1" : runscript(command.browser + ' "https://bit.ly/3rsIcPx"') }),
                powerline(col[1], col[0]),
                icon(' ', col[0], col[1]),
                customscript(col[0], col[1], 60, "clock", {"Button1": runscript(command.script('calender')) }), 

                # System Tray
                powerline(col[0], col[1]),
              #  widget.Battery(),
                widget.Systray(background=col[0], padding = 5),
                icon('', col[1], col[0]),
                customscript(col[1], col[0], 1000, "power", {"Button1": runscript(command.terminal + ' -e poweroff')}),
                widget.Sep(
                    linewidth = 0,
                    padding =0,
                    foreground = col[2],
                    background = col[0]),
            ],
            24, opacity=.8, margin=[8,20,0,20]
        ),
    ),
]





dgroups_key_binder = None
dgroups_app_rules = []  # type: List
main = None  # WARNING: this is deprecated and will be removed soon
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"

@hook.subscribe.startup_once
def autostart():
    home = os.path.expanduser('~/.config/qtile/scripts/autostart.sh')
    subprocess.call([home])


# 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 = "Qtile"
Editor is loading...