From: Michael Stapelberg Date: Wed, 1 Apr 2009 10:50:42 +0000 (+0200) Subject: Bugfix: Don’t set focus if it is not necessary. X-Git-Tag: 3.a-bf1~57 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=28aa13d831d6088f999167f08a8998d341dd89d3;p=i3%2Fi3 Bugfix: Don’t set focus if it is not necessary. This fixes ticket #13 --- diff --git a/include/util.h b/include/util.h index 4100089b..eb126354 100644 --- a/include/util.h +++ b/include/util.h @@ -48,7 +48,7 @@ void start_application(const char *command); void check_error(xcb_connection_t *conn, xcb_void_cookie_t cookie, char *err_message); char *convert_utf8_to_ucs2(char *input, int *real_strlen); void remove_client_from_container(xcb_connection_t *conn, Client *client, Container *container); -void set_focus(xcb_connection_t *conn, Client *client); +void set_focus(xcb_connection_t *conn, Client *client, bool set_anyways); void leave_stack_mode(xcb_connection_t *conn, Container *container); void switch_layout_mode(xcb_connection_t *conn, Container *container, int mode); void warp_pointer_into(xcb_connection_t *conn, Client *client); diff --git a/src/commands.c b/src/commands.c index 50e52f9d..258d5a09 100644 --- a/src/commands.c +++ b/src/commands.c @@ -45,7 +45,7 @@ bool focus_window_in_container(xcb_connection_t *conn, Container *container, dir return false; /* Set focus */ - set_focus(conn, candidate); + set_focus(conn, candidate, true); return true; } @@ -122,7 +122,7 @@ static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t t new_row = (t_ws->rows - 1); if (t_ws->table[new_col][new_row]->currently_focused != NULL) - set_focus(conn, t_ws->table[new_col][new_row]->currently_focused); + set_focus(conn, t_ws->table[new_col][new_row]->currently_focused, true); } /* @@ -235,7 +235,7 @@ static void move_current_window(xcb_connection_t *conn, direction_t direction) { render_layout(conn); - set_focus(conn, current_client); + set_focus(conn, current_client, true); } static void move_current_container(xcb_connection_t *conn, direction_t direction) { @@ -546,7 +546,7 @@ void show_workspace(xcb_connection_t *conn, int workspace) { /* Restore focus on the new workspace */ if (CUR_CELL->currently_focused != NULL) - set_focus(conn, CUR_CELL->currently_focused); + set_focus(conn, CUR_CELL->currently_focused, true); else xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, root, XCB_CURRENT_TIME); //xcb_ungrab_server(conn); diff --git a/src/handlers.c b/src/handlers.c index 17f4462d..e5835184 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -187,7 +187,7 @@ int handle_enter_notify(void *ignored, xcb_connection_t *conn, xcb_enter_notify_ return 1; } - set_focus(conn, client); + set_focus(conn, client, false); return 1; } @@ -223,7 +223,7 @@ static bool button_press_stackwin(xcb_connection_t *conn, xcb_button_press_event LOG("Click on stack_win for client %d\n", destination); CIRCLEQ_FOREACH(client, &(stack_win->container->clients), clients) if (c++ == destination) { - set_focus(conn, client); + set_focus(conn, client, true); return true; } @@ -297,7 +297,7 @@ int handle_button_press(void *ignored, xcb_connection_t *conn, xcb_button_press_ xcb_screen_t *root_screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data; /* Set focus in any case */ - set_focus(conn, client); + set_focus(conn, client, true); /* Let’s see if this was on the borders (= resize). If not, we’re done */ LOG("press button on x=%d, y=%d\n", event->event_x, event->event_y); @@ -616,7 +616,7 @@ int handle_unmap_notify_event(void *data, xcb_connection_t *conn, xcb_unmap_noti con->currently_focused = focus_client; /* Only if this is the active container, we need to really change focus */ if (con == CUR_CELL) - set_focus(conn, focus_client); + set_focus(conn, focus_client, false); break; } } diff --git a/src/table.c b/src/table.c index 62bdba78..791362ed 100644 --- a/src/table.c +++ b/src/table.c @@ -289,7 +289,7 @@ void cleanup_table(xcb_connection_t *conn, Workspace *workspace) { current_row = c_ws->rows-1; if (CUR_CELL->currently_focused != NULL) - set_focus(conn, CUR_CELL->currently_focused); + set_focus(conn, CUR_CELL->currently_focused, true); } /* diff --git a/src/util.c b/src/util.c index 24c42912..a926bda5 100644 --- a/src/util.c +++ b/src/util.c @@ -208,7 +208,7 @@ void remove_client_from_container(xcb_connection_t *conn, Client *client, Contai * the user the new focus situation) * */ -void set_focus(xcb_connection_t *conn, Client *client) { +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; @@ -216,7 +216,12 @@ void set_focus(xcb_connection_t *conn, Client *client) { /* Store the old client */ Client *old_client = CUR_CELL->currently_focused; - /* TODO: check if the focus needs to be changed at all */ + /* Check if the focus needs to be changed at all */ + if (!set_anyways && (old_client == client)) { + LOG("old_client == client, not changing focus\n"); + return; + } + /* Store current_row/current_col */ c_ws->current_row = current_row; c_ws->current_col = current_col;