+int
+get_ws_idx(xcb_window_t id)
+{
+ int ws_idx = -1;
+ char *prop = NULL;
+ size_t proplen;
+ const char *errstr;
+ xcb_get_property_reply_t *gpr;
+
+ gpr = xcb_get_property_reply(conn,
+ xcb_get_property(conn, 0, id, a_swm_ws,
+ XCB_ATOM_STRING, 0, SWM_PROPLEN),
+ NULL);
+ if (!gpr)
+ return (-1);
+ if (gpr->type) {
+ proplen = xcb_get_property_value_length(gpr);
+ if (proplen > 0) {
+ prop = malloc(proplen + 1);
+ if (prop) {
+ memcpy(prop,
+ xcb_get_property_value(gpr),
+ proplen);
+ prop[proplen] = '\0';
+ }
+ }
+ }
+ free(gpr);
+
+ if (prop) {
+ DNPRINTF(SWM_D_PROP, "get_ws_idx: _SWM_WS: %s\n", prop);
+ ws_idx = (int)strtonum(prop, 0, workspace_limit - 1, &errstr);
+ if (errstr) {
+ DNPRINTF(SWM_D_PROP, "get_ws_idx: window: #%s: %s",
+ errstr, prop);
+ }
+ free(prop);
+ }
+
+ return ws_idx;
+}
+