@ -4,7 +4,7 @@
static const struct xdg_positioner_interface xdg_positioner_implementation ;
static const struct xdg_positioner_interface xdg_positioner_implementation ;
struct wlr_xdg_positioner _resource * get _xdg_positioner_from_resource(
struct wlr_xdg_positioner * wlr _xdg_positioner_from_resource(
struct wl_resource * resource ) {
struct wl_resource * resource ) {
assert ( wl_resource_instance_of ( resource , & xdg_positioner_interface ,
assert ( wl_resource_instance_of ( resource , & xdg_positioner_interface ,
& xdg_positioner_implementation ) ) ;
& xdg_positioner_implementation ) ) ;
@ -13,8 +13,8 @@ struct wlr_xdg_positioner_resource *get_xdg_positioner_from_resource(
static void xdg_positioner_handle_set_size ( struct wl_client * client ,
static void xdg_positioner_handle_set_size ( struct wl_client * client ,
struct wl_resource * resource , int32_t width , int32_t height ) {
struct wl_resource * resource , int32_t width , int32_t height ) {
struct wlr_xdg_positioner _resource * positioner =
struct wlr_xdg_positioner * positioner =
get _xdg_positioner_from_resource( resource ) ;
wlr _xdg_positioner_from_resource( resource ) ;
if ( width < 1 | | height < 1 ) {
if ( width < 1 | | height < 1 ) {
wl_resource_post_error ( resource ,
wl_resource_post_error ( resource ,
@ -23,15 +23,15 @@ static void xdg_positioner_handle_set_size(struct wl_client *client,
return ;
return ;
}
}
positioner - > att rs. size . width = width ;
positioner - > rule s. size . width = width ;
positioner - > att rs. size . height = height ;
positioner - > rule s. size . height = height ;
}
}
static void xdg_positioner_handle_set_anchor_rect ( struct wl_client * client ,
static void xdg_positioner_handle_set_anchor_rect ( struct wl_client * client ,
struct wl_resource * resource , int32_t x , int32_t y , int32_t width ,
struct wl_resource * resource , int32_t x , int32_t y , int32_t width ,
int32_t height ) {
int32_t height ) {
struct wlr_xdg_positioner _resource * positioner =
struct wlr_xdg_positioner * positioner =
get _xdg_positioner_from_resource( resource ) ;
wlr _xdg_positioner_from_resource( resource ) ;
if ( width < 0 | | height < 0 ) {
if ( width < 0 | | height < 0 ) {
wl_resource_post_error ( resource ,
wl_resource_post_error ( resource ,
@ -40,16 +40,16 @@ static void xdg_positioner_handle_set_anchor_rect(struct wl_client *client,
return ;
return ;
}
}
positioner - > att rs. anchor_rect . x = x ;
positioner - > rule s. anchor_rect . x = x ;
positioner - > att rs. anchor_rect . y = y ;
positioner - > rule s. anchor_rect . y = y ;
positioner - > att rs. anchor_rect . width = width ;
positioner - > rule s. anchor_rect . width = width ;
positioner - > att rs. anchor_rect . height = height ;
positioner - > rule s. anchor_rect . height = height ;
}
}
static void xdg_positioner_handle_set_anchor ( struct wl_client * client ,
static void xdg_positioner_handle_set_anchor ( struct wl_client * client ,
struct wl_resource * resource , uint32_t anchor ) {
struct wl_resource * resource , uint32_t anchor ) {
struct wlr_xdg_positioner _resource * positioner =
struct wlr_xdg_positioner * positioner =
get _xdg_positioner_from_resource( resource ) ;
wlr _xdg_positioner_from_resource( resource ) ;
if ( anchor > XDG_POSITIONER_ANCHOR_BOTTOM_RIGHT ) {
if ( anchor > XDG_POSITIONER_ANCHOR_BOTTOM_RIGHT ) {
wl_resource_post_error ( resource ,
wl_resource_post_error ( resource ,
@ -58,13 +58,13 @@ static void xdg_positioner_handle_set_anchor(struct wl_client *client,
return ;
return ;
}
}
positioner - > att rs. anchor = anchor ;
positioner - > rule s. anchor = anchor ;
}
}
static void xdg_positioner_handle_set_gravity ( struct wl_client * client ,
static void xdg_positioner_handle_set_gravity ( struct wl_client * client ,
struct wl_resource * resource , uint32_t gravity ) {
struct wl_resource * resource , uint32_t gravity ) {
struct wlr_xdg_positioner _resource * positioner =
struct wlr_xdg_positioner * positioner =
get _xdg_positioner_from_resource( resource ) ;
wlr _xdg_positioner_from_resource( resource ) ;
if ( gravity > XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT ) {
if ( gravity > XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT ) {
wl_resource_post_error ( resource ,
wl_resource_post_error ( resource ,
@ -73,25 +73,25 @@ static void xdg_positioner_handle_set_gravity(struct wl_client *client,
return ;
return ;
}
}
positioner - > att rs. gravity = gravity ;
positioner - > rule s. gravity = gravity ;
}
}
static void xdg_positioner_handle_set_constraint_adjustment (
static void xdg_positioner_handle_set_constraint_adjustment (
struct wl_client * client , struct wl_resource * resource ,
struct wl_client * client , struct wl_resource * resource ,
uint32_t constraint_adjustment ) {
uint32_t constraint_adjustment ) {
struct wlr_xdg_positioner _resource * positioner =
struct wlr_xdg_positioner * positioner =
get _xdg_positioner_from_resource( resource ) ;
wlr _xdg_positioner_from_resource( resource ) ;
positioner - > att rs. constraint_adjustment = constraint_adjustment ;
positioner - > rule s. constraint_adjustment = constraint_adjustment ;
}
}
static void xdg_positioner_handle_set_offset ( struct wl_client * client ,
static void xdg_positioner_handle_set_offset ( struct wl_client * client ,
struct wl_resource * resource , int32_t x , int32_t y ) {
struct wl_resource * resource , int32_t x , int32_t y ) {
struct wlr_xdg_positioner _resource * positioner =
struct wlr_xdg_positioner * positioner =
get _xdg_positioner_from_resource( resource ) ;
wlr _xdg_positioner_from_resource( resource ) ;
positioner - > att rs. offset . x = x ;
positioner - > rule s. offset . x = x ;
positioner - > att rs. offset . y = y ;
positioner - > rule s. offset . y = y ;
}
}
static void xdg_positioner_handle_destroy ( struct wl_client * client ,
static void xdg_positioner_handle_destroy ( struct wl_client * client ,
@ -113,14 +113,13 @@ static const struct xdg_positioner_interface
static void xdg_positioner_handle_resource_destroy (
static void xdg_positioner_handle_resource_destroy (
struct wl_resource * resource ) {
struct wl_resource * resource ) {
struct wlr_xdg_positioner _resource * positioner =
struct wlr_xdg_positioner * positioner =
get _xdg_positioner_from_resource( resource ) ;
wlr _xdg_positioner_from_resource( resource ) ;
free ( positioner ) ;
free ( positioner ) ;
}
}
void create_xdg_positioner ( struct wlr_xdg_client * client , uint32_t id ) {
void create_xdg_positioner ( struct wlr_xdg_client * client , uint32_t id ) {
struct wlr_xdg_positioner_resource * positioner =
struct wlr_xdg_positioner * positioner = calloc ( 1 , sizeof ( * positioner ) ) ;
calloc ( 1 , sizeof ( struct wlr_xdg_positioner_resource ) ) ;
if ( positioner = = NULL ) {
if ( positioner = = NULL ) {
wl_client_post_no_memory ( client - > client ) ;
wl_client_post_no_memory ( client - > client ) ;
return ;
return ;
@ -171,60 +170,40 @@ static bool positioner_gravity_has_edge(enum xdg_positioner_gravity gravity,
( enum xdg_positioner_anchor ) edge ) ;
( enum xdg_positioner_anchor ) edge ) ;
}
}
struct wlr_box wlr_xdg_positioner_get_geometry (
void wlr_xdg_positioner_rules_get_geometry (
struct wlr_xdg_positioner * positioner ) {
struct wlr_xdg_positioner_rules * rules , struct wlr_box * box ) {
struct wlr_box geometry = {
box - > x = rules - > offset . x ;
. x = positioner - > offset . x ,
box - > y = rules - > offset . y ;
. y = positioner - > offset . y ,
box - > width = rules - > size . width ;
. width = positioner - > size . width ,
box - > height = rules - > size . height ;
. height = positioner - > size . height ,
} ;
if ( positioner_anchor_has_edge ( rules - > anchor , XDG_POSITIONER_ANCHOR_TOP ) ) {
box - > y + = rules - > anchor_rect . y ;
if ( positioner_anchor_has_edge ( positioner - > anchor ,
} else if ( positioner_anchor_has_edge ( rules - > anchor , XDG_POSITIONER_ANCHOR_BOTTOM ) ) {
XDG_POSITIONER_ANCHOR_TOP ) ) {
box - > y + = rules - > anchor_rect . y + rules - > anchor_rect . height ;
geometry . y + = positioner - > anchor_rect . y ;
} else if ( positioner_anchor_has_edge ( positioner - > anchor ,
XDG_POSITIONER_ANCHOR_BOTTOM ) ) {
geometry . y + =
positioner - > anchor_rect . y + positioner - > anchor_rect . height ;
} else {
} else {
geometry . y + =
box - > y + = rules - > anchor_rect . y + rules - > anchor_rect . height / 2 ;
positioner - > anchor_rect . y + positioner - > anchor_rect . height / 2 ;
}
}
if ( positioner_anchor_has_edge ( positioner - > anchor ,
if ( positioner_anchor_has_edge ( rules - > anchor , XDG_POSITIONER_ANCHOR_LEFT ) ) {
XDG_POSITIONER_ANCHOR_LEFT ) ) {
box - > x + = rules - > anchor_rect . x ;
geometry . x + = positioner - > anchor_rect . x ;
} else if ( positioner_anchor_has_edge ( rules - > anchor , XDG_POSITIONER_ANCHOR_RIGHT ) ) {
} else if ( positioner_anchor_has_edge ( positioner - > anchor ,
box - > x + = rules - > anchor_rect . x + rules - > anchor_rect . width ;
XDG_POSITIONER_ANCHOR_RIGHT ) ) {
geometry . x + = positioner - > anchor_rect . x + positioner - > anchor_rect . width ;
} else {
} else {
geometry . x + =
box - > x + = rules - > anchor_rect . x + rules - > anchor_rect . width / 2 ;
positioner - > anchor_rect . x + positioner - > anchor_rect . width / 2 ;
}
}
if ( positioner_gravity_has_edge ( positioner - > gravity ,
if ( positioner_gravity_has_edge ( rules - > gravity , XDG_POSITIONER_GRAVITY_TOP ) ) {
XDG_POSITIONER_GRAVITY_TOP ) ) {
box - > y - = box - > height ;
geometry . y - = geometry . height ;
} else if ( ! positioner_gravity_has_edge ( rules - > gravity , XDG_POSITIONER_GRAVITY_BOTTOM ) ) {
} else if ( ! positioner_gravity_has_edge ( positioner - > gravity ,
box - > y - = box - > height / 2 ;
XDG_POSITIONER_GRAVITY_BOTTOM ) ) {
geometry . y - = geometry . height / 2 ;
}
}
if ( positioner_gravity_has_edge ( positioner - > gravity ,
if ( positioner_gravity_has_edge ( rules - > gravity , XDG_POSITIONER_GRAVITY_LEFT ) ) {
XDG_POSITIONER_GRAVITY_LEFT ) ) {
box - > x - = box - > width ;
geometry . x - = geometry . width ;
} else if ( ! positioner_gravity_has_edge ( rules - > gravity , XDG_POSITIONER_GRAVITY_RIGHT ) ) {
} else if ( ! positioner_gravity_has_edge ( positioner - > gravity ,
box - > x - = box - > width / 2 ;
XDG_POSITIONER_GRAVITY_RIGHT ) ) {
geometry . x - = geometry . width / 2 ;
}
}
if ( positioner - > constraint_adjustment = =
XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_NONE ) {
return geometry ;
}
return geometry ;
}
}
static enum xdg_positioner_anchor positioner_anchor_invert_x (
static enum xdg_positioner_anchor positioner_anchor_invert_x (
@ -281,13 +260,12 @@ static enum xdg_positioner_gravity positioner_gravity_invert_y(
( enum xdg_positioner_anchor ) gravity ) ;
( enum xdg_positioner_anchor ) gravity ) ;
}
}
void wlr_xdg_positioner_rules_invert_x ( struct wlr_xdg_positioner_rules * rules ) {
void wlr_positioner_invert_x ( struct wlr_xdg_positioner * positioner ) {
rules - > anchor = positioner_anchor_invert_x ( rules - > anchor ) ;
positioner - > anchor = positioner_anchor_invert_x ( positioner - > anchor ) ;
rules - > gravity = positioner_gravity_invert_x ( rules - > gravity ) ;
positioner - > gravity = positioner_gravity_invert_x ( positioner - > gravity ) ;
}
}
void wlr_ positioner_invert_y( struct wlr_xdg_positioner * positioner ) {
void wlr_ xdg_ positioner_rules _invert_y( struct wlr_xdg_positioner _rules * rules ) {
positioner- > anchor = positioner_anchor_invert_y ( positioner - > anchor ) ;
rules- > anchor = positioner_anchor_invert_y ( rules - > anchor ) ;
positioner- > gravity = positioner_gravity_invert_y ( positioner - > gravity ) ;
rules- > gravity = positioner_gravity_invert_y ( rules - > gravity ) ;
}
}