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/07/04 11:19] – killermoehre | windowgrid [2012/08/05 09:50] – got the panel spacing right… and help is available, too… oh, and argparse is used killermoehre | ||
---|---|---|---|
Line 3: | Line 3: | ||
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:// | ||
- | If there are questions, please ask. | + | If there are questions, please ask (and help). |
---- | ---- | ||
- | | + | # |
- | # -*- coding: utf-8 -*- | + | # -*- coding: utf-8 -*- |
- | + | ||
- | import sys | + | import sys |
- | import | + | import |
- | import | + | from gtk import |
- | from Xlib import | + | import |
- | + | ||
- | PACKAGE = " | + | PACKAGE = " |
- | + | ||
- | def _help_(): | + | def argument_parser(): |
- | print(u'Help:') | + | """ |
- | print(u'Lorem ipsum dolores…') | + | The argument parser. Takes only one number from the cmd line in the range of |
- | return(0) | + | 0 to 10. |
- | + | """ | |
- | def active_window(): | + | parser = argparse.ArgumentParser(description='Tile the current window.') |
- | # returns | + | |
- | # TODO: connect to the dbus-session-bus to get the right environment | + | metavar=' |
- | # (like $DISPLAY) | + | type=int, |
- | | + | help=' |
- | screen.force_update() | + | choices = xrange(10) |
- | return(screen.get_active_window()) | + | |
- | + | | |
- | def get_resolution(orientation): | + | |
- | # Accept only ' | + | def active_window(): |
- | return display.Display.screen(display.Display())[orientation + | + | """ |
- | ' | + | Returns |
- | + | """ | |
- | | + | screen = wnck.screen_get_default() |
- | # just a shorting for wnck.Window.get_geometry(active_window()) | + | screen.force_update() |
- | return(active_window().get_geometry()) | + | return(screen.get_active_window()) |
- | + | ||
- | def window_state(head, | + | 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. |
- | # | + | |
- | # | + | |
- | # | + | ┌─────────────────┬─────────────────┐ |
- | # | + | │ |
- | # | + | │ 7 8 9 │ |
- | # | + | │ |
- | # | + | ├┄┄┄┄┄┄┄╴4╶┄┄┄┄┄┄╴5╶┄┄┄┄┄┄╴6╶┄┄┄┄┄┄┄┤ |
- | # | + | │ |
- | # | + | │ 1 2 3 │ |
- | # | + | │ |
- | # | + | └─────────────────┴─────────────────┘ |
- | # | + | The SubMap showing the widths |
- | # | + | ┌─────────────────┐ |
- | # | + | │ │ |
- | # | + | │ 1 │ |
- | # | + | │ │ |
- | # | + | └─────────────────┘ |
- | # | + | ┌───────────────────────┐ |
- | # | + | │ │ |
- | # | + | │ |
- | # | + | │ │ |
- | head = int(head) | + | └───────────────────────┘ |
- | | + | ┌───────────┐ |
- | | + | │ │ |
- | x_sub_map = {1: x_res / 2, 2: x_res / 3 * 2, 3: x_res / 3} | + | │ |
- | if (head % 3) == 1: | + | │ │ |
- | x = 0 | + | └───────────┘ |
- | width = x_sub_map[sub] | + | """ |
- | elif (head % 3) == 2: | + | |
- | if sub == 1: | + | |
- | x = 0 | + | |
- | width = x_res | + | |
- | | + | x_offset = win_property_array[0] |
- | | + | y_offset = win_property_array[1] |
- | width = x_res / 3 | + | x_wa = win_property_array[2] |
+ | y_wa = win_property_array[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: | else: | ||
- | x = x_res - x_sub_map[sub] | + | x = x_wa / 3 + x_offset |
- | width = x_sub_map[sub] | + | width = x_wa / 3 |
- | if (7 <= head <= 9): | + | else: |
- | y = 0 | + | x = x_wa - x_sub_map[sub] |
- | height = y_res / 2 | + | width = x_sub_map[sub] |
- | elif (4 <= head <= 6): | + | if (7 <= head <= 9): |
- | y = 0 | + | y = y_offset |
- | height = y_res | + | height = y_wa / 2 |
- | else: | + | elif (4 <= head <= 6): |
- | y = y_res / 2 | + | y = y_offset |
- | height = y_res / 2 | + | height = y_wa |
- | return(int(x), | + | else: |
- | + | y = y_wa / 2 + y_offset | |
- | def set_geometry(geo_list): | + | height = y_wa / 2 |
- | # | + | return(int(x), |
- | # | + | |
- | # | + | def set_geometry(geo_list): |
- | # | + | """ |
- | # | + | |
- | # | + | gravity: 0 - current gravity |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # only 10 does what I want… all the other gravities (even 1) don't set | + | |
- | # | + | |
- | active_window().unmaximize_horizontally() | + | |
- | | + | |
- | | + | the windows right (Kind of bug? Maybe. Does it bother me? No, not really). |
- | return 0 | + | """ |
- | + | window = active_window() | |
- | def main(): | + | window.unmaximize_horizontally() |
- | if len(sys.argv) > 2: | + | |
- | | + | |
- | _help_() | + | return 0 |
- | sys.exit(1) | + | |
- | | + | def main(): |
- | print(' | + | args = argument_parser() |
- | _help_() | + | if args.position |
- | sys.exit(1) | + | print get_geometry() |
- | try: | + | sys.exit(0) |
- | cmd_arg = int(str(sys.argv[1])) | + | #print(' |
- | except ValueError: | + | if active_window().get_data(' |
- | print(' | + | #print(' |
- | _help_() | + | set_geometry(window_state(args.position, 2)) |
- | sys.exit(1) | + | active_window().set_data(' |
- | if cmd_arg | + | elif active_window().get_data(' |
- | print get_geometry() | + | if (args.position |
- | sys.exit(0) | + | #print(' |
- | print(' | + | set_geometry(window_state(args.position, 1)) |
- | if active_window().get_data(' | + | |
- | print(' | + | |
- | set_geometry(window_state(cmd_arg, 2)) | + | |
- | active_window().set_data(' | + | |
- | elif active_window().get_data(' | + | |
- | if (cmd_arg | + | |
- | print(' | + | |
- | set_geometry(window_state(cmd_arg, | + | |
- | active_window().set_data(' | + | |
- | | + | |
- | print(' | + | |
- | | + | |
- | active_window().set_data(' | + | |
- | elif active_window().get_data(' | + | |
- | print(' | + | |
- | set_geometry(window_state(cmd_arg, 1)) | + | |
active_window().set_data(' | active_window().set_data(' | ||
else: | else: | ||
- | set_geometry(window_state(cmd_arg, 1)) | + | |
- | active_window().set_data(' | + | |
- | print(' | + | active_window().set_data(' |
- | sys.exit(0) | + | elif active_window().get_data(' |
- | + | # | |
- | if __name__ == ' | + | |
- | main() | + | active_window().set_data(' |
+ | else: | ||
+ | set_geometry(window_state(args.position, | ||
+ | active_window().set_data(' | ||
+ | #print(' | ||
+ | sys.exit((0)) | ||
+ | |||
+ | if __name__ == ' | ||
+ | main() |