-void set_focus(xcb_connection_t *conn, Client *client, bool set_anyways) {
- /* The dock window cannot be focused, but enter notifies are still handled correctly */
- if (client->dock)
- return;
-
- /* Store the old client */
- Client *old_client = SLIST_FIRST(&(c_ws->focus_stack));
-
- /* Check if the focus needs to be changed at all */
- if (!set_anyways && (old_client == client))
- return;
-
- /* Store current_row/current_col */
- c_ws->current_row = current_row;
- c_ws->current_col = current_col;
- c_ws = client->workspace;
- ewmh_update_current_desktop();
- /* Load current_col/current_row if we switch to a client without a container */
- current_col = c_ws->current_col;
- current_row = c_ws->current_row;
-
- /* Update container */
- if (client->container != NULL) {
- client->container->currently_focused = client;
-
- current_col = client->container->col;
- current_row = client->container->row;
- }
-
- CLIENT_LOG(client);
- /* Set focus to the entered window, and flush xcb buffer immediately */
- xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, client->child, XCB_CURRENT_TIME);
- ewmh_update_active_window(client->child);
- //xcb_warp_pointer(conn, XCB_NONE, client->child, 0, 0, 0, 0, 10, 10);
-
- if (client->container != NULL) {
- /* Get the client which was last focused in this particular container, it may be a different
- one than old_client */
- Client *last_focused = get_last_focused_client(conn, client->container, NULL);
-
- /* In stacking containers, raise the client in respect to the one which was focused before */
- if ((client->container->mode == MODE_STACK || client->container->mode == MODE_TABBED) &&
- client->container->workspace->fullscreen_client == NULL) {
- /* We need to get the client again, this time excluding the current client, because
- * we might have just gone into stacking mode and need to raise */
- Client *last_focused = get_last_focused_client(conn, client->container, client);
-
- if (last_focused != NULL) {
- DLOG("raising above frame %p / child %p\n", last_focused->frame, last_focused->child);
- uint32_t values[] = { last_focused->frame, XCB_STACK_MODE_ABOVE };
- xcb_configure_window(conn, client->frame, XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE, values);
- }
- }
-
- /* If it is the same one as old_client, we save us the unnecessary redecorate */
- if ((last_focused != NULL) && (last_focused != old_client))
- redecorate_window(conn, last_focused);
- }
-
- /* If the last client was a floating client, we need to go to the next
- * tiling client in stack and re-decorate it. */
- if (old_client != NULL && client_is_floating(old_client)) {
- DLOG("Coming from floating client, searching next tiling...\n");
- Client *current;
- SLIST_FOREACH(current, &(client->workspace->focus_stack), focus_clients) {
- if (client_is_floating(current))
- continue;
-
- DLOG("Found window: %p / child %p\n", current->frame, current->child);
- redecorate_window(conn, current);
- break;
- }
-
- }
-
- SLIST_REMOVE(&(client->workspace->focus_stack), client, Client, focus_clients);
- SLIST_INSERT_HEAD(&(client->workspace->focus_stack), client, focus_clients);
-
- /* If we’re in stacking mode, this renders the container to update changes in the title
- bars and to raise the focused client */
- if ((old_client != NULL) && (old_client != client) && !old_client->dock)
- redecorate_window(conn, old_client);
-
- /* redecorate_window flushes, so we don’t need to */
- redecorate_window(conn, client);