Merge pull request #519 from emersion/xwayland-primary-selection

Implement xwayland primary selection sync
master
Tony Crisci 7 years ago committed by GitHub
commit e809250171
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -34,6 +34,7 @@ struct wlr_data_source {
struct wl_resource *resource; struct wl_resource *resource;
struct wlr_data_offer *offer; struct wlr_data_offer *offer;
struct wlr_seat_client *seat_client; struct wlr_seat_client *seat_client;
struct wl_array mime_types; struct wl_array mime_types;
bool accepted; bool accepted;
@ -123,4 +124,8 @@ void wlr_seat_client_send_selection(struct wlr_seat_client *seat_client);
void wlr_seat_set_selection(struct wlr_seat *seat, void wlr_seat_set_selection(struct wlr_seat *seat,
struct wlr_data_source *source, uint32_t serial); struct wlr_data_source *source, uint32_t serial);
void wlr_data_source_init(struct wlr_data_source *source);
void wlr_data_source_finish(struct wlr_data_source *source);
#endif #endif

@ -48,6 +48,11 @@ void wlr_primary_selection_device_manager_destroy(
void wlr_seat_client_send_primary_selection(struct wlr_seat_client *seat_client); void wlr_seat_client_send_primary_selection(struct wlr_seat_client *seat_client);
void wlr_seat_set_primary_selection(struct wlr_seat *seat, void wlr_seat_set_primary_selection(struct wlr_seat *seat,
struct wlr_primary_selection_source *source, uint32_t serial); struct wlr_primary_selection_source *source, uint32_t serial);
void wlr_primary_selection_source_init(
struct wlr_primary_selection_source *source);
void wlr_primary_selection_source_finish(
struct wlr_primary_selection_source *source);
#endif #endif

@ -32,6 +32,7 @@ enum atom_name {
_NET_WM_STATE_MAXIMIZED_HORZ, _NET_WM_STATE_MAXIMIZED_HORZ,
WM_STATE, WM_STATE,
CLIPBOARD, CLIPBOARD,
PRIMARY,
WL_SELECTION, WL_SELECTION,
TARGETS, TARGETS,
CLIPBOARD_MANAGER, CLIPBOARD_MANAGER,
@ -49,6 +50,24 @@ enum net_wm_state_action {
NET_WM_STATE_TOGGLE = 2, NET_WM_STATE_TOGGLE = 2,
}; };
struct wlr_xwm_selection {
struct wlr_xwm *xwm;
xcb_atom_t atom;
xcb_window_t window;
xcb_selection_request_event_t request;
xcb_window_t owner;
xcb_timestamp_t timestamp;
int incr;
int source_fd;
int property_start;
xcb_get_property_reply_t *property_reply;
struct wl_event_source *property_source;
int flush_property_on_delete;
struct wl_array source_data;
xcb_atom_t target;
bool property_set;
};
struct wlr_xwm { struct wlr_xwm {
struct wlr_xwayland *xwayland; struct wlr_xwayland *xwayland;
struct wl_event_source *event_source; struct wl_event_source *event_source;
@ -63,20 +82,9 @@ struct wlr_xwm {
xcb_render_pictformat_t render_format_id; xcb_render_pictformat_t render_format_id;
xcb_cursor_t cursor; xcb_cursor_t cursor;
// selection properties
xcb_window_t selection_window; xcb_window_t selection_window;
xcb_selection_request_event_t selection_request; struct wlr_xwm_selection clipboard_selection;
xcb_window_t selection_owner; struct wlr_xwm_selection primary_selection;
xcb_timestamp_t selection_timestamp;
int incr;
int data_source_fd;
int property_start;
xcb_get_property_reply_t *property_reply;
struct wl_event_source *property_source;
int flush_property_on_delete;
struct wl_array source_data;
xcb_atom_t selection_target;
bool selection_property_set;
struct wlr_xwayland_surface *focus_surface; struct wlr_xwayland_surface *focus_surface;
@ -86,7 +94,8 @@ struct wlr_xwm {
const xcb_query_extension_reply_t *xfixes; const xcb_query_extension_reply_t *xfixes;
struct wl_listener compositor_surface_create; struct wl_listener compositor_surface_create;
struct wl_listener seat_selection_change; struct wl_listener seat_selection;
struct wl_listener seat_primary_selection;
}; };
struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland); struct wlr_xwm *xwm_create(struct wlr_xwayland *wlr_xwayland);

@ -856,16 +856,7 @@ void data_device_manager_get_data_device(struct wl_client *client,
static void data_source_resource_destroy(struct wl_resource *resource) { static void data_source_resource_destroy(struct wl_resource *resource) {
struct wlr_data_source *source = struct wlr_data_source *source =
wl_resource_get_user_data(resource); wl_resource_get_user_data(resource);
char **p; wlr_data_source_finish(source);
wl_signal_emit(&source->events.destroy, source);
wl_array_for_each(p, &source->mime_types) {
free(*p);
}
wl_array_release(&source->mime_types);
free(source); free(source);
} }
@ -927,6 +918,25 @@ static struct wl_data_source_interface data_source_impl = {
.set_actions = data_source_set_actions, .set_actions = data_source_set_actions,
}; };
void wlr_data_source_init(struct wlr_data_source *source) {
wl_array_init(&source->mime_types);
wl_signal_init(&source->events.destroy);
}
void wlr_data_source_finish(struct wlr_data_source *source) {
if (source == NULL) {
return;
}
wl_signal_emit(&source->events.destroy, source);
char **p;
wl_array_for_each(p, &source->mime_types) {
free(*p);
}
wl_array_release(&source->mime_types);
}
static void data_device_manager_create_data_source(struct wl_client *client, static void data_device_manager_create_data_source(struct wl_client *client,
struct wl_resource *resource, uint32_t id) { struct wl_resource *resource, uint32_t id) {
struct wlr_data_source *source = calloc(1, sizeof(struct wlr_data_source)); struct wlr_data_source *source = calloc(1, sizeof(struct wlr_data_source));
@ -934,25 +944,21 @@ static void data_device_manager_create_data_source(struct wl_client *client,
wl_resource_post_no_memory(resource); wl_resource_post_no_memory(resource);
return; return;
} }
wlr_data_source_init(source);
source->resource = source->resource = wl_resource_create(client, &wl_data_source_interface,
wl_resource_create(client, &wl_data_source_interface, wl_resource_get_version(resource), id);
wl_resource_get_version(resource), id);
if (source->resource == NULL) { if (source->resource == NULL) {
free(source); free(source);
wl_resource_post_no_memory(resource); wl_resource_post_no_memory(resource);
return; return;
} }
wl_resource_set_implementation(source->resource, &data_source_impl,
source, data_source_resource_destroy);
source->accept = client_data_source_accept; source->accept = client_data_source_accept;
source->send = client_data_source_send; source->send = client_data_source_send;
source->cancel = client_data_source_cancel; source->cancel = client_data_source_cancel;
wl_array_init(&source->mime_types);
wl_signal_init(&source->events.destroy);
wl_resource_set_implementation(source->resource, &data_source_impl,
source, data_source_resource_destroy);
} }
static const struct wl_data_device_manager_interface static const struct wl_data_device_manager_interface

@ -144,15 +144,7 @@ static const struct gtk_primary_selection_source_interface source_impl = {
static void source_resource_handle_destroy(struct wl_resource *resource) { static void source_resource_handle_destroy(struct wl_resource *resource) {
struct wlr_primary_selection_source *source = struct wlr_primary_selection_source *source =
wl_resource_get_user_data(resource); wl_resource_get_user_data(resource);
wlr_primary_selection_source_finish(source);
wl_signal_emit(&source->events.destroy, source);
char **p;
wl_array_for_each(p, &source->mime_types) {
free(*p);
}
wl_array_release(&source->mime_types);
free(source); free(source);
} }
@ -262,6 +254,27 @@ static void device_resource_handle_destroy(struct wl_resource *resource) {
} }
void wlr_primary_selection_source_init(
struct wlr_primary_selection_source *source) {
wl_array_init(&source->mime_types);
wl_signal_init(&source->events.destroy);
}
void wlr_primary_selection_source_finish(
struct wlr_primary_selection_source *source) {
if (source == NULL) {
return;
}
wl_signal_emit(&source->events.destroy, source);
char **p;
wl_array_for_each(p, &source->mime_types) {
free(*p);
}
wl_array_release(&source->mime_types);
}
static void device_manager_handle_create_source(struct wl_client *client, static void device_manager_handle_create_source(struct wl_client *client,
struct wl_resource *manager_resource, uint32_t id) { struct wl_resource *manager_resource, uint32_t id) {
struct wlr_primary_selection_source *source = struct wlr_primary_selection_source *source =
@ -270,6 +283,7 @@ static void device_manager_handle_create_source(struct wl_client *client,
wl_client_post_no_memory(client); wl_client_post_no_memory(client);
return; return;
} }
wlr_primary_selection_source_init(source);
int version = wl_resource_get_version(manager_resource); int version = wl_resource_get_version(manager_resource);
source->resource = wl_resource_create(client, source->resource = wl_resource_create(client,
@ -284,9 +298,6 @@ static void device_manager_handle_create_source(struct wl_client *client,
source->send = client_source_send; source->send = client_source_send;
source->cancel = client_source_cancel; source->cancel = client_source_cancel;
wl_array_init(&source->mime_types);
wl_signal_init(&source->events.destroy);
} }
void device_manager_handle_get_device(struct wl_client *client, void device_manager_handle_get_device(struct wl_client *client,

File diff suppressed because it is too large Load Diff

@ -46,6 +46,7 @@ const char *atom_map[ATOM_LAST] = {
"_NET_WM_STATE_MAXIMIZED_HORZ", "_NET_WM_STATE_MAXIMIZED_HORZ",
"WM_STATE", "WM_STATE",
"CLIPBOARD", "CLIPBOARD",
"PRIMARY",
"_WL_SELECTION", "_WL_SELECTION",
"TARGETS", "TARGETS",
"CLIPBOARD_MANAGER", "CLIPBOARD_MANAGER",

Loading…
Cancel
Save