Forum › Forums › General › Tips and Tricks › Hotkey to Remember window size and position for IceWM
- This topic has 75 replies, 9 voices, and was last updated Feb 23-6:21 pm by Brian Masinick.
-
AuthorPosts
-
June 5, 2020 at 7:48 pm #36857Moderator
BobC
With help from the IceWM devs to come up with the string, this will make it easy to add or update an override window geometry for any particular program.
This is usable for those able to edit the IceWM keys file, because you need to add a hotkey to make it work. I assigned it to Win+R for Remember Window.
key "Super+r" /bin/sh -c "$HOME/add_geo_entry"It runs a little script called $HOME/add_geo_entry. The way its setup at the moment it needs to be in your home directory to work, and has to be executable. I will try to paste the script here if the website will allow it, but it needs to be saved as add_geo_entry and made executable to work. Let me know if you have any problems, comments or possible improvements. This is a first try, and no, there is no way I would have figured out the first bunch of lines myself. LOL, I assembled the easy stuff at the end…
Life is a learning experience everyday, but if we put in a little effort, maybe tomorrow will be a little better.
#!/bin/bash # add geometry entry for active window to winoptions set -- $(icesh -f getGeometry prop _NET_FRAME_EXTENTS prop WM_CLASS | tr '+,' ' ') geo=$1 x=$2 y=$3 left=$7 top=$9 class=${14} let x-=$left let y-=$top # locate winoptions if [[ -d $ICEWM_PRIVCFG ]] then winoptions=$ICEWM_PRIVCFG/winoptions elif [[ -d $XDG_CONFIG_HOME && -d $XDG_CONFIG_HOME/icewm ]] then winoptions=$XDG_CONFIG_HOME/icewm/winoptions elif [[ -d $HOME/.config/icewm ]] then winoptions=$HOME/.config/icewm/winoptions elif [[ -d $HOME/.icewm ]] then winoptions=$HOME/.icewm/winoptions else echo "$0: Cannot find your icewm config directory" >&2 exit 1 fi cls_geo="${class}geometry" newline="${cls_geo}: ${geo}+${x}+${y}" # delete previous sed -i -e "/$cls_geo/d" "$winoptions" # add new echo "$newline" >> "$winoptions" # is there a need to restart icewm? # icewm -r # reload winoptions icesh winoptions- This topic was modified 2 years, 11 months ago by BobC.
- This topic was modified 2 years, 11 months ago by BobC. Reason: code improved by IceWM devs
June 6, 2020 at 12:48 am #36862MemberModdIt
::Hallo BobC,
thanks for the very useful script, not sure if I can do it, a version with addition of remembering “which desktop” together with the position and size as well as setup autostart would mean new users can setup an efficient working environment more easily, yet another step toward perfection along with Antix performance light weight and elegance.Once autostarting an environment in a system has been experienced it feels crazy to have to click around with the mouse, switch desktops setup window sizes before getting anything useful done.
Our work boxes are around 9 to 13 years old but after installing ssd cope well. Ram usage in Conky display right now, 752M, Swap 512. Claws open on WS1, Palemoon on 2, along with Rox filer and Mirage window, and the Firefox I am writing this with. LO Calc on 3 Writer on 4.
Antix magic on a box that was saved from the dump because too weak for windoze 10.. Many Thanks to all who make this possible.
June 6, 2020 at 1:05 am #36863ModeratorBobC
::Thanks for replying. I had hoped you would be one of the people interested in this.
I had thought about that, but don’t have experience using multiple desktops for different purposes like you do. Do you think that it should also remember which workspace as well as the size and position on the workspace?
If people think it would be more useful that way, I can try to make it remember that as well.
I would prefer to just use one hotkey assigned for it rather than have multiple versions if possible. If not, maybe a pop up box with attributes to remember checkboxes would be a reasonable solution. I would expect people would set up the window defaults to match their workflow, and once setup they wouldn’t be changed often.
June 6, 2020 at 1:34 am #36867Member
Xecure
::Have a look at how it looks like in fluxbox, BobC. Open any window, right-click on the window name/bar, and see the “Remember” option. It has workspace, position, size, maximized, etc. When active, a “checkbox” appears for that option.
If you could get some more options (or similar) in the window program you are creating with the iceWM team, it would really be amazing.Fantastic work!
antiX Live system enthusiast.
General Live Boot Parameters for antiX.June 6, 2020 at 2:05 am #36868ModeratorBobC
::I did explain that Fluxbox had the feature and attributes on their window menu pulldown, but don’t know if the IceWM devs will build the feature into the IceWM window menu or not. I suspect if there was sufficient demand for it, they might.
I’ve never used the feature in Fluxbox myself, and haven’t tried doing it in IceWM because it was too difficult trying to maintain it as text in the winoptions text file. I don’t really have an organized workflow myself, so I don’t really know which of those attributes I would want to select often. I thought I would try to be more organized. That was why I decided to prototype the feature with a hotkey to figure out what would be the most the desirable options, and how much I would want to use it, as well as if there was demand from others for the feature, and what options they would want.
It might even work that an attributes selection pop up window could be created and loaded, and then the attributes could be replaced in the winoptions file, like was done with the geometry. It already is much better than trying to figure out the properties and geometry numbers and then typing them into winoptions like Moddit did when he was setting up his system. Lol, that was not something easily explainable or doable for new users. This is.
Just thinking aloud…
June 6, 2020 at 2:31 am #36869MemberPPC
::Bob, you may not believe this, but I’ve been thinking about such a thing for quite some time and I was happy to see you took the matter into your own hands. I tested the script and it’s perfect.
I see it as a part of “wingrid” type of tools, so I set the same kind of keybing: CTRL + ALT + P (for position).Mini how, for users that want to experiment with this functionality but don’t quite know how to do it:
1- on your home folder create a file called “add_geo_entry.sh”
2- open that file, paste into it the script Bob posted in the Original Post, save the file.
3- Menu – Control Centre – Edit IceWM… – “Keys” tab. Roll to the end of the file and paste your keybinding there, for example:
key "Alt+Ctrl+p" /bin/sh -c "$HOME/add_geo_entry.sh"4- Save the file and restart IceWM (Menu – Log Out right arrow – Restart Icewm)
Now you can move/resize any window to the size/place you always want it to be and press the keybinding (in my example, CTRL + ALT + P )
The next time you open that window, it will be in the exact place you want it to be!Note: I used that to always make “Network Settings” (that pops up when you right click the “network info” icon on the tray) appear in the bottom right corner, as god intended it to be 🙂
P.
June 6, 2020 at 4:43 am #36882MemberModdIt
::Hallo BobC, you wrote
maybe a pop up box with attributes to remember (if possible and delete) checkboxes would be a reasonable solution. I would expect people would set up the window defaults to match their workflow, and once setup they wouldn’t be changed often.I agree that would be the most new user friendly solution.
As you noted it took a while to get things working with editing text files, especially as it looked at first as if Ice could do it without help of wmctrl. After i was unable to get my setup working, installed and use that to put applications in correct windows with startup file.
Once setup we have have found no need for changes. Our standard user for schoolkids and students opens Calc on 4, Writer on 3, Palemoon on 2, Last Claws on 1.
Claws is set to show all IMAP folders immediately as checking and answering mail is first step for all of us after login.Depending on usage style LO Calc and Writer can be a bit touchy, at present we use –norestore –writer/calc to open them with fresh pages.
LO is set to autosave with a very short interval to avoid work loss.That is a workaround for users (kids or “angry parents”) just powering off instead of correctly saving work then shutting down, also helps in power outages caused by roadworks in our area.
My setup uses 6 workspaces at present, switching with Alt 1 to 6 is near instant. I have 2 Gig RAM and rarely see swapping whatever I do. Feels more natural to me than tiling or stacking window management with a couple of desktops.
Thanks for your input PPC, we all are working in same direction it seems, just slightly different routes along the way. :-).
June 6, 2020 at 6:06 am #36889MemberModdIt
::Hi all,
Just an addition, some applications seem to remember window size and position, today I was was using qpdfview and master-pdf-editor, both reopening in same place with same size after correct closure.
Maybe more of this behavior to be found, anyone know the logic behind it ??.Sorry must do my tax report so no time to look myself,for a few days anyway.
June 6, 2020 at 8:46 am #36908ModeratorBobC
::Moddit, some programs, especially the fancy ones that open multiple sessions, will keep track of what was open and where so that they can reopen them the same next time. There shouldn’t be much need for this feature for programs that already handle this internally. I would expect you will find the settings stored under $HOME under either a folder for that program or under $HOME/.config possibly.
From what I see above, we typically want the window to be created a certain size, and in a certain position, on either the current workspace or always on that specific workspace. A “Forget Window” (ie don’t Remember anymore) would be desirable as well.
I looked at the other attributes, and I think we should just keep it simple. If you want to roll it up, or maximize it vertically or horizontally, or define what layer it goes on, why not just use the window menu for that? How often will you setup windows with all kinds of attributes that you want enforced every time you open the program? Adding a dozen options that never get used results in bloated code which ends up complex and slow.
What I see is a key to “Remember Window”, and it brings up a pop-up box showing the window class? being affected, and it shows the Position/Size geometry, and a checkbox for if you want it to remember the Workspace number to open in, and shows what number that would be. It has 3 buttons, one to Apply, one to Delete, and one to Cancel. If you Apply or Delete it reloads winoptions after making the changes to the file.
Maybe it should make a backup copy of winoptions, called winoptions~ before it changes the file just to be safe?
Any comments/suggestions?
PS: The IceWM dev helping improved the code to be more generic so it would work on other distros as well… I replaced the code in the first post with the improved version.
- This reply was modified 2 years, 11 months ago by BobC.
- This reply was modified 2 years, 11 months ago by BobC.
June 7, 2020 at 2:04 am #36945MemberModdIt
::Hi Bob, on keep it simple, you wrote,
What I see is a key to “Remember Window”, and it brings up a pop-up box showing the window class? being affected, and it shows the Position/Size geometry, and a checkbox for if you want it to remember the Workspace number to open in, and shows what number that would be. It has 3 buttons, one to Apply, one to Delete, and one to Cancel. If you Apply or Delete it reloads winoptions after making the changes to the file. and a backup copy of winoptions.Sound pretty much perfect to me. Thanks again to you and Icewm devs for making an already fantastic wm even better.
June 7, 2020 at 9:26 am #36964ModeratorBobC
::The IceWM dev posted revised code, and it is improved in that it is command line options driven, but needs to be called with the options. Yad should work to front end that, but I’m not able to write yad scripts. Here is the improved code, hopefully it will post here ok:
#!/bin/bash # # Remember (or forget) window settings in icewm-winoptions. # usage () { cat >&2 <<EOI Usage: $0 [options...] Options are: -a : Use the active window -i : Choose a window interactively -g : Apply the geometry settings -l : Apply the layer settings -r : Remove the existing settings -w : Apply the workspace settings EOI exit 1 } # options defaults active=0 intact=0 geomet=0 layers=0 remove=0 worksp=0 # parse options while [[ $# -ge 1 ]] do case $1 in (-a) active=1 ;; (-i) intact=1 ;; (-g) geomet=1 ;; (-l) layers=1 ;; (-r) remove=1 ;; (-w) worksp=1 ;; (*) usage ;; esac shift done # icesh -f? if [[ $active -eq 1 || $intact -eq 0 ]]; then focus=-f fi if [[ $intact -eq 1 ]]; then focus= fi if [[ $layers -eq 0 && worksp -eq 0 ]]; then geomet=1 fi # create temporary file temp=$(mktemp) # obtain window settings icesh $focus getGeometry getLayer getWorkspace \ prop WM_CLASS prop _NET_FRAME_EXTENTS >"$temp" # file must have something if [[ ! -s $temp ]] then exit 1 fi # remove punctuation sed -i -e 's|[+,]| |g' "$temp" # empty values geo= x= y= left= top= class= layer= work= # read values from file while read a b c d e f g h do if [[ $a =~ ^0x ]] then if [[ $b =~ ^WM_CLASS ]] then class=$d elif [[ $b =~ ^_NET_FRAME_EXTENTS ]] then left=$d top=$f elif [[ $b =~ ^[0-9]+$ || $b -eq -1 || $c = '"All"' ]] then work=$b elif [[ $b =~ ^[A-Z][a-z] ]] then layer=$b fi elif [[ $a =~ ^[0-9] ]] then geo=$a x=$b y=$c fi done <"$temp" # remove temporary file rm -f -- "$temp" # print values if debug? if false then echo "geo=$geo" echo "x=$x" echo "y=$y" echo "left=$left" echo "top=$top" echo "class=$class" echo "layer=$layer" echo "work=$work" fi # correct geometry let x-=$left let y-=$top # locate winoptions if [[ -d $ICEWM_PRIVCFG ]] then winoptions=$ICEWM_PRIVCFG/winoptions elif [[ -d $XDG_CONFIG_HOME && -d $XDG_CONFIG_HOME/icewm ]] then winoptions=$XDG_CONFIG_HOME/icewm/winoptions elif [[ -d $HOME/.config/icewm ]] then winoptions=$HOME/.config/icewm/winoptions elif [[ -d $HOME/.icewm ]] then winoptions=$HOME/.icewm/winoptions else echo "$0: Cannot find your icewm config directory" >&2 exit 1 fi cls_geo="${class}geometry" new_geo="${cls_geo}: ${geo}+${x}+${y}" cls_lay="${class}layer" new_lay="${cls_lay}: ${layer}" cls_wsp="${class}workspace" new_wsp="${cls_wsp}: ${work}" # geometry if [[ $geomet -eq 1 ]] then # delete previous sed -i -e "/$cls_geo/d" "$winoptions" if [[ $remove -eq 0 ]] then # add new echo "$new_geo" >> "$winoptions" fi fi # layer if [[ $layers -eq 1 ]] then # delete previous sed -i -e "/$cls_lay/d" "$winoptions" if [[ $remove -eq 0 ]] then # add new echo "$new_lay" >> "$winoptions" fi fi # workspace if [[ $worksp -eq 1 ]] then # delete previous sed -i -e "/$cls_wsp/d" "$winoptions" if [[ $remove -eq 0 ]] then # add new echo "$new_wsp" >> "$winoptions" fi fi # let icewm reload the winoptions icesh winoptionsJune 7, 2020 at 11:24 am #36968Moderator
Brian Masinick
June 7, 2020 at 3:05 pm #36993ModeratorBobC
::Learning new things is always painful unless and until I’m successful…
Is this what you expected to see?
Attachments:
June 7, 2020 at 3:30 pm #36995ModeratorBobC
::I’m not allowed to delete pictures, so here is a little better version…
Attachments:
June 8, 2020 at 12:18 am #37006MemberModdIt
::Hallo Bob,
looks good, now we have to hope anti will include this tool in full version,then we will be asked for a gui to increase the number of desktops :-).
-
AuthorPosts
- You must be logged in to reply to this topic.

