Re: tiling with openbox

antoine.vigouroux-Bf/[email protected] Fri, 23 Sep 2016 19:41:55 +0200 (CEST)
Newsgroups gmane.comp.window-managers.openbox
Message-ID <[email protected]>
Here it is!


---- Message d'origine ----
De : "Łukasz Grabowski" <[email protected]>
À : [email protected]
Objet : Re: [openbox] tiling with openbox
Date : 23/09/2016 14:07:25 CEST

On Sat, 25 Jun 2016 23:38:59 +0300
TT <[email protected]> wrote:

> Hello,
> thank you for this beautiful script.
> the way i see it it isn't even openbox-specific!
> however, my question was:

Could we see the script in question? I like the feature of the
separating line depending on the position of the cursor very much...

Best,
Łukasz


> 
> >> I am searching for good examples of manual tiling that can be 
> achieved with openbox only, as far as possible.
> 
> i was thinking esp. the new "If" Action might open many new 
> possibilities to do some semimanual tiling with openbox only.
> i tried to use "If" once or twice but soon got lost in the depths of
> the xml tree...
> 
> so, the question remains:
> what can be achieved with openbox only?
> 
> 
> On 23/06/16 23:10, Antoine Vigouroux wrote:
> > Hello,
> >
> > I'm using a custom script to tile my windows, and I'm pretty happy 
> > with it at the moment. I put the script as an attachment because it
> > is not on GitHub, and I could never find time to write a proper 
> > documentation... When it is executed, it tiles the windows so the 
> > central separation line is at the level of the cursor. You can also 
> > use the -c option to have a centered tiling (that's useful for 
> > keybindings).
> >
> > Here is what I have in my config file to start it, so when I click 
> > while pressing Control the windows get tiled:
> >
> > <mousebind action="Press" button="C-Right">
> > <action name="Execute">
> > <command>/home/antoine/Python/Tuile/tuile.py</command>
> > </action>
> > </mousebind>
> >
> > Hope it helps!
> >
> > Antoine 
> 
> 

_______________________________________________
openbox mailing list
[email protected]
http://icculus.org/mailman/listinfo/openbox

_______________________________________________
openbox mailing list
[email protected]
http://icculus.org/mailman/listinfo/openbox
tuile.py (text/x-python, 4.6 KB)
#!/bin/python2.7
import xpybutil.ewmh as ewmh
import xpybutil.window as window
from Xlib import display
import sys

# Configuration
d = display.Display().screen().root.query_pointer()._data
resolution = display.Display().screen().root.get_geometry()
resolution.height = resolution.height - 1 # Bottom margin, uncomment if you want a 1 pixel margin at the bottom to access the menu
overlap = 0
gap = 0
    
def main ():
    client_list = wlist () # Get windows on the current workspace
    nb = len (client_list)
    
    # Define the target center point
    if len (sys.argv) > 1:
        x = resolution.width / 2
        y = resolution.height / 2
    else:
        x = xmouse()
        y = ymouse()
    
    # Chose the right tiling function according to the number of windows
    if nb == 1:
        tile1 (client_list, x)    
    elif nb == 2:
        tile2 (client_list, x)
    elif nb == 3:
        tile3 (client_list, x, y)
    else: # Above 4 windows, only the 4 last windows on the stack (i.e. background ones) will be tiled
        tile4 (client_list, x, y)
    
    # (I don't know why this is needed)
    print (window.get_geometry(client_list[0]))

def xmouse ():
     return d["root_x"]

def ymouse ():
     return d["root_y"]
     
def posx (client):
    geom = window.get_geometry(client)
    return geom[0] + geom[2] / 2
    
def posy (client):
    geom = window.get_geometry(client)
    return geom[1] + geom[3] / 2  

def height (client):
    return window.get_geometry(client)[3]

def wlist ():
    total_client_list = ewmh.get_client_list_stacking().reply()
    current_desktop = ewmh.get_current_desktop().reply()
    
    return [i for i in total_client_list if ewmh.get_wm_desktop(i).reply() == current_desktop]

def tile1 (client_list, x):
    wm = window.WindowManagers.Openbox
    if posx (client_list[0]) < resolution.width / 2:
        window.moveresize(client_list[0], gap, gap, x + overlap - gap * 1.5, resolution.height - gap * 2, wm)
    else:
        window.moveresize(client_list[0], x + gap/2, gap, resolution.width - x - gap * 1.5 , resolution.height - gap * 2, wm)
    
def tile2 (client_list, x):
    client_list.sort (key = lambda k : posx(k)) # Windows are sorted by the x of their middle
   
    wm = window.WindowManagers.Openbox
    # Left
    window.moveresize(client_list[0], gap, gap, x + overlap - gap * 1.5, resolution.height - gap * 2, wm)
    # Right
    window.moveresize(client_list[1], x + gap/2, gap, resolution.width - x - gap * 1.5 , resolution.height - gap * 2, wm)
    
def tile3 (client_list, x, y):
    #tallest = max (client_list, key = lambda x : height(x))
    posx_all = { i : posx(i) for i in client_list }
    client_list.sort (key = lambda k : posx_all[k])
    wm = window.WindowManagers.Openbox
    
    if  posx_all [client_list [1]] - posx_all [client_list [0]]  < posx_all [client_list [2]] - posx_all [client_list [1]] :
        
        client_list = sorted (client_list[0:2], key = lambda k : posy(k)) + [client_list[2]]
        # Top left
        window.moveresize(client_list[0], gap, gap, x + overlap - gap * 1.5, y + overlap - gap * 1.5, wm)
        # Bottom left 
        window.moveresize(client_list[1], gap, y + gap/2, x + overlap - gap * 1.5, resolution.height - y - gap * 1.5, wm)
        # Right
        window.moveresize(client_list[2], x + gap/2, gap, resolution.width - x - gap * 1.5 , resolution.height - gap * 2, wm)
    else :
        
        client_list = [client_list[0]] + sorted (client_list[1:3], key = lambda k : posy(k))
         # Top right
        window.moveresize(client_list[1], x + gap/2, gap, resolution.width - x - gap * 1.5,  y + overlap - gap * 1.5, wm)
        # Bottom right
        window.moveresize(client_list[2], x + gap/2, y + gap/2, resolution.width - x - gap*1.5, resolution.height - y - gap * 1.5, wm)
        # Left
        window.moveresize(client_list[0], gap, gap, x + overlap - gap * 1.5, resolution.height - gap * 2, wm)       
    
def tile4 (client_list, x, y):
    client_list.sort (key = lambda k : posx(k))
    client_list = sorted (client_list[0:2], key = lambda x : posy(x)) + sorted (client_list[2:4], key = lambda x : posy(x))
    
    wm = window.WindowManagers.Openbox
    # Top left
    window.moveresize(client_list[0], gap, gap, x + overlap - gap * 1.5, y + overlap - gap * 1.5, wm)
    # Bottom left
    window.moveresize(client_list[1], gap, y + gap/2, x + overlap - gap * 1.5, resolution.height - y - gap * 1.5, wm)
    # Top right
    window.moveresize(client_list[2], x + gap/2, gap, resolution.width - x - gap * 1.5 , y + overlap - gap * 1.5, wm)
    # Bottom right
    window.moveresize(client_list[3], x + gap/2, y + gap/2, resolution.width - x - gap * 1.5, resolution.height - y - gap * 1.5, wm)
    
main ()