mirror of
https://github.com/love2d/love.git
synced 2026-08-21 05:00:08 +02:00
Added love.window.requestAttention. Bounces the dock icon in OS X and flashes the taskbar icon in Windows when called, if the program isn't in focus.
This commit is contained in:
@@ -50,6 +50,11 @@ std::string checkDropEvents();
|
|||||||
**/
|
**/
|
||||||
std::string getExecutablePath();
|
std::string getExecutablePath();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bounce the dock icon, if the app isn't in the foreground.
|
||||||
|
**/
|
||||||
|
void requestAttention(bool continuous);
|
||||||
|
|
||||||
} // osx
|
} // osx
|
||||||
} // love
|
} // love
|
||||||
|
|
||||||
|
|||||||
+13
-1
@@ -23,6 +23,7 @@
|
|||||||
#ifdef LOVE_MACOSX
|
#ifdef LOVE_MACOSX
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ std::string getLoveInResources()
|
|||||||
NSString *lovepath = [[NSBundle mainBundle] pathForResource:nil ofType:@"love"];
|
NSString *lovepath = [[NSBundle mainBundle] pathForResource:nil ofType:@"love"];
|
||||||
|
|
||||||
if (lovepath != nil)
|
if (lovepath != nil)
|
||||||
path = [lovepath UTF8String];
|
path = lovepath.UTF8String;
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
@@ -77,6 +78,17 @@ std::string getExecutablePath()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void requestAttention(bool continuous)
|
||||||
|
{
|
||||||
|
@autoreleasepool
|
||||||
|
{
|
||||||
|
if (continuous)
|
||||||
|
[NSApp requestUserAttention:NSCriticalRequest];
|
||||||
|
else
|
||||||
|
[NSApp requestUserAttention:NSInformationalRequest];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // osx
|
} // osx
|
||||||
} // love
|
} // love
|
||||||
|
|
||||||
|
|||||||
@@ -171,6 +171,8 @@ public:
|
|||||||
virtual bool showMessageBox(const std::string &title, const std::string &message, MessageBoxType type, bool attachtowindow) = 0;
|
virtual bool showMessageBox(const std::string &title, const std::string &message, MessageBoxType type, bool attachtowindow) = 0;
|
||||||
virtual int showMessageBox(const MessageBoxData &data) = 0;
|
virtual int showMessageBox(const MessageBoxData &data) = 0;
|
||||||
|
|
||||||
|
virtual void requestAttention(bool continuous) = 0;
|
||||||
|
|
||||||
//virtual static Window *createSingleton() = 0;
|
//virtual static Window *createSingleton() = 0;
|
||||||
// No virtual statics, of course, but you are supposed to implement this static.
|
// No virtual statics, of course, but you are supposed to implement this static.
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,13 @@
|
|||||||
// C
|
// C
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
#ifdef LOVE_WINDOWS
|
// SDL
|
||||||
|
#include <SDL_syswm.h>
|
||||||
|
|
||||||
|
#if defined(LOVE_WINDOWS)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#elif defined(LOVE_MACOSX)
|
||||||
|
#include "common/OSX.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef APIENTRY
|
#ifndef APIENTRY
|
||||||
@@ -965,6 +970,36 @@ int Window::showMessageBox(const MessageBoxData &data)
|
|||||||
return pressedbutton;
|
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()
|
love::window::Window *Window::createSingleton()
|
||||||
{
|
{
|
||||||
if (!singleton)
|
if (!singleton)
|
||||||
|
|||||||
@@ -100,6 +100,8 @@ public:
|
|||||||
bool showMessageBox(const std::string &title, const std::string &message, MessageBoxType type, bool attachtowindow);
|
bool showMessageBox(const std::string &title, const std::string &message, MessageBoxType type, bool attachtowindow);
|
||||||
int showMessageBox(const MessageBoxData &data);
|
int showMessageBox(const MessageBoxData &data);
|
||||||
|
|
||||||
|
void requestAttention(bool continuous) override;
|
||||||
|
|
||||||
static love::window::Window *createSingleton();
|
static love::window::Window *createSingleton();
|
||||||
|
|
||||||
const char *getName() const;
|
const char *getName() const;
|
||||||
|
|||||||
@@ -483,6 +483,13 @@ int w_showMessageBox(lua_State *L)
|
|||||||
return 1;
|
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[] =
|
static const luaL_Reg functions[] =
|
||||||
{
|
{
|
||||||
{ "getDisplayCount", w_getDisplayCount },
|
{ "getDisplayCount", w_getDisplayCount },
|
||||||
@@ -509,6 +516,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "minimize", w_minimize },
|
{ "minimize", w_minimize },
|
||||||
{ "maximize", w_maximize },
|
{ "maximize", w_maximize },
|
||||||
{ "showMessageBox", w_showMessageBox },
|
{ "showMessageBox", w_showMessageBox },
|
||||||
|
{ "requestAttention", w_requestAttention },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ int w_fromPixels(lua_State *L);
|
|||||||
int w_minimize(lua_State *L);
|
int w_minimize(lua_State *L);
|
||||||
int w_maximize(lua_State *L);
|
int w_maximize(lua_State *L);
|
||||||
int w_showMessageBox(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);
|
extern "C" LOVE_EXPORT int luaopen_love_window(lua_State *L);
|
||||||
|
|
||||||
} // window
|
} // window
|
||||||
|
|||||||
Reference in New Issue
Block a user