Enhancing Plank Dock’s Flexibility for Virtual Machines

Last Updated on April 9, 2024 by Freddy Reyes

As an avid user of virtual machines (VMs), I’ve often been slightly frustrated with the Plank dock’s static nature. It cannot adjust when the VM window resizes or the resolution changes. The only workaround until now has been a somewhat clunky process of ending and restarting the Plank. But I’m excited to share a neat solution I’ve devised for this issue.

Before diving into the solution, ensure your system has the necessary tools. Open your terminal and run:

sudo apt update 
sudo apt install libx11-dev make gcc

Tweaking the Autostart First things first, let’s deal with the original Plank autostart shortcut. You can rename it for backup:

mv ~/.config/autostart/plank.desktop ~/.config/autostart/plank.desktop.org

Setting Up Plank as a Systemd Service Create the necessary directories:

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

Then, create a new service file using vi or your preferred editor:

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

And add the following content:

[Unit]
Description=Plank

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

[Install]
WantedBy=multi-user.target

Enable and start the service:

systemctl --user enable plank
pkill -f plank
systemctl --user start plank

Monitoring Resolution Changes with xeventbind Install xeventbind:

git clone https://github.com/ritave/xeventbind.git 
cd xeventbind 
make 
cp ./xeventbind /usr/bin/xeventbind

Automating the Restart Create a script to restart Plank:

/home/{username}/.local/bin/restart_plank.sh

Add the script content:

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

Make it executable:

chmod +x ~/bin/restart_plank.sh

Testing Change your resolution to test the setup:

/usr/bin/xeventbind resolution /home/{username}/.local/bin/restart_plank.sh

Finalizing the Autostart Edit the new Plank autostart shortcut:

And add:

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}/.local/bin/restart_plank.sh" 
Terminal=false 
Type=Application X-GNOME-Autostart-enabled=true

Conclusion: With these steps, Plank should seamlessly restart and adjust whenever your VM window size or resolution changes. While not officially packaged, this solution significantly improves over the previous manual method.

Credit & Original Information Sources:

rbreaves @ https://discourse.ubuntubudgie.org/t/fix-plank-location-when-changing-resolution/5198

Also: