~ubuntu-branches/ubuntu/trusty/vdpau-video/trusty-proposed

« back to all changes in this revision

Viewing changes to src/utils_x11.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2011-09-22 11:35:45 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20110922113545-037dkroelik2be0y
Tags: 0.7.3-0ubuntu1
New upstream version, fix FTBFS with libav 0.7. Closes: #614485, LP: #756021.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  utils_x11.h - X11 utilities
 
3
 *
 
4
 *  vdpau-video (C) 2009-2011 Splitted-Desktop Systems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
19
 */
 
20
 
 
21
#include "sysdeps.h"
 
22
#include <X11/Xutil.h>
 
23
#include "utils_x11.h"
 
24
#include "utils.h"
 
25
 
 
26
// X error trap
 
27
static int x11_error_code = 0;
 
28
static int (*old_error_handler)(Display *, XErrorEvent *);
 
29
 
 
30
static int error_handler(Display *dpy, XErrorEvent *error)
 
31
{
 
32
    x11_error_code = error->error_code;
 
33
    return 0;
 
34
}
 
35
 
 
36
void x11_trap_errors(void)
 
37
{
 
38
    x11_error_code    = 0;
 
39
    old_error_handler = XSetErrorHandler(error_handler);
 
40
}
 
41
 
 
42
int x11_untrap_errors(void)
 
43
{
 
44
    XSetErrorHandler(old_error_handler);
 
45
    return x11_error_code;
 
46
}
 
47
 
 
48
int
 
49
x11_get_geometry(
 
50
    Display      *dpy,
 
51
    Drawable      drawable,
 
52
    int          *px,
 
53
    int          *py,
 
54
    unsigned int *pwidth,
 
55
    unsigned int *pheight
 
56
)
 
57
{
 
58
    Window rootwin;
 
59
    int x, y;
 
60
    unsigned int width, height, border_width, depth;
 
61
 
 
62
    x11_trap_errors();
 
63
    XGetGeometry(
 
64
        dpy,
 
65
        drawable,
 
66
        &rootwin,
 
67
        &x, &y, &width, &height,
 
68
        &border_width,
 
69
        &depth
 
70
    );
 
71
    if (x11_untrap_errors())
 
72
        return 0;
 
73
 
 
74
    if (px)      *px      = x;
 
75
    if (py)      *py      = y;
 
76
    if (pwidth)  *pwidth  = width;
 
77
    if (pheight) *pheight = height;
 
78
    return 1;
 
79
}