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:11] – killermoehre | windowgrid [2012/08/22 16:37] – changed to version2 and using a download link instead 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:// | ||
- | If there are questions, please ask. | + | If there are questions, please ask (and help). |
- | ---- | + | https://dl-web.dropbox.com/get/Public/window_grid2? |
- | + | ||
- | # | + | |
- | # -*- coding: utf-8 -*- | + | |
- | + | ||
- | import sys | + | |
- | import os | + | |
- | import wnck | + | |
- | from Xlib import display | + | |
- | from xfce4 import xfconf | + | |
- | + | ||
- | PACKAGE = " | + | |
- | + | ||
- | def _help_(): | + | |
- | print(u' | + | |
- | print(u' | + | |
- | return(0) | + | |
- | + | ||
- | def active_window(): | + | |
- | # returns the default screen, but it fails when not called from X | + | |
- | # TODO: connect to the dbus-session-bus to get the right environment | + | |
- | # (like $DISPLAY) | + | |
- | screen = wnck.screen_get_default() | + | |
- | screen.force_update() | + | |
- | return(screen.get_active_window()) | + | |
- | + | ||
- | def get_resolution(orientation): | + | |
- | # Accept only ' | + | |
- | return display.Display.screen(display.Display())[orientation + | + | |
- | ' | + | |
- | + | ||
- | def get_geometry(): | + | |
- | # just a shorting for wnck.Window.get_geometry(active_window()) | + | |
- | return(active_window().get_geometry()) | + | |
- | + | ||
- | def window_state(head, | + | |
- | # 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) | + | |
- | x_res = get_resolution(u' | + | |
- | y_res = get_resolution(u' | + | |
- | 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 | + | |
- | else: | + | |
- | x = x_res / 3 | + | |
- | width = x_res / 3 | + | |
- | else: | + | |
- | x = x_res - x_sub_map[sub] | + | |
- | width = x_sub_map[sub] | + | |
- | if (7 <= head <= 9): | + | |
- | y = 0 | + | |
- | height = y_res / 2 | + | |
- | elif (4 <= head <= 6): | + | |
- | y = 0 | + | |
- | height = y_res | + | |
- | else: | + | |
- | y = y_res / 2 | + | |
- | height = y_res / 2 | + | |
- | return(int(x), | + | |
- | + | ||
- | def set_geometry(geo_list): | + | |
- | # DOC: http:// | + | |
- | # # | + | |
- | # gravity: | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # | + | |
- | # only 10 does what I want… all the other gravities (even 1) don't set | + | |
- | # the windows right | + | |
- | active_window().unmaximize_horizontally() | + | |
- | active_window().unmaximize_vertically() | + | |
- | active_window().set_geometry(10, | + | |
- | return 0 | + | |
- | + | ||
- | def main(): | + | |
- | if len(sys.argv) > 2: | + | |
- | print(' | + | |
- | _help_() | + | |
- | sys.exit(1) | + | |
- | if len(sys.argv) < 2: | + | |
- | print(' | + | |
- | _help_() | + | |
- | sys.exit(1) | + | |
- | try: | + | |
- | cmd_arg | + | |
- | except ValueError: | + | |
- | print(' | + | |
- | _help_() | + | |
- | sys.exit(1) | + | |
- | if cmd_arg == 0: | + | |
- | print get_geometry() | + | |
- | sys.exit(0) | + | |
- | print(' | + | |
- | if active_window().get_data(' | + | |
- | print(' | + | |
- | set_geometry(window_state(cmd_arg, | + | |
- | active_window().set_data(' | + | |
- | elif active_window().get_data(' | + | |
- | if (cmd_arg % 3) == 2: | + | |
- | print(' | + | |
- | set_geometry(window_state(cmd_arg, | + | |
- | active_window().set_data(' | + | |
- | else: | + | |
- | print(' | + | |
- | set_geometry(window_state(cmd_arg, | + | |
- | active_window().set_data(' | + | |
- | elif active_window().get_data(' | + | |
- | print(' | + | |
- | set_geometry(window_state(cmd_arg, | + | |
- | active_window().set_data(' | + | |
- | else: | + | |
- | set_geometry(window_state(cmd_arg, | + | |
- | active_window().set_data(' | + | |
- | print(' | + | |
- | sys.exit(0) | + | |
- | + | ||
- | if __name__ == ' | + | |
- | main() | + |