diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index a43fd731d..db1f07a74 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -3876,6 +3876,17 @@ glfwCocoaCycleThroughOSWindows(bool backwards) { } +GLFWAPI void +glfwCocoaRegisterMIMETypes(GLFWwindow *window, const char **mimes, size_t count) { + _GLFWwindow *w = (_GLFWwindow*)window; + NSArray *currentTypes = [w->ns.view registeredDraggedTypes]; + NSMutableArray *updatedTypes = [NSMutableArray arrayWithArray:currentTypes]; + for (size_t i = 0; i < count; i++) { + NSString *uti = mime_to_uti(mimes[i]); + if (![updatedTypes containsObject:uti]) [updatedTypes addObject:uti]; + } + [w->ns.view registerForDraggedTypes:updatedTypes]; +} ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// diff --git a/glfw/glfw.py b/glfw/glfw.py index b720d2d0d..1bd7aebc5 100755 --- a/glfw/glfw.py +++ b/glfw/glfw.py @@ -316,6 +316,7 @@ def generate_wrappers(glfw_header: str) -> None: void glfwCocoaCycleThroughOSWindows(bool backwards) void glfwCocoaSetWindowChrome(GLFWwindow* window, unsigned int color, bool use_system_color, unsigned int system_color,\ int background_blur, unsigned int hide_window_decorations, bool show_text_in_titlebar, int color_space, float background_opacity, bool resizable) + void glfwCocoaRegisterMIMETypes(GLFWwindow *window, const char **mimes, size_t count) const char* glfwGetPrimarySelectionString(GLFWwindow* window, void) int glfwGetNativeKeyForName(const char* key_name, int case_sensitive) void glfwRequestWaylandFrameEvent(GLFWwindow *handle, unsigned long long id, GLFWwaylandframecallbackfunc callback) diff --git a/kitty/glfw-wrapper.c b/kitty/glfw-wrapper.c index 588a1745f..92434a2a8 100644 --- a/kitty/glfw-wrapper.c +++ b/kitty/glfw-wrapper.c @@ -491,6 +491,9 @@ load_glfw(const char* path) { *(void **) (&glfwCocoaSetWindowChrome_impl) = dlsym(handle, "glfwCocoaSetWindowChrome"); if (glfwCocoaSetWindowChrome_impl == NULL) dlerror(); // clear error indicator + *(void **) (&glfwCocoaRegisterMIMETypes_impl) = dlsym(handle, "glfwCocoaRegisterMIMETypes"); + if (glfwCocoaRegisterMIMETypes_impl == NULL) dlerror(); // clear error indicator + *(void **) (&glfwGetPrimarySelectionString_impl) = dlsym(handle, "glfwGetPrimarySelectionString"); if (glfwGetPrimarySelectionString_impl == NULL) dlerror(); // clear error indicator diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index d8d1cf90c..c4b260578 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -1540,7 +1540,7 @@ typedef void (* GLFWscrollfun)(GLFWwindow*,const GLFWScrollEvent*); typedef void (* GLFWkeyboardfun)(GLFWwindow*, GLFWkeyevent*); typedef enum { - GLFW_DRAG_DATA_REQUEST, + GLFW_DRAG_DATA_REQUEST, // request data for specified mime type GLFW_DRAG_CANCELLED, GLFW_DRAG_FINSHED, GLFW_DRAG_ACCEPTED, // mimetype was accepted or NULL if drag was accepted but no mime type specified @@ -1557,8 +1557,14 @@ typedef struct GLFWDragSourceItem { typedef struct GLFWDragEvent { GLFWDragEventType type; + // When the drag event callback is called with a mimetype and no data, the + // application should set the data ans data_sz and err_num fields. + // Once glfw is done reading the data the drag event callback will be + // called with the data pointer unchanged. The application is now free + // to delete the data, as needed. const char *mime_type; - const char *data; size_t data_sz; int err_num; + const char *data; size_t data_sz; + int err_num; // POSIX error code indicating failure fetching data GLFWDragOperationType action; // can be 0 indicating no action } GLFWDragEvent; @@ -2459,6 +2465,10 @@ typedef void (*glfwCocoaSetWindowChrome_func)(GLFWwindow*, unsigned int, bool, u GFW_EXTERN glfwCocoaSetWindowChrome_func glfwCocoaSetWindowChrome_impl; #define glfwCocoaSetWindowChrome glfwCocoaSetWindowChrome_impl +typedef void (*glfwCocoaRegisterMIMETypes_func)(GLFWwindow*, const char**, size_t); +GFW_EXTERN glfwCocoaRegisterMIMETypes_func glfwCocoaRegisterMIMETypes_impl; +#define glfwCocoaRegisterMIMETypes glfwCocoaRegisterMIMETypes_impl + typedef const char* (*glfwGetPrimarySelectionString_func)(GLFWwindow*); GFW_EXTERN glfwGetPrimarySelectionString_func glfwGetPrimarySelectionString_impl; #define glfwGetPrimarySelectionString glfwGetPrimarySelectionString_impl