mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	compositor-x11: Set window icon
This commit is contained in:
		
							parent
							
								
									24ed621388
								
							
						
					
					
						commit
						f58d8ca1bd
					
				
					 5 changed files with 76 additions and 23 deletions
				
			
		| 
						 | 
				
			
			@ -61,8 +61,10 @@ struct x11_compositor {
 | 
			
		|||
		xcb_atom_t		 wm_delete_window;
 | 
			
		||||
		xcb_atom_t		 wm_class;
 | 
			
		||||
		xcb_atom_t		 net_wm_name;
 | 
			
		||||
		xcb_atom_t		 net_wm_icon;
 | 
			
		||||
		xcb_atom_t		 string;
 | 
			
		||||
		xcb_atom_t		 utf8_string;
 | 
			
		||||
		xcb_atom_t		 cardinal;
 | 
			
		||||
	} atom;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -330,6 +332,31 @@ struct wm_normal_hints {
 | 
			
		|||
#define WM_NORMAL_HINTS_MIN_SIZE	16
 | 
			
		||||
#define WM_NORMAL_HINTS_MAX_SIZE	32
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
x11_output_set_icon(struct x11_compositor *c, struct x11_output *output,
 | 
			
		||||
		    const char *filename, int width, int height)
 | 
			
		||||
{
 | 
			
		||||
	uint32_t *icon, *pixels;
 | 
			
		||||
 | 
			
		||||
	pixels = wlsc_load_image(filename, width, height);
 | 
			
		||||
	if (!pixels)
 | 
			
		||||
		return;
 | 
			
		||||
	icon = malloc(width * height * 4 + 8);
 | 
			
		||||
	if (!icon) {
 | 
			
		||||
		free(pixels);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	icon[0] = width;
 | 
			
		||||
	icon[1] = height;
 | 
			
		||||
	memcpy(icon + 2, pixels, width * height * 4);
 | 
			
		||||
	xcb_change_property(c->conn, XCB_PROP_MODE_REPLACE, output->window,
 | 
			
		||||
			    c->atom.net_wm_icon, c->atom.cardinal, 32,
 | 
			
		||||
			    width * height + 2, icon);
 | 
			
		||||
	free(icon);
 | 
			
		||||
	free(pixels);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int
 | 
			
		||||
x11_compositor_create_output(struct x11_compositor *c, int width, int height)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -409,6 +436,9 @@ x11_compositor_create_output(struct x11_compositor *c, int width, int height)
 | 
			
		|||
			    c->atom.wm_class, c->atom.string, 8,
 | 
			
		||||
			    sizeof class, class);
 | 
			
		||||
 | 
			
		||||
	x11_output_set_icon(c, output,
 | 
			
		||||
			    DATADIR "/wayland/wayland.png", 128, 128);
 | 
			
		||||
 | 
			
		||||
	xcb_map_window(c->conn, output->window);
 | 
			
		||||
 | 
			
		||||
	rectangle.x = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -611,8 +641,10 @@ x11_compositor_get_resources(struct x11_compositor *c)
 | 
			
		|||
		{ "WM_DELETE_WINDOW",	F(atom.wm_delete_window) },
 | 
			
		||||
		{ "WM_CLASS",		F(atom.wm_class) },
 | 
			
		||||
		{ "_NET_WM_NAME",	F(atom.net_wm_name) },
 | 
			
		||||
		{ "_NET_WM_ICON",	F(atom.net_wm_icon) },
 | 
			
		||||
		{ "STRING",		F(atom.string) },
 | 
			
		||||
		{ "UTF8_STRING",	F(atom.utf8_string) },
 | 
			
		||||
		{ "CARDINAL",		F(atom.cardinal) },
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	xcb_intern_atom_cookie_t cookies[ARRAY_SIZE(atoms)];
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -189,21 +189,22 @@ destroy_surface(struct wl_resource *resource, struct wl_client *client)
 | 
			
		|||
	wlsc_compositor_schedule_repaint(compositor);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static struct wl_buffer *
 | 
			
		||||
create_buffer_from_png(struct wlsc_compositor *ec,
 | 
			
		||||
		       const char *filename, int width, int height)
 | 
			
		||||
uint32_t *
 | 
			
		||||
wlsc_load_image(const char *filename, int width, int height)
 | 
			
		||||
{
 | 
			
		||||
	GdkPixbuf *pixbuf;
 | 
			
		||||
	GError *error = NULL;
 | 
			
		||||
	int stride, i, n_channels;
 | 
			
		||||
	unsigned char *pixels, *end, *argb_pixels, *s, *d;
 | 
			
		||||
	struct wl_buffer *buffer;
 | 
			
		||||
 | 
			
		||||
	pixbuf = gdk_pixbuf_new_from_file_at_scale(filename,
 | 
			
		||||
						   width, height,
 | 
			
		||||
						   FALSE, &error);
 | 
			
		||||
	if (error != NULL)
 | 
			
		||||
	if (error != NULL) {
 | 
			
		||||
		fprintf(stderr, "failed to load image: %s\n", error->message);
 | 
			
		||||
		g_error_free(error);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	stride = gdk_pixbuf_get_rowstride(pixbuf);
 | 
			
		||||
	pixels = gdk_pixbuf_get_pixels(pixbuf);
 | 
			
		||||
| 
						 | 
				
			
			@ -252,11 +253,23 @@ create_buffer_from_png(struct wlsc_compositor *ec,
 | 
			
		|||
 | 
			
		||||
	g_object_unref(pixbuf);
 | 
			
		||||
 | 
			
		||||
	return (uint32_t *) argb_pixels;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static struct wl_buffer *
 | 
			
		||||
create_buffer_from_png(struct wlsc_compositor *ec,
 | 
			
		||||
		       const char *filename, int width, int height)
 | 
			
		||||
{
 | 
			
		||||
	uint32_t *pixels;
 | 
			
		||||
	struct wl_buffer *buffer;
 | 
			
		||||
 | 
			
		||||
	pixels = wlsc_load_image(filename, width, height);
 | 
			
		||||
 | 
			
		||||
	buffer = ec->create_buffer(ec, width, height,
 | 
			
		||||
				   &ec->compositor.premultiplied_argb_visual,
 | 
			
		||||
				   argb_pixels);
 | 
			
		||||
				   pixels);
 | 
			
		||||
 | 
			
		||||
	free(argb_pixels);
 | 
			
		||||
	free(pixels);
 | 
			
		||||
 | 
			
		||||
	return buffer;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -230,4 +230,7 @@ tty_destroy(struct tty *tty);
 | 
			
		|||
void
 | 
			
		||||
screenshooter_create(struct wlsc_compositor *ec);
 | 
			
		||||
 | 
			
		||||
uint32_t *
 | 
			
		||||
wlsc_load_image(const char *filename, int width, int height);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,4 +19,8 @@ dist_waylanddata_DATA =				\
 | 
			
		|||
	top_right_corner.png			\
 | 
			
		||||
	top_side.png				\
 | 
			
		||||
	xterm.png				\
 | 
			
		||||
	wayland.svg
 | 
			
		||||
	wayland.svg				\
 | 
			
		||||
	wayland.png
 | 
			
		||||
 | 
			
		||||
wayland.png : wayland.svg
 | 
			
		||||
	rsvg-convert -w 128 -h 128 wayland.svg -o wayland.png
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue