new scripts for new script structure
[mikachu/openbox.git] / scripts / behavior.py
1 ###############################################################################
2 ### Functions for setting up some default behaviors. This includes the      ###
3 ### default bindings for clicking on various parts of a window, the         ###
4 ### titlebar buttons, and bindings for the scroll wheel on your mouse.      ###
5 ###############################################################################
6
7 import ob
8 import callbacks
9
10 def setup_window_clicks():
11     """Sets up the default bindings for various mouse buttons for various
12        contexts.
13        This includes:
14         * Alt-left drag anywhere on a window will move it
15         * Alt-right drag anywhere on a window will resize it
16         * Left drag on a window's titlebar/handle will move it
17         * Left drag on a window's handle grips will resize it
18         * Alt-left press anywhere on a window's will raise it to the front of
19           its stacking layer.
20         * Left press on a window's titlebar/handle will raise it to the front
21           of its stacking layer.
22         * Alt-middle click anywhere on a window's will lower it to the bottom
23           of its stacking layer.
24         * Middle click on a window's titlebar/handle will lower it to the
25           bottom of its stacking layer.
26         * Double-left click on a window's titlebar will toggle shading it
27     """
28     ob.mbind("A-Left", ob.MouseContext.Frame,
29              ob.MouseAction.Motion, callbacks.move)
30     ob.mbind("Left", ob.MouseContext.Titlebar,
31              ob.MouseAction.Motion, callbacks.move)
32     ob.mbind("Left", ob.MouseContext.Handle,
33              ob.MouseAction.Motion, callbacks.move)
34
35     ob.mbind("A-Right", ob.MouseContext.Frame,
36              ob.MouseAction.Motion, callbacks.resize)
37     ob.mbind("Left", ob.MouseContext.Grip,
38              ob.MouseAction.Motion, callbacks.resize)
39
40     ob.mbind("Left", ob.MouseContext.Titlebar,
41              ob.MouseAction.Press, callbacks.raise_win)
42     ob.mbind("Left", ob.MouseContext.Handle,
43              ob.MouseAction.Press, callbacks.raise_win)
44     ob.mbind("A-Left", ob.MouseContext.Frame,
45              ob.MouseAction.Press, callbacks.raise_win)
46     ob.mbind("A-Middle", ob.MouseContext.Frame,
47              ob.MouseAction.Click, callbacks.lower_win)
48     ob.mbind("Middle", ob.MouseContext.Titlebar,
49              ob.MouseAction.Click, callbacks.lower_win)
50     ob.mbind("Middle", ob.MouseContext.Handle,
51              ob.MouseAction.Click, callbacks.lower_win)
52
53     ob.mbind("Left", ob.MouseContext.Titlebar,
54              ob.MouseAction.DoubleClick, callbacks.toggle_shade)
55
56 def setup_window_buttons():
57     """Sets up the default behaviors for the buttons in the window titlebar."""
58     ob.mbind("Left", ob.MouseContext.AllDesktopsButton,
59              ob.MouseAction.Click, callbacks.toggle_all_desktops)
60     ob.mbind("Left", ob.MouseContext.CloseButton,
61              ob.MouseAction.Click, callbacks.close)
62     ob.mbind("Left", ob.MouseContext.IconifyButton,
63              ob.MouseAction.Click, callbacks.iconify)
64
65 def setup_scroll():
66     """Sets up the default behaviors for the mouse scroll wheel.
67        This includes:
68         * scrolling on a window titlebar will shade/unshade it
69         * alt-scrolling anywhere will switch to the next/previous desktop
70         * control-alt-scrolling on a window will send it to the next/previous
71           desktop, and switch to the desktop with the window
72     """
73     ob.mbind("Up", ob.MouseContext.Titlebar,
74              ob.MouseAction.Click, callbacks.shade)
75     ob.mbind("Down", ob.MouseContext.Titlebar,
76              ob.MouseAction.Click, callbacks.unshade)
77
78     ob.mbind("A-Up", ob.MouseContext.Frame,
79              ob.MouseAction.Click, callbacks.next_desktop)
80     ob.mbind("A-Up", ob.MouseContext.Root,
81              ob.MouseAction.Click, callbacks.next_desktop)
82     ob.mbind("A-Down", ob.MouseContext.Frame,
83              ob.MouseAction.Click, callbacks.prev_desktop)
84     ob.mbind("A-Down", ob.MouseContext.Root,
85              ob.MouseAction.Click, callbacks.prev_desktop)
86
87     ob.mbind("C-A-Up", ob.MouseContext.Frame,
88              ob.MouseAction.Click, callbacks.send_to_next_desktop)
89     ob.mbind("C-A-Down", ob.MouseContext.Frame,
90              ob.MouseAction.Click, callbacks.send_to_prev_desktop)
91
92 print "Loaded behavior.py"