From: Orestis Floros Date: Sat, 17 Mar 2018 18:42:54 +0000 (+0200) Subject: Introduce get_output_from_rect X-Git-Tag: 4.16~120^2~2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8a3ef3a81bd4946777c7e3585384283bf12d89be;p=i3%2Fi3 Introduce get_output_from_rect --- diff --git a/include/randr.h b/include/randr.h index d365a9e4..39182c54 100644 --- a/include/randr.h +++ b/include/randr.h @@ -88,6 +88,14 @@ Output *get_output_by_name(const char *name, const bool require_active); */ Output *get_output_containing(unsigned int x, unsigned int y); +/** + * Returns the active output which contains the midpoint of the given rect. If + * such an output doesn't exist, returns the output which contains most of the + * rectangle or NULL if there is no output which intersects with it. + * + */ +Output *get_output_from_rect(Rect rect); + /** * Returns the active output which spans exactly the area specified by * rect or NULL if there is no output like this. diff --git a/src/randr.c b/src/randr.c index efdd0352..c43c6455 100644 --- a/src/randr.c +++ b/src/randr.c @@ -114,6 +114,20 @@ Output *get_output_containing(unsigned int x, unsigned int y) { return NULL; } +/* + * Returns the active output which contains the midpoint of the given rect. If + * such an output doesn't exist, returns the output which contains most of the + * rectangle or NULL if there is no output which intersects with it. + * + */ +Output *get_output_from_rect(Rect rect) { + unsigned int mid_x = rect.x + rect.width / 2; + unsigned int mid_y = rect.y + rect.height / 2; + Output *output = get_output_containing(mid_x, mid_y); + + return output ? output : output_containing_rect(rect); +} + /* * Returns the active output which spans exactly the area specified by * rect or NULL if there is no output like this.