commit 0013242

Michael Forney  ·  2017-02-06 19:17:51 +0000 UTC
parent cabf369
Update pointer focus on surface resize, move, show, and hide

Otherwise, the focus won't change until we move the mouse over the new
surface.
1 files changed,  +33, -23
+33, -23
 1@@ -174,6 +174,30 @@ error0:
 2 	return NULL;
 3 }
 4 
 5+static void
 6+update_pointer_focus(void)
 7+{
 8+	struct compositor_view *view;
 9+	bool found = false;
10+	int32_t x = wl_fixed_to_int(swc.seat->pointer->x);
11+	int32_t y = wl_fixed_to_int(swc.seat->pointer->y);
12+	struct swc_rectangle *geom;
13+
14+	wl_list_for_each (view, &compositor.views, link) {
15+		if (!view->visible)
16+			continue;
17+		geom = &view->base.geometry;
18+		if (rectangle_contains_point(geom, x, y)) {
19+			if (pixman_region32_contains_point(&view->surface->state.input, x - geom->x, y - geom->y, NULL)) {
20+				found = true;
21+				break;
22+			}
23+		}
24+	}
25+
26+	pointer_set_focus(swc.seat->pointer, found ? view : NULL);
27+}
28+
29 /* Rendering {{{ */
30 
31 static void
32@@ -379,6 +403,7 @@ attach(struct view *base, struct wld_buffer *buffer)
33 			view_update_screens(&view->base);
34 			damage_below_view(view);
35 			update(&view->base);
36+			update_pointer_focus();
37 		}
38 	}
39 
40@@ -406,6 +431,7 @@ move(struct view *base, int32_t x, int32_t y)
41 			view_update_screens(&view->base);
42 			damage_below_view(view);
43 			update(&view->base);
44+			update_pointer_focus();
45 		}
46 	}
47 
48@@ -499,6 +525,8 @@ compositor_view_show(struct compositor_view *view)
49 		if (other->parent == view)
50 			compositor_view_show(other);
51 	}
52+
53+	update_pointer_focus();
54 }
55 
56 void
57@@ -520,6 +548,8 @@ compositor_view_hide(struct compositor_view *view)
58 		if (other->parent == view)
59 			compositor_view_hide(other);
60 	}
61+
62+	update_pointer_focus();
63 }
64 
65 void
66@@ -684,29 +714,9 @@ perform_update(void *data)
67 bool
68 handle_motion(struct pointer_handler *handler, uint32_t time, wl_fixed_t fx, wl_fixed_t fy)
69 {
70-	struct compositor_view *view;
71-	bool found = false;
72-	int32_t x = wl_fixed_to_int(fx), y = wl_fixed_to_int(fy);
73-	struct swc_rectangle *geom;
74-
75-	/* If buttons are pressed, don't change pointer focus. */
76-	if (swc.seat->pointer->buttons.size > 0)
77-		return false;
78-
79-	wl_list_for_each (view, &compositor.views, link) {
80-		if (!view->visible)
81-			continue;
82-		geom = &view->base.geometry;
83-		if (rectangle_contains_point(geom, x, y)) {
84-			if (pixman_region32_contains_point(&view->surface->state.input, x - geom->x, y - geom->y, NULL)) {
85-				found = true;
86-				break;
87-			}
88-		}
89-	}
90-
91-	pointer_set_focus(swc.seat->pointer, found ? view : NULL);
92-
93+	/* Only change pointer focus if no buttons are pressed. */
94+	if (swc.seat->pointer->buttons.size == 0)
95+		update_pointer_focus();
96 	return false;
97 }
98