Wayland: Abort on fatal error should bypass quit confirmation

This commit is contained in:
Kovid Goyal 2020-06-03 14:39:27 +05:30
parent aaf64ad63e
commit 03b1484c96
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
10 changed files with 75 additions and 31 deletions

View File

@ -424,7 +424,7 @@ display_reconfigured(CGDirectDisplayID display UNUSED, CGDisplayChangeSummaryFla
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{ {
(void)sender; (void)sender;
if (_glfw.ns.quitRequestedCallback) _glfw.ns.quitRequestedCallback(); if (_glfw.callbacks.application_close) _glfw.callbacks.application_close(0);
return NSTerminateCancel; return NSTerminateCancel;
} }
@ -585,12 +585,6 @@ GLFWAPI GLFWapplicationwillfinishlaunchingfun glfwSetApplicationWillFinishLaunch
return previous; return previous;
} }
GLFWAPI GLFWcocoaaplicationquitrequestedfun glfwSetApplicationQuitRequestedCallback(GLFWcocoaaplicationquitrequestedfun callback) {
GLFWcocoaaplicationquitrequestedfun ret = _glfw.ns.quitRequestedCallback;
_glfw.ns.quitRequestedCallback = callback;
return ret;
}
int _glfwPlatformInit(void) int _glfwPlatformInit(void)
{ {
@autoreleasepool { @autoreleasepool {

View File

@ -69,7 +69,6 @@ typedef int (* GLFWcocoatextinputfilterfun)(int,int,unsigned int, unsigned long)
typedef bool (* GLFWapplicationshouldhandlereopenfun)(int); typedef bool (* GLFWapplicationshouldhandlereopenfun)(int);
typedef void (* GLFWapplicationwillfinishlaunchingfun)(void); typedef void (* GLFWapplicationwillfinishlaunchingfun)(void);
typedef bool (* GLFWcocoatogglefullscreenfun)(GLFWwindow*); typedef bool (* GLFWcocoatogglefullscreenfun)(GLFWwindow*);
typedef void (* GLFWcocoaaplicationquitrequestedfun)(void);
typedef void (* GLFWcocoarenderframefun)(GLFWwindow*); typedef void (* GLFWcocoarenderframefun)(GLFWwindow*);
typedef VkFlags VkMacOSSurfaceCreateFlagsMVK; typedef VkFlags VkMacOSSurfaceCreateFlagsMVK;
@ -189,8 +188,6 @@ typedef struct _GLFWlibraryNS
double restoreCursorPosX, restoreCursorPosY; double restoreCursorPosX, restoreCursorPosY;
// The window whose disabled cursor mode is active // The window whose disabled cursor mode is active
_GLFWwindow* disabledCursorWindow; _GLFWwindow* disabledCursorWindow;
// The application quit requested callback
GLFWcocoaaplicationquitrequestedfun quitRequestedCallback;
struct { struct {
CFBundleRef bundle; CFBundleRef bundle;

View File

@ -203,7 +203,6 @@ def generate_wrappers(glfw_header: str) -> None:
GLFWcocoatogglefullscreenfun glfwSetCocoaToggleFullscreenIntercept(GLFWwindow *window, GLFWcocoatogglefullscreenfun callback) GLFWcocoatogglefullscreenfun glfwSetCocoaToggleFullscreenIntercept(GLFWwindow *window, GLFWcocoatogglefullscreenfun callback)
GLFWapplicationshouldhandlereopenfun glfwSetApplicationShouldHandleReopen(GLFWapplicationshouldhandlereopenfun callback) GLFWapplicationshouldhandlereopenfun glfwSetApplicationShouldHandleReopen(GLFWapplicationshouldhandlereopenfun callback)
GLFWapplicationwillfinishlaunchingfun glfwSetApplicationWillFinishLaunching(GLFWapplicationwillfinishlaunchingfun callback) GLFWapplicationwillfinishlaunchingfun glfwSetApplicationWillFinishLaunching(GLFWapplicationwillfinishlaunchingfun callback)
GLFWcocoaaplicationquitrequestedfun glfwSetApplicationQuitRequestedCallback(GLFWcocoaaplicationquitrequestedfun callback)
void glfwGetCocoaKeyEquivalent(int glfw_key, int glfw_mods, char* cocoa_key, size_t key_sz, int* cocoa_mods) void glfwGetCocoaKeyEquivalent(int glfw_key, int glfw_mods, char* cocoa_key, size_t key_sz, int* cocoa_mods)
void glfwCocoaRequestRenderFrame(GLFWwindow *w, GLFWcocoarenderframefun callback) void glfwCocoaRequestRenderFrame(GLFWwindow *w, GLFWcocoarenderframefun callback)
void* glfwGetX11Display(void) void* glfwGetX11Display(void)
@ -244,7 +243,6 @@ typedef int (* GLFWcocoatextinputfilterfun)(int,int,unsigned int,unsigned long);
typedef bool (* GLFWapplicationshouldhandlereopenfun)(int); typedef bool (* GLFWapplicationshouldhandlereopenfun)(int);
typedef void (* GLFWapplicationwillfinishlaunchingfun)(void); typedef void (* GLFWapplicationwillfinishlaunchingfun)(void);
typedef bool (* GLFWcocoatogglefullscreenfun)(GLFWwindow*); typedef bool (* GLFWcocoatogglefullscreenfun)(GLFWwindow*);
typedef void (* GLFWcocoaaplicationquitrequestedfun)(void);
typedef void (* GLFWcocoarenderframefun)(GLFWwindow*); typedef void (* GLFWcocoarenderframefun)(GLFWwindow*);
typedef void (*GLFWwaylandframecallbackfunc)(unsigned long long id); typedef void (*GLFWwaylandframecallbackfunc)(unsigned long long id);
typedef void (*GLFWDBusnotificationcreatedfun)(unsigned long long, uint32_t, void*); typedef void (*GLFWDBusnotificationcreatedfun)(unsigned long long, uint32_t, void*);

17
glfw/glfw3.h vendored
View File

@ -1320,6 +1320,22 @@ typedef void (* GLFWwindowsizefun)(GLFWwindow*,int,int);
*/ */
typedef void (* GLFWwindowclosefun)(GLFWwindow*); typedef void (* GLFWwindowclosefun)(GLFWwindow*);
/*! @brief The function pointer type for application close callbacks.
*
* This is the function pointer type for application close callbacks. A application
* close callback function has the following signature:
* @code
* void function_name(int flags)
* @endcode
*
* @param[in] flags 0 for a user requested application quit, 1 if a fatal error occurred and application should quit ASAP
*
* @sa @ref glfwSetApplicationCloseCallback
*
* @ingroup window
*/
typedef void (* GLFWapplicationclosefun)(int);
/*! @brief The function pointer type for window content refresh callbacks. /*! @brief The function pointer type for window content refresh callbacks.
* *
* This is the function pointer type for window content refresh callbacks. * This is the function pointer type for window content refresh callbacks.
@ -3828,6 +3844,7 @@ GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwind
* @ingroup window * @ingroup window
*/ */
GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* window, GLFWwindowclosefun callback); GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* window, GLFWwindowclosefun callback);
GLFWAPI GLFWapplicationclosefun glfwSetApplicationCloseCallback(GLFWapplicationclosefun callback);
/*! @brief Sets the refresh callback for the specified window. /*! @brief Sets the refresh callback for the specified window.
* *

7
glfw/init.c vendored
View File

@ -363,3 +363,10 @@ GLFWAPI void glfwUpdateTimer(unsigned long long timer_id, monotonic_t interval,
GLFWAPI void glfwRemoveTimer(unsigned long long timer_id) { GLFWAPI void glfwRemoveTimer(unsigned long long timer_id) {
_glfwPlatformRemoveTimer(timer_id); _glfwPlatformRemoveTimer(timer_id);
} }
GLFWAPI GLFWapplicationclosefun glfwSetApplicationCloseCallback(GLFWapplicationclosefun cbfun)
{
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(_glfw.callbacks.application_close, cbfun);
return cbfun;
}

2
glfw/internal.h vendored
View File

@ -602,8 +602,10 @@ struct _GLFWlibrary
struct { struct {
GLFWmonitorfun monitor; GLFWmonitorfun monitor;
GLFWjoystickfun joystick; GLFWjoystickfun joystick;
GLFWapplicationclosefun application_close;
} callbacks; } callbacks;
// This is defined in the window API's platform.h // This is defined in the window API's platform.h
_GLFW_PLATFORM_LIBRARY_WINDOW_STATE; _GLFW_PLATFORM_LIBRARY_WINDOW_STATE;
// This is defined in the context API's context.h // This is defined in the context API's context.h

13
glfw/wl_window.c vendored
View File

@ -760,11 +760,14 @@ animateCursorImage(id_type timer_id UNUSED, void *data UNUSED) {
static void static void
abortOnFatalError(int last_error) { abortOnFatalError(int last_error) {
_glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: fatal display error: %s", strerror(last_error)); _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: fatal display error: %s", strerror(last_error));
_GLFWwindow* window = _glfw.windowListHead; if (_glfw.callbacks.application_close) _glfw.callbacks.application_close(1);
while (window) else {
{ _GLFWwindow* window = _glfw.windowListHead;
_glfwInputWindowCloseRequest(window); while (window)
window = window->next; {
_glfwInputWindowCloseRequest(window);
window = window->next;
}
} }
// ensure the tick callback is called // ensure the tick callback is called
_glfw.wl.eventLoopData.wakeup_data_read = true; _glfw.wl.eventLoopData.wakeup_data_read = true;

8
kitty/glfw-wrapper.c generated
View File

@ -216,6 +216,9 @@ load_glfw(const char* path) {
*(void **) (&glfwSetWindowCloseCallback_impl) = dlsym(handle, "glfwSetWindowCloseCallback"); *(void **) (&glfwSetWindowCloseCallback_impl) = dlsym(handle, "glfwSetWindowCloseCallback");
if (glfwSetWindowCloseCallback_impl == NULL) fail("Failed to load glfw function glfwSetWindowCloseCallback with error: %s", dlerror()); if (glfwSetWindowCloseCallback_impl == NULL) fail("Failed to load glfw function glfwSetWindowCloseCallback with error: %s", dlerror());
*(void **) (&glfwSetApplicationCloseCallback_impl) = dlsym(handle, "glfwSetApplicationCloseCallback");
if (glfwSetApplicationCloseCallback_impl == NULL) fail("Failed to load glfw function glfwSetApplicationCloseCallback with error: %s", dlerror());
*(void **) (&glfwSetWindowRefreshCallback_impl) = dlsym(handle, "glfwSetWindowRefreshCallback"); *(void **) (&glfwSetWindowRefreshCallback_impl) = dlsym(handle, "glfwSetWindowRefreshCallback");
if (glfwSetWindowRefreshCallback_impl == NULL) fail("Failed to load glfw function glfwSetWindowRefreshCallback with error: %s", dlerror()); if (glfwSetWindowRefreshCallback_impl == NULL) fail("Failed to load glfw function glfwSetWindowRefreshCallback with error: %s", dlerror());
@ -246,6 +249,9 @@ load_glfw(const char* path) {
*(void **) (&glfwSetInputMode_impl) = dlsym(handle, "glfwSetInputMode"); *(void **) (&glfwSetInputMode_impl) = dlsym(handle, "glfwSetInputMode");
if (glfwSetInputMode_impl == NULL) fail("Failed to load glfw function glfwSetInputMode with error: %s", dlerror()); if (glfwSetInputMode_impl == NULL) fail("Failed to load glfw function glfwSetInputMode with error: %s", dlerror());
*(void **) (&glfwRawMouseMotionSupported_impl) = dlsym(handle, "glfwRawMouseMotionSupported");
if (glfwRawMouseMotionSupported_impl == NULL) fail("Failed to load glfw function glfwRawMouseMotionSupported with error: %s", dlerror());
*(void **) (&glfwGetKeyName_impl) = dlsym(handle, "glfwGetKeyName"); *(void **) (&glfwGetKeyName_impl) = dlsym(handle, "glfwGetKeyName");
if (glfwGetKeyName_impl == NULL) fail("Failed to load glfw function glfwGetKeyName with error: %s", dlerror()); if (glfwGetKeyName_impl == NULL) fail("Failed to load glfw function glfwGetKeyName with error: %s", dlerror());
@ -386,8 +392,6 @@ load_glfw(const char* path) {
*(void **) (&glfwSetApplicationWillFinishLaunching_impl) = dlsym(handle, "glfwSetApplicationWillFinishLaunching"); *(void **) (&glfwSetApplicationWillFinishLaunching_impl) = dlsym(handle, "glfwSetApplicationWillFinishLaunching");
*(void **) (&glfwSetApplicationQuitRequestedCallback_impl) = dlsym(handle, "glfwSetApplicationQuitRequestedCallback");
*(void **) (&glfwGetCocoaKeyEquivalent_impl) = dlsym(handle, "glfwGetCocoaKeyEquivalent"); *(void **) (&glfwGetCocoaKeyEquivalent_impl) = dlsym(handle, "glfwGetCocoaKeyEquivalent");
*(void **) (&glfwCocoaRequestRenderFrame_impl) = dlsym(handle, "glfwCocoaRequestRenderFrame"); *(void **) (&glfwCocoaRequestRenderFrame_impl) = dlsym(handle, "glfwCocoaRequestRenderFrame");

29
kitty/glfw-wrapper.h generated
View File

@ -1083,6 +1083,22 @@ typedef void (* GLFWwindowsizefun)(GLFWwindow*,int,int);
*/ */
typedef void (* GLFWwindowclosefun)(GLFWwindow*); typedef void (* GLFWwindowclosefun)(GLFWwindow*);
/*! @brief The function pointer type for application close callbacks.
*
* This is the function pointer type for application close callbacks. A application
* close callback function has the following signature:
* @code
* void function_name(int flags)
* @endcode
*
* @param[in] flags 0 for a user requested application quit, 1 if a fatal error occurred and application should quit ASAP
*
* @sa @ref glfwSetApplicationCloseCallback
*
* @ingroup window
*/
typedef void (* GLFWapplicationclosefun)(int);
/*! @brief The function pointer type for window content refresh callbacks. /*! @brief The function pointer type for window content refresh callbacks.
* *
* This is the function pointer type for window content refresh callbacks. * This is the function pointer type for window content refresh callbacks.
@ -1587,7 +1603,6 @@ typedef int (* GLFWcocoatextinputfilterfun)(int,int,unsigned int,unsigned long);
typedef bool (* GLFWapplicationshouldhandlereopenfun)(int); typedef bool (* GLFWapplicationshouldhandlereopenfun)(int);
typedef void (* GLFWapplicationwillfinishlaunchingfun)(void); typedef void (* GLFWapplicationwillfinishlaunchingfun)(void);
typedef bool (* GLFWcocoatogglefullscreenfun)(GLFWwindow*); typedef bool (* GLFWcocoatogglefullscreenfun)(GLFWwindow*);
typedef void (* GLFWcocoaaplicationquitrequestedfun)(void);
typedef void (* GLFWcocoarenderframefun)(GLFWwindow*); typedef void (* GLFWcocoarenderframefun)(GLFWwindow*);
typedef void (*GLFWwaylandframecallbackfunc)(unsigned long long id); typedef void (*GLFWwaylandframecallbackfunc)(unsigned long long id);
typedef void (*GLFWDBusnotificationcreatedfun)(unsigned long long, uint32_t, void*); typedef void (*GLFWDBusnotificationcreatedfun)(unsigned long long, uint32_t, void*);
@ -1860,6 +1875,10 @@ typedef GLFWwindowclosefun (*glfwSetWindowCloseCallback_func)(GLFWwindow*, GLFWw
GFW_EXTERN glfwSetWindowCloseCallback_func glfwSetWindowCloseCallback_impl; GFW_EXTERN glfwSetWindowCloseCallback_func glfwSetWindowCloseCallback_impl;
#define glfwSetWindowCloseCallback glfwSetWindowCloseCallback_impl #define glfwSetWindowCloseCallback glfwSetWindowCloseCallback_impl
typedef GLFWapplicationclosefun (*glfwSetApplicationCloseCallback_func)(GLFWapplicationclosefun);
GFW_EXTERN glfwSetApplicationCloseCallback_func glfwSetApplicationCloseCallback_impl;
#define glfwSetApplicationCloseCallback glfwSetApplicationCloseCallback_impl
typedef GLFWwindowrefreshfun (*glfwSetWindowRefreshCallback_func)(GLFWwindow*, GLFWwindowrefreshfun); typedef GLFWwindowrefreshfun (*glfwSetWindowRefreshCallback_func)(GLFWwindow*, GLFWwindowrefreshfun);
GFW_EXTERN glfwSetWindowRefreshCallback_func glfwSetWindowRefreshCallback_impl; GFW_EXTERN glfwSetWindowRefreshCallback_func glfwSetWindowRefreshCallback_impl;
#define glfwSetWindowRefreshCallback glfwSetWindowRefreshCallback_impl #define glfwSetWindowRefreshCallback glfwSetWindowRefreshCallback_impl
@ -1900,6 +1919,10 @@ typedef void (*glfwSetInputMode_func)(GLFWwindow*, int, int);
GFW_EXTERN glfwSetInputMode_func glfwSetInputMode_impl; GFW_EXTERN glfwSetInputMode_func glfwSetInputMode_impl;
#define glfwSetInputMode glfwSetInputMode_impl #define glfwSetInputMode glfwSetInputMode_impl
typedef int (*glfwRawMouseMotionSupported_func)(void);
GFW_EXTERN glfwRawMouseMotionSupported_func glfwRawMouseMotionSupported_impl;
#define glfwRawMouseMotionSupported glfwRawMouseMotionSupported_impl
typedef const char* (*glfwGetKeyName_func)(int, int); typedef const char* (*glfwGetKeyName_func)(int, int);
GFW_EXTERN glfwGetKeyName_func glfwGetKeyName_impl; GFW_EXTERN glfwGetKeyName_func glfwGetKeyName_impl;
#define glfwGetKeyName glfwGetKeyName_impl #define glfwGetKeyName glfwGetKeyName_impl
@ -2096,10 +2119,6 @@ typedef GLFWapplicationwillfinishlaunchingfun (*glfwSetApplicationWillFinishLaun
GFW_EXTERN glfwSetApplicationWillFinishLaunching_func glfwSetApplicationWillFinishLaunching_impl; GFW_EXTERN glfwSetApplicationWillFinishLaunching_func glfwSetApplicationWillFinishLaunching_impl;
#define glfwSetApplicationWillFinishLaunching glfwSetApplicationWillFinishLaunching_impl #define glfwSetApplicationWillFinishLaunching glfwSetApplicationWillFinishLaunching_impl
typedef GLFWcocoaaplicationquitrequestedfun (*glfwSetApplicationQuitRequestedCallback_func)(GLFWcocoaaplicationquitrequestedfun);
GFW_EXTERN glfwSetApplicationQuitRequestedCallback_func glfwSetApplicationQuitRequestedCallback_impl;
#define glfwSetApplicationQuitRequestedCallback glfwSetApplicationQuitRequestedCallback_impl
typedef void (*glfwGetCocoaKeyEquivalent_func)(int, int, char*, size_t, int*); typedef void (*glfwGetCocoaKeyEquivalent_func)(int, int, char*, size_t, int*);
GFW_EXTERN glfwGetCocoaKeyEquivalent_func glfwGetCocoaKeyEquivalent_impl; GFW_EXTERN glfwGetCocoaKeyEquivalent_func glfwGetCocoaKeyEquivalent_impl;
#define glfwGetCocoaKeyEquivalent glfwGetCocoaKeyEquivalent_impl #define glfwGetCocoaKeyEquivalent glfwGetCocoaKeyEquivalent_impl

View File

@ -332,16 +332,19 @@ drop_callback(GLFWwindow *w, const char *mime, const char *data, size_t sz) {
#undef RETURN #undef RETURN
} }
#ifdef __APPLE__
static void static void
application_quit_requested_callback(void) { application_close_requested_callback(int flags) {
if (global_state.quit_request == NO_CLOSE_REQUESTED) { if (flags) {
global_state.has_pending_closes = true; global_state.quit_request = IMPERATIVE_CLOSE_REQUESTED;
global_state.quit_request = CONFIRMABLE_CLOSE_REQUESTED;
request_tick_callback(); request_tick_callback();
} else {
if (global_state.quit_request == NO_CLOSE_REQUESTED) {
global_state.has_pending_closes = true;
global_state.quit_request = CONFIRMABLE_CLOSE_REQUESTED;
request_tick_callback();
}
} }
} }
#endif
// }}} // }}}
void void
@ -523,12 +526,12 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
glfwWindowHint(GLFW_DEPTH_BITS, 0); glfwWindowHint(GLFW_DEPTH_BITS, 0);
glfwWindowHint(GLFW_STENCIL_BITS, 0); glfwWindowHint(GLFW_STENCIL_BITS, 0);
if (OPT(hide_window_decorations) & 1) glfwWindowHint(GLFW_DECORATED, false); if (OPT(hide_window_decorations) & 1) glfwWindowHint(GLFW_DECORATED, false);
glfwSetApplicationCloseCallback(application_close_requested_callback);
#ifdef __APPLE__ #ifdef __APPLE__
cocoa_set_activation_policy(OPT(macos_hide_from_tasks)); cocoa_set_activation_policy(OPT(macos_hide_from_tasks));
glfwWindowHint(GLFW_COCOA_GRAPHICS_SWITCHING, true); glfwWindowHint(GLFW_COCOA_GRAPHICS_SWITCHING, true);
glfwSetApplicationShouldHandleReopen(on_application_reopen); glfwSetApplicationShouldHandleReopen(on_application_reopen);
glfwSetApplicationWillFinishLaunching(cocoa_create_global_menu); glfwSetApplicationWillFinishLaunching(cocoa_create_global_menu);
glfwSetApplicationQuitRequestedCallback(application_quit_requested_callback);
#endif #endif
} }