If it is a different application, then that application needs to be modified, so that it won't steal focus from other applications when it is mapping new windows.
Alternatively, you can change focus stealing prevention settings in your window manager, to get the behavior you want.
It depends who popups the
It depends who popups the other windows.
If it is your application, you can reset the focus to the window (shell widget) you want, by sending _NET_ACTIVE_WINDOW client message.
http://standards.freedesktop.org/wm-spec/wm-spec-latest.html#id2550738
If it is a different application, then that application needs to be modified, so that it won't steal focus from other applications when it is mapping new windows.
Alternatively, you can change focus stealing prevention settings in your window manager, to get the behavior you want.
Dušan Peterc