Check zalloc return for out of memory situation

Most zalloc calls in weston are checked, this fixes a handful that were
being ignored.  As found by `grep -EIsr "[^x]zalloc\(" . -A1`

Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
xwayland: Check zalloc return for out of memory situation

Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
Use the correct width/height when transforming surfaces with viewports.

Previously, because of the wrong width/height,
weston_surface_to_buffer_* would return the wrong values when
wl_viewport was used in combination with wl_surface.set_buffer_transform.

Reviewed-by: Pekka Paalanen <ppaalanen@gmail.com>
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
pixman-renderer: Use width/height_from_buffer for buffer transforms

This fixes an issue in the pixman renderer where it would not render
surfaces correctly if both wl_viewport and wl_surface.set_buffer_transform
were used.

Reviewed-by: Pekka Paalanen <ppaalanen@gmail.com>
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
libinput: Don't process touch events for devices without a valid output

That would be the case of a touch screen mapped to an output that was
unplugged.
evdev: Discard events from a touchscreen paired with an unplugged output

Commit 17bccaed intended to make the events coming from a touchscreen
paired with an unplugged output to be discarded, while an unpaired one
would just choose a different output. However, the logic was inverted
causing the opposite to happen.

Later in commit 161c6c56, the default behavior was changed to map an
output to a default output if the one specified via udev is not
present. This change is reverted by this patch.

v2: undo the change from commit 161c6c56.

v3: deal with libinput too.
evdev: Fix assertion error for unplugged output with paired touchscreen

If the output a touchscreen is paired to is unplugged, events coming
from it should be ignored. Commit 17bccaed introduced logic for that
in evdev_flush_pending_damage(). However, the break statements it
introduced would cause the assertion after the switch statement to
fail.

That function has the odd behavior that goto's are used to skip the
assertion after the switch statement and jump to the hunk of code that
marks the event as processed. Only in the case where the event type has
an invalid value the assertion should trigger. So this patch fixes the
problem by moving the assertion into the default case of the switch
and replacing the goto statements with break ones.

https://bugs.freedesktop.org/show_bug.cgi?id=73950
input: Fix errors due to initializing input before creating outputs

Make sure that we don't map a device to an invalid output pointer and
intead remap devices when an output is created.

v2: fix the error with libinput too.
clients/window: Don't remove the touch listener on a frame event

It looks like the handler for frame events from the wl_touch interface for
widgets may have been erroneously copied from the cancel handler so that it
removes all handlers as they are processed. I don't think this makes much sense
for the frame event. This was stopping the panel icons from being pushable with
touch events when using libinput since commit 1679f232e541489e. All that commit
does it make it start sending the frame events.
Simply the matrix calculation for zooming

In order to apply the zoom transformation to the output matrix, Weston was
doing the following:

• Create a temporary matrix to hold the translation
• Invert the translation matrix using weston_matrix_invert into
  another temporary matrix
• Scale that matrix by the scale factor
• Multiply the current matrix with the temporary matrix

Using weston_matrix_invert to invert a translation matrix is over the top.
Instead we can just negate the values we pass to weston_matrix_translate.
Matrix multiplication is associative so creating a temporary matrix to hold the
scale and translation transform should be equivalent to just applying them
directly to the output matrix.
terminal: Convert all *alloc's to x*alloc's.

This ensures the allocation results are checked for NULL (out of
memory), and terminates the program in such a case.

Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
shell: Fix memory leaks caused by the window close animation

In order to do the window close animation, a reference for a destroyed
surface is kept. However, the reference count was also increased for
unmapped surfaces, in which case the animation wouldn't run. Since the
reference count was decremented in the animation done function, it would
never be decreased for unmapped surfaces, causing them to not be
released.

The close animation also changed how shell surfaces are released. The
destroy function for its resource was changed to not deallocate the
surface, and instead keep it around until the animation finishes and
the weston surface is destroyed. The destruction should happen in the
destroy listener for the weston surface, but it wouldn't destroy the
shell surface in the case the resource was still valid, assuming that
it would be freed in the resource destroy function.
shell: Fix crash when a client is destroyed during the resize grab

If a client exists during a resize grab, the resource for the shell
surface being resized is destroyed. The shell surface is not destroyed
immediately, however, because of the window close animation. In that
case, the compositor would crash trying to send configure events to
the surface being resized, since it would pass a NULL pointer to
wl_resource_post_event().

The code for the resize grab was already able to handle the surface
going away, so expand it to also handle the resource going away and
fix the crash.

https://bugs.freedesktop.org/show_bug.cgi?id=77344
window.c: Update pointer focus when taking a grab
window.c: Prevent key event delivery while a grab is active

Ideally, we'll update the key event handling to deliver events to widgets,
but in the meantime, just blocking key event delivery while a grab is
active goes a long way.
window.c: Also grab touch events when grabbing input
window.c: Dismiss menu on touch up events
desktop-shell: Reject window move in common_surface_move()

We move the check for shsurf->grabbed from surface_move() and
surface_touch_move() up top common_surface_move()
desktop-shell: Reject resize if we're already grabbed

This rejects resizing a window that's currently being moved.  This can
be done using a touch screen and a pointer or just two seats.
desktop-shell: End popup when starting a touch shell grab

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=77345