Xfce Forum

Sub domains
 

You are not logged in.

#1 2016-09-02 08:12:57

amjafuso
Member
Registered: 2015-08-18
Posts: 27

Remember window position

How does xfwm4 handle window position & size? Current behaviour is odd:

- open thunar
- resize window
- drag window to another position
- close thunar
- open thunar again
- window has new size but old position

Even after a reboot positions for thunar, firefox, thunderbird and other programs are always the same. Is this normal behaviour or should I change some settings?

Thanks

Offline

#2 2016-09-02 13:08:34

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 9,536

Re: Remember window position

Position and/or size should be remembered if the application supports it. If not, xfwm4 uses Smart Placement (QA #2 and #3). You can adjust smart placement settings at Settings Manager > Window Manager Tweaks > Placement.

Smart placement cannot be disabled. If you need more precise placement, you need to use tools like wmctrl or devilspie.

Offline

#3 2016-09-02 13:17:43

amjafuso
Member
Registered: 2015-08-18
Posts: 27

Re: Remember window position

Exactly, it depends on the program. Which program supports it, thunar?

Offline

#4 2016-09-02 14:18:58

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 9,536

Re: Remember window position

Looking closer, I see that thunar supports size, but not position. You can see this in the settings editor in the Thunar channel - window height and width are saved (and subsequently restored). I imagine most apps would leave the window placement to the window manager, and xfwm4 uses smart placement.

Offline

#5 2016-09-02 14:46:13

amjafuso
Member
Registered: 2015-08-18
Posts: 27

Re: Remember window position

I see. Every morning I need to rearrange my windows (dual screen). In the very beginning window position for every application was set somewhere in the system. And this position seems to be the same every day. A few months ago I used docky to open applications and changed to cairo. Maybe they influence window position as well. It's a pitty position is not remembered. The only way seems to write a custom script which needs much more time than just close a window ;-)

Thanks for your help.

Last edited by amjafuso (2016-09-02 14:48:29)

Offline

#6 2017-01-20 12:59:03

gnanini
Member
Registered: 2017-01-19
Posts: 16

Re: Remember window position

Use devilspie... it will place your windows exactly where you want and how you want...

Offline

#7 2018-04-24 23:45:09

Misko_2083
Member
Registered: 2015-10-13
Posts: 191
Website

Re: Remember window position

This is sort of a way around this.
Starts Thunar, uses xev to monitor the position and Destroy event.
On destroy event saves the thunar's position and size in one temp file in the other workspace.
If this script is relaunched it will read from those files and move the thunar with xdotool. If thunar was closed on another workspace it will open in that workspace with the sam position and size.

#!/bin/bash

# Temp file to store absolute position and dimensions (change this)
DimFile="/home/misko/Desktop/ThunarXYWH"

# Temp file to store the workspace number                  (change this)
WorkspFile="/home/misko/Desktop/Thunarworkspace" 

[[ ! -f "$DimFile" ]] && >"${DimFile}"

grep -q '[^[:space:]]' < "$DimFile" &&  readarray -t START <"$DimFile"

app=thunar
$app

# Check for running instances of $app on current desktop/workspace.
until xdotool getwindowname "$(xdotool search --desktop $(xdotool get_desktop) --class $app 2>/dev/null | tail -1 2>/dev/null)" &>/dev/null; do
        # sleep until the window opens
        sleep .1
done

#Decimal
WindowID="$(xdotool search --desktop $(xdotool get_desktop) --class $app 2>/dev/null | tail -1)"

workspace="$(cat "${WorkspFile}" 2>/dev/null)"

if [[ ${workspace} != "" ]]; then
   # change desktop
   xdotool set_desktop "${workspace: -1}"
   
   # change desktop for window
   xdotool set_desktop_for_window $WindowID "${workspace: -1}"
fi

if [[ ${START[@]} != "" ]]; then
  xdotool windowsize --sync $WindowID ${START[2]} ${START[3]}
  xdotool windowmove --sync $WindowID ${START[0]} ${START[1]}
fi

#Hexadecimal
WindowIDHex=$(printf "0x%08x" ${WindowID})

#Base seven
WindowBSeven=$(printf "0x%07x" ${WindowID})

#Get starting position and size: x, y, width, height
   XWININFO=$(xwininfo -id $WindowIDHex)
   ARRAY=(${XWININFO#* X: })
   AX=${ARRAY[0]}
   AY=${ARRAY[4]}
   RX=${ARRAY[8]}
   RY=${ARRAY[12]}
   W=${ARRAY[14]}
   H=${ARRAY[16]}
   X=$((AX))
   Y=$((AY)) 

# This monitors the window absolute-top-left x, y, width and height for changes
# If the window is moved - this will get new pos and size
# On destroy event, saves X,Y, W, and H
xev -event structure -id ${WindowIDHex} 2>/dev/null |
       while IFS=$',' read -a A;do
            if [[ "${A[0]#"${A%%[![:space:]]*}"}" =~ "event ${WindowBSeven}" && "${A[1]}${A[2]:1:1}${A[3]: -1}" =~ "window ${WindowBSeven}()" ]]; then
                  X="${A[2]//" ("/}"
                  Y="${A[3]%")"}"
                  W="${A[4]//" width "/}"
                  H="${A[5]//" height "/}"
            # On destroy event
            elif [[ "${A[0]}" =~ "DestroyNotify event" ]]; then
                  >"${DimFile}"
                  X=$((X-RX))
                  Y=$((Y-RY)) 
                  # Exports dimensions
                  echo "$X" >> "${DimFile}"
                  echo "$Y" >> "${DimFile}"
                  echo "$W" >> "${DimFile}"
                  echo "$H" >> "${DimFile}"
                  # save current workspace
                  workspace="$(xprop -root -notype _NET_CURRENT_DESKTOP 2>/dev/null)"
                  echo "${workspace:-1}" > "${WorkspFile}"
                  # xev dies hard
                  XevPID="$(ps -eo pid,cmd | grep "xev -event structure -id $WindowIDHex" | grep -v "grep" | awk '{ print $1 }')"
                  kill $XevPID 2> /dev/null
            fi
             A=()
        done

exit 0

Do you want to exit the Circus?
https://www.youtube.com/watch?v=ZJwQicZHp_c

Offline

Board footer

Powered by FluxBB