From 7c52a3cf5243b42b632fd73789d1b484e81b9b0c Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 22 Aug 2013 15:07:48 +0100 Subject: overlay: Rudiments of config files and option parsing Signed-off-by: Chris Wilson --- overlay/x11/position.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++ overlay/x11/position.h | 38 ++++++++++++++ overlay/x11/x11-overlay.c | 56 +++++++------------- overlay/x11/x11-window.c | 41 ++------------- 4 files changed, 192 insertions(+), 74 deletions(-) create mode 100644 overlay/x11/position.c create mode 100644 overlay/x11/position.h (limited to 'overlay/x11') diff --git a/overlay/x11/position.c b/overlay/x11/position.c new file mode 100644 index 00000000..0dcfc8de --- /dev/null +++ b/overlay/x11/position.c @@ -0,0 +1,131 @@ +/* + * Copyright © 2013 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + */ + +#include +#include +#include + +#include "position.h" +#include "../overlay.h" + +static enum position get_position(struct config *config) +{ + const char *v = config_get_value(config, "window", "position"); + if (v == NULL) + return POS_UNSET; + + if (strcmp(v, "top-left") == 0) + return POS_TOP_LEFT; + + if (strcmp(v, "top-centre") == 0) + return POS_TOP_CENTRE; + + if (strcmp(v, "top-right") == 0) + return POS_TOP_RIGHT; + + if (strcmp(v, "middle-left") == 0) + return POS_MIDDLE_LEFT; + + if (strcmp(v, "middle-centre") == 0) + return POS_MIDDLE_CENTRE; + + if (strcmp(v, "middle-right") == 0) + return POS_MIDDLE_RIGHT; + + if (strcmp(v, "bottom-left") == 0) + return POS_BOTTOM_LEFT; + + if (strcmp(v, "bottom-centre") == 0) + return POS_BOTTOM_CENTRE; + + if (strcmp(v, "bottom-right") == 0) + return POS_BOTTOM_RIGHT; + + return POS_UNSET; +} + +enum position +x11_position(Screen *scr, int width, int height, + struct config *config, + int *x, int *y, int *w, int *h) +{ + enum position position = POS_UNSET; + const char *geometry; + + *x = *y = 0; + *w = width; + *h = height; + + geometry = config_get_value(config, "window", "geometry"); + if (geometry) { + sscanf(geometry, "%dx%d+%d+%d", w, h, x, y); + if (*w < width) + *w = width; + if (*h < height) + *h = height; + } else { + position = get_position(config); + if (position != POS_UNSET) { + if (width == -1) { + *w = scr->width; + switch (position & 7) { + default: + case 0: + case 2: *w >>= 1; break; + } + } else if (width > scr->width) { + *w = scr->width; + } else + *w = width; + + if (height == -1) { + *h = scr->height; + switch ((position >> 4) & 7) { + default: + case 0: + case 2: *h >>= 1; break; + } + } else if (height > scr->height) + *h = scr->height; + else + *h = height; + + switch (position & 7) { + default: + case 0: *x = 0; break; + case 1: *x = (scr->width - *w)/2; break; + case 2: *x = scr->width - *w; break; + } + + switch ((position >> 4) & 7) { + default: + case 0: *y = 0; break; + case 1: *y = (scr->height - *h)/2; break; + case 2: *y = scr->height - *h; break; + } + } + } + + return position; +} diff --git a/overlay/x11/position.h b/overlay/x11/position.h new file mode 100644 index 00000000..6221109f --- /dev/null +++ b/overlay/x11/position.h @@ -0,0 +1,38 @@ +/* + * Copyright © 2013 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + */ + +#ifndef X11_POSITION_H +#define X11_POSITION_H + +#include + +struct config; +enum position; + +enum position +x11_position(Screen *scr, int width, int height, + struct config *config, + int *x, int *y, int *w, int *h); + +#endif /* X11_POSITION_H */ diff --git a/overlay/x11/x11-overlay.c b/overlay/x11/x11-overlay.c index c2693d38..f57bd55d 100644 --- a/overlay/x11/x11-overlay.c +++ b/overlay/x11/x11-overlay.c @@ -38,6 +38,7 @@ #include #include "../overlay.h" #include "dri2.h" +#include "position.h" #include "rgb2yuv.h" #ifndef ALIGN @@ -142,7 +143,7 @@ static void x11_overlay_destroy(void *data) } cairo_surface_t * -x11_overlay_create(enum position position, int *width, int *height) +x11_overlay_create(struct config *config, int *width, int *height) { Display *dpy; Screen *scr; @@ -152,11 +153,12 @@ x11_overlay_create(enum position position, int *width, int *height) struct drm_i915_gem_mmap_gtt map; struct x11_overlay *priv; unsigned int count, i, j; - int fd, w, h; + int fd, x, y, w, h; XvAdaptorInfo *info; XvImage *image; XvPortID port = -1; void *ptr, *mem; + enum position position; dpy = XOpenDisplay(NULL); if (dpy == NULL) @@ -195,29 +197,7 @@ x11_overlay_create(enum position position, int *width, int *height) XSetErrorHandler(noop); - if (*width == -1) { - w = scr->width; - switch (position & 7) { - default: - case 0: - case 2: w >>= 1; break; - } - } else if (*width > scr->width) { - w = scr->width; - } else - w = *width; - - if (*height == -1) { - h = scr->height; - switch ((position >> 4) & 7) { - default: - case 0: - case 2: h >>= 1; break; - } - } else if (*height > scr->height) - h = scr->height; - else - h = *height; + position = x11_position(scr, *width, *height, config, &x, &y, &w, &h); image = XvCreateImage(dpy, port, FOURCC_RGB565, NULL, w, h); if (image == NULL) @@ -308,18 +288,22 @@ x11_overlay_create(enum position position, int *width, int *height) priv->name = flink.name; priv->visible = false; - switch (position & 7) { - default: - case 0: priv->x = 0; break; - case 1: priv->x = (scr->width - image->width)/2; break; - case 2: priv->x = scr->width - image->width; break; - } + priv->x = x; + priv->y = y; + if (position != POS_UNSET) { + switch (position & 7) { + default: + case 0: priv->x = 0; break; + case 1: priv->x = (scr->width - image->width)/2; break; + case 2: priv->x = scr->width - image->width; break; + } - switch ((position >> 4) & 7) { - default: - case 0: priv->y = 0; break; - case 1: priv->y = (scr->height - image->height)/2; break; - case 2: priv->y = scr->height - image->height; break; + switch ((position >> 4) & 7) { + default: + case 0: priv->y = 0; break; + case 1: priv->y = (scr->height - image->height)/2; break; + case 2: priv->y = scr->height - image->height; break; + } } diff --git a/overlay/x11/x11-window.c b/overlay/x11/x11-window.c index b77f5375..7f7d6d72 100644 --- a/overlay/x11/x11-window.c +++ b/overlay/x11/x11-window.c @@ -32,6 +32,7 @@ #include #include "../overlay.h" +#include "position.h" struct x11_window { struct overlay base; @@ -109,7 +110,7 @@ static void x11_window_destroy(void *data) } cairo_surface_t * -x11_window_create(enum position position, int *width, int *height) +x11_window_create(struct config *config, int *width, int *height) { Display *dpy; Screen *scr; @@ -129,43 +130,7 @@ x11_window_create(enum position position, int *width, int *height) XSetErrorHandler(noop); - if (*width == -1) { - w = scr->width; - switch (position & 7) { - default: - case 0: - case 2: w >>= 1; break; - } - } else if (*width > scr->width) { - w = scr->width; - } else - w = *width; - - if (*height == -1) { - h = scr->height; - switch ((position >> 4) & 7) { - default: - case 0: - case 2: h >>= 1; break; - } - } else if (*height > scr->height) - h = scr->height; - else - h = *height; - - switch (position & 7) { - default: - case 0: x = 0; break; - case 1: x = (scr->width - w)/2; break; - case 2: x = scr->width - w; break; - } - - switch ((position >> 4) & 7) { - default: - case 0: y = 0; break; - case 1: y = (scr->height - h)/2; break; - case 2: y = scr->height - h; break; - } + x11_position(scr, *width, *height, config, &x, &y, &w, &h); attr.override_redirect = True; win = XCreateWindow(dpy, DefaultRootWindow(dpy), -- cgit v1.2.3