diff options
Diffstat (limited to 'swaybar')
| -rw-r--r-- | swaybar/bar.c | 78 | 
1 files changed, 36 insertions, 42 deletions
| diff --git a/swaybar/bar.c b/swaybar/bar.c index 71aff691..88de8c04 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -26,11 +26,6 @@  #include "wlr-layer-shell-unstable-v1-client-protocol.h"  #include "xdg-output-unstable-v1-client-protocol.h" -static void bar_init(struct swaybar *bar) { -	bar->config = init_config(); -	wl_list_init(&bar->outputs); -} -  void free_workspaces(struct wl_list *list) {  	struct swaybar_workspace *ws, *tmp;  	wl_list_for_each_safe(ws, tmp, list, link) { @@ -124,35 +119,45 @@ static void destroy_layer_surface(struct swaybar_output *output) {  	output->frame_scheduled = false;  } +static void set_bar_dirty(struct swaybar *bar) { +	struct swaybar_output *output; +	wl_list_for_each(output, &bar->outputs, link) { +		set_output_dirty(output); +	} +} +  bool determine_bar_visibility(struct swaybar *bar, bool moving_layer) {  	struct swaybar_config *config = bar->config;  	bool visible = !(strcmp(config->mode, "invisible") == 0 ||  		(strcmp(config->mode, config->hidden_state) == 0 // both "hide"  			&& !bar->visible_by_modifier && !bar->visible_by_urgency)); +	// Create/destroy layer surfaces as needed  	struct swaybar_output *output; -	if (visible == bar->visible) { -		if (visible && moving_layer) { -			// need to destroy layer surface to move to a different layer -			wl_list_for_each(output, &bar->outputs, link) { -				destroy_layer_surface(output); -				add_layer_surface(output); -			} +	wl_list_for_each(output, &bar->outputs, link) { +		// When moving to a different layer, we need to destroy and re-create +		// the layer surface +		if (!visible || moving_layer) { +			destroy_layer_surface(output); +		} + +		if (visible) { +			add_layer_surface(output);  		} -	} else { +	} +	set_bar_dirty(bar); + +	if (visible != bar->visible) {  		bar->visible = visible; -		wl_list_for_each(output, &bar->outputs, link) { -			if (visible) { -				add_layer_surface(output); -			} else { -				destroy_layer_surface(output); -			} + +		if (bar->status) { +			wlr_log(WLR_DEBUG, "Sending %s signal to status command", +					visible ? "cont" : "stop"); +			kill(bar->status->pid, visible ? +					bar->status->cont_signal : bar->status->stop_signal);  		} -		wlr_log(WLR_DEBUG, "Sending %s signal to status command", -				visible ? "cont" : "stop"); -		kill(bar->status->pid, -				visible ? bar->status->cont_signal : bar->status->stop_signal);  	} +  	return visible;  } @@ -226,6 +231,8 @@ static void xdg_output_handle_done(void *data,  		output->surface = wl_compositor_create_surface(bar->compositor);  		assert(output->surface); + +		determine_bar_visibility(bar, false);  	}  } @@ -314,15 +321,10 @@ static const struct wl_registry_listener registry_listener = {  	.global_remove = handle_global_remove,  }; -static void set_bar_dirty(struct swaybar *bar) { -	struct swaybar_output *output; -	wl_list_for_each(output, &bar->outputs, link) { -		set_output_dirty(output); -	} -} -  bool bar_setup(struct swaybar *bar, const char *socket_path) { -	bar_init(bar); +	bar->visible = true; +	bar->config = init_config(); +	wl_list_init(&bar->outputs);  	bar->eventloop = loop_create();  	bar->ipc_socketfd = ipc_open_socket(socket_path); @@ -348,15 +350,13 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) {  	assert(bar->compositor && bar->layer_shell && bar->shm &&  		bar->xdg_output_manager); -	struct swaybar_output *output; -	wl_list_for_each(output, &bar->outputs, link) { -		add_xdg_output(output); -	} +	// Second roundtrip for xdg-output  	wl_display_roundtrip(bar->display);  	struct swaybar_pointer *pointer = &bar->pointer;  	int max_scale = 1; +	struct swaybar_output *output;  	wl_list_for_each(output, &bar->outputs, link) {  		if (output->scale > max_scale) {  			max_scale = output->scale; @@ -373,16 +373,10 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) {  	pointer->cursor_surface = wl_compositor_create_surface(bar->compositor);  	assert(pointer->cursor_surface); -	bar->visible = true;  	if (bar->config->workspace_buttons) {  		ipc_get_workspaces(bar);  	} -	if (determine_bar_visibility(bar, false)) { -		wl_list_for_each(output, &bar->outputs, link) { -			add_layer_surface(output); -		} -		set_bar_dirty(bar); -	} +	determine_bar_visibility(bar, false);  	return true;  } | 
