Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
windowgrid [2011/12/13 17:49] – killermoehre | windowgrid [2012/08/05 09:57] – killermoehre | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Window-Grid ====== | ====== Window-Grid ====== | ||
Similar to the Window-Grid-PlugIn for Compiz (Link needed) features this python-script some placing capabilities. | Similar to the Window-Grid-PlugIn for Compiz (Link needed) features this python-script some placing capabilities. | ||
+ | |||
TODO: | TODO: | ||
- | * wrote the help | ||
* find some way to store the window state (int; 1, 2, or 3) with the window | * find some way to store the window state (int; 1, 2, or 3) with the window | ||
* hope for fixing of [[https:// | * hope for fixing of [[https:// | ||
Line 10: | Line 9: | ||
---- | ---- | ||
- | |||
# | # | ||
# -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||
| | ||
import sys | import sys | ||
- | import | + | import |
+ | from gtk import gdk | ||
import wnck | import wnck | ||
- | from Xlib import display | ||
| | ||
PACKAGE = " | PACKAGE = " | ||
| | ||
- | def _help_(): | + | def argument_parser(): |
- | | + | |
- | | + | The argument parser. Takes only one number from the cmd line in the range of |
- | return(0) | + | 0 to 10. |
+ | """ | ||
+ | parser = argparse.ArgumentParser(description='Tile the current window.') | ||
+ | | ||
+ | metavar=' | ||
+ | type=int, | ||
+ | help=' | ||
+ | choices = xrange(10) | ||
+ | | ||
+ | return | ||
| | ||
def active_window(): | def active_window(): | ||
- | | + | |
- | | + | Returns |
- | # (like $DISPLAY) | + | |
screen = wnck.screen_get_default() | screen = wnck.screen_get_default() | ||
screen.force_update() | screen.force_update() | ||
- | return(screen.get_active_window()) | + | return(screen.get_active_window()) |
- | + | ||
- | def get_resolution(orientation): | + | |
- | # Accept only ' | + | |
- | return display.Display.screen(display.Display())[orientation + | + | |
- | ' | + | |
| | ||
def get_geometry(): | def get_geometry(): | ||
Line 44: | Line 46: | ||
| | ||
def window_state(head, | def window_state(head, | ||
- | | + | |
- | # | + | Returns the upper left edge and the dimensions of the current window. |
- | | + | |
- | | + | |
- | | + | ┌─────────────────┬─────────────────┐ |
- | | + | │ |
- | | + | │ 7 8 9 │ |
- | | + | │ |
- | | + | ├┄┄┄┄┄┄┄╴4╶┄┄┄┄┄┄╴5╶┄┄┄┄┄┄╴6╶┄┄┄┄┄┄┄┤ |
- | | + | │ |
- | | + | │ 1 2 3 │ |
- | | + | │ |
- | | + | └─────────────────┴─────────────────┘ |
- | | + | The SubMap showing the widths |
- | | + | ┌─────────────────┐ |
- | | + | │ │ |
- | | + | │ 1 │ |
- | | + | │ │ |
- | | + | └─────────────────┘ |
- | | + | ┌───────────────────────┐ |
- | | + | │ │ |
- | | + | │ |
- | | + | │ │ |
- | | + | └───────────────────────┘ |
- | | + | ┌───────────┐ |
- | | + | │ │ |
- | | + | │ |
+ | │ │ | ||
+ | └───────────┘ | ||
+ | """ | ||
head = int(head) | head = int(head) | ||
- | | + | |
- | | + | |
- | x_sub_map = {1: x_res / 2, 2: x_res / 3 * 2, 3: x_res / 3} | + | win_property_array = root_win.property_get(win_property)[2] |
+ | x_offset = win_property_array[0] | ||
+ | y_offset = win_property_array[1] | ||
+ | x_wa = win_property_array[2] | ||
+ | y_wa = win_property_array[3] | ||
+ | x_sub_map = {1: x_wa / 2, 2: x_wa / 3 * 2, 3: x_wa / 3} | ||
if (head % 3) == 1: | if (head % 3) == 1: | ||
- | x = 0 | + | x = x_offset |
width = x_sub_map[sub] | width = x_sub_map[sub] | ||
elif (head % 3) == 2: | elif (head % 3) == 2: | ||
if sub == 1: | if sub == 1: | ||
- | x = 0 | + | x = x_offset |
- | width = x_res | + | width = x_wa |
else: | else: | ||
- | x = x_res / 3 | + | x = x_wa / 3 + x_offset |
- | width = x_res / 3 | + | width = x_wa / 3 |
else: | else: | ||
- | | + | x = x_wa - x_sub_map[sub] |
- | width = x_sub_map[sub] | + | |
if (7 <= head <= 9): | if (7 <= head <= 9): | ||
- | y = 0 | + | y = y_offset |
- | height = y_res / 2 | + | height = y_wa / 2 |
elif (4 <= head <= 6): | elif (4 <= head <= 6): | ||
- | y = 0 | + | y = y_offset |
- | height = y_res | + | height = y_wa |
else: | else: | ||
- | y = y_res / 2 | + | y = y_wa / 2 + y_offset |
- | height = y_res / 2 | + | height = y_wa / 2 |
return(int(x), | return(int(x), | ||
| | ||
def set_geometry(geo_list): | def set_geometry(geo_list): | ||
- | | + | |
- | # | + | |
- | | + | gravity: 0 - current gravity |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | | + | |
- | | + | the windows right (Kind of bug? Maybe. Does it bother me? No, not really). |
- | active_window().unmaximize_horizontally() | + | |
- | | + | window = active_window() |
- | | + | window.unmaximize_horizontally() |
+ | | ||
+ | | ||
return 0 | return 0 | ||
- | | + | |
def main(): | def main(): | ||
- | | + | |
- | print(' | + | if args.position |
- | _help_() | + | |
- | sys.exit(1) | + | |
- | if len(sys.argv) < 2: | + | |
- | print(' | + | |
- | _help_() | + | |
- | sys.exit(1) | + | |
- | try: | + | |
- | cmd_arg = int(str(sys.argv[1])) | + | |
- | except ValueError: | + | |
- | print(' | + | |
- | _help_() | + | |
- | sys.exit(1) | + | |
- | if cmd_arg | + | |
print get_geometry() | print get_geometry() | ||
sys.exit(0) | sys.exit(0) | ||
- | print(' | + | |
if active_window().get_data(' | if active_window().get_data(' | ||
- | print(' | + | |
- | set_geometry(window_state(cmd_arg, 2)) | + | set_geometry(window_state(args.position, 2)) |
active_window().set_data(' | active_window().set_data(' | ||
elif active_window().get_data(' | elif active_window().get_data(' | ||
- | if (cmd_arg | + | if (args.position |
- | print(' | + | |
- | set_geometry(window_state(cmd_arg, 1)) | + | set_geometry(window_state(args.position, 1)) |
active_window().set_data(' | active_window().set_data(' | ||
else: | else: | ||
- | print(' | + | |
- | set_geometry(window_state(cmd_arg, 3)) | + | set_geometry(window_state(args.position, 3)) |
active_window().set_data(' | active_window().set_data(' | ||
elif active_window().get_data(' | elif active_window().get_data(' | ||
- | print(' | + | |
- | set_geometry(window_state(cmd_arg, 1)) | + | set_geometry(window_state(args.position, 1)) |
active_window().set_data(' | active_window().set_data(' | ||
else: | else: | ||
- | set_geometry(window_state(cmd_arg, 1)) | + | set_geometry(window_state(args.position, 1)) |
active_window().set_data(' | active_window().set_data(' | ||
- | | + | #print(' |
- | sys.exit(0) | + | sys.exit((0)) |
| | ||
if __name__ == ' | if __name__ == ' | ||
main() | main() |