diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-11-27 10:20:16 -0700 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-11-27 10:20:16 -0700 |
commit | b7702eb34c9d5485145b0483891e710fae12e967 (patch) | |
tree | f87d318d7701b572932687a1f388af2ec6458b15 | |
parent | Merge pull request #265 from sce/better_logging (diff) | |
parent | workspace: Learn sticky. (diff) | |
download | sway-b7702eb34c9d5485145b0483891e710fae12e967.tar.gz sway-b7702eb34c9d5485145b0483891e710fae12e967.tar.zst sway-b7702eb34c9d5485145b0483891e710fae12e967.zip |
Merge pull request #266 from sce/sticky_floats_0
workspace: Learn sticky.
-rw-r--r-- | include/container.h | 1 | ||||
-rw-r--r-- | sway.5.txt | 4 | ||||
-rw-r--r-- | sway/commands.c | 26 | ||||
-rw-r--r-- | sway/container.c | 2 | ||||
-rw-r--r-- | sway/workspace.c | 22 |
5 files changed, 53 insertions, 2 deletions
diff --git a/include/container.h b/include/container.h index 7b0bdb78..157b996a 100644 --- a/include/container.h +++ b/include/container.h | |||
@@ -74,6 +74,7 @@ struct sway_container { | |||
74 | bool visible; | 74 | bool visible; |
75 | bool is_floating; | 75 | bool is_floating; |
76 | bool is_focused; | 76 | bool is_focused; |
77 | bool sticky; // floating view always visible on its output | ||
77 | 78 | ||
78 | // Attributes that mostly views have. | 79 | // Attributes that mostly views have. |
79 | char *name; | 80 | char *name; |
@@ -166,6 +166,10 @@ Commands | |||
166 | **splitv**:: | 166 | **splitv**:: |
167 | Equivalent to **split vertical**. | 167 | Equivalent to **split vertical**. |
168 | 168 | ||
169 | **sticky** <enable|disable|toggle>:: | ||
170 | If enabled and the windows is floating it will always be present on the active | ||
171 | workspace on that output. | ||
172 | |||
169 | **workspace** <name>:: | 173 | **workspace** <name>:: |
170 | Switches to the specified workspace. | 174 | Switches to the specified workspace. |
171 | 175 | ||
diff --git a/sway/commands.c b/sway/commands.c index f1dbc09e..a46a0b89 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -33,7 +33,6 @@ struct cmd_handler { | |||
33 | }; | 33 | }; |
34 | 34 | ||
35 | static sway_cmd cmd_bindsym; | 35 | static sway_cmd cmd_bindsym; |
36 | static sway_cmd cmd_orientation; | ||
37 | static sway_cmd cmd_debuglog; | 36 | static sway_cmd cmd_debuglog; |
38 | static sway_cmd cmd_exec; | 37 | static sway_cmd cmd_exec; |
39 | static sway_cmd cmd_exec_always; | 38 | static sway_cmd cmd_exec_always; |
@@ -51,6 +50,7 @@ static sway_cmd cmd_log_colors; | |||
51 | static sway_cmd cmd_mode; | 50 | static sway_cmd cmd_mode; |
52 | static sway_cmd cmd_mouse_warping; | 51 | static sway_cmd cmd_mouse_warping; |
53 | static sway_cmd cmd_move; | 52 | static sway_cmd cmd_move; |
53 | static sway_cmd cmd_orientation; | ||
54 | static sway_cmd cmd_output; | 54 | static sway_cmd cmd_output; |
55 | static sway_cmd cmd_reload; | 55 | static sway_cmd cmd_reload; |
56 | static sway_cmd cmd_resize; | 56 | static sway_cmd cmd_resize; |
@@ -59,6 +59,7 @@ static sway_cmd cmd_set; | |||
59 | static sway_cmd cmd_split; | 59 | static sway_cmd cmd_split; |
60 | static sway_cmd cmd_splith; | 60 | static sway_cmd cmd_splith; |
61 | static sway_cmd cmd_splitv; | 61 | static sway_cmd cmd_splitv; |
62 | static sway_cmd cmd_sticky; | ||
62 | static sway_cmd cmd_workspace; | 63 | static sway_cmd cmd_workspace; |
63 | static sway_cmd cmd_ws_auto_back_and_forth; | 64 | static sway_cmd cmd_ws_auto_back_and_forth; |
64 | 65 | ||
@@ -1237,6 +1238,28 @@ static struct cmd_results *cmd_splith(int argc, char **argv) { | |||
1237 | return _do_split(argc, argv, L_HORIZ); | 1238 | return _do_split(argc, argv, L_HORIZ); |
1238 | } | 1239 | } |
1239 | 1240 | ||
1241 | static struct cmd_results *cmd_sticky(int argc, char **argv) { | ||
1242 | struct cmd_results *error = NULL; | ||
1243 | if (config->reading) return cmd_results_new(CMD_FAILURE, "sticky", "Can't be used in config file."); | ||
1244 | if (!config->active) return cmd_results_new(CMD_FAILURE, "sticky", "Can only be used when sway is running."); | ||
1245 | if ((error = checkarg(argc, "sticky", EXPECTED_EQUAL_TO, 1))) { | ||
1246 | return error; | ||
1247 | } | ||
1248 | char *action = argv[0]; | ||
1249 | swayc_t *cont = get_focused_view(&root_container); | ||
1250 | if (strcmp(action, "toggle") == 0) { | ||
1251 | cont->sticky = !cont->sticky; | ||
1252 | } else if (strcmp(action, "enable") == 0) { | ||
1253 | cont->sticky = true; | ||
1254 | } else if (strcmp(action, "disable") == 0) { | ||
1255 | cont->sticky = false; | ||
1256 | } else { | ||
1257 | return cmd_results_new(CMD_FAILURE, "sticky", | ||
1258 | "Expected 'sticky enable|disable|toggle'"); | ||
1259 | } | ||
1260 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1261 | } | ||
1262 | |||
1240 | static struct cmd_results *cmd_log_colors(int argc, char **argv) { | 1263 | static struct cmd_results *cmd_log_colors(int argc, char **argv) { |
1241 | struct cmd_results *error = NULL; | 1264 | struct cmd_results *error = NULL; |
1242 | if (!config->reading) return cmd_results_new(CMD_FAILURE, "log_colors", "Can only be used in config file."); | 1265 | if (!config->reading) return cmd_results_new(CMD_FAILURE, "log_colors", "Can only be used in config file."); |
@@ -1416,6 +1439,7 @@ static struct cmd_handler handlers[] = { | |||
1416 | { "split", cmd_split }, | 1439 | { "split", cmd_split }, |
1417 | { "splith", cmd_splith }, | 1440 | { "splith", cmd_splith }, |
1418 | { "splitv", cmd_splitv }, | 1441 | { "splitv", cmd_splitv }, |
1442 | { "sticky", cmd_sticky }, | ||
1419 | { "workspace", cmd_workspace }, | 1443 | { "workspace", cmd_workspace }, |
1420 | { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth }, | 1444 | { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth }, |
1421 | }; | 1445 | }; |
diff --git a/sway/container.c b/sway/container.c index 1634cce0..ba37d7c8 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -226,6 +226,7 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { | |||
226 | view->app_id = app_id ? strdup(app_id) : NULL; | 226 | view->app_id = app_id ? strdup(app_id) : NULL; |
227 | view->visible = true; | 227 | view->visible = true; |
228 | view->is_focused = true; | 228 | view->is_focused = true; |
229 | view->sticky = false; | ||
229 | // Setup geometry | 230 | // Setup geometry |
230 | const struct wlc_geometry* geometry = wlc_view_get_geometry(handle); | 231 | const struct wlc_geometry* geometry = wlc_view_get_geometry(handle); |
231 | view->width = 0; | 232 | view->width = 0; |
@@ -261,6 +262,7 @@ swayc_t *new_floating_view(wlc_handle handle) { | |||
261 | const char *app_id = wlc_view_get_app_id(handle); | 262 | const char *app_id = wlc_view_get_app_id(handle); |
262 | view->app_id = app_id ? strdup(app_id) : NULL; | 263 | view->app_id = app_id ? strdup(app_id) : NULL; |
263 | view->visible = true; | 264 | view->visible = true; |
265 | view->sticky = false; | ||
264 | 266 | ||
265 | // Set the geometry of the floating view | 267 | // Set the geometry of the floating view |
266 | const struct wlc_geometry* geometry = wlc_view_get_geometry(handle); | 268 | const struct wlc_geometry* geometry = wlc_view_get_geometry(handle); |
diff --git a/sway/workspace.c b/sway/workspace.c index f18a691f..6c9a39e0 100644 --- a/sway/workspace.c +++ b/sway/workspace.c | |||
@@ -221,11 +221,31 @@ bool workspace_switch(swayc_t *workspace) { | |||
221 | strcpy(prev_workspace_name, active_ws->name); | 221 | strcpy(prev_workspace_name, active_ws->name); |
222 | } | 222 | } |
223 | 223 | ||
224 | // move sticky containers | ||
225 | if (swayc_parent_by_type(active_ws, C_OUTPUT) == swayc_parent_by_type(workspace, C_OUTPUT)) { | ||
226 | // don't change list while traversing it, use intermediate list instead | ||
227 | list_t *stickies = create_list(); | ||
228 | for (int i = 0; i < active_ws->floating->length; i++) { | ||
229 | swayc_t *cont = active_ws->floating->items[i]; | ||
230 | if (cont->sticky) { | ||
231 | list_add(stickies, cont); | ||
232 | } | ||
233 | } | ||
234 | for (int i = 0; i < stickies->length; i++) { | ||
235 | swayc_t *cont = stickies->items[i]; | ||
236 | sway_log(L_DEBUG, "Moving sticky container %p to %p:%s", | ||
237 | cont, workspace, workspace->name); | ||
238 | swayc_t *parent = remove_child(cont); | ||
239 | add_floating(workspace, cont); | ||
240 | // Destroy old container if we need to | ||
241 | destroy_container(parent); | ||
242 | } | ||
243 | list_free(stickies); | ||
244 | } | ||
224 | sway_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name); | 245 | sway_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name); |
225 | if (!set_focused_container(get_focused_view(workspace))) { | 246 | if (!set_focused_container(get_focused_view(workspace))) { |
226 | return false; | 247 | return false; |
227 | } | 248 | } |
228 | arrange_windows(workspace, -1, -1); | 249 | arrange_windows(workspace, -1, -1); |
229 | |||
230 | return true; | 250 | return true; |
231 | } | 251 | } |