From f58d8ca1bd20180bfae3a3a047e8098e0b22b5aa Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Wed, 26 Jan 2011 14:37:07 -0500 Subject: compositor-x11: Set window icon --- compositor/compositor-x11.c | 32 ++++++++++++++++++++++++++++++++ compositor/compositor.c | 27 ++++++++++++++++++++------- compositor/compositor.h | 3 +++ data/Makefile.am | 6 +++++- data/wayland.svg | 31 ++++++++++++++++--------------- 5 files changed, 76 insertions(+), 23 deletions(-) diff --git a/compositor/compositor-x11.c b/compositor/compositor-x11.c index 5cacb3f..cbd266a 100644 --- a/compositor/compositor-x11.c +++ b/compositor/compositor-x11.c @@ -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)]; diff --git a/compositor/compositor.c b/compositor/compositor.c index d391fca..746a729 100644 --- a/compositor/compositor.c +++ b/compositor/compositor.c @@ -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; } diff --git a/compositor/compositor.h b/compositor/compositor.h index ac826ed..fbfaa59 100644 --- a/compositor/compositor.h +++ b/compositor/compositor.h @@ -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 diff --git a/data/Makefile.am b/data/Makefile.am index 25ef36a..d03a58c 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -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 diff --git a/data/wayland.svg b/data/wayland.svg index 6e12c7b..29cb8f0 100644 --- a/data/wayland.svg +++ b/data/wayland.svg @@ -1,5 +1,4 @@ -