Commits

Panagiotis Mavrogiorgos committed 9880ca0

Add qtile configuration.

Comments (0)

Files changed (1)

+from libqtile.config import Key, Screen, Group, Drag, Click, Match
+from libqtile.command import lazy
+from libqtile import layout, bar, widget, hook
+from libqtile.dgroups import simple_key_binder
+
+import sys
+import os
+import re
+import subprocess
+import platform
+import sys
+
+def app_or_group(group, app):
+    """
+    Go to specified group if it exists. Otherwise, run the specified app.  When
+    used in conjunction with dgroups to auto-assign apps to specific groups,
+    this can be used as a way to go to an app if it is already running.
+    """
+    def f(qtile):
+        try:
+            qtile.groupMap[group].cmd_toscreen()
+        except KeyError:
+            qtile.cmd_spawn(app)
+    return f
+
+
+# Global mod key.
+mod = "mod1"
+
+# Helpers
+shift = "shift"
+tab = "Tab"
+control = "control"
+
+mod1 = "mod1"
+mod2 = "mod2"
+mod3 = "mod3"
+mod4 = "mod4"
+
+# global font options
+widget_defaults = dict(
+    font = 'Anonymous Pro',
+    fontsize = 14,
+    padding = 3,
+)
+
+# configuration for one screen
+screens = [
+    Screen(
+        top = bar.Bar([
+            widget.GroupBox(urgent_alert_method='text', **widget_defaults),
+            widget.Prompt(**widget_defaults),
+            widget.WindowName(**widget_defaults),
+            widget.Volume(**widget_defaults),
+            widget.Systray(**widget_defaults),
+            widget.Clock('%d-%m-%Y %a %I:%M %p', **widget_defaults),
+            widget.CurrentLayout(fontsize=10),
+            ],
+            30,
+        ),
+    ),
+]
+
+keys = [
+    # Log out; note that this doesn't use mod3: that's intentional in case mod3
+    # gets hosed (which happens if you unplug and replug your usb keyboard
+    # sometimes, or on ubuntu upgrades). This way you can still log back out
+    # and in gracefully.
+    Key([mod1, control], "q",     lazy.shutdown()),
+    Key([mod1, control], "r",     lazy.restart()),
+
+    # Switch window focus to other pane(s) of stack
+    Key([mod], "h", lazy.layout.previous()),
+    Key([mod], "l", lazy.layout.next()),
+    Key([mod], "k", lazy.layout.down()),
+    Key([mod], "j", lazy.layout.up()),
+    # Move windows up or down in current stack
+    Key([mod, control], "k", lazy.layout.shuffle_down()),
+    Key([mod, control], "j", lazy.layout.shuffle_up()),
+
+    # 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, control], "space", lazy.layout.rotate()),
+    Key([mod, control], "Return", lazy.layout.toggle_split()),
+    Key([mod], "space",         lazy.nextlayout()),
+    #Key([mod, "mod4"], "h",      lazy.to_screen(0)),
+    #Key([mod, "mod4"], "l",      lazy.to_screen(1)),
+    Key([mod], "x",              lazy.window.kill()),
+
+    # interact with prompts
+    Key([mod], "r",              lazy.spawncmd()),
+    Key([mod], "g",              lazy.switchgroup()),
+
+    # start specific apps
+    Key([mod], "w",              lazy.function(app_or_group("www", "firefox"))),
+    Key([mod], "e",              lazy.function(app_or_group("email", "thunderbird"))),
+    Key([mod], "c",              lazy.function(app_or_group("pidgin", "pidgin"))),
+    Key([mod], "s",              lazy.function(app_or_group("skype", "skype"))),
+    Key([mod], "m",              lazy.function(app_or_group("music", "musique"))),
+    Key([mod], "f",              lazy.spawn("spacefm")),
+    Key([mod], "Return",         lazy.spawn("terminator")),
+
+    # Change the volume if our keyboard has keys
+    Key([], "XF86AudioRaiseVolume", lazy.spawn("amixer -c 0 -q set Master 2dB+")),
+    Key([], "XF86AudioLowerVolume", lazy.spawn("amixer -c 0 -q set Master 2dB-")),
+    Key([], "XF86AudioMute", lazy.spawn("amixer -c 0 -q set Master toggle")),
+    #Key([], "XF86AudioPlay", lazy.spawn("clementine --play-pause")),
+    #Key([], "XF86AudioNext", lazy.spawn("clementine --next")),
+    #Key([], "XF86AudioPrev", lazy.spawn("clementine --prev")),
+
+    # also allow changing volume the old fashioned way
+    Key([mod], "equal", lazy.spawn("amixer -c 0 -q set Master 2dB+")),
+    Key([mod], "minus", lazy.spawn("amixer -c 0 -q set Master 2dB-")),
+
+    # allow play pause as well
+    Key([mod], "p",     lazy.spawn("vif.py play_pause")),
+]
+
+# 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())
+]
+
+# Next, we specify group names, and use the group name list to generate an appropriate
+# set of bindings for group switching.
+groups = []
+
+# throwaway groups for random stuff
+for i in ['u', 'i', 'o']:
+    groups.append(Group(i))
+    # mod + letter of group = switch to group
+    keys.append(Key([mod], i, lazy.group[i].toscreen()))
+    # mod + mod4 + letter of group = switch to & move focused window to group
+    keys.append(Key([mod, "mod4"], i, lazy.window.togroup(i)))
+
+# groups with special jobs. I usually navigate to these via my app_or_group
+# function.
+groups.extend([
+    Group('media', spawn='musique', layout='max', persist=False, matches=[Match(wm_class=['Musique', 'Vlc'])]),
+    Group('email', spawn='thunderbird', layout='max', matches=[Match(wm_class=['Thunderbird'])]),
+    Group('www',  spawn='firefox', layout='max', matches=[Match(wm_class=['Firefox', 'google-chrome', 'Google-chrome'])]),
+    Group('skype', spawn='skype', layout='max', persist=False, matches=[Match(wm_class=['Skype'], role=['Buddy List'])]),
+    Group('pidgin', spawn='pidgin', layout='pidgin', persist=False, matches=[Match(wm_class=['Pidgin'], role=['Buddy List'])]),
+])
+
+border_args = dict(
+    border_width=1,
+)
+
+layouts = [
+    layout.Max(**border_args),
+    layout.MonadTall(**border_args),
+    #layout.Stack(stacks=2, **border_args),
+
+    # a layout just for gimp
+    #layout.Slice('left', 192, name='gimp', role='gimp-toolbox',
+         #fallback=layout.Slice('right', 256, role='gimp-dock',
+         #fallback=layout.Stack(stacks=1, **border_args))),
+
+    # a layout for pidgin
+    layout.Slice('right', 256, name='pidgin', role='buddy_list',
+                 fallback=layout.Stack(stacks=1, **border_args),
+                 **border_args),
+
+    #layout.Zoomy(column_width=250, **border_args),
+]
+
+
+main = None
+follow_mouse_focus = True
+cursor_warp = False
+floating_layout = layout.Floating()
+mouse = ()
+auto_fullscreen = True
+
+# Automatically float these types. This overrides the default behavior (which
+# is to also float utility types), but the default behavior breaks our fancy
+# gimp slice layout specified later on.
+#floating_layout = layout.Floating(auto_float_types=[
+  #"notification",
+  #"toolbar",
+  #"splash",
+  #"dialog",
+#])
+
+
+@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.startup
+def keyboard():
+    os.system('setxkbmap -option "grp:switch,grp:alt_shift_toggle,grp_led:scroll" -layout "us,gr"')
+
+
+def is_running(process):
+    s = subprocess.Popen(["ps", "axw"], stdout=subprocess.PIPE)
+    for x in s.stdout:
+        if re.search(process, x):
+            return True
+    return False
+
+
+def execute_once(process):
+    if not is_running(process):
+        return subprocess.Popen(process.split())
+
+
+@hook.subscribe.startup
+def startup():
+    #os.system('feh --bg-scale "/home/myle/Pictures/a magic place.jpg"')
+    execute_once("kbdd")
+    execute_once("parcellite")
+    execute_once("wicd-gtk")
+
+
+def show_shortcuts():
+    key_map = {"mod1": "alt", "mod4": "super"}
+    shortcuts_path = "{0}/{1}".format(os.environ["HOME"], "qtile_shortcuts")
+    shortcuts = open("{0}".format(shortcuts_path), 'w')
+    shortcuts.write("{0:30}| {1:50}\n".format("KEYS COMBINATION", "COMMAND"))
+    shortcuts.write("{0:80}\n".format("=" * 80))
+    for key in keys:
+        key_comb = ""
+        for modifier in key.modifiers:
+            key_comb += key_map.get(modifier, modifier) + "+"
+        key_comb += key.key
+        shortcuts.write("{0:30}| ".format(key_comb))
+        cmd_str = ""
+        for command in key.commands:
+            cmd_str += command.name + " "
+            for arg in command.args:
+                cmd_str += "{0} ".format(repr(arg))
+        shortcuts.write("{0:50}\n".format(cmd_str))
+        shortcuts.write("{0:80}\n".format("-" * 80))
+    shortcuts.close()
+    return lazy.spawn("xterm -wf -e less {0}".format(shortcuts_path))
+
+keys.append(Key([mod], "F1", show_shortcuts()))
+
+
+# vim: tabstop=4 shiftwidth=4 expandtab