Skip to content

Instantly share code, notes, and snippets.

@jojo2357
Last active July 24, 2023 20:18
Show Gist options
  • Save jojo2357/0737e9156103d104b0b4cf75533c4f1b to your computer and use it in GitHub Desktop.
Save jojo2357/0737e9156103d104b0b4cf75533c4f1b to your computer and use it in GitHub Desktop.
Linux align dock on seam
KERNEL=="card0", SUBSYSTEM=="drm", ENV{XAUTHORITY}="/path/to/xauthority", ENV{DISPLAY}=":display_number", RUN+="/bin/su ME -c /full/path/to/script"

What does this do?

For a GNOME desktop, it will monitor for hdmi being plugged in/out and will place the taskbar/dock in the middle of the TWO displays (warranty void if using more than that)

Why?

So I know if my monitors are located in the right spot; the taskbar/dock will show me the hot edge immediately

How to install

First, lets config the .rules file provided

Find xauthority cache

run the following: $ echo $XAUTHORITY

which should tell you the location of your xauthority cache. Place that path in the ENV{XAUTHORITY} value

Find the display number

Run the following: $ echo $DISPLAY

and paste that in the ENV{DISPLAY} value

whoami?

in the run, replace ME with your username and specify the full path the the script which you already made executable with chmod +x

Get plugging and put the rules file in /etc/udev/rules.d/

Legal

#!/bin/bash
# Copyright (C) 2023 jojo2357
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# DO NOT RUN AS ROOT!
# Sometines we get old values, try to eliminate that
if ! timeout 2 xrandr -q; then
exit 1
fi
xrandrMonitors=$(xrandr --current --listactivemonitors)
#for debugging
#echo $xrandrMonitors > ~/xrandr.log
elocation=$(echo $xrandrMonitors | grep -o -P " \d: \+[\w\-]+ \d+/\d+x\d+/\d+\+\K\d+\+\d+")
external_name=$(echo $xrandrMonitors | grep -o -P " \d: \+\K[\w\-]+")
if [ -z $elocation ]
then
# echo "No external monitor detected, resetting"
dconf write /org/gnome/shell/extensions/dash-to-dock/dock-position "'RIGHT'"
exit 0
fi
externalx=$(echo $elocation | cut -d+ -f1)
externaly=$(echo $elocation | cut -d+ -f2)
mainlocation=$(echo $xrandrMonitors | grep -o -P " \d: \+\*[\w\-]+ \d+/\d+x\d+/\d+\+\K\d+\+\d+")
mainx=$(echo $mainlocation | cut -d+ -f1)
mainy=$(echo $mainlocation | cut -d+ -f2)
if [ $externalx == "0" ]
then
if [ $externaly == "0" ] && [ $mainy == "0" ]
then
dconf write /org/gnome/shell/extensions/dash-to-dock/dock-position "'LEFT'"
elif [ $externaly == "0" ]
then
dconf write /org/gnome/shell/extensions/dash-to-dock/dock-position "'TOP'"
else
dconf write /org/gnome/shell/extensions/dash-to-dock/dock-position "'BOTTOM'"
fi
else
dconf write /org/gnome/shell/extensions/dash-to-dock/dock-position "'RIGHT'"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment