Allow clicking and mousewheeling on the battery panel
This commit is the same as vimishor's original [*] except that I have
added middle-click and up/down mousewheel actions. In order to fix a
ftbs I also added guards to panel.c, panel.h & tint.c
The following configuration settings have been created :-
battery_lclick_command
battery_mclick_command
battery_rclick_command
battery_uwheel_command
battery_dwheel_command
[*] c78732c46a
This commit is contained in:
@@ -56,6 +56,11 @@ static char buf_bat_time[20];
|
|||||||
int8_t battery_low_status;
|
int8_t battery_low_status;
|
||||||
unsigned char battery_low_cmd_sent;
|
unsigned char battery_low_cmd_sent;
|
||||||
char *battery_low_cmd;
|
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_now;
|
||||||
gchar *path_energy_full;
|
gchar *path_energy_full;
|
||||||
gchar *path_current_now;
|
gchar *path_current_now;
|
||||||
@@ -141,6 +146,11 @@ void default_battery()
|
|||||||
bat1_font_desc = NULL;
|
bat1_font_desc = NULL;
|
||||||
bat2_font_desc = NULL;
|
bat2_font_desc = NULL;
|
||||||
battery_low_cmd = 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_now = NULL;
|
||||||
path_energy_full = NULL;
|
path_energy_full = NULL;
|
||||||
path_current_now = NULL;
|
path_current_now = NULL;
|
||||||
@@ -171,6 +181,16 @@ void cleanup_battery()
|
|||||||
path_status = NULL;
|
path_status = NULL;
|
||||||
free(battery_low_cmd);
|
free(battery_low_cmd);
|
||||||
battery_low_cmd = NULL;
|
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);
|
stop_timeout(battery_timeout);
|
||||||
battery_timeout = NULL;
|
battery_timeout = NULL;
|
||||||
battery_found = 0;
|
battery_found = 0;
|
||||||
@@ -574,3 +594,26 @@ int resize_battery(void *obj)
|
|||||||
}
|
}
|
||||||
return ret;
|
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);
|
||||||
|
}
|
||||||
@@ -56,6 +56,12 @@ extern int percentage_hide;
|
|||||||
extern int8_t battery_low_status;
|
extern int8_t battery_low_status;
|
||||||
extern char *battery_low_cmd;
|
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
|
// default global data
|
||||||
void default_battery();
|
void default_battery();
|
||||||
|
|
||||||
@@ -71,4 +77,6 @@ void draw_battery(void *obj, cairo_t *c);
|
|||||||
|
|
||||||
int resize_battery(void *obj);
|
int resize_battery(void *obj);
|
||||||
|
|
||||||
|
void battery_action(int button);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
30
src/config.c
30
src/config.c
@@ -349,6 +349,36 @@ void add_entry (char *key, char *value)
|
|||||||
battery_low_status = atoi(value);
|
battery_low_status = atoi(value);
|
||||||
if(battery_low_status < 0 || battery_low_status > 100)
|
if(battery_low_status < 0 || battery_low_status > 100)
|
||||||
battery_low_status = 0;
|
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
|
#endif
|
||||||
}
|
}
|
||||||
else if (strcmp (key, "battery_low_cmd") == 0) {
|
else if (strcmp (key, "battery_low_cmd") == 0) {
|
||||||
|
|||||||
16
src/panel.c
16
src/panel.c
@@ -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* click_area(Panel *panel, int x, int y)
|
||||||
{
|
{
|
||||||
Area* result = &panel->area;
|
Area* result = &panel->area;
|
||||||
|
|||||||
@@ -160,6 +160,11 @@ Launcher *click_launcher (Panel *panel, int x, int y);
|
|||||||
LauncherIcon *click_launcher_icon (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_padding(Panel *panel, int x, int y);
|
||||||
int click_clock(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);
|
Area* click_area(Panel *panel, int x, int y);
|
||||||
|
|
||||||
void autohide_show(void* p);
|
void autohide_show(void* p);
|
||||||
|
|||||||
22
src/tint.c
22
src/tint.c
@@ -456,6 +456,18 @@ int tint2_handles_click(Panel* panel, XButtonEvent* e)
|
|||||||
else
|
else
|
||||||
return 0;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -603,6 +615,16 @@ void event_button_release (XEvent *e)
|
|||||||
return;
|
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)) {
|
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);
|
LauncherIcon *icon = click_launcher_icon(panel, e->xbutton.x, e->xbutton.y);
|
||||||
if (icon) {
|
if (icon) {
|
||||||
|
|||||||
Reference in New Issue
Block a user