Bugfix: Don’t set focus if it is not necessary.

This fixes ticket #13
This commit is contained in:
Michael Stapelberg 2009-04-01 12:50:42 +02:00
parent 755540817e
commit 28aa13d831
5 changed files with 17 additions and 12 deletions

View 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); 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); char *convert_utf8_to_ucs2(char *input, int *real_strlen);
void remove_client_from_container(xcb_connection_t *conn, Client *client, Container *container); 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 leave_stack_mode(xcb_connection_t *conn, Container *container);
void switch_layout_mode(xcb_connection_t *conn, Container *container, int mode); void switch_layout_mode(xcb_connection_t *conn, Container *container, int mode);
void warp_pointer_into(xcb_connection_t *conn, Client *client); void warp_pointer_into(xcb_connection_t *conn, Client *client);

View File

@ -45,7 +45,7 @@ bool focus_window_in_container(xcb_connection_t *conn, Container *container, dir
return false; return false;
/* Set focus */ /* Set focus */
set_focus(conn, candidate); set_focus(conn, candidate, true);
return 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); new_row = (t_ws->rows - 1);
if (t_ws->table[new_col][new_row]->currently_focused != NULL) 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); 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) { 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 */ /* Restore focus on the new workspace */
if (CUR_CELL->currently_focused != NULL) 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); else xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, root, XCB_CURRENT_TIME);
//xcb_ungrab_server(conn); //xcb_ungrab_server(conn);

View File

@ -187,7 +187,7 @@ int handle_enter_notify(void *ignored, xcb_connection_t *conn, xcb_enter_notify_
return 1; return 1;
} }
set_focus(conn, client); set_focus(conn, client, false);
return 1; 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); LOG("Click on stack_win for client %d\n", destination);
CIRCLEQ_FOREACH(client, &(stack_win->container->clients), clients) CIRCLEQ_FOREACH(client, &(stack_win->container->clients), clients)
if (c++ == destination) { if (c++ == destination) {
set_focus(conn, client); set_focus(conn, client, true);
return 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; xcb_screen_t *root_screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
/* Set focus in any case */ /* Set focus in any case */
set_focus(conn, client); set_focus(conn, client, true);
/* Lets see if this was on the borders (= resize). If not, were done */ /* Lets see if this was on the borders (= resize). If not, were done */
LOG("press button on x=%d, y=%d\n", event->event_x, event->event_y); 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; con->currently_focused = focus_client;
/* Only if this is the active container, we need to really change focus */ /* Only if this is the active container, we need to really change focus */
if (con == CUR_CELL) if (con == CUR_CELL)
set_focus(conn, focus_client); set_focus(conn, focus_client, false);
break; break;
} }
} }

View File

@ -289,7 +289,7 @@ void cleanup_table(xcb_connection_t *conn, Workspace *workspace) {
current_row = c_ws->rows-1; current_row = c_ws->rows-1;
if (CUR_CELL->currently_focused != NULL) if (CUR_CELL->currently_focused != NULL)
set_focus(conn, CUR_CELL->currently_focused); set_focus(conn, CUR_CELL->currently_focused, true);
} }
/* /*

View File

@ -208,7 +208,7 @@ void remove_client_from_container(xcb_connection_t *conn, Client *client, Contai
* the user the new focus situation) * 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 */ /* The dock window cannot be focused, but enter notifies are still handled correctly */
if (client->dock) if (client->dock)
return; return;
@ -216,7 +216,12 @@ void set_focus(xcb_connection_t *conn, Client *client) {
/* Store the old client */ /* Store the old client */
Client *old_client = CUR_CELL->currently_focused; 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 */ /* Store current_row/current_col */
c_ws->current_row = current_row; c_ws->current_row = current_row;
c_ws->current_col = current_col; c_ws->current_col = current_col;