Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dotool backend support #237

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions config.example
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ layout_cmd () {
setxkbmap us
}

# dotool needs to be run in long-running instance mode (dotoolc, dotoold) to speed up uinput device creation
# Keyboard layout specifiers DOTOOL_XKB_LAYOUT and DOTOOL_XKB_VARIANT should be environment variables visible to dotoold
# Path to dotool pipe DOTOOL_PIPE should be an environment variable visible to dotoolc
# export DOTOOL_PIPE=/tmp/rofi-pass-dotoo-pipe

# fields to be used
URL_field='url'
USERNAME_field='user'
Expand All @@ -70,6 +75,9 @@ wait=0.2
# delay between keypresses when typing (in ms)
type_delay=12

# hold duration between key press and release (in ms)
type_hold=8

## Programs to be used
# Editor
EDITOR='gvim -f'
Expand Down Expand Up @@ -131,4 +139,5 @@ insert_pass="Alt+n"
# Change the backend for rofi-pass, valid backends are:
# xdotool
# wtype
# dotool
#backend=xdotool
28 changes: 19 additions & 9 deletions rofi-pass
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ default_autotype="user :tab pass"
delay=2
wait=0.2
type_delay=12
type_hold=8
default_do='menu' # menu, copyPass, typeUser, typePass, copyUser, copyUrl, viewEntry, typeMenu, actionMenu, copyMenu, openUrl
auto_enter='false'
notify='false'
Expand Down Expand Up @@ -74,6 +75,7 @@ esac
case "$backend" in
"xdotool");;
"wtype");;
"dotool");;
*)
>&2 echo "Invalid backend '$backend', falling back to xdotool"
backend=xdotool
Expand Down Expand Up @@ -118,11 +120,15 @@ _clip_out_clipboard_xclip() {

# Backends for typing what's in stdin
_do_type_xdotool() {
xdotool type --delay ${type_delay} --clearmodifiers --file -
printf '%s' "$1" | xdotool type --delay ${type_delay} --clearmodifiers --file -
}

_do_type_wtype() {
wtype -d ${type_delay} -
printf '%s' "$1" | wtype -d ${type_delay} -
}

_do_type_dotool() {
printf 'typedelay %i\ntypehold %i\ntype %s\n' "${type_delay}" "${type_hold}" "$1" | dotoolc
}

# Backends for pressing the key specified by the first argument ($1)
Expand All @@ -134,6 +140,10 @@ _do_press_key_wtype() {
wtype -P "$1" -p "$1"
}

_do_press_key_dotool() {
printf 'keydelay %i\nkeyhold %i\nkey x:%s\n' "${type_delay}" "${type_hold}" "$1" | dotoolc
}

has_qrencode() {
command -v qrencode >/dev/null 2>&1
}
Expand Down Expand Up @@ -178,10 +188,10 @@ autopass () {
":space") ${do_press_key} space;;
":delay") sleep "${delay}";;
":enter") ${do_press_key} Return;;
":otp") printf '%s' "$(generateOTP)" | ${do_type};;
"pass") printf '%s' "${password}" | ${do_type};;
"path") printf '%s' "${selected_password}" | rev | cut -d'/' -f1 | rev | ${do_type};;
*) printf '%s' "${stuff[${word}]}" | ${do_type};;
":otp") ${do_type} "$(generateOTP)";;
"pass") ${do_type} "${password}";;
"path") ${do_type} "$(printf '%s' "${selected_password}" | rev | cut -d'/' -f1 | rev)";;
*) ${do_type} "${stuff[${word}]}";;
esac
done

Expand Down Expand Up @@ -238,7 +248,7 @@ typeUser () {
xset r off
fi

printf '%s' "${stuff[${USERNAME_field}]}" | ${do_type}
${do_type} "${stuff[${USERNAME_field}]}"

if [[ $backend == "xdotool" ]]; then
xset r "$x_repeat_enabled"
Expand All @@ -256,7 +266,7 @@ typePass () {
xset r off
fi

printf '%s' "${password}" | ${do_type}
${do_type} "${password}"

if [[ $notify == "true" ]]; then
if [[ "${stuff[notify]}" == "false" ]]; then
Expand Down Expand Up @@ -294,7 +304,7 @@ typeField () {
*) to_type="${stuff[${typefield}]}" ;;
esac

printf '%s' "$to_type" | ${do_type}
${do_type} "$to_type"

if [[ $backend == "xdotool" ]]; then
xset r "$x_repeat_enabled"
Expand Down