Skip to content

Commit e7be984

Browse files
committed
Fix desktop icons and GTK config files
See #449 (comment)
1 parent 7b66e7b commit e7be984

File tree

1 file changed

+48
-9
lines changed

1 file changed

+48
-9
lines changed

src/desktop-launch

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ else
4242
needs_update=true
4343
fi
4444

45-
# Set $REALHOME to the users real home directory
46-
REALHOME=$(getent passwd $UID | cut -d ':' -f 6)
47-
4845
export SNAP_DESKTOP_RUNTIME=$SNAP
4946

5047
# Set config folder to local path
@@ -54,9 +51,9 @@ chmod 700 "$XDG_CONFIG_HOME"
5451

5552
# If the user has modified their user-dirs settings, force an update
5653
if [[ -f "$XDG_CONFIG_HOME/user-dirs.dirs.md5sum" ]]; then
57-
if [[ "$(md5sum < "$REALHOME/.config/user-dirs.dirs")" != "$(cat "$XDG_CONFIG_HOME/user-dirs.dirs.md5sum")" ||
54+
if [[ "$(md5sum < "$SNAP_REAL_HOME/.config/user-dirs.dirs")" != "$(cat "$XDG_CONFIG_HOME/user-dirs.dirs.md5sum")" ||
5855
( -f "$XDG_CONFIG_HOME/user-dirs.locale.md5sum" &&
59-
"$(md5sum < "$REALHOME/.config/user-dirs.locale")" != "$(cat "$XDG_CONFIG_HOME/user-dirs.locale.md5sum")" ) ]]; then
56+
"$(md5sum < "$SNAP_REAL_HOME/.config/user-dirs.locale")" != "$(cat "$XDG_CONFIG_HOME/user-dirs.locale.md5sum")" ) ]]; then
6057
needs_update=true
6158
fi
6259
else
@@ -326,6 +323,41 @@ if [ -n "$SNAP_DESKTOP_DEBUG" ]; then
326323
echo "Now running: exec $*"
327324
fi
328325

326+
######################################
327+
# Adjustments to shortcuts and icons #
328+
######################################
329+
330+
DESKTOP_PATH=$(grep "XDG_DESKTOP_DIR" $SNAP_REAL_HOME/.config/user-dirs.dirs | cut -d'=' -f2 | sed 's/"//g' | sed "s#\$HOME#$SNAP_REAL_HOME#g")
331+
ensure_dir_exists $SNAP_REAL_HOME/.local/share/applications/
332+
ensure_dir_exists $SNAP_REAL_HOME/.local/share/icons/
333+
334+
# Copy .desktop of Desktop folder
335+
if [ -d "$SNAP_USER_COMMON/Desktop" ] && [ ! -L "$SNAP_USER_COMMON/Desktop" ]; then
336+
for file in "$SNAP_USER_COMMON/Desktop/"*.desktop; do
337+
if [ -e "$file" ]; then
338+
cp -f "$file" "$DESKTOP_PATH/"
339+
fi
340+
done
341+
fi
342+
343+
# Copy icons folder
344+
if [ -d "$SNAP_USER_COMMON/.local/share/icons" ] && [ ! -L "$SNAP_USER_COMMON/.local/share/icons" ]; then
345+
cp -rf "$SNAP_USER_COMMON/.local/share/icons" "$SNAP_REAL_HOME/.local/share/"
346+
fi
347+
348+
# Copy applications folder
349+
if [ -d "$SNAP_USER_COMMON/.local/share/applications" ] && [ ! -L "$SNAP_USER_COMMON/.local/share/applications" ]; then
350+
cp -rf "$SNAP_USER_COMMON/.local/share/applications" "$SNAP_REAL_HOME/.local/share/"
351+
fi
352+
353+
rm -r $SNAP_USER_COMMON/Desktop
354+
rm -r $SNAP_USER_COMMON/.local/share/applications
355+
rm -r $SNAP_USER_COMMON/.local/share/icons
356+
357+
ln -sf "$DESKTOP_PATH" "$SNAP_USER_COMMON/Desktop"
358+
ln -sf $SNAP_REAL_HOME/.local/share/applications/ $SNAP_USER_COMMON/.local/share/applications
359+
ln -sf $SNAP_REAL_HOME/.local/share/icons/ $SNAP_USER_COMMON/.local/share/icons
360+
329361
# Fix default run command
330362
# The default works on a system with only the Snap installed, but if they also
331363
# have the deb then the default command will run the deb instead of the Snap.
@@ -335,13 +367,20 @@ done
335367

336368
# Links game icons to host
337369
find "$SNAP_USER_COMMON/.local/share/icons/hicolor" -type f -name "steam_icon_*.png" | while read -r file; do
338-
dest="${file/$SNAP_USER_COMMON/$REALHOME}"
370+
dest="${file/$SNAP_USER_COMMON/$SNAP_REAL_HOME}"
339371
ensure_dir_exists "$(dirname $dest)"
340-
ln -sf "$file" "$dest"
341372
done
342373

343-
# Link .desktop files to host
344-
ln -sf $SNAP_USER_COMMON/.local/share/applications/* $REALHOME/.local/share/applications/
374+
# GTK theme and behavior modifier
375+
# Those can impact the theme engine used by Qt as well
376+
gtk_configs=(gtk-4.0/settings.ini gtk-4.0/gtk.css gtk-4.0/bookmarks gtk-4.0/colors.css gtk-3.0/settings.ini gtk-3.0/gtk.css gtk-3.0/bookmarks gtk-3.0/colors.css gtk-2.0/gtkfilechooser.ini)
377+
for f in "${gtk_configs[@]}"; do
378+
dest="$XDG_CONFIG_HOME/$f"
379+
if [ ! -L "$dest" ]; then
380+
ensure_dir_exists "$(dirname "$dest")"
381+
ln -s "$SNAP_REAL_HOME/.config/$f" "$dest"
382+
fi
383+
done
345384

346385
strip_unreachable_dirs XDG_DATA_DIRS
347386
strip_unreachable_dirs XDG_CONFIG_DIRS

0 commit comments

Comments
 (0)