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