aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-10-21 11:26:22 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-10-21 11:26:22 +1000
commitc5a6c37275978ddc8c221ca73ae1a39254dd68f5 (patch)
tree2255d845647357cdbe6fdfcb1c6a40210a69ddb7
parentMerge pull request #2901 from ianyfan/swaybar (diff)
downloadsway-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).
-rw-r--r--include/sway/input/seat.h1
-rw-r--r--include/sway/tree/workspace.h2
-rw-r--r--sway/commands/move.c8
-rw-r--r--sway/commands/swap.c8
-rw-r--r--sway/commands/workspace.c5
-rw-r--r--sway/input/seat.c2
-rw-r--r--sway/tree/view.c4
-rw-r--r--sway/tree/workspace.c35
8 files changed, 32 insertions, 33 deletions
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h
index ef65810c..bef2af77 100644
--- a/include/sway/input/seat.h
+++ b/include/sway/input/seat.h
@@ -51,6 +51,7 @@ struct sway_seat {
51 bool has_focus; 51 bool has_focus;
52 struct wl_list focus_stack; // list of containers in focus order 52 struct wl_list focus_stack; // list of containers in focus order
53 struct sway_workspace *workspace; 53 struct sway_workspace *workspace;
54 char *prev_workspace_name; // for workspace back_and_forth
54 55
55 // If the focused layer is set, views cannot receive keyboard focus 56 // If the focused layer is set, views cannot receive keyboard focus
56 struct wlr_layer_surface_v1 *focused_layer; 57 struct wlr_layer_surface_v1 *focused_layer;
diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h
index efdae5a1..b5ae92f3 100644
--- a/include/sway/tree/workspace.h
+++ b/include/sway/tree/workspace.h
@@ -45,8 +45,6 @@ struct sway_workspace {
45 struct sway_workspace_state current; 45 struct sway_workspace_state current;
46}; 46};
47 47
48extern char *prev_workspace_name;
49
50struct workspace_config *workspace_find_config(const char *ws_name); 48struct workspace_config *workspace_find_config(const char *ws_name);
51 49
52struct sway_output *workspace_get_initial_output(const char *name); 50struct sway_output *workspace_get_initial_output(const char *name);
diff --git a/sway/commands/move.c b/sway/commands/move.c
index 941b284a..a5b7f661 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -429,8 +429,8 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
429 ws = workspace_by_name(argv[2]); 429 ws = workspace_by_name(argv[2]);
430 } else if (strcasecmp(argv[2], "back_and_forth") == 0) { 430 } else if (strcasecmp(argv[2], "back_and_forth") == 0) {
431 if (!(ws = workspace_by_name(argv[2]))) { 431 if (!(ws = workspace_by_name(argv[2]))) {
432 if (prev_workspace_name) { 432 if (seat->prev_workspace_name) {
433 ws_name = strdup(prev_workspace_name); 433 ws_name = strdup(seat->prev_workspace_name);
434 } else { 434 } else {
435 return cmd_results_new(CMD_FAILURE, "move", 435 return cmd_results_new(CMD_FAILURE, "move",
436 "No workspace was previously active."); 436 "No workspace was previously active.");
@@ -455,13 +455,13 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
455 } 455 }
456 456
457 if (!no_auto_back_and_forth && config->auto_back_and_forth && 457 if (!no_auto_back_and_forth && config->auto_back_and_forth &&
458 prev_workspace_name) { 458 seat->prev_workspace_name) {
459 // auto back and forth move 459 // auto back and forth move
460 if (old_ws && old_ws->name && 460 if (old_ws && old_ws->name &&
461 strcmp(old_ws->name, ws_name) == 0) { 461 strcmp(old_ws->name, ws_name) == 0) {
462 // if target workspace is the current one 462 // if target workspace is the current one
463 free(ws_name); 463 free(ws_name);
464 ws_name = strdup(prev_workspace_name); 464 ws_name = strdup(seat->prev_workspace_name);
465 ws = workspace_by_name(ws_name); 465 ws = workspace_by_name(ws_name);
466 } 466 }
467 } 467 }
diff --git a/sway/commands/swap.c b/sway/commands/swap.c
index 6062724d..afe11a47 100644
--- a/sway/commands/swap.c
+++ b/sway/commands/swap.c
@@ -116,8 +116,8 @@ static void container_swap(struct sway_container *con1,
116 output_get_active_workspace(con2->workspace->output); 116 output_get_active_workspace(con2->workspace->output);
117 117
118 char *stored_prev_name = NULL; 118 char *stored_prev_name = NULL;
119 if (prev_workspace_name) { 119 if (seat->prev_workspace_name) {
120 stored_prev_name = strdup(prev_workspace_name); 120 stored_prev_name = strdup(seat->prev_workspace_name);
121 } 121 }
122 122
123 swap_places(con1, con2); 123 swap_places(con1, con2);
@@ -132,8 +132,8 @@ static void container_swap(struct sway_container *con1,
132 swap_focus(con1, con2, seat, focus); 132 swap_focus(con1, con2, seat, focus);
133 133
134 if (stored_prev_name) { 134 if (stored_prev_name) {
135 free(prev_workspace_name); 135 free(seat->prev_workspace_name);
136 prev_workspace_name = stored_prev_name; 136 seat->prev_workspace_name = stored_prev_name;
137 } 137 }
138 138
139 if (fs1) { 139 if (fs1) {
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index da597f8a..745b40c7 100644
--- a/sway/commands/workspace.c
+++ b/sway/commands/workspace.c
@@ -142,12 +142,13 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
142 strcasecmp(argv[0], "current") == 0) { 142 strcasecmp(argv[0], "current") == 0) {
143 ws = workspace_by_name(argv[0]); 143 ws = workspace_by_name(argv[0]);
144 } else if (strcasecmp(argv[0], "back_and_forth") == 0) { 144 } else if (strcasecmp(argv[0], "back_and_forth") == 0) {
145 if (!prev_workspace_name) { 145 struct sway_seat *seat = config->handler_context.seat;
146 if (!seat->prev_workspace_name) {
146 return cmd_results_new(CMD_INVALID, "workspace", 147 return cmd_results_new(CMD_INVALID, "workspace",
147 "There is no previous workspace"); 148 "There is no previous workspace");
148 } 149 }
149 if (!(ws = workspace_by_name(argv[0]))) { 150 if (!(ws = workspace_by_name(argv[0]))) {
150 ws = workspace_create(NULL, prev_workspace_name); 151 ws = workspace_create(NULL, seat->prev_workspace_name);
151 } 152 }
152 } else { 153 } else {
153 char *name = join_args(argv, argc); 154 char *name = join_args(argv, argc);
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 2e352b19..16acc8a5 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -51,6 +51,8 @@ void seat_destroy(struct sway_seat *seat) {
51 wl_list_remove(&seat->new_drag_icon.link); 51 wl_list_remove(&seat->new_drag_icon.link);
52 wl_list_remove(&seat->link); 52 wl_list_remove(&seat->link);
53 wlr_seat_destroy(seat->wlr_seat); 53 wlr_seat_destroy(seat->wlr_seat);
54 free(seat->prev_workspace_name);
55 free(seat);
54} 56}
55 57
56static struct sway_seat_node *seat_node_from_node( 58static struct sway_seat_node *seat_node_from_node(
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 85afbb87..b23afb97 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -465,8 +465,8 @@ static struct sway_workspace *select_workspace(struct sway_view *view) {
465 465
466 if (!ws) { 466 if (!ws) {
467 if (strcasecmp(criteria->target, "back_and_forth") == 0) { 467 if (strcasecmp(criteria->target, "back_and_forth") == 0) {
468 if (prev_workspace_name) { 468 if (seat->prev_workspace_name) {
469 ws = workspace_create(NULL, prev_workspace_name); 469 ws = workspace_create(NULL, seat->prev_workspace_name);
470 } 470 }
471 } else { 471 } else {
472 ws = workspace_create(NULL, criteria->target); 472 ws = workspace_create(NULL, criteria->target);
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
143char *prev_workspace_name = NULL;
144
145void next_name_map(struct sway_container *ws, void *data) {
146 int *count = data;
147 ++count;
148}
149
150static bool workspace_valid_on_output(const char *output_name, 143static 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",