@ -4863,15 +4863,17 @@ static const struct zwp_confined_pointer_v1_listener confined_pointer_listener =
} ;
} ;
int
int
window_confine_pointer_to_widget ( struct window * window ,
window_confine_pointer_to_rectangles ( struct window * window ,
struct widget * widget ,
struct input * input ,
struct input * input )
struct rectangle * rectangles ,
int num_rectangles )
{
{
struct zwp_pointer_constraints_v1 * pointer_constraints =
struct zwp_pointer_constraints_v1 * pointer_constraints =
window - > display - > pointer_constraints ;
window - > display - > pointer_constraints ;
struct zwp_confined_pointer_v1 * confined_pointer ;
struct zwp_confined_pointer_v1 * confined_pointer ;
struct wl_compositor * compositor = window - > display - > compositor ;
struct wl_compositor * compositor = window - > display - > compositor ;
struct wl_region * region = NULL ;
struct wl_region * region = NULL ;
int i ;
if ( ! window - > display - > pointer_constraints )
if ( ! window - > display - > pointer_constraints )
return - 1 ;
return - 1 ;
@ -4885,13 +4887,15 @@ window_confine_pointer_to_widget(struct window *window,
if ( ! input - > pointer )
if ( ! input - > pointer )
return - 1 ;
return - 1 ;
if ( widget ) {
if ( num_rectangles > = 1 ) {
region = wl_compositor_create_region ( compositor ) ;
region = wl_compositor_create_region ( compositor ) ;
for ( i = 0 ; i < num_rectangles ; i + + ) {
wl_region_add ( region ,
wl_region_add ( region ,
widget - > allocation . x ,
rectangles [ i ] . x ,
widget - > allocation . y ,
rectangles [ i ] . y ,
widget - > allocation . width ,
rectangles [ i ] . width ,
widget - > allocation . height ) ;
rectangles [ i ] . height ) ;
}
}
}
confined_pointer =
confined_pointer =
@ -4908,11 +4912,56 @@ window_confine_pointer_to_widget(struct window *window,
input ) ;
input ) ;
window - > confined_pointer = confined_pointer ;
window - > confined_pointer = confined_pointer ;
window - > confined_widget = widget ;
window - > confined_widget = NULL ;
return 0 ;
return 0 ;
}
}
void
window_update_confine_rectangles ( struct window * window ,
struct rectangle * rectangles ,
int num_rectangles )
{
struct wl_compositor * compositor = window - > display - > compositor ;
struct wl_region * region ;
int i ;
region = wl_compositor_create_region ( compositor ) ;
for ( i = 0 ; i < num_rectangles ; i + + ) {
wl_region_add ( region ,
rectangles [ i ] . x ,
rectangles [ i ] . y ,
rectangles [ i ] . width ,
rectangles [ i ] . height ) ;
}
zwp_confined_pointer_v1_set_region ( window - > confined_pointer , region ) ;
wl_region_destroy ( region ) ;
}
int
window_confine_pointer_to_widget ( struct window * window ,
struct widget * widget ,
struct input * input )
{
int ret ;
if ( widget ) {
ret = window_confine_pointer_to_rectangles ( window ,
input ,
& widget - > allocation ,
1 ) ;
window - > confined_widget = widget ;
return ret ;
} else {
return window_confine_pointer_to_rectangles ( window ,
input ,
NULL ,
0 ) ;
}
}
void
void
window_unconfine_pointer ( struct window * window )
window_unconfine_pointer ( struct window * window )
{
{