Use shortcut keys to resize and position windows/frames in Linux.

I am using window maker as my window manger. Always I prefer to use keyboard shortcuts over mouse. I came across a situation where my screen becomes filled with multiple applications, mostly with terminal consoles. I found terminator a terminal emulator which gives multiple terminals in one window. I am OK with terminator but there are situations like working with web page and console, or any other combination of application in side by side in the desktop.

I searched for a application that will resize, potion any window frames in just a few key press. I found a application named WinSplit with all features what I exactly want, but it is not for Linux, It runs on windows

So I taught of writing a application which will grab the shortcut keys and resize and position the current running application. While trying to implement I came across some tools for Linux. Which are doing things separately, so I decided not to reinvent the wheel and to use those utilities and write a script around it to achieve my task.

The concept is simple. CRTL + ALT + Number pad Key will resize and position the frames accordingly.

With the use of the xrandr wmctrl and xbindkeys, I can command the widows to goto where ever I want in the current screen with just a few key press.

xrandr can do lot of stuff but here I only need to know the screen size in pixels. Simply executing xrandr will list the supported resolutions.

thalib@SilentStorm:$ xrandr
Screen 0: minimum 320 x 200, current 1440 x 900, maximum 8192 x 8192
VGA1 connected 1440x900+0+0 (normal left inverted right x axis y axis) 408mm x 255mm
1440x900 59.9*+ 75.0
1280x1024 75.0 60.0
1280x800 59.8
1152x864 75.0
1024x768 75.1 70.1 60.0
832x624 74.6
800x600 72.2 75.0 60.3 56.2
640x480 72.8 75.0 66.7 60.0
720x400 70.1

First one on the list is current resolutions. hence I will use awk to extract the X and Y.

X=`xrandr | grep “*” | awk ‘{print $1}’ | awk -F “x” ‘{print $1}’`
Y=`xrandr | grep “*” | awk ‘{print $1}’ | awk -F “x” ‘{print $2}’`

Here wmctrl will be used for positioning and resizing.

wmctrl -r :ACTIVE: -e “G,X,Y,H,W”


G = Gravity (It can be set to 1 always).
X and Y are Starting X,Y coordinates in pixels.
H and W are Height and width respectively in pixels.

I have created a bash script which will resize and position the current active window in right place when shell script is invoked with corresponding parameter.

My complete script goes below. This script is customized for Window maker. You may do a very small modification and customized for your window manager or suite your need.

The source code of below script can be found in this URL:



#Max Resolution X and Y
X=`xrandr | grep "*" | awk '{print $1}' | awk -F "x" '{print $1}'`
Y=`xrandr | grep "*" | awk '{print $1}' | awk -F "x" '{print $2}'`

echo Screen Resolution X x Y = $X x $Y

#Working area

echo Wroking area resolution X x Y = $WX x $WY

#X Cordinates

#Y Cordinates

echo X1 = $X1, X2 = $X2
echo Y1 = $Y1, Y2 = $Y2

case "$1" in

wmctrl -r :ACTIVE: -e "1,0,0,$X1,$WY"

wmctrl -r :ACTIVE: -e "1,$X2,0,$X2,$WY"

wmctrl -r :ACTIVE: -e "1,0,0,$WX,$Y1"

wmctrl -r :ACTIVE: -e "1,0,$Y2,$WX,$Y1"

wmctrl -r :ACTIVE: -e "1,$X2,0,$X2,$Y1"

wmctrl -r :ACTIVE: -e "1,0,0,$X1,$Y1"

wmctrl -r :ACTIVE: -e "1,$X2,$Y2,$X1,$Y1"

wmctrl -r :ACTIVE: -e "1,0,$Y2,$X1,$Y1"

echo "Usage: $0 {left|right|up|down|righttop|lefttop|rightbot|leftbot}"
exit 1

exit 0

I have name it as . sample usage of the above script:

$ ./ top

If you are using gnome or KDE then you are lucky, they have their our custom shortcut creating mechanism. But I am using window maker, I didn’t have the provision to add custom shortcut to launch custom applications.

In such a situation xbindkeys came to rescue me. Using xbindkeys we can create custom shortcuts which will run commands/scripts for xbindkeys to work properly we need to write a config file, it will be in ~/.xbindkeysrc. Alternatively you can use xbindkeys-config GUI to create .xbindkeysrc for you.

Configuring shortcuts

I used xbindkeys to configuring shortcuts as below.

My .xbindkeysrc is below.

My .xbindkeysrc (xbinkey configuration) file can be downloaded from here

# xbindkeys configuration #
# Version: 0.1.3
# If you edit this, do not forget to uncomment any lines that you change.
# The pound(#) symbol may be used anywhere for comments.
# A list of keys is in /usr/include/X11/keysym.h and in
# /usr/include/X11/keysymdef.h
# The XK_ is not needed.
# List of modifier (on my keyboard):
#   Control, Shift, Mod1 (Alt), Mod2 (NumLock),
#   Mod3 (CapsLock), Mod4, Mod5 (Scroll).
# Another way to specifie a key is to use 'xev' and set the
# keycode with c:nnn or the modifier with m:nnn where nnn is
# the keycode or the state returned by xev
# This file is created by xbindkey_config
# The structure is :
# # Remark
# "command"
# m:xxx + c:xxx
# Shift+...

#keystate_numlock = enable
#keystate_scrolllock = enable
#keystate_capslock = enable

"/home/thalib/  rightop"
 m:0xc + c:81
 Control+Alt + KP_Prior

"/home/thalib/  rightbot"
 m:0xc + c:89
 Control+Alt + KP_Next

"/home/thalib/  leftop"
 m:0xc + c:79
 Control+Alt + KP_Home

"/home/thalib/  leftbot"
 m:0xc + c:87
 Control+Alt + KP_End

"/home/thalib/  left"
 m:0xc + c:83
 Control+Alt + KP_Left

"/home/thalib/  right"
 m:0xc + c:85
 Control+Alt + KP_Right

"/home/thalib/  up"
 m:0xc + c:80
 Control+Alt + KP_Up

"/home/thalib/  down"
 m:0xc + c:88
 Control+Alt + KP_Down

# End of xbindkeys configuration

Now on every time you login to window maker the xbindkeys should be auto run in the background. Its very simple. window maker executes the commands in the file “~/GNUstep/Library/WindowMaker/autostart”. So we can add “xbindkeys” at the end of the file to run xbindkeys on every login.

Thats it. Now pres the shortcut key when you are on top of a window.

Script on work (Screen shots)

Use Ctrl+ALT+(7 or 1 or 9 or 3) to place the window frames in the corner as show below.

Use Ctrl+ALT+(4 or 6) to place the window frames side by side.

Use Ctrl+ALT+(8 or 6) to place the window frames at top and bottom.

Hope this recipe is useful to you. leave your comment.

8 thoughts on “Use shortcut keys to resize and position windows/frames in Linux.

  1. Thanks a bunch for this. I’ve been running my own website for about four months now, and I get some spam as you do. Posters “Brendon Barrena” and “seo greek” are spammers. Beware!

    Thanks again,

    A real human.

    PS: To the guy running a Mac: use ShiftIt. It’s open-source, works like a charm.

  2. That submitting is very properly published, and yes it furthermore includes several valuable information. My spouse and i appreciated you will be specialized manner of making this site article. Thanks a lot, you may have produced that simple and straightforward for myself to comprehend.

  3. Great article, very, very useful and easy to follow. I changed your bash script to perl and adapted it to take into consideration which physical screen the mouse is in, since I’m using xrandr with 2 physical screens. Again, __thank you__ very much!

  4. An impressive share, I just given this onto a colleague who was doing a little analysis on this. And he in fact bought me breakfast because I found it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I feel strongly about it and love reading more on this topic. If possible, as you become expertise, would you mind updating your blog with more details? It is highly helpful for me. Big thumb up for this blog post!

  5. Thank you soooooooooooooooo much!!! I was using SizeUp (which does pretty much the same) on a mac… and was really missing it (Ubuntu)… Thanks!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s