]> icculus.org git repositories - mikachu/openbox.git/blob - python/motion.py
merge the C branch into HEAD
[mikachu/openbox.git] / python / motion.py
1 import config, hooks, ob
2 from input import Pointer
3
4 config.add('motion',
5            'edge_resistance',
6            'Edge Resistance',
7            "The amount of resistance to provide to moving a window past a " + \
8            "screen boundary. Specify a value of 0 to disable edge resistance.",
9            'integer',
10            10,
11            min = 0)
12
13 def move(ptrdata, client):
14     def mymove(ptrdata, client):
15         global _moving, _last_pos
16         if ptrdata.action == Pointer.Action_Release:
17             _moveclient.setArea(_moveclient.area(), True) # finalize the move
18             _moving = False
19             Pointer.ungrab()
20         elif ptrdata.action == Pointer.Action_Motion:
21             pos = ptrdata.pos
22
23             x = _pcarea[0] + pos[0] - _presspos[0]
24             y = _pcarea[1] + pos[1] - _presspos[1]
25
26             resist = config.get('motion', 'edge_resistance')
27             if resist:
28                 ca = _moveclient.area()
29                 w, h = ca[2], ca[3]
30                 # use the area based on the struts
31                 sa = ob.Openbox.screenArea(_moveclient.desktop())
32                 l, t = sa[0], sa[1]
33                 r = l+ sa[2] - w
34                 b = t+ sa[3] - h
35                 # left screen edge
36                 if _last_pos[0] >= pos[0] and x < l and x >= l - resist:
37                     x = l
38                 # right screen edge
39                 if _last_pos[0] <= pos[0] and x > r and x <= r + resist:
40                     x = r
41                 # top screen edge
42                 if _last_pos[1] >= pos[1] and y < t and y >= t - resist:
43                     y = t
44                 # right screen edge
45                 if _last_pos[1] <= pos[1] and y > b and y <= b + resist:
46                     y = b
47
48             _moveclient.setArea((x, y, _pcarea[2], _pcarea[3]), False)
49             _last_pos = pos
50
51     global _last_pos, _moving, _pcarea, _presspos, _moveclient
52     if not _moving:
53         _moving = True
54         _pcarea = ptrdata.pressclientarea
55         _presspos = ptrdata.presspos
56         _last_pos = _presspos
57         _moveclient = client
58         Pointer.grab(mymove)
59         mymove(ptrdata, client)
60
61 def resize(ptrdata, client):
62     x, y = ptrdata.pos
63     px, py = ptrdata.presspos
64     cx, cy, cw, ch = ptrdata.pressclientarea
65     dx = x - px
66     dy = y - py
67     if px < cx + cw / 2: # left side
68         dx *= -1
69         cx -= dx
70     if py < cy + ch / 2: # top side
71         dy *= -1
72         cy -= dy
73     cw += dx
74     ch += dy
75     client.setArea((cx, cy, cw, ch))
76
77 _moving = False
78 _moveclient = 0
79 _last_pos = ()
80 _pcarea = ()
81 _presspos = ()