This repository has been archived by the owner on Nov 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 340
Implement input_method_v2 popups #2550
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,9 @@ | |
static const struct zwp_input_method_v2_interface input_method_impl; | ||
static const struct zwp_input_method_keyboard_grab_v2_interface keyboard_grab_impl; | ||
|
||
static void popup_surface_destroy( | ||
struct wlr_input_popup_surface_v2 *popup_surface); | ||
|
||
static struct wlr_input_method_v2 *input_method_from_resource( | ||
struct wl_resource *resource) { | ||
assert(wl_resource_instance_of(resource, | ||
|
@@ -33,6 +36,11 @@ static struct wlr_input_method_keyboard_grab_v2 *keyboard_grab_from_resource( | |
} | ||
|
||
static void input_method_destroy(struct wlr_input_method_v2 *input_method) { | ||
struct wlr_input_popup_surface_v2 *popup_surface, *tmp; | ||
wl_list_for_each_safe( | ||
popup_surface, tmp, &input_method->popup_surfaces, link) { | ||
popup_surface_destroy(popup_surface); | ||
} | ||
wlr_signal_emit_safe(&input_method->events.destroy, input_method); | ||
wl_list_remove(wl_resource_get_link(input_method->resource)); | ||
wl_list_remove(&input_method->seat_client_destroy.link); | ||
|
@@ -108,10 +116,134 @@ static void im_delete_surrounding_text(struct wl_client *client, | |
input_method->pending.delete.after_length = after_length; | ||
} | ||
|
||
struct wlr_input_popup_surface_v2 *wlr_input_popup_surface_v2_from_wlr_surface( | ||
struct wlr_surface *surface) { | ||
assert(wlr_surface_is_input_popup_surface_v2(surface)); | ||
return (struct wlr_input_popup_surface_v2 *)surface->role_data; | ||
} | ||
|
||
void wlr_input_popup_surface_v2_send_text_input_rectangle( | ||
struct wlr_input_popup_surface_v2 *popup_surface, | ||
struct wlr_box *sbox) { | ||
zwp_input_popup_surface_v2_send_text_input_rectangle( | ||
popup_surface->resource, sbox->x, sbox->y, sbox->width, sbox->height); | ||
} | ||
|
||
static void popup_surface_set_mapped( | ||
struct wlr_input_popup_surface_v2 *popup_surface, bool mapped) { | ||
if (mapped && !popup_surface->mapped) { | ||
popup_surface->mapped = true; | ||
wlr_signal_emit_safe(&popup_surface->events.map, popup_surface); | ||
} else if (!mapped && popup_surface->mapped) { | ||
wlr_signal_emit_safe(&popup_surface->events.unmap, popup_surface); | ||
popup_surface->mapped = false; | ||
} | ||
} | ||
|
||
static void popup_surface_surface_role_commit(struct wlr_surface *surface) { | ||
struct wlr_input_popup_surface_v2 *popup_surface = surface->role_data; | ||
if (popup_surface == NULL) { | ||
return; | ||
} | ||
popup_surface_set_mapped(popup_surface, wlr_surface_has_buffer(surface) | ||
&& popup_surface->input_method->client_active); | ||
} | ||
|
||
static const struct wlr_surface_role input_popup_surface_v2_role = { | ||
.name = "zwp_input_popup_surface_v2", | ||
.commit = popup_surface_surface_role_commit, | ||
}; | ||
|
||
bool wlr_surface_is_input_popup_surface_v2(struct wlr_surface *surface) { | ||
return surface->role == &input_popup_surface_v2_role; | ||
} | ||
|
||
static void popup_surface_destroy( | ||
struct wlr_input_popup_surface_v2 *popup_surface) { | ||
popup_surface_set_mapped(popup_surface, false); | ||
wlr_signal_emit_safe(&popup_surface->events.destroy, NULL); | ||
wl_list_remove(&popup_surface->surface_destroy.link); | ||
wl_list_remove(&popup_surface->link); | ||
wl_resource_set_user_data(popup_surface->resource, NULL); | ||
free(popup_surface); | ||
tadeokondrak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
static void popup_surface_handle_surface_destroy(struct wl_listener *listener, | ||
void *data) { | ||
struct wlr_input_popup_surface_v2 *popup_surface = | ||
wl_container_of(listener, popup_surface, surface_destroy); | ||
popup_surface_destroy(popup_surface); | ||
} | ||
|
||
static void popup_resource_destroy(struct wl_resource *resource) { | ||
struct wlr_input_popup_surface_v2 *popup_surface = | ||
wl_resource_get_user_data(resource); | ||
if (popup_surface == NULL) { | ||
return; | ||
} | ||
popup_surface_destroy(popup_surface); | ||
} | ||
|
||
static void popup_destroy(struct wl_client *client, | ||
struct wl_resource *resource) { | ||
wl_resource_destroy(resource); | ||
} | ||
|
||
static const struct zwp_input_popup_surface_v2_interface input_popup_impl = { | ||
.destroy = popup_destroy, | ||
}; | ||
|
||
static void im_get_input_popup_surface(struct wl_client *client, | ||
struct wl_resource *resource, uint32_t id, | ||
struct wl_resource *surface) { | ||
wlr_log(WLR_INFO, "Stub: zwp_input_method_v2::get_input_popup_surface"); | ||
struct wl_resource *surface_resource) { | ||
struct wlr_input_method_v2 *input_method = | ||
input_method_from_resource(resource); | ||
if (!input_method) { | ||
return; | ||
} | ||
|
||
struct wl_resource *popup_resource = wl_resource_create( | ||
tadeokondrak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
client, &zwp_input_popup_surface_v2_interface, | ||
wl_resource_get_version(resource), id); | ||
if (!popup_resource) { | ||
wl_client_post_no_memory(client); | ||
return; | ||
} | ||
|
||
struct wlr_input_popup_surface_v2 *popup_surface = | ||
calloc(1, sizeof(struct wlr_input_popup_surface_v2)); | ||
if (!popup_surface) { | ||
wl_client_post_no_memory(client); | ||
return; | ||
} | ||
wl_resource_set_implementation(popup_resource, &input_popup_impl, | ||
popup_surface, popup_resource_destroy); | ||
|
||
struct wlr_surface *surface = wlr_surface_from_resource(surface_resource); | ||
if (!wlr_surface_set_role(surface, &input_popup_surface_v2_role, | ||
popup_surface, resource, ZWP_INPUT_METHOD_V2_ERROR_ROLE)) { | ||
free(popup_surface); | ||
return; | ||
} | ||
|
||
popup_surface->resource = popup_resource; | ||
popup_surface->input_method = input_method; | ||
popup_surface->surface = surface; | ||
wl_signal_add(&popup_surface->surface->events.destroy, | ||
&popup_surface->surface_destroy); | ||
popup_surface->surface_destroy.notify = | ||
popup_surface_handle_surface_destroy; | ||
|
||
wl_signal_init(&popup_surface->events.map); | ||
wl_signal_init(&popup_surface->events.unmap); | ||
wl_signal_init(&popup_surface->events.destroy); | ||
|
||
popup_surface_set_mapped(popup_surface, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we allow already-mapped surfaces? I guess the protocol allows them, and disallowing them would be a breaking change. But before getting the text input box, the client can't really know how to draw the popup. |
||
wlr_surface_has_buffer(popup_surface->surface) | ||
&& popup_surface->input_method->client_active); | ||
|
||
wl_list_insert(&input_method->popup_surfaces, &popup_surface->link); | ||
wlr_signal_emit_safe(&input_method->events.new_popup_surface, popup_surface); | ||
} | ||
|
||
void wlr_input_method_keyboard_grab_v2_destroy( | ||
|
@@ -351,6 +483,12 @@ void wlr_input_method_v2_send_done(struct wlr_input_method_v2 *input_method) { | |
zwp_input_method_v2_send_done(input_method->resource); | ||
input_method->client_active = input_method->active; | ||
input_method->current_serial++; | ||
struct wlr_input_popup_surface_v2 *popup_surface; | ||
wl_list_for_each(popup_surface, &input_method->popup_surfaces, link) { | ||
popup_surface_set_mapped(popup_surface, | ||
wlr_surface_has_buffer(popup_surface->surface) && | ||
input_method->client_active); | ||
} | ||
} | ||
|
||
void wlr_input_method_v2_send_unavailable( | ||
|
@@ -390,7 +528,9 @@ static void manager_get_input_method(struct wl_client *client, | |
wl_client_post_no_memory(client); | ||
return; | ||
} | ||
wl_list_init(&input_method->popup_surfaces); | ||
wl_signal_init(&input_method->events.commit); | ||
wl_signal_init(&input_method->events.new_popup_surface); | ||
wl_signal_init(&input_method->events.grab_keyboard); | ||
wl_signal_init(&input_method->events.destroy); | ||
int version = wl_resource_get_version(resource); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Protocol issue: the compositor has no way to know when the client has taken this new information into account. Thus the compositor might draw an old buffer at a new position, resulting in a glitch.