# Howto: Nifty Fluxbox Hotkey Window Moving and Resizing

## xiandrow

If you're anything like me, your Fluxbox environment is heavily driven by terminals.  Gentoo especially demands it, and I find myself continually having 6 or 7 terminals open at once.  Frankly, this leads to a lot of clutter, and Its nice to be able to sort out all of my terminals without removing my hands from the keyboard.

The following hot keys allow you to use the Meta(win) button + a number on the numpad to automatically re-size the active window.  The respective sizes are mapped visually to where they would be on the numpad.  Here's how it works:

The corner numbers, 7, 9, 1, and 3, resize the window to a quarter of the screen and move it to its respective corner.  The "Arrow" numbers, 8, 6, 2, and 4, resize the window to a half screen and move it to its respective corner.  I've changed the function of the 5 key several times, but I've settled on having it maximize the active window.

Before you do any of this, you'll need wmctrl installed. 

```
emerge -av wmctrl
```

Here's the snippet of code that goes in your .fluxbox/keys:

```

#meta+7 upper-left quadrant

mod4 none 79 :execCommand wmctrl -r :ACTIVE: -e 0,0,21,800,545

#meta+8 upper half

mod4 none 80 :execCommand wmctrl -r :ACTIVE: -e 0,0,21,1600,545

#meta+9 upper-right quadrant

mod4 none 81 :execCommand wmctrl -r :ACTIVE: -e 0,800,21,800,545

#meta+4 left half-vertical

mod4 none 83 :execCommand wmctrl -r :ACTIVE: -e 0,0,0,800,1158

#meta+5 fullscreen

mod4 none 84 :execCommand wmctrl -r :ACTIVE: -e 0,190,315,1245,600

#meta+6 right half-vertical

mod4 none 85 :execCommand wmctrl -r :ACTIVE: -e 0,800,0,800,1158

#meta+1 lower-left quadrant

mod4 none 87 :execCommand wmctrl -r :ACTIVE: -e 0,0,594,800,579

#meta+2 lower half

mod4 none 88 :execCommand wmctrl -r :ACTIVE: -e 0,0,594,1600,579

#meta+3 lower-right quadrant

mod4 none 89 :execCommand wmctrl -r :ACTIVE: -e 0,800,594,800,579

```

This particular set up is for a 1600x1200 resolution, and will need to be adjusted for different resolutions.  I thought about writing a script that did this, maybe in the future.  

I set the "Menu" key (the one next to the Right Control key) to open a new terminal, and a bash alias that takes 'e' for 'exit', and I can practically throw terminals around the screen, opening new ones and removing them as I need them.

~/.fluxbox/keys

```

Mod1 Menu :execCommand  aterm

```

~/.bashrc

```

alias e='exit'

```

Hope someone finds this useful, or if nothing else, inspiring!

----------

## RedSquirrel

 *xiandrow wrote:*   

> Before you do any of this, you'll need wmctrl installed. 

 

Have you tried using the built-in functionality that Fluxbox offers, namely, MoveTo, ResizeTo, and so on?

http://fluxbox-wiki.org/index.php?title=Keyboard_shortcuts

Since you enjoy this sort of tiling layout feature, have you looked into tiling window managers? (dwm, ratpoison, etc.)

 *xiandrow wrote:*   

> ~/.bashrc
> 
> ```
> 
> alias e='exit'
> ...

 

Control-d works.  :Wink: 

----------

## i92guboj

Moved from Desktop Environments to Documentation, Tips & Tricks.

I think it fits better here.

----------

## xiandrow

Thanks i92guboj, I wasn't paying attention when I posted it, I'll remember that next time.

RedSquirrel wrote:

 *Quote:*   

> 
> 
> Have you tried using the built-in functionality that Fluxbox offers, namely, MoveTo, ResizeTo, and so on?
> 
> http://fluxbox-wiki.org/index.php?title=Keyboard_shortcuts
> ...

 

Thanks for pointing that out, there's some really potent stuff in there.  I started using Fluxbox years ago, and have since returned to it (Compiz is just too bloated).  Its nice to see that Fluxbox has been growing.  I've been told that ratpoison would be up my alley, I might have to check it out.

----------

## freitass

 *RedSquirrel wrote:*   

> Have you tried using the built-in functionality that Fluxbox offers, namely, MoveTo, ResizeTo, and so on?

 

I was searching for the codes of the keys on the numpad to implement the same feature xiandrow posted here. It turns out that those keys can be also referred to as 'KP_i', where 'i' is the correspondent number of the key. Also, I'm using the built-in functionalities of Fluxbox, as questioned by RedSquirrel. The current state of my implementation is shown below:

```
Control Mod1 KP_1 :MacroCmd {ResizeTo 940 575}  {MoveTo 10 10 LowerLeft}   

Control Mod1 KP_2 :MacroCmd {ResizeTo 1890 575} {MoveTo 10 10 LowerLeft}   

Control Mod1 KP_3 :MacroCmd {ResizeTo 940 575}  {MoveTo 10 10 LowerRight}   

Control Mod1 KP_4 :MacroCmd {ResizeTo 940 1160} {MoveTo 10 10 UpperLeft}   

Control Mod1 KP_5 :Maximize

Control Mod1 KP_6 :MacroCmd {ResizeTo 940 1160} {MoveTo 10 10 UpperRight}   

Control Mod1 KP_7 :MacroCmd {ResizeTo 940 575}  {MoveTo 10 10 UpperLeft}   

Control Mod1 KP_8 :MacroCmd {ResizeTo 1890 575} {MoveTo 10 10 UpperLeft}   

Control Mod1 KP_9 :MacroCmd {ResizeTo 940 575}  {MoveTo 10 10 UpperRight}
```

As you may have noticed, the key strokes to resize and move the windows are Ctrl+Alt+Numpad, and the ResizeTo arguments were calculated for a screen resolution of 1920x1200.

Known issues:

- The current implementation only works for one screen resolution (I don't know if there is some kind of variable that holds the width and height of the screen);

- If you start resizing a mazimized window with one of the commands above, when you try to maximize it again you have to type Ctrl+Alt+5 twice, as at the first time the window behave as it was still maximized;

----------

## cld71

I know this is an old post, but with the new Fluxbox 1.3.2 there are new Fluxbox commands that will arrange the window automatically.

arrangewindowshorizontal will arrange the windows horizontally.

arrangewindowsvertical will arrange the windows vertically.

Add this to your .fluxbox/keys file.

Control Shift H :arrangewindowshorizontal

Control Shift V :arrangewindowsvertical

----------

## lyallp

How about this extract from my keys file

Built in Fluxbox capabilities  :Smile: 

```

Shift KP_Left    :MoveLeft  16

Shift KP_Right    :MoveRight 16

Shift KP_Up    :MoveUp    16

Shift KP_Down    :MoveDown  16

Shift KP_Next    :Lower

Shift KP_Prior    :Raise

Mod1 KP_Left    :ResizeHorizontal -8

Mod1 KP_Right    :ResizeHorizontal +8

Mod1 KP_Up    :ResizeVertical   -8

Mod1 KP_Down    :ResizeVertical   +8

Mod1 KP_Add    :Maximize

Mod1 KP_Subtract :ShadeWindow

Mod4 KP_Begin    :ArrangeWindows

!   Keypad

!   +-----------+-----------+-----------+-----------+

!   | Num Lock  |     /     |    *      |     -     |  Key name

!   |           |           |           |  Shrink * |  Shift   

!   |           |           |           |Toggl Shade|  Alt     

!   +-----------+-----------+-----------+-----------+

!   |     7     |     8     |    9      |     +     |  Key name

!   |           |   Mv Up   |           |  Expand * |  Shift   

!   |           | Shrink Up | Push Back |Toggle Full|  Alt     

!   +-----------+-----------+-----------+           |

!   |     4     |     5     |    6      |           |  Key name

!   |  Mv Left  |           |  Mv Right |           |  Shift   

!   |  Smaller  |           |  Bigger   |           |  Alt     

!   +-----------+-----------+-----------+-----------+

!   |     1     |     2     |    3      |  Enter    |  Key name

!   |           |  Mv Down  |           |           |  Shift   

!   |           |Shrink Down| Pull Front|           |  Alt     

!   +-----------+-----------+-----------+           |

!   |           0           |    .      |           |  Key name

!   |                       |           |           |  Shift   

!   |                       |           |           |  Alt     

!   +-----------------------+-----------+-----------+

!   

!   * - xterm only
```

----------

