问题
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?
回答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.
回答2:
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.
来源:https://stackoverflow.com/questions/25126617/sdl2-raising-a-window-without-giving-it-focus