2009-05-22 00:26:31 +04:00
|
|
|
import operator
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import traceback
|
|
|
|
|
|
|
|
import pygmi
|
|
|
|
from pygmi import *
|
2009-10-10 04:34:23 +04:00
|
|
|
from pygmi import event
|
2009-05-22 00:26:31 +04:00
|
|
|
|
|
|
|
identity = lambda k: k
|
|
|
|
|
2009-08-31 00:00:22 +04:00
|
|
|
# Begin Configuration
|
|
|
|
#
|
|
|
|
# Note: This file loads ~/.wmii/wmiirc_local.py if it exists.
|
|
|
|
# Configuration should be placed in that file, and this file
|
|
|
|
# left unmodified, if possible. wmiirc_local should import
|
|
|
|
# wmiirc or any other modules it needs.
|
|
|
|
|
2009-05-22 00:26:31 +04:00
|
|
|
# Keys
|
2009-10-10 04:34:23 +04:00
|
|
|
keys.defs = dict(
|
2009-05-22 00:26:31 +04:00
|
|
|
mod='Mod4',
|
|
|
|
left='h',
|
|
|
|
down='j',
|
|
|
|
up='k',
|
|
|
|
right='l')
|
|
|
|
|
|
|
|
# Bars
|
|
|
|
noticetimeout=5
|
|
|
|
noticebar=('right', '!notice')
|
|
|
|
|
|
|
|
# Theme
|
|
|
|
background = '#333333'
|
|
|
|
floatbackground='#222222'
|
|
|
|
|
|
|
|
wmii['font'] = 'drift,-*-fixed-*-*-*-*-9-*-*-*-*-*-*-*'
|
|
|
|
wmii['normcolors'] = '#000000', '#c1c48b', '#81654f'
|
|
|
|
wmii['focuscolors'] = '#000000', '#81654f', '#000000'
|
2009-10-10 04:34:23 +04:00
|
|
|
wmii['grabmod'] = keys.defs['mod']
|
2009-05-22 00:26:31 +04:00
|
|
|
wmii['border'] = 2
|
|
|
|
|
|
|
|
def setbackground(color):
|
|
|
|
call('xsetroot', '-solid', color)
|
|
|
|
setbackground(background)
|
|
|
|
|
|
|
|
terminal = 'wmiir', 'setsid', 'xterm'
|
|
|
|
pygmi.shell = os.environ.get('SHELL', 'sh')
|
|
|
|
|
|
|
|
@defmonitor
|
|
|
|
def load(self):
|
|
|
|
return re.sub(r'^.*: ', '', call('uptime')).replace(', ', ' ')
|
|
|
|
@defmonitor
|
|
|
|
def time(self):
|
|
|
|
from datetime import datetime
|
|
|
|
return datetime.now().strftime('%c')
|
|
|
|
|
|
|
|
wmii.colrules = (
|
|
|
|
('gimp', '17+83+41'),
|
|
|
|
('.*', '62+38 # Golden Ratio'),
|
|
|
|
)
|
|
|
|
|
|
|
|
wmii.tagrules = (
|
|
|
|
('MPlayer|VLC', '~'),
|
|
|
|
)
|
|
|
|
|
|
|
|
def unresponsive_client(client):
|
|
|
|
msg = 'The following client is not responding. What would you like to do?'
|
|
|
|
resp = call('wihack', '-transient', client.id,
|
|
|
|
'xmessage', '-nearmouse', '-buttons', 'Kill,Wait', '-print',
|
2009-08-04 00:33:23 +04:00
|
|
|
'%s\n %s' % (msg, client.label))
|
2009-05-22 00:26:31 +04:00
|
|
|
if resp == 'Kill':
|
|
|
|
client.slay()
|
|
|
|
|
|
|
|
# End Configuration
|
|
|
|
|
|
|
|
client.awrite('/event', 'Start wmiirc')
|
|
|
|
|
|
|
|
tags = Tags()
|
2009-10-10 04:34:23 +04:00
|
|
|
events.bind({
|
2009-05-22 23:32:32 +04:00
|
|
|
('Quit', Match('Start', 'wmiirc')): lambda *a: sys.exit(),
|
2009-05-22 00:26:31 +04:00
|
|
|
'CreateTag': tags.add,
|
|
|
|
'DestroyTag': tags.delete,
|
|
|
|
'FocusTag': tags.focus,
|
|
|
|
'UnfocusTag': tags.unfocus,
|
|
|
|
'UrgentTag': lambda args: tags.set_urgent(args.split()[1], True),
|
|
|
|
'NotUrgentTag': lambda args: tags.set_urgent(args.split()[1], False),
|
|
|
|
|
|
|
|
'AreaFocus': lambda args: (args == '~' and
|
|
|
|
(setbackground(floatbackground), True) or
|
|
|
|
setbackground(background)),
|
|
|
|
|
|
|
|
'Unresponsive': lambda args: Thread(target=unresponsive_client,
|
|
|
|
args=(Client(args),)).start(),
|
|
|
|
|
|
|
|
'Notice': lambda args: notice.show(args),
|
|
|
|
|
2009-05-22 23:32:32 +04:00
|
|
|
Match(('LeftBarClick', 'LeftBarDND'), '1'): lambda e, b, tag: tags.select(tag),
|
|
|
|
Match('LeftBarClick', '4'): lambda *a: tags.select(tags.next(True)),
|
|
|
|
Match('LeftBarClick', '5'): lambda *a: tags.select(tags.next()),
|
2009-05-22 00:26:31 +04:00
|
|
|
|
2009-05-22 23:32:32 +04:00
|
|
|
Match('LeftBarMouseDown', 3): lambda e, n, tag: clickmenu((
|
|
|
|
('Delete', lambda t: Tag(t).delete()),
|
|
|
|
), (tag,)),
|
|
|
|
Match('ClientMouseDown', _, 3): lambda e, client, n: clickmenu((
|
|
|
|
('Delete', lambda c: Client(c).kill()),
|
|
|
|
('Kill', lambda c: Client(c).slay()),
|
|
|
|
('Fullscreen', lambda c: Client(c).set('Fullscreen', 'on')),
|
|
|
|
), (client,)),
|
|
|
|
|
|
|
|
Match('ClientClick', _, 4): lambda e, c, n: Tag('sel').select('up'),
|
|
|
|
Match('ClientClick', _, 5): lambda e, c, n: Tag('sel').select('down'),
|
2009-05-22 00:26:31 +04:00
|
|
|
})
|
|
|
|
|
|
|
|
@apply
|
2009-10-10 04:34:23 +04:00
|
|
|
class Actions(event.Actions):
|
2009-05-22 00:26:31 +04:00
|
|
|
def rehash(self, args=''):
|
|
|
|
program_menu.choices = program_list(os.environ['PATH'].split(':'))
|
2009-10-03 05:44:50 +04:00
|
|
|
def showkeys(self, args=''):
|
|
|
|
message(keys.help)
|
2009-05-22 00:26:31 +04:00
|
|
|
def quit(self, args=''):
|
|
|
|
wmii.ctl('quit')
|
|
|
|
def eval_(self, args=''):
|
|
|
|
exec args
|
|
|
|
def exec_(self, args=''):
|
|
|
|
wmii['exec'] = args
|
|
|
|
def exit(self, args=''):
|
|
|
|
client.awrite('/event', 'Quit')
|
|
|
|
|
2009-09-30 23:27:26 +04:00
|
|
|
program_menu = Menu(histfile='%s/history.progs' % confpath[0], nhist=5000,
|
2009-05-22 00:26:31 +04:00
|
|
|
action=curry(call, 'wmiir', 'setsid',
|
|
|
|
pygmi.shell, '-c', background=True))
|
2009-09-30 23:27:26 +04:00
|
|
|
action_menu = Menu(histfile='%s/history.actions' % confpath[0], nhist=500,
|
2009-05-22 00:26:31 +04:00
|
|
|
choices=lambda: Actions._choices,
|
|
|
|
action=Actions._call)
|
|
|
|
tag_menu = Menu(histfile='%s/history.tags' % confpath[0], nhist=100,
|
|
|
|
choices=lambda: sorted(tags.tags.keys()))
|
|
|
|
|
2009-05-22 23:32:32 +04:00
|
|
|
def clickmenu(choices, args):
|
|
|
|
ClickMenu(choices=(k for k, v in choices),
|
|
|
|
action=lambda choice: dict(choices).get(choice, identity)(*args)) \
|
|
|
|
.call()
|
2009-05-22 00:26:31 +04:00
|
|
|
|
|
|
|
class Notice(Button):
|
|
|
|
def __init__(self):
|
2009-09-17 17:27:11 +04:00
|
|
|
super(Notice, self).__init__(*noticebar, colors=wmii['normcolors'])
|
2009-05-22 00:26:31 +04:00
|
|
|
self.timer = None
|
|
|
|
|
|
|
|
def tick(self):
|
2009-05-22 23:32:32 +04:00
|
|
|
self.label = ' '
|
2009-05-22 00:26:31 +04:00
|
|
|
|
|
|
|
def write(self, notice):
|
|
|
|
client.awrite('/event', 'Notice %s' % notice.replace('\n', ' '))
|
|
|
|
|
|
|
|
def show(self, notice):
|
|
|
|
if self.timer:
|
|
|
|
self.timer.cancel()
|
|
|
|
self.label = notice
|
|
|
|
from threading import Timer
|
|
|
|
self.timer = Timer(noticetimeout, self.tick)
|
|
|
|
self.timer.start()
|
|
|
|
notice = Notice()
|
|
|
|
|
2009-10-03 05:44:50 +04:00
|
|
|
keys.bind('main', (
|
2009-10-10 00:40:33 +04:00
|
|
|
"Moving around",
|
|
|
|
('%(mod)s-%(left)s', "Select the client to the left",
|
|
|
|
lambda k: Tag('sel').select('left')),
|
|
|
|
('%(mod)s-%(right)s', "Select the client to the right",
|
|
|
|
lambda k: Tag('sel').select('right')),
|
|
|
|
('%(mod)s-%(up)s', "Select the client above",
|
|
|
|
lambda k: Tag('sel').select('up')),
|
|
|
|
('%(mod)s-%(down)s', "Select the client below",
|
|
|
|
lambda k: Tag('sel').select('down')),
|
|
|
|
|
|
|
|
('%(mod)s-space', "Toggle between floating and managed layers",
|
|
|
|
lambda k: Tag('sel').select('toggle')),
|
|
|
|
|
|
|
|
"Moving through stacks",
|
|
|
|
('%(mod)s-Control-%(up)s', "Select the stack above",
|
|
|
|
lambda k: Tag('sel').select('up', stack=True)),
|
|
|
|
('%(mod)s-Control-%(down)s', "Select the stack below",
|
|
|
|
lambda k: Tag('sel').select('down', stack=True)),
|
|
|
|
|
|
|
|
|
|
|
|
"Moving clients around",
|
|
|
|
('%(mod)s-Shift-%(left)s', "Move selected client to the left",
|
|
|
|
lambda k: Tag('sel').send(Client('sel'), 'left')),
|
|
|
|
('%(mod)s-Shift-%(right)s', "Move selected client to the right",
|
|
|
|
lambda k: Tag('sel').send(Client('sel'), 'right')),
|
|
|
|
('%(mod)s-Shift-%(up)s', "Move selected client up",
|
|
|
|
lambda k: Tag('sel').send(Client('sel'), 'up')),
|
|
|
|
('%(mod)s-Shift-%(down)s', "Move selected client down",
|
|
|
|
lambda k: Tag('sel').send(Client('sel'), 'down')),
|
|
|
|
|
|
|
|
('%(mod)s-Shift-space', "Toggle selected client between floating and managed layers",
|
|
|
|
lambda k: Tag('sel').send(Client('sel'), 'toggle')),
|
|
|
|
|
|
|
|
"Client actions",
|
|
|
|
('%(mod)s-f', "Toggle selected client's fullsceen state",
|
|
|
|
lambda k: Client('sel').set('Fullscreen', 'toggle')),
|
|
|
|
('%(mod)s-Shift-c', "Close client",
|
|
|
|
lambda k: Client('sel').kill()),
|
|
|
|
|
|
|
|
"Changing column modes",
|
|
|
|
('%(mod)s-d', "Set column to default mode",
|
|
|
|
lambda k: setattr(Tag('sel').selcol, 'mode', 'default-max')),
|
|
|
|
('%(mod)s-s', "Set column to stack mode",
|
|
|
|
lambda k: setattr(Tag('sel').selcol, 'mode', 'stack-max')),
|
|
|
|
('%(mod)s-m', "Set column to max mode",
|
|
|
|
lambda k: setattr(Tag('sel').selcol, 'mode', 'stack+max')),
|
|
|
|
|
|
|
|
"Running programs",
|
|
|
|
('%(mod)s-a', "Open wmii actions menu",
|
|
|
|
lambda k: action_menu.call()),
|
|
|
|
('%(mod)s-p', "Open program menu",
|
|
|
|
lambda k: program_menu.call()),
|
|
|
|
|
|
|
|
('%(mod)s-Return', "Launch a terminal",
|
|
|
|
lambda k: call(*terminal, background=True)),
|
|
|
|
|
|
|
|
"Tag actions",
|
|
|
|
('%(mod)s-t', "Change to another tag",
|
|
|
|
lambda k: tags.select(tag_menu.call())),
|
|
|
|
('%(mod)s-Shift-t', "Retag the selected client",
|
|
|
|
lambda k: setattr(Client('sel'), 'tags', tag_menu.call())),
|
|
|
|
|
|
|
|
('%(mod)s-n', "Move to the view to the left",
|
|
|
|
lambda k: tags.select(tags.next())),
|
|
|
|
('%(mod)s-b', "Move to the view to the right",
|
|
|
|
lambda k: tags.select(tags.next(True))),
|
2009-10-10 00:40:33 +04:00
|
|
|
('%(mod)s-Shift-n', "Move to the view to the left, take along current client",
|
|
|
|
lambda k: tags.select(tags.next(), take_client=Client('sel'))),
|
|
|
|
('%(mod)s-Shift-b', "Move to the view to the right, take along current client",
|
|
|
|
lambda k: tags.select(tags.next(True), take_client=Client('sel'))),
|
|
|
|
|
2009-10-10 00:40:33 +04:00
|
|
|
('%(mod)s-i', "Move to the newer tag in the tag stack",
|
|
|
|
lambda k: tags.select(tags.NEXT)),
|
|
|
|
('%(mod)s-o', "Move to the older tag in the tag stack",
|
|
|
|
lambda k: tags.select(tags.PREV)),
|
2009-10-10 00:40:33 +04:00
|
|
|
('%(mod)s-Shift-i', "Move to the newer tag in the tag stack, take along current client",
|
|
|
|
lambda k: tags.select(tags.NEXT, take_client=Client('sel'))),
|
|
|
|
('%(mod)s-Shift-o', "Move to the older tag in the tag stack, take along current client",
|
|
|
|
lambda k: tags.select(tags.PREV, take_client=Client('sel'))),
|
|
|
|
|
2009-10-03 05:44:50 +04:00
|
|
|
))
|
2009-05-22 00:26:31 +04:00
|
|
|
def bind_num(i):
|
2009-10-03 05:44:50 +04:00
|
|
|
keys.bind('main', (
|
2009-10-10 00:40:33 +04:00
|
|
|
"Tag actions",
|
|
|
|
('%%(mod)s-%d' % i, "Move to view '%d'" % i,
|
|
|
|
lambda k: tags.select(str(i))),
|
|
|
|
('%%(mod)s-Shift-%d' % i, "Retag selected client with tag '%d'" % i,
|
|
|
|
lambda k: setattr(Client('sel'), 'tags', i)),
|
2009-10-03 05:44:50 +04:00
|
|
|
))
|
2009-05-22 00:26:31 +04:00
|
|
|
map(bind_num, range(0, 10))
|
|
|
|
|
2009-10-03 05:44:50 +04:00
|
|
|
keys.bind('main', (
|
2009-10-10 00:40:33 +04:00
|
|
|
"Changing modes",
|
|
|
|
('%(mod)s-Control-r', "Enter resize mode",
|
|
|
|
lambda k: setattr(keys, 'mode', 'resize')),
|
|
|
|
('%(mod)s-Control-t', "Enter passthrough mode",
|
|
|
|
lambda k: setattr(keys, 'mode', 'passthrough')),
|
2009-10-03 05:44:50 +04:00
|
|
|
));
|
|
|
|
keys.bind('passthrough', (
|
2009-10-10 00:40:33 +04:00
|
|
|
"Changing modes",
|
|
|
|
('%(mod)s-Control-t', "Leave passthrough mode",
|
|
|
|
lambda k: setattr(keys, 'mode', 'main')),
|
2009-10-03 05:44:50 +04:00
|
|
|
));
|
|
|
|
|
|
|
|
keys.bind('resize', (
|
2009-10-10 00:40:33 +04:00
|
|
|
('Escape', "Leave resize mode",
|
|
|
|
lambda k: setattr(keys, 'mode', 'main')),
|
2009-10-03 05:44:50 +04:00
|
|
|
), import_={'main': ('%(mod)s-%(left)s', '%(mod)s-%(right)s',
|
2009-05-23 00:56:01 +04:00
|
|
|
'%(mod)s-%(up)s', '%(mod)s-%(down)s',
|
|
|
|
'%(mod)s-Space')})
|
|
|
|
|
2009-10-03 05:44:50 +04:00
|
|
|
def addresize(mod, desc, cmd, *args):
|
|
|
|
keys.bind('resize', (
|
2009-10-10 00:40:33 +04:00
|
|
|
(mod + '%(left)s', "%s selected client to the left" % desc,
|
|
|
|
lambda k: Tag('sel').ctl(cmd, 'sel sel', 'left',
|
|
|
|
*args)),
|
|
|
|
(mod + '%(right)s', "%s selected client to the right" % desc,
|
|
|
|
lambda k: Tag('sel').ctl(cmd, 'sel sel', 'right',
|
|
|
|
*args)),
|
|
|
|
(mod + '%(up)s', "%s selected client up" % desc,
|
|
|
|
lambda k: Tag('sel').ctl(cmd, 'sel sel', 'up',
|
|
|
|
*args)),
|
|
|
|
(mod + '%(down)s', "%s selected client down" % desc,
|
|
|
|
lambda k: Tag('sel').ctl(cmd, 'sel sel', 'down',
|
|
|
|
*args)),
|
2009-10-03 05:44:50 +04:00
|
|
|
));
|
|
|
|
addresize('', 'Grow', 'grow')
|
|
|
|
addresize('Control-', 'Shrink', 'grow', '-1')
|
|
|
|
addresize('Shift-', 'Nudge', 'nudge')
|
2009-05-23 00:56:01 +04:00
|
|
|
|
2009-05-22 00:26:31 +04:00
|
|
|
Actions.rehash()
|
|
|
|
|
2009-05-22 23:32:32 +04:00
|
|
|
dirs = filter(curry(os.access, _, os.R_OK),
|
|
|
|
('%s/plugins' % dir for dir in confpath))
|
2009-05-22 00:26:31 +04:00
|
|
|
files = filter(re.compile(r'\.py$').match,
|
|
|
|
reduce(operator.add, map(os.listdir, dirs), []))
|
|
|
|
for f in ['wmiirc_local'] + ['plugins.%s' % file[:-3] for file in files]:
|
|
|
|
try:
|
|
|
|
exec 'import %s' % f
|
|
|
|
except Exception, e:
|
|
|
|
traceback.print_exc(sys.stdout)
|
|
|
|
|
2009-10-10 04:34:23 +04:00
|
|
|
events.loop()
|
2009-05-22 00:26:31 +04:00
|
|
|
|
|
|
|
# vim:se sts=4 sw=4 et:
|