Can't you just not allow applications to request focus from themselves, and allow focus changes only from the window manager based on user actions?