Discussion:
[PATCH 1/3] Revert "Fix a crash when unlocking or unconfining a pointer"
(too old to reply)
Dima Ryazanov
2018-11-15 06:25:53 UTC
Permalink
This reverts commit e0dc5d47cb5f29deec495efd958fcd5f6f833389.

Signed-off-by: Dima Ryazanov <***@gmail.com>
---
clients/window.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/clients/window.c b/clients/window.c
index 12939cb7..1ab33545 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -286,7 +286,6 @@ struct window {
confined_pointer_unconfined_handler_t pointer_unconfined_handler;

struct zwp_confined_pointer_v1 *confined_pointer;
- struct input *confined_input;
struct widget *confined_widget;
bool confined;

@@ -4793,8 +4792,8 @@ static void
locked_pointer_locked(void *data,
struct zwp_locked_pointer_v1 *locked_pointer)
{
- struct window *window = data;
- struct input *input = window->locked_input;
+ struct input *input = data;
+ struct window *window = input->pointer_focus;

window->pointer_locked = true;

@@ -4809,8 +4808,8 @@ static void
locked_pointer_unlocked(void *data,
struct zwp_locked_pointer_v1 *locked_pointer)
{
- struct window *window = data;
- struct input *input = window->locked_input;
+ struct input *input = data;
+ struct window *window = input->pointer_focus;

window_unlock_pointer(window);

@@ -4865,7 +4864,7 @@ window_lock_pointer(struct window *window, struct input *input)
ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT);
zwp_locked_pointer_v1_add_listener(locked_pointer,
&locked_pointer_listener,
- window);
+ input);

window->locked_input = input;
window->locked_pointer = locked_pointer;
@@ -4907,8 +4906,8 @@ static void
confined_pointer_confined(void *data,
struct zwp_confined_pointer_v1 *confined_pointer)
{
- struct window *window = data;
- struct input *input = window->confined_input;
+ struct input *input = data;
+ struct window *window = input->pointer_focus;

window->confined = true;

@@ -4923,8 +4922,8 @@ static void
confined_pointer_unconfined(void *data,
struct zwp_confined_pointer_v1 *confined_pointer)
{
- struct window *window = data;
- struct input *input = window->confined_input;
+ struct input *input = data;
+ struct window *window = input->pointer_focus;

window_unconfine_pointer(window);

@@ -4989,9 +4988,8 @@ window_confine_pointer_to_rectangles(struct window *window,

zwp_confined_pointer_v1_add_listener(confined_pointer,
&confined_pointer_listener,
- window);
+ input);

- window->confined_input = input;
window->confined_pointer = confined_pointer;
window->confined_widget = NULL;

@@ -5052,7 +5050,6 @@ window_unconfine_pointer(struct window *window)
zwp_confined_pointer_v1_destroy(window->confined_pointer);
window->confined_pointer = NULL;
window->confined = false;
- window->confined_input = NULL;
}

static void
--
2.19.1
Dima Ryazanov
2018-11-15 06:25:54 UTC
Permalink
Signed-off-by: Dima Ryazanov <***@gmail.com>
---
clients/window.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/clients/window.c b/clients/window.c
index 1ab33545..470ac090 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -278,7 +278,6 @@ struct window {

struct zwp_relative_pointer_v1 *relative_pointer;
struct zwp_locked_pointer_v1 *locked_pointer;
- struct input *locked_input;
bool pointer_locked;
locked_pointer_locked_handler_t pointer_locked_handler;
locked_pointer_unlocked_handler_t pointer_unlocked_handler;
@@ -4866,7 +4865,6 @@ window_lock_pointer(struct window *window, struct input *input)
&locked_pointer_listener,
input);

- window->locked_input = input;
window->locked_pointer = locked_pointer;
window->relative_pointer = relative_pointer;

@@ -4884,7 +4882,6 @@ window_unlock_pointer(struct window *window)
window->locked_pointer = NULL;
window->relative_pointer = NULL;
window->pointer_locked = false;
- window->locked_input = NULL;
}

void
--
2.19.1
Dima Ryazanov
2018-11-15 06:25:55 UTC
Permalink
This is a rewrite of the fix in:
https://lists.freedesktop.org/archives/wayland-devel/2018-May/038140.html

It addresses Pekka's concerns about window getting destroyed before the
unlock/unconfine event is triggered.

Signed-off-by: Dima Ryazanov <***@gmail.com>
---
clients/window.c | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/clients/window.c b/clients/window.c
index 470ac090..d55d27eb 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -343,6 +343,8 @@ struct input {
struct window *pointer_focus;
struct window *keyboard_focus;
struct window *touch_focus;
+ struct window *locked_window;
+ struct window *confined_window;
int current_cursor;
uint32_t cursor_anim_start;
struct wl_callback *cursor_frame_cb;
@@ -1584,6 +1586,10 @@ window_destroy(struct window *window)
input->pointer_focus = NULL;
if (input->keyboard_focus == window)
input->keyboard_focus = NULL;
+ if (input->locked_window == window)
+ input->locked_window = NULL;
+ if (input->confined_window == window)
+ input->confined_window = NULL;
if (input->focus_widget &&
input->focus_widget->window == window)
input->focus_widget = NULL;
@@ -4792,7 +4798,10 @@ locked_pointer_locked(void *data,
struct zwp_locked_pointer_v1 *locked_pointer)
{
struct input *input = data;
- struct window *window = input->pointer_focus;
+ struct window *window = input->locked_window;
+
+ if (!window)
+ return;

window->pointer_locked = true;

@@ -4808,10 +4817,15 @@ locked_pointer_unlocked(void *data,
struct zwp_locked_pointer_v1 *locked_pointer)
{
struct input *input = data;
- struct window *window = input->pointer_focus;
+ struct window *window = input->locked_window;
+
+ if (!window)
+ return;

window_unlock_pointer(window);

+ input->locked_window = NULL;
+
if (window->pointer_unlocked_handler) {
window->pointer_unlocked_handler(window,
input,
@@ -4867,6 +4881,7 @@ window_lock_pointer(struct window *window, struct input *input)

window->locked_pointer = locked_pointer;
window->relative_pointer = relative_pointer;
+ input->locked_window = window;

return 0;
}
@@ -4904,7 +4919,10 @@ confined_pointer_confined(void *data,
struct zwp_confined_pointer_v1 *confined_pointer)
{
struct input *input = data;
- struct window *window = input->pointer_focus;
+ struct window *window = input->confined_window;
+
+ if (!window)
+ return;

window->confined = true;

@@ -4920,11 +4938,15 @@ confined_pointer_unconfined(void *data,
struct zwp_confined_pointer_v1 *confined_pointer)
{
struct input *input = data;
- struct window *window = input->pointer_focus;
+ struct window *window = input->confined_window;
+
+ if (!window)
+ return;

window_unconfine_pointer(window);

window->confined = false;
+ input->confined_window = NULL;

if (window->pointer_unconfined_handler) {
window->pointer_unconfined_handler(window,
@@ -4989,6 +5011,7 @@ window_confine_pointer_to_rectangles(struct window *window,

window->confined_pointer = confined_pointer;
window->confined_widget = NULL;
+ input->confined_window = window;

return 0;
}
--
2.19.1
Loading...