]> icculus.org git repositories - dana/openbox.git/blob - python/rc.py
merge the C branch into HEAD
[dana/openbox.git] / python / rc.py
1 import hooks, ob, keymap, buttonmap, os, sys, input, motion, historyplacement
2 import stackedcycle
3 from input import Pointer
4
5 hooks.managed.append(historyplacement.place)
6
7 _grab = 0
8 def printshit(keydata, client):
9     global _grab
10     print "shit"
11     _grab = not _grab
12     print _grab
13     def gfunc(data, client=None): pass
14     if _grab:
15         input.Keyboard.grab(gfunc)
16         input.Pointer.grab(gfunc)
17     else:
18         input.Keyboard.ungrab()
19         input.Pointer.ungrab()
20
21 def myexec(prog):
22     print "execing: ", prog
23     if (os.fork() == 0):
24         try:
25             os.setsid()
26             os.execl("/bin/sh", "/bin/sh", "-c", prog)
27         except:
28             print str(sys.exc_info()[0]) + ": " + str(sys.exc_info()[1])
29             try:
30                 print "failed to execute '" + prog + "'"
31             except:
32                 print str(sys.exc_info()[0]) + ": " + str(sys.exc_info()[1])
33             os._exit(0)
34
35 def myactivate(c):
36     if ob.Openbox.showingDesktop():
37         ob.Openbox.setShowingDesktop(False)
38     if c.iconic():
39         c.setIconic(False)
40     elif not c.visible():
41         # if its not visible for other reasons, then don't mess with it
42         return
43     if c.shaded():
44         c.setShaded(False)
45     c.focus()
46     c.raiseWindow()
47                                                       
48 hooks.requestactivate.append(myactivate)
49
50 def myfocus(c):
51     if c and c.normal(): c.focus()
52
53 #hooks.showwindow.append(myfocus)
54 hooks.pointerenter.append(myfocus)
55
56 hooks.visible.append(myfocus)
57
58 mykmap=((("C-a", "d"), printshit),
59         (("C-Tab",), stackedcycle.next),
60         (("C-S-Tab",), stackedcycle.previous),
61         (("C-space",), lambda k, c: myexec("xterm")))
62 keymap.set(mykmap)
63
64 def mytogglesticky(client):
65     if client.desktop() == 0xffffffff: d = ob.Openbox.desktop()
66     else: d = 0xffffffff
67     client.setDesktop(d)
68
69 mybmap=(("1", "maximize", Pointer.Action_Click,
70          lambda c: c.setMaximized(not c.maximized())),
71         ("2", "maximize", Pointer.Action_Click,
72          lambda c: c.setMaximizedVert(not c.maximizedVert())),
73         ("3", "maximize", Pointer.Action_Click,
74          lambda c: c.setMaximizedHorz(not c.maximizedHorz())),
75         ("1", "alldesktops", Pointer.Action_Click, mytogglesticky),
76         ("1", "iconify", Pointer.Action_Click,
77          lambda c: c.setIconic(True)),
78         ("1", "icon", Pointer.Action_DoubleClick, ob.Client.close),
79         ("1", "close", Pointer.Action_Click, ob.Client.close),
80         ("1", "titlebar", Pointer.Action_Motion, motion.move),
81         ("1", "handle", Pointer.Action_Motion, motion.move),
82         ("Mod1-1", "frame", Pointer.Action_Click, ob.Client.raiseWindow),
83         ("Mod1-1", "frame", Pointer.Action_Motion, motion.move),
84         ("1", "titlebar", Pointer.Action_Press, ob.Client.raiseWindow),
85         ("1", "handle", Pointer.Action_Press, ob.Client.raiseWindow),
86         ("1", "client", Pointer.Action_Press, ob.Client.raiseWindow),
87         ("2", "titlebar", Pointer.Action_Press, ob.Client.lowerWindow),
88         ("2", "handle", Pointer.Action_Press, ob.Client.lowerWindow),
89         ("Mod1-3", "frame", Pointer.Action_Click, ob.Client.lowerWindow),
90         ("Mod1-3", "frame", Pointer.Action_Motion, motion.resize),
91         ("1", "blcorner", Pointer.Action_Motion, motion.resize),
92         ("1", "brcorner", Pointer.Action_Motion, motion.resize),
93         ("1", "titlebar", Pointer.Action_Press, ob.Client.focus),
94         ("1", "handle", Pointer.Action_Press, ob.Client.focus),
95         ("1", "client", Pointer.Action_Press, ob.Client.focus),
96         ("1", "titlebar", Pointer.Action_DoubleClick,
97          lambda c: c.setShaded(not c.shaded())),
98         ("4", "titlebar", Pointer.Action_Click,
99          lambda c: c.setShaded(True)),
100         ("5", "titlebar", Pointer.Action_Click,
101          lambda c: c.setShaded(False)),
102         ("4", "root", Pointer.Action_Click,
103          lambda c: ob.Openbox.setNextDesktop()),
104         ("5", "root", Pointer.Action_Click,
105          lambda c: ob.Openbox.setPreviousDesktop()),
106         ("Mod1-4", "frame", Pointer.Action_Click,
107          lambda c: ob.Openbox.setNextDesktop()),
108         ("Mod1-5", "frame", Pointer.Action_Click,
109          lambda c: ob.Openbox.setPreviousDesktop()),
110         ("Mod1-4", "root", Pointer.Action_Click,
111          lambda c: ob.Openbox.setNextDesktop()),
112         ("Mod1-5", "root", Pointer.Action_Click,
113          lambda c: ob.Openbox.setPreviousDesktop()))
114 buttonmap.set(mybmap)