rofi/sane-open: fix so "Apps" menu item reveals keyboard
This commit is contained in:
parent
181ebfc627
commit
9a210b4a63
@ -16,7 +16,8 @@ binArgs=("$@")
|
|||||||
if [ "$desktop" != .desktop ]; then
|
if [ "$desktop" != .desktop ]; then
|
||||||
exec sane-open --auto-keyboard --application "$desktop"
|
exec sane-open --auto-keyboard --application "$desktop"
|
||||||
elif [ "$binary" = "xdg-open" ]; then
|
elif [ "$binary" = "xdg-open" ]; then
|
||||||
exec sane-open --auto-keyboard --file "${binArgs[@]}"
|
# the file we want to open could be a symlink to a .desktop file, so omit `--file` and let sane-open figure that part out for itself:
|
||||||
|
exec sane-open --auto-keyboard "${binArgs[@]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "no .desktop file, and unexpected binary; not invoking: %s %s\n" "$binary" "${binArgs[*]}" >&2
|
printf "no .desktop file, and unexpected binary; not invoking: %s %s\n" "$binary" "${binArgs[*]}" >&2
|
||||||
|
@ -22,6 +22,7 @@ log() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configureKeyboardFor_application() {
|
configureKeyboardFor_application() {
|
||||||
|
log "configureKeyboardFor_application: $1"
|
||||||
case "$1" in
|
case "$1" in
|
||||||
Alacritty.desktop)
|
Alacritty.desktop)
|
||||||
setKeyboard show
|
setKeyboard show
|
||||||
@ -66,6 +67,7 @@ configureKeyboardFor_application() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configureKeyboardFor_file() {
|
configureKeyboardFor_file() {
|
||||||
|
log "configureKeyboardFor_file: $1"
|
||||||
local mime=$(xdg-mime query filetype "$1")
|
local mime=$(xdg-mime query filetype "$1")
|
||||||
local application=$(xdg-mime query default "$mime")
|
local application=$(xdg-mime query default "$mime")
|
||||||
configureKeyboardFor_application "$application"
|
configureKeyboardFor_application "$application"
|
||||||
@ -87,10 +89,24 @@ open_file() {
|
|||||||
--dest org.freedesktop.portal.Desktop \
|
--dest org.freedesktop.portal.Desktop \
|
||||||
--object-path /org/freedesktop/portal/desktop \
|
--object-path /org/freedesktop/portal/desktop \
|
||||||
--method org.freedesktop.portal.OpenURI.OpenFile \
|
--method org.freedesktop.portal.OpenURI.OpenFile \
|
||||||
'' 3 "{'ask': <false>}"
|
"" 3 "{'ask': <false>}"
|
||||||
}
|
}
|
||||||
open_desktopFile() {
|
open_desktopFile() {
|
||||||
log "open_desktopFile: '$1'"
|
log "open_desktopFile: '$1'"
|
||||||
|
local target=$(tryAsDesktopFile "$1")
|
||||||
|
if [ -n "$target" ]; then
|
||||||
|
open_application "$target"
|
||||||
|
else
|
||||||
|
log "open_desktopFile: '$path' does not deref to anything in ~/.local/share/applications: falling back to heuristics"
|
||||||
|
# assume that the deref'd name matches the application name.
|
||||||
|
# there's nothing *guaranteeing* this, but i have yet to see it fail.
|
||||||
|
local target=$(basename "$path")
|
||||||
|
open_application "$target"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# evaluate truthy and print desktop name as `FOO.desktop` if the provided file is a .desktop file suitable for open_application.
|
||||||
|
tryAsDesktopFile() {
|
||||||
# open_application (i.e. the DynamicLauncher portal) only understands applications by their
|
# open_application (i.e. the DynamicLauncher portal) only understands applications by their
|
||||||
# .desktop filename (relative to ~/.local/share/applications) -- not by their full path.
|
# .desktop filename (relative to ~/.local/share/applications) -- not by their full path.
|
||||||
# therefore, see if this .desktop file is equivalent to anything in ~/.local/share/applications.
|
# therefore, see if this .desktop file is equivalent to anything in ~/.local/share/applications.
|
||||||
@ -99,24 +115,21 @@ open_desktopFile() {
|
|||||||
path="$PWD/$path"
|
path="$PWD/$path"
|
||||||
fi
|
fi
|
||||||
if [[ "$path" == $HOME/.local/share/applications/*.desktop ]]; then
|
if [[ "$path" == $HOME/.local/share/applications/*.desktop ]]; then
|
||||||
open_application "$(basename "$path")"
|
echo $(basename "$path")
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# the given path doesn't exist in ~/.local/share/applications: check if it's a symlink which
|
# the given path doesn't exist in ~/.local/share/applications: check if it's a symlink which
|
||||||
# derefs to an application
|
# derefs to an application
|
||||||
local target="$(readlink "$path")"
|
local target=$(readlink "$path")
|
||||||
if [ -z "$target" ]; then
|
if [ -n "$target" ]; then
|
||||||
log "open_desktopFile: '$path' does not deref to anything in ~/.local/share/applications: falling back to heuristics"
|
log "tryAsDesktopFile: deref'd $1 -> $target"
|
||||||
# assume that the deref'd name matches the application name.
|
if [[ "${target:0:1}" != "/" ]]; then
|
||||||
# there's nothing *guaranteeing* this, but i have yet to see it fail.
|
target=$(dirname "$path")/$target
|
||||||
open_application "$(basename "$path")"
|
fi
|
||||||
return
|
tryAsDesktopFile "$target"
|
||||||
|
else
|
||||||
|
log "tryAsDesktopFile: '$path' does not deref to anything in ~/.local/share/applications"
|
||||||
fi
|
fi
|
||||||
if [[ "${target:0:1}" != "/" ]]; then
|
|
||||||
target="$(dirname "$path")/$target"
|
|
||||||
fi
|
|
||||||
open_desktopFile "$target"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -130,7 +143,7 @@ isLandscape() {
|
|||||||
_keyboardPid=
|
_keyboardPid=
|
||||||
setKeyboard() {
|
setKeyboard() {
|
||||||
if [ -z "$KEYBOARD" ]; then
|
if [ -z "$KEYBOARD" ]; then
|
||||||
log "KEYBOARD is not set"
|
log "KEYBOARD is not set: not setting keyboard $1"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
if [ -z "$_keyboardPid" ]; then
|
if [ -z "$_keyboardPid" ]; then
|
||||||
@ -194,13 +207,16 @@ while [ $# -gt 0 ]; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [ -z "$resourceType" ]; then
|
if [ -z "$resourceType" ]; then
|
||||||
if [ -e "$HOME/.local/share/applications/$resource" ]; then
|
asApplication=$(tryAsDesktopFile "$resource")
|
||||||
|
if [ -n "$asApplication" ]; then
|
||||||
log "detected resourceType=application"
|
log "detected resourceType=application"
|
||||||
resourceType=application
|
resourceType=application
|
||||||
|
resource=$asApplication
|
||||||
elif [ -e "$resource" ]; then
|
elif [ -e "$resource" ]; then
|
||||||
log "detected resourceType=file"
|
log "detected resourceType=file"
|
||||||
resourceType=file
|
resourceType=file
|
||||||
elif [[ "$resource" == *.desktop ]]; then
|
elif [[ "$resource" == *.desktop ]]; then
|
||||||
|
# XXX(2024/07/02): this is probably dead code
|
||||||
log "detected resourceType=application (warning: '$resource' is not visible on disk)"
|
log "detected resourceType=application (warning: '$resource' is not visible on disk)"
|
||||||
resourceType=application
|
resourceType=application
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user