Codebase list wlroots / 16a93ed
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
3 changed file(s) with 40 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
189189 "wl_data_device.set_selection");
190190 }
191191
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
192207 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);
200210 wl_resource_post_no_memory(resource);
201 }
211 return;
212 }
213
214 *p = dup_mime_type;
202215 }
203216
204217 static const struct wl_data_source_interface data_source_impl = {
44 #include <unistd.h>
55 #include <wlr/types/wlr_data_control_v1.h>
66 #include <wlr/types/wlr_data_device.h>
7 #include <wlr/util/log.h>
78 #include "util/signal.h"
89 #include "wlr-data-control-unstable-v1-protocol.h"
910
6667 ZWLR_DATA_CONTROL_SOURCE_V1_ERROR_INVALID_OFFER,
6768 "cannot mutate offer after set_selection");
6869 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 }
6979 }
7080
7181 char *dup_mime_type = strdup(mime_type);
142142 wlr_log(WLR_DEBUG, "Offering additional MIME type after set_selection");
143143 }
144144
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
145154 char *dup_mime_type = strdup(mime_type);
146155 if (dup_mime_type == NULL) {
147156 wl_resource_post_no_memory(resource);