summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon TURNEY <jon.turney@dronecode.org.uk>2013-06-29 16:34:55 +0100
committerJon TURNEY <jon.turney@dronecode.org.uk>2013-07-06 12:09:30 +0100
commited1d6509594a9d3490f734f92c36f7c386dd1e8d (patch)
tree44bbb2206a22952f8758cb627ffc67662f22adf6
parent6248c51507839a753823a37dacac6b66ddbdc1d1 (diff)
Factor out common code as xcwm_image_copy_partial()
Factor out common code from xcwm_image_copy_full() and xcwm_image_copy_damaged() as xcwm_image_copy_partial()
-rw-r--r--include/xcwm/image.h9
-rw-r--r--src/libxcwm/image.c90
2 files changed, 52 insertions, 47 deletions
diff --git a/include/xcwm/image.h b/include/xcwm/image.h
index a425458..b69203a 100644
--- a/include/xcwm/image.h
+++ b/include/xcwm/image.h
@@ -64,6 +64,15 @@ xcwm_image_t *
xcwm_image_copy_damaged(xcwm_window_t *window);
/**
+ * Returns a part of a window's image
+ * @param window The window to get image from.
+ * @param area The area of the window to get image from.
+ * @return an xcwm_image_t with an the image of a window
+ */
+xcwm_image_t *
+xcwm_image_copy_partial (xcwm_window_t *window, xcwm_rect_t *area);
+
+/**
* Free the memory used by an xcwm_image_t created
* during a call to xcwm_image_get_*.
* @param image The image to be freed.
diff --git a/src/libxcwm/image.c b/src/libxcwm/image.c
index e762716..cb5ca26 100644
--- a/src/libxcwm/image.c
+++ b/src/libxcwm/image.c
@@ -33,31 +33,27 @@
#include <xcb/xcb_image.h>
#include "xcwm_internal.h"
-
xcwm_image_t *
-xcwm_image_copy_full(xcwm_window_t *window)
+xcwm_image_copy_partial(xcwm_window_t *window, xcwm_rect_t *area)
{
-
- xcb_get_geometry_reply_t *geom_reply;
xcb_image_t *image;
- geom_reply = _xcwm_get_window_geometry(window->context->conn,
- window->window_id);
-
- if (!geom_reply)
+ /* Return null if image is 0 by 0 */
+ if (area->width == 0 || area->height == 0) {
return NULL;
+ }
- xcb_flush(window->context->conn);
- /* Get the full image of the window */
+ /* Get the image of the specified area of the window */
image = xcb_image_get(window->context->conn,
window->composite_pixmap_id,
- 0,
- 0,
- geom_reply->width,
- geom_reply->height,
+ area->x,
+ area->y,
+ area->width,
+ area->height,
(unsigned int)~0L,
XCB_IMAGE_FORMAT_Z_PIXMAP);
+ /* Failed to get a valid image, return null */
if (!image) {
return NULL;
}
@@ -65,59 +61,59 @@ xcwm_image_copy_full(xcwm_window_t *window)
xcwm_image_t * xcwm_image = malloc(sizeof(xcwm_image_t));
xcwm_image->image = image;
- xcwm_image->x = geom_reply->x;
- xcwm_image->y = geom_reply->y;
- xcwm_image->width = geom_reply->width;
- xcwm_image->height = geom_reply->height;
-
- free(geom_reply);
+ xcwm_image->x = area->x;
+ xcwm_image->y = area->y;
+ xcwm_image->width = area->width;
+ xcwm_image->height = area->height;
return xcwm_image;
}
xcwm_image_t *
-xcwm_image_copy_damaged(xcwm_window_t *window)
+xcwm_image_copy_full(xcwm_window_t *window)
{
- xcb_image_t *image;
+ xcb_get_geometry_reply_t *geom_reply;
- xcb_flush(window->context->conn);
+ geom_reply = _xcwm_get_window_geometry(window->context->conn,
+ window->window_id);
- /* Return null if image is 0 by 0 */
- if (window->dmg_bounds.width == 0 || window->dmg_bounds.height == 0) {
+ if (!geom_reply)
return NULL;
- }
- /* Get the image of the damaged area of the window */
- image = xcb_image_get(window->context->conn,
- window->composite_pixmap_id,
- window->dmg_bounds.x,
- window->dmg_bounds.y,
- window->dmg_bounds.width,
- window->dmg_bounds.height,
- (unsigned int)~0L,
- XCB_IMAGE_FORMAT_Z_PIXMAP);
+ xcb_flush(window->context->conn);
- /* Failed to get a valid image, return null */
- if (!image) {
- return NULL;
- }
+ xcwm_rect_t area;
+ area.x = 0;
+ area.y = 0;
+ area.width = geom_reply->width;
+ area.height = geom_reply->height;
- xcwm_image_t * xcwm_image = malloc(sizeof(xcwm_image_t));
+ /* Get the full image of the window */
+ xcwm_image_t *xcwm_image = xcwm_image_copy_partial(window, &area);
- xcwm_image->image = image;
- xcwm_image->x = window->dmg_bounds.x;
- xcwm_image->y = window->dmg_bounds.y;
- xcwm_image->width = window->dmg_bounds.width;
- xcwm_image->height = window->dmg_bounds.height;
+ /* The x and y position of the window (unused, but historical) */
+ if (xcwm_image) {
+ xcwm_image->x = geom_reply->x;
+ xcwm_image->y = geom_reply->y;
+ }
+
+ free(geom_reply);
return xcwm_image;
}
+xcwm_image_t *
+xcwm_image_copy_damaged(xcwm_window_t *window)
+{
+ xcb_flush(window->context->conn);
+
+ /* Get the image of the damaged area of the window */
+ return xcwm_image_copy_partial(window, &(window->dmg_bounds));
+}
+
void
xcwm_image_destroy(xcwm_image_t * image)
{
-
xcb_image_destroy(image->image);
free(image);
}
-