2010-03-16 09:12:47 +00:00
|
|
|
/*
|
|
|
|
* gstvaapiutils_x11.c - X11 utilties
|
|
|
|
*
|
2012-01-16 09:41:10 +00:00
|
|
|
* Copyright (C) 2010-2011 Splitted-Desktop Systems
|
2010-03-16 09:12:47 +00:00
|
|
|
*
|
2011-06-14 11:51:41 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2.1
|
|
|
|
* of the License, or (at your option) any later version.
|
2010-03-16 09:12:47 +00:00
|
|
|
*
|
2011-06-14 11:51:41 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2010-03-16 09:12:47 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-06-14 11:51:41 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2010-03-16 09:12:47 +00:00
|
|
|
*
|
2011-06-14 11:51:41 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA
|
2010-03-16 09:12:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <glib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include "gstvaapiutils_x11.h"
|
|
|
|
|
|
|
|
// X error trap
|
|
|
|
static int x11_error_code = 0;
|
|
|
|
static int (*old_error_handler)(Display *, XErrorEvent *);
|
|
|
|
|
|
|
|
static int error_handler(Display *dpy, XErrorEvent *error)
|
|
|
|
{
|
|
|
|
x11_error_code = error->error_code;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void x11_trap_errors(void)
|
|
|
|
{
|
|
|
|
x11_error_code = 0;
|
|
|
|
old_error_handler = XSetErrorHandler(error_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
int x11_untrap_errors(void)
|
|
|
|
{
|
|
|
|
XSetErrorHandler(old_error_handler);
|
|
|
|
return x11_error_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
// X window management
|
|
|
|
static const int x11_event_mask = (KeyPressMask |
|
|
|
|
KeyReleaseMask |
|
|
|
|
ButtonPressMask |
|
|
|
|
ButtonReleaseMask |
|
|
|
|
PointerMotionMask |
|
|
|
|
EnterWindowMask |
|
|
|
|
ExposureMask |
|
|
|
|
StructureNotifyMask);
|
|
|
|
|
2010-03-25 13:54:06 +00:00
|
|
|
/**
|
|
|
|
* x11_create_window:
|
2010-03-25 17:18:06 +00:00
|
|
|
* @dpy: an X11 #Display
|
|
|
|
* @w: the requested width, in pixels
|
|
|
|
* @h: the requested height, in pixels
|
2010-03-25 13:54:06 +00:00
|
|
|
* @vis: the request visual
|
2010-03-25 17:18:06 +00:00
|
|
|
* @cmap: the request colormap
|
2010-03-25 13:54:06 +00:00
|
|
|
*
|
|
|
|
* Creates a border-less window with the specified dimensions. If @vis
|
2010-03-25 17:18:06 +00:00
|
|
|
* is %NULL, the default visual for @display will be used. If @cmap is
|
|
|
|
* %None, no specific colormap will be bound to the window. Also note
|
|
|
|
* the default background color is black.
|
2010-03-25 13:54:06 +00:00
|
|
|
*
|
|
|
|
* Return value: the newly created X #Window.
|
|
|
|
*/
|
2010-03-16 09:12:47 +00:00
|
|
|
Window
|
2010-03-25 17:18:06 +00:00
|
|
|
x11_create_window(Display *dpy, guint w, guint h, Visual *vis, Colormap cmap)
|
2010-03-16 09:12:47 +00:00
|
|
|
{
|
2010-03-25 17:18:06 +00:00
|
|
|
Window rootwin, win;
|
2010-03-16 09:12:47 +00:00
|
|
|
int screen, depth;
|
|
|
|
XSetWindowAttributes xswa;
|
|
|
|
unsigned long xswa_mask;
|
|
|
|
XWindowAttributes wattr;
|
2011-12-13 14:59:02 +00:00
|
|
|
unsigned long black_pixel;
|
2010-03-16 09:12:47 +00:00
|
|
|
|
2010-03-25 17:18:06 +00:00
|
|
|
screen = DefaultScreen(dpy);
|
|
|
|
rootwin = RootWindow(dpy, screen);
|
|
|
|
black_pixel = BlackPixel(dpy, screen);
|
2010-03-16 09:12:47 +00:00
|
|
|
|
2010-03-25 13:54:06 +00:00
|
|
|
if (!vis)
|
2010-03-25 17:18:06 +00:00
|
|
|
vis = DefaultVisual(dpy, screen);
|
2010-03-25 13:54:06 +00:00
|
|
|
|
2010-03-25 17:18:06 +00:00
|
|
|
XGetWindowAttributes(dpy, rootwin, &wattr);
|
2010-03-16 09:12:47 +00:00
|
|
|
depth = wattr.depth;
|
|
|
|
if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
|
|
|
|
depth = 24;
|
|
|
|
|
|
|
|
xswa_mask = CWBorderPixel | CWBackPixel;
|
|
|
|
xswa.border_pixel = black_pixel;
|
2010-03-23 17:29:47 +00:00
|
|
|
xswa.background_pixel = black_pixel;
|
2010-03-16 09:12:47 +00:00
|
|
|
|
2010-03-25 17:18:06 +00:00
|
|
|
if (cmap) {
|
|
|
|
xswa_mask |= CWColormap;
|
|
|
|
xswa.colormap = cmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
win = XCreateWindow(
|
|
|
|
dpy,
|
|
|
|
rootwin,
|
|
|
|
0, 0, w, h,
|
2010-03-16 09:12:47 +00:00
|
|
|
0,
|
|
|
|
depth,
|
|
|
|
InputOutput,
|
|
|
|
vis,
|
|
|
|
xswa_mask, &xswa
|
|
|
|
);
|
2010-03-25 17:18:06 +00:00
|
|
|
if (!win)
|
2010-03-16 09:12:47 +00:00
|
|
|
return None;
|
|
|
|
|
2010-03-25 17:18:06 +00:00
|
|
|
XSelectInput(dpy, win, x11_event_mask);
|
|
|
|
return win;
|
2010-03-16 09:12:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
x11_get_geometry(
|
|
|
|
Display *dpy,
|
|
|
|
Drawable drawable,
|
|
|
|
gint *px,
|
|
|
|
gint *py,
|
|
|
|
guint *pwidth,
|
|
|
|
guint *pheight
|
|
|
|
)
|
|
|
|
{
|
|
|
|
Window rootwin;
|
|
|
|
int x, y;
|
2010-03-18 08:02:25 +00:00
|
|
|
guint width, height, border_width, depth;
|
2010-03-16 09:12:47 +00:00
|
|
|
|
|
|
|
x11_trap_errors();
|
|
|
|
XGetGeometry(
|
|
|
|
dpy,
|
|
|
|
drawable,
|
|
|
|
&rootwin,
|
|
|
|
&x, &y, &width, &height,
|
|
|
|
&border_width,
|
|
|
|
&depth
|
|
|
|
);
|
|
|
|
if (x11_untrap_errors())
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (px) *px = x;
|
|
|
|
if (py) *py = y;
|
|
|
|
if (pwidth) *pwidth = width;
|
|
|
|
if (pheight) *pheight = height;
|
|
|
|
return TRUE;
|
|
|
|
}
|