Remove GDK dependency from registry daemon.
[platform/upstream/at-spi2-core.git] / registryd / display.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2009 Nokia.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include <glib.h>
24
25 #include <X11/Xlib.h>
26 #include <X11/Xutil.h>
27 #include <X11/Xos.h>
28 #include <X11/Xatom.h>
29
30 #include <stdio.h>
31 #include <stdlib.h>
32
33 #include "display.h"
34
35 static Display *default_display = NULL;
36
37 Display *spi_set_display (const char *display_name)
38 {
39         /* 
40          * TODO - Should we ever do anything different might need to
41          * close previous display.
42          */
43         default_display = XOpenDisplay (display_name);  
44         if (!default_display)
45         {
46                 g_error ("AT-SPI: Cannot open default display");
47                 return NULL;
48         }
49 }
50
51 Display *spi_get_display ()
52 {
53         if (!default_display)
54                 spi_set_display (NULL);
55
56         return default_display;
57 }
58
59 Window spi_get_root_window ()
60 {
61         if (!default_display)
62                 spi_set_display (NULL);
63
64         return DefaultRootWindow (default_display);
65 }
66
67 static int (*old_x_error_handler) (Display *, XErrorEvent *);
68 static int x_error_code;
69
70 static int spi_x_error_handler (Display *display, XErrorEvent *error)
71 {
72         if (error->error_code)
73                 x_error_code = error->error_code;
74         else
75                 x_error_code = 0;
76   
77         return 0;
78 }
79
80 void spi_x_error_trap (void)
81 {
82         old_x_error_handler = XSetErrorHandler (spi_x_error_handler);
83 }
84
85 int spi_x_error_release (void)
86 {
87         XSetErrorHandler (old_x_error_handler);
88         return x_error_code;
89 }