Hello,
When a tool window is activated by a tab or title bar click, it tries to focus the last control that had focus within it. In this case, it sounds like the ribbon button may have been that last control. I'm not sure what your control setup is, but perhaps your button click logic could focus another control within the tool window first, and then execute the normal button click logic. That way if your normal button logic moves focus out of the tool window, the control that should be focused next time the tool window is activated will be the one you focused above.