]> Dogcows Code - chaz/openbox/blobdiff - scripts/motion.py
off-by-one
[chaz/openbox] / scripts / motion.py
index 1c854eccb5d091043dac5aee5a23211acbb53c95..174f3c8e2bebf93f455161c404e3018ad690e306 100644 (file)
@@ -1,11 +1,16 @@
 ############################################################################
-### Functions that provide callbacks for motion events to move and       ###
-### windows.                                                             ###
+###    Functions that provide callbacks for motion events to move and    ###
+###    resize windows.                                                   ###
 ############################################################################
 
 #############################################################################
 ### Options that can be modified to change the functions' behaviors.      ###
 ###                                                                       ###
+# edge_resistance - the amount of resistance to provide to moving a       ###
+###                 window past a screen boundary. Specify a value of 0   ###
+###                 to disable edge resistance.                           ###
+edge_resistance = 10                                                      ###
+###                                                                       ###
 # move_popup - display a coordinates popup when moving windows.           ###
 move_popup = 1                                                            ###
 ###                                                                       ###
@@ -28,6 +33,20 @@ resize_rubberband = 0                                                     ###
 ###                is, 0 to resize always from the bottom right corner.   ###
 resize_nearest = 1                                                        ###
 ###                                                                       ###
+###                                                                       ###
+# Provides:                                                               ###
+# def move(data):                                                         ###
+#     """Moves the window interactively. This should only be used with    ###
+#        MouseMotion events. If move_popup or move_rubberband is enabled, ###
+#        then the end_move function needs to be bound as well."""         ###
+# def end_move(data):                                                     ###
+#     """Complete the interactive move of a window."""                    ###
+# def resize(data):                                                       ###
+#     """Resizes the window interactively. This should only be used with  ###
+#        MouseMotion events"""                                            ###
+# def end_resize(data):                                                   ###
+#     """Complete the interactive resize of a window."""                  ###
+###                                                                       ###
 #############################################################################
 
 import ob
@@ -73,6 +92,30 @@ def _do_move():
     x = _cx + _dx
     y = _cy + _dy
 
+    global edge_resistance
+    if edge_resistance:
+        fs = _client.frame.size()
+        w = _client.area().width() + fs.left + fs.right
+        h = _client.area().height() + fs.top + fs.bottom
+        # use the area based on the struts
+        area = ob.openbox.screen(_screen).area()
+        l = area.left()
+        r = area.right() - w + 1
+        t = area.top()
+        b = area.bottom() - h + 1
+        # left screen edge
+        if x < l and x >= l - edge_resistance:
+            x = l
+        # right screen edge
+        if x > r and x <= r + edge_resistance:
+            x = r
+        # top screen edge
+        if y < t and y >= t - edge_resistance:
+            y = t
+        # right screen edge
+        if y > b and y <= b + edge_resistance:
+            y = b
+
     global move_rubberband
     if move_rubberband:
         # draw the outline ...
@@ -94,15 +137,15 @@ def _do_move():
             _popwidget.setTexture(style.titlebarFocusBackground())
             _poplabel = otk.Label(_popwidget)
             _poplabel.setTexture(style.labelFocusBackground())
-            _popwidget.show(1)
-        _poplabel.resize(length, font.height())
+        _poplabel.fitString(text)
         _poplabel.setText(text)
-        area = otk.display.screenInfo(_screen).rect()
         _popwidget.update() 
+        area = otk.display.screenInfo(_screen).rect()
         _popwidget.move(area.x() + (area.width() -
                                     _popwidget.width()) / 2,
                         area.y() + (area.height() -
                                     _popwidget.height()) / 2)
+        _popwidget.show(1)
 
 def move(data):
     """Moves the window interactively. This should only be used with
@@ -189,7 +232,6 @@ def _do_resize():
             _popwidget.setTexture(style.titlebarFocusBackground())
             _poplabel = otk.Label(_popwidget)
             _poplabel.setTexture(style.labelFocusBackground())
-            _popwidget.show(1)
         _poplabel.fitString(text)
         _poplabel.setText(text)
         area = otk.display.screenInfo(_screen).rect()
@@ -198,6 +240,7 @@ def _do_resize():
                                     _popwidget.width()) / 2,
                         area.y() + (area.height() -
                                     _popwidget.height()) / 2)
+        _popwidget.show(1)
 
 def resize(data):
     """Resizes the window interactively. This should only be used with
This page took 0.022413 seconds and 4 git commands to generate.