diff options
author | Kristian Høgsberg <krh@bitplanet.net> | 2011-01-26 14:37:07 -0500 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2011-01-26 14:37:07 -0500 |
commit | f58d8ca1bd20180bfae3a3a047e8098e0b22b5aa (patch) | |
tree | 51ca2d7afe676494811e766e746fee6436e03b5e | |
parent | 24ed62138869e8d510f374445c0f9bc644594142 (diff) |
compositor-x11: Set window icon
-rw-r--r-- | compositor/compositor-x11.c | 32 | ||||
-rw-r--r-- | compositor/compositor.c | 27 | ||||
-rw-r--r-- | compositor/compositor.h | 3 | ||||
-rw-r--r-- | data/Makefile.am | 6 | ||||
-rw-r--r-- | 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 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> - <!-- Copyright © 2010 Kristian Høgsberg Permission to use, copy, modify, distribute, and sell this @@ -33,12 +32,12 @@ xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="744.09448819" - height="1052.3622047" + width="128" + height="128" id="svg2" version="1.1" inkscape:version="0.48.0 r9654" - sodipodi:docname="wayland-2.svg" + sodipodi:docname="wayland.svg" inkscape:export-filename="/home/krh/wayland.png" inkscape:export-xdpi="41.302303" inkscape:export-ydpi="41.302303"> @@ -51,16 +50,16 @@ borderopacity="1.0" inkscape:pageopacity="0" inkscape:pageshadow="2" - inkscape:zoom="1.3493453" + inkscape:zoom="1.1" inkscape:cx="246.80131" - inkscape:cy="588.75473" + inkscape:cy="58.818182" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="false" - inkscape:window-width="1391" - inkscape:window-height="1086" - inkscape:window-x="904" - inkscape:window-y="339" + inkscape:window-width="1278" + inkscape:window-height="740" + inkscape:window-x="0" + inkscape:window-y="26" inkscape:window-maximized="0" /> <metadata id="metadata7"> @@ -70,7 +69,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -78,7 +77,8 @@ inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" - style="display:inline"> + style="display:inline" + transform="translate(0,-924.36218)"> <path sodipodi:type="arc" style="fill:#ffbc00;fill-opacity:1;stroke:none" @@ -87,10 +87,11 @@ sodipodi:cy="465.21933" sodipodi:rx="122.85714" sodipodi:ry="122.85714" - d="m 464.2857,465.21933 a 122.85714,122.85714 0 1 1 -245.71428,0 122.85714,122.85714 0 1 1 245.71428,0 z" /> + d="m 464.2857,465.21933 a 122.85714,122.85714 0 1 1 -245.71428,0 122.85714,122.85714 0 1 1 245.71428,0 z" + transform="matrix(0.49134614,0,0,0.49134614,-102.99669,759.57895)" /> <g - transform="scale(0.9155896,1.0921924)" - style="font-size:437.47387695px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;" + transform="matrix(0.44987141,0,0,0.53664452,-102.99669,759.57895)" + style="font-size:437.47387695px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none" id="text2987"> <path d="m 443.91049,314.59549 2.34971,0 -1.49527,1.49528 -0.85444,0 0,-1.49528 m -173.02434,3.63138 0,1.70888 -5.55387,6.83553 -0.85444,0 -0.85444,-5.34026 c 3.27538,-2.13591 5.69629,-3.20396 7.26275,-3.20415 m 202.50256,2.34971 c 4.84164,1.9e-4 7.54736,3.06194 8.11719,9.18524 l -4.0586,28.83739 1.49528,0 3.20415,-2.1361 0.85444,0 0,0.64083 c -4.41481,2.70589 -8.68701,10.11103 -12.81662,22.21547 -1.56666,10.39583 -4.20118,20.00828 -7.90358,28.83739 -3.27553,9.11414 -4.91321,17.51613 -4.91303,25.20602 l -6.1947,15.16633 c -1.7e-4,1.28172 2.34954,2.56338 7.04914,3.84498 -0.85462,2.9906 -2.13628,4.48587 -3.84499,4.48582 l 0,0.85444 1.49527,0 0,0.64083 c -1.7e-4,1.56653 -2.42108,2.34977 -7.26275,2.34971 l 0.85444,0.85444 0,2.99055 -1.49527,0 c 0.99668,2.99059 3.13279,4.48586 6.40831,4.48581 l 0,1.49528 -6.40831,0 0,0.85444 c 2.13594,4e-5 3.20399,1.2817 3.20416,3.84498 l -8.97163,2.99055 0.85444,0.85444 0,0.64083 c -1.6e-4,0.99688 -1.06821,1.4953 -3.20416,1.49527 l 0,0.85444 c 2.70557,3e-5 4.05844,0.49846 4.0586,1.49527 -3.84515,1.28169 -8.90058,7.61879 -15.16633,19.01132 -6.40845,10.11089 -11.96231,15.16633 -16.66161,15.16633 l -1.70888,0 c -3.56029,-2.27851 -6.47963,-9.82607 -8.75802,-22.64269 -9.11415,-19.5097 -13.67116,-30.97344 -13.67106,-34.39126 -1e-4,-8.82916 -2.91944,-18.228 -8.75802,-28.19656 -1.56657,-4.41452 -2.63462,-9.96839 -3.20416,-16.6616 l -3.84498,-0.85444 c -9.68375,14.66799 -14.73919,26.13173 -15.16633,34.39126 -2.7058,4.84189 -4.8419,10.68057 -6.40831,17.51604 5.83861,1.56652 8.75795,3.06179 8.75802,4.48582 l 0,0.85444 c -4.55709,-0.56959 -7.76124,-1.63764 -9.61246,-3.20416 -1.99376,3.84503 -4.62829,14.52553 -7.90358,32.04155 -2.56338,8.11719 -5.76753,12.17578 -9.61247,12.17578 -10.82295,-3.56016 -19.86578,-9.39884 -27.1285,-17.51604 -1.13928,2e-5 -2.99057,-4.05857 -5.55387,-12.17579 -1.56649,3e-5 -2.63454,-4.05856 -3.20415,-12.17578 -5.41147,-11.5349 -9.11405,-24.70753 -11.10774,-39.51791 l 0,-22.21547 -0.85444,0 -3.84499,0.85444 0,-0.85444 c 1e-5,-0.99674 1.28167,-1.49516 3.84499,-1.49527 l -0.85444,-12.81662 0,-10.03968 -6.1947,-32.04154 0,-13.67106 c 2.70573,-8.54423 7.40515,-12.81643 14.09828,-12.81662 l 44.85816,0 0,1.49527 c -3.56022,0.14259 -5.98114,0.92583 -7.26275,2.34972 -2.70577,-1.5663 -5.3403,-2.34953 -7.90358,-2.34972 l -8.75802,0 -4.91304,0.64083 -0.85444,-0.64083 -0.64083,0 -6.40831,0.64083 -3.20415,-0.64083 -2.34972,0.64083 -2.56332,-0.64083 c 10.39568,11.39272 16.51917,21.00518 18.37048,28.83739 l 7.26275,0 0,1.49527 -5.55386,0 0,1.70889 c 2.13607,6.55086 3.70254,9.82621 4.69942,9.82607 l 1.70889,0 3.84498,-0.85444 0.85444,0.85444 0.85444,-0.85444 0.85444,0.85444 0,0.64083 c -2.84817,1.70902 -4.77066,4.05873 -5.76747,7.04914 l -0.64083,0 0,1.49527 1.49527,0 c 1.99366,23.78206 5.69623,41.79651 11.10773,54.04341 l 3.20416,2.1361 1.70888,0 c 2.13605,8e-5 6.62186,-8.33072 13.45745,-24.99241 4.41454,-7.54745 7.61869,-14.16936 9.61246,-19.86575 l -0.85444,-2.34972 c 4.41453,-5.55373 8.97155,-8.33066 13.67106,-8.3308 l 1.49527,0 c 2.99045,1.4e-4 5.12655,1.56661 6.40831,4.69943 3.98729,4.69955 7.19144,11.74868 9.61246,21.14742 l 11.96218,22.21547 c 1.56635,1.56656 2.34959,3.34664 2.34971,5.34026 4.41449,8.40207 8.40188,13.95593 11.96218,16.6616 l 2.56332,0 c 2.99041,6e-5 6.9778,-10.39563 11.96218,-31.1871 0.85429,9e-5 3.204,-5.55377 7.04914,-16.66161 l 0,-0.85444 -13.45745,-1.49527 -3.20416,0.85444 -4.05859,0 0,-1.70888 8.11719,-0.64083 15.80716,0 c 6.12333,-18.37035 11.7484,-32.61103 16.87521,-42.72206 1.70871,-20.79122 4.05842,-31.18691 7.04914,-31.1871 l 9.61247,-3.84499 m -45.49899,2.34971 c -0.85459,1.99389 -2.70588,2.99074 -5.55387,2.99055 l 0,-1.49527 5.55387,-1.49528 m -80.53108,3.84499 21.57464,0 0,1.49527 -4.91304,0.64083 -4.69943,-0.64083 -4.05859,1.49527 -1.49528,-1.49527 -6.4083,0 0,-1.49527 m -112.35902,2.99054 2.34972,0 1.49527,1.49528 0,0.85444 -4.69943,4.48581 0,3.84499 -1.70888,0 0,-2.34971 0.85444,-0.64084 0,-0.85444 -4.0586,-3.84498 c 0.99691,-1.99352 2.9194,-2.99036 5.76748,-2.99055 m 157.00357,9.18525 2.34971,0 0,0.64083 c -1.1e-4,0.99702 -0.78335,1.49544 -2.34971,1.49527 l -0.85444,0.85444 0,0.85444 -2.34972,-0.85444 0,-1.49527 3.20416,-1.49527 m -11.96218,8.3308 0,0.85444 c -1e-4,1.13942 -3.41786,2.34988 -10.25329,3.63137 l 0,-1.49527 4.69942,-2.1361 0.85444,0.64083 0.64083,0 4.0586,-1.49527 m -139.48752,7.68997 0,0.64083 -1.70888,1.49527 -0.64083,-0.64083 0,-0.85444 0.64083,-0.64083 1.70888,0 m 116.41761,0 0,0.64083 c -2.99062,2.27866 -7.83244,4.34356 -14.5255,6.1947 l 0,-1.49527 c 1.13919,1.5e-4 1.70882,-0.78309 1.70888,-2.34972 l 12.81662,-2.99054 m 40.58595,7.47636 0.85445,0.85444 0,0.64083 -1.49528,1.70888 -0.85444,0 -1.70888,-1.70888 0,-0.64083 3.20415,-0.85444 m 29.47822,0.85444 0.85445,0 0,0.64083 -1.49528,1.70888 -0.85444,0 0,-0.85444 1.49527,-1.49527 m -13.45744,10.68051 3.20415,2.13611 c -0.56976,1.56661 -2.13623,2.34985 -4.69943,2.34971 l -1.70888,-2.34971 c -1.3e-4,-0.7119 1.06792,-1.42393 3.20416,-2.13611 m 19.22492,9.82608 0.64083,0.85444 0,0.64083 -0.64083,0.85444 -1.70888,0 0,-0.85444 1.70888,-1.49527 m -30.33266,7.68997 0,0.64083 -4.05859,3.20415 -2.34972,0 0,-0.85444 c -1.1e-4,-1.28154 2.13599,-2.27839 6.40831,-2.99054 m -132.43838,29.69183 0.85444,0 0,0.64083 c -2.13609,4.69951 -3.98737,7.54765 -5.55387,8.54441 l -1.70888,0 0,-3.20415 6.40831,-5.98109 m 104.45543,35.67292 0.85444,0 0,1.49527 -6.4083,3.20415 -0.85445,-0.85444 0,-1.49527 6.40831,-2.34971 m -87.79383,10.03968 1.49527,0 2.56333,8.3308 -1.70888,0 -2.34972,-7.68997 0,-0.64083 m 85.44412,9.82607 0.64083,0 2.56332,2.34972 -0.85444,0.64083 -0.85444,0 -1.49527,-2.1361 0,-0.85445" |