From 68d3799c476d20248f29b7d8777558856dd449a7 Mon Sep 17 00:00:00 2001 From: o9000 Date: Wed, 4 Nov 2015 13:02:12 +0100 Subject: [PATCH] Mouse effects: tint icons --- src/launcher/launcher.c | 24 +++++++++++++++++++++++- src/launcher/launcher.h | 2 ++ src/taskbar/task.c | 39 ++++++++++++++++++++++++++++++++++++--- src/taskbar/task.h | 2 ++ src/util/common.c | 16 ++++++++++++++++ src/util/common.h | 3 +++ 6 files changed, 82 insertions(+), 4 deletions(-) diff --git a/src/launcher/launcher.c b/src/launcher/launcher.c index aef78a8..d3d82ea 100644 --- a/src/launcher/launcher.c +++ b/src/launcher/launcher.c @@ -153,6 +153,8 @@ void cleanup_launcher_theme(Launcher *launcher) LauncherIcon *launcherIcon = (LauncherIcon*)l->data; if (launcherIcon) { free_icon(launcherIcon->image); + free_icon(launcherIcon->image_hover); + free_icon(launcherIcon->image_pressed); free(launcherIcon->icon_name); free(launcherIcon->icon_path); free(launcherIcon->cmd); @@ -197,12 +199,16 @@ int resize_launcher(void *obj) if (!new_icon_path) { // Draw a blank icon free_icon(launcherIcon->image); + free_icon(launcherIcon->image_hover); + free_icon(launcherIcon->image_pressed); launcherIcon->image = NULL; continue; } // Free the old files free_icon(launcherIcon->image); + free_icon(launcherIcon->image_hover); + free_icon(launcherIcon->image_pressed); // Load the new file launcherIcon->image = load_image(new_icon_path, 1); // On loading error, fallback to default @@ -226,6 +232,11 @@ int resize_launcher(void *obj) fprintf(stderr, "launcher.c %d: Using icon %s\n", __LINE__, launcherIcon->icon_path); } } + + if (panel_config.mouse_effects) { + launcherIcon->image_hover = adjust_icon(launcherIcon->image, 100, 0, 10); + launcherIcon->image_pressed = adjust_icon(launcherIcon->image, 100, 0, -10); + } } count = g_slist_length(launcher->list_icons); @@ -322,8 +333,19 @@ void draw_launcher_icon(void *obj, cairo_t *c) { LauncherIcon *launcherIcon = (LauncherIcon*)obj; + Imlib_Image image; // Render - imlib_context_set_image(launcherIcon->image); + if (panel_config.mouse_effects) { + if (launcherIcon->area.mouse_state == MOUSE_OVER) + image = launcherIcon->image_hover ? launcherIcon->image_hover : launcherIcon->image; + else if (launcherIcon->area.mouse_state == MOUSE_DOWN) + image = launcherIcon->image_pressed ? launcherIcon->image_pressed : launcherIcon->image; + else + image = launcherIcon->image; + } else { + image = launcherIcon->image; + } + imlib_context_set_image(image); render_image(launcherIcon->area.pix, 0, 0); } diff --git a/src/launcher/launcher.h b/src/launcher/launcher.h index 1f77f47..14d602c 100644 --- a/src/launcher/launcher.h +++ b/src/launcher/launcher.h @@ -24,6 +24,8 @@ typedef struct LauncherIcon { // always start with area Area area; Imlib_Image image; + Imlib_Image image_hover; + Imlib_Image image_pressed; char *cmd; char *icon_name; char *icon_path; diff --git a/src/taskbar/task.c b/src/taskbar/task.c index d76898e..0c71749 100644 --- a/src/taskbar/task.c +++ b/src/taskbar/task.c @@ -111,6 +111,8 @@ Task *add_task (Window win) new_tsk2->area._get_tooltip_text = task_get_tooltip; for (k=0; kicon[k] = new_tsk.icon[k]; + new_tsk2->icon_hover[k] = new_tsk.icon_hover[k]; + new_tsk2->icon_press[k] = new_tsk.icon_press[k]; new_tsk2->state_pix[k] = 0; } new_tsk2->icon_width = new_tsk.icon_width; @@ -162,8 +164,18 @@ void remove_task (Task *tsk) imlib_context_set_image(tsk->icon[k]); imlib_free_image(); tsk->icon[k] = 0; - if (tsk->state_pix[k]) XFreePixmap(server.dsp, tsk->state_pix[k]); } + if (tsk->icon_hover[k]) { + imlib_context_set_image(tsk->icon_hover[k]); + imlib_free_image(); + tsk->icon_hover[k] = 0; + } + if (tsk->icon_press[k]) { + imlib_context_set_image(tsk->icon_press[k]); + imlib_free_image(); + tsk->icon_press[k] = 0; + } + if (tsk->state_pix[k]) XFreePixmap(server.dsp, tsk->state_pix[k]); } int i; @@ -310,6 +322,10 @@ void get_icon (Task *tsk) adjust_asb(data32, tsk->icon_width, tsk->icon_height, panel->g_task.alpha[k], (float)panel->g_task.saturation[k]/100, (float)panel->g_task.brightness[k]/100); imlib_image_put_back_data(data32); } + if (panel_config.mouse_effects) { + tsk->icon_hover[k] = adjust_icon(tsk->icon[k], 100, 0, 10); + tsk->icon_press[k] = adjust_icon(tsk->icon[k], 100, 0, -10); + } } imlib_context_set_image(orig_image); imlib_free_image(); @@ -326,8 +342,11 @@ void get_icon (Task *tsk) tsk2->icon_width = tsk->icon_width; tsk2->icon_height = tsk->icon_height; int k; - for (k=0; kicon[k] = tsk->icon[k]; + tsk2->icon_hover[k] = tsk->icon_hover[k]; + tsk2->icon_press[k] = tsk->icon_press[k]; + } set_task_redraw(tsk2); } } @@ -350,7 +369,21 @@ void draw_task_icon (Task *tsk, int text_width) else pos_x = panel->g_task.area.paddingxlr + tsk->area.bg->border.width; // Render - imlib_context_set_image (tsk->icon[tsk->current_state]); + + Imlib_Image image; + // Render + if (panel_config.mouse_effects) { + if (tsk->area.mouse_state == MOUSE_OVER) + image = tsk->icon_hover[tsk->current_state]; + else if (tsk->area.mouse_state == MOUSE_DOWN) + image = tsk->icon_press[tsk->current_state]; + else + image = tsk->icon[tsk->current_state]; + } else { + image = tsk->icon[tsk->current_state]; + } + + imlib_context_set_image(image); render_image(tsk->area.pix, pos_x, panel->g_task.icon_posy); } diff --git a/src/taskbar/task.h b/src/taskbar/task.h index 31a62a4..ea24842 100644 --- a/src/taskbar/task.h +++ b/src/taskbar/task.h @@ -57,6 +57,8 @@ typedef struct { int desktop; int current_state; Imlib_Image icon[TASK_STATE_COUNT]; + Imlib_Image icon_hover[TASK_STATE_COUNT]; + Imlib_Image icon_press[TASK_STATE_COUNT]; Pixmap state_pix[TASK_STATE_COUNT]; unsigned int icon_width; unsigned int icon_height; diff --git a/src/util/common.c b/src/util/common.c index 94c2c62..6293aeb 100644 --- a/src/util/common.c +++ b/src/util/common.c @@ -508,3 +508,19 @@ Imlib_Image load_image(const char *path, int cached) } return image; } + +Imlib_Image adjust_icon(Imlib_Image original, int alpha, int saturation, int brightness) +{ + if (!original) + return NULL; + + imlib_context_set_image(original); + Imlib_Image copy = imlib_clone_image(); + + imlib_context_set_image(copy); + imlib_image_set_has_alpha(1); + DATA32* data = imlib_image_get_data(); + adjust_asb(data, imlib_image_get_width(), imlib_image_get_height(), alpha, (float)saturation/100, (float)brightness/100); + imlib_image_put_back_data(data); + return copy; +} diff --git a/src/util/common.h b/src/util/common.h index 30af0a6..e25a5b3 100644 --- a/src/util/common.h +++ b/src/util/common.h @@ -75,5 +75,8 @@ void render_image(Drawable d, int x, int y); void draw_text(PangoLayout *layout, cairo_t *c, int posx, int posy, Color *color, int font_shadow); Imlib_Image load_image(const char *path, int cached); + +Imlib_Image adjust_icon(Imlib_Image original, int alpha, int saturation, int brightness); + #endif