fix: [draw] The application interface is unresponsive to clicks.

problem:
After switching screens using a KVM switch, there is a probability
that the application interface will become unresponsive to clicks.

analysis:
The valid size range supported by the Cairo surface is [0,32767].
If the width and height exceed this range, the surface's status is set
to CAIRO_STATUS_INVALID_SIZE, indicating an invalid size exception.
In this exception state, Cairo does not have a clipping region.

When determining whether the window needs to be drawn,
the function gdk_cairo_get_clip_rectangle() is used to check
if the cairo_t has a clipping region. If there is none, the window
and its child windows will not be drawn (i.e., the draw signal will not be emitted).

If an error occurs in the X server and a value exceeding Cairo's
valid size is provided in the ConfigureNotify, it will result in
the window and its child windows not being drawn.
Therefore, we will add range checks here to avoid this special situation.
This commit is contained in:
Gong Heng 2025-03-04 19:32:31 +08:00
parent 7bf902178f
commit 90390d6493

View File

@ -72,6 +72,8 @@
#include <X11/extensions/Xdamage.h>
#endif
#define XLIB_COORD_MAX 32767
const int _gdk_x11_event_mask_table[21] =
{
ExposureMask,
@ -193,6 +195,14 @@ _gdk_x11_window_update_size (GdkWindowImplX11 *impl)
{
if (impl->cairo_surface)
{
if (impl->unscaled_width < 0)
impl->unscaled_width = 0;
else if (impl->unscaled_width > XLIB_COORD_MAX)
impl->unscaled_width = XLIB_COORD_MAX;
if (impl->unscaled_height < 0)
impl->unscaled_height = 0;
else if (impl->unscaled_height > XLIB_COORD_MAX)
impl->unscaled_height = XLIB_COORD_MAX;
cairo_xlib_surface_set_size (impl->cairo_surface,
impl->unscaled_width, impl->unscaled_height);
}