all repos — tint2 @ 067234e9fb01364645416dd7f77cb0f6182e56a6

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

Unify code used to execute external programs
o9000 mrovi9000@gmail.com
commit

067234e9fb01364645416dd7f77cb0f6182e56a6

parent

e32d2342a6ecf529ae696a64c2aafab97204ff5d

M src/battery/battery.csrc/battery/battery.c

@@ -437,7 +437,7 @@ {

return battery_os_tooltip(); } -void battery_action(int button, Time time) +void battery_action(void *obj, int button, int x, int y, Time time) { char *command = NULL; switch (button) {

@@ -457,5 +457,5 @@ case 5:

command = battery_dwheel_command; break; } - tint_exec(command, NULL, NULL, time); + tint_exec(command, NULL, NULL, time, obj, x, y); }
M src/battery/battery.hsrc/battery/battery.h

@@ -108,7 +108,7 @@ void battery_default_font_changed();

gboolean resize_battery(void *obj); -void battery_action(int button, Time time); +void battery_action(void *obj, int button, int x, int y, Time time); /* operating system specific functions */ gboolean battery_os_init();
M src/button/button.csrc/button/button.c

@@ -516,7 +516,6 @@

void button_action(void *obj, int mouse_button, int x, int y, Time time) { Button *button = (Button *)obj; - Panel *panel = (Panel *)button->area.panel; char *command = NULL; switch (mouse_button) { case 1:

@@ -535,100 +534,7 @@ case 5:

command = button->backend->dwheel_command; break; } - if (command) { - int aligned_x, aligned_y, aligned_x1, aligned_y1, aligned_x2, aligned_y2; - int panel_x1, panel_x2, panel_y1, panel_y2; - if (panel_horizontal) { - if (area_is_first(button)) - aligned_x1 = panel->posx; - else - aligned_x1 = panel->posx + button->area.posx; - - if (area_is_last(button)) - aligned_x2 = panel->posx + panel->area.width; - else - aligned_x2 = panel->posx + button->area.posx + button->area.width; - - if (area_is_first(button)) - aligned_x = aligned_x1; - else if (area_is_last(button)) - aligned_x = aligned_x2; - else - aligned_x = aligned_x1; - - if (panel_position & BOTTOM) - aligned_y = panel->posy; - else - aligned_y = panel->posy + panel->area.height; - - aligned_y1 = aligned_y2 = aligned_y; - - panel_x1 = panel->posx; - panel_x2 = panel->posx + panel->area.width; - panel_y1 = panel_y2 = aligned_y; - } else { - if (area_is_first(button)) - aligned_y1 = panel->posy; - else - aligned_y1 = panel->posy + button->area.posy; - - if (area_is_last(button)) - aligned_y2 = panel->posy + panel->area.height; - else - aligned_y2 = panel->posy + button->area.posy + button->area.height; - - if (area_is_first(button)) - aligned_y = aligned_y1; - else if (area_is_last(button)) - aligned_y = aligned_y2; - else - aligned_y = aligned_y1; - - if (panel_position & RIGHT) - aligned_x = panel->posx; - else - aligned_x = panel->posx + panel->area.width; - - aligned_x1 = aligned_x2 = aligned_x; - - panel_x1 = panel_x2 = aligned_x; - panel_y1 = panel->posy; - panel_y2 = panel->posy + panel->area.height; - } - - char *full_cmd = g_strdup_printf("export TINT2_BUTTON_X=%d;" - "export TINT2_BUTTON_Y=%d;" - "export TINT2_BUTTON_W=%d;" - "export TINT2_BUTTON_H=%d;" - "export TINT2_BUTTON_ALIGNED_X=%d;" - "export TINT2_BUTTON_ALIGNED_Y=%d;" - "export TINT2_BUTTON_ALIGNED_X1=%d;" - "export TINT2_BUTTON_ALIGNED_Y1=%d;" - "export TINT2_BUTTON_ALIGNED_X2=%d;" - "export TINT2_BUTTON_ALIGNED_Y2=%d;" - "export TINT2_BUTTON_PANEL_X1=%d;" - "export TINT2_BUTTON_PANEL_Y1=%d;" - "export TINT2_BUTTON_PANEL_X2=%d;" - "export TINT2_BUTTON_PANEL_Y2=%d;" - "%s", - x, - y, - button->area.width, - button->area.height, - aligned_x, - aligned_y, - aligned_x1, - aligned_y1, - aligned_x2, - aligned_y2, - panel_x1, - panel_y1, - panel_x2, - panel_y2, - command); - tint_exec(full_cmd, NULL, NULL, time); - g_free(full_cmd); - } + tint_exec(command, NULL, NULL, time, obj, x, y); } char *button_get_tooltip(void *obj)
M src/clock/clock.csrc/clock/clock.c

@@ -393,7 +393,7 @@ strftime(buf_tooltip, sizeof(buf_tooltip), time_tooltip_format, clock_gettime_for_tz(time_tooltip_timezone));

return strdup(buf_tooltip); } -void clock_action(int button, Time time) +void clock_action(void *obj, int button, int x, int y, Time time) { char *command = NULL; switch (button) {

@@ -413,5 +413,5 @@ case 5:

command = clock_dwheel_command; break; } - tint_exec(command, NULL, NULL, time); + tint_exec(command, NULL, NULL, time, obj, x, y); }
M src/clock/clock.hsrc/clock/clock.h

@@ -54,6 +54,6 @@ void draw_clock(void *obj, cairo_t *c);

gboolean resize_clock(void *obj); -void clock_action(int button, Time time); +void clock_action(void *obj, int button, int x, int y, Time time); #endif
M src/execplugin/execplugin.csrc/execplugin/execplugin.c

@@ -588,7 +588,7 @@ y,

execp->area.width, execp->area.height, command); - pid_t pid = tint_exec(full_cmd, NULL, NULL, time); + pid_t pid = tint_exec(full_cmd, NULL, NULL, time, obj, x, y); g_free(full_cmd); if (pid > 0) g_tree_insert(execp->backend->cmd_pids, GINT_TO_POINTER(pid), GINT_TO_POINTER(1));
M src/launcher/launcher.csrc/launcher/launcher.c

@@ -415,13 +415,13 @@ imlib_free_image();

} } -void launcher_action(LauncherIcon *icon, XEvent *evt) +void launcher_action(LauncherIcon *icon, XEvent *evt, int x, int y) { launcher_reload_icon((Launcher *)icon->area.parent, icon); launcher_reload_hidden_icons((Launcher *)icon->area.parent); if (evt->type == ButtonPress || evt->type == ButtonRelease) - tint_exec(icon->cmd, icon->cwd, icon->icon_tooltip, evt->xbutton.time); + tint_exec(icon->cmd, icon->cwd, icon->icon_tooltip, evt->xbutton.time, &icon->area, x, y); } // Populates the list_icons list from the list_apps list
M src/launcher/launcher.hsrc/launcher/launcher.h

@@ -67,7 +67,7 @@ void launcher_default_icon_theme_changed();

// Populates the list_icons list void launcher_load_icons(Launcher *launcher); -void launcher_action(LauncherIcon *icon, XEvent *e); +void launcher_action(LauncherIcon *icon, XEvent *e, int x, int y); void test_launcher_read_desktop_file(); void test_launcher_read_theme_file();
M src/tint.csrc/tint.c

@@ -967,8 +967,9 @@ action = mouse_tilt_right;

break; } - if (click_clock(panel, e->xbutton.x, e->xbutton.y)) { - clock_action(e->xbutton.button, e->xbutton.time); + Clock *clock = click_clock(panel, e->xbutton.x, e->xbutton.y); + if (clock) { + clock_action(clock, e->xbutton.button, e->xbutton.x - clock->area.posx, e->xbutton.y - clock->area.posy, e->xbutton.time); if (panel_layer == BOTTOM_LAYER) XLowerWindow(server.display, panel->main_win); task_drag = 0;

@@ -976,8 +977,9 @@ return;

} #ifdef ENABLE_BATTERY - if (click_battery(panel, e->xbutton.x, e->xbutton.y)) { - battery_action(e->xbutton.button, e->xbutton.time); + Battery *battery = click_battery(panel, e->xbutton.x, e->xbutton.y); + if (battery) { + battery_action(battery, e->xbutton.button, e->xbutton.x - battery->area.posx, e->xbutton.y - battery->area.posy, e->xbutton.time); if (panel_layer == BOTTOM_LAYER) XLowerWindow(server.display, panel->main_win); task_drag = 0;

@@ -1006,7 +1008,7 @@

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) { - launcher_action(icon, e); + launcher_action(icon, e, e->xbutton.x - icon->area.posx, e->xbutton.y - icon->area.posy); } task_drag = 0; return;

@@ -2131,7 +2133,7 @@ }

strcat(cmd, "\""); strcat(cmd, "&)"); fprintf(stderr, "DnD %s:%d: Running command: %s\n", __FILE__, __LINE__, cmd); - tint_exec(cmd, NULL, NULL, e.xselection.time); + tint_exec(cmd, NULL, NULL, e.xselection.time, NULL, 0, 0); free(cmd); // Reply OK.
M src/util/common.csrc/util/common.c

@@ -103,22 +103,121 @@ }

extern char *config_path; -pid_t tint_exec(const char *command, const char *dir, const char *tooltip, Time time) +#ifndef TINT2CONF +pid_t tint_exec(const char *command, const char *dir, const char *tooltip, Time time, Area *area, int x, int y) { if (!command || strlen(command) == 0) return -1; - command = g_strdup_printf("export TINT2_CONFIG=%s;" - "%s", - config_path, - command); + if (area) { + Panel *panel = (Panel *)area->panel; + + int aligned_x, aligned_y, aligned_x1, aligned_y1, aligned_x2, aligned_y2; + int panel_x1, panel_x2, panel_y1, panel_y2; + if (panel_horizontal) { + if (area_is_first(area)) + aligned_x1 = panel->posx; + else + aligned_x1 = panel->posx + area->posx; + + if (area_is_last(area)) + aligned_x2 = panel->posx + panel->area.width; + else + aligned_x2 = panel->posx + area->posx + area->width; + + if (area_is_first(area)) + aligned_x = aligned_x1; + else if (area_is_last(area)) + aligned_x = aligned_x2; + else + aligned_x = aligned_x1; + + if (panel_position & BOTTOM) + aligned_y = panel->posy; + else + aligned_y = panel->posy + panel->area.height; + + aligned_y1 = aligned_y2 = aligned_y; + + panel_x1 = panel->posx; + panel_x2 = panel->posx + panel->area.width; + panel_y1 = panel_y2 = aligned_y; + } else { + if (area_is_first(area)) + aligned_y1 = panel->posy; + else + aligned_y1 = panel->posy + area->posy; + + if (area_is_last(area)) + aligned_y2 = panel->posy + panel->area.height; + else + aligned_y2 = panel->posy + area->posy + area->height; + + if (area_is_first(area)) + aligned_y = aligned_y1; + else if (area_is_last(area)) + aligned_y = aligned_y2; + else + aligned_y = aligned_y1; + + if (panel_position & RIGHT) + aligned_x = panel->posx; + else + aligned_x = panel->posx + panel->area.width; + + aligned_x1 = aligned_x2 = aligned_x; + + panel_x1 = panel_x2 = aligned_x; + panel_y1 = panel->posy; + panel_y2 = panel->posy + panel->area.height; + } + + command = g_strdup_printf("export TINT2_CONFIG=%s;" + "export TINT2_BUTTON_X=%d;" + "export TINT2_BUTTON_Y=%d;" + "export TINT2_BUTTON_W=%d;" + "export TINT2_BUTTON_H=%d;" + "export TINT2_BUTTON_ALIGNED_X=%d;" + "export TINT2_BUTTON_ALIGNED_Y=%d;" + "export TINT2_BUTTON_ALIGNED_X1=%d;" + "export TINT2_BUTTON_ALIGNED_Y1=%d;" + "export TINT2_BUTTON_ALIGNED_X2=%d;" + "export TINT2_BUTTON_ALIGNED_Y2=%d;" + "export TINT2_BUTTON_PANEL_X1=%d;" + "export TINT2_BUTTON_PANEL_Y1=%d;" + "export TINT2_BUTTON_PANEL_X2=%d;" + "export TINT2_BUTTON_PANEL_Y2=%d;" + "%s", + config_path, + x, + y, + area->width, + area->height, + aligned_x, + aligned_y, + aligned_x1, + aligned_y1, + aligned_x2, + aligned_y2, + panel_x1, + panel_y1, + panel_x2, + panel_y2, + command); + } else { + command = g_strdup_printf("export TINT2_CONFIG=%s;" + "%s", + config_path, + command); + } + if (!command) return -1; if (!tooltip) tooltip = command; -#if HAVE_SN && !defined TINT2CONF +#if HAVE_SN SnLauncherContext *ctx = 0; if (startup_notifications && time) { ctx = sn_launcher_context_new(server.sn_display, server.screen);

@@ -134,7 +233,7 @@ if (pid < 0) {

fprintf(stderr, "Could not fork\n"); } else if (pid == 0) { // Child process -#if HAVE_SN && !defined TINT2CONF +#if HAVE_SN if (startup_notifications && time) { sn_launcher_context_setup_child_process(ctx); }

@@ -146,7 +245,7 @@ if (dir)

chdir(dir); execl("/bin/sh", "/bin/sh", "-c", command, NULL); fprintf(stderr, "Failed to execlp %s\n", command); -#if HAVE_SN && !defined TINT2CONF +#if HAVE_SN if (startup_notifications && time) { sn_launcher_context_unref(ctx); }

@@ -154,7 +253,7 @@ #endif // HAVE_SN

_exit(1); } else { // Parent process -#if HAVE_SN && !defined TINT2CONF +#if HAVE_SN if (startup_notifications && time) { g_tree_insert(server.pids, GINT_TO_POINTER(pid), ctx); }

@@ -165,8 +264,9 @@ }

void tint_exec_no_sn(const char *command) { - tint_exec(command, NULL, NULL, 0); + tint_exec(command, NULL, NULL, 0, NULL, 0, 0); } +#endif char *expand_tilde(const char *s) {
M src/util/common.hsrc/util/common.h

@@ -54,7 +54,7 @@ void extract_values(const char *value, char **value1, char **value2, char **value3);

void extract_values_4(const char *value, char **value1, char **value2, char **value3, char **value4); // Executes a command in a shell. -pid_t tint_exec(const char *command, const char *dir, const char *tooltip, Time time); +pid_t tint_exec(const char *command, const char *dir, const char *tooltip, Time time, Area *area, int x, int y); void tint_exec_no_sn(const char *command); // Returns a copy of s in which "~" is expanded to the path to the user's home directory.