all repos — tint2 @ fd78e6d8867cc832a8c1ab1421d5f8df052b0a1c

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

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

[*] https://github.com/vimishor/tint2/commit/c78732c46a058a39cc4264505f63c2317d3e5e5d
berkley4 jeffblake0@gmail.com
commit

fd78e6d8867cc832a8c1ab1421d5f8df052b0a1c

parent

e84d963ab6278284c8a85aff5ec0931ab004a616

6 files changed, 124 insertions(+), 0 deletions(-)

jump to
M src/battery/battery.csrc/battery/battery.c

@@ -56,6 +56,11 @@

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 @@ battery_timeout = NULL;

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 @@ g_free(path_status);

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 @@ }

} 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); +}
M src/battery/battery.hsrc/battery/battery.h

@@ -56,6 +56,12 @@

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();

@@ -70,5 +76,7 @@

void draw_battery(void *obj, cairo_t *c); int resize_battery(void *obj); + +void battery_action(int button); #endif
M src/config.csrc/config.c

@@ -351,6 +351,36 @@ 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) { #ifdef ENABLE_BATTERY if (strlen(value) > 0)
M src/panel.csrc/panel.c

@@ -796,6 +796,22 @@ return FALSE;

} +#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;
M src/panel.hsrc/panel.h

@@ -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);
M src/tint.csrc/tint.c

@@ -456,6 +456,18 @@ 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; }

@@ -602,6 +614,16 @@ XLowerWindow (server.dsp, panel->main_win);

task_drag = 0; 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);