If I execute sleep(1) before the "if (gdk_keyboard_grab ...", pinentry-gtk-2 is always able to grab the keyboard. Waiting only some milliseconds (say 500) would do the trick too, I guess.
Not many people seem to be able to reproduce this bug. What kind of additional information do you need?
pgpTrlEXuDOVR.pgp
Description: PGP signature