Changeset 196

Show
Ignore:
Timestamp:
02/25/2008 11:19:36 AM (11 months ago)
Author:
mwm
Message:

Extend the plpwm xml configuration facilities to allow for automatic
configuration and window placement. Tweak panes.py to deal with a bad reference
this uncovered.

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/examples/plpwm.py

    r195 r196  
    11#!/usr/bin/env python 
    2 # $Id: plpwm.py,v 1.44 2007-07-14 09:19:34 mwm Exp $ 
     2# $Id: plpwm.py,v 1.45 2008-02-25 17:19:36 mwm Exp $ 
    33# 
    44# plpwm.py -- Example PLWM window manager configuration with panes. 
     
    3131 
    3232from time import sleep 
     33from string import digits 
    3334     
    3435from Xlib import X, XK 
     
    6061    C_a = input.InputKeyHandler._begin 
    6162    C_e = input.InputKeyHandler._end 
    62     C_y = input.InputKeyHandler._paste 
     63    C_y = input.InputKeyHandler._paste_selection 
    6364    c_p = input.InputKeyHandler._history_up 
    6465    c_n = input.InputKeyHandler._history_down 
     
    8485    menu_bordercolor = "Red" 
    8586    message_bordercolor = "Blue" 
     87 
    8688     
    87  
    8889class WMConfig: 
    8990    def __wm_init__(my): 
    90         "install the panes key map" 
    91         PaneKeys(my) 
    92  
     91        "install the panes key map, menus, and try to restore my config." 
     92 
     93        auto_restore(my, PaneKeys(my).menus.find('paneconfigmenus')) 
     94        
    9395 
    9496class PLPWM(wmanager.WindowManager, 
     
    9698            panes.panesManager, 
    9799            inspect.InspectServer, 
    98             WMConfig): 
     100            WMConfig): 
    99101    "Set up my window manager." 
    100102 
     
    219221 
    220222    def M1_m(my, event): 
    221         def itunes(node): os.system('itunes %s' % node.get('command')) 
     223        def itunes(node): os.system('itunes "%s" &' % node.get('command')) 
    222224        view_menu(my.wm.panes_list[my.wm.panes_current], 
    223225                  XML_controller(my.menus.find('itunesmenu'), 
     
    240242        def reload_menus(): 
    241243            my.menus = load_menus(my.menu_file) 
     244            auto_restore(my.wm, my.menus.find('paneconfigmenus')) 
    242245 
    243246        def restore_menu(wm): 
     
    301304 
    302305 
     306def auto_restore(wm, panes): 
     307    "Look for and restore an automatic config." 
     308 
     309    geom = '%dx%d' % (wm.screens[0].root_full_width, 
     310                      wm.screens[0].root_full_height) 
     311    for config in panes: 
     312        startup = config.get('startup') 
     313        if (startup == 'match' and config.get('label').endswith(geom)) or \ 
     314               startup == 'use': 
     315            restore(wm, config) 
     316            break 
     317 
    303318def restore(wm, config): 
    304319    "Build my standard work environment." 
    305320 
    306     pane = wm.panes_list[0] 
    307     pane.maximize() 
     321    wm.panes_list[0].maximize() 
    308322         
    309323    # Disconnect all windows from panes to avoid displaying everything 
     
    313327 
    314328    # Disconnect any remaining panes from their windows as well. 
    315     pane.window = None 
    316  
     329    wm.panes_list[0].window = None 
     330 
     331    places = dict() 
    317332    for node in config: 
    318333        if node.tag == 'vertical': 
    319             pane.vertical_split(float(node.get('fraction'))) 
     334            wm.panes_list[wm.panes_current].vertical_split(float(node.get('fraction'))) 
    320335        elif node.tag == 'horizontal': 
    321             pane.horizontal_split(float(node.get('fraction'))) 
     336            wm.panes_list[wm.panes_current].horizontal_split(float(node.get('fraction'))) 
    322337        elif node.tag == 'newpane': 
    323338            pane = wm.panes_list[int(node.get('pane'))] 
    324339        elif node.tag == 'goto': 
    325             wm.panes_goto(int(node.get('number'))) 
     340            wm.panes_goto(int(node.get('pane'))) 
    326341        elif node.tag == 'number': 
    327             wm.panes_number(int(node.get('number'))) 
     342            wm.panes_number(int(node.get('new'))) 
     343        elif node.tag == 'placewindow': 
     344            places[node.get('name')] = int(node.get('pane')) 
    328345        else: 
    329346            raise ValueError, 'Unrecognized pane config element %s' % node 
    330347 
     348    # Now fix any windows wired by title 
     349    panecount = len(wm.panes_list) 
     350    for s in wm.screens: 
     351        for c in s.query_clients(cfilter.true, 1): 
     352            title = c.get_title() 
     353            if title[-2] == '@' and title[-1] in digits: 
     354                pane = digits.index(title[-1]) 
     355                if pane < panecount: 
     356                    wm.panes_list[pane].add_window(c) 
     357                    continue 
     358            else: 
     359                for name in places: 
     360                    if name in title: 
     361                        if places[name] < panecount: 
     362                            wm.panes_list[places[name]].add_window(c) 
     363                            break 
    331364 
    332365    # And now make the world sane 
  • trunk/plwm/panes.py

    r191 r196  
    1 # $Id: panes.py,v 1.21 2006-09-18 21:43:28 mwm Exp $ 
     1# $Id: panes.py,v 1.22 2008-02-25 17:19:36 mwm Exp $ 
    22# 
    33# panes.py -- Handle panes (sometimes known as "frames") 
     
    174174 
    175175        w = my.get_window(event.window) 
    176         if w: 
     176        if w and w.panes_pane: 
    177177            if event.value_mask & (X.CWX | X.CWY | X.CWWidth | X.CWHeight): 
    178178                w.panes_pane.place_window(w) 
     
    236236        if my.window: my.deactivate() 
    237237        my.window = window 
    238         if my.wm.panes_list[my.wm.panes_current] == my: 
    239             my.activate() 
     238        my.activate() 
    240239 
    241240    def iconify_window(my):