Xfce Forum

Sub domains
 

You are not logged in.

#1 2018-09-23 04:11:55

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

Icon Position Reset Work Around

This is bothering me for a long time.

How to prevent the icons from reseting their position on boot/logout?

1. The folder ~/.config/xfce4/desktop must be locked before the shutdown, reset or logout happens.
2. There has to be only one (latest) rc file in ~/.config/xfce4/desktop
3. Before ~/.config/xfce4/desktop folder permissions are set back to writable, all the panels have to set their panel struts (reserved spaces).

If the panels are in the window stack the struts are (probably) already set.

I need two scripts:
The first one will be set to start on boot.
Requires innotify-tools

Standard way: Save, chmod +x, make it load on startup.
Settings > Session And Startup > Application Autostart
Command: bash -c 'path/to/script_name'

#!/bin/bash

# This script removes old rc files in $HOME/.config/xfce4/desktop/
# It keeps only the latest created
 
# Get process id of all inotifywait procs watching
# for moved_to events in $HOME/.config/xfce4/desktop/
 
notify_pid=`ps -eo pid,cmd | grep "inotifywait -m $HOME/.config/xfce4/desktop/ -e moved_to" | grep -v grep |  awk '{print $1}'`
 
# kill any watching job if any
for pid in $notify_pid; do
    kill -SIGKILL $pid
    wait $notify_pid >/dev/null 2>&1
done
 
cd $HOME/.config/xfce4/desktop

NUM_PANELS=$(cat $HOME/.config/xfce4/desktop/num_of_panels)

# wait untill all the panels are in the window stack
until [[ "$(xwininfo -root -tree | awk '/[Xx]fce4\-[Pp]anel.*[Xx]fce4-[Pp]anel/ {print $1,$6}' | wc -l)" -eq $NUM_PANELS ]] ; do
    sleep 1
done

# Sets folder permission to writable
chmod 755 $HOME/.config/xfce4/desktop

# When the icons are moved, temp file is created and moved to rc file
 
# Watching for file moved_to event with inotify
# inotifywait prints two lines, second one is ignored.
 
   inotifywait -m $HOME/.config/xfce4/desktop/ -e moved_to \
      | while read path action file && read dummy
        do
 
           # Nested loop lists all the rc files
           for rc_file in $HOME/.config/xfce4/desktop/*.rc
               do
                  # echo "$rc_file" "${path}${file%.*}"
 
                  # If the file is not the latest moved removes it
                  [[ "$rc_file" != "${path}${file%.*}" ]] && rm -v "${rc_file}"
               done
 
         notify-send "icon position saved" "${path}${file%.*}" -i gtk-info -t 2000
     done

Start this script and move one icon and wait untill a notification appears.
This step is necessary because it will remove all but the latest rc file in $HOME/.config/xfce4/desktop/
Then proceed to the second script.

The second script is from ToZ, this script is for log out, shutdown, etc. Uses zenity or yad dialog.
Changed to save the number of panels and sets the folder permission to non-writtable.
On login/boot number of panels will be checked in the second script.

Requires: yad
Save, chmod +x

#!/bin/bash

lock() {
  # Remembers how many panels are there
  xwininfo -root -tree |awk '/[Xx]fce4\-[Pp]anel.*[Xx]fce4-[Pp]anel/ {print $1,$6}' | wc -l > ~/.config/xfce4/desktop/num_of_panels
  # lock dir
  chmod -w ~/.config/xfce4/desktop
}

### Uncomment either the zenity or yad command

#ans=$(zenity  --title "Save With Exit" --height 300 --width 200 --list  --text "Log Out: $USER" --radiolist  --column " " --column "Method" TRUE Logout FALSE Shutdown FALSE Reboot FALSE Suspend FALSE Hibernate FALSE "Lock Screen" FALSE "Reboot Kubuntu")

ans=$(yad  --window-icon=system-devices-panel-information --on-top --sticky --fixed --center --width 200 --entry --title "Xfce Exit" --text "\nSelect an action:\n" --image=xfce4_xicon3 --image-on-top --button="gtk-ok:0" --button="gtk-cancel:1" --text-align center --entry-text  "Logout" "Reboot" "Suspend" "Hibernate" "Power Off" "Lock Screen")

[[ $ret -eq 1 ]] && exit 0

case $ans in 
	Logout*)
                lock
		xfce4-session-logout -l
	;;
	Power*)
                lock
		xfce4-session-logout -h
	;;
	Reboot)
                lock
		xfce4-session-logout -r
	;;
	Suspend*)
		xfce4-session-logout -s
	;;
	Hibernate*)
		xfce4-session-logout --hibernate
	;;
    	Lock*)
        	xflock4
	;;
	*)
	;;
esac
exit 0

* No idea if it will work if a  monitor is replaced with another monitor with the different resolution.
   Or in case a second monitor is plugged in on reboot/new login.

With xfce4, icon position is saved only when the icon or icons are moived, created or deleted. This happens with some delay so you have to wait some time untill the icon position is saved before initiating shutdown/logout...

Last edited by Misko_2083 (2018-09-23 04:51:05)


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

Offline

#2 2018-09-24 11:07:39

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

Re: Icon Position Reset Work Around

Improved: no extra file needed - gets the number of panel windows from xfconf
                 added a timeout - unlocks dir $HOME/.config/xfce4/desktop/ after 15 seconds

clean-xfce-rc

#!/bin/bash

# This script removes old rc files in $HOME/.config/xfce4/desktop/
# It keeps only the latest created
 
# Get process id of all inotifywait procs watching
# for moved_to events in $HOME/.config/xfce4/desktop/
 
notify_pid=`ps -eo pid,cmd | grep "inotifywait -m $HOME/.config/xfce4/desktop/ -e moved_to" | grep -v grep |  awk '{print $1}'`
 
# kill any watching job if any
for pid in $notify_pid; do
    kill -SIGKILL $pid
    wait $notify_pid >/dev/null 2>&1
done
 
cd $HOME/.config/xfce4/desktop

# Gets the number of panel windows
# conviniently xfconf prints two extra lines
NUM_PANEL_WINDOWS=$(xfconf-query -c xfce4-panel -p /panels | wc -l)

# wait buntill all the panels are in the window stack
_WAIT () {
    until [[ "$(xwininfo -root -tree | awk '/[Xx]fce4\-[Pp]anel.*[Xx]fce4-[Pp]anel/ {print $1,$6}' | wc -l)" -eq $NUM_PANEL_WINDOWS ]] ; do
        sleep 1
    done
}

export -f _WAIT

# runs with the timeout
timeout 15 bash -c _WAIT

# Sets folder permission to writable
chmod 755 $HOME/.config/xfce4/desktop

# When the icons are moved, temp file is created and moved to rc file
 
# Watching for file moved_to event with inotify
# inotifywait prints two lines, second one is ignored.
 
   inotifywait -m $HOME/.config/xfce4/desktop/ -e moved_to \
      | while read path action file && read dummy
        do
 
           # Nested loop lists all the rc files
           for rc_file in $HOME/.config/xfce4/desktop/*.rc
               do
                  # echo "$rc_file" "${path}${file%.*}"
 
                  # If the file is not the latest moved removes it
                  [[ "$rc_file" != "${path}${file%.*}" ]] && rm -v "${rc_file}"
               done
 
         notify-send "icon position saved" "${path}${file%.*}" -i gtk-info -t 2000
     done

toz-shutdown-dialog

#!/bin/bash

lock() {
  # lock dir
  chmod -w ~/.config/xfce4/desktop
}

### Uncomment either the zenity or yad command

#ans=$(zenity  --title "Save With Exit" --height 300 --width 200 --list  --text "Log Out: $USER" --radiolist  --column " " --column "Method" TRUE Logout FALSE Shutdown FALSE Reboot FALSE Suspend FALSE Hibernate FALSE "Lock Screen" FALSE "Reboot Kubuntu")

ans=$(yad  --window-icon=system-devices-panel-information --on-top --sticky --fixed --center --width 200 --entry --title "Xfce Exit" --text "\nSelect an action:\n" --image=xfce4_xicon3 --image-on-top --button="gtk-ok:0" --button="gtk-cancel:1" --text-align center --entry-text  "Logout" "Reboot" "Suspend" "Hibernate" "Power Off" "Lock Screen")

[[ $ret -eq 1 ]] && exit 0

case $ans in 
	Logout*)
                lock
		xfce4-session-logout -l
	;;
	Power*)
                lock
		xfce4-session-logout -h
	;;
	Reboot)
                lock
		xfce4-session-logout -r
	;;
	Suspend*)
		xfce4-session-logout -s
	;;
	Hibernate*)
		xfce4-session-logout --hibernate
	;;
    	Lock*)
        	xflock4
	;;
	*)
	;;
esac
exit 0

So far, this works for me. Icons did move a couple of times on startup but that lasted only for a few moments before taking the right position.

Last edited by Misko_2083 (2018-09-24 11:37:10)


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

Offline

#3 2019-05-24 09:34:06

Rossagator
Member
Registered: 2019-05-24
Posts: 1

Re: Icon Position Reset Work Around

I have a monitor positioned above my main monitor.  Naturally this causes all of my icons on my main screen to be repositioned to my top monitor upon login.  Quite frustrating and neck jarring.  I think these scripts will be very useful.  Apologies for the basic question, but how do I get toz-shutdown-dialog to be called upon shutdown / logout etc?  Have I got it wrong? Do i call this one on login too?

Thanks for your help,

Offline

#4 2021-01-26 19:21:07

wsxian
Member
Registered: 2021-01-26
Posts: 1

Re: Icon Position Reset Work Around

I have used this for some time (+2 years) but now have this error message when trying to init:

Failed to init libxfconf: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.

Any help would be appreciated.  Have tried to google the message and not finding a clear answer.
Use MX-18.3 (nice distribution!)

Offline

#5 2021-01-26 22:58:57

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Icon Position Reset Work Around

Hello and welcome.

Make sure you are running Xfce and all of its components as a regular user and not mixing it up with root uses. The error message indicates that it can't connect to the xfconf daemon.

Maybe post back your ~/.xsession-errors file after a fresh login.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

Board footer

Powered by FluxBB