mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	Merge pull request #738 from deklov/panel-as-shell-02
Make swaybar and swaybg shell surfaces, take 2
This commit is contained in:
		
						commit
						58804a044f
					
				
					 7 changed files with 61 additions and 21 deletions
				
			
		| 
						 | 
					@ -42,5 +42,6 @@ struct window *window_setup(struct registry *registry, uint32_t width, uint32_t
 | 
				
			||||||
void window_teardown(struct window *state);
 | 
					void window_teardown(struct window *state);
 | 
				
			||||||
int window_prerender(struct window *state);
 | 
					int window_prerender(struct window *state);
 | 
				
			||||||
int window_render(struct window *state);
 | 
					int window_render(struct window *state);
 | 
				
			||||||
 | 
					void window_make_shell(struct window *window);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,33 +7,37 @@
 | 
				
			||||||
#include "list.h"
 | 
					#include "list.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct background_config {
 | 
					struct background_config {
 | 
				
			||||||
        wlc_handle output;
 | 
						wlc_handle output;
 | 
				
			||||||
        wlc_resource surface;
 | 
						wlc_resource surface;
 | 
				
			||||||
        // we need the wl_resource of the surface in the destructor
 | 
						// we need the wl_resource of the surface in the destructor
 | 
				
			||||||
        struct wl_resource *wl_surface_res;
 | 
						struct wl_resource *wl_surface_res;
 | 
				
			||||||
 | 
						// used to determine if client is a background
 | 
				
			||||||
 | 
						struct wl_client *client;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct panel_config {
 | 
					struct panel_config {
 | 
				
			||||||
        // wayland resource used in callbacks, is used to track this panel
 | 
						// wayland resource used in callbacks, is used to track this panel
 | 
				
			||||||
        struct wl_resource *wl_resource;
 | 
						struct wl_resource *wl_resource;
 | 
				
			||||||
        wlc_handle output;
 | 
						wlc_handle output;
 | 
				
			||||||
        wlc_resource surface;
 | 
						wlc_resource surface;
 | 
				
			||||||
        // we need the wl_resource of the surface in the destructor
 | 
						// we need the wl_resource of the surface in the destructor
 | 
				
			||||||
        struct wl_resource *wl_surface_res;
 | 
						struct wl_resource *wl_surface_res;
 | 
				
			||||||
        enum desktop_shell_panel_position panel_position;
 | 
						enum desktop_shell_panel_position panel_position;
 | 
				
			||||||
 | 
						// used to determine if client is a panel
 | 
				
			||||||
 | 
						struct wl_client *client;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct desktop_shell_state {
 | 
					struct desktop_shell_state {
 | 
				
			||||||
        list_t *backgrounds;
 | 
						list_t *backgrounds;
 | 
				
			||||||
        list_t *panels;
 | 
						list_t *panels;
 | 
				
			||||||
        list_t *lock_surfaces;
 | 
						list_t *lock_surfaces;
 | 
				
			||||||
        bool is_locked;
 | 
						bool is_locked;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct swaylock_state {
 | 
					struct swaylock_state {
 | 
				
			||||||
        bool active;
 | 
						bool active;
 | 
				
			||||||
        wlc_handle output;
 | 
						wlc_handle output;
 | 
				
			||||||
        wlc_resource surface;
 | 
						wlc_resource surface;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern struct desktop_shell_state desktop_shell;
 | 
					extern struct desktop_shell_state desktop_shell;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -73,6 +73,7 @@ static void set_background(struct wl_client *client, struct wl_resource *resourc
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	sway_log(L_DEBUG, "Setting surface %p as background for output %d", surface, (int)output);
 | 
						sway_log(L_DEBUG, "Setting surface %p as background for output %d", surface, (int)output);
 | 
				
			||||||
	struct background_config *config = malloc(sizeof(struct background_config));
 | 
						struct background_config *config = malloc(sizeof(struct background_config));
 | 
				
			||||||
 | 
						config->client = client;
 | 
				
			||||||
	config->output = output;
 | 
						config->output = output;
 | 
				
			||||||
	config->surface = wlc_resource_from_wl_surface_resource(surface);
 | 
						config->surface = wlc_resource_from_wl_surface_resource(surface);
 | 
				
			||||||
	config->wl_surface_res = surface;
 | 
						config->wl_surface_res = surface;
 | 
				
			||||||
| 
						 | 
					@ -91,6 +92,7 @@ static void set_panel(struct wl_client *client, struct wl_resource *resource,
 | 
				
			||||||
	sway_log(L_DEBUG, "Setting surface %p as panel for output %d (wl_resource: %p)", surface, (int)output, resource);
 | 
						sway_log(L_DEBUG, "Setting surface %p as panel for output %d (wl_resource: %p)", surface, (int)output, resource);
 | 
				
			||||||
	struct panel_config *config = find_or_create_panel_config(resource);
 | 
						struct panel_config *config = find_or_create_panel_config(resource);
 | 
				
			||||||
	config->output = output;
 | 
						config->output = output;
 | 
				
			||||||
 | 
						config->client = client;
 | 
				
			||||||
	config->surface = wlc_resource_from_wl_surface_resource(surface);
 | 
						config->surface = wlc_resource_from_wl_surface_resource(surface);
 | 
				
			||||||
	config->wl_surface_res = surface;
 | 
						config->wl_surface_res = surface;
 | 
				
			||||||
	wl_resource_set_destructor(surface, panel_surface_destructor);
 | 
						wl_resource_set_destructor(surface, panel_surface_destructor);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -176,6 +176,28 @@ static void handle_output_focused(wlc_handle output, bool focus) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static bool client_is_background(struct wl_client *client) {
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
						for (i = 0; i < desktop_shell.backgrounds->length; i++) {
 | 
				
			||||||
 | 
							struct background_config *config = desktop_shell.backgrounds->items[i];
 | 
				
			||||||
 | 
							if (config->client == client) {
 | 
				
			||||||
 | 
								return true;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static bool client_is_panel(struct wl_client *client) {
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
						for (i = 0; i < desktop_shell.panels->length; i++) {
 | 
				
			||||||
 | 
							struct panel_config *config = desktop_shell.panels->items[i];
 | 
				
			||||||
 | 
							if (config->client == client) {
 | 
				
			||||||
 | 
								return true;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static bool handle_view_created(wlc_handle handle) {
 | 
					static bool handle_view_created(wlc_handle handle) {
 | 
				
			||||||
	// if view is child of another view, the use that as focused container
 | 
						// if view is child of another view, the use that as focused container
 | 
				
			||||||
	wlc_handle parent = wlc_view_get_parent(handle);
 | 
						wlc_handle parent = wlc_view_get_parent(handle);
 | 
				
			||||||
| 
						 | 
					@ -186,6 +208,10 @@ static bool handle_view_created(wlc_handle handle) {
 | 
				
			||||||
	struct wl_client *client = wlc_view_get_wl_client(handle);
 | 
						struct wl_client *client = wlc_view_get_wl_client(handle);
 | 
				
			||||||
	pid_t pid;
 | 
						pid_t pid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (client_is_background(client) || client_is_panel(client)) {
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get parent container, to add view in
 | 
						// Get parent container, to add view in
 | 
				
			||||||
	if (parent) {
 | 
						if (parent) {
 | 
				
			||||||
		focused = swayc_by_handle(parent);
 | 
							focused = swayc_by_handle(parent);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -87,6 +87,8 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) {
 | 
				
			||||||
		desktop_shell_set_panel(bar_output->registry->desktop_shell, output->output, bar_output->window->surface);
 | 
							desktop_shell_set_panel(bar_output->registry->desktop_shell, output->output, bar_output->window->surface);
 | 
				
			||||||
		desktop_shell_set_panel_position(bar_output->registry->desktop_shell, bar->config->position);
 | 
							desktop_shell_set_panel_position(bar_output->registry->desktop_shell, bar->config->position);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							window_make_shell(bar_output->window);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* set font */
 | 
							/* set font */
 | 
				
			||||||
		bar_output->window->font = bar->config->font;
 | 
							bar_output->window->font = bar->config->font;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -54,6 +54,7 @@ int main(int argc, const char **argv) {
 | 
				
			||||||
		sway_abort("Failed to create surfaces.");
 | 
							sway_abort("Failed to create surfaces.");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	desktop_shell_set_background(registry->desktop_shell, output->output, window->surface);
 | 
						desktop_shell_set_background(registry->desktop_shell, output->output, window->surface);
 | 
				
			||||||
 | 
						window_make_shell(window);
 | 
				
			||||||
	list_add(surfaces, window);
 | 
						list_add(surfaces, window);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef WITH_GDK_PIXBUF
 | 
					#ifdef WITH_GDK_PIXBUF
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -59,6 +59,12 @@ static const struct wl_shell_surface_listener surface_listener = {
 | 
				
			||||||
	.configure = shell_surface_configure
 | 
						.configure = shell_surface_configure
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void window_make_shell(struct window *window) {
 | 
				
			||||||
 | 
						window->shell_surface = wl_shell_get_shell_surface(window->registry->shell, window->surface);
 | 
				
			||||||
 | 
						wl_shell_surface_add_listener(window->shell_surface, &surface_listener, window);
 | 
				
			||||||
 | 
						wl_shell_surface_set_toplevel(window->shell_surface);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct window *window_setup(struct registry *registry, uint32_t width, uint32_t height, bool shell_surface) {
 | 
					struct window *window_setup(struct registry *registry, uint32_t width, uint32_t height, bool shell_surface) {
 | 
				
			||||||
	struct window *window = malloc(sizeof(struct window));
 | 
						struct window *window = malloc(sizeof(struct window));
 | 
				
			||||||
	memset(window, 0, sizeof(struct window));
 | 
						memset(window, 0, sizeof(struct window));
 | 
				
			||||||
| 
						 | 
					@ -69,9 +75,7 @@ struct window *window_setup(struct registry *registry, uint32_t width, uint32_t
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	window->surface = wl_compositor_create_surface(registry->compositor);
 | 
						window->surface = wl_compositor_create_surface(registry->compositor);
 | 
				
			||||||
	if (shell_surface) {
 | 
						if (shell_surface) {
 | 
				
			||||||
		window->shell_surface = wl_shell_get_shell_surface(registry->shell, window->surface);
 | 
							window_make_shell(window);
 | 
				
			||||||
		wl_shell_surface_add_listener(window->shell_surface, &surface_listener, window);
 | 
					 | 
				
			||||||
		wl_shell_surface_set_toplevel(window->shell_surface);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (registry->pointer) {
 | 
						if (registry->pointer) {
 | 
				
			||||||
		wl_pointer_add_listener(registry->pointer, &pointer_listener, window);
 | 
							wl_pointer_add_listener(registry->pointer, &pointer_listener, window);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue