Move the bell implementation into glfw
This commit is contained in:
@@ -1350,6 +1350,12 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)
|
|||||||
[NSApp requestUserAttention:NSInformationalRequest];
|
[NSApp requestUserAttention:NSInformationalRequest];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int _glfwPlatformWindowBell(_GLFWwindow* window, int64_t param)
|
||||||
|
{
|
||||||
|
NSBeep();
|
||||||
|
return GLFW_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
void _glfwPlatformFocusWindow(_GLFWwindow* window)
|
void _glfwPlatformFocusWindow(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
// Make us the active application
|
// Make us the active application
|
||||||
|
|||||||
27
glfw/glfw3.h
vendored
27
glfw/glfw3.h
vendored
@@ -3086,6 +3086,33 @@ GLFWAPI void glfwFocusWindow(GLFWwindow* window);
|
|||||||
*/
|
*/
|
||||||
GLFWAPI void glfwRequestWindowAttention(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 and X11).
|
||||||
|
*
|
||||||
|
* @param[in] window The window with which the bell is associated.
|
||||||
|
* @param[in] param The meaning of this parameter is platform dependent. On
|
||||||
|
* X11 it corresponds to the percentage controlling bell volume (see man
|
||||||
|
* XBell). On Windows it is the type of sound to make, see the MSDN docs for
|
||||||
|
* MessageBeep. On macOS, it is ignored.
|
||||||
|
* @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, int64_t param);
|
||||||
|
|
||||||
|
|
||||||
/*! @brief Returns the monitor that the window uses for full screen mode.
|
/*! @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
|
* This function returns the handle of the monitor that the specified window is
|
||||||
|
|||||||
1
glfw/internal.h
vendored
1
glfw/internal.h
vendored
@@ -680,6 +680,7 @@ void _glfwPlatformMaximizeWindow(_GLFWwindow* window);
|
|||||||
void _glfwPlatformShowWindow(_GLFWwindow* window);
|
void _glfwPlatformShowWindow(_GLFWwindow* window);
|
||||||
void _glfwPlatformHideWindow(_GLFWwindow* window);
|
void _glfwPlatformHideWindow(_GLFWwindow* window);
|
||||||
void _glfwPlatformRequestWindowAttention(_GLFWwindow* window);
|
void _glfwPlatformRequestWindowAttention(_GLFWwindow* window);
|
||||||
|
int _glfwPlatformWindowBell(_GLFWwindow* window, int64_t);
|
||||||
void _glfwPlatformFocusWindow(_GLFWwindow* window);
|
void _glfwPlatformFocusWindow(_GLFWwindow* window);
|
||||||
void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate);
|
void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate);
|
||||||
int _glfwPlatformWindowFocused(_GLFWwindow* window);
|
int _glfwPlatformWindowFocused(_GLFWwindow* window);
|
||||||
|
|||||||
5
glfw/null_window.c
vendored
5
glfw/null_window.c
vendored
@@ -200,6 +200,11 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int _glfwPlatformWindowBell(_GLFWwindow* window, int64_t param)
|
||||||
|
{
|
||||||
|
return GLFW_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
void _glfwPlatformUnhideWindow(_GLFWwindow* window)
|
void _glfwPlatformUnhideWindow(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
5
glfw/win32_window.c
vendored
5
glfw/win32_window.c
vendored
@@ -1456,6 +1456,11 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)
|
|||||||
FlashWindow(window->win32.handle, TRUE);
|
FlashWindow(window->win32.handle, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int _glfwPlatformWindowBell(_GLFWwindow* window, int64_t param)
|
||||||
|
{
|
||||||
|
return MessageBeep(0xFFFFFFFF & param) ? GLFW_TRUE : GLFW_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
void _glfwPlatformFocusWindow(_GLFWwindow* window)
|
void _glfwPlatformFocusWindow(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
BringWindowToTop(window->win32.handle);
|
BringWindowToTop(window->win32.handle);
|
||||||
|
|||||||
10
glfw/window.c
vendored
10
glfw/window.c
vendored
@@ -731,6 +731,16 @@ GLFWAPI void glfwRequestWindowAttention(GLFWwindow* handle)
|
|||||||
_glfwPlatformRequestWindowAttention(window);
|
_glfwPlatformRequestWindowAttention(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GLFWAPI int glfwWindowBell(GLFWwindow* handle, int64_t param)
|
||||||
|
{
|
||||||
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
|
assert(window != NULL);
|
||||||
|
|
||||||
|
_GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE);
|
||||||
|
|
||||||
|
return _glfwPlatformWindowBell(window, param);
|
||||||
|
}
|
||||||
|
|
||||||
GLFWAPI void glfwHideWindow(GLFWwindow* handle)
|
GLFWAPI void glfwHideWindow(GLFWwindow* handle)
|
||||||
{
|
{
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
|
|||||||
8
glfw/wl_window.c
vendored
8
glfw/wl_window.c
vendored
@@ -618,6 +618,14 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)
|
|||||||
"Wayland: Window attention request not implemented yet");
|
"Wayland: Window attention request not implemented yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int _glfwPlatformWindowBell(_GLFWwindow* window, int64_t param)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
|
"Wayland: Window bell request not implemented yet");
|
||||||
|
return GLFW_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
void _glfwPlatformFocusWindow(_GLFWwindow* window)
|
void _glfwPlatformFocusWindow(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
|
|||||||
5
glfw/x11_window.c
vendored
5
glfw/x11_window.c
vendored
@@ -2357,6 +2357,11 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window)
|
|||||||
0, 1, 0);
|
0, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int _glfwPlatformWindowBell(_GLFWwindow* window, int64_t param)
|
||||||
|
{
|
||||||
|
return XkbBell(_glfw.x11.display, window->x11.handle, (int)param, (Atom)0) ? GLFW_TRUE : GLFW_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
void _glfwPlatformFocusWindow(_GLFWwindow* window)
|
void _glfwPlatformFocusWindow(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
if (_glfw.x11.NET_ACTIVE_WINDOW)
|
if (_glfw.x11.NET_ACTIVE_WINDOW)
|
||||||
|
|||||||
@@ -152,11 +152,6 @@ cocoa_make_window_resizable(void *w) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
cocoa_audio_bell(void) {
|
|
||||||
NSBeep();
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject*
|
PyObject*
|
||||||
cocoa_get_lang(PyObject UNUSED *self) {
|
cocoa_get_lang(PyObject UNUSED *self) {
|
||||||
NSString* locale = nil;
|
NSString* locale = nil;
|
||||||
|
|||||||
3
kitty/glfw-wrapper.c
generated
3
kitty/glfw-wrapper.c
generated
@@ -152,6 +152,9 @@ load_glfw(const char* path) {
|
|||||||
*(void **) (&glfwRequestWindowAttention_impl) = dlsym(handle, "glfwRequestWindowAttention");
|
*(void **) (&glfwRequestWindowAttention_impl) = dlsym(handle, "glfwRequestWindowAttention");
|
||||||
if (glfwRequestWindowAttention_impl == NULL) fail("Failed to load glfw function glfwRequestWindowAttention with error: %s", dlerror());
|
if (glfwRequestWindowAttention_impl == NULL) fail("Failed to load glfw function glfwRequestWindowAttention with error: %s", dlerror());
|
||||||
|
|
||||||
|
*(void **) (&glfwWindowBell_impl) = dlsym(handle, "glfwWindowBell");
|
||||||
|
if (glfwWindowBell_impl == NULL) fail("Failed to load glfw function glfwWindowBell with error: %s", dlerror());
|
||||||
|
|
||||||
*(void **) (&glfwGetWindowMonitor_impl) = dlsym(handle, "glfwGetWindowMonitor");
|
*(void **) (&glfwGetWindowMonitor_impl) = dlsym(handle, "glfwGetWindowMonitor");
|
||||||
if (glfwGetWindowMonitor_impl == NULL) fail("Failed to load glfw function glfwGetWindowMonitor with error: %s", dlerror());
|
if (glfwGetWindowMonitor_impl == NULL) fail("Failed to load glfw function glfwGetWindowMonitor with error: %s", dlerror());
|
||||||
|
|
||||||
|
|||||||
4
kitty/glfw-wrapper.h
generated
4
kitty/glfw-wrapper.h
generated
@@ -1531,6 +1531,10 @@ typedef void (*glfwRequestWindowAttention_func)(GLFWwindow*);
|
|||||||
glfwRequestWindowAttention_func glfwRequestWindowAttention_impl;
|
glfwRequestWindowAttention_func glfwRequestWindowAttention_impl;
|
||||||
#define glfwRequestWindowAttention glfwRequestWindowAttention_impl
|
#define glfwRequestWindowAttention glfwRequestWindowAttention_impl
|
||||||
|
|
||||||
|
typedef int (*glfwWindowBell_func)(GLFWwindow*, int64_t);
|
||||||
|
glfwWindowBell_func glfwWindowBell_impl;
|
||||||
|
#define glfwWindowBell glfwWindowBell_impl
|
||||||
|
|
||||||
typedef GLFWmonitor* (*glfwGetWindowMonitor_func)(GLFWwindow*);
|
typedef GLFWmonitor* (*glfwGetWindowMonitor_func)(GLFWwindow*);
|
||||||
glfwGetWindowMonitor_func glfwGetWindowMonitor_impl;
|
glfwGetWindowMonitor_func glfwGetWindowMonitor_impl;
|
||||||
#define glfwGetWindowMonitor glfwGetWindowMonitor_impl
|
#define glfwGetWindowMonitor glfwGetWindowMonitor_impl
|
||||||
|
|||||||
43
kitty/glfw.c
43
kitty/glfw.c
@@ -10,7 +10,6 @@
|
|||||||
#include "glfw-wrapper.h"
|
#include "glfw-wrapper.h"
|
||||||
extern bool cocoa_make_window_resizable(void *w);
|
extern bool cocoa_make_window_resizable(void *w);
|
||||||
extern void cocoa_create_global_menu(void);
|
extern void cocoa_create_global_menu(void);
|
||||||
extern void cocoa_audio_bell(void);
|
|
||||||
|
|
||||||
#if GLFW_KEY_LAST >= MAX_KEY_COUNT
|
#if GLFW_KEY_LAST >= MAX_KEY_COUNT
|
||||||
#error "glfw has too many keys, you should increase MAX_KEY_COUNT"
|
#error "glfw has too many keys, you should increase MAX_KEY_COUNT"
|
||||||
@@ -33,23 +32,6 @@ update_os_window_viewport(OSWindow *window, bool notify_boss) {
|
|||||||
window->last_resize_at = monotonic();
|
window->last_resize_at = monotonic();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void*
|
|
||||||
load_libX11(bool unload) {
|
|
||||||
static void* ans = NULL;
|
|
||||||
static bool tried = false;
|
|
||||||
if (unload) { if (ans) { dlclose(ans); ans = NULL; }; return NULL; }
|
|
||||||
if (!tried) {
|
|
||||||
tried = true;
|
|
||||||
ans = dlopen("libX11.so", RTLD_LAZY);
|
|
||||||
if (ans == NULL) fprintf(stderr, "Failed to load libX11.so with error: %s\n", dlerror());
|
|
||||||
}
|
|
||||||
return ans;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef bool (*xkb_bell_func)(void*, int32_t, int, void*);
|
|
||||||
xkb_bell_func xkb_bell = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// callbacks {{{
|
// callbacks {{{
|
||||||
|
|
||||||
@@ -346,7 +328,6 @@ glfw_init(PyObject UNUSED *self, PyObject *args) {
|
|||||||
PyObject*
|
PyObject*
|
||||||
glfw_terminate(PyObject UNUSED *self) {
|
glfw_terminate(PyObject UNUSED *self) {
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
load_libX11(true);
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -494,29 +475,9 @@ ring_audio_bell(OSWindow *w) {
|
|||||||
double now = monotonic();
|
double now = monotonic();
|
||||||
if (now - last_bell_at <= 0.1) return;
|
if (now - last_bell_at <= 0.1) return;
|
||||||
last_bell_at = now;
|
last_bell_at = now;
|
||||||
#ifdef __APPLE__
|
if (w->handle) {
|
||||||
(void)w;
|
glfwWindowBell(w->handle, OPT(x11_bell_volume));
|
||||||
cocoa_audio_bell();
|
|
||||||
#else
|
|
||||||
if (glfwGetX11Display) {
|
|
||||||
static bool tried = false;
|
|
||||||
if (!tried) {
|
|
||||||
tried = true;
|
|
||||||
void *lib = load_libX11(false);
|
|
||||||
if (lib) {
|
|
||||||
*(void **) (&xkb_bell) = dlsym(lib, "XkbBell");
|
|
||||||
if (!xkb_bell) fprintf(stderr, "Failed to load the XkbBell function with error: %s\n", dlerror());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (xkb_bell) {
|
|
||||||
void* display = glfwGetX11Display();
|
|
||||||
int32_t x11win = glfwGetX11Window(w->handle);
|
|
||||||
if (display) {
|
|
||||||
xkb_bell(display, x11win, OPT(x11_bell_volume), NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user