From 2e83d2193eab403673340c19dd785f2708be12b3 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Fri, 22 Sep 2017 19:22:48 +0300 Subject: [PATCH] Add con_exists function Checks the all_cons queue and returns true if a given con is found. --- include/con.h | 7 +++++++ src/con.c | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/include/con.h b/include/con.h index 6cd1ef3e..674ee61d 100644 --- a/include/con.h +++ b/include/con.h @@ -165,6 +165,13 @@ Con *con_by_window_id(xcb_window_t window); */ Con *con_by_con_id(long target); +/** + * Returns true if the given container (still) exists. + * This can be used, e.g., to make sure a container hasn't been closed in the meantime. + * + */ +bool con_exists(Con *con); + /** * Returns the container with the given frame ID or NULL if no such container * exists. diff --git a/src/con.c b/src/con.c index 2e22619f..fcde4c10 100644 --- a/src/con.c +++ b/src/con.c @@ -604,6 +604,15 @@ Con *con_by_con_id(long target) { return NULL; } +/* + * Returns true if the given container (still) exists. + * This can be used, e.g., to make sure a container hasn't been closed in the meantime. + * + */ +bool con_exists(Con *con) { + return con_by_con_id((long)con) != NULL; +} + /* * Returns the container with the given frame ID or NULL if no such container * exists. -- 2.39.5