Commits

Alexandru Guzinschi  committed c78732c

added left & right click support for battery panel

  • Participants
  • Parent commits d23c785

Comments (0)

Files changed (6)

File src/battery/battery.c

 int8_t battery_low_status;
 unsigned char battery_low_cmd_send;
 char *battery_low_cmd;
+char *battery_lclick_command;
+char *battery_rclick_command;
 char *path_energy_now;
 char *path_energy_full;
 char *path_current_now;
 	battery_state.percentage = 0;
 	battery_state.time.hours = 0;
 	battery_state.time.minutes = 0;
+	battery_lclick_command = 0;
+	battery_rclick_command = 0;
 #if defined(__OpenBSD__) || defined(__NetBSD__)
 	apm_fd = -1;
 #endif
 	if (path_status) g_free(path_status);
 	if (battery_low_cmd) g_free(battery_low_cmd);
 	if (battery_timeout) stop_timeout(battery_timeout);
+	if (battery_lclick_command) g_free(battery_lclick_command);
+	if (battery_rclick_command) g_free(battery_rclick_command);
 
 #if defined(__OpenBSD__) || defined(__NetBSD__)
 	if ((apm_fd != -1) && (close(apm_fd) == -1))
 	return ret;
 }
 
+void battery_action(int button)
+{
+	char *command = 0;
+	switch (button) {
+		case 1:
+		command = battery_lclick_command;
+		break;
+		case 3:
+		command = battery_rclick_command;
+		break;
+	}
+	tint_exec(command);
+}

File src/battery/battery.h

 
 extern int8_t battery_low_status;
 extern char *battery_low_cmd;
+extern char *battery_lclick_command;
+extern char *battery_rclick_command;
 extern char *path_energy_now, *path_energy_full, *path_current_now, *path_status;
 
 // default global data
 
 int  resize_battery(void *obj);
 
+void battery_action(int button);
+
 #endif

File src/config.c

 	}
 
 	/* Battery */
+	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_rclick_command") == 0) {
+#ifdef ENABLE_BATTERY
+		if (strlen(value) > 0)
+			battery_rclick_command = strdup(value);
+#endif
+	}
 	else if (strcmp (key, "battery_low_status") == 0) {
 #ifdef ENABLE_BATTERY
 		battery_low_status = atoi(value);
 	return FALSE;
 }
 
+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;
+}
 
 Area* click_area(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);
+int click_battery(Panel *panel, int x, int y);
 Area* click_area(Panel *panel, int x, int y);
 
 void autohide_show(void* p);
 		else
 			return 0;
 	}
+	if (click_battery(panel, e->x, e->y)) {
+		if ( (e->button == 1 && battery_lclick_command) || (e->button == 3 && battery_rclick_command) )
+			return 1;
+		else
+			return 0;
+	}
+
 	return 0;
 }
 
 		return;
 	}
 
+	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;
+	}
+
 	if ( click_launcher(panel, e->xbutton.x, e->xbutton.y)) {
 		LauncherIcon *icon = click_launcher_icon(panel, e->xbutton.x, e->xbutton.y);
 		if (icon) {