Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
xdotool vs xvkbd madness
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
cz0
Apprentice
Apprentice


Joined: 13 Jun 2005
Posts: 244
Location: /earth/russia/moscow

PostPosted: Sat Aug 22, 2015 11:52 am    Post subject: xdotool vs xvkbd madness Reply with quote

Hi, folks!

This story began when I finally realized that I can't use Opera any more just cause it is Chromium and not a tool that I got used to for past decade. I had to switch to Firefox. Firefox itself is an excellent bit of software, especially with all of it extensions/addons. But it lack of a significant option: it does not allow to bind mouse buttons to some actions as desired. Opera had a special configuration menu/schema, that allowed to bind just any button to any action. Firefox does not. Sine I have a couple (one for home and one for work) of this grate Logitech MX Revolution mice, that have over a dozen buttons, I was pretty disappointed that I can't continue my web surfing experience. The thumb buttons that are regularly binded to Back-Forth function work as expected: out of the box. But the outstanding useful thing as wheel left-right shake, that I use to switch between tabs in Opera is not working. And I was not able to find no regular way to bind this actions in Firefox itself, neither extension. That slows me quite a lot. I recalled times, when Opera was not capable of direct bindings and got my xbindkeys + xvkbd pack out of dust. But before putting it back to work, I did a quick search and figured out, that xdotool is actually a lot more powerful thing, so I decided to replace xvkbd with xdotool.

With a help of xev and some googling I came to a quick solution, but the happiness was short. Firefox does not always switch tabs! Initially it does, then stop without any reason. And after some time/event start switching again. Due to some odd selections, I came to conclusion, that Firefox actually receive some events, but they
seem to be different from programmed keypress sequences. Instead, I get some strange scrolling, or element selections.

At the same time, I have konsole and qpdfview working perfectly fine, even if windows are next one to each other on the same desktop. That means, that xbindkeys-xdotool actually work fine, but not for some programs. I suspect, that gtk based programms are working somehow different in that respect. Because of another non-working program: Pidgin (which is gtk based).

At the same moment, xvkbd work perfect all that time. Even if I bind wheel-left to xvkbd, and wheel-right to xbindkeys, xvkbd always work perfect, xdotoo fails randomly.

I experimented quite a lot with xdotool parameters and key sequences, system sleep and --delay, including --clearmodifiers option. With no luck.

The most irritating thing in all this is that I can't trace down why xdotool behaves randomly, while xvkbd work fine.

Here is my .xbindkey config:
Code:

"~/.xbindkeys/mouse_wheel.sh left"
 b:6

"~/.xbindkeys/mouse_wheel.sh right"
 b:7

"/usr/bin/qdbus org.kde.kglobalaccel /component/kwin invokeShortcut Expose"
  m:0x0 + c:225


And here is my program-specific action script, that is activated by xbindkeys on wheel shaking:
Code:

#!/bin/sh

EVENT=$1
XPROP="/usr/bin/xprop"
XDOTOOL="/usr/bin/xdotool"

PROGRAM=$($XPROP -id `$XPROP -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f2` WM_CLASS | cut -d'"' -f4)


# It is possible to list cases like this: 'Program1'|'Program2'|'Program3')
case "$PROGRAM" in
    'Firefox')
#        if [ $EVENT == "left" ]; then $XDOTOOL keydown Control_L key --delay 5 Prior keyup --delay 5 Control_L; fi
        if [ $EVENT == "right" ]; then $XDOTOOL keydown Control_L key --delay 50 Next keyup --delay 5 Control_L; fi
        if [ $EVENT == "left" ]; then /usr/bin/xvkbd -xsendevent -text "\[Control_L]\[Prior]"; fi
#        if [ $EVENT == "right" ]; then /usr/bin/xvkbd -xsendevent -text "\[Control_L]\[Next]"; fi
    ;;
    'Konsole')
        if [ $EVENT == "left" ]; then $XDOTOOL keydown Shift_L key Left keyup Shift_L; fi
        if [ $EVENT == "right" ]; then $XDOTOOL keydown Shift_L key Right keyup Shift_L; fi
    ;;
    'Pidgin')
        if [ $EVENT == "left" ]; then $XDOTOOL keydown Control_L key --delay 50 bracketleft keyup --delay 5 Control_L; fi
        if [ $EVENT == "right" ]; then $XDOTOOL keydown Control_L key --delay 50 bracketright keyup --delay 5 Control_L; fi
    ;;
    'Qpdfview')
        if [ $EVENT == "left" ]; then $XDOTOOL keydown Control_L keydown Shift_L key Tab keyup Shift_L keyup Control_L; fi
        if [ $EVENT == "right" ]; then $XDOTOOL keydown Control_L key Tab keyup Control_L; fi
    ;;
    *)
#        if [ $EVENT == "left" ]; then $XDOTOOL keydown Control_L key --delay 5 Prior keyup --delay 5 Control_L; fi
#        if [ $EVENT == "right" ]; then $XDOTOOL keydown Control_L key --delay 5 Next keyup --delay 5 Control_L; fi
        if [ $EVENT == "left" ]; then /usr/bin/xvkbd -xsendevent -text "\[Control_L]\[Page_Up]"; fi
        if [ $EVENT == "right" ]; then /usr/bin/xvkbd -xsendevent -text "\[Control_L]\[Page_Down]"; fi
#        if [[ $EVENT == "left" && $XBKWLF == "false" ]]; then export XBKWLF "true"; $XDOTOOL click 6; export XBKWLF "false"; fi
#        if [ $EVENT == "right" ]; then $XDOTOOL click 7; fi
    ;;
esac


The sections, corresponding to Firefox and Pidgin do not work always, if configured to use xdotool and work fine, if I use xvkbd. The sections, corresponding to Konsole and Qpdfview work fine with xdotool.

I did a quick investigation what actions are actually take place, if I use xvkbd and xdotool (the following outputs are from exactly that same mouse event):
xev output for xvkbd (working sequence):
Code:

eaveNotify event, serial 40, synthetic NO, window 0x2600001,
    root 0xaf, subw 0x0, time 20824600, (107,106), root:(987,495),
    mode NotifyGrab, detail NotifyAncestor, same_screen YES,
    focus YES, state 0

EnterNotify event, serial 40, synthetic NO, window 0x2600001,
    root 0xaf, subw 0x0, time 20824600, (107,106), root:(987,495),
    mode NotifyUngrab, detail NotifyAncestor, same_screen YES,
    focus YES, state 0

KeymapNotify event, serial 40, synthetic NO, window 0x0,
    keys:  4294967215 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   16  0

KeyPress event, serial 40, synthetic YES, window 0x2600001,
    root 0xaf, subw 0x0, time 0, (1,1), root:(1,1),
    state 0x0, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyPress event, serial 40, synthetic YES, window 0x2600001,
    root 0xaf, subw 0x0, time 0, (1,1), root:(1,1),
    state 0x4, keycode 117 (keysym 0xff56, Next), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 40, synthetic YES, window 0x2600001,
    root 0xaf, subw 0x0, time 0, (1,1), root:(1,1),
    state 0x4, keycode 117 (keysym 0xff56, Next), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 40, synthetic YES, window 0x2600001,
    root 0xaf, subw 0x0, time 0, (1,1), root:(1,1),
    state 0x4, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False


xev output for xdotool (randomly working):
Code:

LeaveNotify event, serial 43, synthetic NO, window 0x2600001,
    root 0xaf, subw 0x0, time 20770198, (112,106), root:(927,345),
    mode NotifyGrab, detail NotifyAncestor, same_screen YES,
    focus YES, state 0

EnterNotify event, serial 43, synthetic NO, window 0x2600001,
    root 0xaf, subw 0x0, time 20770198, (112,106), root:(927,345),
    mode NotifyUngrab, detail NotifyAncestor, same_screen YES,
    focus YES, state 0

KeymapNotify event, serial 43, synthetic NO, window 0x0,
    keys:  1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   16  0

KeyPress event, serial 43, synthetic NO, window 0x2600001,
    root 0xaf, subw 0x0, time 20770502, (112,106), root:(927,345),
    state 0x0, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyPress event, serial 43, synthetic NO, window 0x2600001,
    root 0xaf, subw 0x0, time 20770514, (112,106), root:(927,345),
    state 0x4, keycode 117 (keysym 0xff56, Next), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 43, synthetic NO, window 0x2600001,
    root 0xaf, subw 0x0, time 20770518, (112,106), root:(927,345),
    state 0x4, keycode 117 (keysym 0xff56, Next), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 43, synthetic NO, window 0x2600001,
    root 0xaf, subw 0x0, time 20770523, (112,106), root:(927,345),
    state 0x4, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False


So, now I'm just curious about why xdotool not working properly all the time. For sure, I can stick with xvkbd, but I just want to make it work.
Any ideas?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum