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 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 killermoehrewindowgrid [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:
   * 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
Line 9: Line 9:
  
 ---- ----
- +    #!/usr/bin/python2 
-#!/usr/bin/python2 +    # -*- coding: utf-8 -*- 
-# -*- coding: utf-8 -*- +     
- +    import sys 
-import sys +    import argparse 
-import argparse +    from gtk import gdk 
-from gtk import gdk +    import wnck 
-import wnck +     
- +    PACKAGE = "window_grid" 
-PACKAGE = "window_grid" +     
- +    def argument_parser(): 
-def argument_parser(): +        """ 
-    """ +        The argument parser. Takes only one number from the cmd line in the range of 
-    The argument parser. Takes only one number from the cmd line in the range of +        0 to 10. 
-    0 to 10. +        """ 
-    """ +        parser = argparse.ArgumentParser(description='Tile the current window.'
-    parser = argparse.ArgumentParser(description='Tile the current window.'+        parser.add_argument('position', 
-    parser.add_argument('position', +            metavar='N', 
-        metavar='N', +            type=int, 
-        type=int, +            help='an integer describing the position', 
-        help='an integer describing the position', +            choices = xrange(10) 
-        choices = xrange(10) +            
-        +        return parser.parse_args() 
-    return parser.parse_args() +     
- +    def active_window(): 
-def active_window(): +        """ 
-    """ +        Returns the default screen, but it fails uncatchable when not called from X. 
-    Returns the default screen, but it fails uncatchable when not called from X. +        """ 
-    """ +        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_geometry(): 
-def get_geometry(): +        # just a shorting for wnck.Window.get_geometry(active_window()) 
-    # just a shorting for wnck.Window.get_geometry(active_window()) +        return(active_window().get_geometry()) 
-    return(active_window().get_geometry()) +     
- +    def window_state(head, sub = int(1)): 
-def window_state(head, sub = int(1)): +        """ 
-    """ +        Returns the upper left edge and the dimensions of the current window. 
-    Returns the upper left edge and the dimensions of the current window. +        The HeadMap showing the screen; 4, 5 and 6 are vertical full, 
-    The HeadMap showing the screen; 4, 5 and 6 are vertical full, +                                       2, 5 and 8 are horizontal full. 
-                                   2, 5 and 8 are horizontal full. +        ┌─────────────────┬─────────────────┐ 
-    ┌─────────────────┬─────────────────┐ +        │                 ┆                 │ 
-    │                 ┆                 │ +        │        7        8        9        │ 
-    │        7        8        9        │ +        │                 ┆                 │ 
-    │                 ┆                 │ +        ├┄┄┄┄┄┄┄╴4╶┄┄┄┄┄┄╴5╶┄┄┄┄┄┄╴6╶┄┄┄┄┄┄┄┤ 
-    ├┄┄┄┄┄┄┄╴4╶┄┄┄┄┄┄╴5╶┄┄┄┄┄┄╴6╶┄┄┄┄┄┄┄┤ +        │                 ┆                 │ 
-    │                 ┆                 │ +        │        1        2        3        │ 
-    │        1        2        3        │ +        │                 ┆                 │ 
-    │                 ┆                 │ +        └─────────────────┴─────────────────┘ 
-    └─────────────────┴─────────────────┘ +        The SubMap showing the widths 
-    The SubMap showing the widths +        ┌─────────────────┐ 
-    ┌─────────────────┐ +        │                 │ 
-    │                 │ +        │        1        │ 
-    │        1        │ +        │                 │ 
-    │                 │ +        └─────────────────┘ 
-    └─────────────────┘ +        ┌───────────────────────┐ 
-    ┌───────────────────────┐ +        │                       │ 
-    │                       │ +        │                     │ 
-    │                     │ +        │                       │ 
-    │                       │ +        └───────────────────────┘ 
-    └───────────────────────┘ +        ┌───────────┐ 
-    ┌───────────┐ +        │           │ 
-    │           │ +        │         │ 
-    │         │ +        │           │ 
-    │           │ +        └───────────┘ 
-    └───────────┘ +        """ 
-    """ +        head = int(head) 
-    head = int(head) +        root_win = gdk.get_default_root_window() 
-    root_win = gdk.get_default_root_window() +        win_property = gdk.atom_intern("_NET_WORKAREA"
-    win_property = gdk.atom_intern("_NET_WORKAREA"+        win_property_array = root_win.property_get(win_property)[2] 
-    win_property_array = root_win.property_get(win_property)[2] +        x_offset = win_property_array[0] 
-    x_offset = win_property_array[0] +        y_offset = win_property_array[1] 
-    y_offset = win_property_array[1] +        x_wa = win_property_array[2] 
-    x_wa = win_property_array[2] +        y_wa = win_property_array[3] 
-    y_wa = win_property_array[3] +        x_sub_map = {1: x_wa / 2, 2: x_wa / 3 * 2, 3: x_wa / 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 = x_offset +
-        width = x_sub_map[sub] +
-    elif (head % 3) == 2: +
-        if sub == 1:+
             x = x_offset             x = x_offset
-            width = x_wa+            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:         else:
-            x = x_wa / 3 + x_offset +             x = x_wa - x_sub_map[sub] + x_offset 
-            width = x_wa / 3 +             width = x_sub_map[sub] 
-    else: +        if (7 <= head <= 9): 
-        x = x_wa - x_sub_map[sub] + x_offset +            y = y_offset 
-        width = x_sub_map[sub] +            height = y_wa / 2 
-    if (7 <= head <= 9): +        elif (4 <= head <= 6): 
-        y = y_offset +            y = y_offset 
-        height = y_wa / 2 +            height = y_wa 
-    elif (4 <= head <= 6): +        else: 
-        y = y_offset +            y = y_wa / 2 + y_offset 
-        height = y_wa +            height = y_wa / 2 
-    else: +        return(int(x), int(y), int(width), int(height)) 
-        y = y_wa / 2 + y_offset +     
-        height = y_wa / 2 +    def set_geometry(geo_list): 
-    return(int(x), int(y), int(width), int(height)) +        """ 
- +        DOC: http://library.gnome.org/devel/libwnck/stable/WnckWindow.html#wnck-window-set-geometry 
-def set_geometry(geo_list): +        gravity: 0   - current gravity 
-    """ +                 1   - top left 
-    DOC: http://library.gnome.org/devel/libwnck/stable/WnckWindow.html#wnck-window-set-geometry +                 2   - top center            2    3 
-    gravity: 0   - current gravity +                 3   - top right           ┏━╾─┴─╼━┓ 
-             1   - top left +                 4   - center left         ╿       ╿ 
-             2   - top center            2    3 +                 5   - center center      4┤     ├6 
-             3   - top right           ┏━╾─┴─╼━┓ +                 6   - center right        ╽       ╽ 
-             4   - center left         ╿       ╿ +                 7   - bottom left         ┗━╾─┬─╼━┛ 
-             5   - center center      4┤     ├6 +                 8   - bottom center      7    8    9 
-             6   - center right        ╽       ╽ +                 9   - bottom right 
-             7   - bottom left         ┗━╾─┬─╼━┛ +                 10  - static (top left) 
-             8   - bottom center      7    8    9 +        Only 10 does what I want… all the other gravities (even 1) don't set 
-             9   - bottom right +        the windows right (Kind of bug? Maybe. Does it bother me? No, not really). 
-             10  - static (top left) +        """ 
-    Only 10 does what I want… all the other gravities (even 1) don't set +        window = active_window() 
-    the windows right (Kind of bug? Maybe. Does it bother me? No, not really). +        window.unmaximize_horizontally() 
-    """ +        window.unmaximize_vertically() 
-    window = active_window() +        window.set_geometry(10, 15, geo_list[0], geo_list[1], geo_list[2], geo_list[3]) 
-    window.unmaximize_horizontally() +        return 0 
-    window.unmaximize_vertically() +     
-    window.set_geometry(10, 15, geo_list[0], geo_list[1], geo_list[2], geo_list[3]) +    def main(): 
-    return 0 +        args = argument_parser() 
- +        if args.position == 0: 
-def main(): +            print get_geometry() 
-    args = argument_parser() +            sys.exit(0) 
-    if args.position == 0: +        #print('%s' % active_window().get_data('submap')) 
-        print get_geometry() +        if active_window().get_data('submap') == '1': 
-        sys.exit(0) +            #print('Known state! Switch to SubMap 2!') 
-    #print('%s' % active_window().get_data('submap')) +            set_geometry(window_state(args.position, 2)) 
-    if active_window().get_data('submap') == '1': +            active_window().set_data('submap', 2) 
-        #print('Known state! Switch to SubMap 2!') +        elif active_window().get_data('submap') == '2': 
-        set_geometry(window_state(args.position, 2)) +            if (args.position % 3) == 2
-        active_window().set_data('submap', 2) +                #print('Known state! Switch to SubMap 1!') 
-    elif active_window().get_data('submap') == '2': +                set_geometry(window_state(args.position, 1)) 
-        if (args.position % 3) == 2:+                active_window().set_data('submap', 1) 
 +            else: 
 +                #print('Known state! Switch to SubMap 3!') 
 +                set_geometry(window_state(args.position, 3)) 
 +                active_window().set_data('submap', 3) 
 +        elif active_window().get_data('submap') == '3':
             #print('Known state! Switch to SubMap 1!')             #print('Known state! Switch to SubMap 1!')
             set_geometry(window_state(args.position, 1))             set_geometry(window_state(args.position, 1))
             active_window().set_data('submap', 1)             active_window().set_data('submap', 1)
         else:         else:
-            #print('Known state! Switch to SubMap 3!') +            set_geometry(window_state(args.position, 1)) 
-            set_geometry(window_state(args.position, 3)) +            active_window().set_data('submap', 1) 
-            active_window().set_data('submap', 3) +            #print('%s' % active_window().get_data('submap')) 
-    elif active_window().get_data('submap') == '3': +        sys.exit((0)) 
-        #print('Known state! Switch to SubMap 1!'+     
-        set_geometry(window_state(args.position, 1)) +    if __name__ == '__main__': 
-        active_window().set_data('submap', 1) +        main()
-    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()+