From a34cd828984bb1ba9b04b70ed47739e873163d38 Mon Sep 17 00:00:00 2001 From: Sanel Zukan Date: Mon, 24 Oct 2011 12:21:05 +0000 Subject: [PATCH] Replacing external program ede-launch-sn with StartupNotify code --- ede-launch/Jamfile | 8 ++- ede-launch/StartupNotify.cpp | 90 ++++++++++++++++++++++++++++++++++ ede-launch/StartupNotify.h | 21 ++++++++ ede-launch/ede-launch-sn.cpp | 95 ------------------------------------ ede-launch/ede-launch.cpp | 31 ++++++++++-- 5 files changed, 140 insertions(+), 105 deletions(-) create mode 100644 ede-launch/StartupNotify.cpp create mode 100644 ede-launch/StartupNotify.h delete mode 100644 ede-launch/ede-launch-sn.cpp diff --git a/ede-launch/Jamfile b/ede-launch/Jamfile index 7784698..4e28222 100644 --- a/ede-launch/Jamfile +++ b/ede-launch/Jamfile @@ -10,11 +10,9 @@ SubDir TOP ede-launch ; -SOURCE = ede-launch.cpp ; +SOURCE = ede-launch.cpp StartupNotify.cpp ; +ObjectC++Flags $(SOURCE) : $(STARTUP_NOTIFICATION_INCLUDE) ; EdeProgram ede-launch : $(SOURCE) ; +LinkAgainst ede-launch : $(STARTUP_NOTIFICATION_LIB) ; TranslationStrings locale : $(SOURCE) ; - -ObjectC++Flags ede-launch-sn.cpp : $(STARTUP_NOTIFICATION_INCLUDE) ; -EdeProgram ede-launch-sn : ede-launch-sn.cpp ; -LinkAgainst ede-launch-sn : $(STARTUP_NOTIFICATION_LIB) ; diff --git a/ede-launch/StartupNotify.cpp b/ede-launch/StartupNotify.cpp new file mode 100644 index 0000000..3e76491 --- /dev/null +++ b/ede-launch/StartupNotify.cpp @@ -0,0 +1,90 @@ +/* + * $Id: ede-launch.cpp 3112 2011-10-24 09:02:36Z karijes $ + * + * ede-launch, launch external application + * Part of Equinox Desktop Environment (EDE). + * Copyright (c) 2008-2011 EDE Authors. + * + * This program is licensed under terms of the + * GNU General Public License version 2 or newer. + * See COPYING for details. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifdef HAVE_LIBSTARTUP_NOTIFICATION +# include +# include +# include + +# define SN_API_NOT_YET_FROZEN /* required, for now */ +# include +#endif + +#include "StartupNotify.h" + +struct StartupNotify { +#ifdef HAVE_LIBSTARTUP_NOTIFICATION + SnDisplay *display; + SnLauncherContext *context; +#endif + /* if we have empty struct */ + int dummy; +}; + +#ifdef HAVE_LIBSTARTUP_NOTIFICATION +static int error_trap_depth = 0; + +static void error_trap_push(SnDisplay *display, Display *xdisplay) { + error_trap_depth++; +} + +static void error_trap_pop(SnDisplay *display, Display *xdisplay) { + if(error_trap_depth == 0) + E_FATAL(E_STRLOC ": Error trap underflow!\n"); + + XSync(xdisplay, False); + error_trap_depth--; +} +#endif + +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 +} + +void startup_notify_end(StartupNotify *s) { +#if HAVE_LIBSTARTUP_NOTIFICATION + E_RETURN_IF_FAIL(s != 0); + sn_launcher_context_complete(s->context); + sn_launcher_context_unref(s->context); + sn_display_unref(s->display); + + edelib_unsetenv("DESKTOP_STARTUP_ID"); + XSync(fl_display, False); + + delete s; +#endif +} diff --git a/ede-launch/StartupNotify.h b/ede-launch/StartupNotify.h new file mode 100644 index 0000000..356a75b --- /dev/null +++ b/ede-launch/StartupNotify.h @@ -0,0 +1,21 @@ +/* + * $Id: ede-launch.cpp 3112 2011-10-24 09:02:36Z karijes $ + * + * ede-launch, launch external application + * Part of Equinox Desktop Environment (EDE). + * Copyright (c) 2008-2011 EDE Authors. + * + * This program is licensed under terms of the + * GNU General Public License version 2 or newer. + * See COPYING for details. + */ + +#ifndef __STARTUPNOTIFY_H__ +#define __STARTUPNOTIFY_H__ + +struct StartupNotify; + +StartupNotify *startup_notify_start(const char *progam, const char *icon); +void startup_notify_end(StartupNotify *s); + +#endif diff --git a/ede-launch/ede-launch-sn.cpp b/ede-launch/ede-launch-sn.cpp deleted file mode 100644 index db43b30..0000000 --- a/ede-launch/ede-launch-sn.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * $Id$ - * - * ede-launch, launch external application - * Part of Equinox Desktop Environment (EDE). - * Copyright (c) 2008-2009 EDE Authors. - * - * This program is licensed under terms of the - * GNU General Public License version 2 or newer. - * See COPYING for details. - * - * This is an helper program for startup notification system, and - * is run from ede-launch. To simplify things, it was written as separate - * program, but it does not mean that will stay ;) (Sanel) - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_LIBSTARTUP_NOTIFICATION -# define SN_API_NOT_YET_FROZEN /* required, for now */ -# include -#endif - -#ifdef HAVE_LIBSTARTUP_NOTIFICATION -static int error_trap_depth = 0; - -static void error_trap_push(SnDisplay* display, Display* xdisplay) { - error_trap_depth++; -} - -static void error_trap_pop(SnDisplay* display, Display* xdisplay) { - if(error_trap_depth == 0) - E_FATAL(E_STRLOC ": Error trap underflow!\n"); - - XSync(xdisplay, False); - error_trap_depth--; -} - -void help(void) { - puts("You should not run this program manualy! It is meant to be run from 'ede-launch' program"); -} -#endif - -int main(int argc, char** argv) { -#ifdef HAVE_LIBSTARTUP_NOTIFICATION - /* ede-launch-sn --program foo --icon baz */ - if(argc != 5) { - help(); - return 0; - } - - if(!(strcmp(argv[1], "--program") == 0 && strcmp(argv[3], "--icon") == 0)) { - help(); - return 0; - } - - const char* progname, *icon; - progname = argv[2]; - icon = argv[4]; - - fl_open_display(); - - SnDisplay* display = sn_display_new(fl_display, error_trap_push, error_trap_pop); - SnLauncherContext* context = sn_launcher_context_new(display, fl_screen); - - sn_launcher_context_set_binary_name(context, progname); - sn_launcher_context_set_icon_name(context, icon); - sn_launcher_context_initiate(context, "ede-launch", progname, CurrentTime); - - const char* id = sn_launcher_context_get_startup_id(context); - if(!id) - id = ""; - edelib_setenv("DESKTOP_STARTUP_ID", id, 1); - XSync(fl_display, False); - - /* default timeout before stopping notification */ - sleep(2); - - sn_launcher_context_complete(context); - sn_launcher_context_unref(context); - sn_display_unref(display); - edelib_unsetenv("DESKTOP_STARTUP_ID"); - XSync(fl_display, False); -#endif - return 0; -} diff --git a/ede-launch/ede-launch.cpp b/ede-launch/ede-launch.cpp index 02647d9..18af1db 100644 --- a/ede-launch/ede-launch.cpp +++ b/ede-launch/ede-launch.cpp @@ -45,6 +45,7 @@ #include #include #include +#include "StartupNotify.h" #include "icons/run.xpm" @@ -69,10 +70,30 @@ EDELIB_NS_USING(str_ends) static Fl_Pixmap image_run((const char**)run_xpm); static Fl_Input* dialog_input; static Fl_Check_Button* in_term; +static const char *launch_type[] = { + "browser", + "mail", + "terminal", + "file_manager", + 0 +}; static void help(void) { - puts("Usage: ede-launch program"); + puts("Usage: ede-launch [OPTIONS] [URLs...]"); puts("EDE program launcher"); + puts("Options:"); + puts(" -h, --help show this help"); + puts(" -l, --launch [TYPE] [PARAMETERS] launch preferred application of TYPE with"); + puts(" given PARAMETERS; see Types below"); + puts(" -w, --working-dir [DIR] run programs with DIR as working directory\n"); + puts("Types:"); + puts(" browser preferred web browser"); + puts(" mail preferred mail reader"); + puts(" terminal preferred terminal"); + puts(" file_manager preferred file manager\n"); + puts("Example:"); + puts(" ede-launch --launch browser http://www.foo.com"); + puts(" ede-launch gvim"); } static char* get_basename(const char* path) { @@ -235,13 +256,13 @@ static int start_child_process_with_core(const char* cmd) { } static bool start_child(const char* cmd) { -#ifdef HAVE_LIBSTARTUP_NOTIFICATION - run_async("ede-launch-sn --program %s --icon applications-order", cmd); -#endif - E_DEBUG(E_STRLOC ": Starting '%s'\n", cmd); + + StartupNotify *n = startup_notify_start(cmd, "applications-order"); int ret = start_child_process_with_core(cmd); + startup_notify_end(n); + if(ret == 199) { alert(_("Program '%s' not found.\n\nPlease check if given path to the " "executable was correct or adjust $PATH environment variable to "