3

I need to display a tooltip over a window. I'm creating a second window with the tool tip and using SDL_RaiseWindow() to bring it to the top. However, doing that causes the tooltip to steal focus which is not what I want. Is there a way to bring a window to the top without changing focus?

Also, is there a way to set focus (mouse and/or keyboard) without changing the Z order of the windows?

QuickGrip
  • 143
  • 1
  • 8
  • As a total stab in the dark you could try changing the window flags for your main window. Do this after you call `SDL_RaiseWindow()` though. Assuming that your main window pointer is called m_window and raised window is m_raised it would be `m_window->flags |= SDL_WINDOW_INPUT_FOCUS` followed by `m_raised->flags &= ~SDL_WINDOW_INPUT_FOCUS` You may also need to manually call `SDL_OnWindowFocusGained(m_window)` and `SDL_OnWindowFocusLost(m_raised)` - None of this is tested and it only 'may' work. – TPS Aug 05 '14 at 11:49

3 Answers3

1

The answer offered by Neil will only work under X11 as SDL_SetWindowInputFocus() is only implemented for that environment. In essence, the desired behaviour is otherwise not achievable. I have seen that there is a feature request in the SDL forums for an overload of the SDL_RaiseWindow() function to include an optional bool parameter to indicate if the raised window should also receive the input focus, or not. I hope they do implement that.

In any case, the support for multiple windows under SDL 2.x is a little weak. There is no built in support for the Z-order of different windows, and trying to build one based on the "painter's method" works, but leaves one no control over the input focus.

GermanNerd
  • 643
  • 5
  • 12
0

Old question, but this came up during my own search. You could try SDL_RaiseWindow() to bring your tooltip to the top, then use SDL_SetWindowInputFocus() on the main window to switch focus back to it.

Neil Roy
  • 603
  • 5
  • 13
0

I got this working sufficiently for my tooltips on mac by using SDL_WINDOW_ALWAYS_ON_TOP flag with SDL2:

SDL_CreateWindow(tooltip_window->name, x, y, w, h,
    SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS |
    SDL_WINDOW_ALWAYS_ON_TOP);
SDL_RaiseWindow(windowThatShouldHaveFocus);
// ...render what you want on that tooltip (SDL_RenderClear, SDL_RenderCopy, SDL_RenderPresent) & hide it with SDL_HideWindow

And when showing the tooltip:

SDL_ShowWindow(tooltipWindow);
SDL_RaiseWindow(windowThatShouldHaveFocus);