Replacing external program ede-launch-sn with StartupNotify code

This commit is contained in:
Sanel Zukan 2011-10-24 12:21:05 +00:00
parent a6b055530b
commit a34cd82898
5 changed files with 140 additions and 105 deletions

View File

@ -10,11 +10,9 @@
SubDir TOP ede-launch ; SubDir TOP ede-launch ;
SOURCE = ede-launch.cpp ; SOURCE = ede-launch.cpp StartupNotify.cpp ;
ObjectC++Flags $(SOURCE) : $(STARTUP_NOTIFICATION_INCLUDE) ;
EdeProgram ede-launch : $(SOURCE) ; EdeProgram ede-launch : $(SOURCE) ;
LinkAgainst ede-launch : $(STARTUP_NOTIFICATION_LIB) ;
TranslationStrings locale : $(SOURCE) ; 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) ;

View File

@ -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 <config.h>
#endif
#ifdef HAVE_LIBSTARTUP_NOTIFICATION
# include <FL/x.H>
# include <edelib/Missing.h>
# include <edelib/Debug.h>
# define SN_API_NOT_YET_FROZEN /* required, for now */
# include <libsn/sn.h>
#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
}

View File

@ -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

View File

@ -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 <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <FL/x.H>
#include <edelib/Missing.h>
#include <edelib/Debug.h>
#ifdef HAVE_LIBSTARTUP_NOTIFICATION
# define SN_API_NOT_YET_FROZEN /* required, for now */
# include <libsn/sn.h>
#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;
}

View File

@ -45,6 +45,7 @@
#include <edelib/DesktopFile.h> #include <edelib/DesktopFile.h>
#include <edelib/StrUtil.h> #include <edelib/StrUtil.h>
#include <edelib/Ede.h> #include <edelib/Ede.h>
#include "StartupNotify.h"
#include "icons/run.xpm" #include "icons/run.xpm"
@ -69,10 +70,30 @@ EDELIB_NS_USING(str_ends)
static Fl_Pixmap image_run((const char**)run_xpm); static Fl_Pixmap image_run((const char**)run_xpm);
static Fl_Input* dialog_input; static Fl_Input* dialog_input;
static Fl_Check_Button* in_term; static Fl_Check_Button* in_term;
static const char *launch_type[] = {
"browser",
"mail",
"terminal",
"file_manager",
0
};
static void help(void) { static void help(void) {
puts("Usage: ede-launch program"); puts("Usage: ede-launch [OPTIONS] [URLs...]");
puts("EDE program launcher"); 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) { 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) { 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); E_DEBUG(E_STRLOC ": Starting '%s'\n", cmd);
StartupNotify *n = startup_notify_start(cmd, "applications-order");
int ret = start_child_process_with_core(cmd); int ret = start_child_process_with_core(cmd);
startup_notify_end(n);
if(ret == 199) { if(ret == 199) {
alert(_("Program '%s' not found.\n\nPlease check if given path to the " alert(_("Program '%s' not found.\n\nPlease check if given path to the "
"executable was correct or adjust $PATH environment variable to " "executable was correct or adjust $PATH environment variable to "