diff options
author | Paulo Cesar Pereira de Andrade <pcpa@mandriva.com.br> | 2008-07-29 14:18:10 -0300 |
---|---|---|
committer | Paulo Cesar Pereira de Andrade <pcpa@mandriva.com.br> | 2008-07-29 14:18:10 -0300 |
commit | a3e1a9b4cb732b86b84375013e3fa531395b45cf (patch) | |
tree | 0ad434c72a83fda1a84cfd044abeb163c3cc4b68 | |
parent | cb21acd94353c82c4b49a7ddef99309b31b07500 (diff) |
Properly handle multiple depth windows.
This patch will not cause X Errors when magnifying windows with portions
offscreen, or windows with a dimension smaller than the default 64x64.
A common case where this patch is required is when Composite is enabled,
the default depth has a value other than 24, and some application is
using the Composite argb visual; example is WindowMaker, that will choose
the "best" available visual, unless the visual-id option is used.
-rw-r--r-- | xmag.c | 106 |
1 files changed, 71 insertions, 35 deletions
@@ -52,6 +52,10 @@ from The Open Group. #define min(a, b) ((a) < (b) ? (a) : (b)) #endif +#ifndef max +#define max(a, b) ((a) > (b) ? (a) : (b)) +#endif + /* highlight interval (in milliseconds) */ @@ -763,41 +767,73 @@ static void GetImageAndAttributes(Window w, int x, int y, int width, int height, hlPtr data) { - /* get parameters of window being magnified */ - XGetWindowAttributes(dpy, w, &data->win_info); - - if (data->win_info.depth == DefaultDepth(dpy, scr)) { - /* avoid off screen pixels */ - if (x < 0) x = 0; if (y < 0) y = 0; - if (x + width > DisplayWidth(dpy,scr)) x = DisplayWidth(dpy,scr) - width; - if (y + height > DisplayHeight(dpy,scr)) - y = DisplayHeight(dpy,scr) - height; - data->x = x; data->y = y; - /* get image pixels */ - data->image = XGetImage (dpy, - RootWindow(dpy, scr), - x, y, - width, height, - AllPlanes, ZPixmap); - } - else { - int xInWin, yInWin; Window childWin; - XTranslateCoordinates(dpy, DefaultRootWindow(dpy), w, x, y, - &xInWin, &yInWin, &childWin); - /* avoid off screen pixels */ - if (x + data->win_info.x < 0) x = abs(data->win_info.x); - if (y + data->win_info.y < 0) y = abs(data->win_info.y); - if (x + width > DisplayWidth(dpy,scr)) x = DisplayWidth(dpy,scr) - width; - if (y + height > DisplayHeight(dpy,scr)) - y = DisplayHeight(dpy,scr) - height; - data->x = x; data->y = y; - data->image = XGetImage (dpy, - w, - xInWin, yInWin, - width, height, - AllPlanes, ZPixmap); - - } + /* get parameters of window being magnified */ + XGetWindowAttributes(dpy, w, &data->win_info); + + if (data->win_info.depth == DefaultDepth(dpy, scr)) { + /* avoid off screen pixels */ + if (x < 0) + x = 0; + if (y < 0) + y = 0; + if (x + width > DisplayWidth(dpy,scr)) + x = DisplayWidth(dpy,scr) - width; + if (y + height > DisplayHeight(dpy,scr)) + y = DisplayHeight(dpy,scr) - height; + data->x = x; data->y = y; + /* get image pixels */ + data->image = XGetImage (dpy, + RootWindow(dpy, scr), + x, y, + width, height, + AllPlanes, ZPixmap); + } + else { + int t0, t1; + int x0, x1, y0, y1; + int xInWin, yInWin; + Window childWin; + + XTranslateCoordinates(dpy, DefaultRootWindow(dpy), w, x, y, + &xInWin, &yInWin, &childWin); + + /* Avoid off screen pixels. Assume this routine is not + * called for totally offscreen windows. */ + x0 = max(x, 0); + y0 = max(y, 0); + x1 = min(DisplayWidth(dpy, scr), + min(x0 + width, x0 + (data->win_info.width - xInWin))); + y1 = min(DisplayHeight(dpy, scr), + min(y0 + height, y0 + (data->win_info.height - yInWin))); + + /* Try to use up to width x height pixels */ + if (x1 - x0 < width) { + t0 = x0; + t1 = max(0, x - xInWin + data->win_info.width - + DisplayWidth(dpy, scr)); + x0 = max(0, x1 - min(width, data->win_info.width - t1)); + xInWin -= t0 - x0; + } + if (y1 - y0 < height) { + t0 = y0; + t1 = max(0, y - yInWin + data->win_info.height - + DisplayHeight(dpy, scr)); + y0 = max(0, y1 - min(height, data->win_info.height - t1)); + yInWin -= t0 - y0; + } + + data->x = x0; + data->y = y0; + data->width = x1 - x0; + data->height = y1 - y0; + + data->image = XGetImage (dpy, + w, + xInWin, yInWin, + data->width, data->height, + AllPlanes, ZPixmap); + + } } |