Mouse effects: fixes, changed defaults, more config options

This commit is contained in:
o9000 2015-11-04 23:14:11 +01:00
parent 68d3799c47
commit 0900c088ee
6 changed files with 86 additions and 26 deletions

View file

@ -70,6 +70,11 @@ char *snapshot_path;
// detect if it's an old config file (==1)
static int new_config_file;
static int read_bg_color_hover;
static int read_border_color_hover;
static int read_bg_color_press;
static int read_border_color_press;
void default_config()
{
@ -205,10 +210,25 @@ void add_entry (char *key, char *value)
/* Background and border */
if (strcmp (key, "rounded") == 0) {
// 'rounded' is the first parameter => alloc a new background
if (backgrounds->len > 0) {
Background *bg = &g_array_index(backgrounds, Background, backgrounds->len-1);
if (!read_bg_color_hover)
memcpy(&bg->back_hover, &bg->back, sizeof(Color));
if (!read_border_color_hover)
memcpy(&bg->border_hover, &bg->border, sizeof(Color));
if (!read_bg_color_press)
memcpy(&bg->back_pressed, &bg->back, sizeof(Color));
if (!read_border_color_press)
memcpy(&bg->border_pressed, &bg->border, sizeof(Color));
}
Background bg;
init_background(&bg);
bg.border.rounded = atoi(value);
g_array_append_val(backgrounds, bg);
read_bg_color_hover = 0;
read_border_color_hover = 0;
read_bg_color_press = 0;
read_border_color_press = 0;
}
else if (strcmp (key, "border_width") == 0) {
g_array_index(backgrounds, Background, backgrounds->len-1).border.width = atoi(value);
@ -233,6 +253,7 @@ void add_entry (char *key, char *value)
get_color (value1, bg->back_hover.color);
if (value2) bg->back_hover.alpha = (atoi (value2) / 100.0);
else bg->back_hover.alpha = 0.5;
read_bg_color_hover = 1;
}
else if (strcmp (key, "border_color_hover") == 0) {
Background* bg = &g_array_index(backgrounds, Background, backgrounds->len-1);
@ -240,6 +261,23 @@ void add_entry (char *key, char *value)
get_color (value1, bg->border_hover.color);
if (value2) bg->border_hover.alpha = (atoi (value2) / 100.0);
else bg->border_hover.alpha = 0.5;
read_border_color_hover = 1;
}
else if (strcmp (key, "background_color_pressed") == 0) {
Background* bg = &g_array_index(backgrounds, Background, backgrounds->len-1);
extract_values(value, &value1, &value2, &value3);
get_color (value1, bg->back_pressed.color);
if (value2) bg->back_pressed.alpha = (atoi (value2) / 100.0);
else bg->back_pressed.alpha = 0.5;
read_bg_color_press = 1;
}
else if (strcmp (key, "border_color_pressed") == 0) {
Background* bg = &g_array_index(backgrounds, Background, backgrounds->len-1);
extract_values(value, &value1, &value2, &value3);
get_color (value1, bg->border_pressed.color);
if (value2) bg->border_pressed.alpha = (atoi (value2) / 100.0);
else bg->border_pressed.alpha = 0.5;
read_border_color_press = 1;
}
/* Panel */
@ -842,6 +880,19 @@ void add_entry (char *key, char *value)
get_action (value, &mouse_scroll_down);
else if (strcmp (key, "mouse_effects") == 0)
panel_config.mouse_effects = atoi(value);
else if (strcmp(key, "mouse_hover_icon_asb") == 0) {
extract_values(value, &value1, &value2, &value3);
panel_config.mouse_over_alpha = atoi(value1);
panel_config.mouse_over_saturation = atoi(value2);
panel_config.mouse_over_brightness = atoi(value3);
}
else if (strcmp(key, "mouse_pressed_icon_asb") == 0) {
extract_values(value, &value1, &value2, &value3);
panel_config.mouse_pressed_alpha = atoi(value1);
panel_config.mouse_pressed_saturation = atoi(value2);
panel_config.mouse_pressed_brightness = atoi(value3);
}
/* autohide options */
else if (strcmp(key, "autohide") == 0)
@ -985,6 +1036,18 @@ int config_read_file (const char *path)
panel_items_order = strdup("T");
}
if (backgrounds->len > 0) {
Background *bg = &g_array_index(backgrounds, Background, backgrounds->len-1);
if (!read_bg_color_hover)
memcpy(&bg->back_hover, &bg->back, sizeof(Color));
if (!read_border_color_hover)
memcpy(&bg->border_hover, &bg->border, sizeof(Color));
if (!read_bg_color_press)
memcpy(&bg->back_pressed, &bg->back, sizeof(Color));
if (!read_border_color_press)
memcpy(&bg->border_pressed, &bg->border, sizeof(Color));
}
return 1;
}

View file

@ -234,8 +234,8 @@ int resize_launcher(void *obj)
}
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);
launcherIcon->image_hover = adjust_icon(launcherIcon->image, panel_config.mouse_over_alpha, panel_config.mouse_over_saturation, panel_config.mouse_over_brightness);
launcherIcon->image_pressed = adjust_icon(launcherIcon->image, panel_config.mouse_pressed_alpha, panel_config.mouse_pressed_saturation, panel_config.mouse_pressed_brightness);
}
}

View file

@ -97,6 +97,12 @@ void default_panel()
backgrounds = g_array_new(0, 0, sizeof(Background));
memset(&panel_config, 0, sizeof(Panel));
panel_config.mouse_over_alpha = 100;
panel_config.mouse_over_saturation = 0;
panel_config.mouse_over_brightness = 10;
panel_config.mouse_pressed_alpha = 100;
panel_config.mouse_pressed_saturation = 0;
panel_config.mouse_pressed_brightness = -10;
// append full transparency background
Background transparent_bg;
@ -227,7 +233,7 @@ void init_panel()
XChangeWindowAttributes(server.dsp, p->main_win, CWEventMask, &(XSetWindowAttributes){.event_mask=event_mask});
if (!server.gc) {
XGCValues gcv;
XGCValues gcv;
server.gc = XCreateGC(server.dsp, p->main_win, 0, &gcv);
}
//printf("panel %d : %d, %d, %d, %d\n", i, p->posx, p->posy, p->area.width, p->area.height);
@ -444,7 +450,7 @@ void update_strut(Panel* p)
int d3;
XGetGeometry(server.dsp, server.root_win, &d2, &d3, &d3, &screen_width, &screen_height, &d1, &d1);
Monitor monitor = server.monitor[p->monitor];
long struts [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
long struts [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
if (panel_horizontal) {
int height = p->area.height + p->marginy;
if (panel_strut_policy == STRUT_MINIMUM || (panel_strut_policy == STRUT_FOLLOW_SIZE && p->is_hidden))
@ -613,7 +619,7 @@ void set_panel_background(Panel *p)
get_root_pixmap();
// copy background (server.root_pmap) in panel.area.pix
Window dummy;
int x, y;
int x, y;
XTranslateCoordinates(server.dsp, p->main_win, server.root_win, 0, 0, &x, &y, &dummy);
if (panel_autohide && p->is_hidden) {
x -= xoff;

View file

@ -92,6 +92,13 @@ typedef struct {
int monitor;
int font_shadow;
int mouse_effects;
// Mouse effects for icons
int mouse_over_alpha;
int mouse_over_saturation;
int mouse_over_brightness;
int mouse_pressed_alpha;
int mouse_pressed_saturation;
int mouse_pressed_brightness;
// --------------------------------------------------
// task and taskbar parameter per panel

View file

@ -61,6 +61,7 @@ Task *add_task (Window win)
else monitor = 0;
Task new_tsk;
memset(&new_tsk, 0, sizeof(new_tsk));
new_tsk.area.mouse_over_effect = 1;
new_tsk.area.mouse_press_effect = 1;
new_tsk.win = win;
@ -271,7 +272,7 @@ void get_icon (Task *tsk)
DATA32 icon_data[w * h];
int length = w * h;
for (i = 0; i < length; ++i)
icon_data[i] = tmp_data[i];
icon_data[i] = tmp_data[i];
img = imlib_create_image_using_copied_data (w, h, icon_data);
#else
img = imlib_create_image_using_data (w, h, (DATA32*)tmp_data);
@ -284,7 +285,7 @@ void get_icon (Task *tsk)
if (hints->flags & IconPixmapHint && hints->icon_pixmap != 0) {
// get width, height and depth for the pixmap
Window root;
int icon_x, icon_y;
int icon_x, icon_y;
uint border_width, bpp;
uint w, h;
@ -323,8 +324,8 @@ void get_icon (Task *tsk)
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);
tsk->icon_hover[k] = adjust_icon(tsk->icon[k], panel_config.mouse_over_alpha, panel_config.mouse_over_saturation, panel_config.mouse_over_brightness);
tsk->icon_press[k] = adjust_icon(tsk->icon[k], panel_config.mouse_pressed_alpha, panel_config.mouse_pressed_saturation, panel_config.mouse_pressed_brightness);
}
}
imlib_context_set_image(orig_image);

View file

@ -596,21 +596,4 @@ void mouse_out()
void init_background(Background *bg)
{
memset(bg, 0, sizeof(Background));
bg->back_hover.color[0] = 0.8;
bg->back_hover.color[1] = 0.8;
bg->back_hover.color[2] = 0.8;
bg->back_hover.alpha = 0.3;
bg->border_hover.color[0] = 0.8;
bg->border_hover.color[1] = 0.8;
bg->border_hover.color[2] = 0.8;
bg->border_hover.alpha = 0.5;
bg->back_pressed.color[0] = 0.6;
bg->back_pressed.color[1] = 0.6;
bg->back_pressed.color[2] = 0.6;
bg->back_pressed.alpha = 0.3;
bg->border_pressed.color[0] = 0.8;
bg->border_pressed.color[1] = 0.8;
bg->border_pressed.color[2] = 0.8;
bg->border_pressed.alpha = 0.5;
}