Track the X Shape input region and use it for picking

We now track whether a window has an input shape specified via the X
Shape extension. Intersecting that with the bounding shape (as required
by the X Shape extension) we use the resulting rectangles to paint
window silhouettes when picking. As well as improving the correctness of
picking this should also be much more efficient because typically when
only picking solid rectangles then the need to actually render and issue
a read_pixels request can be optimized away and instead the picking is
done on the cpu.
This commit is contained in:
Robert Bragg
2012-01-19 01:20:02 +00:00
committed by Jasper St. Pierre
parent f0c503b5a9
commit 531be6c413
6 changed files with 257 additions and 61 deletions

View File

@ -2283,6 +2283,33 @@ event_callback (XEvent *event,
window->desc);
}
if (display->compositor)
meta_compositor_window_shape_changed (display->compositor,
window);
}
else if (sev->kind == ShapeInput)
{
if (sev->shaped && !window->has_input_shape)
{
window->has_input_shape = TRUE;
meta_topic (META_DEBUG_SHAPES,
"Window %s now has an input shape\n",
window->desc);
}
else if (!sev->shaped && window->has_input_shape)
{
window->has_input_shape = FALSE;
meta_topic (META_DEBUG_SHAPES,
"Window %s no longer has an input shape\n",
window->desc);
}
else
{
meta_topic (META_DEBUG_SHAPES,
"Window %s input shape changed\n",
window->desc);
}
if (display->compositor)
meta_compositor_window_shape_changed (display->compositor,
window);

View File

@ -325,8 +325,10 @@ struct _MetaWindow
guint using_net_wm_icon_name : 1; /* vs. plain wm_icon_name */
guint using_net_wm_visible_icon_name : 1; /* tracked so we can clear it */
/* has a shape mask */
/* has a bounding shape mask */
guint has_shape : 1;
/* has an input shape mask */
guint has_input_shape : 1;
/* icon props have changed */
guint need_reread_icon : 1;

View File

@ -826,6 +826,7 @@ meta_window_new_with_attrs (MetaDisplay *display,
gulong event_mask;
MetaMoveResizeFlags flags;
gboolean has_shape;
gboolean has_input_shape;
MetaScreen *screen;
g_assert (attrs != NULL);
@ -960,12 +961,15 @@ meta_window_new_with_attrs (MetaDisplay *display,
}
has_shape = FALSE;
has_input_shape = FALSE;
#ifdef HAVE_SHAPE
if (META_DISPLAY_HAS_SHAPE (display))
{
int x_bounding, y_bounding, x_clip, y_clip;
unsigned w_bounding, h_bounding, w_clip, h_clip;
int bounding_shaped, clip_shaped;
XRectangle *input_rectangles;
int n_rects, ordering;
XShapeSelectInput (display->xdisplay, xwindow, ShapeNotifyMask);
@ -977,6 +981,27 @@ meta_window_new_with_attrs (MetaDisplay *display,
has_shape = bounding_shaped != FALSE;
/* XXX: The x shape extension doesn't provide a way to only test if an
* input shape has been specified, so we have to query and throw away the
* rectangles. */
meta_error_trap_push (display);
input_rectangles = XShapeGetRectangles (display->xdisplay, xwindow,
ShapeInput, &n_rects, &ordering);
meta_error_trap_pop (display);
if (input_rectangles)
{
if (n_rects > 1 ||
(n_rects == 1 &&
(input_rectangles[0].x != x_bounding ||
input_rectangles[1].y != y_bounding ||
input_rectangles[2].width != w_bounding ||
input_rectangles[3].height != h_bounding)))
{
has_input_shape = TRUE;
}
XFree (input_rectangles);
}
meta_topic (META_DEBUG_SHAPES,
"Window has_shape = %d extents %d,%d %u x %u\n",
has_shape, x_bounding, y_bounding,
@ -1042,6 +1067,7 @@ meta_window_new_with_attrs (MetaDisplay *display,
meta_stack_freeze (window->screen->stack);
window->has_shape = has_shape;
window->has_input_shape = has_input_shape;
window->rect.x = attrs->x;
window->rect.y = attrs->y;