Mouse pressed effect + some fixes for mouse over
This commit is contained in:
parent
34b341767c
commit
732b9d3910
12 changed files with 89 additions and 35 deletions
|
@ -65,6 +65,7 @@ strut_policy = follow_size
|
|||
panel_window_name = tint2
|
||||
disable_transparency = 0
|
||||
font_shadow = 0
|
||||
mouse_effects = 1
|
||||
|
||||
#-------------------------------------
|
||||
# Taskbar
|
||||
|
|
|
@ -63,6 +63,7 @@ strut_policy = follow_size
|
|||
panel_window_name = tint2
|
||||
disable_transparency = 0
|
||||
font_shadow = 0
|
||||
mouse_effects = 1
|
||||
|
||||
#-------------------------------------
|
||||
# Taskbar
|
||||
|
|
|
@ -69,6 +69,7 @@ strut_policy = follow_size
|
|||
panel_window_name = tint2
|
||||
disable_transparency = 0
|
||||
font_shadow = 0
|
||||
mouse_effects = 1
|
||||
|
||||
#-------------------------------------
|
||||
# Taskbar
|
||||
|
|
|
@ -71,6 +71,7 @@ strut_policy = follow_size
|
|||
panel_window_name = tint2
|
||||
disable_transparency = 0
|
||||
font_shadow = 0
|
||||
mouse_effects = 1
|
||||
|
||||
#-------------------------------------
|
||||
# Taskbar
|
||||
|
|
|
@ -227,12 +227,12 @@ void init_battery_panel(void *p)
|
|||
battery->area._resize = resize_battery;
|
||||
battery->area.on_screen = 1;
|
||||
battery->area.resize = 1;
|
||||
battery->area.mouse_effects = battery_lclick_command ||
|
||||
battery_mclick_command ||
|
||||
battery_rclick_command ||
|
||||
battery_uwheel_command ||
|
||||
battery_dwheel_command;
|
||||
|
||||
battery->area.mouse_over_effect = battery_lclick_command ||
|
||||
battery_mclick_command ||
|
||||
battery_rclick_command ||
|
||||
battery_uwheel_command ||
|
||||
battery_dwheel_command;
|
||||
battery->area.mouse_press_effect = battery->area.mouse_over_effect;
|
||||
if (battery_tooltip_enabled)
|
||||
battery->area._get_tooltip_text = battery_get_tooltip;
|
||||
}
|
||||
|
|
|
@ -185,11 +185,11 @@ void init_clock_panel(void *p)
|
|||
clock->area.bg = &g_array_index(backgrounds, Background, 0);
|
||||
clock->area.parent = p;
|
||||
clock->area.panel = p;
|
||||
clock->area.mouse_effects = clock_lclick_command ||
|
||||
clock_mclick_command ||
|
||||
clock_rclick_command ||
|
||||
clock_uwheel_command ||
|
||||
clock_dwheel_command;
|
||||
clock->area.mouse_press_effect = clock->area.mouse_over_effect = clock_lclick_command ||
|
||||
clock_mclick_command ||
|
||||
clock_rclick_command ||
|
||||
clock_uwheel_command ||
|
||||
clock_dwheel_command;
|
||||
clock->area._draw_foreground = draw_clock;
|
||||
clock->area.size_mode = SIZE_BY_CONTENT;
|
||||
clock->area._resize = resize_clock;
|
||||
|
|
|
@ -431,7 +431,8 @@ void launcher_load_icons(Launcher *launcher)
|
|||
launcherIcon->area._resize = NULL;
|
||||
launcherIcon->area.resize = 0;
|
||||
launcherIcon->area.redraw = 1;
|
||||
launcherIcon->area.mouse_effects = 1;
|
||||
launcherIcon->area.mouse_over_effect = 1;
|
||||
launcherIcon->area.mouse_press_effect = 1;
|
||||
launcherIcon->area.bg = launcher_icon_bg;
|
||||
launcherIcon->area.on_screen = 1;
|
||||
launcherIcon->area._on_change_layout = launcher_icon_on_change_layout;
|
||||
|
|
|
@ -61,7 +61,8 @@ Task *add_task (Window win)
|
|||
else monitor = 0;
|
||||
|
||||
Task new_tsk;
|
||||
new_tsk.area.mouse_effects = 1;
|
||||
new_tsk.area.mouse_over_effect = 1;
|
||||
new_tsk.area.mouse_press_effect = 1;
|
||||
new_tsk.win = win;
|
||||
new_tsk.desktop = window_get_desktop (win);
|
||||
new_tsk.area.panel = &panel1[monitor];
|
||||
|
@ -92,7 +93,8 @@ Task *add_task (Window win)
|
|||
new_tsk2 = calloc(1, sizeof(Task));
|
||||
memcpy(&new_tsk2->area, &panel1[monitor].g_task.area, sizeof(Area));
|
||||
new_tsk2->area.parent = tskbar;
|
||||
new_tsk2->area.mouse_effects = 1;
|
||||
new_tsk2->area.mouse_over_effect = 1;
|
||||
new_tsk2->area.mouse_press_effect = 1;
|
||||
new_tsk2->win = new_tsk.win;
|
||||
new_tsk2->desktop = new_tsk.desktop;
|
||||
new_tsk2->win_x = new_tsk.win_x;
|
||||
|
@ -356,7 +358,8 @@ void draw_task_icon (Task *tsk, int text_width)
|
|||
void draw_task (void *obj, cairo_t *c)
|
||||
{
|
||||
Task *tsk = obj;
|
||||
//tsk->state_pix[tsk->current_state] = tsk->area.pix;
|
||||
if (!panel_config.mouse_effects)
|
||||
tsk->state_pix[tsk->current_state] = tsk->area.pix;
|
||||
PangoLayout *layout;
|
||||
Color *config_text;
|
||||
int width=0, height;
|
||||
|
@ -515,9 +518,13 @@ void set_task_state(Task *tsk, int state)
|
|||
Task* tsk1 = g_ptr_array_index(task_group, i);
|
||||
tsk1->current_state = state;
|
||||
tsk1->area.bg = panel1[0].g_task.background[state];
|
||||
//tsk1->area.pix = tsk1->state_pix[state];
|
||||
if (!tsk1->area.pix)
|
||||
if (!panel_config.mouse_effects) {
|
||||
tsk1->area.pix = tsk1->state_pix[state];
|
||||
if (!tsk1->area.pix)
|
||||
tsk1->area.redraw = 1;
|
||||
} else {
|
||||
tsk1->area.redraw = 1;
|
||||
}
|
||||
if (state == TASK_ACTIVE && g_slist_find(urgent_list, tsk1))
|
||||
del_urgent(tsk1);
|
||||
int hide = 0;
|
||||
|
|
|
@ -62,7 +62,8 @@ void init_taskbarname_panel(void *p)
|
|||
tskbar = &panel->taskbar[j];
|
||||
memcpy(&tskbar->bar_name.area, &panel->g_taskbar.area_name, sizeof(Area));
|
||||
tskbar->bar_name.area.parent = tskbar;
|
||||
tskbar->bar_name.area.mouse_effects = 1;
|
||||
tskbar->bar_name.area.mouse_over_effect = 1;
|
||||
tskbar->bar_name.area.mouse_press_effect = 1;
|
||||
if (j == server.desktop)
|
||||
tskbar->bar_name.area.bg = panel->g_taskbar.background_name[TASKBAR_ACTIVE];
|
||||
else
|
||||
|
|
14
src/tint.c
14
src/tint.c
|
@ -1296,14 +1296,22 @@ start:
|
|||
}
|
||||
|
||||
switch (e.type) {
|
||||
case ButtonPress:
|
||||
case ButtonPress: {
|
||||
tooltip_hide(0);
|
||||
event_button_press (&e);
|
||||
Area* area = click_area(panel, e.xbutton.x, e.xbutton.y);
|
||||
if (panel_config.mouse_effects)
|
||||
mouse_over(area, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
case ButtonRelease:
|
||||
case ButtonRelease: {
|
||||
event_button_release(&e);
|
||||
Area* area = click_area(panel, e.xbutton.x, e.xbutton.y);
|
||||
if (panel_config.mouse_effects)
|
||||
mouse_over(area, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
case MotionNotify: {
|
||||
unsigned int button_mask = Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask;
|
||||
|
@ -1317,7 +1325,7 @@ start:
|
|||
else
|
||||
tooltip_trigger_hide();
|
||||
if (panel_config.mouse_effects)
|
||||
mouse_over(area);
|
||||
mouse_over(area, e.xmotion.state & button_mask);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -393,7 +393,7 @@ void set_redraw (Area *a)
|
|||
|
||||
GList *l;
|
||||
for (l = a->children ; l ; l = l->next)
|
||||
set_redraw(l->data);
|
||||
set_redraw((Area*)l->data);
|
||||
}
|
||||
|
||||
void hide(Area *a)
|
||||
|
@ -446,11 +446,13 @@ void draw (Area *a)
|
|||
void draw_background (Area *a, cairo_t *c)
|
||||
{
|
||||
if (a->bg->back.alpha > 0.0 ||
|
||||
(panel_config.mouse_effects && a->mouse_effects && a->mouse_state == MOUSE_OVER)) {
|
||||
(panel_config.mouse_effects && (a->mouse_over_effect || a->mouse_press_effect))) {
|
||||
//printf(" draw_background (%d %d) RGBA (%lf, %lf, %lf, %lf)\n", a->posx, a->posy, pix->back.color[0], pix->back.color[1], pix->back.color[2], pix->back.alpha);
|
||||
if (a->mouse_state == MOUSE_OVER) {
|
||||
if (a->mouse_state == MOUSE_OVER)
|
||||
cairo_set_source_rgba(c, a->bg->back_hover.color[0], a->bg->back_hover.color[1], a->bg->back_hover.color[2], a->bg->back_hover.alpha);
|
||||
} else
|
||||
else if (a->mouse_state == MOUSE_DOWN)
|
||||
cairo_set_source_rgba(c, a->bg->back_pressed.color[0], a->bg->back_pressed.color[1], a->bg->back_pressed.color[2], a->bg->back_pressed.alpha);
|
||||
else
|
||||
cairo_set_source_rgba(c, a->bg->back.color[0], a->bg->back.color[1], a->bg->back.color[2], a->bg->back.alpha);
|
||||
draw_rect(c, a->bg->border.width, a->bg->border.width, a->width-(2.0 * a->bg->border.width), a->height-(2.0*a->bg->border.width), a->bg->border.rounded - a->bg->border.width/1.571);
|
||||
cairo_fill(c);
|
||||
|
@ -460,9 +462,11 @@ void draw_background (Area *a, cairo_t *c)
|
|||
cairo_set_line_width (c, a->bg->border.width);
|
||||
|
||||
// draw border inside (x, y, width, height)
|
||||
if (a->mouse_state == MOUSE_OVER) {
|
||||
if (a->mouse_state == MOUSE_OVER)
|
||||
cairo_set_source_rgba(c, a->bg->border_hover.color[0], a->bg->border_hover.color[1], a->bg->border_hover.color[2], a->bg->border_hover.alpha);
|
||||
} else
|
||||
else if (a->mouse_state == MOUSE_DOWN)
|
||||
cairo_set_source_rgba(c, a->bg->border_pressed.color[0], a->bg->border_pressed.color[1], a->bg->border_pressed.color[2], a->bg->border_pressed.alpha);
|
||||
else
|
||||
cairo_set_source_rgba(c, a->bg->border.color[0], a->bg->border.color[1], a->bg->border.color[2], a->bg->border.alpha);
|
||||
draw_rect(c, a->bg->border.width/2.0, a->bg->border.width/2.0, a->width - a->bg->border.width, a->height - a->bg->border.width, a->bg->border.rounded);
|
||||
|
||||
|
@ -481,7 +485,7 @@ void remove_area (void *a)
|
|||
set_redraw (parent);
|
||||
|
||||
if (mouse_over_area == a) {
|
||||
mouse_over_area = NULL;
|
||||
mouse_out();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -547,16 +551,32 @@ void clear_pixmap(Pixmap p, int x, int y, int w, int h)
|
|||
XRenderFreePicture(server.dsp, pict);
|
||||
}
|
||||
|
||||
void mouse_over(Area *area)
|
||||
void mouse_over(Area *area, int pressed)
|
||||
{
|
||||
if (mouse_over_area == area)
|
||||
if (mouse_over_area == area && !area)
|
||||
return;
|
||||
|
||||
MouseState new_state = MOUSE_NORMAL;
|
||||
if (area) {
|
||||
if (!pressed) {
|
||||
new_state = area->mouse_over_effect ? MOUSE_OVER : MOUSE_NORMAL;
|
||||
} else {
|
||||
new_state = area->mouse_press_effect
|
||||
? MOUSE_DOWN
|
||||
: area->mouse_over_effect
|
||||
? MOUSE_OVER
|
||||
: MOUSE_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
if (mouse_over_area == area && mouse_over_area->mouse_state == new_state)
|
||||
return;
|
||||
mouse_out();
|
||||
if (!area->mouse_effects)
|
||||
if (new_state == MOUSE_NORMAL)
|
||||
return;
|
||||
mouse_over_area = area;
|
||||
|
||||
mouse_over_area->mouse_state = MOUSE_OVER;
|
||||
mouse_over_area->mouse_state = new_state;
|
||||
set_redraw(mouse_over_area);
|
||||
panel_refresh = 1;
|
||||
}
|
||||
|
@ -582,4 +602,13 @@ void init_background(Background *bg)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,8 @@ typedef struct
|
|||
Border border;
|
||||
Color back_hover;
|
||||
Color border_hover;
|
||||
Color back_pressed;
|
||||
Color border_pressed;
|
||||
} Background;
|
||||
|
||||
|
||||
|
@ -57,7 +59,8 @@ enum { ALIGN_LEFT = 0, ALIGN_CENTER = 1, ALIGN_RIGHT = 2 };
|
|||
|
||||
typedef enum {
|
||||
MOUSE_NORMAL = 0,
|
||||
MOUSE_OVER = 1
|
||||
MOUSE_OVER = 1,
|
||||
MOUSE_DOWN = 2
|
||||
} MouseState;
|
||||
|
||||
|
||||
|
@ -91,7 +94,8 @@ typedef struct {
|
|||
// panel
|
||||
void *panel;
|
||||
|
||||
int mouse_effects;
|
||||
int mouse_over_effect;
|
||||
int mouse_press_effect;
|
||||
MouseState mouse_state;
|
||||
|
||||
// each object can overwrite following function
|
||||
|
@ -141,7 +145,7 @@ void draw_rect(cairo_t *c, double x, double y, double w, double h, double r);
|
|||
// clear pixmap with transparent color
|
||||
void clear_pixmap(Pixmap p, int x, int y, int w, int h);
|
||||
|
||||
void mouse_over(Area *area);
|
||||
void mouse_over(Area *area, int pressed);
|
||||
void mouse_out();
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue