“Aero Snap” in Pekwm

May 12, 2012

I have never used Windows Vista or Windows 7, but from what I’ve learned from others it seems to have one really neat feature: Aero snap. If you drag a window to a screen edge that window will fill half of the available screen space. Tiling two windows is extremely easy with this. You can comfortably view two documents at the same time without losing much screen estate.

Now that I am using Pekwm again, I tried to replicate this behaviour with this window manager. One of Pekwm’s neatest features is its use of screen edges: you can assign mouse actions to the edges of the screen.

Could we use those screen edges to get a window to take up half of the screen space? One of the mouse actions you can use with the screen edges is “EnterMoving”, a mouse event that is only used for the screen edges. As the documentation states, this action “defines how to act when a dragged window enters a ScreenEdge”. The default action assigned to this action is “WarpToWorkspace”; if you drag a window to the left screen edge, the window will be moved to the workspace on the left.

I rarely use this feature, so I lose little by assigning a different action to this mouse binding. I initially tried to use Pekwm’s own window management actions to resize a window that I dragged to a screen edge, but that did not seem to work. But luckily there is wmctrl, a little tool that can manipulate windows managed by standard compliant window managers (like pekwm), from the command line.

Wmctrl is in the repositories of most distributions. If you use Debian or Ubuntu (or one of its derivatives), you can install it with the following command:

sudo aptitude install wmctrl

Once you have wmctrl installed, you have to reconfigure Pekwm’s mouse behaviour, by editing the ~/.pekwm/mouse file which governs all mouse actions. In the ScreenEdge section you’ll find the settings for each of the four screen edges. Look for the line that begins EnterMoving = “Any Any” in each of those section. This is what we will modify (or create if it doesn’t have that behaviour mapped yet for a screen edge).

The wmctrl commands we will use are specific to a particular screen size. The settings I give below are for my desktop screen, which has a 2048×1152 resolution, and for my laptop screen, which has a 1028×768 resolution. If you have a screen of a different size, you’ll have to modify this (I’ll explain how later).

For a 2048×1152 resolution

In the Down section, I have the following:

EnterMoving = "Any Any" { Actions = "Exec wmctrl -r :ACTIVE: -e 0,0,627,2048,550 &" }

In the Up section, I have the following:

EnterMoving = "Any Any" { Actions = "Exec wmctrl -r :ACTIVE: -e 0,0,0,2048,542 &" }

In the Left section:

EnterMoving = "Any Any" { Actions = "Exec wmctrl -r :ACTIVE: -e 0,0,0,1024,1152 &" }

And in the Right section, I have the following:

EnterMoving = "Any Any" { Actions = "Exec wmctrl -r :ACTIVE: -e 0,1025,0,1024,1152 &" }

For a 1028×768 resolution

In the Down section, I have the following:

EnterMoving = "Any Any" { Actions = "Exec wmctrl -r :ACTIVE: -e 0,0,412,1028,324 &" }

In the Up section, I have the following:

EnterMoving = "Any Any" { Actions = "Exec wmctrl -r :ACTIVE: -e 0,0,0,1028,384 &" }

In the Left section:

EnterMoving = "Any Any" { Actions = "Exec wmctrl -r :ACTIVE: -e 0,0,0,513,768 &" }

And in the Right section, I have the following:

EnterMoving = "Any Any" { Actions = "Exec wmctrl -r :ACTIVE: -e 0,513,0,513,768 &" }

These settings work as follows: If I drag a window to the right or left screen edge, it takes up the right or left half of the screen. If I drag it to the top or bottom edge, the window will tile vertically and take up the top or bottom half of the screen. These last settings are a little more troublesome, as you need to take the window decorations into consideration. The above settings are based on the Infinity Pekwm theme. If I were to use a different theme, that has smaller or bigger window decorations, I’ll have to adjust these settings by a few pixels so that the windows will not overlap. Since I very rarely use the vertical tiling (where the biggest changes would have to be made to account for the theme’s window decorations), I am not really bothered by this.

If you have to adjust these settings for your own screen size, it probably helps to know the syntax of the wmctrl command I use above. Let’s use the command for the Left screen edge as an example:

wmctrl -r :ACTIVE: -e 0,0,0,1024,1152

-r :ACTIVE: tells wmctrl to do something with the active window, which would be the window you are dragging into the screen edge. -e, then, tells wmctrl that you want to move and resize the window, according to the values given in the rest of the command, using the following syntax as explained in wmctrl man’s page: g,x,y,w,h.

  • g stands for the gravity. I’m not entirely sure what this does (you can read up on it on the EWMH standards documentation, if you like), but if you use the value 0 for this, it works.
  • x and y determine where the window will be positioned. For the left screen edge this is 0,0, as we want the window in the top left corner. For the right screen edge, this should be 0,half-of-your-horizontal-resolution as you want the window to be positioned at the top of the screen (the 0 value for x), but only beginning from a pixel after the middle of the screen (if you would start from the middle of the screen, it would overlap by a pixel the left window). In my case this is 1025 (half of 2048 + 1). For a 1024×768 screen resolution, this would be 513 (half of 1024 + 1). For the top and bottom edges you would set 0,0 for your top edge (as you want the window to placed in the top right corner), and 0,half-of-your-vertical-resolution for the bottom edge, as you want it to be placed in the middle of your screen.
  • The final two values (w and h) tell wmctrl how to resize the window: how wide and high it should be. For the left and right screen edges, you would want it to fill half of the screen horizontally, and to fill the entire screen vertically, so you would set the first value to half of your screen size (in my case 1024), and the second value to the size of your screen width (in my case 1152). For the top and bottom screen edges, you would reverse these values: the first would be the entire width of your screen (in my case 2048) and half of your vertical screen size, minus the size of your window decorations, as I mentioned before. You could, of course, also adjust the positioning of these windows, by adjusting the previous values.

Make sure that you did not delete the & sign at the end of the action in your configuration file. Once you have configured this for your screen, save your ~/.pekwm/mouse and reconfigure Pekwm. If you drag a window to one of the screen edges now, it should “snap” as it would in Aero (or, since I’ve never used Aero, as I think it would snap in Aero).

The standard Openbox does not make use of the screen edges, so you can’t accomplish this with Openbox, but you could assign these commands to keybindings and do so manually. But in Openbox, you would probably want to use Openbox’ own actions, instead of wmctrl. Have a look at this post for ideas on how to set this up.

About these ads

2 Responses to ““Aero Snap” in Pekwm”

  1. pibarnas said

    First, I’m impressed with your post! First class, as usual! I’m glad you came back to pekwm, to keep teaching us amazing things like this! The question: Maybe I didn’t understand so well, because I followed the steps in this resolution: 1920×1080, so the code got this way: Down 0,0,541,1092,540; Up 0,0,0,1920,542; Left 0,0,0,960,540 and Right 0,961,0,960,540 (only wmctrl arguments). It worked only for the two upper quadrants. For the other two on the bottom of the screen, the windows are positioned above the other ones in the quadrants of the top. Did I miss something??

  2. urukrama said

    I’m not sure I understand exactly what you encounter. But I suspect you want settings that are more like the following:

    Down 0,0,541,1920,540

    Up 0,0,0,1920,542

    Left 0,0,0,960,1080

    Right 0,961,0,960,1080

    Note that for Left and Right, you want the height of the window (the last value) to be the full height of your screen (or a the height of your screen minus the height of your panel if you want to keep the panel visible). You had halfed that last value. You also had a typo in the Down value (1092 instead of 1920). But the above should work. Your Up and Down values will still cause your windows to overlap, though they should be more or less in the right place. Just play a little with the final value of each of these until you get what you want (you should want lower values for both).

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.

Join 79 other followers