wayland: move clipboard/primary structs into the wayland struct

These are application global and very wayland specific
This commit is contained in:
Daniel Eklöf 2019-10-27 16:15:32 +01:00
parent 9e6c28f5b6
commit 5ca1ee701b
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
5 changed files with 45 additions and 45 deletions

10
main.c
View file

@ -1151,16 +1151,6 @@ out:
shm_fini(); shm_fini();
if (term.selection.clipboard.data_source != NULL)
wl_data_source_destroy(term.selection.clipboard.data_source);
if (term.selection.clipboard.data_offer != NULL)
wl_data_offer_destroy(term.selection.clipboard.data_offer);
free(term.selection.clipboard.text);
if (term.selection.primary.data_source != NULL)
zwp_primary_selection_source_v1_destroy(term.selection.primary.data_source);
if (term.selection.primary.data_offer != NULL)
zwp_primary_selection_offer_v1_destroy(term.selection.primary.data_offer);
free(term.selection.primary.text);
if (term.kbd.xkb_compose_state != NULL) if (term.kbd.xkb_compose_state != NULL)
xkb_compose_state_unref(term.kbd.xkb_compose_state); xkb_compose_state_unref(term.kbd.xkb_compose_state);
if (term.kbd.xkb_compose_table != NULL) if (term.kbd.xkb_compose_table != NULL)

View file

@ -319,7 +319,7 @@ static void
send(void *data, struct wl_data_source *wl_data_source, const char *mime_type, send(void *data, struct wl_data_source *wl_data_source, const char *mime_type,
int32_t fd) int32_t fd)
{ {
const struct clipboard *clipboard const struct wl_clipboard *clipboard
= wl_data_source_get_user_data(wl_data_source); = wl_data_source_get_user_data(wl_data_source);
assert(clipboard != NULL); assert(clipboard != NULL);
@ -346,7 +346,7 @@ send(void *data, struct wl_data_source *wl_data_source, const char *mime_type,
static void static void
cancelled(void *data, struct wl_data_source *wl_data_source) cancelled(void *data, struct wl_data_source *wl_data_source)
{ {
struct clipboard *clipboard = wl_data_source_get_user_data(wl_data_source); struct wl_clipboard *clipboard = wl_data_source_get_user_data(wl_data_source);
assert(clipboard->data_source == wl_data_source); assert(clipboard->data_source == wl_data_source);
wl_data_source_destroy(clipboard->data_source); wl_data_source_destroy(clipboard->data_source);
@ -386,7 +386,7 @@ primary_send(void *data,
struct zwp_primary_selection_source_v1 *zwp_primary_selection_source_v1, struct zwp_primary_selection_source_v1 *zwp_primary_selection_source_v1,
const char *mime_type, int32_t fd) const char *mime_type, int32_t fd)
{ {
const struct primary *primary const struct wl_primary *primary
= zwp_primary_selection_source_v1_get_user_data(zwp_primary_selection_source_v1); = zwp_primary_selection_source_v1_get_user_data(zwp_primary_selection_source_v1);
assert(primary != NULL); assert(primary != NULL);
@ -414,7 +414,7 @@ static void
primary_cancelled(void *data, primary_cancelled(void *data,
struct zwp_primary_selection_source_v1 *zwp_primary_selection_source_v1) struct zwp_primary_selection_source_v1 *zwp_primary_selection_source_v1)
{ {
struct primary *primary = zwp_primary_selection_source_v1_get_user_data( struct wl_primary *primary = zwp_primary_selection_source_v1_get_user_data(
zwp_primary_selection_source_v1); zwp_primary_selection_source_v1);
//assert(primary->data_source == zwp_primary_selection_source_v1); //assert(primary->data_source == zwp_primary_selection_source_v1);
@ -434,10 +434,10 @@ static const struct zwp_primary_selection_source_v1_listener primary_selection_s
bool bool
text_to_clipboard(struct terminal *term, char *text, uint32_t serial) text_to_clipboard(struct terminal *term, char *text, uint32_t serial)
{ {
if (term->selection.clipboard.data_source != NULL) { struct wl_clipboard *clipboard = &term->wl.clipboard;
/* Kill previous data source */
struct clipboard *clipboard = &term->selection.clipboard;
if (term->wl.clipboard.data_source != NULL) {
/* Kill previous data source */
assert(clipboard->serial != 0); assert(clipboard->serial != 0);
wl_data_device_set_selection(term->wl.data_device, NULL, clipboard->serial); wl_data_device_set_selection(term->wl.data_device, NULL, clipboard->serial);
wl_data_source_destroy(clipboard->data_source); wl_data_source_destroy(clipboard->data_source);
@ -447,8 +447,6 @@ text_to_clipboard(struct terminal *term, char *text, uint32_t serial)
clipboard->serial = 0; clipboard->serial = 0;
} }
struct clipboard *clipboard = &term->selection.clipboard;
clipboard->data_source clipboard->data_source
= wl_data_device_manager_create_data_source(term->wl.data_device_manager); = wl_data_device_manager_create_data_source(term->wl.data_device_manager);
@ -484,7 +482,7 @@ text_from_clipboard(struct terminal *term, uint32_t serial,
void (*cb)(const char *data, size_t size, void *user), void (*cb)(const char *data, size_t size, void *user),
void *user) void *user)
{ {
struct clipboard *clipboard = &term->selection.clipboard; struct wl_clipboard *clipboard = &term->wl.clipboard;
if (clipboard->data_offer == NULL) if (clipboard->data_offer == NULL)
return; return;
@ -541,7 +539,7 @@ from_clipboard_cb(const char *data, size_t size, void *user)
void void
selection_from_clipboard(struct terminal *term, uint32_t serial) selection_from_clipboard(struct terminal *term, uint32_t serial)
{ {
struct clipboard *clipboard = &term->selection.clipboard; struct wl_clipboard *clipboard = &term->wl.clipboard;
if (clipboard->data_offer == NULL) if (clipboard->data_offer == NULL)
return; return;
@ -560,10 +558,11 @@ text_to_primary(struct terminal *term, char *text, uint32_t serial)
if (term->wl.primary_selection_device_manager == NULL) if (term->wl.primary_selection_device_manager == NULL)
return false; return false;
struct wl_primary *primary = &term->wl.primary;
/* TODO: somehow share code with the clipboard equivalent */ /* TODO: somehow share code with the clipboard equivalent */
if (term->selection.primary.data_source != NULL) { if (term->wl.primary.data_source != NULL) {
/* Kill previous data source */ /* Kill previous data source */
struct primary *primary = &term->selection.primary;
assert(primary->serial != 0); assert(primary->serial != 0);
zwp_primary_selection_device_v1_set_selection( zwp_primary_selection_device_v1_set_selection(
@ -575,8 +574,6 @@ text_to_primary(struct terminal *term, char *text, uint32_t serial)
primary->serial = 0; primary->serial = 0;
} }
struct primary *primary = &term->selection.primary;
primary->data_source primary->data_source
= zwp_primary_selection_device_manager_v1_create_source( = zwp_primary_selection_device_manager_v1_create_source(
term->wl.primary_selection_device_manager); term->wl.primary_selection_device_manager);
@ -620,7 +617,7 @@ text_from_primary(
if (term->wl.primary_selection_device_manager == NULL) if (term->wl.primary_selection_device_manager == NULL)
return; return;
struct primary *primary = &term->selection.primary; struct wl_primary *primary = &term->wl.primary;
if (primary->data_offer == NULL) if (primary->data_offer == NULL)
return; return;
@ -673,7 +670,7 @@ selection_from_primary(struct terminal *term)
if (term->wl.primary_selection_device_manager == NULL) if (term->wl.primary_selection_device_manager == NULL)
return; return;
struct clipboard *clipboard = &term->selection.clipboard; struct wl_clipboard *clipboard = &term->wl.clipboard;
if (clipboard->data_offer == NULL) if (clipboard->data_offer == NULL)
return; return;
@ -746,7 +743,7 @@ selection(void *data, struct wl_data_device *wl_data_device,
/* Selection offer from other client */ /* Selection offer from other client */
struct terminal *term = data; struct terminal *term = data;
struct clipboard *clipboard = &term->selection.clipboard; struct wl_clipboard *clipboard = &term->wl.clipboard;
if (clipboard->data_offer != NULL) if (clipboard->data_offer != NULL)
wl_data_offer_destroy(clipboard->data_offer); wl_data_offer_destroy(clipboard->data_offer);
@ -795,7 +792,7 @@ primary_selection(void *data,
/* Selection offer from other client, for primary */ /* Selection offer from other client, for primary */
struct terminal *term = data; struct terminal *term = data;
struct primary *primary = &term->selection.primary; struct wl_primary *primary = &term->wl.primary;
if (primary->data_offer != NULL) if (primary->data_offer != NULL)
zwp_primary_selection_offer_v1_destroy(primary->data_offer); zwp_primary_selection_offer_v1_destroy(primary->data_offer);

View file

@ -171,20 +171,6 @@ enum mouse_reporting {
MOUSE_URXVT, /* ?1015h */ MOUSE_URXVT, /* ?1015h */
}; };
struct clipboard {
struct wl_data_source *data_source;
struct wl_data_offer *data_offer;
char *text;
uint32_t serial;
};
struct primary {
struct zwp_primary_selection_source_v1 *data_source;
struct zwp_primary_selection_offer_v1 *data_offer;
char *text;
uint32_t serial;
};
enum cursor_style { CURSOR_BLOCK, CURSOR_UNDERLINE, CURSOR_BAR }; enum cursor_style { CURSOR_BLOCK, CURSOR_UNDERLINE, CURSOR_BAR };
struct terminal { struct terminal {
@ -279,8 +265,6 @@ struct terminal {
struct { struct {
struct coord start; struct coord start;
struct coord end; struct coord end;
struct clipboard clipboard;
struct primary primary;
} selection; } selection;
bool is_searching; bool is_searching;

View file

@ -34,6 +34,17 @@ wayl_destroy(struct wayland *wayl)
if (wayl->xdg_output_manager != NULL) if (wayl->xdg_output_manager != NULL)
zxdg_output_manager_v1_destroy(wayl->xdg_output_manager); zxdg_output_manager_v1_destroy(wayl->xdg_output_manager);
if (wayl->clipboard.data_source != NULL)
wl_data_source_destroy(wayl->clipboard.data_source);
if (wayl->clipboard.data_offer != NULL)
wl_data_offer_destroy(wayl->clipboard.data_offer);
free(wayl->clipboard.text);
if (wayl->primary.data_source != NULL)
zwp_primary_selection_source_v1_destroy(wayl->primary.data_source);
if (wayl->primary.data_offer != NULL)
zwp_primary_selection_offer_v1_destroy(wayl->primary.data_offer);
free(wayl->primary.text);
free(wayl->pointer.theme_name); free(wayl->pointer.theme_name);
if (wayl->pointer.theme != NULL) if (wayl->pointer.theme != NULL)
wl_cursor_theme_destroy(wayl->pointer.theme); wl_cursor_theme_destroy(wayl->pointer.theme);

View file

@ -27,6 +27,20 @@ struct monitor {
float refresh; float refresh;
}; };
struct wl_clipboard {
struct wl_data_source *data_source;
struct wl_data_offer *data_offer;
char *text;
uint32_t serial;
};
struct wl_primary {
struct zwp_primary_selection_source_v1 *data_source;
struct zwp_primary_selection_offer_v1 *data_offer;
char *text;
uint32_t serial;
};
struct wl_window { struct wl_window {
struct wl_surface *surface; struct wl_surface *surface;
struct xdg_wm_base *shell; struct xdg_wm_base *shell;
@ -74,6 +88,10 @@ struct wayland {
char *theme_name; char *theme_name;
} pointer; } pointer;
/* Clipboard */
struct wl_clipboard clipboard;
struct wl_primary primary;
bool have_argb8888; bool have_argb8888;
tll(struct monitor) monitors; /* All available outputs */ tll(struct monitor) monitors; /* All available outputs */
}; };