Accurately get correct window id for non-terminals

For some window managers, head -n 1 won't give the correct one
long-opts
angelic-sedition 10 years ago
parent 1b5a0c002e
commit 07b526efed

24
tdrop

@ -199,6 +199,10 @@ get_class_name() {
xprop -id "$1" WM_CLASS | awk '{gsub(/"/, ""); print $4}' xprop -id "$1" WM_CLASS | awk '{gsub(/"/, ""); print $4}'
} }
get_visibility() {
xwininfo -id "$1" | awk '/Map State/ {print $3}'
}
map_pre_command() { map_pre_command() {
# a user set option has higher priority # a user set option has higher priority
if [[ -n $map_pre ]]; then if [[ -n $map_pre ]]; then
@ -268,10 +272,22 @@ win_create() {
$term & $term &
# need to wait for window to be created # need to wait for window to be created
sleep 0.5 sleep 0.5
# often pids have two wids; first one has always been the right one for what I've tested # often pids have two wids
wid=$(xdotool search --pid $! | head -n 1) wids=$(xdotool search --pid $!)
echo "$wid" > /tmp/tdrop/"$term$num" wid1=$(echo "$wids" | head -n 1)
wid2=$(echo "$wids" | tail -n 1)
if [[ -n $wid2 ]]; then
if [[ $(get_visibility "$wid2") == IsUnMapped ]]; then
wid=$wid1
else
wid=$wid2
fi
else
wid=$wid1
fi
# only works with pre-command
xdotool windowmove "$wid" "$xoff" "$yoff" windowsize "$wid" "$width" "$height" xdotool windowmove "$wid" "$xoff" "$yoff" windowsize "$wid" "$width" "$height"
echo "$wid" > /tmp/tdrop/"$term$num"
} }
current_create() { current_create() {
@ -287,7 +303,7 @@ wid_toggle() {
wid=$(< /tmp/tdrop/"$term$num") wid=$(< /tmp/tdrop/"$term$num")
exists=true exists=true
if [[ -n $wid ]]; then if [[ -n $wid ]]; then
visibility=$(xwininfo -id "$wid" | awk '/Map State/ {print $3}') visibility=$(get_visibility "$wid")
# sometimes xwininfo will still report a window as existing hence xprop check # sometimes xwininfo will still report a window as existing hence xprop check
if [[ -z $visibility ]] || [[ -z $(xprop -id "$wid") ]]; then if [[ -z $visibility ]] || [[ -z $(xprop -id "$wid") ]]; then
# window no longer exists # window no longer exists

Loading…
Cancel
Save