]> Dogcows Code - chaz/openbox/blob - obt/instance.c
8299eb85745958935fd8772b2361373b76392b7b
[chaz/openbox] / obt / instance.c
1 #include "obt/obt.h"
2
3 #ifdef HAVE_STRING_H
4 # include <string.h>
5 #endif
6 #ifdef HAVE_FCNTL_H
7 # include <fcntl.h>
8 #endif
9 #ifdef HAVE_UNISTD_H
10 # include <unistd.h>
11 #endif
12
13 struct _ObtInstance
14 {
15 gint ref;
16 Display *d;
17 };
18
19 ObtInstance* obt_instance_new(const char *display_name)
20 {
21 gchar *n;
22 Display *d;
23 ObtInstance *inst = NULL;
24
25 n = display_name ? g_strdup(display_name) : NULL;
26 d = XOpenDisplay(n);
27 if (d) {
28 if (fcntl(ConnectionNumber(d), F_SETFD, 1) == -1)
29 g_message("Failed to set display as close-on-exec");
30
31 inst = g_new(ObtInstance, 1);
32 inst->ref = 1;
33 inst->d = d;
34 }
35 g_free(n);
36
37 return inst;
38 }
39
40 void obt_instance_ref(ObtInstance *inst)
41 {
42 ++inst->ref;
43 }
44
45 void obt_instance_unref(ObtInstance *inst)
46 {
47 if (inst && --inst->ref == 0) {
48 XCloseDisplay(inst->d);
49 obt_free0(inst, ObtInstance, 1);
50 }
51 }
52
53 Display* obt_display(const ObtInstance *inst)
54 {
55 return inst->d;
56 }
This page took 0.040841 seconds and 3 git commands to generate.