-
- /* Check if we need to change something or if we’re already there */
- if (c_ws->screen->current_workspace == (workspace-1)) {
- if (CUR_CELL->currently_focused != NULL) {
- set_focus(conn, CUR_CELL->currently_focused, true);
- if (need_warp) {
- warp_pointer_into(conn, CUR_CELL->currently_focused);
- xcb_flush(conn);
- }
- }
- return;
- }
-
- t_ws->screen->current_workspace = workspace-1;
-
- /* TODO: does grabbing the server actually bring us any (speed)advantages? */
- //xcb_grab_server(conn);
-
- ignore_enter_notify_forall(conn, c_ws, true);
-
- /* Unmap all clients of the current workspace */
- int unmapped_clients = 0;
- FOR_TABLE(c_ws)
- CIRCLEQ_FOREACH(client, &(c_ws->table[cols][rows]->clients), clients) {
- xcb_unmap_window(conn, client->frame);
- unmapped_clients++;
- }
-
- /* If we did not unmap any clients, the workspace is empty and we can destroy it */
- if (unmapped_clients == 0)
- c_ws->screen = NULL;
-
- /* Unmap the stack windows on the current workspace, if any */
- struct Stack_Window *stack_win;
- SLIST_FOREACH(stack_win, &stack_wins, stack_windows)
- if (stack_win->container->workspace == c_ws)
- xcb_unmap_window(conn, stack_win->window);
-
- ignore_enter_notify_forall(conn, c_ws, false);
-
- c_ws = &workspaces[workspace-1];
- current_row = c_ws->current_row;
- current_col = c_ws->current_col;
- LOG("new current row = %d, current col = %d\n", current_row, current_col);
-
- ignore_enter_notify_forall(conn, c_ws, true);
-
- /* Map all clients on the new workspace */
- FOR_TABLE(c_ws)
- CIRCLEQ_FOREACH(client, &(c_ws->table[cols][rows]->clients), clients)
- xcb_map_window(conn, client->frame);
-
- /* Map all stack windows, if any */
- SLIST_FOREACH(stack_win, &stack_wins, stack_windows)
- if (stack_win->container->workspace == c_ws)
- xcb_map_window(conn, stack_win->window);
-
- ignore_enter_notify_forall(conn, c_ws, false);
-
- /* Restore focus on the new workspace */
- if (CUR_CELL->currently_focused != NULL) {
- set_focus(conn, CUR_CELL->currently_focused, true);
- if (need_warp) {
- warp_pointer_into(conn, CUR_CELL->currently_focused);
- xcb_flush(conn);
- }
- } else xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, root, XCB_CURRENT_TIME);
-
- //xcb_ungrab_server(conn);
-
- render_layout(conn);
-}
-
-/*
- * Checks if the given window class and title match the given client
- * Window title is passed as "normal" string and as UCS-2 converted string for
- * matching _NET_WM_NAME capable clients as well as those using legacy hints.
- *
- */
-static bool client_matches_class_name(Client *client, char *to_class, char *to_title,
- char *to_title_ucs, int to_title_ucs_len) {
- /* Check if the given class is part of the window class */
- if (strcasestr(client->window_class, to_class) == NULL)
- return false;
-
- /* If no title was given, we’re done */
- if (to_title == NULL)
- return true;
-
- if (client->name_len > -1) {
- /* UCS-2 converted window titles */
- if (memmem(client->name, (client->name_len * 2), to_title_ucs, (to_title_ucs_len * 2)) == NULL)
- return false;
- } else {
- /* Legacy hints */
- if (strcasestr(client->name, to_title) == NULL)
- return false;
- }
-
- return true;