summaryrefslogtreecommitdiffstats
path: root/utils/xdbe.c
blob: d62183efa7748cc4b38b2ddc1c23c4f6b682f83b (plain) (blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* xscreensaver, Copyright (c) 1998, 1999, 2006
 *  by Jamie Zawinski <jwz@jwz.org>
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation.  No representations are made about the suitability of this
 * software for any purpose.  It is provided "as is" without express or 
 * implied warranty.
 */

/* The XDBE (Double Buffering) extension is pretty tricky to use, since you
   can get X errors at inconvenient times during initialization.  This file
   contains a utility routine to make it easier to deal with.
 */

#include "utils.h"
#include "xdbe.h"
#include "resources.h"		/* for get_string_resource() */

/* #define DEBUG */

#ifdef DEBUG
# include <X11/Xmu/Error.h>
#endif

extern char *progname;

#ifdef HAVE_DOUBLE_BUFFER_EXTENSION	/* whole file */

static Bool xdbe_got_x_error = False;
static int
xdbe_ehandler (Display *dpy, XErrorEvent *error)
{
  xdbe_got_x_error = True;

#ifdef DEBUG
  fprintf (stderr, "\n%s: ignoring X error from DOUBLE-BUFFER:\n", progname);
  XmuPrintDefaultErrorMessage (dpy, error, stderr);
  fprintf (stderr, "\n");
#endif

  return 0;
}


XdbeBackBuffer 
xdbe_get_backbuffer (Display *dpy, Window window,
                     XdbeSwapAction action)
{
  XdbeBackBuffer b;
  XErrorHandler old_handler;
  int maj, min;

  if (!get_boolean_resource(dpy, "useDBE", "Boolean"))
    return 0;

  if (!XdbeQueryExtension (dpy, &maj, &min))
    return 0;

  XSync (dpy, False);
  xdbe_got_x_error = False;
  old_handler = XSetErrorHandler (xdbe_ehandler);
  b = XdbeAllocateBackBufferName(dpy, window, XdbeUndefined);
  XSync (dpy, False);
  XSetErrorHandler (old_handler);

  if (xdbe_got_x_error)
    return 0;

  return b;
}

#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */