how to make a window occupy half the screen?

Forum rules
Before you post please read this

how to make a window occupy half the screen?

Postby ChickenPie4Tea on Tue Mar 06, 2012 7:32 am

on windows I used AutoHotkey and a little script combined with a keyboard shortcut so that I could make the active programs gui go to one half of the screen. There is no AutoHotkey for Linux so I wonder if instead I could use two different bash scripts that I could link to keyboard shortucts to call them. I would like one script to put the active window at the left half of the screen and one to put it to the right. Basically what I want is to be able to see two windows side by side with each one occupying half the screen.
any one got a bash script that can do this? I dont know bash at all.
ChickenPie4Tea
Level 3
Level 3
 
Posts: 109
Joined: Sun Jan 22, 2012 6:44 pm

Linux Mint is funded by ads and donations.
 

Re: how to make a window occupy half the screen?

Postby viking777 on Tue Mar 06, 2012 11:06 am

Why can't you just drag it there? - it happens automatically for me.
Fujitsu Lifebook AH532. Intel i5 processor, 6Gb ram, Intel HD3000 graphics, Intel Audio/wifi. Realtek RTL8111/8168B Ethernet.Lubuntu 13.10,Ubuntu12.10 (Unity), Mint16 (Cinnamon), Manjaro (Xfce).
Image
User avatar
viking777
Level 14
Level 14
 
Posts: 5153
Joined: Mon Dec 01, 2008 11:21 am

Re: how to make a window occupy half the screen?

Postby mph426 on Wed Mar 14, 2012 10:01 am

I don't know about going to 1/2 screen but, if you click on the System menu button then Preferences -> Keyboard Shortcuts. Scroll down to Window Management, there you can Toggle maximization state, vertical and horizontal maximization states from the keyboard. Since I do a lot of scripting, I use these shortcuts very extensively.

It may not be exactly what you want, but it should be useful.

Regards,

MPH
I'd rather have a bottle in front of me than a frontal lobotomy.
mph426
Level 1
Level 1
 
Posts: 23
Joined: Fri Dec 16, 2011 3:03 pm
Location: State of confusion

Re: how to make a window occupy half the screen?

Postby xenopeek on Wed Mar 14, 2012 4:23 pm

You can probably program that, once you know a little bash, using wmctrl or xdotool. I've used both in the past to automatically make applications start on a specific workspace. Documentation on these is available, but perhaps search for some examples to get you started easier.

Perhaps if this is your workflow (having windows occupy half the screen), a tiling window manager would be more to your liking. Something like xmonad, but there are lots of others.
User avatar
xenopeek
Level 21
Level 21
 
Posts: 14823
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: how to make a window occupy half the screen?

Postby mph426 on Thu Mar 15, 2012 1:13 pm

Vincent,
Excellent source of info. I installed wmctrl this morning. Very nice, I wish I'd of found this years ago. THANKS!

ChickenPie4Tea,
I threw this script together fairly hastily this morning, but it might suit your purposes. I does mine. ;)
It's not quite right but close enough for now. Now all I need to do is set it up to some keyboard short cuts. 8)

NOTE: The window's maximized state toggle will override this. I.E. If the window is already toggled maximized this won't work in whatever direction the window is maximized.

Code: Select all
#! /bin/ksh
#
# wm_ctrl.sh MPH (2011/03/15)
#
###########################################################################
# Vars
###########################################################################
wm_size=`wmctrl -d | head -1 | awk '{print $9}'`
wm_wd=`echo "$wm_size" | awk -F"x" '{print $1}'`
wm_hi=`echo "$wm_size" | awk -F"x" '{print $2}'`
hh=`echo "scale=0; $wm_hi/2" | bc -l`
hw=`echo "scale=0; $wm_wd/2" | bc -l`
vpos="-1"
hpos="-1"
wd="-1"
ht="-1"
type=":ACTIVE:"

###########################################################################
# Functions
###########################################################################
# usage: A brief explanation.
usage(){
  echo
  echo "Usage:"
  echo `basename "$0"` " [Option(s)] [window]"
  echo
  echo "Options:"
  echo "  -a Manipulate the active window."
  echo "  -s Forces the user to select a window to manipulate."
  echo "  -d Forces window to full width."
  echo "  -f Forces window to full height."
  echo "  -b When resizing a window's height specify that it is to use"
  echo "     the bottom half of the screen, top is the default."
  echo "  -t Resize a window to half the height of the current desktop."
  echo "  -w Resize a window to half the width of the current desktop."
  echo "  -b When resizing a window send it to the bottom. Top is the default."
  echo "     Most usefull when halfing a window."
  echo "  -h This help."
  exit 0
}
###########################################################################
# Main
###########################################################################

while getopts abdfhlrstw opt
do
  case "$opt" in
    a) type=":ACTIVE:";;
    b) hpos="$hh";;
    f) ht="$wm_hi";;
    d) wd="$wm_wd";;
    l) vpos="0";;
    r) vpos="$hw";;
    s) type=":SELECT:";;
    t) ht="$hh";;
    w) wd="$hw";;
    h) usage;;
    *) usage;;
  esac
done

wmctrl -r "$type" -e 0,"$vpos","$hpos","$wd","$ht"
I'd rather have a bottle in front of me than a frontal lobotomy.
mph426
Level 1
Level 1
 
Posts: 23
Joined: Fri Dec 16, 2011 3:03 pm
Location: State of confusion


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 1 guest