+ num_screens = get_screen_count();
+ for (i = 0; i < num_screens; ++i) {
+ for (j = 0; j < workspace_limit; ++j)
+ TAILQ_FOREACH(win, &screens[i].ws[j].winlist, entry)
+ ++count;
+
+ DNPRINTF(SWM_D_PROP, "ewmh_update_client_list: win count: %d\n",
+ count);
+
+ if (count == 0)
+ continue;
+
+ wins = calloc(count, sizeof(xcb_window_t));
+ if (wins == NULL)
+ err(1, "ewmh_update_client_list: calloc: failed to "
+ "allocate memory.");
+
+ for (j = 0, k = 0; j < workspace_limit; ++j)
+ TAILQ_FOREACH(win, &screens[i].ws[j].winlist, entry)
+ wins[k++] = win->id;
+
+ xcb_change_property(conn, XCB_PROP_MODE_REPLACE,
+ screens[i].root, ewmh[_NET_CLIENT_LIST].atom,
+ XCB_ATOM_WINDOW, 32, count, wins);
+
+ free(wins);
+ }
+}
+
+void
+ewmh_update_current_desktop(void)
+{
+ int num_screens, i;
+
+ num_screens = get_screen_count();
+ for (i = 0; i < num_screens; ++i)
+ xcb_change_property(conn, XCB_PROP_MODE_REPLACE,
+ screens[i].root, ewmh[_NET_CURRENT_DESKTOP].atom,
+ XCB_ATOM_CARDINAL, 32, 1, &screens[i].r_focus->ws->idx);
+}
+
+void
+ewmh_update_desktops(void)
+{
+ int num_screens, i, j;
+ uint32_t *vals;
+
+ vals = calloc(workspace_limit * 2, sizeof(uint32_t));
+ if (vals == NULL)
+ err(1, "ewmh_update_desktops: calloc: failed to allocate "
+ "memory.");
+
+ num_screens = get_screen_count();
+ for (i = 0; i < num_screens; i++) {
+ xcb_change_property(conn, XCB_PROP_MODE_REPLACE,
+ screens[i].root, ewmh[_NET_NUMBER_OF_DESKTOPS].atom,
+ XCB_ATOM_CARDINAL, 32, 1, &workspace_limit);
+
+ for (j = 0; j < workspace_limit; ++j) {
+ if (screens[i].ws[j].r != NULL) {
+ vals[j * 2] = X(screens[i].ws[j].r);
+ vals[j * 2 + 1] = Y(screens[i].ws[j].r);
+ } else if (screens[i].ws[j].old_r != NULL) {
+ vals[j * 2] = X(screens[i].ws[j].old_r);
+ vals[j * 2 + 1] = Y(screens[i].ws[j].old_r);
+ } else {
+ vals[j * 2] = vals[j * 2 + 1] = 0;
+ }
+ }
+
+ xcb_change_property(conn, XCB_PROP_MODE_REPLACE,
+ screens[i].root, ewmh[_NET_DESKTOP_VIEWPORT].atom,
+ XCB_ATOM_CARDINAL, 32, workspace_limit * 2, vals);
+ }
+
+ free(vals);
+}
+
+void
+search_resp_search_workspace(const char *resp)
+{
+ char *p, *q;
+ int ws_idx;
+ const char *errstr;
+ union arg a;
+
+ DNPRINTF(SWM_D_MISC, "search_resp_search_workspace: resp: %s\n", resp);
+
+ q = strdup(resp);
+ if (q == NULL) {
+ DNPRINTF(SWM_D_MISC, "search_resp_search_workspace: strdup: %s",
+ strerror(errno));
+ return;
+ }
+ p = strchr(q, ':');
+ if (p != NULL)
+ *p = '\0';
+ ws_idx = (int)strtonum(q, 1, workspace_limit, &errstr);
+ if (errstr) {
+ DNPRINTF(SWM_D_MISC, "workspace idx is %s: %s",
+ errstr, q);
+ free(q);
+ return;
+ }
+ free(q);
+ a.id = ws_idx - 1;
+ switchws(search_r, &a);
+}
+
+void
+search_resp_search_window(const char *resp)
+{
+ char *s;
+ int idx;
+ const char *errstr;
+ struct search_window *sw;
+
+ DNPRINTF(SWM_D_MISC, "search_resp_search_window: resp: %s\n", resp);
+
+ s = strdup(resp);
+ if (s == NULL) {
+ DNPRINTF(SWM_D_MISC, "search_resp_search_window: strdup: %s",
+ strerror(errno));
+ return;
+ }
+
+ idx = (int)strtonum(s, 1, INT_MAX, &errstr);
+ if (errstr) {
+ DNPRINTF(SWM_D_MISC, "window idx is %s: %s",
+ errstr, s);
+ free(s);
+ return;
+ }
+ free(s);
+
+ TAILQ_FOREACH(sw, &search_wl, entry)
+ if (idx == sw->idx) {
+ focus_win(sw->win);
+ break;
+ }
+}
+
+#define MAX_RESP_LEN 1024
+
+void
+search_do_resp(void)
+{
+ ssize_t rbytes;
+ char *resp;
+ size_t len;
+
+ DNPRINTF(SWM_D_MISC, "search_do_resp:\n");