This patch highlites appicon of a currently focused window.

Original-patch-by: Peter Zijlstra <[email protected]>
Signed-off-by: Alexey I. Froloff <[email protected]>
---
 src/actions.c     |   15 ++++++++++++-
 src/application.c |    3 ++
 src/application.h |   18 +++++++++++++++++
 src/icon.c        |   28 +++++++++++++++++++++++---
 wrlib/misc.c      |   55 ++++++++++++++++++++++++++++++++++++++++++----------
 wrlib/wraster.h   |    2 +
 6 files changed, 104 insertions(+), 17 deletions(-)

diff --git a/src/actions.c b/src/actions.c
index f8339b1..65d7801 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -132,8 +132,12 @@ void wSetFocusTo(WScreen *scr, WWindow *wwin)
                XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, 
CurrentTime);
                if (old_focused)
                        wWindowUnfocus(old_focused);
-               if (oapp)
+               if (oapp) {
                        wAppMenuUnmap(oapp->menu);
+#ifdef NEWAPPICON
+                       wApplicationDeactivate(oapp);
+#endif
+               }
 
                WMPostNotificationName(WMNChangedFocus, NULL, (void *)True);
                return;
@@ -194,8 +198,12 @@ void wSetFocusTo(WScreen *scr, WWindow *wwin)
                wwin->next = NULL;
                scr->focused_window = wwin;
 
-               if (oapp && oapp != napp)
+               if (oapp && oapp != napp) {
                        wAppMenuUnmap(oapp->menu);
+#ifdef NEWAPPICON
+                       wApplicationDeactivate(oapp);
+#endif
+               }
        }
 
        wWindowFocus(wwin, focused);
@@ -207,6 +215,9 @@ void wSetFocusTo(WScreen *scr, WWindow *wwin)
 
                if (wwin->flags.mapped)
                        wAppMenuMap(napp->menu, wwin);
+#ifdef NEWAPPICON
+               wApplicationActivate(napp);
+#endif
        }
 
        XFlush(dpy);
diff --git a/src/application.c b/src/application.c
index 19fcb52..9e511f8 100644
--- a/src/application.c
+++ b/src/application.c
@@ -434,6 +434,9 @@ void wApplicationDestroy(WApplication * wapp)
 
        XDeleteContext(dpy, wapp->main_window, wAppWinContext);
        wAppMenuDestroy(wapp->menu);
+#ifdef NEWAPPICON
+       wApplicationDeactivate(wapp);
+#endif
        if (wapp->app_icon) {
                if (wapp->app_icon->docked && !wapp->app_icon->attracted) {
                        wapp->app_icon->running = 0;
diff --git a/src/application.h b/src/application.h
index b7c1e09..c408cf5 100644
--- a/src/application.h
+++ b/src/application.h
@@ -62,5 +62,23 @@ void wApplicationExtractDirPackIcon(WScreen *scr,char *path, 
char *wm_instance,
                                     char *wm_class);
 
 void wAppBounce(WApplication *);
+
+#ifdef NEWAPPICON
+
+#define wApplicationActivate(wapp) do { \
+               if (wapp->app_icon) { \
+                       wIconSetHighlited(wapp->app_icon->icon, True); \
+                       wAppIconPaint(wapp->app_icon);\
+               } \
+       } while(0)
+
+#define wApplicationDeactivate(wapp) do { \
+               if (wapp->app_icon) { \
+                       wIconSetHighlited(wapp->app_icon->icon, False); \
+                       wAppIconPaint(wapp->app_icon);\
+               } \
+       } while(0)
+
 #endif
 
+#endif
diff --git a/src/icon.c b/src/icon.c
index c781542..d1392c8 100644
--- a/src/icon.c
+++ b/src/icon.c
@@ -279,7 +279,7 @@ static void drawIconTitle(WScreen * scr, Pixmap pixmap, int 
height)
                  wPreferences.icon_size - 1, 0, wPreferences.icon_size - 1, 
height + 1);
 }
 
-static Pixmap makeIcon(WScreen * scr, RImage * icon, int titled, int shadowed, 
int tileType)
+static Pixmap makeIcon(WScreen *scr, RImage *icon, int titled, int shadowed, 
int tileType, int highlighted)
 {
        RImage *tile;
        Pixmap pixmap;
@@ -322,6 +322,13 @@ static Pixmap makeIcon(WScreen * scr, RImage * icon, int 
titled, int shadowed, i
                color.alpha = 150;      /* about 60% */
                RClearImage(tile, &color);
        }
+       if (highlighted) {
+               RColor color;
+
+               color.red = color.green = color.blue = 0;
+               color.alpha = 160;
+               RLightImage(tile, &color);
+       }
 
        if (!RConvertImage(scr->rcontext, tile, &pixmap)) {
                wwarning(_("error rendering image:%s"), 
RMessageForError(RErrorCode));
@@ -520,6 +527,19 @@ static void cycleColor(void *data)
        icon->handlerID = WMAddTimerHandler(COLOR_CYCLE_DELAY, cycleColor, 
icon);
 }
 
+#ifdef NEWAPPICON
+void wIconSetHighlited(WIcon * icon, Bool flag)
+{
+       if (icon->highlighted == flag) {
+               return;
+       }
+
+       icon->highlighted = flag;
+       icon->force_paint = True;
+       wIconPaint(icon);
+}
+#endif
+
 void wIconSelect(WIcon * icon)
 {
        WScreen *scr = icon->core->screen_ptr;
@@ -669,7 +689,7 @@ void wIconUpdate(WIcon * icon)
 
                if (icon->image) {
                        icon->pixmap = makeIcon(scr, icon->image, 
icon->show_title,
-                                               icon->shadowed, 
icon->tile_type);
+                                               icon->shadowed, 
icon->tile_type, icon->highlighted);
                } else {
                        /* make default icons */
 
@@ -696,8 +716,8 @@ void wIconUpdate(WIcon * icon)
  make_icons:
 
                                image = wIconValidateIconSize(scr, image);
-                               scr->def_icon_pixmap = makeIcon(scr, image, 
False, False, icon->tile_type);
-                               scr->def_ticon_pixmap = makeIcon(scr, image, 
True, False, icon->tile_type);
+                               scr->def_icon_pixmap = makeIcon(scr, image, 
False, False, icon->tile_type, icon->highlighted);
+                               scr->def_ticon_pixmap = makeIcon(scr, image, 
True, False, icon->tile_type, icon->highlighted);
                                if (image)
                                        RReleaseImage(image);
                        }
diff --git a/wrlib/misc.c b/wrlib/misc.c
index 7904215..c8963af 100644
--- a/wrlib/misc.c
+++ b/wrlib/misc.c
@@ -140,7 +140,7 @@ void RClearImage(RImage * image, RColor * color)
                }
        } else {
                int bytes = image->width * image->height;
-               int alpha, nalpha, r, g, b;
+               int alpha, nalpha, r, g, b, s;
 
                alpha = color->alpha;
                r = color->red * alpha;
@@ -148,16 +148,49 @@ void RClearImage(RImage * image, RColor * color)
                b = color->blue * alpha;
                nalpha = 255 - alpha;
 
-               for (i = 0; i < bytes; i++) {
-                       *d = (((int)*d * nalpha) + r) / 256;
-                       d++;
-                       *d = (((int)*d * nalpha) + g) / 256;
-                       d++;
-                       *d = (((int)*d * nalpha) + b) / 256;
-                       d++;
-                       if (image->format == RRGBAFormat) {
-                               d++;
-                       }
+               s = (image->format == RRGBAFormat) ? 4 : 3;
+
+               for (i=0; i<bytes; i++, d+=s) {
+                       d[0] = (((int)d[0] * nalpha) + r)/256;
+                       d[1] = (((int)d[1] * nalpha) + g)/256;
+                       d[2] = (((int)d[2] * nalpha) + b)/256;
+               }
+       }
+}
+
+static __inline__ unsigned char
+clip(int c) {
+       if (c > 255) c=255;
+       return (unsigned char)c;
+}
+
+void
+RLightImage(RImage *image, RColor *color)
+{
+       unsigned char *d = image->data;
+       unsigned char *dd;
+       int alpha, r, g, b, s;
+
+       s = (image->format == RRGBAFormat) ? 4 : 3;
+       dd = d + s*image->width*image->height;
+
+       r = color->red;
+       g = color->green;
+       b = color->blue;
+
+       alpha = color->alpha;
+
+       if (r == 0 && g == 0 && b == 0) {
+               for (; d<dd; d+=s) {
+                       d[0] = clip(((int)d[0] * alpha)/128);
+                       d[1] = clip(((int)d[1] * alpha)/128);
+                       d[2] = clip(((int)d[2] * alpha)/128);
+               }
+       } else {
+               for (; d<dd; d+=s) {
+                       d[0] = clip((((int)d[0] * alpha) + r)/128);
+                       d[1] = clip((((int)d[1] * alpha) + g)/128);
+                       d[2] = clip((((int)d[2] * alpha) + b)/128);
                }
        }
 }
diff --git a/wrlib/wraster.h b/wrlib/wraster.h
index 73611d4..78bfc16 100644
--- a/wrlib/wraster.h
+++ b/wrlib/wraster.h
@@ -411,6 +411,8 @@ void RHSVtoRGB(RHSVColor *hsv, RColor *rgb);
  */
 void RClearImage(RImage *image, RColor *color);
 
+void RLightImage(RImage *image, RColor *color);
+
 void RFillImage(RImage *image, RColor *color);
 
 void RBevelImage(RImage *image, int bevel_type);
-- 
1.7.2.3


-- 
To unsubscribe, send mail to [email protected].

Reply via email to