1 /*****************************************************************************
2 * This file is part of gfxprim library. *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
24 * X11 connection, singleton.
29 /* window reference counter */
33 static struct x11_conn x11_conn
= {
38 static unsigned int x11_open(const char *display
)
40 if (x11_conn
.ref_cnt
!= 0)
41 return ++x11_conn
.ref_cnt
;
43 GP_DEBUG(1, "Opening X11 display '%s'", display
);
45 if (!XInitThreads()) {
46 GP_DEBUG(2, "XInitThreads failed");
50 x11_conn
.dpy
= XOpenDisplay(display
);
52 if (x11_conn
.dpy
== NULL
) {
53 GP_WARN("Failed to initialize X11 display");
57 /* Initialized key translation table */
58 GP_InputDriverX11Init(x11_conn
.dpy
);
60 return ++x11_conn
.ref_cnt
;
63 static void x11_close(void)
65 /* Ignore close requests if connection is closed */
66 if (x11_conn
.ref_cnt
== 0)
69 if (--x11_conn
.ref_cnt
!= 0)
72 GP_DEBUG(1, "Closing X11 display");
74 XLockDisplay(x11_conn
.dpy
);
76 /* I wonder if this is right sequence... */
77 //XUnlockDisplay(x11_conn.dpy);
78 XCloseDisplay(x11_conn
.dpy
);