Implement glfwWindowBell

Exposes the platform specific Bell/Beep API to make the default
system beep sound.
This commit is contained in:
Kovid Goyal 2017-11-20 22:55:09 +05:30
parent 2884915000
commit 0fbf489bbb
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
8 changed files with 67 additions and 8 deletions

View File

@ -3185,6 +3185,29 @@ GLFWAPI void glfwFocusWindow(GLFWwindow* window);
*/
GLFWAPI void glfwRequestWindowAttention(GLFWwindow* window);
/*! @brief Sounds an audible bell associated with the window
*
* This function sounds an audible bell, on platforms where it is
* supported. Currently (macOS, Windows, X11 and Wayland).
*
* @param[in] window The window with which the bell is associated.
* @return GLFW_TRUE if the bell succeeded otherwise GLFW_FALSE
*
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_ERROR.
*
* @remark @macos Bell is associated to the application as a whole, not the
* specific window.
*
* @thread_safety This function must only be called from the main thread.
*
* @since Added in version 3.3.
*
* @ingroup window
*/
GLFWAPI int glfwWindowBell(GLFWwindow* window);
/*! @brief Returns the monitor that the window uses for full screen mode.
*
* This function returns the handle of the monitor that the specified window is
@ -5519,4 +5542,3 @@ GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window
#endif
#endif /* _glfw3_h_ */

View File

@ -1367,6 +1367,12 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)
[NSApp requestUserAttention:NSInformationalRequest];
}
int _glfwPlatformWindowBell(_GLFWwindow* window)
{
NSBeep();
return GLFW_TRUE;
}
void _glfwPlatformFocusWindow(_GLFWwindow* window)
{
// Make us the active application
@ -1906,4 +1912,3 @@ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* handle)
_GLFW_REQUIRE_INIT_OR_RETURN(nil);
return window->ns.object;
}

View File

@ -653,6 +653,7 @@ void _glfwPlatformMaximizeWindow(_GLFWwindow* window);
void _glfwPlatformShowWindow(_GLFWwindow* window);
void _glfwPlatformHideWindow(_GLFWwindow* window);
void _glfwPlatformRequestWindowAttention(_GLFWwindow* window);
int _glfwPlatformWindowBell(_GLFWwindow* window);
void _glfwPlatformFocusWindow(_GLFWwindow* window);
void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor,
int xpos, int ypos, int width, int height,
@ -768,4 +769,3 @@ void _glfwTerminateVulkan(void);
const char* _glfwGetVulkanResultString(VkResult result);
char* _glfw_strdup(const char* source);

View File

@ -205,6 +205,11 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)
{
}
int _glfwPlatformWindowBell(_GLFWwindow* window)
{
return GLFW_FALSE;
}
void _glfwPlatformUnhideWindow(_GLFWwindow* window)
{
}
@ -318,4 +323,3 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
// This seems like the most appropriate error to return here
return VK_ERROR_INITIALIZATION_FAILED;
}

View File

@ -1474,6 +1474,11 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)
FlashWindow(window->win32.handle, TRUE);
}
int _glfwPlatformWindowBell(_GLFWwindow* window)
{
return MessageBeep(0xFFFFFFFF) ? GLFW_TRUE : GLFW_FALSE;
}
void _glfwPlatformFocusWindow(_GLFWwindow* window)
{
BringWindowToTop(window->win32.handle);
@ -2009,4 +2014,3 @@ GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle)
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return window->win32.handle;
}

View File

@ -768,6 +768,16 @@ GLFWAPI void glfwRequestWindowAttention(GLFWwindow* handle)
_glfwPlatformRequestWindowAttention(window);
}
GLFWAPI int glfwWindowBell(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
assert(window != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE);
return _glfwPlatformWindowBell(window);
}
GLFWAPI void glfwHideWindow(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
@ -1096,4 +1106,3 @@ GLFWAPI void glfwPostEmptyEvent(void)
_glfwPlatformPostEmptyEvent();
}

View File

@ -1079,6 +1079,18 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)
"Wayland: Window attention request not implemented yet");
}
int _glfwPlatformWindowBell(_GLFWwindow* window)
{
// TODO: Use an actual Wayland API to implement this when one becomes available
int fd = open("/dev/tty", O_WRONLY | O_CLOEXEC);
if (fd > -1) {
int ret = write(fd, "\x07", 1) == 1 ? GLFW_TRUE : GLFW_FALSE;
close(fd);
return ret;
}
return GLFW_FALSE;
}
void _glfwPlatformFocusWindow(_GLFWwindow* window)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
@ -1539,4 +1551,3 @@ GLFWAPI struct wl_surface* glfwGetWaylandWindow(GLFWwindow* handle)
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return window->wl.surface;
}

View File

@ -2340,6 +2340,11 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)
0, 1, 0);
}
int _glfwPlatformWindowBell(_GLFWwindow* window)
{
return XkbBell(_glfw.x11.display, window->x11.handle, 100, (Atom)0) ? GLFW_TRUE : GLFW_FALSE;
}
void _glfwPlatformFocusWindow(_GLFWwindow* window)
{
if (_glfw.x11.NET_ACTIVE_WINDOW)
@ -3039,4 +3044,3 @@ GLFWAPI const char* glfwGetX11SelectionString(void)
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return getSelectionString(_glfw.x11.PRIMARY);
}