separate seat get focus and seat get focus inactive

This commit is contained in:
Tony Crisci 2018-02-07 18:17:57 -05:00
parent 7d8f2c52aa
commit a7d49da239
7 changed files with 30 additions and 24 deletions

View file

@ -56,7 +56,9 @@ void sway_seat_configure_xcursor(struct sway_seat *seat);
void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container);
swayc_t *sway_seat_get_focus(struct sway_seat *seat, swayc_t *container);
swayc_t *sway_seat_get_focus(struct sway_seat *seat);
swayc_t *sway_seat_get_focus_inactive(struct sway_seat *seat, swayc_t *container);
void sway_seat_set_config(struct sway_seat *seat, struct seat_config *seat_config);

View file

@ -282,9 +282,7 @@ struct cmd_results *handle_command(char *_exec) {
}
if (seat) {
config->handler_context.current_container =
(seat->has_focus ?
sway_seat_get_focus(seat, &root_container) :
NULL);
sway_seat_get_focus(seat);
struct cmd_results *res = handler->handle(argc-1, argv+1);
if (res->status != CMD_SUCCESS) {
free_argv(argc, argv);

View file

@ -91,7 +91,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
}
workspace_switch(ws);
current_container =
sway_seat_get_focus(config->handler_context.seat, &root_container);
sway_seat_get_focus(config->handler_context.seat);
swayc_t *new_output = swayc_parent_by_type(current_container, C_OUTPUT);
if (config->mouse_warping && old_output != new_output) {

View file

@ -135,7 +135,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
wl_signal_add(&xdg_surface->events.destroy, &sway_surface->destroy);
struct sway_seat *seat = input_manager_current_seat(input_manager);
swayc_t *focus = sway_seat_get_focus(seat, &root_container);
swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container);
swayc_t *cont = new_view(focus, sway_view);
sway_view->swayc = cont;

View file

@ -282,7 +282,7 @@ bool sway_input_manager_has_focus(struct sway_input_manager *input,
swayc_t *container) {
struct sway_seat *seat = NULL;
wl_list_for_each(seat, &input->seats, link) {
if (seat->has_focus && sway_seat_get_focus(seat, &root_container) == container) {
if (sway_seat_get_focus(seat) == container) {
return true;
}
}

View file

@ -137,16 +137,14 @@ static void seat_configure_keyboard(struct sway_seat *seat,
struct wlr_keyboard *wlr_keyboard = seat_device->input_device->wlr_device->keyboard;
sway_keyboard_configure(seat_device->keyboard);
wlr_seat_set_keyboard(seat->wlr_seat,
seat_device->input_device->wlr_device);
if (seat->has_focus) {
swayc_t *focus = sway_seat_get_focus(seat, &root_container);
if (focus && focus->type == C_VIEW) {
// force notify reenter to pick up the new configuration
wlr_seat_keyboard_clear_focus(seat->wlr_seat);
wlr_seat_keyboard_notify_enter(seat->wlr_seat,
focus->sway_view->surface, wlr_keyboard->keycodes,
wlr_keyboard->num_keycodes, &wlr_keyboard->modifiers);
}
seat_device->input_device->wlr_device);
swayc_t *focus = sway_seat_get_focus(seat);
if (focus && focus->type == C_VIEW) {
// force notify reenter to pick up the new configuration
wlr_seat_keyboard_clear_focus(seat->wlr_seat);
wlr_seat_keyboard_notify_enter(seat->wlr_seat,
focus->sway_view->surface, wlr_keyboard->keycodes,
wlr_keyboard->num_keycodes, &wlr_keyboard->modifiers);
}
}
@ -266,12 +264,13 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) {
static void handle_focus_destroy(struct wl_listener *listener, void *data) {
struct sway_seat *seat = wl_container_of(listener, seat, focus_destroy);
swayc_t *container = data;
// TODO dont set focus to the parent, set focus to the next focus inactive
// of the parent
sway_seat_set_focus(seat, container->parent);
}
void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) {
swayc_t *last_focus =
(seat->has_focus ? sway_seat_get_focus(seat, &root_container) : NULL);
swayc_t *last_focus = sway_seat_get_focus(seat);
if (container && last_focus == container) {
return;
@ -314,7 +313,7 @@ void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) {
}
}
swayc_t *sway_seat_get_focus(struct sway_seat *seat, swayc_t *container) {
swayc_t *sway_seat_get_focus_inactive(struct sway_seat *seat, swayc_t *container) {
struct sway_seat_container *current = NULL;
swayc_t *parent = NULL;
wl_list_for_each(current, &seat->focus_stack, link) {
@ -338,6 +337,13 @@ swayc_t *sway_seat_get_focus(struct sway_seat *seat, swayc_t *container) {
return NULL;
}
swayc_t *sway_seat_get_focus(struct sway_seat *seat) {
if (!seat->has_focus) {
return NULL;
}
return sway_seat_get_focus_inactive(seat, &root_container);
}
void sway_seat_set_config(struct sway_seat *seat,
struct seat_config *seat_config) {
// clear configs

View file

@ -63,8 +63,8 @@ static bool _workspace_by_name(swayc_t *view, void *data) {
swayc_t *workspace_by_name(const char *name) {
struct sway_seat *seat = input_manager_current_seat(input_manager);
swayc_t *current_workspace = NULL, *current_output = NULL;
if (seat->has_focus) {
swayc_t *focus = sway_seat_get_focus(seat, &root_container);
swayc_t *focus = sway_seat_get_focus(seat);
if (focus) {
current_workspace = swayc_parent_by_type(focus, C_WORKSPACE);
current_output = swayc_parent_by_type(focus, C_OUTPUT);
}
@ -103,7 +103,7 @@ swayc_t *workspace_create(const char *name) {
}
// Otherwise create a new one
struct sway_seat *seat = input_manager_current_seat(input_manager);
swayc_t *focus = sway_seat_get_focus(seat, &root_container);
swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container);
parent = focus;
parent = swayc_parent_by_type(parent, C_OUTPUT);
return new_workspace(parent, name);
@ -195,7 +195,7 @@ bool workspace_switch(swayc_t *workspace) {
return false;
}
struct sway_seat *seat = input_manager_current_seat(input_manager);
swayc_t *focus = sway_seat_get_focus(seat, &root_container);
swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container);
if (!seat || !focus) {
return false;
}