Added a window flash operation to be explicit about window flash behavior

This commit is contained in:
Sam Lantinga
2021-07-24 13:41:55 -07:00
parent b2c8d3e9e4
commit f1633127d1
16 changed files with 79 additions and 32 deletions

View File

@@ -240,7 +240,7 @@ struct SDL_VideoDevice
int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects);
void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
void (*OnWindowEnter) (_THIS, SDL_Window * window);
int (*FlashWindow) (_THIS, SDL_Window * window);
int (*FlashWindow) (_THIS, SDL_Window * window, SDL_FlashOperation operation);
/* * * */
/*

View File

@@ -2793,12 +2793,12 @@ SDL_GetGrabbedWindow(void)
}
int
SDL_FlashWindow(SDL_Window * window)
SDL_FlashWindow(SDL_Window * window, SDL_FlashOperation operation)
{
CHECK_WINDOW_MAGIC(window, -1);
if (_this->FlashWindow) {
return _this->FlashWindow(_this, window);
return _this->FlashWindow(_this, window, operation);
}
return SDL_Unsupported();

View File

@@ -117,6 +117,7 @@ struct SDL_WindowData
NSMutableArray *nscontexts;
SDL_bool created;
SDL_bool inWindowFullscreenTransition;
NSInteger flash_request;
Cocoa_WindowListener *listener;
struct SDL_VideoData *videodata;
#if SDL_VIDEO_OPENGL_EGL
@@ -151,7 +152,7 @@ extern void Cocoa_DestroyWindow(_THIS, SDL_Window * window);
extern SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info);
extern int Cocoa_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
extern void Cocoa_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept);
extern int Cocoa_FlashWindow(_THIS, SDL_Window * window);
extern int Cocoa_FlashWindow(_THIS, SDL_Window * window, SDL_FlashOperation operation);
#endif /* SDL_cocoawindow_h_ */

View File

@@ -2117,11 +2117,30 @@ Cocoa_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept)
}
int
Cocoa_FlashWindow(_THIS, SDL_Window *window)
Cocoa_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation)
{ @autoreleasepool
{
/* Note that this is app-wide and not window-specific! */
[NSApp requestUserAttention:NSInformationalRequest];
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
if (data->flash_request) {
[NSApp cancelUserAttentionRequest:data->flash_request];
data->flash_request = 0;
}
switch (operation) {
case SDL_FLASH_CANCEL:
/* Canceled above */
break;
case SDL_FLASH_BRIEFLY:
data->flash_request = [NSApp requestUserAttention:NSInformationalRequest];
break;
case SDL_FLASH_UNTIL_FOCUSED:
data->flash_request = [NSApp requestUserAttention:NSCriticalRequest];
break;
default:
return SDL_Unsupported();
}
return 0;
}}

View File

@@ -196,7 +196,7 @@ static void UpdateMouseGrab()
static int SetGCMouseRelativeMode(SDL_bool enabled)
{
mouse_relative_mode = enabled;
mouse_relative_mode = enabled;
UpdateMouseGrab();
return 0;
}

View File

@@ -920,7 +920,7 @@ Wayland_RaiseWindow(_THIS, SDL_Window *window)
}
int
Wayland_FlashWindow(_THIS, SDL_Window *window)
Wayland_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation)
{
Wayland_activate_window(_this->driverdata,
window->driverdata,

View File

@@ -113,7 +113,7 @@ extern void Wayland_SuspendScreenSaver(_THIS);
extern SDL_bool
Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
extern int Wayland_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
extern int Wayland_FlashWindow(_THIS, SDL_Window * window);
extern int Wayland_FlashWindow(_THIS, SDL_Window * window, SDL_FlashOperation operation);
extern void Wayland_HandlePendingResize(SDL_Window *window);

View File

@@ -1064,19 +1064,26 @@ WIN_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept)
}
int
WIN_FlashWindow(_THIS, SDL_Window * window)
WIN_FlashWindow(_THIS, SDL_Window * window, SDL_FlashOperation operation)
{
FLASHWINFO desc;
const char *hint = SDL_GetHint(SDL_HINT_WINDOW_FLASH_COUNT);
SDL_zero(desc);
desc.cbSize = sizeof(desc);
desc.hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
desc.dwFlags = FLASHW_TRAY;
if (hint && *hint) {
desc.uCount = SDL_atoi(hint);
} else {
desc.dwFlags |= FLASHW_TIMERNOFG;
switch (operation) {
case SDL_FLASH_CANCEL:
desc.dwFlags = FLASHW_STOP;
break;
case SDL_FLASH_BRIEFLY:
desc.dwFlags = FLASHW_TRAY;
desc.uCount = 1;
break;
case SDL_FLASH_UNTIL_FOCUSED:
desc.dwFlags = (FLASHW_TRAY | FLASHW_TIMERNOFG);
break;
default:
return SDL_Unsupported();
}
FlashWindowEx(&desc);

View File

@@ -86,7 +86,7 @@ extern void WIN_OnWindowEnter(_THIS, SDL_Window * window);
extern void WIN_UpdateClipCursor(SDL_Window *window);
extern int WIN_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
extern void WIN_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept);
extern int WIN_FlashWindow(_THIS, SDL_Window * window);
extern int WIN_FlashWindow(_THIS, SDL_Window * window, SDL_FlashOperation operation);
#endif /* SDL_windowswindow_h_ */

View File

@@ -1749,7 +1749,7 @@ X11_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept)
}
int
X11_FlashWindow(_THIS, SDL_Window * window)
X11_FlashWindow(_THIS, SDL_Window * window, SDL_FlashOperation operation)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;

View File

@@ -107,7 +107,7 @@ extern SDL_bool X11_GetWindowWMInfo(_THIS, SDL_Window * window,
struct SDL_SysWMinfo *info);
extern int X11_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
extern void X11_AcceptDragAndDrop(SDL_Window * window, SDL_bool accept);
extern int X11_FlashWindow(_THIS, SDL_Window * window);
extern int X11_FlashWindow(_THIS, SDL_Window * window, SDL_FlashOperation operation);
#endif /* SDL_x11window_h_ */