Skip to content

Commit

Permalink
Only reset the clip rect if it's currently the rect we previously cli…
Browse files Browse the repository at this point in the history
…pped.

This prevents us from clearing the clip rect globally when another application has set it.

There's also an experimental change to regularly update the clip rect for a window defensively, in case someone else has reset it. It works well, but I don't know if it's cheap enough to call as frequently as it would be called now, and might have other undesirable side effects.

Also fixed whitespace and SDL coding style
  • Loading branch information
slouken committed Aug 26, 2018
1 parent 09ab752 commit 15b3794
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 37 deletions.
3 changes: 2 additions & 1 deletion src/video/SDL_video.c
Expand Up @@ -1543,8 +1543,9 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
// Clear minimized if not on windows, only windows handles it at create rather than FinishWindowCreation,
// but it's important or window focus will get broken on windows!
#if !defined(__WIN32__)
if ( window->flags & SDL_WINDOW_MINIMIZED )
if (window->flags & SDL_WINDOW_MINIMIZED) {
window->flags &= ~SDL_WINDOW_MINIMIZED;
}
#endif

#if __WINRT__ && (NTDDI_VERSION < NTDDI_WIN10)
Expand Down
29 changes: 19 additions & 10 deletions src/video/windows/SDL_windowsevents.c
Expand Up @@ -228,9 +228,7 @@ WIN_CheckWParamMouseButton(SDL_bool bwParamMousePressed, SDL_bool bSDLMousePress
/* Ignore the button click for activation */
if (!bwParamMousePressed) {
data->focus_click_pending &= ~SDL_BUTTON(button);
if (!data->focus_click_pending) {
WIN_UpdateClipCursor(data->window);
}
WIN_UpdateClipCursor(data->window);
}
if (WIN_ShouldIgnoreFocusClick()) {
return;
Expand Down Expand Up @@ -401,6 +399,11 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
#endif /* WMMSG_DEBUG */

/* Update the clipping rect in case someone else has stolen it */
/* FIXME: Is this function cheap enough to call this frequently?
WIN_UpdateClipCursor(data->window);
*/

if (IME_HandleMessage(hwnd, msg, wParam, &lParam, data->videodata))
return 0;

Expand Down Expand Up @@ -465,14 +468,20 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
SDL_ToggleModState(KMOD_CAPS, (GetKeyState(VK_CAPITAL) & 0x0001) != 0);
SDL_ToggleModState(KMOD_NUM, (GetKeyState(VK_NUMLOCK) & 0x0001) != 0);
} else {
RECT rect;

data->in_window_deactivation = SDL_TRUE;

if (SDL_GetKeyboardFocus() == data->window) {
SDL_SetKeyboardFocus(NULL);
WIN_ResetDeadKeys();
}

ClipCursor(NULL);
if (GetClipCursor(&rect) && SDL_memcmp(&rect, &data->cursor_clipped_rect, sizeof(rect) == 0)) {
SDL_Log("Windows deactivate, ClipCursor(NULL)\n");
ClipCursor(NULL);
SDL_zero(data->cursor_clipped_rect);
}

data->in_window_deactivation = SDL_FALSE;
}
Expand Down Expand Up @@ -653,16 +662,16 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
break;

case WM_UNICHAR:
if ( wParam == UNICODE_NOCHAR ) {
if (wParam == UNICODE_NOCHAR) {
returnCode = 1;
break;
}
/* otherwise fall through to below */
case WM_CHAR:
{
char text[5];
if ( WIN_ConvertUTF32toUTF8( (UINT32)wParam, text ) ) {
SDL_SendKeyboardText( text );
if (WIN_ConvertUTF32toUTF8((UINT32)wParam, text)) {
SDL_SendKeyboardText(text);
}
}
returnCode = 0;
Expand Down Expand Up @@ -1099,9 +1108,9 @@ IsWin10FCUorNewer(void)
SDL_zero(info);
info.dwOSVersionInfoSize = sizeof(info);
if (getVersionPtr(&info) == 0) { /* STATUS_SUCCESS == 0 */
if ( (info.dwMajorVersion == 10 && info.dwMinorVersion == 0 && info.dwBuildNumber >= 16299)
|| (info.dwMajorVersion == 10 && info.dwMinorVersion > 0)
|| (info.dwMajorVersion > 10) )
if ((info.dwMajorVersion == 10 && info.dwMinorVersion == 0 && info.dwBuildNumber >= 16299) ||
(info.dwMajorVersion == 10 && info.dwMinorVersion > 0) ||
(info.dwMajorVersion > 10))
{
return SDL_TRUE;
}
Expand Down
56 changes: 30 additions & 26 deletions src/video/windows/SDL_windowswindow.c
Expand Up @@ -98,9 +98,10 @@ GetWindowStyle(SDL_Window * window)
style |= STYLE_RESIZABLE;
}

/* Need to set initialize minimize style, or when we call ShowWindow with WS_MINIMIZE it will activate a random window */
if ( window->flags & SDL_WINDOW_MINIMIZED )
style |= WS_MINIMIZE;
/* Need to set initialize minimize style, or when we call ShowWindow with WS_MINIMIZE it will activate a random window */
if (window->flags & SDL_WINDOW_MINIMIZED) {
style |= WS_MINIMIZE;
}
}
return style;
}
Expand Down Expand Up @@ -334,8 +335,9 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
/* Inform Windows of the frame change so we can respond to WM_NCCALCSIZE */
SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);

if ( window->flags & SDL_WINDOW_MINIMIZED )
ShowWindow( hwnd, SW_SHOWMINNOACTIVE );
if (window->flags & SDL_WINDOW_MINIMIZED) {
ShowWindow(hwnd, SW_SHOWMINNOACTIVE);
}

if (!(window->flags & SDL_WINDOW_OPENGL)) {
return 0;
Expand Down Expand Up @@ -409,13 +411,11 @@ WIN_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
SDL_sscanf(hint, "%p", (void**)&otherWindow);

/* Do some error checking on the pointer */
if (otherWindow != NULL && otherWindow->magic == &_this->window_magic)
{
if (otherWindow != NULL && otherWindow->magic == &_this->window_magic) {
/* If the otherWindow has SDL_WINDOW_OPENGL set, set it for the new window as well */
if (otherWindow->flags & SDL_WINDOW_OPENGL)
{
if (otherWindow->flags & SDL_WINDOW_OPENGL) {
window->flags |= SDL_WINDOW_OPENGL;
if(!WIN_GL_SetPixelFormatFrom(_this, otherWindow, window)) {
if (!WIN_GL_SetPixelFormatFrom(_this, otherWindow, window)) {
return -1;
}
}
Expand Down Expand Up @@ -548,17 +548,17 @@ WIN_GetWindowBordersSize(_THIS, SDL_Window * window, int *top, int *left, int *b
void
WIN_ShowWindow(_THIS, SDL_Window * window)
{
DWORD style;
HWND hwnd;
int nCmdShow;
hwnd = ( (SDL_WindowData *)window->driverdata )->hwnd;
nCmdShow = SW_SHOW;
style = GetWindowLong(hwnd, GWL_EXSTYLE);
if ( style & WS_EX_NOACTIVATE )
nCmdShow = SW_SHOWNOACTIVATE;
ShowWindow(hwnd, nCmdShow );
DWORD style;
HWND hwnd;
int nCmdShow;
hwnd = ((SDL_WindowData *)window->driverdata)->hwnd;
nCmdShow = SW_SHOW;
style = GetWindowLong(hwnd, GWL_EXSTYLE);
if (style & WS_EX_NOACTIVATE) {
nCmdShow = SW_SHOWNOACTIVATE;
}
ShowWindow(hwnd, nCmdShow);
}

void
Expand Down Expand Up @@ -902,6 +902,7 @@ WIN_UpdateClipCursor(SDL_Window *window)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_Mouse *mouse = SDL_GetMouse();
RECT rect;

if (data->focus_click_pending) {
return;
Expand All @@ -911,7 +912,6 @@ WIN_UpdateClipCursor(SDL_Window *window)
(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
if (mouse->relative_mode && !mouse->relative_mode_warp) {
LONG cx, cy;
RECT rect;
GetWindowRect(data->hwnd, &rect);

cx = (rect.left + rect.right) / 2;
Expand All @@ -923,17 +923,21 @@ WIN_UpdateClipCursor(SDL_Window *window)
rect.top = cy - 1;
rect.bottom = cy + 1;

ClipCursor(&rect);
if (ClipCursor(&rect)) {
data->cursor_clipped_rect = rect;
}
} else {
RECT rect;
if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) {
ClientToScreen(data->hwnd, (LPPOINT) & rect);
ClientToScreen(data->hwnd, (LPPOINT) & rect + 1);
ClipCursor(&rect);
if (ClipCursor(&rect)) {
data->cursor_clipped_rect = rect;
}
}
}
} else {
} else if (GetClipCursor(&rect) && SDL_memcmp(&rect, &data->cursor_clipped_rect, sizeof(rect)) == 0) {
ClipCursor(NULL);
SDL_zero(data->cursor_clipped_rect);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/video/windows/SDL_windowswindow.h
Expand Up @@ -46,6 +46,7 @@ typedef struct
Uint8 focus_click_pending;
SDL_bool windowed_mode_was_maximized;
SDL_bool in_window_deactivation;
RECT cursor_clipped_rect;
struct SDL_VideoData *videodata;
#if SDL_VIDEO_OPENGL_EGL
EGLSurface egl_surface;
Expand Down

0 comments on commit 15b3794

Please sign in to comment.