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