Open current tint2 config automatically when started from tint2

This commit is contained in:
o9000 2017-04-22 19:07:49 +02:00
parent affac4cfa6
commit 701b57e113
17 changed files with 98 additions and 113 deletions

View file

@ -227,14 +227,14 @@ void update_battery_tick(void *arg)
if (old_ac_connected != battery_state.ac_connected) { if (old_ac_connected != battery_state.ac_connected) {
if (battery_state.ac_connected) if (battery_state.ac_connected)
tint_exec(ac_connected_cmd); tint_exec_no_sn(ac_connected_cmd);
else else
tint_exec(ac_disconnected_cmd); tint_exec_no_sn(ac_disconnected_cmd);
} }
if (battery_state.percentage < battery_low_status && battery_state.state == BATTERY_DISCHARGING && if (battery_state.percentage < battery_low_status && battery_state.state == BATTERY_DISCHARGING &&
!battery_low_cmd_sent) { !battery_low_cmd_sent) {
tint_exec(battery_low_cmd); tint_exec_no_sn(battery_low_cmd);
battery_low_cmd_sent = TRUE; battery_low_cmd_sent = TRUE;
} }
if (battery_state.percentage > battery_low_status && battery_state.state == BATTERY_CHARGING && if (battery_state.percentage > battery_low_status && battery_state.state == BATTERY_CHARGING &&
@ -437,7 +437,7 @@ char *battery_get_tooltip(void *obj)
return battery_os_tooltip(); return battery_os_tooltip();
} }
void battery_action(int button) void battery_action(int button, Time time)
{ {
char *command = NULL; char *command = NULL;
switch (button) { switch (button) {
@ -457,5 +457,5 @@ void battery_action(int button)
command = battery_dwheel_command; command = battery_dwheel_command;
break; break;
} }
tint_exec(command); tint_exec(command, NULL, NULL, time);
} }

View file

@ -108,7 +108,7 @@ void battery_default_font_changed();
gboolean resize_battery(void *obj); gboolean resize_battery(void *obj);
void battery_action(int button); void battery_action(int button, Time time);
/* operating system specific functions */ /* operating system specific functions */
gboolean battery_os_init(); gboolean battery_os_init();

View file

@ -513,7 +513,7 @@ void button_dump_geometry(void *obj, int indent)
button->backend->text); button->backend->text);
} }
void button_action(void *obj, int mouse_button, int x, int y) void button_action(void *obj, int mouse_button, int x, int y, Time time)
{ {
Button *button = (Button *)obj; Button *button = (Button *)obj;
Panel *panel = (Panel *)button->area.panel; Panel *panel = (Panel *)button->area.panel;
@ -626,18 +626,8 @@ void button_action(void *obj, int mouse_button, int x, int y)
panel_x2, panel_x2,
panel_y2, panel_y2,
command); command);
pid_t pid = fork(); tint_exec(full_cmd, NULL, NULL, time);
if (pid < 0) { g_free(full_cmd);
fprintf(stderr, "Could not fork\n");
} else if (pid == 0) {
// Child process
// Allow children to exist after parent destruction
setsid();
// Run the command
execl("/bin/sh", "/bin/sh", "-c", full_cmd, NULL);
fprintf(stderr, "Failed to execlp %s\n", full_cmd);
exit(1);
}
} }
} }

View file

@ -103,7 +103,7 @@ void draw_button(void *obj, cairo_t *c);
gboolean resize_button(void *obj); gboolean resize_button(void *obj);
// Called on mouse click event. // Called on mouse click event.
void button_action(void *obj, int button, int x, int y); void button_action(void *obj, int button, int x, int y, Time time);
void button_default_font_changed(); void button_default_font_changed();
void button_default_icon_theme_changed(); void button_default_icon_theme_changed();

View file

@ -393,7 +393,7 @@ char *clock_get_tooltip(void *obj)
return strdup(buf_tooltip); return strdup(buf_tooltip);
} }
void clock_action(int button) void clock_action(int button, Time time)
{ {
char *command = NULL; char *command = NULL;
switch (button) { switch (button) {
@ -413,5 +413,5 @@ void clock_action(int button)
command = clock_dwheel_command; command = clock_dwheel_command;
break; break;
} }
tint_exec(command); tint_exec(command, NULL, NULL, time);
} }

View file

@ -54,6 +54,6 @@ void draw_clock(void *obj, cairo_t *c);
gboolean resize_clock(void *obj); gboolean resize_clock(void *obj);
void clock_action(int button); void clock_action(int button, Time time);
#endif #endif

View file

@ -62,8 +62,8 @@
#endif #endif
// global path // global path
char *config_path; char *config_path = NULL;
char *snapshot_path; char *snapshot_path = NULL;
#ifndef TINT2CONF #ifndef TINT2CONF

View file

@ -557,7 +557,7 @@ void execp_force_update(Execp *execp)
} }
} }
void execp_action(void *obj, int button, int x, int y) void execp_action(void *obj, int button, int x, int y, Time time)
{ {
Execp *execp = obj; Execp *execp = obj;
char *command = NULL; char *command = NULL;
@ -588,20 +588,7 @@ void execp_action(void *obj, int button, int x, int y)
execp->area.width, execp->area.width,
execp->area.height, execp->area.height,
command); command);
pid_t pid = fork(); tint_exec(full_cmd, NULL, NULL, time);
if (pid < 0) {
fprintf(stderr, "Could not fork\n");
} else if (pid == 0) {
// Child process
// Allow children to exist after parent destruction
setsid();
// Run the command
execl("/bin/sh", "/bin/sh", "-c", full_cmd, NULL);
fprintf(stderr, "Failed to execlp %s\n", full_cmd);
exit(1);
}
// Parent process
g_tree_insert(execp->backend->cmd_pids, GINT_TO_POINTER(pid), GINT_TO_POINTER(1));
g_free(full_cmd); g_free(full_cmd);
} else { } else {
execp_force_update(execp); execp_force_update(execp);

View file

@ -129,7 +129,7 @@ void draw_execp(void *obj, cairo_t *c);
gboolean resize_execp(void *obj); gboolean resize_execp(void *obj);
// Called on mouse click event. // Called on mouse click event.
void execp_action(void *obj, int button, int x, int y); void execp_action(void *obj, int button, int x, int y, Time time);
void execp_cmd_completed(Execp *obj, pid_t pid); void execp_cmd_completed(Execp *obj, pid_t pid);

View file

@ -50,7 +50,6 @@ int launcher_brightness;
char *icon_theme_name_config; char *icon_theme_name_config;
char *icon_theme_name_xsettings; char *icon_theme_name_xsettings;
int launcher_icon_theme_override; int launcher_icon_theme_override;
int startup_notifications;
Background *launcher_icon_bg; Background *launcher_icon_bg;
GList *launcher_icon_gradients; GList *launcher_icon_gradients;
@ -420,60 +419,9 @@ void launcher_action(LauncherIcon *icon, XEvent *evt)
{ {
launcher_reload_icon((Launcher *)icon->area.parent, icon); launcher_reload_icon((Launcher *)icon->area.parent, icon);
launcher_reload_hidden_icons((Launcher *)icon->area.parent); launcher_reload_hidden_icons((Launcher *)icon->area.parent);
char *cmd = calloc(strlen(icon->cmd) + 10, 1);
sprintf(cmd, "(%s&)", icon->cmd); if (evt->type == ButtonPress || evt->type == ButtonRelease)
#if HAVE_SN tint_exec(icon->cmd, icon->cwd, icon->icon_tooltip, evt->xbutton.time);
SnLauncherContext *ctx = 0;
Time time;
if (startup_notifications) {
ctx = sn_launcher_context_new(server.sn_display, server.screen);
sn_launcher_context_set_name(ctx, icon->icon_tooltip);
sn_launcher_context_set_description(ctx, "Application launched from tint2");
sn_launcher_context_set_binary_name(ctx, icon->cmd);
// Get a timestamp from the X event
if (evt->type == ButtonPress || evt->type == ButtonRelease) {
time = evt->xbutton.time;
} else {
fprintf(stderr, "Unknown X event: %d\n", evt->type);
free(cmd);
return;
}
sn_launcher_context_initiate(ctx, "tint2", icon->cmd, time);
}
#endif /* HAVE_SN */
pid_t pid;
pid = fork();
if (pid < 0) {
fprintf(stderr, "Could not fork\n");
} else if (pid == 0) {
// Child process
#if HAVE_SN
if (startup_notifications) {
sn_launcher_context_setup_child_process(ctx);
}
#endif // HAVE_SN
// Allow children to exist after parent destruction
setsid();
// Run the command
if (icon->cwd)
chdir(icon->cwd);
execl("/bin/sh", "/bin/sh", "-c", icon->cmd, NULL);
fprintf(stderr, "Failed to execlp %s\n", icon->cmd);
#if HAVE_SN
if (startup_notifications) {
sn_launcher_context_unref(ctx);
}
#endif // HAVE_SN
exit(1);
} else {
// Parent process
#if HAVE_SN
if (startup_notifications) {
g_tree_insert(server.pids, GINT_TO_POINTER(pid), ctx);
}
#endif // HAVE_SN
}
free(cmd);
} }
// Populates the list_icons list from the list_apps list // Populates the list_icons list from the list_apps list

View file

@ -49,7 +49,6 @@ extern int launcher_brightness;
extern char *icon_theme_name_xsettings; // theme name extern char *icon_theme_name_xsettings; // theme name
extern char *icon_theme_name_config; extern char *icon_theme_name_config;
extern int launcher_icon_theme_override; extern int launcher_icon_theme_override;
extern int startup_notifications;
extern Background *launcher_icon_bg; extern Background *launcher_icon_bg;
extern GList *launcher_icon_gradients; extern GList *launcher_icon_gradients;

View file

@ -57,6 +57,7 @@ gboolean task_dragged;
char *panel_window_name = NULL; char *panel_window_name = NULL;
gboolean debug_geometry; gboolean debug_geometry;
gboolean debug_gradients; gboolean debug_gradients;
gboolean startup_notifications;
gboolean panel_autohide; gboolean panel_autohide;
int panel_autohide_show_timeout; int panel_autohide_show_timeout;

View file

@ -90,6 +90,7 @@ extern Imlib_Image default_icon;
#define DEFAULT_FONT "sans 10" #define DEFAULT_FONT "sans 10"
extern char *default_font; extern char *default_font;
extern XSettingsClient *xsettings_client; extern XSettingsClient *xsettings_client;
extern gboolean startup_notifications;
extern gboolean debug_geometry; extern gboolean debug_geometry;
extern gboolean debug_fps; extern gboolean debug_fps;
extern gboolean debug_frames; extern gboolean debug_frames;

View file

@ -968,7 +968,7 @@ void event_button_release(XEvent *e)
} }
if (click_clock(panel, e->xbutton.x, e->xbutton.y)) { if (click_clock(panel, e->xbutton.x, e->xbutton.y)) {
clock_action(e->xbutton.button); clock_action(e->xbutton.button, e->xbutton.time);
if (panel_layer == BOTTOM_LAYER) if (panel_layer == BOTTOM_LAYER)
XLowerWindow(server.display, panel->main_win); XLowerWindow(server.display, panel->main_win);
task_drag = 0; task_drag = 0;
@ -977,7 +977,7 @@ void event_button_release(XEvent *e)
#ifdef ENABLE_BATTERY #ifdef ENABLE_BATTERY
if (click_battery(panel, e->xbutton.x, e->xbutton.y)) { if (click_battery(panel, e->xbutton.x, e->xbutton.y)) {
battery_action(e->xbutton.button); battery_action(e->xbutton.button, e->xbutton.time);
if (panel_layer == BOTTOM_LAYER) if (panel_layer == BOTTOM_LAYER)
XLowerWindow(server.display, panel->main_win); XLowerWindow(server.display, panel->main_win);
task_drag = 0; task_drag = 0;
@ -987,7 +987,7 @@ void event_button_release(XEvent *e)
Execp *execp = click_execp(panel, e->xbutton.x, e->xbutton.y); Execp *execp = click_execp(panel, e->xbutton.x, e->xbutton.y);
if (execp) { if (execp) {
execp_action(execp, e->xbutton.button, e->xbutton.x - execp->area.posx, e->xbutton.y - execp->area.posy); execp_action(execp, e->xbutton.button, e->xbutton.x - execp->area.posx, e->xbutton.y - execp->area.posy, e->xbutton.time);
if (panel_layer == BOTTOM_LAYER) if (panel_layer == BOTTOM_LAYER)
XLowerWindow(server.display, panel->main_win); XLowerWindow(server.display, panel->main_win);
task_drag = 0; task_drag = 0;
@ -996,7 +996,7 @@ void event_button_release(XEvent *e)
Button *button = click_button(panel, e->xbutton.x, e->xbutton.y); Button *button = click_button(panel, e->xbutton.x, e->xbutton.y);
if (button) { if (button) {
button_action(button, e->xbutton.button, e->xbutton.x - button->area.posx, e->xbutton.y - button->area.posy); button_action(button, e->xbutton.button, e->xbutton.x - button->area.posx, e->xbutton.y - button->area.posy, e->xbutton.time);
if (panel_layer == BOTTOM_LAYER) if (panel_layer == BOTTOM_LAYER)
XLowerWindow(server.display, panel->main_win); XLowerWindow(server.display, panel->main_win);
task_drag = 0; task_drag = 0;
@ -2131,7 +2131,7 @@ start:
strcat(cmd, "\""); strcat(cmd, "\"");
strcat(cmd, "&)"); strcat(cmd, "&)");
fprintf(stderr, "DnD %s:%d: Running command: %s\n", __FILE__, __LINE__, cmd); fprintf(stderr, "DnD %s:%d: Running command: %s\n", __FILE__, __LINE__, cmd);
tint_exec(cmd); tint_exec(cmd, NULL, NULL, e.xselection.time);
free(cmd); free(cmd);
// Reply OK. // Reply OK.

View file

@ -340,6 +340,10 @@ int main(int argc, char **argv)
if (argc > 0) { if (argc > 0) {
load_specific_themes(argv, argc); load_specific_themes(argv, argc);
g_timeout_add(SNAPSHOT_TICK, edit_theme, NULL); g_timeout_add(SNAPSHOT_TICK, edit_theme, NULL);
} else if (getenv("TINT2_CONFIG")) {
char *themes[2] = {getenv("TINT2_CONFIG"), NULL};
load_specific_themes(themes, 1);
g_timeout_add(SNAPSHOT_TICK, edit_theme, NULL);
} }
gtk_widget_show_all(g_window); gtk_widget_show_all(g_window);

View file

@ -44,6 +44,8 @@
#include <librsvg/rsvg.h> #include <librsvg/rsvg.h>
#endif #endif
#include "../panel.h"
void copy_file(const char *path_src, const char *path_dest) void copy_file(const char *path_src, const char *path_dest)
{ {
if (g_str_equal(path_src, path_dest)) if (g_str_equal(path_src, path_dest))
@ -99,18 +101,70 @@ gboolean parse_line(const char *line, char **key, char **value)
return TRUE; return TRUE;
} }
void tint_exec(const char *command) extern char *config_path;
void tint_exec(const char *command, const char *dir, const char *tooltip, Time time)
{ {
if (command) { if (!command || strlen(command) == 0)
if (fork() == 0) { return;
// change for the fork the signal mask
// sigset_t sigset; command = g_strdup_printf("export TINT2_CONFIG=%s;"
// sigprocmask(SIG_SETMASK, &sigset, 0); "%s",
// sigprocmask(SIG_UNBLOCK, &sigset, 0); config_path,
command);
if (!command)
return;
if (!tooltip)
tooltip = command;
#if HAVE_SN && !defined TINT2CONF
SnLauncherContext *ctx = 0;
if (startup_notifications && time) {
ctx = sn_launcher_context_new(server.sn_display, server.screen);
sn_launcher_context_set_name(ctx, tooltip);
sn_launcher_context_set_description(ctx, "Application launched from tint2");
sn_launcher_context_set_binary_name(ctx, command);
sn_launcher_context_initiate(ctx, "tint2", command, time);
}
#endif /* HAVE_SN */
pid_t pid;
pid = fork();
if (pid < 0) {
fprintf(stderr, "Could not fork\n");
} else if (pid == 0) {
// Child process
#if HAVE_SN && !defined TINT2CONF
if (startup_notifications && time) {
sn_launcher_context_setup_child_process(ctx);
}
#endif // HAVE_SN
// Allow children to exist after parent destruction
setsid();
// Run the command
if (dir)
chdir(dir);
execl("/bin/sh", "/bin/sh", "-c", command, NULL); execl("/bin/sh", "/bin/sh", "-c", command, NULL);
_exit(0); fprintf(stderr, "Failed to execlp %s\n", command);
#if HAVE_SN && !defined TINT2CONF
if (startup_notifications && time) {
sn_launcher_context_unref(ctx);
} }
#endif // HAVE_SN
_exit(1);
} else {
// Parent process
#if HAVE_SN && !defined TINT2CONF
if (startup_notifications && time) {
g_tree_insert(server.pids, GINT_TO_POINTER(pid), ctx);
} }
#endif // HAVE_SN
}
}
void tint_exec_no_sn(const char *command)
{
tint_exec(command, NULL, NULL, 0);
} }
char *expand_tilde(const char *s) char *expand_tilde(const char *s)

View file

@ -54,7 +54,8 @@ void extract_values(const char *value, char **value1, char **value2, char **valu
void extract_values_4(const char *value, char **value1, char **value2, char **value3, char **value4); void extract_values_4(const char *value, char **value1, char **value2, char **value3, char **value4);
// Executes a command in a shell. // Executes a command in a shell.
void tint_exec(const char *command); void tint_exec(const char *command, const char *dir, const char *tooltip, Time time);
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. // Returns a copy of s in which "~" is expanded to the path to the user's home directory.
// The caller takes ownership of the string. // The caller takes ownership of the string.