File: gnome-startup.c

package info (click to toggle)
control-center 1%3A2.8.2-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 19,208 kB
  • ctags: 3,408
  • sloc: ansic: 37,294; sh: 10,539; makefile: 844; xml: 18
file content (47 lines) | stat: -rw-r--r-- 1,235 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* gnome-startup.c - Functions for handling one-time startups in sessions.
   Written by Tom Tromey <tromey@cygnus.com>.  */

#include "config.h"

//#include "libgnome/libgnomeP.h"
#include <gnome.h>
#include "gnome-startup.h"

#include <string.h>
#include <gdk/gdkx.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>

gboolean
gnome_startup_acquire_token (const char *property, const char *session_id)
{
	Atom atom, actual;
	unsigned long nitems, nbytes;
	unsigned char *current;
	int len, format;
	gboolean result;

	atom = XInternAtom (GDK_DISPLAY (), property, False);
	len = strlen (session_id);

	/* Append our session id to the property.  We do this to avoid a
	   race condition: if two clients run this code, we want to make
	   sure that only one client can acquire the lock.  */
	XChangeProperty (GDK_DISPLAY (),
			 DefaultRootWindow (GDK_DISPLAY ()), atom,
			 XA_STRING, 8, PropModeAppend, session_id, len);

	if (XGetWindowProperty
	    (GDK_DISPLAY (), DefaultRootWindow (GDK_DISPLAY ()), atom, 0,
	     len, False, XA_STRING, &actual, &format, &nitems, &nbytes,
	     &current) != Success)
		current = NULL;

	if (!current)
		return 0;

	result = !strncmp (current, session_id, len);
	XFree (current);

	return result;
}