Enter does not work in dialogs which use --tail

178 views
Skip to first unread message

Joe

unread,
Aug 7, 2017, 7:31:14 AM8/7/17
to yad-common
I originally thought this was a focus issue and posted here https://groups.google.com/forum/#!searchin/yad-common/ctrl$20enter/yad-common/8SBDV__Zm0k/StslbHqjAgAJ.

Victor replied and told me that Ctrl+Enter works in such cases (and, it does), but I'd really prefer to just use Enter - which works fine in my other dialogs.

I want the default button (usually --button=gtk-ok:0) to be activated when Enter is pressed.

Is this a yad bug?

Currently, in these dialogs, Enter acts as a dead key which does nothing.

--scroll has the same issue.

Code which recreates the issue:
#!/bin/bash
## The Enter key doesn't work with any of these dialog boxes
message="$(for i in {1..20}; do echo "line $i"; done)"
echo -e "${message}" | yad --center --on-top --tail --no-markup --height=300 --text-info --title "Enter Test with pipe"
yad --center --on-top --tail --no-markup --height=300 --text-info --title "Enter Test with here" <<< "${message}"
yad --form --scroll --field="$(for i in {1..20}; do echo "line $i"; done):lbl" --height=300 --title "Enter Test with subshell"


kubuntu 16.04 / QT 5.5 / yad 0.39.0 (GTK+ 3.18.9)

Милош Павловић

unread,
Sep 9, 2017, 4:36:27 PM9/9/17
to yad-common
Hey Joe, (Sounds like Jimi Hendrix)
I came up with this little hack with xinput and xdotool.
We also add --class to the yad window.
#!/bin/bash


message
="$(for i in {1..20}; do echo "line $i"; done)"

echo
-e "${message}" | yad --class="YAD_APP" --text="OK=Enter (Return or Enter on the numpad)\nCancel=End" --center --on-top --tail --no-markup --height=300 --text-info --title "Enter Test with pipe" &
pid
=$!  # get the process id

until xdotool search --class "YAD_APP" &>/dev/null; do   # sleep until the window opens
        sleep
0.1
done

xinput test
-xi2 --root | perl -lne '
  BEGIN{$"=",";
    open X, "-|", "xmodmap -pke";
    while (<X>) {$k{$1}=$2 if /^keycode\s+(\d+) = (\w+)/}
    open X, "-|", "xmodmap -pm"; <X>;<X>;
    while (<X>) {if (/^(\w+)\s+(\w*)/){($k=$2)=~s/_[LR]$//;$m[$i++]=$k||$1}}
    close X;
  }
  if (/detail: (\d+)/) {$d=$1;
      if ($k{$d} eq "Return" && (`xdotool getwindowfocus 2> /dev/null` eq `xdotool search --class YAD_APP | tail -1 2> /dev/null`) ){
      system ("xdotool windowactivate --sync `xdotool search --class YAD_APP | tail -1` key --clearmodifiers ctrl+Return > /dev/null 2>&1");
      }
      elsif ($k{$d} eq "KP_Enter" && (`xdotool getwindowfocus 2> /dev/null` eq `xdotool search --class YAD_APP | tail -1 2> /dev/null`) ){
      system ("xdotool windowactivate --sync `xdotool search --class YAD_APP | tail -1` key --clearmodifiers ctrl+Return > /dev/null 2>&1");
      }
      elsif ($k{$d} eq "End" && (`xdotool getwindowfocus 2> /dev/null` eq `xdotool search --class YAD_APP | tail -1 2> /dev/null`) ){
      system ("xdotool windowactivate --sync `xdotool search --class YAD_APP | tail -1` key --clearmodifiers alt+F4 > /dev/null 2>&1");
     }
  }'
& xinpid=$!

wait $pid  
# Wait for the window close, wait also returns the status
echo $
?    # return status

# Kills the monitor
kill $xinpid
First we monitor for Enter (Return) key from keyboard with xinput.
When the yad window is in focus and "Return" or "KP_Enter" is pressed, we send ctrl+Return to the yad window. That returns 0.
When the yad window is in focus and "End" is pressed, we send alt+F4 to the yad window. That returns 252.
Tested on XFCE 4.10, yad 0.39, GTK 2, no systemd.

Милош Павловић

unread,
Sep 9, 2017, 6:48:14 PM9/9/17
to yad-common
By the way, with other dialogs, when a button gets focus on start, Enter key will execute that button.
^Workaround works mostly with dialogs with --no-buttons, but not when there is --no-focus option, for obvious reasons.
...
yad
--class="YAD_APP" --text="OK=Enter (Return or Enter on the numpad)\nCancel=End" --width=500 --height=500 --text-align=fill --no-buttons &
pid=$!  # get the process id

...
Anyway, yad takes ctrl+Return even when there are no buttons, so it's either buttons or keypress.

Joe Consultant

unread,
Sep 11, 2017, 9:54:47 PM9/11/17
to yad-common
Hey. That's not fair. I don't even have a clue as to how to pronounce your name, let alone make a joke about it!
One of my favorite songs from that era was by the Beach Boys. I think it was "Fun, Fun, Fun Till Her Daddy Took Her Keyboard Away".  ;)

On a more  serous note, Thanks a lot for what looks like a significant amount of effort. Now, I wish I knew Perl.
I'm starting to study the code. Your comments at the end make perfect sense. I just have to figure out how your code does it.

Apparently, you know a whole lot more than I do about processing X keyboard events!
I'm gradually making sense of the pieces.

Joe

--
You received this message because you are subscribed to a topic in the Google Groups "yad-common" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/yad-common/b2UKOJVLerU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to yad-common+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages