diff options
| author | Přemysl Janouch <p@janouch.name> | 2018-10-28 19:16:22 +0100 | 
|---|---|---|
| committer | Přemysl Janouch <p@janouch.name> | 2018-10-28 19:16:22 +0100 | 
| commit | da2899f72172205c86e48ac6a2f3dfcf78c3930a (patch) | |
| tree | 380fb88d67f126c57f0902d2d76ed4fc4630c3ee | |
| parent | 1f36351ab7cbded30f44f83ce6cdba414aa540c7 (diff) | |
| download | desktop-tools-da2899f72172205c86e48ac6a2f3dfcf78c3930a.tar.gz desktop-tools-da2899f72172205c86e48ac6a2f3dfcf78c3930a.tar.xz desktop-tools-da2899f72172205c86e48ac6a2f3dfcf78c3930a.zip | |
paswitch: add robustness
| -rw-r--r-- | paswitch.c | 28 | 
1 files changed, 21 insertions, 7 deletions
| @@ -196,6 +196,15 @@ app_context_free (struct app_context *self)  	poller_free (&self->poller);  } +static struct sink * +current_sink (struct app_context *ctx) +{ +	LIST_FOR_EACH (struct sink, iter, ctx->sinks) +		if (iter->index == ctx->selected_sink) +			return iter; +	return NULL; +} +  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  #define VOLUME_PERCENT(x) (((x) * 100 + PA_VOLUME_NORM / 2) / PA_VOLUME_NORM) @@ -260,9 +269,14 @@ on_sink_info (pa_context *context, const pa_sink_info *info, int eol,  	}  	if (!info || eol)  	{ -		// TODO: handle the case of when sinks disappear -		if (ctx->selected_sink == PA_INVALID_INDEX && ctx->sinks) +		struct sink *sink = current_sink (ctx); +		if (!sink && ctx->sinks) +		{  			ctx->selected_sink = ctx->sinks->index; +			ctx->selected_port = -1; +		} +		else if (sink && ctx->selected_port >= (ssize_t) sink->ports_len) +			ctx->selected_port = -1;  		poller_idle_set (&ctx->redraw_event);  		ctx->reset_sinks = true; @@ -304,6 +318,8 @@ update_sinks (struct app_context *ctx)  		(ctx->context, on_sink_info, ctx));  } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  static void  forget_sink_inputs (struct app_context *ctx)  { @@ -358,6 +374,8 @@ on_server_info (pa_context *context, const struct pa_server_info *info,  		cstr_set (&ctx->default_sink, NULL);  } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  static void  update_server_info (struct app_context *ctx)  { @@ -600,11 +618,7 @@ on_action (struct app_context *ctx, enum action action)  {  	poller_idle_set (&ctx->redraw_event); -	struct sink *sink = NULL; -	LIST_FOR_EACH (struct sink, iter, ctx->sinks) -		if (iter->index == ctx->selected_sink) -			sink = iter; - +	struct sink *sink = current_sink (ctx);  	switch (action)  	{  	case ACTION_UP: | 
