Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from libqtile.config import Key, Screen, Group, Drag, Click
- from libqtile.command import lazy
- from libqtile import layout, bar, widget
- from pulsectl import Pulse
- from contextlib import contextmanager
- import xcffib
- import xcffib.xproto
- from PIL import Image
- from datetime import datetime
- from os.path import expanduser, join, exists
- import string
- import random
- SCREENSHOT_DIR = expanduser('~/Pictures')
- @contextmanager
- def cap_pulse():
- with Pulse('qtile-config') as pulse:
- yield pulse
- def do_with_all_sinks(cb):
- with cap_pulse() as pulse:
- for obj in pulse.sink_list():
- cb(pulse, obj)
- def _change_volume(inc):
- def cb(pulse, obj):
- obj.volume.values = [min(1, max(0, v + inc)) for v in obj.volume.values]
- pulse.volume_set(obj, obj.volume)
- do_with_all_sinks(cb)
- def audio_mute(qtile):
- def cb(pulse, obj):
- pulse.mute(obj, mute=not obj.mute)
- do_with_all_sinks(cb)
- def audio_raise_volume(qtile):
- _change_volume(0.1)
- def audio_lower_volume(qtile):
- _change_volume(-0.1)
- def _pick_screenshot_name():
- def make_fname():
- return join(SCREENSHOT_DIR, 'screenshot ' + sdate + tail + '.png')
- tail, sdate = '', datetime.now().strftime('%Y-%m-%d %H:%M:%S')
- while exists(make_fname()):
- tail = ' ' + ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(6))
- return make_fname()
- def take_screenshot(qtile):
- screen = qtile.conn.default_screen
- width, height = screen.width_in_pixels, screen.height_in_pixels
- reply = qtile.conn.conn.core.GetImage(
- xcffib.xproto.ImageFormat.ZPixmap,
- qtile.root.wid,
- 0, 0, width, height,
- 0xFFFFFFFF
- ).reply()
- im = Image.frombytes('RGBX', (width, height), bytes(reply.data.list), 'raw', 'BGRX').convert('RGB')
- with open(_pick_screenshot_name(), 'wb') as f:
- im.save(f, format='png')
- mod = "mod4"
- keys = [
- # Switch between windows in current stack pane
- 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()),
- # Switch window focus to other pane(s) of stack
- Key([mod], "space", lazy.layout.next()),
- # Swap panes of split stack
- Key([mod, "shift"], "space", lazy.layout.rotate()),
- # 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()),
- # Toggle between different layouts as defined below
- Key([mod], "Tab", lazy.next_layout()),
- Key([mod], "w", lazy.window.kill()),
- Key([mod, "control"], "r", lazy.restart()),
- Key([mod, "control"], "q", lazy.shutdown()),
- Key([mod], "r", lazy.spawncmd()),
- Key([mod], "F10", lazy.window.toggle_floating()),
- Key([mod], "F11", lazy.window.toggle_fullscreen()),
- Key([], "XF86AudioMute", lazy.function(audio_mute)),
- Key([], "XF86AudioRaiseVolume", lazy.function(audio_raise_volume)),
- Key([], "XF86AudioLowerVolume", lazy.function(audio_lower_volume)),
- Key([mod], "Return", lazy.spawn("gnome-terminal")),
- Key([], "XF86HomePage", lazy.spawn("firefox")),
- Key([], "XF86Tools", lazy.spawn("audacious")),
- Key([], "XF86Mail", lazy.spawn("slack")),
- Key([], "XF86Explorer", lazy.spawn("nautilus")),
- Key([mod], "Print", lazy.function(take_screenshot)),
- Key([mod, "control"], "Print", lazy.spawn("shutter -f")),
- ]
- groups = [Group(i) for i in "asdfgh".upper()]
- for i in groups:
- # mod1 + letter of group = switch to group
- keys.append(Key([mod], i.name.lower(), lazy.group[i.name].toscreen()))
- # mod1 + shift + letter of group = switch to & move focused window to group
- keys.append(Key([mod, "shift"], i.name.lower(), lazy.window.togroup(i.name)))
- layouts = [
- layout.Max(),
- layout.Stack(num_stacks=2)
- ]
- widget_defaults = dict(
- font='Ubuntu Mono',
- fontsize=16,
- padding=3,
- )
- screens = [
- Screen(
- bottom=bar.Bar(
- [
- widget.GroupBox(disable_drag=True),
- widget.Prompt(),
- widget.WindowName(font='Ubuntu', fontsize=16, padding=3),
- # widget.Notify(),
- widget.Systray(),
- widget.Clock(format='%A %H:%M'),
- ],
- 30,
- ),
- ),
- ]
- # 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()),
- Drag([], "Button8", lazy.window.set_position_floating(), start=lazy.window.get_position()),
- Drag([], "Button9", lazy.window.set_size_floating(), start=lazy.window.get_size()),
- ]
- dgroups_key_binder = None
- dgroups_app_rules = []
- main = None
- follow_mouse_focus = True
- bring_front_click = False
- cursor_warp = False
- floating_layout = layout.Floating()
- auto_fullscreen = True
- focus_on_window_activation = "smart"
- # 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"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement