“Aero Snap” in Pekwm | urukrama's weblog

Written by Laurent Marechal - 31 march 2015

Classified in : Unix, Links - Tags : UI, Unix

Site d'origine : https://urukrama.wordpress.com/2012/05/12/aero-snap-in-pekwm/

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.

Comments are closed.

SEARCH

Categories

Tags

Archives

Last articles

Last comments

 

Valid XHTML 1.0 Strict