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 Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 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
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library; if not, write to the
19
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
 * Boston, MA 02110-1301, USA.
21
 */
22

            
23
#include <glib.h>
24

            
25
#include <X11/Xatom.h>
26
#include <X11/Xlib.h>
27
#include <X11/Xos.h>
28
#include <X11/Xutil.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 *
38
28
spi_set_display (const char *display_name)
39
{
40
  /*
41
   * TODO - Should we ever do anything different might need to
42
   * close previous display.
43
   */
44
28
  default_display = XOpenDisplay (display_name);
45
28
  if (!default_display)
46
    {
47
      g_warning ("AT-SPI: Cannot open default display");
48
      exit (1);
49
    }
50
28
  return default_display;
51
}
52

            
53
Display *
54
336
spi_get_display ()
55
{
56
336
  if (!default_display)
57
28
    spi_set_display (NULL);
58

            
59
336
  return default_display;
60
}
61

            
62
Window
63
56
spi_get_root_window ()
64
{
65
56
  if (!default_display)
66
    spi_set_display (NULL);
67

            
68
56
  return DefaultRootWindow (default_display);
69
}
70

            
71
static int (*old_x_error_handler) (Display *, XErrorEvent *);
72
static int x_error_code;
73

            
74
static int
75
spi_x_error_handler (Display *display, XErrorEvent *error)
76
{
77
  if (error->error_code)
78
    x_error_code = error->error_code;
79
  else
80
    x_error_code = 0;
81

            
82
  return 0;
83
}
84

            
85
void
86
28
spi_x_error_trap (void)
87
{
88
28
  old_x_error_handler = XSetErrorHandler (spi_x_error_handler);
89
28
}
90

            
91
int
92
28
spi_x_error_release (void)
93
{
94
28
  XSetErrorHandler (old_x_error_handler);
95
28
  return x_error_code;
96
}