Merge branch 'moreclicks' into 'master'

Moreclicks

The two commits in this merge request would allow the user to set up as many as eight extra custom actions via tint2rc.

I've been running these changes (minus the up/down wheel actions) for many months without any obvious issues, mainly to adjust laptop screen brightness via a couple of scripts.

I've just tested the wheel actions and they appeared to work fine. The clock commit should solve issue #505.

I have merely augmented the work of two other people, and appropriate credits/references are indicated in the individual commit messages.

See merge request !5
This commit is contained in:
o9000 2015-08-01 07:02:51 +00:00
commit c874e76343
8 changed files with 165 additions and 1 deletions

View file

@ -56,6 +56,11 @@ static char buf_bat_time[20];
int8_t battery_low_status;
unsigned char battery_low_cmd_sent;
char *battery_low_cmd;
char *battery_lclick_command;
char *battery_mclick_command;
char *battery_rclick_command;
char *battery_uwheel_command;
char *battery_dwheel_command;
gchar *path_energy_now;
gchar *path_energy_full;
gchar *path_current_now;
@ -141,6 +146,11 @@ void default_battery()
bat1_font_desc = NULL;
bat2_font_desc = NULL;
battery_low_cmd = NULL;
battery_lclick_command = NULL;
battery_mclick_command = NULL;
battery_rclick_command = NULL;
battery_uwheel_command = NULL;
battery_dwheel_command = NULL;
path_energy_now = NULL;
path_energy_full = NULL;
path_current_now = NULL;
@ -171,6 +181,16 @@ void cleanup_battery()
path_status = NULL;
free(battery_low_cmd);
battery_low_cmd = NULL;
free(battery_lclick_command);
battery_lclick_command = NULL;
free(battery_mclick_command);
battery_mclick_command = NULL;
free(battery_rclick_command);
battery_rclick_command = NULL;
free(battery_uwheel_command);
battery_uwheel_command = NULL;
free(battery_dwheel_command);
battery_dwheel_command = NULL;
stop_timeout(battery_timeout);
battery_timeout = NULL;
battery_found = 0;
@ -574,3 +594,26 @@ int resize_battery(void *obj)
}
return ret;
}
void battery_action(int button)
{
char *command = 0;
switch (button) {
case 1:
command = battery_lclick_command;
break;
case 2:
command = battery_mclick_command;
break;
case 3:
command = battery_rclick_command;
break;
case 4:
command = battery_uwheel_command;
break;
case 5:
command = battery_dwheel_command;
break;
}
tint_exec(command);
}

View file

@ -56,6 +56,12 @@ extern int percentage_hide;
extern int8_t battery_low_status;
extern char *battery_low_cmd;
extern char *battery_lclick_command;
extern char *battery_mclick_command;
extern char *battery_rclick_command;
extern char *battery_uwheel_command;
extern char *battery_dwheel_command;
// default global data
void default_battery();
@ -71,4 +77,6 @@ void draw_battery(void *obj, cairo_t *c);
int resize_battery(void *obj);
void battery_action(int button);
#endif

View file

@ -39,7 +39,10 @@ char *time2_timezone;
char *time_tooltip_format;
char *time_tooltip_timezone;
char *clock_lclick_command;
char *clock_mclick_command;
char *clock_rclick_command;
char *clock_uwheel_command;
char *clock_dwheel_command;
struct timeval time_clock;
PangoFontDescription *time1_font_desc;
PangoFontDescription *time2_font_desc;
@ -61,7 +64,10 @@ void default_clock()
time_tooltip_format = NULL;
time_tooltip_timezone = NULL;
clock_lclick_command = NULL;
clock_mclick_command = NULL;
clock_rclick_command = NULL;
clock_uwheel_command = NULL;
clock_dwheel_command = NULL;
time1_font_desc = NULL;
time2_font_desc = NULL;
}
@ -86,8 +92,14 @@ void cleanup_clock()
time_tooltip_timezone = NULL;
free(clock_lclick_command);
clock_lclick_command = NULL;
free(clock_mclick_command);
clock_mclick_command = NULL;
free(clock_rclick_command);
clock_rclick_command = NULL;
free(clock_uwheel_command);
clock_uwheel_command = NULL;
free(clock_dwheel_command);
clock_dwheel_command = NULL;
stop_timeout(clock_timeout);
clock_timeout = NULL;
}
@ -277,9 +289,18 @@ void clock_action(int button)
case 1:
command = clock_lclick_command;
break;
case 2:
command = clock_mclick_command;
break;
case 3:
command = clock_rclick_command;
break;
case 4:
command = clock_uwheel_command;
break;
case 5:
command = clock_dwheel_command;
break;
}
tint_exec(command);
}

View file

@ -33,7 +33,10 @@ extern char *time_tooltip_timezone;
extern PangoFontDescription *time1_font_desc;
extern PangoFontDescription *time2_font_desc;
extern char *clock_lclick_command;
extern char *clock_mclick_command;
extern char *clock_rclick_command;
extern char *clock_uwheel_command;
extern char *clock_dwheel_command;
extern int clock_enabled;

View file

@ -356,6 +356,36 @@ void add_entry (char *key, char *value)
battery_low_status = atoi(value);
if(battery_low_status < 0 || battery_low_status > 100)
battery_low_status = 0;
#endif
}
else if (strcmp(key, "battery_lclick_command") == 0) {
#ifdef ENABLE_BATTERY
if (strlen(value) > 0)
battery_lclick_command = strdup(value);
#endif
}
else if (strcmp(key, "battery_mclick_command") == 0) {
#ifdef ENABLE_BATTERY
if (strlen(value) > 0)
battery_mclick_command = strdup(value);
#endif
}
else if (strcmp(key, "battery_rclick_command") == 0) {
#ifdef ENABLE_BATTERY
if (strlen(value) > 0)
battery_rclick_command = strdup(value);
#endif
}
else if (strcmp(key, "battery_uwheel_command") == 0) {
#ifdef ENABLE_BATTERY
if (strlen(value) > 0)
battery_uwheel_command = strdup(value);
#endif
}
else if (strcmp(key, "battery_dwheel_command") == 0) {
#ifdef ENABLE_BATTERY
if (strlen(value) > 0)
battery_dwheel_command = strdup(value);
#endif
}
else if (strcmp (key, "battery_low_cmd") == 0) {
@ -470,10 +500,22 @@ void add_entry (char *key, char *value)
if (strlen(value) > 0)
clock_lclick_command = strdup(value);
}
else if (strcmp(key, "clock_mclick_command") == 0) {
if (strlen(value) > 0)
clock_mclick_command = strdup(value);
}
else if (strcmp(key, "clock_rclick_command") == 0) {
if (strlen(value) > 0)
clock_rclick_command = strdup(value);
}
else if (strcmp(key, "clock_uwheel_command") == 0) {
if (strlen(value) > 0)
clock_uwheel_command = strdup(value);
}
else if (strcmp(key, "clock_dwheel_command") == 0) {
if (strlen(value) > 0)
clock_dwheel_command = strdup(value);
}
/* Taskbar */
else if (strcmp (key, "taskbar_mode") == 0) {

View file

@ -796,6 +796,22 @@ int click_clock(Panel *panel, int x, int y)
}
#ifdef ENABLE_BATTERY
int click_battery(Panel *panel, int x, int y)
{
Battery bat = panel->battery;
if (panel_horizontal) {
if (bat.area.on_screen && x >= bat.area.posx && x <= (bat.area.posx + bat.area.width))
return TRUE;
} else {
if (bat.area.on_screen && y >= bat.area.posy && y <= (bat.area.posy + bat.area.height))
return TRUE;
}
return FALSE;
}
#endif
Area* click_area(Panel *panel, int x, int y)
{
Area* result = &panel->area;

View file

@ -160,6 +160,11 @@ Launcher *click_launcher (Panel *panel, int x, int y);
LauncherIcon *click_launcher_icon (Panel *panel, int x, int y);
int click_padding(Panel *panel, int x, int y);
int click_clock(Panel *panel, int x, int y);
#ifdef ENABLE_BATTERY
int click_battery(Panel *panel, int x, int y);
#endif
Area* click_area(Panel *panel, int x, int y);
void autohide_show(void* p);

View file

@ -447,11 +447,27 @@ int tint2_handles_click(Panel* panel, XButtonEvent* e)
if (tskbar && e->button == 1 && panel_mode == MULTI_DESKTOP)
return 1;
if (click_clock(panel, e->x, e->y)) {
if ( (e->button == 1 && clock_lclick_command) || (e->button == 3 && clock_rclick_command) )
if ( (e->button == 1 && clock_lclick_command) ||
(e->button == 2 && clock_mclick_command) ||
(e->button == 3 && clock_rclick_command) ||
(e->button == 4 && clock_uwheel_command) ||
(e->button == 5 && clock_dwheel_command) )
return 1;
else
return 0;
}
#ifdef ENABLE_BATTERY
if (click_battery(panel, e->x, e->y)) {
if ( (e->button == 1 && battery_lclick_command) ||
(e->button == 2 && battery_mclick_command) ||
(e->button == 3 && battery_rclick_command) ||
(e->button == 4 && battery_uwheel_command) ||
(e->button == 5 && battery_dwheel_command) )
return 1;
else
return 0;
}
#endif
return 0;
}
@ -599,6 +615,16 @@ void event_button_release (XEvent *e)
return;
}
#ifdef ENABLE_BATTERY
if (click_battery(panel, e->xbutton.x, e->xbutton.y)) {
battery_action(e->xbutton.button);
if (panel_layer == BOTTOM_LAYER)
XLowerWindow (server.dsp, panel->main_win);
task_drag = 0;
return;
}
#endif
if (e->xbutton.button == 1 && click_launcher(panel, e->xbutton.x, e->xbutton.y)) {
LauncherIcon *icon = click_launcher_icon(panel, e->xbutton.x, e->xbutton.y);
if (icon) {