diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-10-21 11:26:22 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-10-21 11:26:22 +1000 |
commit | c5a6c37275978ddc8c221ca73ae1a39254dd68f5 (patch) | |
tree | 2255d845647357cdbe6fdfcb1c6a40210a69ddb7 /sway/tree/workspace.c | |
parent | Merge pull request #2901 from ianyfan/swaybar (diff) | |
download | sway-c5a6c37275978ddc8c221ca73ae1a39254dd68f5.tar.gz sway-c5a6c37275978ddc8c221ca73ae1a39254dd68f5.tar.zst sway-c5a6c37275978ddc8c221ca73ae1a39254dd68f5.zip |
Make workspace back_and_forth seat-specific
* When using multiple seats, each seat has its own prev_workspace_name
for the purpose of workspace back_and_forth.
* Removes prev_workspace_name global variable.
* Removes unused next_name_map function in tree/workspace.c.
* Fixes memory leak in seat_destroy (seat was not freed).
Diffstat (limited to 'sway/tree/workspace.c')
-rw-r--r-- | sway/tree/workspace.c | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index fff16515..65284679 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -140,13 +140,6 @@ void workspace_consider_destroy(struct sway_workspace *ws) { | |||
140 | workspace_begin_destroy(ws); | 140 | workspace_begin_destroy(ws); |
141 | } | 141 | } |
142 | 142 | ||
143 | char *prev_workspace_name = NULL; | ||
144 | |||
145 | void next_name_map(struct sway_container *ws, void *data) { | ||
146 | int *count = data; | ||
147 | ++count; | ||
148 | } | ||
149 | |||
150 | static bool workspace_valid_on_output(const char *output_name, | 143 | static bool workspace_valid_on_output(const char *output_name, |
151 | const char *ws_name) { | 144 | const char *ws_name) { |
152 | struct workspace_config *wsc = workspace_find_config(ws_name); | 145 | struct workspace_config *wsc = workspace_find_config(ws_name); |
@@ -309,9 +302,12 @@ struct sway_workspace *workspace_by_name(const char *name) { | |||
309 | } else if (strcmp(name, "current") == 0) { | 302 | } else if (strcmp(name, "current") == 0) { |
310 | return current; | 303 | return current; |
311 | } else if (strcasecmp(name, "back_and_forth") == 0) { | 304 | } else if (strcasecmp(name, "back_and_forth") == 0) { |
312 | return prev_workspace_name ? | 305 | struct sway_seat *seat = input_manager_current_seat(); |
313 | root_find_workspace(_workspace_by_name, (void*)prev_workspace_name) | 306 | if (!seat->prev_workspace_name) { |
314 | : NULL; | 307 | return NULL; |
308 | } | ||
309 | return root_find_workspace(_workspace_by_name, | ||
310 | (void*)seat->prev_workspace_name); | ||
315 | } else { | 311 | } else { |
316 | return root_find_workspace(_workspace_by_name, (void*)name); | 312 | return root_find_workspace(_workspace_by_name, (void*)name); |
317 | } | 313 | } |
@@ -380,23 +376,24 @@ bool workspace_switch(struct sway_workspace *workspace, | |||
380 | struct sway_workspace *active_ws = seat_get_focused_workspace(seat); | 376 | struct sway_workspace *active_ws = seat_get_focused_workspace(seat); |
381 | 377 | ||
382 | if (!no_auto_back_and_forth && config->auto_back_and_forth | 378 | if (!no_auto_back_and_forth && config->auto_back_and_forth |
383 | && active_ws == workspace | 379 | && active_ws == workspace && seat->prev_workspace_name) { |
384 | && prev_workspace_name) { | 380 | struct sway_workspace *new_ws = |
385 | struct sway_workspace *new_ws = workspace_by_name(prev_workspace_name); | 381 | workspace_by_name(seat->prev_workspace_name); |
386 | workspace = new_ws ? | 382 | workspace = new_ws ? |
387 | new_ws : | 383 | new_ws : |
388 | workspace_create(NULL, prev_workspace_name); | 384 | workspace_create(NULL, seat->prev_workspace_name); |
389 | } | 385 | } |
390 | 386 | ||
391 | if (!prev_workspace_name || (strcmp(prev_workspace_name, active_ws->name) | 387 | if (!seat->prev_workspace_name || |
388 | (strcmp(seat->prev_workspace_name, active_ws->name) | ||
392 | && active_ws != workspace)) { | 389 | && active_ws != workspace)) { |
393 | free(prev_workspace_name); | 390 | free(seat->prev_workspace_name); |
394 | prev_workspace_name = malloc(strlen(active_ws->name) + 1); | 391 | seat->prev_workspace_name = malloc(strlen(active_ws->name) + 1); |
395 | if (!prev_workspace_name) { | 392 | if (!seat->prev_workspace_name) { |
396 | wlr_log(WLR_ERROR, "Unable to allocate previous workspace name"); | 393 | wlr_log(WLR_ERROR, "Unable to allocate previous workspace name"); |
397 | return false; | 394 | return false; |
398 | } | 395 | } |
399 | strcpy(prev_workspace_name, active_ws->name); | 396 | strcpy(seat->prev_workspace_name, active_ws->name); |
400 | } | 397 | } |
401 | 398 | ||
402 | wlr_log(WLR_DEBUG, "Switching to workspace %p:%s", | 399 | wlr_log(WLR_DEBUG, "Switching to workspace %p:%s", |