X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Fsystray%2Fsystraybar.c;h=e9b6c509b040b5a058f9e4772e2ca2c7e3907484;hb=367bf8f76227dea6e7e10e974967ae1d60cfe38e;hp=7e28239fadc2b3ea7a005967c9ffe8051892fc0a;hpb=2e63fd9929fd2c261ad47f4d995dc99722177954;p=chaz%2Ftint2 diff --git a/src/systray/systraybar.c b/src/systray/systraybar.c index 7e28239..e9b6c50 100644 --- a/src/systray/systraybar.c +++ b/src/systray/systraybar.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include "systraybar.h" @@ -49,6 +48,9 @@ int refresh_systray; int systray_enabled; int systray_max_icon_size = 0; +// background pixmap if we render ourselves the icons +static Pixmap render_background = 0; + void init_systray() { @@ -88,12 +90,19 @@ void cleanup_systray() systray_enabled = 0; systray.area.on_screen = 0; free_area(&systray.area); + if (render_background) XFreePixmap(server.dsp, render_background); } void draw_systray(void *obj, cairo_t *c, int active) { - // tint2 don't draw systray icons. just the background. + if (real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) { + if (render_background) XFreePixmap(server.dsp, render_background); + render_background = XCreatePixmap(server.dsp, server.root_win, systray.area.width, systray.area.height, server.depth); + XCopyArea(server.dsp, systray.area.pix.pmap, render_background, server.gc, 0, 0, systray.area.width, systray.area.height, 0, 0); + } + + // tint2 don't draw systray icons. just the background. refresh_systray = 1; } @@ -331,20 +340,22 @@ gboolean add_icon(Window id) int hide = 0; error = FALSE; - int wrong_format = 0; XWindowAttributes attr; XGetWindowAttributes(server.dsp, id, &attr); + unsigned long mask = 0; XSetWindowAttributes set_attr; - wrong_format = (attr.depth != server.depth); - set_attr.colormap = attr.colormap; - set_attr.background_pixel = 0; - set_attr.border_pixel = 0; - unsigned long mask = CWColormap|CWBackPixel|CWBorderPixel; + if (attr.depth != server.depth || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0 ) { + set_attr.colormap = attr.colormap; + set_attr.background_pixel = 0; + set_attr.border_pixel = 0; + mask = CWColormap|CWBackPixel|CWBorderPixel; + } + else { + set_attr.background_pixmap = ParentRelative; + mask = CWBackPixmap; + } Window parent_window; - if (real_transparency) - parent_window = XCreateWindow(server.dsp, panel->main_win, 0, 0, 30, 30, 0, attr.depth, InputOutput, attr.visual, mask, &set_attr); - else - parent_window = panel->main_win; + parent_window = XCreateWindow(server.dsp, panel->main_win, 0, 0, 30, 30, 0, attr.depth, InputOutput, attr.visual, mask, &set_attr); old = XSetErrorHandler(window_error_handler); XReparentWindow(server.dsp, id, parent_window, 0, 0); XSync(server.dsp, False); @@ -393,13 +404,11 @@ gboolean add_icon(Window id) } traywin = g_new0(TrayWindow, 1); - if (real_transparency) - traywin->id = parent_window; - else - traywin->id = id; + traywin->id = parent_window; traywin->tray_id = id; traywin->hide = hide; - traywin->wrong_format = wrong_format; + traywin->depth = attr.depth; + traywin->damage = 0; if (systray.sort == 3) systray.list_icons = g_slist_prepend(systray.list_icons, traywin); @@ -413,15 +422,15 @@ gboolean add_icon(Window id) // watch for the icon trying to resize itself! XSelectInput(server.dsp, traywin->tray_id, StructureNotifyMask); - if (real_transparency) { - XDamageCreate(server.dsp, traywin->id, XDamageReportRawRectangles); + if (real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) { + traywin->damage = XDamageCreate(server.dsp, traywin->id, XDamageReportNonEmpty); XCompositeRedirectWindow(server.dsp, traywin->id, CompositeRedirectManual); } // show the window if (!traywin->hide) { - XMapRaised(server.dsp, traywin->id); XMapRaised(server.dsp, traywin->tray_id); + XMapRaised(server.dsp, traywin->id); } // changed in systray force resize on panel @@ -442,6 +451,8 @@ void remove_icon(TrayWindow *traywin) //printf("remove_icon id %lx, %d\n", traywin->id); XSelectInput(server.dsp, traywin->tray_id, NoEventMask); + if (traywin->damage) + XDamageDestroy(server.dsp, traywin->damage); // reparent to root error = FALSE; @@ -449,8 +460,7 @@ void remove_icon(TrayWindow *traywin) if (!traywin->hide) XUnmapWindow(server.dsp, traywin->id); XReparentWindow(server.dsp, traywin->tray_id, server.root_win, 0, 0); - if (traywin->id != traywin->tray_id) - XDestroyWindow(server.dsp, traywin->id); + XDestroyWindow(server.dsp, traywin->id); XSync(server.dsp, False); XSetErrorHandler(old); g_free(traywin); @@ -488,48 +498,49 @@ void net_message(XClientMessageEvent *e) } } - -void systray_render_icons(TrayWindow* traywin) +void systray_render_icon_now(void* t) { - // most systray icons support 32 bit depth, but some icons are still 24 bit. + TrayWindow* traywin = t; + traywin->render_timeout = 0; + + // good systray icons support 32 bit depth, but some icons are still 24 bit. // We create a heuristic mask for these icons, i.e. we get the rgb value in the top left corner, and // mask out all pixel with the same rgb value - - Picture picture_systray, picture_tray, picture_panel; - Drawable mask, tray_pixmap; Panel* panel = systray.area.panel; - XWindowAttributes attr; - XGetWindowAttributes(server.dsp, traywin->id, &attr); - XRenderPictFormat *format = XRenderFindVisualFormat(server.dsp, attr.visual); - XRenderPictFormat *panel_format = XRenderFindVisualFormat(server.dsp, server.visual); - if (traywin->wrong_format) { - imlib_context_set_drawable(traywin->id); - Imlib_Image image = imlib_create_image_from_drawable(0, 0, 0, traywin->width, traywin->height, 0); - imlib_context_set_image(image); - imlib_image_set_has_alpha(1); - DATA32* data = imlib_image_get_data(); + imlib_context_set_drawable(traywin->id); + Imlib_Image image = imlib_create_image_from_drawable(0, 0, 0, traywin->width, traywin->height, 0); + if (image == 0) + return; + + imlib_context_set_image(image); + imlib_image_set_has_alpha(1); + DATA32* data = imlib_image_get_data(); + if (traywin->depth == 24) { createHeuristicMask(data, traywin->width, traywin->height); - imlib_image_put_back_data(data); - imlib_render_pixmaps_for_whole_image(&tray_pixmap, &mask); - picture_tray = XRenderCreatePicture( server.dsp, tray_pixmap, panel_format, 0, 0); - Picture mask2 = XRenderCreatePicture( server.dsp, mask, XRenderFindStandardFormat(server.dsp, PictStandardA1), 0, 0); - picture_systray = XRenderCreatePicture( server.dsp, systray.area.pix.pmap, panel_format, 0, 0); - picture_panel = XRenderCreatePicture(server.dsp, panel->main_win, panel_format, 0, 0); - XRenderComposite(server.dsp, PictOpOver, picture_tray, mask2, picture_systray, 0, 0, 0, 0, traywin->x-systray.area.posx, traywin->y-systray.area.posy, traywin->width, traywin->height); - XRenderComposite(server.dsp, PictOpOver, picture_tray, mask2, picture_panel, 0, 0, 0, 0, traywin->x, traywin->y, traywin->width, traywin->height); - imlib_free_pixmap_and_mask(tray_pixmap); - imlib_free_image(); + } + if (systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) + adjust_asb(data, traywin->width, traywin->height, systray.alpha, (float)systray.saturation/100, (float)systray.brightness/100); + imlib_image_put_back_data(data); + XCopyArea(server.dsp, render_background, systray.area.pix.pmap, server.gc, traywin->x-systray.area.posx, traywin->y-systray.area.posy, traywin->width, traywin->height, traywin->x-systray.area.posx, traywin->y-systray.area.posy); + if ( !real_transparency ) { + imlib_context_set_drawable(systray.area.pix.pmap); + imlib_render_image_on_drawable(traywin->x-systray.area.posx, traywin->y-systray.area.posy); } else { - picture_tray = XRenderCreatePicture( server.dsp, traywin->id, format, 0, 0); - picture_systray = XRenderCreatePicture( server.dsp, systray.area.pix.pmap, panel_format, 0, 0); - picture_panel = XRenderCreatePicture(server.dsp, panel->main_win, panel_format, 0, 0); - XRenderComposite(server.dsp, PictOpOver, picture_tray, None, picture_systray, 0, 0, 0, 0, traywin->x-systray.area.posx, traywin->y-systray.area.posy, traywin->width, traywin->height); - XRenderComposite(server.dsp, PictOpOver, picture_tray, None, picture_panel, 0, 0, 0, 0, traywin->x, traywin->y, traywin->width, traywin->height); + render_image(systray.area.pix.pmap, traywin->x-systray.area.posx, traywin->y-systray.area.posy, traywin->width, traywin->height); } - XRenderFreePicture(server.dsp, picture_systray); - XRenderFreePicture(server.dsp, picture_tray); - XRenderFreePicture(server.dsp, picture_panel); + XCopyArea(server.dsp, systray.area.pix.pmap, panel->main_win, server.gc, traywin->x-systray.area.posx, traywin->y-systray.area.posy, traywin->width, traywin->height, traywin->x, traywin->y); + imlib_free_image_and_decache(); + + XDamageSubtract(server.dsp, traywin->damage, None, None); + XFlush(server.dsp); +} + +void systray_render_icon(TrayWindow* traywin) +{ + // wine tray icons update whenever mouse is over them, so we limit the updates to 50 ms + if (traywin->render_timeout == 0) + traywin->render_timeout = add_timeout(50, 0, systray_render_icon_now, traywin); } @@ -540,9 +551,9 @@ void refresh_systray_icon() for (l = systray.list_icons; l ; l = l->next) { traywin = (TrayWindow*)l->data; if (traywin->hide) continue; - if (real_transparency) systray_render_icons(traywin); - else XClearArea(server.dsp, traywin->id, 0, 0, traywin->width, traywin->height, True); + if (real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) + systray_render_icon(traywin); + else + XClearArea(server.dsp, traywin->id, 0, 0, traywin->width, traywin->height, True); } - if (real_transparency) - XFlush(server.dsp); }