1
0
mirror of https://github.com/gryf/moveto.git synced 2025-12-17 11:30:21 +01:00

Added readme, fixed in-file docs

This commit is contained in:
2015-01-05 15:32:09 +01:00
parent f0e4ee0817
commit d7a0cb0ecc
2 changed files with 135 additions and 45 deletions

25
README.rst Normal file
View File

@@ -0,0 +1,25 @@
moveto
======
"Moveto" is an simple script, which is acting similar to shortcut Super-Left and
Super-Right in Windows 7, but for WindoMaker with additional stuff. To use it,
simply create the menu entries for two motions (left and right) and assign
shortcuts for them.
Features
--------
There is several thing which may be done using ``moveto.py`` script:
- Window movement.
- Moving window around using pattern: maximized-left to fullscreen to
maximized-right to maximized-left on next available screen on the right or
stop. This way one can move the window across the screens in intuitive way.
- Moved window is aware of the WindowMaker settings regarding covering dock
and miniwindows.
- Mouse cursor is moving along with the window.
- Move (send) mouse cursor to the specified monitor. Monitor name can
- Display currently connected and active monitors (first string (e.g. ``VGA1``,
``LVDS1`` and so on, is the name for the ``--monitor-name`` option)

155
moveto.py
View File

@@ -16,6 +16,9 @@ Calculate possible moves of the window against to the current size and
position. Assuming we have screen layout (two physical monitors in twin view position. Assuming we have screen layout (two physical monitors in twin view
nvidia mode which makes one big screen available) nvidia mode which makes one big screen available)
To illustrate the behaviour, lets analyze following layout. Note, the window
is not maximized:
+---------------------+-----------------------------+--+ +---------------------+-----------------------------+--+
| | | | | | | |
| +--------+ | +--+ | +--------+ | +--+
@@ -24,33 +27,95 @@ nvidia mode which makes one big screen available)
| +--------+ | | | | +--------+ | | |
| | +--+ | | +--+
| | | | | | | |
| screen 0 | screen 1 +--+ | | +--+
| | | | | |
+--+ +--+--+ | +--+ +--+--+ |
| | | | | | | | screen 0 | | | screen 1 |
+--+------------------+--+--+--------------------------+ +--+------------------+--+--+--------------------------+
possible moves of the depicted window would be: Possible moves of the depicted window would be:
1. without resizing: - 'move left' will move window to to the left half on screen 0
- move to the left edge of the screen 0 - 'move right' will move window to to the right half on screen 0
- move to the right edge of the screen 0
- move to the left edge of the screen 1 Let's assume that we chose the latter, so the new layout would be as follow:
- move to the right edge of the screen 1
- move to the screen 1 (don't cross boundary of the +----------+----------+-----------------------------+--+
screen) | | window | | |
- move to the left edge of the screen 1 | | | +--+
- move to the right edge of the screen 1 | | | | |
2. with resizing: | | | +--+
- move to the screen 1 (maximized) | | | | |
- maximize on current screen | | | +--+
- move to screen 0 to the left half | | | | |
- move to screen 0 to the right half | | | +--+
- move to screen 1 to the left half | | | |
- move to screen 1 to the right half +--+ +----------+--+--+ |
| | screen 0 | | | screen 1 |
+--+------------------+--+--+--------------------------+
The possibilities are:
- 'move left' will maximize window on screen 0
- 'move right' will move window to to the left half on screen 1
Move right will end up with following layout. Note, that mouse cursor follow
the window, so possible child windows of the current window should appear on
the screen, where main window is.
+---------------------+--------------+--------------+--+
| | window | | |
| | | +--+
| | | | |
| | | +--+
| | | | |
| | | +--+
| | | | |
| | | +--+
| | | |
+--+ +--+--+--------+ |
| | screen 0 | | | screen 1 |
+--+------------------+--+--+--------------------------+
Again, the possibilities are:
- 'move left' will move window to to the right half on screen 0
- 'move right' will maximize window on screen 1
And, if user keeps pushing window to the right it will need just two more
steps to end up like this:
+---------------------+-----------------------------+--+
| | window | |
| | +--+
| | | |
| | +--+
| | | |
| | +--+
| | | |
| | +--+
| | | |
+--+ +--+--+-----------------------+ |
| | screen 0 | | | screen 1 |
+--+------------------+--+--+--------------------------+
+---------------------+--------------+--------------+--+
| | | window | |
| | | +--+
| | | | |
| | | +--+
| | | | |
| | | +--+
| | | | |
| | | +--+
| | | | |
+--+ +--+--+ +--------------+ |
| | screen 0 | | | screen 1 |
+--+------------------+--+--+--------------------------+
Further moving window to the right will have no effect.
TODO: Make it more flexible with different screen configurations TODO: Make it more flexible with different screen configurations
Author: Roman 'gryf' Dobosz <gryf73@gmail.com> Author: Roman "gryf" Dobosz <gryf73@gmail.com>
Date: 2013-01-06 Date: 2013-01-06
Date: 2014-03-31 (used pygtk instead of xrandr, which is faster) Date: 2014-03-31 (used pygtk instead of xrandr, which is faster)
Date: 2014-06-25 added docopt, corrections and simplify the process Date: 2014-06-25 added docopt, corrections and simplify the process
@@ -131,9 +196,9 @@ class Screens(object):
return "right" return "right"
# check for maximized window (approximated) # check for maximized window (approximated)
if window['pos_x'] == window['pos_y'] == 0: if window["pos_x"] == window["pos_y"] == 0:
if window['size_x'] in range(scr.x - 32, scr.x + 32) and \ if window["size_x"] in range(scr.x - 32, scr.x + 32) and \
window['size_x'] in range(scr.x - 32, scr.x + 32): window["size_x"] in range(scr.x - 32, scr.x + 32):
return "maximized" return "maximized"
return None return None
@@ -189,16 +254,16 @@ class Screen(object):
if not COVER_MINIWINDOWS: if not COVER_MINIWINDOWS:
self.y = sy = sy - (64 + 2) self.y = sy = sy - (64 + 2)
self.left_half['size_x'] = sx / 2 - 1 self.left_half["size_x"] = sx / 2 - 1
self.maximized['pos_x'] = self.left_half['pos_x'] = self.x_shift self.maximized["pos_x"] = self.left_half["pos_x"] = self.x_shift
self.right_half['size_x'] = sx / 2 self.right_half["size_x"] = sx / 2
self.right_half['pos_x'] = sx / 2 + self.x_shift self.right_half["pos_x"] = sx / 2 + self.x_shift
self.maximized['size_x'] = sx self.maximized["size_x"] = sx
self.maximized['size_y'] = self.right_half['size_y'] = \ self.maximized["size_y"] = self.right_half["size_y"] = \
self.left_half['size_y'] = sy - DECOTATORS_HEIGHT self.left_half["size_y"] = sy - DECOTATORS_HEIGHT
class WMWindow(object): class WMWindow(object):
@@ -232,7 +297,7 @@ class WMWindow(object):
""" """
self.x = self.y = self.pos_x = self.pos_y = None self.x = self.y = self.pos_x = self.pos_y = None
out = Popen(['xdotool', 'getactivewindow', 'getwindowgeometry'], out = Popen(["xdotool", "getactivewindow", "getwindowgeometry"],
stdout=PIPE).communicate()[0] stdout=PIPE).communicate()[0]
out = out.strip().split("\n") out = out.strip().split("\n")
@@ -364,17 +429,17 @@ def cycle(monitors, right=False, main=None):
coords = wmwin.get_coords(key) coords = wmwin.get_coords(key)
if order: if order:
cmd = ['xdotool', "getactivewindow", cmd = ["xdotool", "getactivewindow",
"windowsize", str(coords['size_x']), str(coords['size_y']), "windowsize", str(coords["size_x"]), str(coords["size_y"]),
"windowmove", str(coords['pos_x']), str(coords['pos_y']), "windowmove", str(coords["pos_x"]), str(coords["pos_y"]),
"mousemove", str(coords['pos_x'] + coords['size_x'] / 2), "mousemove", str(coords["pos_x"] + coords["size_x"] / 2),
str(coords['pos_y'] + coords['size_y'] / 2)] str(coords["pos_y"] + coords["size_y"] / 2)]
else: else:
cmd = ['xdotool', "getactivewindow", cmd = ["xdotool", "getactivewindow",
"windowmove", str(coords['pos_x']), str(coords['pos_y']), "windowmove", str(coords["pos_x"]), str(coords["pos_y"]),
"windowsize", str(coords['size_x']), str(coords['size_y']), "windowsize", str(coords["size_x"]), str(coords["size_y"]),
"mousemove", str(coords['pos_x'] + coords['size_x'] / 2), "mousemove", str(coords["pos_x"] + coords["size_x"] / 2),
str(coords['pos_y'] + coords['size_y'] / 2)] str(coords["pos_y"] + coords["size_y"] / 2)]
call(cmd) call(cmd)
@@ -399,7 +464,7 @@ def move_mouse(monitors, name):
posx = mon["sx"] + 15 posx = mon["sx"] + 15
posy = mon["sy"] + 50 posy = mon["sy"] + 50
cmd = ['xdotool', "mousemove", str(posx), str(posy)] cmd = ["xdotool", "mousemove", str(posx), str(posy)]
call(cmd) call(cmd)
@@ -415,8 +480,8 @@ Usage:
%(prog)s --version %(prog)s --version
Options: Options:
-m NAME --monitor-name=NAME Name of the monitor to be treade as the main one -m NAME --monitor-name=NAME Name of the monitor to be treades as the main
(so the one containing dock) one (so the one containing dock)
-r --dock-right Dock is on the right edge of the rightmost -r --dock-right Dock is on the right edge of the rightmost
screen screen
-l --dock-left Dock is on the left edge of the leftmost screen -l --dock-left Dock is on the left edge of the leftmost screen
@@ -432,7 +497,7 @@ Options:
return return
if opts["mousemove"]: if opts["mousemove"]:
move_mouse(monitors, opts['--monitor-name']) move_mouse(monitors, opts["--monitor-name"])
return return
if opts["move"]: if opts["move"]: