Create an XDG desktop entry override for the LibreOffice components you want to use, for example ~/.local/share/applications/libreoffice7.5-writer.desktop You can copy the installed ones from /usr/share/applications as a starting template.
Override the Exec= line to look similar to this:
Exec=GTK_THEME=Adwaita libreoffice7.5 --writer %U
Then rebuild the menus:
kbuildsycoca5 # for KDE, not sure about other desktop environments
If you use KDE make sure (important!) libobasis-{version}-kde-integration is uninstalled:
apt purge libobasis7.5-kde-integration
Here’s a Python script I wrote called libreoffice-menu-update
which will automatically do all of the above after a LibreOffice upgrade (for Debian). Just update the vrs
variable at the top with the version you’re updating to:
#!/usr/bin/python3
# Script to create/update LibreOffice XDG menu entry overrides to force the light theme
# This script is for Debian but may work with other Debian-based distros
# Created by Dhya O
from shutil import copy
from pathlib import Path
from string import Template
import subprocess
vrs = "7.5" # the version of LibreOffice
prepend = "GTK_THEME=Adwaita" # The theme to be applied
srcdir = "/usr/share/applications/"
dstdir = str( Path.home() ) + "/.local/share/applications/"
# Uninstall libobasis<version>-kde-integration
subprocess.run( ['sudo','apt','remove',f'libobasis{vrs}-kde-integration'],
stderr=subprocess.DEVNULL )
lapps = [
"base",
"calc",
"draw",
"impress",
"math",
"startcenter",
"writer"
]
# delete user's existing custom LibreOffice .desktop files
for f in Path( dstdir ).glob( "libreoffice*.desktop" ):
f.unlink()
# copy system LibreOffice .desktop files to user's XDG .desktop dir
for app in lapps:
appname = f"libreoffice{vrs}-{app}.desktop"
src = f"{srcdir}{appname}"
dst = f"{dstdir}{appname}"
copy(src, dst)
with open(dst,'r') as f:
fs = f.read()
fs = fs.replace( 'Exec=',f'Exec={prepend} ' )
with open( dst,'w' ) as f:
f.write(fs)
# Rebuild KService desktop file system configuration cache
subprocess.run( ['kbuildsycoca5'], stderr=subprocess.DEVNULL )