From bf41e7a794cf4bde3612ec23744400388b9d6756 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 19 Nov 2017 19:14:31 +0100 Subject: [PATCH] Make the close command use roots_seat_get_focus, rename a few symbols --- include/rootston/seat.h | 4 ++-- rootston/cursor.c | 6 +++--- rootston/input.c | 2 +- rootston/keyboard.c | 7 +++---- rootston/seat.c | 16 ++++++++-------- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 14ba9224..d9a44c2d 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -28,7 +28,7 @@ struct roots_seat_view { struct roots_view *view; struct wl_list link; // roots_seat::views - struct wl_listener destroy; + struct wl_listener view_destroy; }; struct roots_pointer { @@ -69,7 +69,7 @@ void roots_seat_configure_xcursor(struct roots_seat *seat); bool roots_seat_has_meta_pressed(struct roots_seat *seat); -struct roots_view *roots_seat_get_focused_view(struct roots_seat *seat); +struct roots_view *roots_seat_get_focus(struct roots_seat *seat); void roots_seat_focus_view(struct roots_seat *seat, struct roots_view *view); diff --git a/rootston/cursor.c b/rootston/cursor.c index 046fd4f4..3bb2a700 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -58,7 +58,7 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, } break; case ROOTS_CURSOR_MOVE: - view = roots_seat_get_focused_view(seat); + view = roots_seat_get_focus(seat); if (view != NULL) { double dx = cursor->cursor->x - cursor->offs_x; double dy = cursor->cursor->y - cursor->offs_y; @@ -67,7 +67,7 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, } break; case ROOTS_CURSOR_RESIZE: - view = roots_seat_get_focused_view(seat); + view = roots_seat_get_focus(seat); if (view != NULL) { double dx = cursor->cursor->x - cursor->offs_x; double dy = cursor->cursor->y - cursor->offs_y; @@ -111,7 +111,7 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, } break; case ROOTS_CURSOR_ROTATE: - view = roots_seat_get_focused_view(seat); + view = roots_seat_get_focus(seat); if (view != NULL) { int ox = view->x + view->wlr_surface->current->width/2, oy = view->y + view->wlr_surface->current->height/2; diff --git a/rootston/input.c b/rootston/input.c index d698c952..ce20e840 100644 --- a/rootston/input.c +++ b/rootston/input.c @@ -116,7 +116,7 @@ bool input_view_has_focus(struct roots_input *input, struct roots_view *view) { } struct roots_seat *seat; wl_list_for_each(seat, &input->seats, link) { - if (view == roots_seat_get_focused_view(seat)) { + if (view == roots_seat_get_focus(seat)) { return true; } } diff --git a/rootston/keyboard.c b/rootston/keyboard.c index d16d2b75..b8c7aca6 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -91,10 +91,9 @@ static void keyboard_binding_execute(struct roots_keyboard *keyboard, if (strcmp(command, "exit") == 0) { wl_display_terminate(keyboard->input->server->wl_display); } else if (strcmp(command, "close") == 0) { - if (!wl_list_empty(&seat->views)) { - struct roots_seat_view *first_seat_view = wl_container_of( - seat->views.next, first_seat_view, link); - view_close(first_seat_view->view); + struct roots_view *focus = roots_seat_get_focus(seat); + if (focus != NULL) { + view_close(focus); } } else if (strcmp(command, "next_window") == 0) { if (!wl_list_empty(&seat->views)) { diff --git a/rootston/seat.c b/rootston/seat.c index d5844ea6..61399850 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -485,7 +485,7 @@ bool roots_seat_has_meta_pressed(struct roots_seat *seat) { return false; } -struct roots_view *roots_seat_get_focused_view(struct roots_seat *seat) { +struct roots_view *roots_seat_get_focus(struct roots_seat *seat) { if (!seat->has_focus || wl_list_empty(&seat->views)) { return NULL; } @@ -497,12 +497,12 @@ struct roots_view *roots_seat_get_focused_view(struct roots_seat *seat) { static void seat_view_destroy(struct roots_seat_view *seat_view) { struct roots_seat *seat = seat_view->seat; - if (seat_view->view == roots_seat_get_focused_view(seat)) { + if (seat_view->view == roots_seat_get_focus(seat)) { seat->has_focus = false; seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH; } - wl_list_remove(&seat_view->destroy.link); + wl_list_remove(&seat_view->view_destroy.link); wl_list_remove(&seat_view->link); free(seat_view); @@ -516,7 +516,7 @@ static void seat_view_destroy(struct roots_seat_view *seat_view) { static void seat_view_handle_destroy(struct wl_listener *listener, void *data) { struct roots_seat_view *seat_view = - wl_container_of(listener, seat_view, destroy); + wl_container_of(listener, seat_view, view_destroy); seat_view_destroy(seat_view); } @@ -532,14 +532,14 @@ static struct roots_seat_view *seat_add_view(struct roots_seat *seat, wl_list_insert(&seat->views, &seat_view->link); - seat_view->destroy.notify = seat_view_handle_destroy; - wl_signal_add(&view->events.destroy, &seat_view->destroy); + seat_view->view_destroy.notify = seat_view_handle_destroy; + wl_signal_add(&view->events.destroy, &seat_view->view_destroy); return seat_view; } void roots_seat_focus_view(struct roots_seat *seat, struct roots_view *view) { - struct roots_view *prev_focus = roots_seat_get_focused_view(seat); + struct roots_view *prev_focus = roots_seat_get_focus(seat); if (view == prev_focus) { return; } @@ -569,7 +569,7 @@ void roots_seat_focus_view(struct roots_seat *seat, struct roots_view *view) { seat->has_focus = false; - // unfocus the old view if it is not focused by some other seat + // deactivate the old view if it is not focused by some other seat if (prev_focus != NULL && !input_view_has_focus(seat->input, prev_focus)) { view_activate(prev_focus, false); }