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
|
||||
exec sane-open --auto-keyboard --application "$desktop"
|
||||
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
|
||||
|
||||
printf "no .desktop file, and unexpected binary; not invoking: %s %s\n" "$binary" "${binArgs[*]}" >&2
|
||||
|
@ -22,6 +22,7 @@ log() {
|
||||
}
|
||||
|
||||
configureKeyboardFor_application() {
|
||||
log "configureKeyboardFor_application: $1"
|
||||
case "$1" in
|
||||
Alacritty.desktop)
|
||||
setKeyboard show
|
||||
@ -66,6 +67,7 @@ configureKeyboardFor_application() {
|
||||
}
|
||||
|
||||
configureKeyboardFor_file() {
|
||||
log "configureKeyboardFor_file: $1"
|
||||
local mime=$(xdg-mime query filetype "$1")
|
||||
local application=$(xdg-mime query default "$mime")
|
||||
configureKeyboardFor_application "$application"
|
||||
@ -87,10 +89,24 @@ open_file() {
|
||||
--dest org.freedesktop.portal.Desktop \
|
||||
--object-path /org/freedesktop/portal/desktop \
|
||||
--method org.freedesktop.portal.OpenURI.OpenFile \
|
||||
'' 3 "{'ask': <false>}"
|
||||
"" 3 "{'ask': <false>}"
|
||||
}
|
||||
open_desktopFile() {
|
||||
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
|
||||
# .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.
|
||||
@ -99,24 +115,21 @@ open_desktopFile() {
|
||||
path="$PWD/$path"
|
||||
fi
|
||||
if [[ "$path" == $HOME/.local/share/applications/*.desktop ]]; then
|
||||
open_application "$(basename "$path")"
|
||||
echo $(basename "$path")
|
||||
return
|
||||
fi
|
||||
|
||||
# the given path doesn't exist in ~/.local/share/applications: check if it's a symlink which
|
||||
# derefs to an application
|
||||
local target="$(readlink "$path")"
|
||||
if [ -z "$target" ]; then
|
||||
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.
|
||||
open_application "$(basename "$path")"
|
||||
return
|
||||
local target=$(readlink "$path")
|
||||
if [ -n "$target" ]; then
|
||||
log "tryAsDesktopFile: deref'd $1 -> $target"
|
||||
if [[ "${target:0:1}" != "/" ]]; then
|
||||
target=$(dirname "$path")/$target
|
||||
fi
|
||||
tryAsDesktopFile "$target"
|
||||
else
|
||||
log "tryAsDesktopFile: '$path' does not deref to anything in ~/.local/share/applications"
|
||||
fi
|
||||
if [[ "${target:0:1}" != "/" ]]; then
|
||||
target="$(dirname "$path")/$target"
|
||||
fi
|
||||
open_desktopFile "$target"
|
||||
}
|
||||
|
||||
|
||||
@ -130,7 +143,7 @@ isLandscape() {
|
||||
_keyboardPid=
|
||||
setKeyboard() {
|
||||
if [ -z "$KEYBOARD" ]; then
|
||||
log "KEYBOARD is not set"
|
||||
log "KEYBOARD is not set: not setting keyboard $1"
|
||||
return
|
||||
fi
|
||||
if [ -z "$_keyboardPid" ]; then
|
||||
@ -194,13 +207,16 @@ while [ $# -gt 0 ]; do
|
||||
done
|
||||
|
||||
if [ -z "$resourceType" ]; then
|
||||
if [ -e "$HOME/.local/share/applications/$resource" ]; then
|
||||
asApplication=$(tryAsDesktopFile "$resource")
|
||||
if [ -n "$asApplication" ]; then
|
||||
log "detected resourceType=application"
|
||||
resourceType=application
|
||||
resource=$asApplication
|
||||
elif [ -e "$resource" ]; then
|
||||
log "detected resourceType=file"
|
||||
resourceType=file
|
||||
elif [[ "$resource" == *.desktop ]]; then
|
||||
# XXX(2024/07/02): this is probably dead code
|
||||
log "detected resourceType=application (warning: '$resource' is not visible on disk)"
|
||||
resourceType=application
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user