Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.60 KB | None | 0 0
  1. from libqtile.config import Key, Screen, Group, Drag, Click
  2. from libqtile.command import lazy
  3. from libqtile import layout, bar, widget
  4. from pulsectl import Pulse
  5. from contextlib import contextmanager
  6. import xcffib
  7. import xcffib.xproto
  8. from PIL import Image
  9. from datetime import datetime
  10. from os.path import expanduser, join, exists
  11. import string
  12. import random
  13.  
  14.  
  15. SCREENSHOT_DIR = expanduser('~/Pictures')
  16.  
  17.  
  18. @contextmanager
  19. def cap_pulse():
  20. with Pulse('qtile-config') as pulse:
  21. yield pulse
  22.  
  23.  
  24. def do_with_all_sinks(cb):
  25. with cap_pulse() as pulse:
  26. for obj in pulse.sink_list():
  27. cb(pulse, obj)
  28.  
  29.  
  30. def _change_volume(inc):
  31. def cb(pulse, obj):
  32. obj.volume.values = [min(1, max(0, v + inc)) for v in obj.volume.values]
  33. pulse.volume_set(obj, obj.volume)
  34.  
  35. do_with_all_sinks(cb)
  36.  
  37.  
  38. def audio_mute(qtile):
  39. def cb(pulse, obj):
  40. pulse.mute(obj, mute=not obj.mute)
  41.  
  42. do_with_all_sinks(cb)
  43.  
  44.  
  45. def audio_raise_volume(qtile):
  46. _change_volume(0.1)
  47.  
  48.  
  49. def audio_lower_volume(qtile):
  50. _change_volume(-0.1)
  51.  
  52.  
  53. def _pick_screenshot_name():
  54. def make_fname():
  55. return join(SCREENSHOT_DIR, 'screenshot ' + sdate + tail + '.png')
  56.  
  57. tail, sdate = '', datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  58. while exists(make_fname()):
  59. tail = ' ' + ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(6))
  60. return make_fname()
  61.  
  62.  
  63. def take_screenshot(qtile):
  64. screen = qtile.conn.default_screen
  65. width, height = screen.width_in_pixels, screen.height_in_pixels
  66. reply = qtile.conn.conn.core.GetImage(
  67. xcffib.xproto.ImageFormat.ZPixmap,
  68. qtile.root.wid,
  69. 0, 0, width, height,
  70. 0xFFFFFFFF
  71. ).reply()
  72. im = Image.frombytes('RGBX', (width, height), bytes(reply.data.list), 'raw', 'BGRX').convert('RGB')
  73. with open(_pick_screenshot_name(), 'wb') as f:
  74. im.save(f, format='png')
  75.  
  76.  
  77. mod = "mod4"
  78.  
  79. keys = [
  80. # Switch between windows in current stack pane
  81. Key([mod], "k", lazy.layout.down()),
  82. Key([mod], "j", lazy.layout.up()),
  83.  
  84. # Move windows up or down in current stack
  85. Key([mod, "control"], "k", lazy.layout.shuffle_down()),
  86. Key([mod, "control"], "j", lazy.layout.shuffle_up()),
  87.  
  88. # Switch window focus to other pane(s) of stack
  89. Key([mod], "space", lazy.layout.next()),
  90.  
  91. # Swap panes of split stack
  92. Key([mod, "shift"], "space", lazy.layout.rotate()),
  93.  
  94. # Toggle between split and unsplit sides of stack.
  95. # Split = all windows displayed
  96. # Unsplit = 1 window displayed, like Max layout, but still with
  97. # multiple stack panes
  98. Key([mod, "shift"], "Return", lazy.layout.toggle_split()),
  99.  
  100. # Toggle between different layouts as defined below
  101. Key([mod], "Tab", lazy.next_layout()),
  102. Key([mod], "w", lazy.window.kill()),
  103.  
  104. Key([mod, "control"], "r", lazy.restart()),
  105. Key([mod, "control"], "q", lazy.shutdown()),
  106. Key([mod], "r", lazy.spawncmd()),
  107. Key([mod], "F10", lazy.window.toggle_floating()),
  108. Key([mod], "F11", lazy.window.toggle_fullscreen()),
  109.  
  110. Key([], "XF86AudioMute", lazy.function(audio_mute)),
  111. Key([], "XF86AudioRaiseVolume", lazy.function(audio_raise_volume)),
  112. Key([], "XF86AudioLowerVolume", lazy.function(audio_lower_volume)),
  113.  
  114. Key([mod], "Return", lazy.spawn("gnome-terminal")),
  115. Key([], "XF86HomePage", lazy.spawn("firefox")),
  116. Key([], "XF86Tools", lazy.spawn("audacious")),
  117. Key([], "XF86Mail", lazy.spawn("slack")),
  118. Key([], "XF86Explorer", lazy.spawn("nautilus")),
  119.  
  120. Key([mod], "Print", lazy.function(take_screenshot)),
  121. Key([mod, "control"], "Print", lazy.spawn("shutter -f")),
  122. ]
  123.  
  124. groups = [Group(i) for i in "asdfgh".upper()]
  125.  
  126. for i in groups:
  127. # mod1 + letter of group = switch to group
  128. keys.append(Key([mod], i.name.lower(), lazy.group[i.name].toscreen()))
  129.  
  130. # mod1 + shift + letter of group = switch to & move focused window to group
  131. keys.append(Key([mod, "shift"], i.name.lower(), lazy.window.togroup(i.name)))
  132.  
  133. layouts = [
  134. layout.Max(),
  135. layout.Stack(num_stacks=2)
  136. ]
  137.  
  138. widget_defaults = dict(
  139. font='Ubuntu Mono',
  140. fontsize=16,
  141. padding=3,
  142. )
  143.  
  144. screens = [
  145. Screen(
  146. bottom=bar.Bar(
  147. [
  148. widget.GroupBox(disable_drag=True),
  149. widget.Prompt(),
  150. widget.WindowName(font='Ubuntu', fontsize=16, padding=3),
  151. # widget.Notify(),
  152. widget.Systray(),
  153. widget.Clock(format='%A %H:%M'),
  154. ],
  155. 30,
  156. ),
  157. ),
  158. ]
  159.  
  160. # Drag floating layouts.
  161. mouse = [
  162. Drag([mod], "Button1", lazy.window.set_position_floating(), start=lazy.window.get_position()),
  163. Drag([mod], "Button3", lazy.window.set_size_floating(), start=lazy.window.get_size()),
  164. Click([mod], "Button2", lazy.window.bring_to_front()),
  165. Drag([], "Button8", lazy.window.set_position_floating(), start=lazy.window.get_position()),
  166. Drag([], "Button9", lazy.window.set_size_floating(), start=lazy.window.get_size()),
  167. ]
  168.  
  169. dgroups_key_binder = None
  170. dgroups_app_rules = []
  171. main = None
  172. follow_mouse_focus = True
  173. bring_front_click = False
  174. cursor_warp = False
  175. floating_layout = layout.Floating()
  176. auto_fullscreen = True
  177. focus_on_window_activation = "smart"
  178.  
  179. # XXX: Gasp! We're lying here. In fact, nobody really uses or cares about this
  180. # string besides java UI toolkits; you can see several discussions on the
  181. # mailing lists, github issues, and other WM documentation that suggest setting
  182. # this string if your java app doesn't work correctly. We may as well just lie
  183. # and say that we're a working one by default.
  184. #
  185. # We choose LG3D to maximize irony: it is a 3D non-reparenting WM written in
  186. # java that happens to be on java's whitelist.
  187. wmname = "LG3D"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement