"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libsn/sn-launcher.c" between
xfe-1.42.tar.gz and xfe-1.43.tar.gz

About: Xfe (X File Explorer) is a file manager and browser (using the FOX toolkit).

sn-launcher.c  (xfe-1.42):sn-launcher.c  (xfe-1.43)
skipping to change at line 37 skipping to change at line 37
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
#include <assert.h> #include <assert.h>
static SnList* context_list = NULL; static SnList* context_list = NULL;
struct SnLauncherContext struct SnLauncherContext
{ {
int refcount; int refcount;
SnDisplay *display; SnDisplay *display;
int screen; int screen;
char *startup_id; char *startup_id;
char *name; char *name;
char *description; char *description;
int workspace; int workspace;
char *wmclass; char *wmclass;
char *binary_name; char *binary_name;
char *icon_name; char *icon_name;
struct timeval initiation_time; char *application_id;
unsigned int completed : 1; struct timeval initiation_time;
unsigned int canceled : 1; unsigned int completed : 1;
unsigned int canceled : 1;
}; };
/** /**
* sn_launcher_context_new: * sn_launcher_context_new:
* @display: an #SnDisplay * @display: an #SnDisplay
* @screen: X screen number * @screen: X screen number
* @event_func: function to be called when a notable event occurs * @event_func: function to be called when a notable event occurs
* @event_func_data: data to pass to @event_func * @event_func_data: data to pass to @event_func
* @free_data_func: function to be called on @event_func_data when freeing the c ontext * @free_data_func: function to be called on @event_func_data when freeing the c ontext
* *
skipping to change at line 71 skipping to change at line 72
* starting a startup sequence. For example a file manager might * starting a startup sequence. For example a file manager might
* create a launcher context when the user double-clicks on * create a launcher context when the user double-clicks on
* an application icon. * an application icon.
* *
* Return value: a new #SnLauncherContext * Return value: a new #SnLauncherContext
**/ **/
SnLauncherContext* SnLauncherContext*
sn_launcher_context_new (SnDisplay *display, sn_launcher_context_new (SnDisplay *display,
int screen) int screen)
{ {
SnLauncherContext *context; SnLauncherContext *context;
if (context_list == NULL) if (context_list == NULL)
context_list = sn_list_new (); context_list = sn_list_new ();
context = sn_new0 (SnLauncherContext, 1); context = sn_new0 (SnLauncherContext, 1);
context->refcount = 1; context->refcount = 1;
context->display = display; context->display = display;
sn_display_ref (context->display); context->screen = screen;
sn_display_ref (context->display);
context->workspace = -1; context->workspace = -1;
sn_list_prepend (context_list, context); sn_list_prepend (context_list, context);
return context; return context;
} }
/** /**
* sn_launcher_context_ref: * sn_launcher_context_ref:
* @context: a #SnLauncherContext * @context: a #SnLauncherContext
* *
* Increments the reference count of @context * Increments the reference count of @context
**/ **/
void void
sn_launcher_context_ref (SnLauncherContext *context) sn_launcher_context_ref (SnLauncherContext *context)
{ {
context->refcount += 1; context->refcount += 1;
} }
/** /**
* sn_launcher_context_unref: * sn_launcher_context_unref:
* @context: a #SnLauncherContext * @context: a #SnLauncherContext
* *
* Decrements the reference count of @context and frees the * Decrements the reference count of @context and frees the
* context if the count reaches zero. * context if the count reaches zero.
**/ **/
void void
sn_launcher_context_unref (SnLauncherContext *context) sn_launcher_context_unref (SnLauncherContext *context)
{ {
context->refcount -= 1; context->refcount -= 1;
if (context->refcount == 0) if (context->refcount == 0)
{ {
sn_list_remove (context_list, context); sn_list_remove (context_list, context);
sn_free (context->startup_id); sn_free (context->startup_id);
sn_free (context->name); sn_free (context->name);
sn_free (context->description); sn_free (context->description);
sn_free (context->wmclass); sn_free (context->wmclass);
sn_free (context->binary_name); sn_free (context->binary_name);
sn_free (context->icon_name); sn_free (context->icon_name);
sn_free (context->application_id);
sn_display_unref (context->display); sn_display_unref (context->display);
sn_free (context); sn_free (context);
} }
} }
static char* static char*
strip_slashes (const char *src) strip_slashes (const char *src)
{ {
char *canonicalized_name; char *canonicalized_name;
char *s; char *s;
canonicalized_name = sn_internal_strdup (src); canonicalized_name = sn_internal_strdup (src);
s = canonicalized_name; s = canonicalized_name;
while (*s) while (*s)
{ {
if (*s == '/') if (*s == '/')
*s = '|'; *s = '|';
++s; ++s;
} }
return canonicalized_name; return canonicalized_name;
} }
/** /**
* sn_launcher_context_initiate: * sn_launcher_context_initiate:
* @context: an #SnLaunchContext * @context: an #SnLaunchContext
* @launcher_name: name of the launcher app, suitable for debug output * @launcher_name: name of the launcher app, suitable for debug output
* @launchee_name: name of the launchee app, suitable for debug output * @launchee_name: name of the launchee app, suitable for debug output
* @timestamp: X timestamp of event causing the launch * @timestamp: X timestamp of event causing the launch
* *
* Initiates a startup sequence. All the properties of the launch (such * Initiates a startup sequence. All the properties of the launch (such
* as type, geometry, description) should be set up prior to * as type, geometry, description) should be set up prior to
* initiating the sequence. * initiating the sequence.
**/ **/
void void
sn_launcher_context_initiate (SnLauncherContext *context, sn_launcher_context_initiate (SnLauncherContext *context,
const char *launcher_name, const char *launcher_name,
const char *launchee_name, const char *launchee_name,
Time timestamp) Time timestamp)
{ {
static int sequence_number = 0; static int sequence_number = 0;
static sn_bool_t have_hostname = FALSE; static sn_bool_t have_hostname = FALSE;
static char hostbuf[257]; static char hostbuf[257];
char *s; char *s;
int len; int len;
char *canonicalized_launcher; char *canonicalized_launcher;
char *canonicalized_launchee; char *canonicalized_launchee;
int i; int i;
#define MAX_PROPS 12 #define MAX_PROPS 12
char *names[MAX_PROPS]; char *names[MAX_PROPS];
char *values[MAX_PROPS]; char *values[MAX_PROPS];
char *message; char *message;
char workspacebuf[257]; char workspacebuf[257];
char screenbuf[257]; char screenbuf[257];
if (context->startup_id != NULL) if (context->startup_id != NULL)
{ {
fprintf (stderr, "%s called twice for the same SnLaunchContext\n", fprintf (stderr, "%s called twice for the same SnLaunchContext\n",
__func__); __func__);
return; return;
} }
if (!have_hostname) if (!have_hostname)
{ {
if (gethostname (hostbuf, sizeof (hostbuf)-1) == 0) if (gethostname (hostbuf, sizeof (hostbuf)-1) == 0)
have_hostname = TRUE; have_hostname = TRUE;
else else
hostbuf[0] = '\0'; hostbuf[0] = '\0';
} }
canonicalized_launcher = strip_slashes (launcher_name); canonicalized_launcher = strip_slashes (launcher_name);
canonicalized_launchee = strip_slashes (launchee_name); canonicalized_launchee = strip_slashes (launchee_name);
/* man I wish we could use g_strdup_printf */ /* man I wish we could use g_strdup_printf */
len = strlen (launcher_name) + strlen (launchee_name) + len = strlen (launcher_name) + strlen (launchee_name) +
256; /* 256 is longer than a couple %d and some slashes */ 256; /* 256 is longer than a couple %d and some slashes */
s = sn_malloc (len + 3); s = sn_malloc (len + 3);
snprintf (s, len, "%s/%s/%d-%d-%s_TIME%lu", snprintf (s, len, "%s/%s/%d-%d-%s_TIME%lu",
canonicalized_launcher, canonicalized_launchee, canonicalized_launcher, canonicalized_launchee,
(int) getpid (), (int) sequence_number, hostbuf, (int) getpid (), (int) sequence_number, hostbuf,
(unsigned long) timestamp); (unsigned long) timestamp);
++sequence_number; ++sequence_number;
sn_free (canonicalized_launcher); sn_free (canonicalized_launcher);
sn_free (canonicalized_launchee); sn_free (canonicalized_launchee);
context->startup_id = s; context->startup_id = s;
i = 0; i = 0;
names[i] = "ID"; names[i] = "ID";
values[i] = context->startup_id; values[i] = context->startup_id;
++i; ++i;
names[i] = "SCREEN"; names[i] = "SCREEN";
snprintf (screenbuf, sizeof(screenbuf)-1, "%d", context->screen); sprintf (screenbuf, "%d", context->screen);
values[i] = screenbuf; values[i] = screenbuf;
++i; ++i;
if (context->name != NULL) if (context->name != NULL)
{ {
names[i] = "NAME"; names[i] = "NAME";
values[i] = context->name; values[i] = context->name;
++i; ++i;
} }
if (context->description != NULL) if (context->description != NULL)
{ {
names[i] = "DESCRIPTION"; names[i] = "DESCRIPTION";
values[i] = context->description; values[i] = context->description;
++i; ++i;
} }
if (context->workspace >= 0) if (context->workspace >= 0)
{ {
names[i] = "DESKTOP"; names[i] = "DESKTOP";
snprintf (workspacebuf, sizeof(workspacebuf)-1, "%d", context->workspace sprintf (workspacebuf, "%d", context->workspace);
); values[i] = workspacebuf;
values[i] = workspacebuf; ++i;
++i;
} }
if (context->wmclass != NULL) if (context->wmclass != NULL)
{ {
names[i] = "WMCLASS"; names[i] = "WMCLASS";
values[i] = context->wmclass; values[i] = context->wmclass;
++i; ++i;
} }
if (context->binary_name != NULL) if (context->binary_name != NULL)
{ {
names[i] = "BIN"; names[i] = "BIN";
values[i] = context->binary_name; values[i] = context->binary_name;
++i; ++i;
} }
if (context->icon_name != NULL) if (context->icon_name != NULL)
{ {
names[i] = "ICON"; names[i] = "ICON";
values[i] = context->icon_name; values[i] = context->icon_name;
++i; ++i;
} }
assert (i < MAX_PROPS); if (context->application_id != NULL)
{
names[i] = "APPLICATION_ID";
values[i] = context->application_id;
++i;
}
assert (i < MAX_PROPS);
names[i] = NULL; names[i] = NULL;
values[i] = NULL; values[i] = NULL;
gettimeofday (&context->initiation_time, NULL); gettimeofday (&context->initiation_time, NULL);
message = sn_internal_serialize_message ("new", message = sn_internal_serialize_message ("new",
(const char**) names, (const char**) names,
(const char**) values); (const char**) values);
sn_internal_broadcast_xmessage (context->display, sn_internal_broadcast_xmessage (context->display,
context->screen, context->screen,
"_NET_STARTUP_INFO", sn_internal_get_net_startup_info_atom(context-
"_NET_STARTUP_INFO_BEGIN", >display),
message); sn_internal_get_net_startup_info_begin_atom(co
ntext->display),
message);
sn_free (message); sn_free (message);
} }
void void
sn_launcher_context_complete (SnLauncherContext *context) sn_launcher_context_complete (SnLauncherContext *context)
{ {
char *keys[2]; char *keys[2];
char *vals[2]; char *vals[2];
char *message; char *message;
if (context->startup_id == NULL) if (context->startup_id == NULL)
{ {
fprintf (stderr, "%s called for an SnLauncherContext that hasn't been in fprintf (stderr, "%s called for an SnLauncherContext that hasn't been init
itiated\n", iated\n",
"sn_launcher_context_complete"); "sn_launcher_context_complete");
return; return;
} }
keys[0] = "ID"; keys[0] = "ID";
keys[1] = NULL; keys[1] = NULL;
vals[0] = context->startup_id; vals[0] = context->startup_id;
vals[1] = NULL; vals[1] = NULL;
message = sn_internal_serialize_message ("remove", message = sn_internal_serialize_message ("remove",
(const char**) keys, (const char**) keys,
(const char **) vals); (const char **) vals);
sn_internal_broadcast_xmessage (context->display, sn_internal_broadcast_xmessage (context->display,
context->screen, context->screen,
"_NET_STARTUP_INFO", sn_internal_get_net_startup_info_atom(context-
"_NET_STARTUP_INFO_BEGIN", >display),
message); sn_internal_get_net_startup_info_begin_atom(co
ntext->display),
message);
sn_free (message); sn_free (message);
} }
const char* const char*
sn_launcher_context_get_startup_id (SnLauncherContext *context) sn_launcher_context_get_startup_id (SnLauncherContext *context)
{ {
return context->startup_id; return context->startup_id;
} }
sn_bool_t sn_bool_t
sn_launcher_context_get_initiated (SnLauncherContext *context) sn_launcher_context_get_initiated (SnLauncherContext *context)
{ {
return context->startup_id != NULL; return context->startup_id != NULL;
} }
/** /**
* sn_launcher_context_setup_child_process: * sn_launcher_context_setup_child_process:
* @context: an #SnLauncherContext * @context: an #SnLauncherContext
* *
* This function should be called after forking, but before exec(), in * This function should be called after forking, but before exec(), in
* the child process being launched. It sets up the environment variables * the child process being launched. It sets up the environment variables
* telling the child process about the launch ID. * telling the child process about the launch ID.
* This function will leak the strings passed to putenv() so should * This function will leak the strings passed to putenv() so should
* only be used prior to an exec(). * only be used prior to an exec().
* *
**/ **/
void void
sn_launcher_context_setup_child_process (SnLauncherContext *context) sn_launcher_context_setup_child_process (SnLauncherContext *context)
{ {
char *startup_id; char *startup_id;
size_t stsize;
if (context->startup_id == NULL) if (context->startup_id == NULL)
{ {
fprintf (stderr, "%s called for an SnLauncherContext that hasn't been in fprintf (stderr, "%s called for an SnLauncherContext that hasn't been init
itiated\n", iated\n",
"sn_launcher_context_setup_child_process"); "sn_launcher_context_setup_child_process");
return; return;
} }
/* Man we need glib here */ /* Man we need glib here */
stsize = strlen (context->startup_id) + strlen ("DESKTOP_STARTUP_ID") + 3;
startup_id = sn_malloc (stsize);
strncpy (startup_id, "DESKTOP_STARTUP_ID=", stsize);
strncat (startup_id, context->startup_id, stsize);
putenv (startup_id); startup_id = sn_malloc (strlen (context->startup_id) + strlen ("DESKTOP_STARTU
P_ID") + 3);
strcpy (startup_id, "DESKTOP_STARTUP_ID=");
strcat (startup_id, context->startup_id);
/* Can't free strings passed to putenv */ putenv (startup_id);
/* Can't free strings passed to putenv */
} }
/* FIXME use something pluggable, not fprintf */ /* FIXME use something pluggable, not fprintf */
#define WARN_ALREADY_INITIATED(context) do { if ((context)->startup_id != NULL) { \ #define WARN_ALREADY_INITIATED(context) do { if ((context)->startup_id != NULL) { \
fprintf (stderr, "%s called for an SnLauncherContext that has already been initiated\n", \ fprintf (stderr, "%s called for an SnLauncherContext that has already been initiated\n", \
__func__); \ __func__); \
return; \ return; \
} } while (0) } } while (0)
void void
sn_launcher_context_set_name (SnLauncherContext *context, sn_launcher_context_set_name (SnLauncherContext *context,
const char *name) const char *name)
{ {
WARN_ALREADY_INITIATED (context); WARN_ALREADY_INITIATED (context);
sn_free (context->name); sn_free (context->name);
context->name = sn_internal_strdup (name); context->name = sn_internal_strdup (name);
} }
void void
sn_launcher_context_set_description (SnLauncherContext *context, sn_launcher_context_set_description (SnLauncherContext *context,
const char *description) const char *description)
{ {
WARN_ALREADY_INITIATED (context); WARN_ALREADY_INITIATED (context);
sn_free (context->description); sn_free (context->description);
context->description = sn_internal_strdup (description); context->description = sn_internal_strdup (description);
} }
void void
sn_launcher_context_set_workspace (SnLauncherContext *context, sn_launcher_context_set_workspace (SnLauncherContext *context,
int workspace) int workspace)
{ {
WARN_ALREADY_INITIATED (context); WARN_ALREADY_INITIATED (context);
context->workspace = workspace; context->workspace = workspace;
} }
void void
sn_launcher_context_set_wmclass (SnLauncherContext *context, sn_launcher_context_set_wmclass (SnLauncherContext *context,
const char *klass) const char *klass)
{ {
WARN_ALREADY_INITIATED (context); WARN_ALREADY_INITIATED (context);
sn_free (context->wmclass); sn_free (context->wmclass);
context->wmclass = sn_internal_strdup (klass); context->wmclass = sn_internal_strdup (klass);
} }
void void
sn_launcher_context_set_binary_name (SnLauncherContext *context, sn_launcher_context_set_binary_name (SnLauncherContext *context,
const char *name) const char *name)
{ {
WARN_ALREADY_INITIATED (context); WARN_ALREADY_INITIATED (context);
sn_free (context->binary_name); sn_free (context->binary_name);
context->binary_name = sn_internal_strdup (name); context->binary_name = sn_internal_strdup (name);
} }
void void
sn_launcher_context_set_icon_name (SnLauncherContext *context, sn_launcher_context_set_icon_name (SnLauncherContext *context,
const char *name) const char *name)
{ {
WARN_ALREADY_INITIATED (context); WARN_ALREADY_INITIATED (context);
sn_free (context->icon_name);
context->icon_name = sn_internal_strdup (name);
}
void
sn_launcher_set_application_id (SnLauncherContext *context,
const char *desktop_file)
{
WARN_ALREADY_INITIATED (context);
sn_free (context->icon_name); sn_free (context->application_id);
context->icon_name = sn_internal_strdup (name); context->application_id = sn_internal_strdup (desktop_file);
} }
void void
sn_launcher_context_set_extra_property (SnLauncherContext *context, sn_launcher_context_set_extra_property (SnLauncherContext *context,
const char *name, const char *name,
const char *value) const char *value)
{ {
WARN_ALREADY_INITIATED (context); WARN_ALREADY_INITIATED (context);
/* FIXME implement this */ /* FIXME implement this */
} }
void void
sn_launcher_context_get_initiated_time (SnLauncherContext *context, sn_launcher_context_get_initiated_time (SnLauncherContext *context,
long *tv_sec, long *tv_sec,
long *tv_usec) long *tv_usec)
{ {
if (context->startup_id == NULL) if (context->startup_id == NULL)
{ {
fprintf (stderr, "%s called for an SnLauncherContext that hasn't been in fprintf (stderr, "%s called for an SnLauncherContext that hasn't been init
itiated\n", iated\n",
"sn_launcher_context_get_initiated_time"); "sn_launcher_context_get_initiated_time");
return; return;
} }
if (tv_sec) if (tv_sec)
*tv_sec = context->initiation_time.tv_sec; *tv_sec = context->initiation_time.tv_sec;
if (tv_usec) if (tv_usec)
*tv_usec = context->initiation_time.tv_usec; *tv_usec = context->initiation_time.tv_usec;
} }
void void
sn_launcher_context_get_last_active_time (SnLauncherContext *context, sn_launcher_context_get_last_active_time (SnLauncherContext *context,
long *tv_sec, long *tv_sec,
long *tv_usec) long *tv_usec)
{ {
if (context->startup_id == NULL) if (context->startup_id == NULL)
{ {
fprintf (stderr, "%s called for an SnLauncherContext that hasn't been in fprintf (stderr, "%s called for an SnLauncherContext that hasn't been init
itiated\n", iated\n",
"sn_launcher_context_get_initiated_time"); "sn_launcher_context_get_initiated_time");
return; return;
} }
/* for now, maybe forever, the same as initiated time. */ /* for now, maybe forever, the same as initiated time. */
if (tv_sec) if (tv_sec)
*tv_sec = context->initiation_time.tv_sec; *tv_sec = context->initiation_time.tv_sec;
if (tv_usec) if (tv_usec)
*tv_usec = context->initiation_time.tv_usec; *tv_usec = context->initiation_time.tv_usec;
} }
 End of changes. 89 change blocks. 
204 lines changed or deleted 227 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)