Merge pull request #1519 from emersion/dedup-source-mime-type
De-duplicate data source MIME types
Drew DeVault authored 5 years ago
GitHub committed 5 years ago
189 | 189 |
"wl_data_device.set_selection");
|
190 | 190 |
}
|
191 | 191 |
|
|
192 |
const char **mime_type_ptr;
|
|
193 |
wl_array_for_each(mime_type_ptr, &source->source.mime_types) {
|
|
194 |
if (strcmp(*mime_type_ptr, mime_type) == 0) {
|
|
195 |
wlr_log(WLR_DEBUG, "Ignoring duplicate MIME type offer %s",
|
|
196 |
mime_type);
|
|
197 |
return;
|
|
198 |
}
|
|
199 |
}
|
|
200 |
|
|
201 |
char *dup_mime_type = strdup(mime_type);
|
|
202 |
if (dup_mime_type == NULL) {
|
|
203 |
wl_resource_post_no_memory(resource);
|
|
204 |
return;
|
|
205 |
}
|
|
206 |
|
192 | 207 |
char **p = wl_array_add(&source->source.mime_types, sizeof(*p));
|
193 | |
if (p) {
|
194 | |
*p = strdup(mime_type);
|
195 | |
}
|
196 | |
if (!p || !*p) {
|
197 | |
if (p) {
|
198 | |
source->source.mime_types.size -= sizeof(*p);
|
199 | |
}
|
|
208 |
if (p == NULL) {
|
|
209 |
free(dup_mime_type);
|
200 | 210 |
wl_resource_post_no_memory(resource);
|
201 | |
}
|
|
211 |
return;
|
|
212 |
}
|
|
213 |
|
|
214 |
*p = dup_mime_type;
|
202 | 215 |
}
|
203 | 216 |
|
204 | 217 |
static const struct wl_data_source_interface data_source_impl = {
|
4 | 4 |
#include <unistd.h>
|
5 | 5 |
#include <wlr/types/wlr_data_control_v1.h>
|
6 | 6 |
#include <wlr/types/wlr_data_device.h>
|
|
7 |
#include <wlr/util/log.h>
|
7 | 8 |
#include "util/signal.h"
|
8 | 9 |
#include "wlr-data-control-unstable-v1-protocol.h"
|
9 | 10 |
|
|
66 | 67 |
ZWLR_DATA_CONTROL_SOURCE_V1_ERROR_INVALID_OFFER,
|
67 | 68 |
"cannot mutate offer after set_selection");
|
68 | 69 |
return;
|
|
70 |
}
|
|
71 |
|
|
72 |
const char **mime_type_ptr;
|
|
73 |
wl_array_for_each(mime_type_ptr, &source->source.mime_types) {
|
|
74 |
if (strcmp(*mime_type_ptr, mime_type) == 0) {
|
|
75 |
wlr_log(WLR_DEBUG, "Ignoring duplicate MIME type offer %s",
|
|
76 |
mime_type);
|
|
77 |
return;
|
|
78 |
}
|
69 | 79 |
}
|
70 | 80 |
|
71 | 81 |
char *dup_mime_type = strdup(mime_type);
|
142 | 142 |
wlr_log(WLR_DEBUG, "Offering additional MIME type after set_selection");
|
143 | 143 |
}
|
144 | 144 |
|
|
145 |
const char **mime_type_ptr;
|
|
146 |
wl_array_for_each(mime_type_ptr, &source->source.mime_types) {
|
|
147 |
if (strcmp(*mime_type_ptr, mime_type) == 0) {
|
|
148 |
wlr_log(WLR_DEBUG, "Ignoring duplicate MIME type offer %s",
|
|
149 |
mime_type);
|
|
150 |
return;
|
|
151 |
}
|
|
152 |
}
|
|
153 |
|
145 | 154 |
char *dup_mime_type = strdup(mime_type);
|
146 | 155 |
if (dup_mime_type == NULL) {
|
147 | 156 |
wl_resource_post_no_memory(resource);
|