]> git.sur5r.net Git - i3/i3/commitdiff
Bugfix: Don’t set focus if it is not necessary.
authorMichael Stapelberg <michael+x200@stapelberg.de>
Wed, 1 Apr 2009 10:50:42 +0000 (12:50 +0200)
committerMichael Stapelberg <michael+x200@stapelberg.de>
Wed, 1 Apr 2009 10:50:42 +0000 (12:50 +0200)
This fixes ticket #13

include/util.h
src/commands.c
src/handlers.c
src/table.c
src/util.c

index 4100089bdb6e78c09fe63efd6608497a28631fe3..eb1263542678117aedb2d56178115cd63b4753bd 100644 (file)
@@ -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);
index 50e52f9d09660db8ca58f46cb3604532621228b6..258d5a0925d00baf5e1751609b1d23b93628d30a 100644 (file)
@@ -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);
index 17f4462d51cd97cfc3268ac5656a12bc1e3e75d3..e5835184a03a858fc02b9049f8f0627e0a66c20a 100644 (file)
@@ -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;
                         }
         }
index 62bdba78cd26d7e946a16a4ab87eca50c5bcfd4e..791362edefd34f47107179710a0d2d6c688ae0e1 100644 (file)
@@ -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);
 }
 
 /*
index 24c42912e60d022930a46b8d14582769ec9952f9..a926bda5b298448cca06f92b59351ab51cddc497 100644 (file)
@@ -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;