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