JWM: How to quickly display 2 windows side-by-side

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

JWM: How to quickly display 2 windows side-by-side

#1 Post by MochiMoppel »

A user made a request to mimic the AeroSnap function of Windows 7 with JWM. I don't know if it is useful for anyone else, but I gave it a shot.
AeroSnap lets you quickly snap a window to any of the 4 screen edges, resizing it to half of screen size. This makes it easy to display 2 windows side-by-side.

The following steps will add 4 keyboard shortcuts Ctrl+Alt+Left/Top/Right/Down to JWM's configuration. The code requires wmctrl to be installed. Please note that the windows will be horizontally or vertically maximized. This allows to restore them (approximately!) to their previous size.

Step 1: Open file /root/.jwm/jwmrc-personal with an editor
Step 2: Insert following 4 shortcuts (If your browser shows more than 4 lines: copy the whole code section to your editor. This will eliminate any confusing line wraps and you should end up with only 4 lines)
Step 3: Save jwmrc-personal
Step 4: Restart JWM (Menu: Shutdown > Restart JWM or from Terminal: jwm -restart)

Code: Select all

<Key mask="AC" key="Left"> exec:SW=$(($(cat /tmp/pup_event_frontend_scrn_x)/2));wmctrl -r :ACTIVE: -e 0,0,-1,$SW,-1;  wmctrl -r :ACTIVE: -b add,maximized_vert</Key>
<Key mask="AC" key="Right">exec:SW=$(($(cat /tmp/pup_event_frontend_scrn_x)/2));wmctrl -r :ACTIVE: -e 0,$SW,-1,$SW,-1;wmctrl -r :ACTIVE: -b add,maximized_vert</Key>
<Key mask="AC" key="Up">   exec:SH=$(($(cat /tmp/pup_event_frontend_scrn_y)/2));wmctrl -r :ACTIVE: -e 0,-1,0,-1,$SH;  wmctrl -r :ACTIVE: -b add,maximized_horz</Key>
<Key mask="AC" key="Down"> exec:SH=$(($(cat /tmp/pup_event_frontend_scrn_y)/2));wmctrl -r :ACTIVE: -e 0,-1,$SH,-1,$SH;wmctrl -r :ACTIVE: -b add,maximized_horz</Key>
That's all.

IMPORTANT UPDATE 2015-05-16
JWM v.2.3 adds new configuration options and key bindings: maxh, maxv, maxtop, maxbottom, maxleft and maxright.
This not only makes above wmctrl work around obsolete, it provides much faster and reliable tiling. Above shortcuts would look like this:

Code: Select all

<Key mask="AC" key="Left">maxleft</Key>
<Key mask="AC" key="Right">maxright</Key>
<Key mask="AC" key="Up">maxtop</Key>
<Key mask="AC" key="Down">maxbottom</Key>
Tested with the currently newest snapshot 1102 Looks perfect. Screen orientation observed, trays observed and window size/position correctly restored to pre-tiling settings.
Last edited by MochiMoppel on Sat 16 May 2015, 07:11, edited 1 time in total.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: JWM: How to quickly display 2 windows side-by-side

#2 Post by L18L »

Gave it a shot in Puppy Precise 5.7.1
Works like a charm.
Thank you.
Attachments
side-by-side.png
(49.4 KiB) Downloaded 1777 times

User avatar
recobayu
Posts: 387
Joined: Wed 15 Sep 2010, 22:48
Location: indonesia

#3 Post by recobayu »

Great! Finally, someone use this method. Thanks Mochi. Your script is very very simple. Ohya, in the new jwm like Tahrpup, the windows key is work nice. So we can change

Code: Select all

<Key mask="AC" key="Left">
by

Code: Select all

<Key mask="4" key="Left">
then we can control window position by win + arrow. :wink: just like cinnamon and wdz10 did.
I'm so sorry about your personal jwmrc. :cry:
I think usually I install a new pet comes from this universe into a 'prefix = ram' puppy.

User avatar
Puppus Dogfellow
Posts: 1667
Joined: Tue 08 Jan 2013, 01:39
Location: nyc

Re: JWM: How to quickly display 2 windows side-by-side

#4 Post by Puppus Dogfellow »

MochiMoppel wrote:A user made a request to mimic the AeroSnap function of Windows 7 with JWM. I don't know if it is useful for anyone else, but I gave it a shot.
AeroSnap lets you quickly snap a window to any of the 4 screen edges, resizing it to half of screen size. This makes it easy to display 2 windows side-by-side.

The following steps will add 4 keyboard shortcuts Ctrl+Alt+Left/Top/Right/Down to JWM's configuration. The code requires wmctrl to be installed. Please note that the windows will be horizontally or vertically maximized. This allows to restore them (approximately!) to their previous size.

Step 1: Open file /root/.jwm/jwmrc-personal with an editor
Step 2: Insert following 4 red lines (If your browser shows more than 4 lines: copy the whole red section to your editor. This will eliminate any confusing line wraps and you should end up with only 4 lines)
Step 3: Save jwmrc-personal
Step 4: Restart JWM (Menu: Shutdown > Restart JWM or from Terminal: jwm -restart)

<Key keycode="236">exec:defaultbrowser</Key>
<Key keycode="111">exec:tas</Key>


<Key mask="AC" key="Left"> exec:SW=$(($(cat /tmp/pup_event_frontend_scrn_x)/2));wmctrl -r :ACTIVE: -e 0,0,-1,$SW,-1; wmctrl -r :ACTIVE: -b add,maximized_vert</Key>
<Key mask="AC" key="Right">exec:SW=$(($(cat /tmp/pup_event_frontend_scrn_x)/2));wmctrl -r :ACTIVE: -e 0,$SW,-1,$SW,-1;wmctrl -r :ACTIVE: -b add,maximized_vert</Key>
<Key mask="AC" key="Up"> exec:SH=$(($(cat /tmp/pup_event_frontend_scrn_y)/2));wmctrl -r :ACTIVE: -e 0,-1,0,-1,$SH; wmctrl -r :ACTIVE: -b add,maximized_horz</Key>
<Key mask="AC" key="Down"> exec:SH=$(($(cat /tmp/pup_event_frontend_scrn_y)/2));wmctrl -r :ACTIVE: -e 0,-1,$SH,-1,$SH;wmctrl -r :ACTIVE: -b add,maximized_horz</Key>

</JWM>

That's all.
this is potentially much nicer, neater, and more convenient than whati have, that i already have it notwithstanding.
:D

Mochi, how can i get wmctrl to work on a specific screen/monitor, or more directly to the point, how can your code be adapted to work on the second, or third (etc) monitor? i can't find the part of puppy that identifies each screen as an individual entity--i thought your "pup_event_frontend_scrn_y" might be the clue i needed, but--if it is, i still don't get it.
:?


and not something i'm interested in, but since it's come up before--do you know what would make a dragged window snap to a given edge like the OP was requesting? i know ETP had something like that--is it a mouse thing or a move onto script thing or... just curious and in case it comes up again.

also, thanks in advance and thanks once again for the nearly countless tweaks you've helped me make to my setups.

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

#5 Post by step »

On Windows I'm addicted to a autohotkey script that uses a clever combination of keys to resize and position the active window: CAPS LOCK followed by a letter key. I don't know, I'm asking now: can linux use CAPS+letter instead of Ctrl/Win/Shift/Alt combinations?

If you're curious, the autohotkey script is pretty smart. CAPSLOCK+a resizes the active window to half screen width and snaps it to the left edge of the screen. CAPSLOCK+d does the same to the right edge. CAPSLOCK+d followed again by CAPSLOCK+d reduces to 1/4 screen width and snaps to right edge. CAPSLOCK+w snaps to top. CAPS+x to bottom. CAPS+s to screen center. Repeatedly pressing the same key combo cycles through predefined sizes: 1/2, 1/4, 3/4. And letters a,d,w,x, and s form a cross by the CAPS key. Very visual, easy to remember.
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#6 Post by greengeek »

step wrote:And letters a,d,w,x, and s form a cross by the CAPS key. Very visual, easy to remember.
If anyone gets this going I'd love to see it using caps+arrows rather than caps+letter.

The arrow functions would be more visual for me than adwsx (which is admittedly visual but easily forgotten by my brain...

hapless_user
Posts: 14
Joined: Fri 20 Feb 2015, 15:21

#7 Post by hapless_user »

Thanks,MochiMoppel! Simply solves the annoyance of windows overlap!

unL33T
Posts: 8
Joined: Sun 10 May 2015, 00:05

#8 Post by unL33T »

For some reason only Left and Up are working for me. Using Right or Down does the same and Left and Up respectively.

Any suggestions?

Edit: Nevermind, I found there is different behaviour depending on whether I have already used this shortcut on a window or not. For example, if I use the shortcut to push it to the right of the screen and then try to push it to the left, it doesn't work. Wonder why. But on a newly opened window, any of the shortcuts will work. Guessing it has something to do with how the hotkey script interacts with the window manager?

User avatar
recobayu
Posts: 387
Joined: Wed 15 Sep 2010, 22:48
Location: indonesia

#9 Post by recobayu »


unL33T
Posts: 8
Joined: Sun 10 May 2015, 00:05

#10 Post by unL33T »

recobayu wrote:unL33T,
try here, stickyjwm2.pet:
http://murga-linux.com/puppy/viewtopic. ... 071#834071
:)
Awesome! Thanks!

Is there a way I can use my Windows key (Super_L) as a hotkey while also using it as a mask?

I'd like to be able to use it to open the menu (ideally also from the bottom left corner) while maintaining it's use as a mask for these window shortcuts and a few others I have set up to mimic the behaviour of Windows.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#11 Post by MochiMoppel »

unL33T wrote:if I use the shortcut to push it to the right of the screen and then try to push it to the left, it doesn't work. Wonder why. But on a newly opened window, any of the shortcuts will work. Guessing it has something to do with how the hotkey script interacts with the window manager?
Probably. I tried to keep the code as short as possible, but this may have pushed the wm to its limits. Checking my own implementation I notice that I added a step to clear the maximized status of a window before changing back to normal size. Can't remember why I did it (my original code works for me), but it could well be that I faced the same issues as you did in some distributions.

This is basically what I use now. Maybe you can kindly try it and report back if it solves your issue:

Code: Select all

<Key mask="AC" key="Left"> exec:
	SW=$(($(xwininfo -root|awk '$1=="Width:"{print $2}')/2))
	wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz
	wmctrl -r :ACTIVE: -e 0,0,-1,$SW,-1
	wmctrl -r :ACTIVE: -b add,maximized_vert
</Key>
<Key mask="AC" key="Right">exec:
	SW=$(($(xwininfo -root|awk '$1=="Width:"{print $2}')/2))
	wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz
	wmctrl -r :ACTIVE: -e 0,$SW,-1,$SW,-1
	wmctrl -r :ACTIVE: -b add,maximized_vert
</Key>
<Key mask="AC" key="Up"> exec:
	SH=$(($(xwininfo -root|awk '$1=="Height:"{print $2}')/2))
	wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz
	wmctrl -r :ACTIVE: -e 0,-1,0,-1,$SH
	wmctrl -r :ACTIVE: -b add,maximized_horz
</Key>
<Key mask="AC" key="Down"> exec:
	SH=$(($(xwininfo -root|awk '$1=="Height:"{print $2}')/2))
	wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz
	wmctrl -r :ACTIVE: -e 0,-1,$SH,-1,$SH
	wmctrl -r :ACTIVE: -b add,maximized_horz
</Key>
As for the Windows key: You can use it as a modifier key or a normal key, but both? How should this possibly work? You can however use different assignments for left and right Windows keys.

unL33T
Posts: 8
Joined: Sun 10 May 2015, 00:05

#12 Post by unL33T »

MochiMoppel wrote:
unL33T wrote:if I use the shortcut to push it to the right of the screen and then try to push it to the left, it doesn't work. Wonder why. But on a newly opened window, any of the shortcuts will work. Guessing it has something to do with how the hotkey script interacts with the window manager?
Probably. I tried to keep the code as short as possible, but this may have pushed the wm to its limits. Checking my own implementation I notice that I added a step to clear the maximized status of a window before changing back to normal size. Can't remember why I did it (my original code works for me), but it could well be that I faced the same issues as you did in some distributions.

This is basically what I use now. Maybe you can kindly try it and report back if it solves your issue:

Code: Select all

<Key mask="AC" key="Left"> exec:
	SW=$(($(xwininfo -root|awk '$1=="Width:"{print $2}')/2))
	wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz
	wmctrl -r :ACTIVE: -e 0,0,-1,$SW,-1
	wmctrl -r :ACTIVE: -b add,maximized_vert
</Key>
<Key mask="AC" key="Right">exec:
	SW=$(($(xwininfo -root|awk '$1=="Width:"{print $2}')/2))
	wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz
	wmctrl -r :ACTIVE: -e 0,$SW,-1,$SW,-1
	wmctrl -r :ACTIVE: -b add,maximized_vert
</Key>
<Key mask="AC" key="Up"> exec:
	SH=$(($(xwininfo -root|awk '$1=="Height:"{print $2}')/2))
	wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz
	wmctrl -r :ACTIVE: -e 0,-1,0,-1,$SH
	wmctrl -r :ACTIVE: -b add,maximized_horz
</Key>
<Key mask="AC" key="Down"> exec:
	SH=$(($(xwininfo -root|awk '$1=="Height:"{print $2}')/2))
	wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz
	wmctrl -r :ACTIVE: -e 0,-1,$SH,-1,$SH
	wmctrl -r :ACTIVE: -b add,maximized_horz
</Key>
As for the Windows key: You can use it as a modifier key or a normal key, but both? How should this possibly work? You can however use different assignments for left and right Windows keys.
The second version that was posted above already resolved my problem. Thanks, though. :)

It works in Windows (single press of the Win key brings up Start Menu, Win + other keys are many shortcuts [show desktop, run, open explorer, etc]) but I agree, it is hard to implement in JWM, it seems. No matter what I try I end up with just the menu opening.

Post Reply