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 [2012/08/05 09:50] – got the panel spacing right… and help is available, too… oh, and argparse is used killermoehre | windowgrid [2012/08/29 19:49] – 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: | ||
Line 8: | Line 8: | ||
If there are questions, please ask (and help). | If there are questions, please ask (and help). | ||
- | ---- | + | http://dl.dropbox.com/u/391333/window_grid2 |
- | + | ||
- | # | + | |
- | # -*- coding: utf-8 -*- | + | |
- | + | ||
- | import sys | + | |
- | import argparse | + | |
- | from gtk import gdk | + | |
- | import wnck | + | |
- | + | ||
- | PACKAGE = " | + | |
- | + | ||
- | def argument_parser(): | + | |
- | """ | + | |
- | The argument parser. Takes only one number from the cmd line in the range of | + | |
- | 0 to 10. | + | |
- | """ | + | |
- | parser = argparse.ArgumentParser(description=' | + | |
- | parser.add_argument(' | + | |
- | metavar=' | + | |
- | type=int, | + | |
- | help=' | + | |
- | choices = xrange(10) | + | |
- | ) | + | |
- | return parser.parse_args() | + | |
- | + | ||
- | def active_window(): | + | |
- | """ | + | |
- | Returns the default screen, but it fails uncatchable when not called from X. | + | |
- | """ | + | |
- | screen = wnck.screen_get_default() | + | |
- | screen.force_update() | + | |
- | return(screen.get_active_window()) | + | |
- | + | ||
- | def get_geometry(): | + | |
- | # just a shorting for wnck.Window.get_geometry(active_window()) | + | |
- | return(active_window().get_geometry()) | + | |
- | + | ||
- | def window_state(head, | + | |
- | """ | + | |
- | Returns the upper left edge and the dimensions of the current window. | + | |
- | The HeadMap showing the screen; 4, 5 and 6 are vertical full, | + | |
- | 2, 5 and 8 are horizontal full. | + | |
- | ┌─────────────────┬─────────────────┐ | + | |
- | │ | + | |
- | │ 7 8 9 │ | + | |
- | │ | + | |
- | ├┄┄┄┄┄┄┄╴4╶┄┄┄┄┄┄╴5╶┄┄┄┄┄┄╴6╶┄┄┄┄┄┄┄┤ | + | |
- | │ | + | |
- | │ 1 2 3 │ | + | |
- | │ | + | |
- | └─────────────────┴─────────────────┘ | + | |
- | The SubMap showing the widths | + | |
- | ┌─────────────────┐ | + | |
- | │ │ | + | |
- | │ 1 │ | + | |
- | │ │ | + | |
- | └─────────────────┘ | + | |
- | ┌───────────────────────┐ | + | |
- | │ │ | + | |
- | │ | + | |
- | │ │ | + | |
- | └───────────────────────┘ | + | |
- | ┌───────────┐ | + | |
- | │ │ | + | |
- | │ | + | |
- | │ │ | + | |
- | └───────────┘ | + | |
- | """ | + | |
- | head = int(head) | + | |
- | root_win = gdk.get_default_root_window() | + | |
- | win_property = gdk.atom_intern(" | + | |
- | 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: | + | |
- | x = x_offset | + | |
- | width = x_sub_map[sub] | + | |
- | elif (head % 3) == 2: | + | |
- | if sub == 1: | + | |
- | x = x_offset | + | |
- | width = x_wa | + | |
- | else: | + | |
- | x = x_wa / 3 + x_offset | + | |
- | width = x_wa / 3 | + | |
- | else: | + | |
- | x = x_wa - x_sub_map[sub] + x_offset | + | |
- | width = x_sub_map[sub] | + | |
- | if (7 <= head <= 9): | + | |
- | y = y_offset | + | |
- | height = y_wa / 2 | + | |
- | elif (4 <= head <= 6): | + | |
- | y = y_offset | + | |
- | height = y_wa | + | |
- | else: | + | |
- | y = y_wa / 2 + y_offset | + | |
- | height = y_wa / 2 | + | |
- | return(int(x), | + | |
- | + | ||
- | def set_geometry(geo_list): | + | |
- | """ | + | |
- | DOC: http://library.gnome.org/devel/libwnck/stable/ | + | |
- | gravity: 0 - current gravity | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | Only 10 does what I want… all the other gravities (even 1) don't set | + | |
- | the windows right (Kind of bug? Maybe. Does it bother me? No, not really). | + | |
- | """ | + | |
- | window = active_window() | + | |
- | window.unmaximize_horizontally() | + | |
- | window.unmaximize_vertically() | + | |
- | window.set_geometry(10, | + | |
- | return 0 | + | |
- | + | ||
- | def main(): | + | |
- | args = argument_parser() | + | |
- | if args.position == 0: | + | |
- | print get_geometry() | + | |
- | sys.exit(0) | + | |
- | # | + | |
- | if active_window().get_data(' | + | |
- | # | + | |
- | set_geometry(window_state(args.position, | + | |
- | active_window().set_data(' | + | |
- | elif active_window().get_data(' | + | |
- | if (args.position % 3) == 2: | + | |
- | # | + | |
- | set_geometry(window_state(args.position, | + | |
- | active_window().set_data(' | + | |
- | else: | + | |
- | # | + | |
- | set_geometry(window_state(args.position, | + | |
- | active_window().set_data(' | + | |
- | elif active_window().get_data(' | + | |
- | # | + | |
- | set_geometry(window_state(args.position, | + | |
- | active_window().set_data(' | + | |
- | else: | + | |
- | set_geometry(window_state(args.position, | + | |
- | active_window().set_data(' | + | |
- | # | + | |
- | sys.exit((0)) | + | |
- | + | ||
- | if __name__ == ' | + | |
- | main() | + |