How to make jwm or wmctrl resize browser window?

Using applications, configuring, problems
Post Reply
Message
Author
User avatar
tallboy
Posts: 1760
Joined: Tue 21 Sep 2010, 21:56
Location: Drøbak, Norway

How to make jwm or wmctrl resize browser window?

#1 Post by tallboy »

With great help from MochiMoppel, I made my Palemoon browser open, and also take focus, in virtual desktop 4, using wmctrl:
Browser open in virtual desktop 4, how to move focus too?.
My old 15" Dell monitor gave up a few days ago, and I was fortunate to pick up for free an HP 22" wide-screen monitor. I am not used to wide-screen, and I don't like the browser window to fill the entire screen. So, I try to make it open in a spesific screen, position and size, thus keeping my desktop icons visible.
My script palemon-4 opens the browser: (wmctrl counts from 0)

Code: Select all

#!/bin/bash
wmctrl -s 3; exec /usr/bin/palemoon "$@"
I can also resize the browser window with this command in a terminal:

Code: Select all

# wmctrl -r Pale Moon -e 8,270,88,1200,910
But I have 2 problems:
1) I would like the browser window to open in v.d.4, resize/reposition and take focus, but I am not capable of including the command in the script, and make it work! :(
2) If I open a new regular or private window from the browser menu, the command will not resize the new window, not even from a new terminal. Is that because it is a child window?
BTW, the main and child window share the PID, but using wmctrl -i -r plus the PID, doesn't work for either window.

Can someone please suggest a solution?

Edit: There is one solution for a command using the :SELECT: option, where there is a pause which let you click on the window that is to be resized, it works on child windows, but only as a separate command.

Code: Select all

# wmctrl -r :SELECT: -e 0,270,88,1200,910
When I make a script paleselect of that and pipe the original script into it, I can open a new window and click on it to reposition and resize it. But as long as it only works on new windows, it is only a half solution.

Code: Select all

#!/bin/bash
wmctrl -s 3; exec /usr/bin/palemoon "$@" | paleselect
tallboy
Last edited by tallboy on Wed 30 Aug 2017, 05:46, edited 2 times in total.

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

#2 Post by MochiMoppel »

Try

Code: Select all

#!/bin/bash
wmctrl -s 3
exec /usr/bin/palemoon "$@" &
sleep 3
wmctrl -r "Pale Moon" -e 8,270,88,1200,910
Note the '&' and the quotes around "Pale Moon".
As the browser needs some time to "settle" the sleep command is necessary before you start the resizing. 3 seconds works fine here but you may need a different timing.

When you open a new window from the browser the size will be the same as the resized original window.
Your terminal command does not resize the 2nd window as wmctrl will search for a window matching "Pale Moon" in the title, and the first it will find will always be the original window (lower window ID)

User avatar
tallboy
Posts: 1760
Joined: Tue 21 Sep 2010, 21:56
Location: Drøbak, Norway

#3 Post by tallboy »

Thank you Mochi, I'll try it out..
BTW, I added something to my post at the same time you posted.

tallboy
True freedom is a live Puppy on a multisession CD/DVD.

User avatar
tallboy
Posts: 1760
Joined: Tue 21 Sep 2010, 21:56
Location: Drøbak, Norway

#4 Post by tallboy »

That work very well, Mochi, thank you. I can actually get away with 2 seconds sleep.

By using the last script in my post with the :SELECT: option, it will work on all new windows, but not children.

I also saw that JWM 2.3.7 has some new options in Rule Settings, with initial geometry settings for windows, but I don't know if I can use the latest JWM in my Lucid 5.2.8.7, and I don't know if they'll work!

Why the "Pale Moon" in quotes? wmctrl also works with just pale.

tallboy
True freedom is a live Puppy on a multisession CD/DVD.

User avatar
tallboy
Posts: 1760
Joined: Tue 21 Sep 2010, 21:56
Location: Drøbak, Norway

#5 Post by tallboy »

Another path to a solution may be extracting the window ID from wmctrl -lp, a new window will be the last one listed, but how to make a script that interprets the making of a new window from the browser's menu, is way beyond me! :lol:

tallboy
True freedom is a live Puppy on a multisession CD/DVD.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#6 Post by musher0 »

Hi tallboy.

The following will resize any window to 4/8 th's of your screen.

It is based on wmctrl's functions SELECT and ACTIVE.

The SELECT function brings a cross-hair on screen. With it you select the
window you wish to resize. The ACTIVE function does the job.

I used ACTIVE twice in this script because I found that it was necessary at
times to "insist" to get the result you want. You may wish to re-check this.

As the file name implies, this script is part of a series of scripts that can
resize a window from 1/8 to 7/8 of your monitor's dimensions. Just play
around with the fractions on the Height and Width lines -- or use another
denominator that suits you.

The code really tells it all! ;) If you need precisions, just ask me.

IHTH. BFN.

~~~~~~~~~~~~~

Code: Select all

#!/bin/sh
# fractions_4-8.sh # To resize an application window
# © Christian L'Écuyer, Gatineau (Qc), Canada, Aug. 30 2017. GPL3
# (alias musher0 [forum Puppy]). https://opensource.org/licenses/GPL-3.0
#################    
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##########
Hauteur="`xwininfo -root | awk '$1 ~ /Height/ { print $2/2 }'`"
Largeur="`xwininfo -root | awk '$1 ~ /Width/ { print $2/2 }'`"

Y="`xwininfo -root | awk '$1 ~ /Height/ { print $2/8 }'`" # Anchor points
X="`xwininfo -root | awk '$1 ~ /Width/ { print $2/8 }'`" # on monitor.

wmctrl -r :SELECT: -e 0,$X,$Y,$Largeur,$Hauteur

# For most windows you need to "insist".
sleep 0.34s
wmctrl -r :ACTIVE: -e 0,$X,$Y,$Largeur,$Hauteur
# & # Do not use the ampersand, it makes the window go a bit nuts.
sleep 0.34s
wmctrl -r :ACTIVE: -e 0,$X,$Y,$Largeur,$Hauteur
#
# NOTE -- Do not use on a window controlled by java, DOSBOX or Wine.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
tallboy
Posts: 1760
Joined: Tue 21 Sep 2010, 21:56
Location: Drøbak, Norway

#7 Post by tallboy »

Thank you, Musher0.
I used ACTIVE twice in this script because I found that it was necessary at times to "insist" to get the result you want. You may wish to re-check this.
The sleep command fixed that.

I now have two solutions to make a new window appear on dt 4, be repositoned, resized and take focus. I usually open new tabs, but I sometimes use a private window, and it seems I will have to use a separate command to place that window on top of the existing.(or somewhere else)

tallboy
Attachments
window.jpg
(39.04 KiB) Downloaded 157 times
True freedom is a live Puppy on a multisession CD/DVD.

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

#8 Post by MochiMoppel »

tallboy wrote:Why the "Pale Moon" in quotes? wmctrl also works with just pale.
Because "Pale Moon" is 1 string and Pale Moon are 2 strings. Wmtrl ignores the 2nd string, so would search only for Pale. In my case found a ROX-Filer window /tmp/palemoon on a different desktop and resized it. The less precise you define the match string the greater your chances that wmctrl finds the wrong window.

If you want to (partly) match the title you could use the more precise

Code: Select all

wmctrl -r " - Pale Moon" -e 8,270,88,1200,910
Hard to believe that any other window except the browser window would match.

Another option is to use the WM_CLASS property:

Code: Select all

wmctrl -xr "Pale moon" -e 8,270,88,1200,910
Will match only windows of the Pale Moon browser

or even more precise

Code: Select all

wmctrl -xr "Navigator" -e 8,270,88,1200,910
Will match only main windows of the Pale Moon browser, but not the initial window "Pale Moon is not currently set as your default browser".

User avatar
tallboy
Posts: 1760
Joined: Tue 21 Sep 2010, 21:56
Location: Drøbak, Norway

#9 Post by tallboy »

Thank you, Mochi, that is very interesting.
I think I will use this script for now:

Code: Select all

#!/bin/bash
wmctrl -s 3; exec /usr/bin/palemoon "$@" | wmctrl -r :SELECT: -e 0,270,88,1200,910
That way all new windows get intentionally selected and repositioned/resized. Can I catch the children with a deamon?

Have you seen the latest JWM options that I mentioned above?

tallboy
True freedom is a live Puppy on a multisession CD/DVD.

Post Reply