Skip to content

Commit 2458c3a

Browse files
committed
Implement drag and drop of text/plain for Wayland as well
1 parent e827e6f commit 2458c3a

File tree

17 files changed

+204
-225
lines changed

17 files changed

+204
-225
lines changed

docs/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
7777
- Workaround for bug in less that causes colors to reset at wrapped lines
7878
(:iss:`2381`)
7979

80-
- X11: Allow drag and drop of text/plain in addition to text/uri-list
80+
- X11/Wayland: Allow drag and drop of text/plain in addition to text/uri-list
8181
(:iss:`2441`)
8282

8383
- Dont strip :code:`&` and :code:`-` from the end of URLs (:iss:`2436`)

glfw/backend_utils.c

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -332,54 +332,3 @@ pollForEvents(EventLoopData *eld, monotonic_t timeout, watch_callback_func displ
332332
}
333333
return read_ok;
334334
}
335-
336-
// Splits and translates a text/uri-list into separate file paths
337-
// NOTE: This function destroys the provided string
338-
//
339-
char** parseUriList(char* text, int* count)
340-
{
341-
const char* prefix = "file://";
342-
char** paths = NULL;
343-
char* line;
344-
345-
*count = 0;
346-
347-
while ((line = strtok(text, "\r\n")))
348-
{
349-
text = NULL;
350-
351-
if (line[0] == '#')
352-
continue;
353-
354-
if (strncmp(line, prefix, strlen(prefix)) == 0)
355-
{
356-
line += strlen(prefix);
357-
// TODO: Validate hostname
358-
while (*line != '/')
359-
line++;
360-
}
361-
362-
(*count)++;
363-
364-
char* path = calloc(strlen(line) + 1, 1);
365-
paths = realloc(paths, *count * sizeof(char*));
366-
paths[*count - 1] = path;
367-
368-
while (*line)
369-
{
370-
if (line[0] == '%' && line[1] && line[2])
371-
{
372-
const char digits[3] = { line[1], line[2], '\0' };
373-
*path = strtol(digits, NULL, 16);
374-
line += 2;
375-
}
376-
else
377-
*path = *line;
378-
379-
path++;
380-
line++;
381-
}
382-
}
383-
384-
return paths;
385-
}

glfw/backend_utils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,4 @@ int pollForEvents(EventLoopData *eld, monotonic_t timeout, watch_callback_func);
9494
unsigned dispatchTimers(EventLoopData *eld);
9595
void finalizePollData(EventLoopData *eld);
9696
bool initPollData(EventLoopData *eld, int display_fd);
97-
char** parseUriList(char* text, int* count);
9897
void wakeupEventLoop(EventLoopData *eld);

glfw/glfw3.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,19 +1593,22 @@ typedef void (* GLFWscrollfun)(GLFWwindow*,double,double,int);
15931593
*/
15941594
typedef void (* GLFWkeyboardfun)(GLFWwindow*, GLFWkeyevent*);
15951595

1596-
/*! @brief The function pointer type for path drop callbacks.
1596+
/*! @brief The function pointer type for drag and drop callbacks.
15971597
*
1598-
* This is the function pointer type for path drop callbacks. A path drop
1598+
* This is the function pointer type for drop callbacks. A drop
15991599
* callback function has the following signature:
16001600
* @code
1601-
* void function_name(GLFWwindow* window, int path_count, const char* paths[])
1601+
* int function_name(GLFWwindow* window, const char* mime, const char* text)
16021602
* @endcode
16031603
*
16041604
* @param[in] window The window that received the event.
1605-
* @param[in] path_count The number of dropped paths.
1606-
* @param[in] paths The UTF-8 encoded file and/or directory path names.
1605+
* @param[in] mime The UTF-8 encoded drop mime-type
1606+
* @param[in] data The dropped data or NULL for drag enter events
1607+
* @param[in] sz The size of the dropped data
1608+
* @return For drag events should return the priority for the specified mime type. A priority of zero
1609+
* or lower means the mime type is not accepted. Highest priority will be the finally accepted mime-type.
16071610
*
1608-
* @pointer_lifetime The path array and its strings are valid until the
1611+
* @pointer_lifetime The text is valid until the
16091612
* callback function returns.
16101613
*
16111614
* @sa @ref path_drop
@@ -1615,7 +1618,7 @@ typedef void (* GLFWkeyboardfun)(GLFWwindow*, GLFWkeyevent*);
16151618
*
16161619
* @ingroup input
16171620
*/
1618-
typedef void (* GLFWdropfun)(GLFWwindow*,int,const char*[]);
1621+
typedef int (* GLFWdropfun)(GLFWwindow*, const char *, const char*, size_t);
16191622

16201623
typedef void (* GLFWliveresizefun)(GLFWwindow*, bool);
16211624

glfw/input.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,11 @@ void _glfwInputCursorEnter(_GLFWwindow* window, bool entered)
350350

351351
// Notifies shared code of files or directories dropped on a window
352352
//
353-
void _glfwInputDrop(_GLFWwindow* window, int count, const char** paths)
353+
int _glfwInputDrop(_GLFWwindow* window, const char *mime, const char *text, size_t sz)
354354
{
355355
if (window->callbacks.drop)
356-
window->callbacks.drop((GLFWwindow*) window, count, paths);
356+
return window->callbacks.drop((GLFWwindow*) window, mime, text, sz);
357+
return 0;
357358
}
358359

359360
// Notifies shared code of a joystick connection or disconnection

glfw/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset, int f
759759
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods);
760760
void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos);
761761
void _glfwInputCursorEnter(_GLFWwindow* window, bool entered);
762-
void _glfwInputDrop(_GLFWwindow* window, int count, const char** names);
762+
int _glfwInputDrop(_GLFWwindow* window, const char *mime, const char *text, size_t sz);
763763
void _glfwInputJoystick(_GLFWjoystick* js, int event);
764764
void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value);
765765
void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value);

glfw/wl_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ void _glfwPlatformTerminate(void)
852852
wl_data_source_destroy(_glfw.wl.dataSourceForClipboard);
853853
for (size_t doi=0; doi < arraysz(_glfw.wl.dataOffers); doi++) {
854854
if (_glfw.wl.dataOffers[doi].id) {
855-
wl_data_offer_destroy(_glfw.wl.dataOffers[doi].id);
855+
destroy_data_offer(&_glfw.wl.dataOffers[doi]);
856856
}
857857
}
858858
if (_glfw.wl.dataDevice)

glfw/wl_platform.h

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -195,28 +195,19 @@ typedef enum _GLFWWaylandOfferType
195195

196196
typedef struct _GLFWWaylandDataOffer
197197
{
198-
struct wl_data_offer *id;
199-
const char *mime;
198+
void *id;
200199
_GLFWWaylandOfferType offer_type;
201200
size_t idx;
202-
int is_self_offer;
203-
int has_uri_list;
201+
bool is_self_offer;
202+
bool is_primary;
203+
const char *plain_text_mime, *mime_for_drop;
204204
uint32_t source_actions;
205205
uint32_t dnd_action;
206206
struct wl_surface *surface;
207+
const char **mimes;
208+
size_t mimes_capacity, mimes_count;
207209
} _GLFWWaylandDataOffer;
208210

209-
typedef struct _GLFWWaylandPrimaryOffer
210-
{
211-
struct zwp_primary_selection_offer_v1 *id;
212-
const char *mime;
213-
_GLFWWaylandOfferType offer_type;
214-
size_t idx;
215-
int is_self_offer;
216-
int has_uri_list;
217-
struct wl_surface *surface;
218-
} _GLFWWaylandPrimaryOffer;
219-
220211
// Wayland-specific global data
221212
//
222213
typedef struct _GLFWlibraryWayland
@@ -287,8 +278,6 @@ typedef struct _GLFWlibraryWayland
287278
size_t dataOffersCounter;
288279
_GLFWWaylandDataOffer dataOffers[8];
289280
char* primarySelectionString;
290-
size_t primarySelectionOffersCounter;
291-
_GLFWWaylandPrimaryOffer primarySelectionOffers[8];
292281
} _GLFWlibraryWayland;
293282

294283
// Wayland-specific per-monitor data
@@ -322,3 +311,4 @@ void _glfwSetupWaylandDataDevice(void);
322311
void _glfwSetupWaylandPrimarySelectionDevice(void);
323312
void animateCursorImage(id_type timer_id, void *data);
324313
struct wl_cursor* _glfwLoadCursor(GLFWCursorShape);
314+
void destroy_data_offer(_GLFWWaylandDataOffer*);

0 commit comments

Comments
 (0)