macOS: When clicking dock icon with no windows, create a new window

This commit is contained in:
Kovid Goyal 2018-06-07 07:17:37 +05:30
parent 1afa91bbb4
commit faa5443d43
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
6 changed files with 37 additions and 0 deletions

View File

@ -38,6 +38,7 @@ typedef void* id;
typedef VkFlags VkMacOSSurfaceCreateFlagsMVK; typedef VkFlags VkMacOSSurfaceCreateFlagsMVK;
typedef int (* GLFWcocoatextinputfilterfun)(int,int,int); typedef int (* GLFWcocoatextinputfilterfun)(int,int,int);
typedef int (* GLFWapplicationshouldhandlereopenfun)(int);
typedef struct VkMacOSSurfaceCreateInfoMVK typedef struct VkMacOSSurfaceCreateInfoMVK
{ {

View File

@ -482,6 +482,15 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
return NSTerminateCancel; return NSTerminateCancel;
} }
static GLFWapplicationshouldhandlereopenfun handle_reopen_callback = NULL;
- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag
{
if (!handle_reopen_callback) return YES;
if (handle_reopen_callback(flag)) return YES;
return NO;
}
- (void)applicationDidChangeScreenParameters:(NSNotification *) notification - (void)applicationDidChangeScreenParameters:(NSNotification *) notification
{ {
_GLFWwindow* window; _GLFWwindow* window;
@ -2089,6 +2098,12 @@ GLFWAPI GLFWcocoatextinputfilterfun glfwSetCocoaTextInputFilter(GLFWwindow *hand
return previous; return previous;
} }
GLFWAPI GLFWapplicationshouldhandlereopenfun glfwSetApplicationShouldHandleReopen(GLFWapplicationshouldhandlereopenfun callback) {
GLFWapplicationshouldhandlereopenfun previous = handle_reopen_callback;
handle_reopen_callback = callback;
return previous;
}
GLFWAPI void glfwGetCocoaKeyEquivalent(int glfw_key, int glfw_mods, unsigned short *cocoa_key, int *cocoa_mods) { GLFWAPI void glfwGetCocoaKeyEquivalent(int glfw_key, int glfw_mods, unsigned short *cocoa_key, int *cocoa_mods) {
*cocoa_key = 0; *cocoa_key = 0;
*cocoa_mods = 0; *cocoa_mods = 0;

View File

@ -202,6 +202,7 @@ def generate_wrappers(glfw_header, glfw_native_header):
void* glfwGetCocoaWindow(GLFWwindow* window) void* glfwGetCocoaWindow(GLFWwindow* window)
uint32_t glfwGetCocoaMonitor(GLFWmonitor* monitor) uint32_t glfwGetCocoaMonitor(GLFWmonitor* monitor)
GLFWcocoatextinputfilterfun glfwSetCocoaTextInputFilter(GLFWwindow* window, GLFWcocoatextinputfilterfun callback) GLFWcocoatextinputfilterfun glfwSetCocoaTextInputFilter(GLFWwindow* window, GLFWcocoatextinputfilterfun callback)
GLFWapplicationshouldhandlereopenfun glfwSetApplicationShouldHandleReopen(GLFWapplicationshouldhandlereopenfun callback)
void glfwGetCocoaKeyEquivalent(int glfw_key, int glfw_mods, void* cocoa_key, void* cocoa_mods) void glfwGetCocoaKeyEquivalent(int glfw_key, int glfw_mods, void* cocoa_key, void* cocoa_mods)
void* glfwGetX11Display(void) void* glfwGetX11Display(void)
int32_t glfwGetX11Window(GLFWwindow* window) int32_t glfwGetX11Window(GLFWwindow* window)
@ -220,6 +221,8 @@ def generate_wrappers(glfw_header, glfw_native_header):
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
typedef int (* GLFWcocoatextinputfilterfun)(int,int,unsigned int); typedef int (* GLFWcocoatextinputfilterfun)(int,int,unsigned int);
typedef int (* GLFWapplicationshouldhandlereopenfun)(int);
{} {}
{} {}

2
kitty/glfw-wrapper.c generated
View File

@ -359,6 +359,8 @@ load_glfw(const char* path) {
*(void **) (&glfwSetCocoaTextInputFilter_impl) = dlsym(handle, "glfwSetCocoaTextInputFilter"); *(void **) (&glfwSetCocoaTextInputFilter_impl) = dlsym(handle, "glfwSetCocoaTextInputFilter");
*(void **) (&glfwSetApplicationShouldHandleReopen_impl) = dlsym(handle, "glfwSetApplicationShouldHandleReopen");
*(void **) (&glfwGetCocoaKeyEquivalent_impl) = dlsym(handle, "glfwGetCocoaKeyEquivalent"); *(void **) (&glfwGetCocoaKeyEquivalent_impl) = dlsym(handle, "glfwGetCocoaKeyEquivalent");
*(void **) (&glfwGetX11Display_impl) = dlsym(handle, "glfwGetX11Display"); *(void **) (&glfwGetX11Display_impl) = dlsym(handle, "glfwGetX11Display");

6
kitty/glfw-wrapper.h generated
View File

@ -2,6 +2,8 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
typedef int (* GLFWcocoatextinputfilterfun)(int,int,unsigned int); typedef int (* GLFWcocoatextinputfilterfun)(int,int,unsigned int);
typedef int (* GLFWapplicationshouldhandlereopenfun)(int);
/*! @name GLFW version macros /*! @name GLFW version macros
@ -1836,6 +1838,10 @@ typedef GLFWcocoatextinputfilterfun (*glfwSetCocoaTextInputFilter_func)(GLFWwind
glfwSetCocoaTextInputFilter_func glfwSetCocoaTextInputFilter_impl; glfwSetCocoaTextInputFilter_func glfwSetCocoaTextInputFilter_impl;
#define glfwSetCocoaTextInputFilter glfwSetCocoaTextInputFilter_impl #define glfwSetCocoaTextInputFilter glfwSetCocoaTextInputFilter_impl
typedef GLFWapplicationshouldhandlereopenfun (*glfwSetApplicationShouldHandleReopen_func)(GLFWapplicationshouldhandlereopenfun);
glfwSetApplicationShouldHandleReopen_func glfwSetApplicationShouldHandleReopen_impl;
#define glfwSetApplicationShouldHandleReopen glfwSetApplicationShouldHandleReopen_impl
typedef void (*glfwGetCocoaKeyEquivalent_func)(int, int, void*, void*); typedef void (*glfwGetCocoaKeyEquivalent_func)(int, int, void*, void*);
glfwGetCocoaKeyEquivalent_func glfwGetCocoaKeyEquivalent_impl; glfwGetCocoaKeyEquivalent_func glfwGetCocoaKeyEquivalent_impl;
#define glfwGetCocoaKeyEquivalent glfwGetCocoaKeyEquivalent_impl #define glfwGetCocoaKeyEquivalent glfwGetCocoaKeyEquivalent_impl

View File

@ -331,6 +331,15 @@ filter_option(int key UNUSED, int mods, unsigned int scancode UNUSED) {
return ((mods == GLFW_MOD_ALT) || (mods == (GLFW_MOD_ALT | GLFW_MOD_SHIFT))) ? 1 : 0; return ((mods == GLFW_MOD_ALT) || (mods == (GLFW_MOD_ALT | GLFW_MOD_SHIFT))) ? 1 : 0;
} }
static GLFWwindow *application_quit_canary = NULL; static GLFWwindow *application_quit_canary = NULL;
static int
on_application_reopen(int has_visible_windows) {
if (has_visible_windows) return true;
set_cocoa_pending_action(NEW_OS_WINDOW);
// Without unjam wait_for_events() blocks until the next event
unjam_event_loop();
return false;
}
#endif #endif
void void
@ -372,6 +381,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
#ifdef __APPLE__ #ifdef __APPLE__
if (OPT(macos_hide_titlebar)) glfwWindowHint(GLFW_DECORATED, false); if (OPT(macos_hide_titlebar)) glfwWindowHint(GLFW_DECORATED, false);
glfwWindowHint(GLFW_COCOA_GRAPHICS_SWITCHING, true); glfwWindowHint(GLFW_COCOA_GRAPHICS_SWITCHING, true);
glfwSetApplicationShouldHandleReopen(on_application_reopen);
#endif #endif
} }