You are not logged in.

#1 2009-03-10 00:12:16

Shapeshifter
Member
Registered: 2008-03-11
Posts: 230

splitize - for displays which are too big.

Hello there,

I just got rid of my two lovely CRT screens a few days ago (21" and 19", had them for like 7 years or more) as I though it's time to move on. So I bought myself a beautiful 1920x1200 TFT. But I am so used to having two screens that I got a bit frustrated as I always had to drag around window borders to have multiple windows open at the same time in a tidy fashion. And on such a big screen maximising to full width is usually a waste of space.
One obvious solution would be to use a tiling WM! But here's another:

Splitize - In case maximise is useless!

splitize-thumb.png

Bind this script to a global hotkey and it will resize the currently active window to fit a pre-set percentage of the width of the screen. There are three options you need to set at the top of the file:

deskheight=1147 # This is how high your desktop is without any panels
ypos=0 # Set this to another value if you have a panel at the top (e.g. gnome)
leftperc=60 # This is the percentage of the left portion of the screen. I use a 60% - 40% setup as seen on the screenshot. Any other value should work.
sideborder=10 # Set this to the cumulative width of the borders of the left and right of your window decorations.

When everything is set, press the hot key and the currently focused window should resize either to the left or right portion of the screen. press it again and it will go back to its old position/size.

Download it HERE or copy from below. It needs both xdotool and wmctrl to run.

Hope you like it!

A few notes on odd behaviour:
Due to the inconsequence of xdotool and wmctrl (e.g. getting geometry includes borders, setting geometry does not), I had to do some ugly if-conditions. If you splitize a window and then move it less than 30px, it might go to its original size instead of splitizing again and such. I only tried it under kde4 yet, so please report any issues with other WMs. Also note that terminals might not resize to the absolute value you set as they usually have fixed steps. Sometimes the position wont be reset because wmctrl reports wrong coordinates in which case it will only resize to its old size. Also note that windows will resize to the left if the top left corner is in the 1st third of the screen and resize to the left if the top left corner is in the 2nd-3rd third of the screen.

In practical use it has still proven to be usable.

#!/bin/bash

#exec >> /tmp/splitize.log

# Settings
######
deskheight=1147
ypos=0
leftperc=60
sideborder=10
######

deskwidth="$(xwininfo -root | grep "Width" | awk '{print $2}')"
wleft=$((((deskwidth/100))*leftperc))
wright=$((deskwidth-wleft))

window="$((xdotool getactivewindow) 2>/dev/null)"
windowid="$((xwininfo -id $window | grep 'xwininfo: Window id' | awk '{print $4}' | awk -F "x" '{print $2}') 2>/dev/null)"
winprops="$(wmctrl -Gl | grep $windowid)"


x="$(awk '{print $3}' <<< $winprops)"
y="$(awk '{print $4}' <<< $winprops)"
w="$(awk '{print $5}' <<< $winprops)"
h="$(awk '{print $6}' <<< $winprops)"

if ((x<((deskwidth/3)))); then
    nw=$((wleft-sideborder))
    side="l" 
    place=0
else
    nw=$((wright-sideborder))
    side="r"
    place="$wleft"
fi

if [[ ! -e "/tmp/splitize.$windowid" ]]; then
    wmctrl -i -r $window -e "0,$place,$ypos,$nw,$deskheight"
    winprops="$(wmctrl -Gl | grep $windowid)"
    nx="$(awk '{print $3}' <<< $winprops)" 
    ny="$(awk '{print $4}' <<< $winprops)"
    # substract window borders from old position
    if [[ "$side" == "l" ]]; then
        x=$((x-nx)) 
    else
        x=$((x-((nx-place)))) 
    fi
    y=$((y-ny))
    echo "$x $y $w $h" >> "/tmp/splitize.$windowid"
    
else
    if ((h<((deskheight-20)))) || ((y>((ypos+30)))) || ((((x>10)) && ((((x>((wleft+20)))) || ((x<((wleft-20)))))))); then
        
        # Restart if user resized window by hand
        rm "/tmp/splitize.$windowid"
        $0
    else
        file="$(cat "/tmp/splitize.$windowid")"
        echo "$file"
        x="$(awk '{print $1}' <<< $file)"
        y="$(awk '{print $2}' <<< $file)"
        w="$(awk '{print $3}' <<< $file)"
        h="$(awk '{print $4}' <<< $file)" 
        wmctrl -i -r $window -e "0,$x,$y,$w,$h"
        rm "/tmp/splitize.$windowid"
    fi
fi

Last edited by Shapeshifter (2009-03-10 00:28:11)

Offline

Board footer

Powered by FluxBB