mirror of
https://github.com/swaywm/sway.git
synced 2024-11-26 01:41:30 +00:00
Implement focus_on_window_activation
Depends on https://github.com/swaywm/wlroots/pull/1223
This commit is contained in:
parent
159edc6d13
commit
f057a0195e
|
@ -117,6 +117,7 @@ sway_cmd cmd_floating_modifier;
|
|||
sway_cmd cmd_floating_scroll;
|
||||
sway_cmd cmd_focus;
|
||||
sway_cmd cmd_focus_follows_mouse;
|
||||
sway_cmd cmd_focus_on_window_activation;
|
||||
sway_cmd cmd_focus_wrapping;
|
||||
sway_cmd cmd_font;
|
||||
sway_cmd cmd_for_window;
|
||||
|
|
|
@ -57,6 +57,16 @@ struct sway_mouse_binding {
|
|||
char *command;
|
||||
};
|
||||
|
||||
/**
|
||||
* Focus on window activation.
|
||||
*/
|
||||
enum fowa {
|
||||
FOWA_SMART,
|
||||
FOWA_URGENT,
|
||||
FOWA_FOCUS,
|
||||
FOWA_NONE,
|
||||
};
|
||||
|
||||
/**
|
||||
* A "mode" of keybindings created via the `mode` command.
|
||||
*/
|
||||
|
@ -340,6 +350,7 @@ struct sway_config {
|
|||
size_t font_height;
|
||||
bool pango_markup;
|
||||
size_t urgent_timeout;
|
||||
enum fowa focus_on_window_activation;
|
||||
|
||||
// Flags
|
||||
bool focus_follows_mouse;
|
||||
|
|
|
@ -167,6 +167,7 @@ struct sway_xwayland_view {
|
|||
struct wl_listener request_maximize;
|
||||
struct wl_listener request_configure;
|
||||
struct wl_listener request_fullscreen;
|
||||
struct wl_listener request_activate;
|
||||
struct wl_listener set_title;
|
||||
struct wl_listener set_class;
|
||||
struct wl_listener set_window_type;
|
||||
|
@ -259,6 +260,11 @@ void view_autoconfigure(struct sway_view *view);
|
|||
|
||||
void view_set_activated(struct sway_view *view, bool activated);
|
||||
|
||||
/**
|
||||
* Called when the view requests to be focused.
|
||||
*/
|
||||
void view_request_activate(struct sway_view *view);
|
||||
|
||||
void view_set_tiled(struct sway_view *view, bool tiled);
|
||||
|
||||
void view_close(struct sway_view *view);
|
||||
|
|
|
@ -106,6 +106,7 @@ static struct cmd_handler handlers[] = {
|
|||
{ "floating_modifier", cmd_floating_modifier },
|
||||
{ "focus", cmd_focus },
|
||||
{ "focus_follows_mouse", cmd_focus_follows_mouse },
|
||||
{ "focus_on_window_activation", cmd_focus_on_window_activation },
|
||||
{ "focus_wrapping", cmd_focus_wrapping },
|
||||
{ "font", cmd_font },
|
||||
{ "for_window", cmd_for_window },
|
||||
|
|
25
sway/commands/focus_on_window_activation.c
Normal file
25
sway/commands/focus_on_window_activation.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include "sway/commands.h"
|
||||
|
||||
struct cmd_results *cmd_focus_on_window_activation(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "focus_on_window_activation",
|
||||
EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0], "smart") == 0) {
|
||||
config->focus_on_window_activation = FOWA_SMART;
|
||||
} else if (strcmp(argv[0], "urgent") == 0) {
|
||||
config->focus_on_window_activation = FOWA_URGENT;
|
||||
} else if (strcmp(argv[0], "focus") == 0) {
|
||||
config->focus_on_window_activation = FOWA_FOCUS;
|
||||
} else if (strcmp(argv[0], "none") == 0) {
|
||||
config->focus_on_window_activation = FOWA_NONE;
|
||||
} else {
|
||||
return cmd_results_new(CMD_INVALID, "focus_on_window_activation",
|
||||
"Expected "
|
||||
"'focus_on_window_activation smart|urgent|focus|none'");
|
||||
}
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
|
@ -337,6 +337,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
|
|||
wl_list_remove(&xwayland_view->request_fullscreen.link);
|
||||
wl_list_remove(&xwayland_view->request_move.link);
|
||||
wl_list_remove(&xwayland_view->request_resize.link);
|
||||
wl_list_remove(&xwayland_view->request_activate.link);
|
||||
wl_list_remove(&xwayland_view->set_title.link);
|
||||
wl_list_remove(&xwayland_view->set_class.link);
|
||||
wl_list_remove(&xwayland_view->set_window_type.link);
|
||||
|
@ -463,6 +464,19 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
|
|||
seat_begin_resize_floating(seat, view->swayc, seat->last_button, e->edges);
|
||||
}
|
||||
|
||||
static void handle_request_activate(struct wl_listener *listener, void *data) {
|
||||
struct sway_xwayland_view *xwayland_view =
|
||||
wl_container_of(listener, xwayland_view, request_activate);
|
||||
struct sway_view *view = &xwayland_view->view;
|
||||
struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface;
|
||||
if (!xsurface->mapped) {
|
||||
return;
|
||||
}
|
||||
view_request_activate(view);
|
||||
|
||||
transaction_commit_dirty();
|
||||
}
|
||||
|
||||
static void handle_set_title(struct wl_listener *listener, void *data) {
|
||||
struct sway_xwayland_view *xwayland_view =
|
||||
wl_container_of(listener, xwayland_view, set_title);
|
||||
|
@ -555,6 +569,10 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
|
|||
&xwayland_view->request_fullscreen);
|
||||
xwayland_view->request_fullscreen.notify = handle_request_fullscreen;
|
||||
|
||||
wl_signal_add(&xsurface->events.request_activate,
|
||||
&xwayland_view->request_activate);
|
||||
xwayland_view->request_activate.notify = handle_request_activate;
|
||||
|
||||
wl_signal_add(&xsurface->events.request_move,
|
||||
&xwayland_view->request_move);
|
||||
xwayland_view->request_move.notify = handle_request_move;
|
||||
|
|
|
@ -46,6 +46,7 @@ sway_sources = files(
|
|||
'commands/floating_modifier.c',
|
||||
'commands/focus.c',
|
||||
'commands/focus_follows_mouse.c',
|
||||
'commands/focus_on_window_activation.c',
|
||||
'commands/focus_wrapping.c',
|
||||
'commands/font.c',
|
||||
'commands/for_window.c',
|
||||
|
|
|
@ -280,6 +280,29 @@ void view_set_activated(struct sway_view *view, bool activated) {
|
|||
}
|
||||
}
|
||||
|
||||
void view_request_activate(struct sway_view *view) {
|
||||
if (config->focus_on_window_activation == FOWA_NONE) {
|
||||
return;
|
||||
}
|
||||
if (config->focus_on_window_activation == FOWA_FOCUS) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
seat_set_focus(seat, view->swayc);
|
||||
return;
|
||||
}
|
||||
if (config->focus_on_window_activation == FOWA_URGENT) {
|
||||
view_set_urgent(view, true);
|
||||
return;
|
||||
}
|
||||
// FOWA_SMART
|
||||
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
|
||||
if (workspace_is_visible(ws)) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
seat_set_focus(seat, view->swayc);
|
||||
} else {
|
||||
view_set_urgent(view, true);
|
||||
}
|
||||
}
|
||||
|
||||
void view_set_tiled(struct sway_view *view, bool tiled) {
|
||||
if (!tiled) {
|
||||
view->using_csd = true;
|
||||
|
|
Loading…
Reference in a new issue