Mouse effects: tint icons
This commit is contained in:
parent
1b554ebc1e
commit
68d3799c47
6 changed files with 82 additions and 4 deletions
|
@ -153,6 +153,8 @@ void cleanup_launcher_theme(Launcher *launcher)
|
||||||
LauncherIcon *launcherIcon = (LauncherIcon*)l->data;
|
LauncherIcon *launcherIcon = (LauncherIcon*)l->data;
|
||||||
if (launcherIcon) {
|
if (launcherIcon) {
|
||||||
free_icon(launcherIcon->image);
|
free_icon(launcherIcon->image);
|
||||||
|
free_icon(launcherIcon->image_hover);
|
||||||
|
free_icon(launcherIcon->image_pressed);
|
||||||
free(launcherIcon->icon_name);
|
free(launcherIcon->icon_name);
|
||||||
free(launcherIcon->icon_path);
|
free(launcherIcon->icon_path);
|
||||||
free(launcherIcon->cmd);
|
free(launcherIcon->cmd);
|
||||||
|
@ -197,12 +199,16 @@ int resize_launcher(void *obj)
|
||||||
if (!new_icon_path) {
|
if (!new_icon_path) {
|
||||||
// Draw a blank icon
|
// Draw a blank icon
|
||||||
free_icon(launcherIcon->image);
|
free_icon(launcherIcon->image);
|
||||||
|
free_icon(launcherIcon->image_hover);
|
||||||
|
free_icon(launcherIcon->image_pressed);
|
||||||
launcherIcon->image = NULL;
|
launcherIcon->image = NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free the old files
|
// Free the old files
|
||||||
free_icon(launcherIcon->image);
|
free_icon(launcherIcon->image);
|
||||||
|
free_icon(launcherIcon->image_hover);
|
||||||
|
free_icon(launcherIcon->image_pressed);
|
||||||
// Load the new file
|
// Load the new file
|
||||||
launcherIcon->image = load_image(new_icon_path, 1);
|
launcherIcon->image = load_image(new_icon_path, 1);
|
||||||
// On loading error, fallback to default
|
// 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);
|
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);
|
count = g_slist_length(launcher->list_icons);
|
||||||
|
@ -322,8 +333,19 @@ void draw_launcher_icon(void *obj, cairo_t *c)
|
||||||
{
|
{
|
||||||
LauncherIcon *launcherIcon = (LauncherIcon*)obj;
|
LauncherIcon *launcherIcon = (LauncherIcon*)obj;
|
||||||
|
|
||||||
|
Imlib_Image image;
|
||||||
// Render
|
// 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);
|
render_image(launcherIcon->area.pix, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@ typedef struct LauncherIcon {
|
||||||
// always start with area
|
// always start with area
|
||||||
Area area;
|
Area area;
|
||||||
Imlib_Image image;
|
Imlib_Image image;
|
||||||
|
Imlib_Image image_hover;
|
||||||
|
Imlib_Image image_pressed;
|
||||||
char *cmd;
|
char *cmd;
|
||||||
char *icon_name;
|
char *icon_name;
|
||||||
char *icon_path;
|
char *icon_path;
|
||||||
|
|
|
@ -111,6 +111,8 @@ Task *add_task (Window win)
|
||||||
new_tsk2->area._get_tooltip_text = task_get_tooltip;
|
new_tsk2->area._get_tooltip_text = task_get_tooltip;
|
||||||
for (k=0; k<TASK_STATE_COUNT; ++k) {
|
for (k=0; k<TASK_STATE_COUNT; ++k) {
|
||||||
new_tsk2->icon[k] = new_tsk.icon[k];
|
new_tsk2->icon[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->state_pix[k] = 0;
|
||||||
}
|
}
|
||||||
new_tsk2->icon_width = new_tsk.icon_width;
|
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_context_set_image(tsk->icon[k]);
|
||||||
imlib_free_image();
|
imlib_free_image();
|
||||||
tsk->icon[k] = 0;
|
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;
|
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);
|
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);
|
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_context_set_image(orig_image);
|
||||||
imlib_free_image();
|
imlib_free_image();
|
||||||
|
@ -326,8 +342,11 @@ void get_icon (Task *tsk)
|
||||||
tsk2->icon_width = tsk->icon_width;
|
tsk2->icon_width = tsk->icon_width;
|
||||||
tsk2->icon_height = tsk->icon_height;
|
tsk2->icon_height = tsk->icon_height;
|
||||||
int k;
|
int k;
|
||||||
for (k=0; k<TASK_STATE_COUNT; ++k)
|
for (k=0; k<TASK_STATE_COUNT; ++k) {
|
||||||
tsk2->icon[k] = tsk->icon[k];
|
tsk2->icon[k] = tsk->icon[k];
|
||||||
|
tsk2->icon_hover[k] = tsk->icon_hover[k];
|
||||||
|
tsk2->icon_press[k] = tsk->icon_press[k];
|
||||||
|
}
|
||||||
set_task_redraw(tsk2);
|
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;
|
else pos_x = panel->g_task.area.paddingxlr + tsk->area.bg->border.width;
|
||||||
|
|
||||||
// Render
|
// 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);
|
render_image(tsk->area.pix, pos_x, panel->g_task.icon_posy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,8 @@ typedef struct {
|
||||||
int desktop;
|
int desktop;
|
||||||
int current_state;
|
int current_state;
|
||||||
Imlib_Image icon[TASK_STATE_COUNT];
|
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];
|
Pixmap state_pix[TASK_STATE_COUNT];
|
||||||
unsigned int icon_width;
|
unsigned int icon_width;
|
||||||
unsigned int icon_height;
|
unsigned int icon_height;
|
||||||
|
|
|
@ -508,3 +508,19 @@ Imlib_Image load_image(const char *path, int cached)
|
||||||
}
|
}
|
||||||
return image;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
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 load_image(const char *path, int cached);
|
||||||
|
|
||||||
|
Imlib_Image adjust_icon(Imlib_Image original, int alpha, int saturation, int brightness);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue