File: gnome-startup.c

package info (click to toggle)
gnome-libs 0.30.1-5
  • links: PTS
  • area: main
  • in suites: slink
  • size: 7,576 kB
  • ctags: 8,906
  • sloc: ansic: 96,177; sh: 5,055; makefile: 984; awk: 279; perl: 170; sed: 93
file content (46 lines) | stat: -rw-r--r-- 1,239 bytes parent folder | download | duplicates (6)
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
/* 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-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;
}