Xfce Wiki

Sub domains
 

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
windowgrid [2011/07/04 11:11] killermoehrewindowgrid [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://bugzilla.xfce.org/show_bug.cgi?id=4178|this]] bug   * hope for fixing of [[https://bugzilla.xfce.org/show_bug.cgi?id=4178|this]] bug
  
-If there are questions, please ask.+If there are questions, please ask (and help).
  
 ---- ----
  
-    #!/usr/bin/python2 +#!/usr/bin/python2 
-    # -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- 
-     + 
-    import sys +import sys 
-    import os +import argparse 
-    import wnck +from gtk import gdk 
-    from Xlib import display +import wnck 
-    from xfce4 import xfconf + 
-     +PACKAGE = "window_grid" 
-    PACKAGE = "window_grid" + 
-     +def argument_parser(): 
-    def _help_(): +    """ 
-        print(u'Help:') +    The argument parser. Takes only one number from the cmd line in the range of 
-        print(u'Lorem ipsum dolores…') +    0 to 10. 
-        return(0+    """ 
-     +    parser = argparse.ArgumentParser(description='Tile the current window.') 
-    def active_window(): +    parser.add_argument('position'
-        # returns the default screen, but it fails when not called from X +        metavar='N', 
-        # TODO: connect to the dbus-session-bus to get the right environment +        type=int, 
-        # (like $DISPLAY) +        help='an integer describing the position', 
-        screen = wnck.screen_get_default() +        choices = xrange(10
-        screen.force_update() +        
-        return(screen.get_active_window()) +    return parser.parse_args() 
-     + 
-    def get_resolution(orientation): +def active_window(): 
-        # Accept only 'width' and 'height' for the specific resolution +    """ 
-        return display.Display.screen(display.Display())[orientation + +    Returns the default screen, but it fails uncatchable when not called from X. 
-           '_in_pixels'] +    """ 
-     +    screen = wnck.screen_get_default() 
-    def get_geometry(): +    screen.force_update() 
-        # just a shorting for wnck.Window.get_geometry(active_window()) +    return(screen.get_active_window()) 
-        return(active_window().get_geometry()) + 
-     +def get_geometry(): 
-    def window_state(head, sub = int(1)): +    # just a shorting for wnck.Window.get_geometry(active_window()) 
-        # The HeadMap showing the screen; 4, 5 and 6 are vertical full, +    return(active_window().get_geometry()) 
-        #                                 2, 5 and 8 are horizontal full. + 
-        # ┌─────────────────┬─────────────────┐ +def window_state(head, sub = int(1)): 
-        # │                 ┆                 │ +    """ 
-        # │        7        8        9        │ +    Returns the upper left edge and the dimensions of the current window. 
-        # │                 ┆                 │ +    The HeadMap showing the screen; 4, 5 and 6 are vertical full, 
-        # ├┄┄┄┄┄┄┄╴4╶┄┄┄┄┄┄╴5╶┄┄┄┄┄┄╴6╶┄┄┄┄┄┄┄┤ +                                   2, 5 and 8 are horizontal full. 
-        # │                 ┆                 │ +    ┌─────────────────┬─────────────────┐ 
-        # │        1        2        3        │ +    │                 ┆                 │ 
-        # │                 ┆                 │ +    │        7        8        9        │ 
-        # └─────────────────┴─────────────────┘ +    │                 ┆                 │ 
-        # The SubMap showing the widths +    ├┄┄┄┄┄┄┄╴4╶┄┄┄┄┄┄╴5╶┄┄┄┄┄┄╴6╶┄┄┄┄┄┄┄┤ 
-        # ┌─────────────────┐ +    │                 ┆                 │ 
-        # │                 │ +    │        1        2        3        │ 
-        # │        1        │ +    │                 ┆                 │ 
-        # │                 │ +    └─────────────────┴─────────────────┘ 
-        # └─────────────────┘ +    The SubMap showing the widths 
-        # ┌───────────────────────┐ +    ┌─────────────────┐ 
-        # │                       │ +    │                 │ 
-        # │                     │ +    │        1        │ 
-        # │                       │ +    │                 │ 
-        # └───────────────────────┘ +    └─────────────────┘ 
-        # ┌───────────┐ +    ┌───────────────────────┐ 
-        # │           │ +    │                       │ 
-        # │         │ +    │                     │ 
-        # │           │ +    │                       │ 
-        # └───────────┘ +    └───────────────────────┘ 
-        head = int(head) +    ┌───────────┐ 
-        x_res get_resolution(u'width'+    │           │ 
-        y_res get_resolution(u'height'+    │         │ 
-        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] +    head = int(head) 
-        elif (head % 3) == 2: +    root_win gdk.get_default_root_window() 
-            if sub == 1: +    win_property gdk.atom_intern("_NET_WORKAREA"
-                x = 0 +    win_property_array = root_win.property_get(win_property)[2] 
-                width = x_res +    x_offset = win_property_array[0] 
-            else: +    y_offset = win_property_array[1] 
-                x = x_res / 3 +    x_wa = win_property_array[2] 
-                width = x_res / 3+    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:         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] + x_offset 
-            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), int(y), int(width), int(height)) +    else: 
-     +        y = y_wa / 2 + y_offset 
-    def set_geometry(geo_list): +        height = y_wa / 2 
-        # DOC: http://library.gnome.org/devel/libwnck/stable/WnckWindow.html +    return(int(x), int(y), int(width), int(height)) 
-        #      #wnck-window-set-geometry + 
-        # gravity:  0   - current gravity +def set_geometry(geo_list): 
-        #           1   - top left +    """ 
-        #           2   - top center                    +    DOC: http://library.gnome.org/devel/libwnck/stable/WnckWindow.html#wnck-window-set-geometry 
-        #           3   - top right               ┏━╾─┴─╼━┓ +    gravity: 0   - current gravity 
-        #           4   - center left             ╿       ╿ +             1   - top left 
-        #           5   - center center         4 ┤     ├ 6 +             2   - top center               
-        #           6   - center right            ╽       ╽ +             3   - top right           ┏━╾─┴─╼━┓ 
-        #           7   - bottom left             ┗━╾─┬─╼━┛ +             4   - center left         ╿       ╿ 
-        #           8   - bottom center                 +             5   - center center      4┤     ├6 
-        #           9   - bottom right +             6   - center right        ╽       ╽ 
-        #           10  - static (top left) +             7   - bottom left         ┗━╾─┬─╼━┛ 
-        # only 10 does what I want… all the other gravities (even 1) don't set +             8   - bottom center            
-        # the windows right +             9   - bottom right 
-        active_window().unmaximize_horizontally() +             10  - static (top left) 
-        active_window().unmaximize_vertically() +    Only 10 does what I want… all the other gravities (even 1) don't set 
-        active_window().set_geometry(10, 15, geo_list[0], geo_list[1], geo_list[2], geo_list[3]) +    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: +    window.unmaximize_vertically() 
-            print('Too many arguments! Only one allowed!'+    window.set_geometry(10, 15, geo_list[0], geo_list[1], geo_list[2], geo_list[3]) 
-            _help_() +    return 0 
-            sys.exit(1) + 
-        if len(sys.argv) < 2: +def main(): 
-            print('Too few arguments! At least one required!'+    args = argument_parser() 
-            _help_() +    if args.position == 0: 
-            sys.exit(1) +        print get_geometry() 
-        try: +        sys.exit(0) 
-            cmd_arg = int(str(sys.argv[1])) +    #print('%s' % active_window().get_data('submap')) 
-        except ValueError: +    if active_window().get_data('submap') == '1': 
-            print('Wrong argument!'+        #print('Known state! Switch to SubMap 2!') 
-            _help_() +        set_geometry(window_state(args.position, 2)) 
-            sys.exit(1) +        active_window().set_data('submap', 2) 
-        if cmd_arg == 0: +    elif active_window().get_data('submap') == '2': 
-            print get_geometry() +        if (args.position % 3) == 2: 
-            sys.exit(0) +            #print('Known state! Switch to SubMap 1!') 
-        print('%s' % active_window().get_data('submap')) +            set_geometry(window_state(args.position, 1))
-        if active_window().get_data('submap') == '1': +
-            print('Known state! Switch to SubMap 2!') +
-            set_geometry(window_state(cmd_arg, 2)) +
-            active_window().set_data('submap', 2) +
-        elif active_window().get_data('submap') == '2': +
-            if (cmd_arg % 3) == 2: +
-                print('Known state! Switch to SubMap 1!'+
-                set_geometry(window_state(cmd_arg, 1)) +
-                active_window().set_data('submap', 1+
-            else: +
-                print('Known state! Switch to SubMap 3!') +
-                set_geometry(window_state(cmd_arg, 3)) +
-                active_window().set_data('submap', 3) +
-        elif active_window().get_data('submap') == '3': +
-            print('Known state! Switch to SubMap 1!') +
-            set_geometry(window_state(cmd_arg, 1))+
             active_window().set_data('submap', 1)             active_window().set_data('submap', 1)
         else:         else:
-            set_geometry(window_state(cmd_arg1)) +            #print('Known state! Switch to SubMap 3!') 
-            active_window().set_data('submap', 1) +            set_geometry(window_state(args.position3)) 
-        print('%s' % active_window().get_data('submap')) +            active_window().set_data('submap', 3) 
-        sys.exit(0) +    elif active_window().get_data('submap') == '3': 
-     +        #print('Known state! Switch to SubMap 1!'
-    if __name__ == '__main__': +        set_geometry(window_state(args.position, 1)) 
-        main()+        active_window().set_data('submap', 1) 
 +    else: 
 +        set_geometry(window_state(args.position, 1)) 
 +        active_window().set_data('submap', 1) 
 +        #print('%s' % active_window().get_data('submap')) 
 +    sys.exit((0)
 + 
 +if __name__ == '__main__': 
 +    main()