From f057a0195ee79dfcaeddbcab026c06e310998c75 Mon Sep 17 00:00:00 2001
From: Ryan Dwyer <ryandwyer1@gmail.com>
Date: Sun, 2 Sep 2018 15:03:58 +1000
Subject: Implement focus_on_window_activation

Depends on https://github.com/swaywm/wlroots/pull/1223
---
 include/sway/commands.h  |  1 +
 include/sway/config.h    | 11 +++++++++++
 include/sway/tree/view.h |  6 ++++++
 3 files changed, 18 insertions(+)

(limited to 'include')

diff --git a/include/sway/commands.h b/include/sway/commands.h
index 8e91c158..b0b5ed0f 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -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;
diff --git a/include/sway/config.h b/include/sway/config.h
index 18d10faa..45fa73c4 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -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;
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h
index f73ce571..382ab6b9 100644
--- a/include/sway/tree/view.h
+++ b/include/sway/tree/view.h
@@ -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);
-- 
cgit v1.2.3


From 6fb03817c9d2bd29697a91f92d680b0c6a2c5996 Mon Sep 17 00:00:00 2001
From: Ryan Dwyer <ryandwyer1@gmail.com>
Date: Sun, 2 Sep 2018 18:25:45 +1000
Subject: Rename fowa enum and use switch in view_request_activate

---
 include/sway/config.h |  4 ++--
 sway/tree/view.c      | 34 +++++++++++++++++-----------------
 2 files changed, 19 insertions(+), 19 deletions(-)

(limited to 'include')

diff --git a/include/sway/config.h b/include/sway/config.h
index 45fa73c4..4ee8c3c2 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -60,7 +60,7 @@ struct sway_mouse_binding {
 /**
  * Focus on window activation.
  */
-enum fowa {
+enum sway_fowa {
 	FOWA_SMART,
 	FOWA_URGENT,
 	FOWA_FOCUS,
@@ -350,7 +350,7 @@ struct sway_config {
 	size_t font_height;
 	bool pango_markup;
 	size_t urgent_timeout;
-	enum fowa focus_on_window_activation;
+	enum sway_fowa focus_on_window_activation;
 
 	// Flags
 	bool focus_follows_mouse;
diff --git a/sway/tree/view.c b/sway/tree/view.c
index c6ed68f6..6bd0ef67 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -281,25 +281,25 @@ 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 {
+	struct sway_seat *seat = input_manager_current_seat(input_manager);
+
+	switch (config->focus_on_window_activation) {
+	case FOWA_SMART:
+		if (workspace_is_visible(ws)) {
+			seat_set_focus(seat, view->swayc);
+		} else {
+			view_set_urgent(view, true);
+		}
+		break;
+	case FOWA_URGENT:
 		view_set_urgent(view, true);
+		break;
+	case FOWA_FOCUS:
+		seat_set_focus(seat, view->swayc);
+		break;
+	case FOWA_NONE:
+		break;
 	}
 }
 
-- 
cgit v1.2.3