From d0f839bbd8d0727fcfef6a356a9a18e2a3182a0a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 27 Mar 2018 19:45:19 +0530 Subject: [PATCH] Fix audible bell not working under Wayland --- CHANGELOG.rst | 2 ++ glfw/cocoa_window.m | 3 +-- glfw/glfw3.h | 9 ++------- glfw/internal.h | 3 +-- glfw/null_window.c | 3 +-- glfw/win32_window.c | 5 ++--- glfw/window.c | 5 ++--- glfw/wl_window.c | 13 ++++++++----- glfw/x11_window.c | 5 ++--- kitty/config.py | 1 - kitty/glfw-wrapper.h | 2 +- kitty/glfw.c | 2 +- kitty/kitty.conf | 4 ---- kitty/state.c | 1 - kitty/state.h | 1 - 15 files changed, 23 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d764c7857..3ddbdc8e1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -25,6 +25,8 @@ version 0.8.3 [future] - Add a --debug-config command line flag to output data about the system and kitty configuration. +- Fix audible bell not working under Wayland + version 0.8.2 [2018-03-17] ----------------------------- diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index cbeffd12a..d6c6f9265 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -1361,7 +1361,7 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window) [NSApp requestUserAttention:NSInformationalRequest]; } -int _glfwPlatformWindowBell(_GLFWwindow* window, int64_t param) +int _glfwPlatformWindowBell(_GLFWwindow* window) { NSBeep(); return GLFW_TRUE; @@ -1906,4 +1906,3 @@ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* handle) _GLFW_REQUIRE_INIT_OR_RETURN(nil); return window->ns.object; } - diff --git a/glfw/glfw3.h b/glfw/glfw3.h index 224c3e606..9361ea92d 100644 --- a/glfw/glfw3.h +++ b/glfw/glfw3.h @@ -3188,13 +3188,9 @@ 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). + * supported. Currently (macOS, Windows, X11 and Wayland). * * @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 @@ -3209,7 +3205,7 @@ GLFWAPI void glfwRequestWindowAttention(GLFWwindow* window); * * @ingroup window */ -GLFWAPI int glfwWindowBell(GLFWwindow* window, int64_t param); +GLFWAPI int glfwWindowBell(GLFWwindow* window); /*! @brief Returns the monitor that the window uses for full screen mode. @@ -5546,4 +5542,3 @@ GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window #endif #endif /* _glfw3_h_ */ - diff --git a/glfw/internal.h b/glfw/internal.h index 529a77f92..fb6317458 100644 --- a/glfw/internal.h +++ b/glfw/internal.h @@ -653,7 +653,7 @@ void _glfwPlatformMaximizeWindow(_GLFWwindow* window); void _glfwPlatformShowWindow(_GLFWwindow* window); void _glfwPlatformHideWindow(_GLFWwindow* window); void _glfwPlatformRequestWindowAttention(_GLFWwindow* window); -int _glfwPlatformWindowBell(_GLFWwindow* window, int64_t); +int _glfwPlatformWindowBell(_GLFWwindow* window); void _glfwPlatformFocusWindow(_GLFWwindow* window); void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, @@ -769,4 +769,3 @@ void _glfwTerminateVulkan(void); const char* _glfwGetVulkanResultString(VkResult result); char* _glfw_strdup(const char* source); - diff --git a/glfw/null_window.c b/glfw/null_window.c index 9da15b1ad..0e380c58d 100644 --- a/glfw/null_window.c +++ b/glfw/null_window.c @@ -205,7 +205,7 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window) { } -int _glfwPlatformWindowBell(_GLFWwindow* window, int64_t param) +int _glfwPlatformWindowBell(_GLFWwindow* window) { return GLFW_FALSE; } @@ -323,4 +323,3 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, // This seems like the most appropriate error to return here return VK_ERROR_INITIALIZATION_FAILED; } - diff --git a/glfw/win32_window.c b/glfw/win32_window.c index 653a33cfa..9dfe94ff6 100644 --- a/glfw/win32_window.c +++ b/glfw/win32_window.c @@ -1474,9 +1474,9 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window) FlashWindow(window->win32.handle, TRUE); } -int _glfwPlatformWindowBell(_GLFWwindow* window, int64_t param) +int _glfwPlatformWindowBell(_GLFWwindow* window) { - return MessageBeep(0xFFFFFFFF & param) ? GLFW_TRUE : GLFW_FALSE; + return MessageBeep(0xFFFFFFFF) ? GLFW_TRUE : GLFW_FALSE; } void _glfwPlatformFocusWindow(_GLFWwindow* window) @@ -2014,4 +2014,3 @@ GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle) _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return window->win32.handle; } - diff --git a/glfw/window.c b/glfw/window.c index 01b6cebf5..6be617433 100644 --- a/glfw/window.c +++ b/glfw/window.c @@ -768,14 +768,14 @@ GLFWAPI void glfwRequestWindowAttention(GLFWwindow* handle) _glfwPlatformRequestWindowAttention(window); } -GLFWAPI int glfwWindowBell(GLFWwindow* handle, int64_t param) +GLFWAPI int glfwWindowBell(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); - return _glfwPlatformWindowBell(window, param); + return _glfwPlatformWindowBell(window); } GLFWAPI void glfwHideWindow(GLFWwindow* handle) @@ -1106,4 +1106,3 @@ GLFWAPI void glfwPostEmptyEvent(void) _glfwPlatformPostEmptyEvent(); } - diff --git a/glfw/wl_window.c b/glfw/wl_window.c index 02ef04900..8201560c5 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -1079,11 +1079,15 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window) "Wayland: Window attention request not implemented yet"); } -int _glfwPlatformWindowBell(_GLFWwindow* window, int64_t param) +int _glfwPlatformWindowBell(_GLFWwindow* window) { - // TODO - _glfwInputError(GLFW_PLATFORM_ERROR, - "Wayland: Window bell request not implemented yet"); + // 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; } @@ -1547,4 +1551,3 @@ GLFWAPI struct wl_surface* glfwGetWaylandWindow(GLFWwindow* handle) _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return window->wl.surface; } - diff --git a/glfw/x11_window.c b/glfw/x11_window.c index 3977684cd..0186db8a7 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -2340,9 +2340,9 @@ void _glfwPlatformRequestWindowAttention(_GLFWwindow* window) 0, 1, 0); } -int _glfwPlatformWindowBell(_GLFWwindow* window, int64_t param) +int _glfwPlatformWindowBell(_GLFWwindow* window) { - return XkbBell(_glfw.x11.display, window->x11.handle, (int)param, (Atom)0) ? GLFW_TRUE : GLFW_FALSE; + return XkbBell(_glfw.x11.display, window->x11.handle, 100, (Atom)0) ? GLFW_TRUE : GLFW_FALSE; } void _glfwPlatformFocusWindow(_GLFWwindow* window) @@ -3044,4 +3044,3 @@ GLFWAPI const char* glfwGetX11SelectionString(void) _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return getSelectionString(_glfw.x11.PRIMARY); } - diff --git a/kitty/config.py b/kitty/config.py index 69218663f..21a7c4966 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -293,7 +293,6 @@ type_map = { 'macos_option_as_alt': to_bool, 'macos_titlebar_color': macos_titlebar_color, 'box_drawing_scale': box_drawing_scale, - 'x11_bell_volume': int, 'background_opacity': unit_float, 'tab_separator': tab_separator, 'active_tab_font_style': tab_font_style, diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index cf1c39e19..29271c490 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -1585,7 +1585,7 @@ typedef void (*glfwRequestWindowAttention_func)(GLFWwindow*); glfwRequestWindowAttention_func glfwRequestWindowAttention_impl; #define glfwRequestWindowAttention glfwRequestWindowAttention_impl -typedef int (*glfwWindowBell_func)(GLFWwindow*, int64_t); +typedef int (*glfwWindowBell_func)(GLFWwindow*); glfwWindowBell_func glfwWindowBell_impl; #define glfwWindowBell glfwWindowBell_impl diff --git a/kitty/glfw.c b/kitty/glfw.c index 132e855b4..47cf1777c 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -604,7 +604,7 @@ ring_audio_bell(OSWindow *w) { if (now - last_bell_at <= 0.1) return; last_bell_at = now; if (w->handle) { - glfwWindowBell(w->handle, OPT(x11_bell_volume)); + glfwWindowBell(w->handle); } } diff --git a/kitty/kitty.conf b/kitty/kitty.conf index 4251c4a0c..d94d8feda 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -463,8 +463,4 @@ macos_hide_titlebar no # break any Alt+key keyboard shortcuts in your terminal programs, but you # can use the macOS unicode input technique. macos_option_as_alt yes - -# The number is a percentage of maximum volume. -# See man XBell for details. -x11_bell_volume 80 # }}} diff --git a/kitty/state.c b/kitty/state.c index 420b188ff..198750967 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -340,7 +340,6 @@ PYWRAP1(set_options) { S(inactive_text_alpha, PyFloat_AsDouble); S(cursor_shape, PyLong_AsLong); S(url_style, PyLong_AsUnsignedLong); - S(x11_bell_volume, PyLong_AsLong); S(tab_bar_edge, PyLong_AsLong); S(mouse_hide_wait, PyFloat_AsDouble); S(wheel_scroll_multiplier, PyFloat_AsDouble); diff --git a/kitty/state.h b/kitty/state.h index 79e7352ac..41d6e6494 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -26,7 +26,6 @@ typedef struct { bool macos_option_as_alt, macos_hide_titlebar; int adjust_line_height_px, adjust_column_width_px; float adjust_line_height_frac, adjust_column_width_frac; - int x11_bell_volume; float background_opacity; float inactive_text_alpha; Edge tab_bar_edge;