diff --git a/src/common/OSX.h b/src/common/OSX.h index 4d40b17bd..696646794 100644 --- a/src/common/OSX.h +++ b/src/common/OSX.h @@ -50,6 +50,11 @@ std::string checkDropEvents(); **/ std::string getExecutablePath(); +/** + * Bounce the dock icon, if the app isn't in the foreground. + **/ +void requestAttention(bool continuous); + } // osx } // love diff --git a/src/common/OSX.mm b/src/common/OSX.mm index 725bdcb2a..e5112b240 100644 --- a/src/common/OSX.mm +++ b/src/common/OSX.mm @@ -23,6 +23,7 @@ #ifdef LOVE_MACOSX #import +#import #include @@ -41,7 +42,7 @@ std::string getLoveInResources() NSString *lovepath = [[NSBundle mainBundle] pathForResource:nil ofType:@"love"]; if (lovepath != nil) - path = [lovepath UTF8String]; + path = lovepath.UTF8String; } return path; @@ -77,6 +78,17 @@ std::string getExecutablePath() } } +void requestAttention(bool continuous) +{ + @autoreleasepool + { + if (continuous) + [NSApp requestUserAttention:NSCriticalRequest]; + else + [NSApp requestUserAttention:NSInformationalRequest]; + } +} + } // osx } // love diff --git a/src/modules/window/Window.h b/src/modules/window/Window.h index 5fe8a59da..e0738011b 100644 --- a/src/modules/window/Window.h +++ b/src/modules/window/Window.h @@ -171,6 +171,8 @@ public: virtual bool showMessageBox(const std::string &title, const std::string &message, MessageBoxType type, bool attachtowindow) = 0; virtual int showMessageBox(const MessageBoxData &data) = 0; + virtual void requestAttention(bool continuous) = 0; + //virtual static Window *createSingleton() = 0; // No virtual statics, of course, but you are supposed to implement this static. diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index c45c9f9b2..6947c3bd7 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -31,8 +31,13 @@ // C #include -#ifdef LOVE_WINDOWS +// SDL +#include + +#if defined(LOVE_WINDOWS) #include +#elif defined(LOVE_MACOSX) +#include "common/OSX.h" #endif #ifndef APIENTRY @@ -965,6 +970,36 @@ int Window::showMessageBox(const MessageBoxData &data) return pressedbutton; } +void Window::requestAttention(bool continuous) +{ +#if defined(LOVE_WINDOWS) + + SDL_SysWMinfo wminfo = {}; + SDL_VERSION(&wminfo.version); + + if (SDL_GetWindowWMInfo(window, &wminfo)) + { + FLASHWINFO flashinfo = {}; + flashinfo.cbSize = sizeof(FLASHWINFO); + flashinfo.hwnd = wminfo.info.win.window; + flashinfo.uCount = 1; + flashinfo.dwFlags = FLASHW_ALL; + + if (continuous) + flashinfo.dwFlags |= FLASHW_TIMERNOFG; + + FlashWindowEx(&flashinfo); + } + +#elif defined(LOVE_MACOSX) + + love::osx::requestAttention(continuous); + +#endif + + // TODO: Linux? +} + love::window::Window *Window::createSingleton() { if (!singleton) diff --git a/src/modules/window/sdl/Window.h b/src/modules/window/sdl/Window.h index 994408e89..2174f5489 100644 --- a/src/modules/window/sdl/Window.h +++ b/src/modules/window/sdl/Window.h @@ -100,6 +100,8 @@ public: bool showMessageBox(const std::string &title, const std::string &message, MessageBoxType type, bool attachtowindow); int showMessageBox(const MessageBoxData &data); + void requestAttention(bool continuous) override; + static love::window::Window *createSingleton(); const char *getName() const; diff --git a/src/modules/window/wrap_Window.cpp b/src/modules/window/wrap_Window.cpp index c5f1c9dd3..5ab492150 100644 --- a/src/modules/window/wrap_Window.cpp +++ b/src/modules/window/wrap_Window.cpp @@ -483,6 +483,13 @@ int w_showMessageBox(lua_State *L) return 1; } +int w_requestAttention(lua_State *L) +{ + bool continuous = luax_optboolean(L, 1, false); + instance()->requestAttention(continuous); + return 0; +} + static const luaL_Reg functions[] = { { "getDisplayCount", w_getDisplayCount }, @@ -509,6 +516,7 @@ static const luaL_Reg functions[] = { "minimize", w_minimize }, { "maximize", w_maximize }, { "showMessageBox", w_showMessageBox }, + { "requestAttention", w_requestAttention }, { 0, 0 } }; diff --git a/src/modules/window/wrap_Window.h b/src/modules/window/wrap_Window.h index 513c463b2..882be9964 100644 --- a/src/modules/window/wrap_Window.h +++ b/src/modules/window/wrap_Window.h @@ -53,6 +53,7 @@ int w_fromPixels(lua_State *L); int w_minimize(lua_State *L); int w_maximize(lua_State *L); int w_showMessageBox(lua_State *L); +int w_requestAttention(lua_State *L); extern "C" LOVE_EXPORT int luaopen_love_window(lua_State *L); } // window