Fix Plank Location when Changing Resolution

So I was getting annoyed that the Plank dock does not relocate itself when your VM window resizes or resolution changes. You have to end it and then restart it. Well I have found a decent way to implement a fix for this. Not sure if @fossfreedom will want to try and package this as a fix or wait for the Plank authors to implement a better fix altogether.

Here is an overview of what I strung together though.

  1. Remove the original Plank autostart desktop shortcut.
  2. Create Plank as a systemd service
  3. Use xeventbind to monitor resolution changes
  4. Launch Plank and xeventbind in a new Plank autostart shortcut.

Pre-setup

sudo apt update
sudo apt install libx11-dev make gcc

  1. Remove or rename plank.desktop
rm ~/.config/autostart/plank.desktop
#
mv ~/.config/autostart/plank.desktop ~/.config/autostart/plank.desktop.org
  1. Plank as a Systemd service

mkdir -p ~/.config/systemd
mkdir -p ~/.config/systemd/user

vi ~/.config/systemd/user/plank.service

[Unit]
Description=Plank

[Service]
ExecStart=/usr/bin/plank
KillMode=process
RestartSec=3
Restart=always

[Install]
WantedBy=multi-user.target

systemctl --user enable plank
# Kill plank if it is running
pkill -f plank
systemctl --user start plank

  1. Install xeventbind
git clone https://github.com/ritave/xeventbind.git
cd xeventbind
make
cp ./xeventbind /usr/bin/xeventbind
  1. Setup new autostart launcher and script to trigger.

mkdir -p ~/bin
vi ~/bin/restart_plank.sh

#!/bin/bash
systemctl --user restart plank

chmod +x ~/bin/restart_plank.sh

Test it - change your resolution

/usr/bin/xeventbind resolution ~/bin/restart_plank.sh

vi ~/.config/autostart/plank.desktop

[Desktop Entry]
Name=Plank
GenericName=Plank
Comment=Plank
Exec=/usr/bin/bash -c "systemctl --user start plank && /usr/bin/xeventbind resolution /home/{username}/bin/restart_plank.sh"
Terminal=false
Type=Application
X-GNOME-Autostart-enabled=true

https://launchpad.net/ubuntu/+source/plank

If you look at the changelog for 21.04 and 21.10 it sounds like debian has included a relevant patch that maybe messing up here.

Might be worth removing this patch and seeing what happens in a vm

1 Like

Thanks I did not notice this.

ok - the utility does look very small.

If this was ported to run with Vala then we could incorporate this into budgie-extras-daemon (budgie-extras/budgie-extras-daemon at master · UbuntuBudgie/budgie-extras · GitHub)

The idea would be simply to “kill plank; sleep 1 && plank &” on a resolution change.

That way we would have a generic solution specifically for budgie on debian/ubuntu & other distros using budgie-extras.

1 Like

Thanks for pointing me in that direction. Tempted to start digging right now, but I probably won’t be able to look at forking extras until about a week from now. I did mention this issue on their launchpad issues page and have confirmed that I am running the latest -3 minor build so yea… no reason why that patch shouldn’t have worked other than it simply not working.

Wonder if this issue is only on 21.04 or pre-existed, I am not sure.