Add config option startup_notifications = 0/1
git-svn-id: http://tint2.googlecode.com/svn/trunk@737 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
parent
c900bc24b2
commit
5faf063f96
7 changed files with 76 additions and 44 deletions
|
@ -651,6 +651,9 @@ void add_entry (char *key, char *value)
|
|||
else if (strcmp(key, "launcher_tooltip") == 0) {
|
||||
launcher_tooltip_enabled = atoi(value);
|
||||
}
|
||||
else if (strcmp(key, "startup_notifications") == 0) {
|
||||
startup_notifications = atoi(value);
|
||||
}
|
||||
|
||||
/* Tooltip */
|
||||
else if (strcmp (key, "tooltip_show_timeout") == 0) {
|
||||
|
|
|
@ -55,6 +55,7 @@ int launcher_brightness;
|
|||
char *icon_theme_name_config;
|
||||
char *icon_theme_name_xsettings;
|
||||
XSettingsClient *xsettings_client;
|
||||
int startup_notifications;
|
||||
|
||||
Imlib_Image scale_icon(Imlib_Image original, int icon_size);
|
||||
void free_icon(Imlib_Image icon);
|
||||
|
@ -70,6 +71,7 @@ void default_launcher()
|
|||
icon_theme_name_config = NULL;
|
||||
icon_theme_name_xsettings = NULL;
|
||||
xsettings_client = NULL;
|
||||
startup_notifications = 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -118,7 +120,7 @@ void cleanup_launcher()
|
|||
xsettings_client_destroy(xsettings_client);
|
||||
for (i = 0 ; i < nb_panel ; i++) {
|
||||
Panel *panel = &panel1[i];
|
||||
Launcher *launcher = &panel->launcher;
|
||||
Launcher *launcher = &panel->launcher;
|
||||
cleanup_launcher_theme(launcher);
|
||||
}
|
||||
for (l = panel_config.launcher.list_apps; l ; l = l->next) {
|
||||
|
@ -243,10 +245,10 @@ int resize_launcher(void *obj)
|
|||
free(new_icon_path);
|
||||
} else {
|
||||
// Loaded icon successfully
|
||||
launcherIcon->icon_scaled = scale_icon(launcherIcon->icon_original, launcherIcon->icon_size);
|
||||
free(launcherIcon->icon_path);
|
||||
launcherIcon->icon_path = new_icon_path;
|
||||
fprintf(stderr, "launcher.c %d: Using icon %s\n", __LINE__, launcherIcon->icon_path);
|
||||
launcherIcon->icon_scaled = scale_icon(launcherIcon->icon_original, launcherIcon->icon_size);
|
||||
free(launcherIcon->icon_path);
|
||||
launcherIcon->icon_path = new_icon_path;
|
||||
fprintf(stderr, "launcher.c %d: Using icon %s\n", __LINE__, launcherIcon->icon_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -386,49 +388,54 @@ void launcher_action(LauncherIcon *icon, XEvent* evt)
|
|||
char *cmd = malloc(strlen(icon->cmd) + 10);
|
||||
sprintf(cmd, "(%s&)", icon->cmd);
|
||||
#if HAVE_SN
|
||||
SnLauncherContext* ctx;
|
||||
Time time;
|
||||
|
||||
SnLauncherContext* ctx;
|
||||
Time time;
|
||||
if (startup_notifications) {
|
||||
ctx = sn_launcher_context_new(server.sn_dsp, 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);
|
||||
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) {
|
||||
} else if (pid == 0) {
|
||||
// Child process
|
||||
#if HAVE_SN
|
||||
sn_launcher_context_setup_child_process (ctx);
|
||||
if (startup_notifications) {
|
||||
sn_launcher_context_setup_child_process(ctx);
|
||||
}
|
||||
#endif // HAVE_SN
|
||||
// Allow children to exist after parent destruction
|
||||
setsid ();
|
||||
setsid();
|
||||
// Run the command
|
||||
execl("/bin/sh", "/bin/sh", "-c", icon->cmd, NULL);
|
||||
|
||||
fprintf(stderr, "Failed to execlp %s\n", icon->cmd);
|
||||
#if HAVE_SN
|
||||
sn_launcher_context_unref (ctx);
|
||||
if (startup_notifications) {
|
||||
sn_launcher_context_unref(ctx);
|
||||
}
|
||||
#endif // HAVE_SN
|
||||
_exit(1);
|
||||
}
|
||||
exit(1);
|
||||
} else {
|
||||
// Parent process
|
||||
#if HAVE_SN
|
||||
else {
|
||||
g_tree_insert (server.pids, GINT_TO_POINTER (pid), ctx);
|
||||
}
|
||||
if (startup_notifications) {
|
||||
g_tree_insert(server.pids, GINT_TO_POINTER (pid), ctx);
|
||||
}
|
||||
#endif // HAVE_SN
|
||||
}
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ extern int launcher_brightness;
|
|||
extern char *icon_theme_name_xsettings; // theme name
|
||||
extern char *icon_theme_name_config;
|
||||
extern XSettingsClient *xsettings_client;
|
||||
extern int startup_notifications;
|
||||
|
||||
// default global data
|
||||
void default_launcher();
|
||||
|
|
43
src/tint.c
43
src/tint.c
|
@ -148,6 +148,8 @@ static void error_trap_pop(SnDisplay *display, Display *xdisplay)
|
|||
}
|
||||
|
||||
static void sigchld_handler(int sig) {
|
||||
if (!startup_notifications)
|
||||
return;
|
||||
if (!sn_pipe_valid)
|
||||
return;
|
||||
ssize_t wur = write(sn_pipe[1], "x", 1);
|
||||
|
@ -156,6 +158,8 @@ static void sigchld_handler(int sig) {
|
|||
}
|
||||
|
||||
static void sigchld_handler_async() {
|
||||
if (!startup_notifications)
|
||||
return;
|
||||
// Wait for all dead processes
|
||||
pid_t pid;
|
||||
while ((pid = waitpid(-1, NULL, WNOHANG)) > 0) {
|
||||
|
@ -213,18 +217,20 @@ void init_X11_post_config()
|
|||
|
||||
#ifdef HAVE_SN
|
||||
// Initialize startup-notification
|
||||
server.sn_dsp = sn_display_new (server.dsp, error_trap_push, error_trap_pop);
|
||||
server.pids = g_tree_new (cmp_ptr);
|
||||
// Setup a handler for child termination
|
||||
if (pipe(sn_pipe) != 0) {
|
||||
fprintf(stderr, "Creating pipe failed.\n");
|
||||
} else {
|
||||
sn_pipe_valid = 1;
|
||||
struct sigaction act;
|
||||
memset (&act, 0, sizeof (struct sigaction));
|
||||
act.sa_handler = sigchld_handler;
|
||||
if (sigaction(SIGCHLD, &act, 0)) {
|
||||
perror("sigaction");
|
||||
if (startup_notifications) {
|
||||
server.sn_dsp = sn_display_new (server.dsp, error_trap_push, error_trap_pop);
|
||||
server.pids = g_tree_new (cmp_ptr);
|
||||
// Setup a handler for child termination
|
||||
if (pipe(sn_pipe) != 0) {
|
||||
fprintf(stderr, "Creating pipe failed.\n");
|
||||
} else {
|
||||
sn_pipe_valid = 1;
|
||||
struct sigaction act;
|
||||
memset (&act, 0, sizeof (struct sigaction));
|
||||
act.sa_handler = sigchld_handler;
|
||||
if (sigaction(SIGCHLD, &act, 0)) {
|
||||
perror("sigaction");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // HAVE_SN
|
||||
|
@ -273,10 +279,12 @@ void cleanup()
|
|||
if (server.dsp) XCloseDisplay(server.dsp);
|
||||
|
||||
#ifdef HAVE_SN
|
||||
if (sn_pipe_valid) {
|
||||
sn_pipe_valid = 0;
|
||||
close(sn_pipe[1]);
|
||||
close(sn_pipe[0]);
|
||||
if (startup_notifications) {
|
||||
if (sn_pipe_valid) {
|
||||
sn_pipe_valid = 0;
|
||||
close(sn_pipe[1]);
|
||||
close(sn_pipe[0]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -1160,7 +1168,8 @@ start:
|
|||
while (XPending (server.dsp)) {
|
||||
XNextEvent(server.dsp, &e);
|
||||
#if HAVE_SN
|
||||
sn_display_process_event (server.sn_dsp, &e);
|
||||
if (startup_notifications)
|
||||
sn_display_process_event(server.sn_dsp, &e);
|
||||
#endif // HAVE_SN
|
||||
|
||||
panel = get_panel(e.xany.window);
|
||||
|
|
|
@ -108,7 +108,7 @@ GtkWidget *launcher_apps_dirs;
|
|||
GtkWidget *launcher_icon_size, *launcher_icon_theme, *launcher_padding_x, *launcher_padding_y, *launcher_spacing;
|
||||
GtkWidget *margin_x, *margin_y;
|
||||
GtkWidget *launcher_background;
|
||||
|
||||
GtkWidget *startup_notifications;
|
||||
IconThemeWrapper *icon_theme;
|
||||
|
||||
GtkListStore *backgrounds;
|
||||
|
@ -1780,7 +1780,7 @@ void create_launcher(GtkWidget *parent)
|
|||
gtk_widget_show(label);
|
||||
gtk_box_pack_start(GTK_BOX(parent), label, FALSE, FALSE, 0);
|
||||
|
||||
table = gtk_table_new(6, 10, FALSE);
|
||||
table = gtk_table_new(7, 10, FALSE);
|
||||
gtk_widget_show(table);
|
||||
gtk_box_pack_start(GTK_BOX(parent), table, FALSE, FALSE, 0);
|
||||
gtk_table_set_row_spacings(GTK_TABLE(table), ROW_SPACING);
|
||||
|
@ -1836,7 +1836,6 @@ void create_launcher(GtkWidget *parent)
|
|||
gtk_widget_show(label);
|
||||
gtk_table_attach(GTK_TABLE(table), label, 6, 7, 2, 3, GTK_FILL, 0, 0, 0);
|
||||
|
||||
|
||||
launcher_icon_theme = gtk_combo_box_new_with_model(GTK_TREE_MODEL(icon_themes));
|
||||
GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
|
||||
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(launcher_icon_theme), renderer, FALSE);
|
||||
|
@ -1845,6 +1844,15 @@ void create_launcher(GtkWidget *parent)
|
|||
gtk_widget_show(launcher_icon_theme);
|
||||
gtk_table_attach(GTK_TABLE(table), launcher_icon_theme, 7, 8, 2, 3, GTK_FILL, 0, 0, 0);
|
||||
|
||||
label = gtk_label_new(_("Startup notifications"));
|
||||
gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
|
||||
gtk_widget_show(label);
|
||||
gtk_table_attach(GTK_TABLE(table), label, 2, 3, 3, 4, GTK_FILL, 0, 0, 0);
|
||||
|
||||
startup_notifications = gtk_check_button_new();
|
||||
gtk_widget_show(startup_notifications);
|
||||
gtk_table_attach(GTK_TABLE(table), startup_notifications, 3, 4, 3, 4, GTK_FILL, 0, 0, 0);
|
||||
|
||||
change_paragraph(parent);
|
||||
|
||||
GtkTreeIter iter;
|
||||
|
|
|
@ -121,7 +121,7 @@ extern GtkWidget *launcher_apps_dirs;
|
|||
extern GtkWidget *launcher_icon_size, *launcher_icon_theme, *launcher_padding_x, *launcher_padding_y, *launcher_spacing;
|
||||
extern GtkWidget *margin_x, *margin_y;
|
||||
extern GtkWidget *launcher_background;
|
||||
|
||||
extern GtkWidget *startup_notifications;
|
||||
extern IconThemeWrapper *icon_theme;
|
||||
|
||||
void load_desktop_file(const char *file, gboolean selected);
|
||||
|
|
|
@ -393,6 +393,7 @@ void config_write_launcher(FILE *fp)
|
|||
g_free(icon_theme);
|
||||
icon_theme = NULL;
|
||||
}
|
||||
fprintf(fp, "startup_notifications = %d\n", gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(startup_notifications)) ? 1 : 0);
|
||||
|
||||
int index;
|
||||
for (index = 0; ; index++) {
|
||||
|
@ -1119,6 +1120,9 @@ void add_entry(char *key, char *value)
|
|||
else if (strcmp(key, "launcher_icon_theme") == 0) {
|
||||
set_current_icon_theme(value);
|
||||
}
|
||||
else if (strcmp(key, "startup_notifications") == 0) {
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(startup_notifications), atoi(value));
|
||||
}
|
||||
|
||||
/* Tooltip */
|
||||
else if (strcmp(key, "tooltip_show_timeout") == 0) {
|
||||
|
|
Loading…
Reference in a new issue