3

Is there any known application which can achieve this? If not, is there anyway of meddling with this myself, I don't need 50/50 for a specific setup I need one program to take up 2/3 and the other 1/3. Would be extremely useful!

As said, if a program doesn't exist, what should I be reading up on to get this to work? (A specific shortcut for example for 2/3 and another for 1/3)

Using Pantheon as of today.

1 Answers1

0

Introduction

The script bellow asks user to choose 1/3 or 2/3 resize option for a window, then allows the user to select a window that is to be resized. The window to be resized to 1/3 will jump on the left and 2/3 window will jump on the right. The script can be bound to a keyboard shortcut as necessary.

Preliminary setup

The script relies on wmctrl program to do the job. Make sure it is installed first with

sudo apt-get install wmctrl

Setting up the Script

  1. Create folder in your home folder called bin. You can do so with the command

    mkdir $HOME/bin`
    
  2. In that folder create a file resizer.sh. Copy over the script below to that file.

  3. Make sure the script is executable with

    chmod 755 $HOME/bin/resizer.sh
    
  4. Open System Settings -> Keyboard -> Shortcuts -> Custom Shortcuts.
    Create a new shortcut and give it full path of the script as command,
    for example, /home/serg/bin/resizer.sh.

My example

I set up the shortcut first:

enter image description here

Then press the shortcut. The popup menu allows selection of 1/3 or 2/3 resize; I choose 1. Notice, there's no additional input, except a single 1 digit

enter image description here

Next I choose the free-floating browser window. It jumps to the left, now 1/3 in width, desktop height.

enter image description here

Same behaviour will be for the 2/3 option, excep the 2/3 window will be placed on the right side enter image description here

Quirks

Having tested this script, the resizing doesn't work on maximized or left/right split windows (CtrlSuper/). Hence, the window must be un-maximized, free-floating.

Script source

#!/bin/bash

#--------------------
# Author: Serg Kolo
# Date: Sept 26,2015
# Purpose: a script to resize a window to its
# 1/3 or 2/3 of width.
# Written for http://askubuntu.com/q/678608/295286
#--------------------


#---------------------
# This part takes user input through graphical popup;
# Input must be 1 or 2, anything else results into an error
# If user selects 1, we set window to 1/3 of desktop width
# and place it on the left;
# If user selects 2,  we set window to 2/3 of desktop width
# and place it on the right;
SIZE=$(zenity --entry --text "Enter (1) for 1/3 and (2) for 2/3 of width")
case  $SIZE in
    "1")NUM=0.333; XPOS=0;;
    "2")NUM=0.667;XPOS=455;;
    *) zenity --error --text="Invalid input"; exit  ;;
esac
#--------------------
# In this part we determine the geometry of the desktop
# and then calculate the width that we want the window to 
# be set using bc, the command line calculator
# printf is used to convert floating point result to 
# integer value, which is required for wmctrl
ROOT_WIDTH=$(xwininfo -root | awk '/Width/ {print $2}')
ROOT_HEIGHT=$(xwininfo -root | awk '/Height/ {print $2}' )
NEW_WIDTH=$(bc <<< $ROOT_WIDTH*$NUM)
NEW_WIDTH=$(printf "%.0f" $NEW_WIDTH)
#----------------------
# This is what actually does the job.
# wmctrl allows you to select the window with -r :SELECT:
# and sets that window to specific gravity,x-position,y-position,width
# height. To keep the script neutral, I've decided to set the 
# height to default desktop height. User can resize the height as 
# necessary by themselves
wmctrl -r :SELECT: -e 0,$XPOS,0,$NEW_WIDTH,$ROOT_HEIGHT
Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497