API for registering MIME types for drag enter

This commit is contained in:
Kovid Goyal 2026-02-21 17:25:25 +05:30
parent 57e7dc2cdc
commit dea3ad5eed
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
4 changed files with 27 additions and 2 deletions

View file

@ -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 //////

View file

@ -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)

3
kitty/glfw-wrapper.c generated
View file

@ -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

14
kitty/glfw-wrapper.h generated
View file

@ -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