diff options
| author | Drew DeVault <[email protected]> | 2015-09-01 12:56:35 -0400 | 
|---|---|---|
| committer | Drew DeVault <[email protected]> | 2015-09-01 12:56:35 -0400 | 
| commit | 569c6710a976f92518754c6f7fe2840caa9edda2 (patch) | |
| tree | 810e78292b6bf80337af70200f6ae55a2579e80d | |
| parent | 9eb5ba49614d5934108dc4da18419b033c976e5b (diff) | |
| parent | 972748e674918dea00533ef895748577dfb7759b (diff) | |
Merge pull request #160 from taiyu-len/master
cleaned up leaky prev_workspace_name
| -rw-r--r-- | sway/commands.c | 7 | ||||
| -rw-r--r-- | sway/workspace.c | 21 | 
2 files changed, 15 insertions, 13 deletions
| diff --git a/sway/commands.c b/sway/commands.c index 177c54ab..6e74a442 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -822,11 +822,8 @@ static bool cmd_workspace(struct sway_config *config, int argc, char **argv) {  		}  		if (strcasecmp(argv[0], "back_and_forth") == 0) {  			if (prev_workspace_name) { -				if (workspace_by_name(prev_workspace_name)) { -					workspace_switch(workspace_by_name(prev_workspace_name)); -				} else { -					workspace_switch(workspace_create(prev_workspace_name)); -				} +				swayc_t *ws = workspace_by_name(prev_workspace_name); +				workspace_switch(ws ? ws : workspace_create(prev_workspace_name));  			}  			return true;  		} diff --git a/sway/workspace.c b/sway/workspace.c index 866276d8..7eb422c4 100644 --- a/sway/workspace.c +++ b/sway/workspace.c @@ -13,7 +13,7 @@  #include "focus.h"  #include "util.h" -char *prev_workspace_name = ""; +char *prev_workspace_name = NULL;  char *workspace_next_name(void) {  	sway_log(L_DEBUG, "Workspace: Generating new name"); @@ -182,13 +182,18 @@ void workspace_switch(swayc_t *workspace) {  	if (!workspace) {  		return;  	} -	if (strcmp(prev_workspace_name, swayc_active_workspace()->name) != 0 && swayc_active_workspace() != workspace) { -		prev_workspace_name = malloc(strlen(swayc_active_workspace()->name) + 1); -		strcpy(prev_workspace_name, swayc_active_workspace()->name); -	} else if (config->auto_back_and_forth && swayc_active_workspace() == workspace && strlen(prev_workspace_name) != 0) { -		workspace = workspace_by_name(prev_workspace_name) ? workspace_by_name(prev_workspace_name) : workspace_create(prev_workspace_name); -		prev_workspace_name = malloc(strlen(swayc_active_workspace()->name) + 1); -		strcpy(prev_workspace_name, swayc_active_workspace()->name); +	swayc_t *active_ws = swayc_active_workspace(); +	if (config->auto_back_and_forth && active_ws == workspace && prev_workspace_name) { +		swayc_t *new_ws = workspace_by_name(prev_workspace_name); +		workspace = new_ws ? new_ws : workspace_create(prev_workspace_name); +	} + +	if (!prev_workspace_name +			|| (strcmp(prev_workspace_name, active_ws->name) +				&& active_ws != workspace)) { +		free(prev_workspace_name); +		prev_workspace_name = malloc(strlen(active_ws->name)+1); +		strcpy(prev_workspace_name, active_ws->name);  	}  	sway_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name); | 
