Page 1 of 1

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

Posted: Sun 01 Mar 2015, 04:43
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.

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

Posted: Sun 01 Mar 2015, 10:35
by L18L
Gave it a shot in Puppy Precise 5.7.1
Works like a charm.
Thank you.

Posted: Sun 01 Mar 2015, 17:55
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.

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

Posted: Mon 02 Mar 2015, 03:29
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.

Posted: Wed 04 Mar 2015, 20:25
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.

Posted: Thu 05 Mar 2015, 07:11
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...

Posted: Mon 30 Mar 2015, 16:58
by hapless_user
Thanks,MochiMoppel! Simply solves the annoyance of windows overlap!

Posted: Sun 10 May 2015, 00:26
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?

Posted: Mon 11 May 2015, 02:56
by recobayu

Posted: Mon 11 May 2015, 22:20
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.

Posted: Tue 12 May 2015, 01:43
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.

Posted: Wed 13 May 2015, 00:16
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.