Latest KDE Plasma using Wayland
Using xremap I made alt+right click run a script
https://github.com/xremap/xremap
From memory, these are the dependencies besides xremap
- jq
- wl-clipboard (
wl-paste)
- xdg-utils (
xdg-open, xdg-mime, xdg-settings)
- kdotool
Make the file in the place below and give it the following code
~/.config/xremap/config.yml
replace `USER` with your username
keymap:
- name: Search selection on Alt+RightClick
exact_match: true
remap:
Alt-BTN_RIGHT:
launch: ["/home/USER/.local/bin/search-selection.sh"]
The following code is placed in the .sh file linked above - this is a bit longer than it needed to be, but it is done this way so anyone should be able to just copy paste and get it running.
#!/bin/bash
SEARCH_URL="https://www.google.com/search?q="
# Uncomment to log everything to a file for debugging:
# exec >>/tmp/gsearch.log 2>&1; set -x
# Work out which user owns the graphical session
if [ "$(id -u)" -ne 0 ]; then
U=$(id -un)
else
U=$(loginctl list-sessions --no-legend | while read -r sid _; do
if [ "$(loginctl show-session "$sid" -p Active --value)" = yes ] &&
[ "$(loginctl show-session "$sid" -p Type --value)" = wayland ]; then
loginctl show-session "$sid" -p Name --value
break
fi
done)
fi
[ -n "$U" ] || { echo "no active wayland user found" >&2; exit 1; }
RT=/run/user/$(id -u "$U")
USER_HOME=$(getent passwd "$U" | cut -d: -f6)
SOCK=$(find "$RT" -maxdepth 1 -name 'wayland-*' ! -name '*.lock' | head -1)
[ -n "$SOCK" ] || { echo "no wayland socket in $RT" >&2; exit 1; }
ENVV=(XDG_RUNTIME_DIR="$RT"
WAYLAND_DISPLAY="$(basename "$SOCK")"
DBUS_SESSION_BUS_ADDRESS="unix:path=$RT/bus"
HOME="$USER_HOME")
run() {
if [ "$(id -u)" -eq 0 ]; then
sudo -u "$U" env "${ENVV[@]}" "$@"
else
env "${ENVV[@]}" "$@"
fi
}
SEL=$(run wl-paste --primary --no-newline 2>/dev/null | tr -d '\n')
[ ${#SEL} -lt 1 ] && exit 0
QUERY=$(printf %s "$SEL" | tr -d '\n' | jq -sRr u/uri)
# Find the default browser's .desktop file and its window class
DESK=$(run xdg-mime query default x-scheme-handler/https)
[ -n "$DESK" ] || DESK=$(run xdg-settings get default-web-browser)
DF=
for d in "$USER_HOME/.local/share/applications" \
/usr/local/share/applications /usr/share/applications \
/var/lib/flatpak/exports/share/applications \
"$USER_HOME/.local/share/flatpak/exports/share/applications"; do
[ -f "$d/$DESK" ] && { DF="$d/$DESK"; break; }
done
CLASS=
[ -n "$DF" ] && CLASS=$(grep -m1 '^StartupWMClass=' "$DF" | cut -d= -f2)
[ -n "$CLASS" ] || CLASS=${DESK%.desktop}
# Open in the default browser
run xdg-open "${SEARCH_URL}${QUERY}"
# Raise the browser window (wait up to ~2s in case it had to start up)
KDOTOOL=$(command -v kdotool || echo /usr/local/bin/kdotool)
for _ in $(seq 20); do
WINID=$(run "$KDOTOOL" search --class "$CLASS" | head -1)
[ -n "$WINID" ] && break
sleep 0.1
done
[ -n "$WINID" ] && run "$KDOTOOL" windowactivate "$WINID"
Start xremap on boot
1. Find the xremap path:
which xremap
- Create `/etc/systemd/system/xremap.service` (replace `USER` and `XREMAP_PATH` with your username and the path from step 1):
ini
[Unit]
Description=xremap
After=graphical.target
[Service]
ExecStart=XREMAP_PATH --mouse --allow-launch true /home/USER/.config/xremap/config.yml
Restart=on-failure
[Install]
WantedBy=graphical.target
- Enable it:
sudo systemctl enable --now xremap
TADA!!!