---
name: "wayland_viewport_t"
section: "3"
platform: "linux"
package: "waylandpp-dev"
version: "1.0.0-6+b2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/wayland_viewport_t"
---

# wayland\_viewport\_t(3)

crop and scale interface to a wl\_surface

## NAME

wayland::viewport\_t - crop and scale interface to a wl\_surface

## SYNOPSIS

`#include <wayland-client-protocol-extra.hpp>`

Inherits **wayland::proxy\_t**.

### Public Types

enum class **wrapper\_type** { **standard**, **display**, **foreign**, **proxy\_wrapper** }\

### Public Member Functions

void **set\_source** (double x, double y, double width, double height)\
 set the source rectangle for cropping  void **set\_destination** (int32\_t width, int32\_t height)\
 set the surface size for scaling  uint32\_t **get\_id** () const\
 Get the id of a proxy object.  std::string **get\_class** () const\
 Get the interface name (class) of a proxy object.  uint32\_t **get\_version** () const\
 Get the protocol object version of a proxy object.  **wrapper\_type** **get\_wrapper\_type** () const\
 Get the type of a proxy object.  void **set\_queue** (**event\_queue\_t** queue)\
 Assign a proxy to an event queue.  wl\_proxy \* **c\_ptr** () const\
 Get a pointer to the underlying C struct.  bool **proxy\_has\_object** () const\
 Check whether this wrapper actually wraps an object.  **operator bool** () const\
 Check whether this wrapper actually wraps an object.  bool **operator==** (const **proxy\_t** &right) const\
 Check whether two wrappers refer to the same object.  bool **operator!=** (const **proxy\_t** &right) const\
 Check whether two wrappers refer to different objects.  void **proxy\_release** ()\
 Release the wrapped object (if any), making this an empty wrapper.

### Static Public Attributes

static constexpr std::uint32\_t **set\_source\_since\_version** = 1\
 Minimum protocol version required for the **set\_source** function.  static constexpr std::uint32\_t **set\_destination\_since\_version** = 1\
 Minimum protocol version required for the **set\_destination** function.

## Detailed Description

crop and scale interface to a wl\_surface

An additional interface to a wl\_surface object, which allows the client to specify the cropping and scaling of the surface contents.

This interface works with two concepts: the source rectangle (src\_x, src\_y, src\_width, src\_height), and the destination size (dst\_width, dst\_height). The contents of the source rectangle are scaled to the destination size, and content outside the source rectangle is ignored. This state is double-buffered, and is applied on the next wl\_surface.commit.

The two parts of crop and scale state are independent: the source rectangle, and the destination size. Initially both are unset, that is, no scaling is applied. The whole of the current wl\_buffer is used as the source, and the surface size is as defined in wl\_surface.attach.

If the destination size is set, it causes the surface size to become dst\_width, dst\_height. The source (rectangle) is scaled to exactly this size. This overrides whatever the attached wl\_buffer size is, unless the wl\_buffer is NULL. If the wl\_buffer is NULL, the surface has no content and therefore no size. Otherwise, the size is always at least 1x1 in surface local coordinates.

If the source rectangle is set, it defines what area of the wl\_buffer is taken as the source. If the source rectangle is set and the destination size is not set, then src\_width and src\_height must be integers, and the surface size becomes the source rectangle size. This results in cropping without scaling. If src\_width or src\_height are not integers and destination size is not set, the bad\_size protocol error is raised when the surface state is applied.

The coordinate transformations from buffer pixel coordinates up to the surface-local coordinates happen in the following order:

- 1\.

  buffer\_transform (wl\_surface.set\_buffer\_transform)

- 2\.

  buffer\_scale (wl\_surface.set\_buffer\_scale)

- 3\.

  crop and scale (wp\_viewport.set\*) This means, that the source rectangle coordinates of crop and scale are given in the coordinates after the buffer transform and scale, i.e. in the coordinates that would be the surface-local coordinates if the crop and scale was not applied.

If src\_x or src\_y are negative, the bad\_value protocol error is raised. Otherwise, if the source rectangle is partially or completely outside of the non-NULL wl\_buffer, then the out\_of\_buffer protocol error is raised when the surface state is applied. A NULL wl\_buffer does not raise the out\_of\_buffer error.

The x, y arguments of wl\_surface.attach are applied as normal to the surface. They indicate how many pixels to remove from the surface size from the left and the top. In other words, they are still in the surface-local coordinate system, just like dst\_width and dst\_height are.

If the wl\_surface associated with the wp\_viewport is destroyed, all wp\_viewport requests except 'destroy' raise the protocol error no\_surface.

If the wp\_viewport object is destroyed, the crop and scale state is removed from the wl\_surface. The change will be applied on the next wl\_surface.commit.

Definition at line **436** of file **wayland-client-protocol-extra.hpp**.

## Member Enumeration Documentation

### enum class wayland::proxy\_t::wrapper\_type` [strong]`, ` [inherited]`

Underlying wl\_proxy type and properties of a **proxy\_t** that affect construction, destruction, and event handling

**Enumerator**

- *standard*

  *C pointer is a standard type compatible with wl\_proxy\*. Events are dispatched and it is destructed when the* **proxy\_t** *is destructed. User data is set.*

- *display*

  *C pointer is a wl\_display\*. No events are dispatched, wl\_display\_disconnect is called when the* **proxy\_t** *is destructed. User data is set.*

- *foreign*

  *C pointer is a standard type compatible with wl\_proxy\*, but another library owns it and it should not be touched in a way that could affect the operation of the other library. No events are dispatched, wl\_proxy\_destroy is not called when the* **proxy\_t** *is destructed, user data is not touched. Consequently, there is no reference counting for the* **proxy\_t***. Lifetime of such wrappers should preferably be short to minimize the chance that the owning library decides to destroy the wl\_proxy.*

- *proxy\_wrapper*

  *C pointer is a wl\_proxy\* that was constructed with wl\_proxy\_create\_wrapper. No events are dispatched, wl\_proxy\_wrapper\_destroy is called when the* **proxy\_t** *is destroyed. Reference counting is active. A reference to the* **proxy\_t** *creating this proxy wrapper is held to extend its lifetime until after the proxy wrapper is destroyed.*

*Definition at line* **116** *of file* **wayland-client.hpp***.*

## Member Function Documentation

### wl\_proxy \* wayland::proxy\_t::c\_ptr () const` [inherited]`

*Get a pointer to the underlying C struct.*

**Returns**

*The underlying wl\_proxy wrapped by this* **proxy\_t** *if it exists, otherwise an exception is thrown*

### std::string wayland::proxy\_t::get\_class () const` [inherited]`

*Get the interface name (class) of a proxy object.*

**Returns**

*The interface name of the object associated with the proxy*

### uint32\_t wayland::proxy\_t::get\_id () const` [inherited]`

*Get the id of a proxy object.*

**Returns**

*The id the object associated with the proxy*

### uint32\_t wayland::proxy\_t::get\_version () const` [inherited]`

*Get the protocol object version of a proxy object. Gets the protocol object version of a proxy object, or 0 if the proxy was created with unversioned API.*

*A returned value of 0 means that no version information is available, so the caller must make safe assumptions about the object's real version.*

**display\_t** *will always return version 0.*

**Returns**

*The protocol object version of the proxy or 0*

### wrapper\_type wayland::proxy\_t::get\_wrapper\_type () const` [inline]`, ` [inherited]`

*Get the type of a proxy object.*

*Definition at line* **302** *of file* **wayland-client.hpp***.*

### wayland::proxy\_t::operator bool () const` [inherited]`

*Check whether this wrapper actually wraps an object.*

**Returns**

*true if there is an underlying object, false if this wrapper is empty*

### bool wayland::proxy\_t::operator!= (const proxy\_t & right) const` [inherited]`

*Check whether two wrappers refer to different objects.*

### bool wayland::proxy\_t::operator== (const proxy\_t & right) const` [inherited]`

*Check whether two wrappers refer to the same object.*

### bool wayland::proxy\_t::proxy\_has\_object () const` [inherited]`

*Check whether this wrapper actually wraps an object.*

**Returns**

*true if there is an underlying object, false if this wrapper is empty*

### void wayland::proxy\_t::proxy\_release ()` [inherited]`

*Release the wrapped object (if any), making this an empty wrapper. Note that* **display\_t** *instances cannot be released this way. Attempts to do so are ignored.*

**Examples** **foreign\_display.cpp***.*

### void viewport\_t::set\_destination (int32\_t width, int32\_t height)

*set the surface size for scaling*

**Parameters**

*width surface width* \
 *height surface height*

*Set the destination size of the associated wl\_surface. See wp\_viewport for the description, and relation to the wl\_buffer size.*

*If width is -1 and height is -1, the destination size is unset instead. Any other pair of values for width and height that contains zero or negative values raises the bad\_value protocol error.*

*The crop and scale state is double-buffered state, and will be applied on the next wl\_surface.commit.*

*Definition at line* **953** *of file* **wayland-client-protocol-extra.cpp***.*

### void wayland::proxy\_t::set\_queue (event\_queue\_t queue)` [inherited]`

*Assign a proxy to an event queue.*

**Parameters**

*queue The event queue that will handle this proxy*

*Assign proxy to event queue. Events coming from proxy will be queued in queue instead of the display's main queue.*

*See also:* **display\_t::dispatch\_queue()***.*

**Examples** **proxy\_wrapper.cpp***.*

### void viewport\_t::set\_source (double x, double y, double width, double height)

*set the source rectangle for cropping*

**Parameters**

*x source rectangle x* \
 *y source rectangle y* \
 *width source rectangle width* \
 *height source rectangle height*

*Set the source rectangle of the associated wl\_surface. See wp\_viewport for the description, and relation to the wl\_buffer size.*

*If all of x, y, width and height are -1.0, the source rectangle is unset instead. Any other set of values where width or height are zero or negative, or x or y are negative, raise the bad\_value protocol error.*

*The crop and scale state is double-buffered state, and will be applied on the next wl\_surface.commit.*

*Definition at line* **947** *of file* **wayland-client-protocol-extra.cpp***.*

## Member Data Documentation

### constexpr std::uint32\_t wayland::viewport\_t::set\_destination\_since\_version = 1` [static]`, ` [constexpr]`

*Minimum protocol version required for the* **set\_destination** *function.*

*Definition at line* **504** *of file* **wayland-client-protocol-extra.hpp***.*

### constexpr std::uint32\_t wayland::viewport\_t::set\_source\_since\_version = 1` [static]`, ` [constexpr]`

*Minimum protocol version required for the* **set\_source** *function.*

*Definition at line* **481** *of file* **wayland-client-protocol-extra.hpp***.*

## Author

*Generated automatically by Doxygen for Wayland++ from the source code.*
