mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-28 15:39:10 +00:00
Add SDL_WINDOW_NOT_FOCUSABLE flag to set that the window should not be able to gain key focus
- Also adds SDL_SetWindowFocusable() to set/clear flag on existing windows
This commit is contained in:
parent
b385dc3b68
commit
a5e7214795
15 changed files with 101 additions and 8 deletions
|
@ -150,7 +150,8 @@ typedef enum
|
||||||
SDL_WINDOW_KEYBOARD_GRABBED = 0x00100000, /**< window has grabbed keyboard input */
|
SDL_WINDOW_KEYBOARD_GRABBED = 0x00100000, /**< window has grabbed keyboard input */
|
||||||
SDL_WINDOW_VULKAN = 0x10000000, /**< window usable for Vulkan surface */
|
SDL_WINDOW_VULKAN = 0x10000000, /**< window usable for Vulkan surface */
|
||||||
SDL_WINDOW_METAL = 0x20000000, /**< window usable for Metal view */
|
SDL_WINDOW_METAL = 0x20000000, /**< window usable for Metal view */
|
||||||
SDL_WINDOW_TRANSPARENT = 0x40000000 /**< window with transparent buffer */
|
SDL_WINDOW_TRANSPARENT = 0x40000000, /**< window with transparent buffer */
|
||||||
|
SDL_WINDOW_NOT_FOCUSABLE = 0x80000000, /**< window should not be focusable */
|
||||||
|
|
||||||
} SDL_WindowFlags;
|
} SDL_WindowFlags;
|
||||||
|
|
||||||
|
@ -1676,6 +1677,19 @@ extern DECLSPEC int SDLCALL SDL_SetWindowModalFor(SDL_Window *modal_window, SDL_
|
||||||
*/
|
*/
|
||||||
extern DECLSPEC int SDLCALL SDL_SetWindowInputFocus(SDL_Window *window);
|
extern DECLSPEC int SDLCALL SDL_SetWindowInputFocus(SDL_Window *window);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether the window may have input focus.
|
||||||
|
*
|
||||||
|
* \param window the window to set focusable state
|
||||||
|
* \param focusable SDL_TRUE to allow input focus, SDL_FALSE to not allow input focus
|
||||||
|
* \returns 0 on success or a negative error code on failure; call
|
||||||
|
* SDL_GetError() for more information.
|
||||||
|
*
|
||||||
|
* \since This function is available since SDL 3.0.0.
|
||||||
|
*/
|
||||||
|
extern DECLSPEC int SDLCALL SDL_SetWindowFocusable(SDL_Window *window, SDL_bool focusable);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the system-level window menu.
|
* Display the system-level window menu.
|
||||||
*
|
*
|
||||||
|
|
|
@ -901,6 +901,7 @@ SDL3_0.0.0 {
|
||||||
SDL_WriteS64LE;
|
SDL_WriteS64LE;
|
||||||
SDL_WriteS64BE;
|
SDL_WriteS64BE;
|
||||||
SDL_GDKGetDefaultUser;
|
SDL_GDKGetDefaultUser;
|
||||||
|
SDL_SetWindowFocusable;
|
||||||
# extra symbols go here (don't modify this line)
|
# extra symbols go here (don't modify this line)
|
||||||
local: *;
|
local: *;
|
||||||
};
|
};
|
||||||
|
|
|
@ -926,3 +926,4 @@
|
||||||
#define SDL_WriteS64LE SDL_WriteS64LE_REAL
|
#define SDL_WriteS64LE SDL_WriteS64LE_REAL
|
||||||
#define SDL_WriteS64BE SDL_WriteS64BE_REAL
|
#define SDL_WriteS64BE SDL_WriteS64BE_REAL
|
||||||
#define SDL_GDKGetDefaultUser SDL_GDKGetDefaultUser_REAL
|
#define SDL_GDKGetDefaultUser SDL_GDKGetDefaultUser_REAL
|
||||||
|
#define SDL_SetWindowFocusable SDL_SetWindowFocusable_REAL
|
||||||
|
|
|
@ -972,3 +972,4 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_WriteS64BE,(SDL_RWops *a, Sint64 b),(a,b),return)
|
||||||
#ifdef __GDK__
|
#ifdef __GDK__
|
||||||
SDL_DYNAPI_PROC(int,SDL_GDKGetDefaultUser,(XUserHandle *a),(a),return)
|
SDL_DYNAPI_PROC(int,SDL_GDKGetDefaultUser,(XUserHandle *a),(a),return)
|
||||||
#endif
|
#endif
|
||||||
|
SDL_DYNAPI_PROC(int,SDL_SetWindowFocusable,(SDL_Window *a, SDL_bool b),(a,b),return)
|
||||||
|
|
|
@ -264,6 +264,7 @@ struct SDL_VideoDevice
|
||||||
void (*DestroyWindowFramebuffer)(SDL_VideoDevice *_this, SDL_Window *window);
|
void (*DestroyWindowFramebuffer)(SDL_VideoDevice *_this, SDL_Window *window);
|
||||||
void (*OnWindowEnter)(SDL_VideoDevice *_this, SDL_Window *window);
|
void (*OnWindowEnter)(SDL_VideoDevice *_this, SDL_Window *window);
|
||||||
int (*FlashWindow)(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation);
|
int (*FlashWindow)(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation);
|
||||||
|
int (*SetWindowFocusable)(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool focusable);
|
||||||
|
|
||||||
/* * * */
|
/* * * */
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1740,7 +1740,7 @@ Uint32 SDL_GetWindowPixelFormat(SDL_Window *window)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CREATE_FLAGS \
|
#define CREATE_FLAGS \
|
||||||
(SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_ALWAYS_ON_TOP | SDL_WINDOW_POPUP_MENU | SDL_WINDOW_UTILITY | SDL_WINDOW_TOOLTIP | SDL_WINDOW_VULKAN | SDL_WINDOW_MINIMIZED | SDL_WINDOW_METAL | SDL_WINDOW_TRANSPARENT)
|
(SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_ALWAYS_ON_TOP | SDL_WINDOW_POPUP_MENU | SDL_WINDOW_UTILITY | SDL_WINDOW_TOOLTIP | SDL_WINDOW_VULKAN | SDL_WINDOW_MINIMIZED | SDL_WINDOW_METAL | SDL_WINDOW_TRANSPARENT | SDL_WINDOW_NOT_FOCUSABLE)
|
||||||
|
|
||||||
static SDL_INLINE SDL_bool IsAcceptingDragAndDrop(void)
|
static SDL_INLINE SDL_bool IsAcceptingDragAndDrop(void)
|
||||||
{
|
{
|
||||||
|
@ -3205,6 +3205,24 @@ int SDL_SetWindowInputFocus(SDL_Window *window)
|
||||||
return _this->SetWindowInputFocus(_this, window);
|
return _this->SetWindowInputFocus(_this, window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SDL_SetWindowFocusable(SDL_Window *window, SDL_bool focusable)
|
||||||
|
{
|
||||||
|
CHECK_WINDOW_MAGIC(window, -1);
|
||||||
|
|
||||||
|
const int want = (focusable != SDL_FALSE); /* normalize the flag. */
|
||||||
|
const int have = !(window->flags & SDL_WINDOW_NOT_FOCUSABLE);
|
||||||
|
if ((want != have) && (_this->SetWindowFocusable)) {
|
||||||
|
if (want) {
|
||||||
|
window->flags &= ~SDL_WINDOW_NOT_FOCUSABLE;
|
||||||
|
} else {
|
||||||
|
window->flags |= SDL_WINDOW_NOT_FOCUSABLE;
|
||||||
|
}
|
||||||
|
_this->SetWindowFocusable(_this, window, (SDL_bool)want);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void SDL_UpdateWindowGrab(SDL_Window *window)
|
void SDL_UpdateWindowGrab(SDL_Window *window)
|
||||||
{
|
{
|
||||||
SDL_bool keyboard_grabbed, mouse_grabbed;
|
SDL_bool keyboard_grabbed, mouse_grabbed;
|
||||||
|
|
|
@ -119,6 +119,7 @@ static SDL_VideoDevice *Cocoa_CreateDevice(void)
|
||||||
device->SetWindowHitTest = Cocoa_SetWindowHitTest;
|
device->SetWindowHitTest = Cocoa_SetWindowHitTest;
|
||||||
device->AcceptDragAndDrop = Cocoa_AcceptDragAndDrop;
|
device->AcceptDragAndDrop = Cocoa_AcceptDragAndDrop;
|
||||||
device->FlashWindow = Cocoa_FlashWindow;
|
device->FlashWindow = Cocoa_FlashWindow;
|
||||||
|
device->SetWindowFocusable = Cocoa_SetWindowFocusable;
|
||||||
|
|
||||||
device->shape_driver.CreateShaper = Cocoa_CreateShaper;
|
device->shape_driver.CreateShaper = Cocoa_CreateShaper;
|
||||||
device->shape_driver.SetWindowShape = Cocoa_SetWindowShape;
|
device->shape_driver.SetWindowShape = Cocoa_SetWindowShape;
|
||||||
|
|
|
@ -169,5 +169,6 @@ extern int Cocoa_GetWindowWMInfo(SDL_VideoDevice *_this, SDL_Window *window, str
|
||||||
extern int Cocoa_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
|
extern int Cocoa_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
|
||||||
extern void Cocoa_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept);
|
extern void Cocoa_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept);
|
||||||
extern int Cocoa_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation);
|
extern int Cocoa_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation);
|
||||||
|
extern int Cocoa_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool focusable);
|
||||||
|
|
||||||
#endif /* SDL_cocoawindow_h_ */
|
#endif /* SDL_cocoawindow_h_ */
|
||||||
|
|
|
@ -116,7 +116,7 @@
|
||||||
- (BOOL)canBecomeKeyWindow
|
- (BOOL)canBecomeKeyWindow
|
||||||
{
|
{
|
||||||
SDL_Window *window = [self findSDLWindow];
|
SDL_Window *window = [self findSDLWindow];
|
||||||
if (window && !(window->flags & SDL_WINDOW_TOOLTIP)) {
|
if (window && !(window->flags & (SDL_WINDOW_TOOLTIP | SDL_WINDOW_NOT_FOCUSABLE))) {
|
||||||
return YES;
|
return YES;
|
||||||
} else {
|
} else {
|
||||||
return NO;
|
return NO;
|
||||||
|
@ -2678,6 +2678,11 @@ int Cocoa_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOpera
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Cocoa_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool focusable)
|
||||||
|
{
|
||||||
|
return 0; /* just succeed, the real work is done elsewhere. */
|
||||||
|
}
|
||||||
|
|
||||||
int Cocoa_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity)
|
int Cocoa_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity)
|
||||||
{
|
{
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
|
|
|
@ -211,6 +211,7 @@ static SDL_VideoDevice *WIN_CreateDevice(void)
|
||||||
device->AcceptDragAndDrop = WIN_AcceptDragAndDrop;
|
device->AcceptDragAndDrop = WIN_AcceptDragAndDrop;
|
||||||
device->FlashWindow = WIN_FlashWindow;
|
device->FlashWindow = WIN_FlashWindow;
|
||||||
device->ShowWindowSystemMenu = WIN_ShowWindowSystemMenu;
|
device->ShowWindowSystemMenu = WIN_ShowWindowSystemMenu;
|
||||||
|
device->SetWindowFocusable = WIN_SetWindowFocusable;
|
||||||
|
|
||||||
device->shape_driver.CreateShaper = Win32_CreateShaper;
|
device->shape_driver.CreateShaper = Win32_CreateShaper;
|
||||||
device->shape_driver.SetWindowShape = Win32_SetWindowShape;
|
device->shape_driver.SetWindowShape = Win32_SetWindowShape;
|
||||||
|
|
|
@ -144,10 +144,11 @@ static DWORD GetWindowStyleEx(SDL_Window *window)
|
||||||
{
|
{
|
||||||
DWORD style = 0;
|
DWORD style = 0;
|
||||||
|
|
||||||
if (SDL_WINDOW_IS_POPUP(window)) {
|
if (SDL_WINDOW_IS_POPUP(window) || (window->flags & SDL_WINDOW_UTILITY)) {
|
||||||
style = WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE;
|
style |= WS_EX_TOOLWINDOW;
|
||||||
} else if (window->flags & SDL_WINDOW_UTILITY) {
|
}
|
||||||
style = WS_EX_TOOLWINDOW;
|
if (SDL_WINDOW_IS_POPUP(window) || (window->flags & SDL_WINDOW_NOT_FOCUSABLE)) {
|
||||||
|
style |= WS_EX_NOACTIVATE;
|
||||||
}
|
}
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
|
@ -1539,6 +1540,31 @@ void WIN_ShowWindowSystemMenu(SDL_Window *window, int x, int y)
|
||||||
ClientToScreen(data->hwnd, &pt);
|
ClientToScreen(data->hwnd, &pt);
|
||||||
SendMessage(data->hwnd, WM_POPUPSYSTEMMENU, 0, MAKELPARAM(pt.x, pt.y));
|
SendMessage(data->hwnd, WM_POPUPSYSTEMMENU, 0, MAKELPARAM(pt.x, pt.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WIN_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool focusable)
|
||||||
|
{
|
||||||
|
SDL_WindowData *data = window->driverdata;
|
||||||
|
HWND hwnd = data->hwnd;
|
||||||
|
const LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
|
||||||
|
|
||||||
|
SDL_assert(style != 0);
|
||||||
|
|
||||||
|
if (focusable) {
|
||||||
|
if (style & WS_EX_NOACTIVATE) {
|
||||||
|
if (SetWindowLong(hwnd, GWL_EXSTYLE, style & ~WS_EX_NOACTIVATE) == 0) {
|
||||||
|
return WIN_SetError("SetWindowLong()");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!(style & WS_EX_NOACTIVATE)) {
|
||||||
|
if (SetWindowLong(hwnd, GWL_EXSTYLE, style | WS_EX_NOACTIVATE) == 0) {
|
||||||
|
return WIN_SetError("SetWindowLong()");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
|
#endif /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/
|
||||||
|
|
||||||
void WIN_UpdateDarkModeForHWND(HWND hwnd)
|
void WIN_UpdateDarkModeForHWND(HWND hwnd)
|
||||||
|
|
|
@ -109,6 +109,7 @@ extern int WIN_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Flash
|
||||||
extern void WIN_UpdateDarkModeForHWND(HWND hwnd);
|
extern void WIN_UpdateDarkModeForHWND(HWND hwnd);
|
||||||
extern int WIN_SetWindowPositionInternal(SDL_Window *window, UINT flags);
|
extern int WIN_SetWindowPositionInternal(SDL_Window *window, UINT flags);
|
||||||
extern void WIN_ShowWindowSystemMenu(SDL_Window *window, int x, int y);
|
extern void WIN_ShowWindowSystemMenu(SDL_Window *window, int x, int y);
|
||||||
|
extern int WIN_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool focusable);
|
||||||
|
|
||||||
/* Ends C function definitions when using C++ */
|
/* Ends C function definitions when using C++ */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -212,6 +212,7 @@ static SDL_VideoDevice *X11_CreateDevice(void)
|
||||||
device->AcceptDragAndDrop = X11_AcceptDragAndDrop;
|
device->AcceptDragAndDrop = X11_AcceptDragAndDrop;
|
||||||
device->FlashWindow = X11_FlashWindow;
|
device->FlashWindow = X11_FlashWindow;
|
||||||
device->ShowWindowSystemMenu = X11_ShowWindowSystemMenu;
|
device->ShowWindowSystemMenu = X11_ShowWindowSystemMenu;
|
||||||
|
device->SetWindowFocusable = X11_SetWindowFocusable;
|
||||||
|
|
||||||
#ifdef SDL_VIDEO_DRIVER_X11_XFIXES
|
#ifdef SDL_VIDEO_DRIVER_X11_XFIXES
|
||||||
device->SetWindowMouseRect = X11_SetWindowMouseRect;
|
device->SetWindowMouseRect = X11_SetWindowMouseRect;
|
||||||
|
|
|
@ -623,7 +623,7 @@ int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window)
|
||||||
|
|
||||||
/* Setup the input hints so we get keyboard input */
|
/* Setup the input hints so we get keyboard input */
|
||||||
wmhints = X11_XAllocWMHints();
|
wmhints = X11_XAllocWMHints();
|
||||||
wmhints->input = True;
|
wmhints->input = !(window->flags & SDL_WINDOW_NOT_FOCUSABLE) ? True : False;
|
||||||
wmhints->window_group = data->window_group;
|
wmhints->window_group = data->window_group;
|
||||||
wmhints->flags = InputHint | WindowGroupHint;
|
wmhints->flags = InputHint | WindowGroupHint;
|
||||||
|
|
||||||
|
@ -1982,4 +1982,24 @@ void X11_ShowWindowSystemMenu(SDL_Window *window, int x, int y)
|
||||||
X11_XFlush(display);
|
X11_XFlush(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int X11_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool focusable)
|
||||||
|
{
|
||||||
|
SDL_WindowData *data = window->driverdata;
|
||||||
|
Display *display = data->videodata->display;
|
||||||
|
XWMHints *wmhints;
|
||||||
|
|
||||||
|
wmhints = X11_XGetWMHints(display, data->xwindow);
|
||||||
|
if (wmhints == NULL) {
|
||||||
|
return SDL_SetError("Couldn't get WM hints");
|
||||||
|
}
|
||||||
|
|
||||||
|
wmhints->input = focusable ? True : False;
|
||||||
|
wmhints->flags |= InputHint;
|
||||||
|
|
||||||
|
X11_XSetWMHints(display, data->xwindow, wmhints);
|
||||||
|
X11_XFree(wmhints);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* SDL_VIDEO_DRIVER_X11 */
|
#endif /* SDL_VIDEO_DRIVER_X11 */
|
||||||
|
|
|
@ -116,6 +116,7 @@ extern int X11_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
|
||||||
extern void X11_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept);
|
extern void X11_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept);
|
||||||
extern int X11_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation);
|
extern int X11_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation);
|
||||||
extern void X11_ShowWindowSystemMenu(SDL_Window *window, int x, int y);
|
extern void X11_ShowWindowSystemMenu(SDL_Window *window, int x, int y);
|
||||||
|
extern int X11_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, SDL_bool focusable);
|
||||||
|
|
||||||
int SDL_X11_SetWindowTitle(Display *display, Window xwindow, char *title);
|
int SDL_X11_SetWindowTitle(Display *display, Window xwindow, char *title);
|
||||||
void X11_UpdateWindowPosition(SDL_Window *window);
|
void X11_UpdateWindowPosition(SDL_Window *window);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue