how to make a window occupy half the screen?

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
ChickenPie4Tea

how to make a window occupy half the screen?

Post by ChickenPie4Tea »

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.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
viking777

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

Post by viking777 »

Why can't you just drag it there? - it happens automatically for me.
mph426

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

Post by mph426 »

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
User avatar
xenopeek
Level 25
Level 25
Posts: 29507
Joined: Wed Jul 06, 2011 3:58 am

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

Post by xenopeek »

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.
Image
mph426

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

Post by mph426 »

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"
Locked

Return to “Scripts & Bash”