void sn_setup_spawn_environment(const gchar *program, const gchar *name, const gchar *icon_name, const gchar *wmclass, gint desktop) { gchar *desc; const char *id; desc = g_strdup_printf(_("Running %s"), program); if (sn_launcher_context_get_initiated(sn_launcher)) { sn_launcher_context_unref(sn_launcher); sn_launcher = sn_launcher_context_new(sn_display, ob_screen); } sn_launcher_context_set_name(sn_launcher, name ? name : program); sn_launcher_context_set_description(sn_launcher, desc); sn_launcher_context_set_icon_name(sn_launcher, icon_name ? icon_name : program); sn_launcher_context_set_binary_name(sn_launcher, program); if (wmclass) sn_launcher_context_set_wmclass(sn_launcher, wmclass); if (desktop >= 0 && (unsigned) desktop < screen_num_desktops) sn_launcher_context_set_workspace(sn_launcher, (signed) desktop); sn_launcher_context_initiate(sn_launcher, "openbox", program, event_time()); id = sn_launcher_context_get_startup_id(sn_launcher); /* 20 second timeout for apps to start */ sn_launcher_context_ref(sn_launcher); obt_main_loop_timeout_add(ob_main_loop, 20 * G_USEC_PER_SEC, sn_launch_wait_timeout, sn_launcher, g_direct_equal, (GDestroyNotify)sn_launcher_context_unref); setenv("DESKTOP_STARTUP_ID", id, TRUE); g_free(desc); }
StartupNotify *startup_notify_start(const char *program, const char *icon) { #ifdef HAVE_LIBSTARTUP_NOTIFICATION const char *id; fl_open_display(); StartupNotify *s = new StartupNotify; s->display = sn_display_new(fl_display, error_trap_push, error_trap_pop); s->context = sn_launcher_context_new(s->display, fl_screen); sn_launcher_context_set_binary_name(s->context, program); sn_launcher_context_set_icon_name(s->context, icon); sn_launcher_context_initiate(s->context, "ede-launch", program, CurrentTime); id = sn_launcher_context_get_startup_id(s->context); if(!id) id = ""; edelib_setenv("DESKTOP_STARTUP_ID", id, 1); XSync(fl_display, False); return s; #else return 0; #endif }
gboolean vfs_exec_on_screen( GdkScreen* screen, const char* work_dir, char** argv, char** envp, const char* disp_name, GSpawnFlags flags, GError **err ) { #ifdef HAVE_SN SnLauncherContext * ctx = NULL; SnDisplay* display; #endif gboolean ret; GSpawnChildSetupFunc setup_func = NULL; extern char **environ; char** new_env = envp; int i, n_env = 0; char* display_name; int display_index = -1, startup_id_index = -1; if ( ! envp ) envp = environ; n_env = g_strv_length(envp); new_env = g_new0( char*, n_env + 4 ); for ( i = 0; i < n_env; ++i ) { /* g_debug( "old envp[%d] = \"%s\"" , i, envp[i]); */ if ( 0 == strncmp( envp[ i ], "DISPLAY=", 8 ) ) display_index = i; else { if ( 0 == strncmp( envp[ i ], "DESKTOP_STARTUP_ID=", 19 ) ) startup_id_index = i; new_env[i] = g_strdup( envp[ i ] ); } } #ifdef HAVE_SN display = sn_display_new ( GDK_SCREEN_XDISPLAY ( screen ), ( SnDisplayErrorTrapPush ) gdk_error_trap_push, ( SnDisplayErrorTrapPush ) gdk_error_trap_pop ); if ( G_LIKELY ( display ) ) { if ( !disp_name ) disp_name = argv[ 0 ]; ctx = sn_launcher_context_new( display, gdk_screen_get_number( screen ) ); sn_launcher_context_set_description( ctx, disp_name ); sn_launcher_context_set_name( ctx, g_get_prgname() ); sn_launcher_context_set_binary_name( ctx, argv[ 0 ] ); sn_launcher_context_set_workspace ( ctx, tvsn_get_active_workspace_number( screen ) ); /* FIXME: I don't think this is correct, other people seem to use CurrentTime here. However, using CurrentTime causes problems, so I so it like this. Maybe this is incorrect, but it works, so, who cares? */ /* time( &cur_time ); */ sn_launcher_context_initiate( ctx, g_get_prgname(), argv[ 0 ], gtk_get_current_event_time() /*cur_time*/ ); setup_func = (GSpawnChildSetupFunc) sn_launcher_context_setup_child_process; if( startup_id_index >= 0 ) g_free( new_env[i] ); else startup_id_index = i++; new_env[ startup_id_index ] = g_strconcat( "DESKTOP_STARTUP_ID=", sn_launcher_context_get_startup_id ( ctx ), NULL ); } #endif /* This is taken from gdk_spawn_on_screen */ display_name = gdk_screen_make_display_name ( screen ); if ( display_index >= 0 ) new_env[ display_index ] = g_strconcat( "DISPLAY=", display_name, NULL ); else new_env[ i++ ] = g_strconcat( "DISPLAY=", display_name, NULL ); g_free( display_name ); new_env[ i ] = NULL; ret = g_spawn_async( work_dir, argv, new_env, flags, NULL, NULL, NULL, err ); /* for debugging */ #if 0 g_debug( "debug vfs_execute_on_screen(): flags: %d, display_index=%d", flags, display_index ); for( i = 0; argv[i]; ++i ) { g_debug( "argv[%d] = \"%s\"" , i, argv[i] ); } for( i = 0; i < n_env /*new_env[i]*/; ++i ) { g_debug( "new_env[%d] = \"%s\"" , i, new_env[i] ); } if( ret ) g_debug( "the program was executed without error" ); else g_debug( "launch failed: %s", (*err)->message ); #endif g_strfreev( new_env ); #ifdef HAVE_SN if ( G_LIKELY ( ctx ) ) { if ( G_LIKELY ( ret ) ) g_timeout_add ( 20 * 1000, sn_timeout, ctx ); else { sn_launcher_context_complete ( ctx ); sn_launcher_context_unref ( ctx ); } } if ( G_LIKELY ( display ) ) sn_display_unref ( display ); #endif return ret; }