CLI Method 2022
pomsky's solution doesn't work anymore, as the preferred-monitor
setting is now deprecated according to the dconf editor.
Luckily they point to the new responsible setting: preferred-monitor-by-connector
, which now uses not numbers but monitor names as used in output of:
xrandr --listactivemonitors
which in my case is:
0: +*DP-0 3840/600x2160/340+3840+0 DP-0
1: +HDMI-1 3840/600x2160/340+0+0 HDMI-1
Monitor with the index 0
is my primary one. But I need it on the second monitor. So I grab the last field of the row with the index 1 and run this:
gsettings set org.gnome.shell.extensions.dash-to-dock preferred-monitor-by-connector HDMI-1
done.
Why I need a command line solution at all? Because after upgrade to 22.04 my monitor settings get reset each time one or both of the displays get turned off and on again. It's totally annoying to set everything back again manually (by mouse) in the settings. Therefore I wrote a script where I set everything I need back again. I then call the script easily by a ulauncher shortcut after one of my displays gets disconnected or when I login after a suspension of the session. It's (probably) easier then to figure out what actually causes the reset of the settings again and again - I've just recently (a couple of months ago) switched to Ubuntu from macOS, so I think such kind of quick hacks are totally legit.