From d8fab39242f683f84027402d8b174ff68a581811 Mon Sep 17 00:00:00 2001 From: Mathieu OTHACEHE Date: Wed, 7 Dec 2016 10:03:56 +0100 Subject: Add a function to find a screen matching a given XWindowAttributes It allows to find the screen associated to a Window, using it's x and y position. --- src/screen.c | 18 ++++++++++++++++++ src/screen.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/screen.c b/src/screen.c index b9bb696..7bbc133 100644 --- a/src/screen.c +++ b/src/screen.c @@ -165,6 +165,24 @@ find_screen (Window w) return NULL; } +/* Given a window attr, return the rp_screen struct */ +rp_screen * +find_screen_by_attr (XWindowAttributes attr) +{ + rp_screen *cur; + + list_for_each_entry (cur, &rp_screens, node) + { + if (attr.x >= cur->left && + attr.x <= cur->left + cur->width && + attr.y >= cur->top && + attr.y <= cur->top + cur->height) + return cur; + } + + return NULL; +} + /* Return 1 if w is a root window of any of the screens. */ int is_a_root_window (unsigned int w) diff --git a/src/screen.h b/src/screen.h index 67d8ab4..69bc032 100644 --- a/src/screen.h +++ b/src/screen.h @@ -36,6 +36,8 @@ rp_frame *screen_get_frame (rp_screen *s, int frame_num); rp_frame *screen_find_frame_by_frame (rp_screen *s, rp_frame *f); rp_screen *find_screen (Window w); +rp_screen *find_screen_by_attr (XWindowAttributes w); + void init_screens (void); void activate_screen (rp_screen *s); void deactivate_screen (rp_screen *s); -- cgit v1.2.3