commit d148560f50ce81bd5ca0e0f0d52c65c21f8b751d
parent 30434b2beb0c621015452775011426da8d5e4705
Author: ShootingStarDragons <ShootingStarDragons@protonmail.com>
Date: Thu, 20 Mar 2025 21:58:21 +0900
text_input: Fix ime panic in ext-session-lock
in the origin text_input.c, we only check the sway_view and layershell,
but now we have the third shell named sessionlock, so we need to modify
both text_input.c and view.c to handle the new type of shell
Diffstat:
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/sway/input/text_input.c b/sway/input/text_input.c
@@ -10,6 +10,7 @@
#include "sway/input/text_input_popup.h"
#include "sway/layers.h"
#include "sway/server.h"
+#include <wlr/types/wlr_session_lock_v1.h>
static struct sway_text_input *relay_get_focusable_text_input(
struct sway_input_method_relay *relay) {
@@ -385,6 +386,8 @@ static void input_popup_set_focus(struct sway_input_popup *popup,
struct wlr_layer_surface_v1 *layer_surface =
wlr_layer_surface_v1_try_from_wlr_surface(surface);
+ struct wlr_session_lock_surface_v1 *lock_surface =
+ wlr_session_lock_surface_v1_try_from_wlr_surface(surface);
struct wlr_scene_tree *relative_parent;
if (layer_surface) {
@@ -404,8 +407,30 @@ static void input_popup_set_focus(struct sway_input_popup *popup,
// surface. Layer surfaces get destroyed as part of the output being
// destroyed, thus also trickling down to popups.
popup->fixed_output = layer->layer_surface->output;
+ } else if (lock_surface) {
+ wl_signal_add(&lock_surface->surface->events.unmap,
+ &popup->focused_surface_unmap);
+
+ struct sway_layer_surface *lock = lock_surface->data;
+ if (lock == NULL) {
+ return;
+ }
+
+ relative_parent = lock->scene->tree;
+ popup->desc.view = NULL;
+
+ // we don't need to add an event here to NULL out this field because
+ // this field will only be initialized if the popup is part of a layer
+ // surface. Layer surfaces get destroyed as part of the output being
+ // destroyed, thus also trickling down to popups.
+ popup->fixed_output = lock->layer_surface->output;
} else {
struct sway_view *view = view_from_wlr_surface(surface);
+ // In the future there may be other shells been added, so we also need to check here.
+ if (view == NULL) {
+ sway_log(SWAY_DEBUG, "Unsupported IME focus surface");
+ return;
+ }
wl_signal_add(&view->events.unmap, &popup->focused_surface_unmap);
relative_parent = view->scene_tree;
popup->desc.view = view;
diff --git a/sway/tree/view.c b/sway/tree/view.c
@@ -12,6 +12,7 @@
#include <wlr/types/wlr_server_decoration.h>
#include <wlr/types/wlr_subcompositor.h>
#include <wlr/types/wlr_xdg_decoration_v1.h>
+#include <wlr/types/wlr_session_lock_v1.h>
#if WLR_HAS_XWAYLAND
#include <wlr/xwayland.h>
#endif
@@ -1010,6 +1011,9 @@ struct sway_view *view_from_wlr_surface(struct wlr_surface *wlr_surface) {
if (wlr_layer_surface_v1_try_from_wlr_surface(wlr_surface) != NULL) {
return NULL;
}
+ if (wlr_session_lock_surface_v1_try_from_wlr_surface(wlr_surface) != NULL) {
+ return NULL;
+ }
const char *role = wlr_surface->role ? wlr_surface->role->name : NULL;
sway_log(SWAY_DEBUG, "Surface of unknown type (role %s): %p",