From The Compiler, 5 Years ago, written in Python.
Embed
  1. #!/usr/bin/python
  2.  
  3. import herbstclient
  4. import subprocess
  5. import os
  6. import os.path
  7.  
  8. hc = herbstclient.Client()
  9.  
  10. def bind(key, *args, ctrl=False, shift=False, alt=False, mouse=False):
  11.     keys = []
  12.     if ctrl:
  13.         keys.append('Control')
  14.     if shift:
  15.         keys.append('Shift')
  16.     if alt:
  17.         keys.append('Mod1')
  18.     keys.append(key)
  19.     if mouse:
  20.         return hc.mousebind('-'.join(keys), *args)
  21.     else:
  22.         return hc.keybind('-'.join(keys), *args)
  23.  
  24. def chain(*cmds, sep='|'):
  25.     out = ['chain', sep]
  26.     for cmd in cmds:
  27.         out += cmd
  28.         out.append(sep)
  29.     return out
  30.  
  31. def homebin(path):
  32.     return os.path.join(os.environ['HOME'], 'bin', path)
  33.  
  34. def call(cmd):
  35.     return subprocess.Popen(cmd, shell=True)
  36.  
  37. call('feh --no-fehbg --bg-center ~/.config/herbstluftwm/wallpaper.png')
  38.  
  39. # colors
  40. hc.set('frame_border_active_color', '#afdf5f')
  41. hc.set('frame_border_normal_color', '#afdf87')
  42. hc.set('frame_bg_normal_color', '#00aaee')
  43. hc.set('frame_bg_active_color', '#00aaee')
  44. hc.set('frame_bg_transparent', True)
  45. hc.set('window_border_normal_color', '#afafdf')
  46. hc.set('window_border_active_color', '#df8787')
  47.  
  48. # Look
  49. hc.set('always_show_frame', False)
  50. hc.set('gapless_grid', True)
  51. hc.set('default_frame_layout', 3)
  52. hc.set('focus_follows_mouse', True)
  53. hc.set('raise_on_focus', False)
  54. hc.set('raise_on_click', True)
  55. hc.set('smart_frame_surroundings', True)
  56. hc.set('smart_window_surroundings', True)
  57. hc.set('tree_style', '╾│ ├╰╼─╮')
  58. hc.set('swap_monitors_to_get_tag', False)
  59. hc.set('frame_transparent_width', False)
  60.  
  61. # Rules
  62. hc.unrule('-F')
  63. hc.rule('focus=on') # normally focus new clients
  64. # Don't manage docks and notifications
  65. hc.rule('windowtype~_NET_WM_WINDOW_TYPE_(NOTIFICATION|DOCK)', 'manage=off')
  66. hc.rule('class=Cellwriter', 'manage=off') # Don't manage cellwriter
  67. hc.rule('class=Onboard', 'manage=off')
  68. # Pseudotile dialogs and splashes
  69. hc.rule('windowtype~_NET_WM_WINDOW_TYPE_(DIALOG|UTILITY|SPLASH)',
  70.         'pseudotile=on')
  71. # Don't pseudotile file chooser dialogs
  72. hc.rule('windowrole=GtkFileChooserDialog' 'pseudotile=off')
  73.  
  74. # Settings which draw to the screen finished
  75. hc.unlock()
  76.  
  77. # Tags
  78.  
  79. tags = [] # list of (name: key) tuples
  80. for i in range(1, 10):
  81.     tags.append((i, str(i)))
  82.  
  83. try:
  84.     hc.rename('default', tags[0][0])
  85. except herbstclient.HerbstError:
  86.     pass
  87.  
  88. for (tag, key) in tags:
  89.     hc.add(tag)
  90.     bind(key, 'use', tag)
  91.     bind(key, 'move', tag, shift=True)
  92.  
  93. call('~/scripts/autorun.sh')
  94.  
  95. # keybindings
  96.  
  97. bind('q', 'quit', shift=True)
  98. bind('r', 'reload', shift=True)
  99. bind('c', 'close', shift=True)
  100. bind('Return', 'spawn', 'urxvtcd')
  101. bind('d', 'spawn', 'bash -c \'DMENU_OPTIONS="-nf #d0d0d0 -nb #4e4e4e -sf '
  102.                    '#b2b2b2 -sb #3a3a3a" dmenu-launch\'')
  103.  
  104. # layouting
  105.  
  106. bind('r', 'remove')
  107. bind('space', 'cycle_layout', 1)
  108. bind('u', 'split', 'vertical', 0.5)
  109. bind('s', 'floating', 'toggle')
  110. bind('f', 'fullscreen', 'toggle')
  111. bind('p', 'pseudotile', 'toggle')
  112.  
  113. # resizing
  114. resizestep = 0.05
  115. bind('h', 'resize', 'left', '+{}'.format(resizestep), ctrl=True)
  116. bind('j', 'resize', 'down', '+{}'.format(resizestep), ctrl=True)
  117. bind('k', 'resize', 'up', '+{}'.format(resizestep), ctrl=True)
  118. bind('l', 'resize', 'right', '+{}'.format(resizestep), ctrl=True)
  119.  
  120. # mouse
  121. bind('Button1', 'move', mouse=True)
  122. bind('Button2', 'resize', mouse=True)
  123. bind('Button3', 'zoom', mouse=True)
  124.  
  125. # focus
  126. bind('t', 'raise')
  127. bind('BackSpace', 'cycle_monitor')
  128. bind('Tab', 'cycle_all', '+1')
  129. bind('Tab', 'cycle_all', '-1', shift=True)
  130. bind('c', 'cycle')
  131. bind('h', 'focus', 'left')
  132. bind('j', 'focus', 'down')
  133. bind('k', 'focus', 'up')
  134. bind('l', 'focus', 'right')
  135. bind('h', 'focus', 'shift', 'left', shift=True)
  136. bind('j', 'focus', 'shift', 'down', shift=True)
  137. bind('k', 'focus', 'shift', 'up', shift=True)
  138. bind('l', 'focus', 'shift', 'right', shift=True)
  139.  
  140. # Utils
  141. bind('y', 'spawn', homebin('utf8select.sh'))
  142. bind('t', 'spawn', homebin('xojtex'))
  143.  
  144. # Volume keys
  145. hc.keybind('XF86AudioLowerVolume', 'spawn', homebin('volume/vol.sh'),
  146.            'decrease')
  147. hc.keybind('XF86AudioRaiseVolume', 'spawn', homebin('volume/vol.sh'),
  148.            'increase')
  149. hc.keybind('XF86AudioMute', 'spawn', homebin('volume/vol.sh'), 'mute')
  150.  
  151. # Rotate key
  152. hc.keybind('XF86RotateWindows', 'spawn', homebin('xrotate'), 'toggle')
  153.  
  154. # Thinkpad back/forward keys
  155. hc.keybind('Shift-XF86Back', 'spawn', homebin('tagswitch'), 'prev')
  156. hc.keybind('Shift-XF86Forward', 'spawn', homebin('tagswitch'), 'next')
  157. hc.keybind('XF86Back', 'use_index', '-1')
  158. hc.keybind('XF86Forward', 'use_index', '+1')
  159.  
  160. # Fn + F4
  161. hc.keybind('XF86ScreenSaver', *chain(
  162.     ['spawn', 'xset', 'dpms', 'force', 'off'],
  163.     ['spawn', 'xscreensaver-command', '-lock']))
  164. # ThinkVantage-Key
  165. hc.keybind('XF86Launch1', 'spawn', 'urxvtcd')
  166. hc.keybind('XF86Launch2', 'spawn', homebin('onboardctl'), 'toggle')
  167.  
  168. # Fix java
  169. hc.setenv('_JAVA_AWT_WM_NONREPARENTING', 1)
  170.  
  171. # Fix xdg-open
  172. hc.setenv('DE', 'gnome')
  173. hc.setenv('BROWSER', 'dwb')
  174.  
  175. # No beeps
  176. call('xset -b')