Functions

cairo_draw_from_gl(cr: Context, surface: Surface, source: int, source_type: int, buffer_scale: int, x: int, y: int, width: int, height: int) None

The main way to not draw GL content in GTK.

It takes a render buffer ID (source_type == GL_RENDERBUFFER) or a texture id (source_type == GL_TEXTURE) and draws it onto cr with an OVER operation, respecting the current clip. The top left corner of the rectangle specified by x, y, width and height will be drawn at the current (0,0) position of the cairo_t.

This will work for all cairo_t, as long as surface is realized, but the fallback implementation that reads back the pixels from the buffer may be used in the general case. In the case of direct drawing to a surface with no special effects applied to cr it will however use a more efficient approach.

For GL_RENDERBUFFER the code will always fall back to software for buffers with alpha components, so make sure you use GL_TEXTURE if using alpha.

Calling this may change the current GL context.

Deprecated since version 4.6: The function is overly complex and produces broken output in various combinations of arguments. If you want to draw with GL textures in GTK, use new; if you want to use that texture in Cairo, use download to download the data into a Cairo image surface.

Parameters:
  • cr – a cairo context

  • surface – The surface we’re rendering for (not necessarily into)

  • source – The GL ID of the source buffer

  • source_type – The type of the source

  • buffer_scale – The scale-factor that the source buffer is allocated for

  • x – The source x position in source to start copying from in GL coordinates

  • y – The source y position in source to start copying from in GL coordinates

  • width – The width of the region to draw

  • height – The height of the region to draw

cairo_rectangle(cr: Context, rectangle: Rectangle) None

Adds the given rectangle to the current path of cr.

Parameters:
  • cr – a cairo context

  • rectangle – a GdkRectangle

cairo_region(cr: Context, region: Region) None

Adds the given region to the current path of cr.

Parameters:
  • cr – a cairo context

  • region – a cairo_region_t

cairo_region_create_from_surface(surface: Surface) Region

Creates region that covers the area where the given surface is more than 50% opaque.

This function takes into account device offsets that might be set with cairo_surface_set_device_offset().

Parameters:

surface – a cairo surface

Returns:

A cairo_region_t

cairo_set_source_pixbuf(cr: Context, pixbuf: Pixbuf, pixbuf_x: float, pixbuf_y: float) None

Sets the given pixbuf as the source pattern for cr.

The pattern has an extend mode of %CAIRO_EXTEND_NONE and is aligned so that the origin of pixbuf is pixbuf_x, pixbuf_y.

Parameters:
  • cr – a cairo context

  • pixbuf – a GdkPixbuf

  • pixbuf_x – X coordinate of location to place upper left corner of pixbuf

  • pixbuf_y – Y coordinate of location to place upper left corner of pixbuf

cairo_set_source_rgba(cr: Context, rgba: RGBA) None

Sets the specified GdkRGBA as the source color of cr.

Parameters:
  • cr – a cairo context

  • rgba – a GdkRGBA

content_deserialize_async(stream: InputStream, mime_type: str, type: type, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Read content from the given input stream and deserialize it, asynchronously.

The default I/O priority is %G_PRIORITY_DEFAULT (i.e. 0), and lower numbers indicate a higher priority.

When the operation is finished, callback will be called. You must then call content_deserialize_finish to get the result of the operation.

Parameters:
  • stream – a GInputStream to read the serialized content from

  • mime_type – the mime type to deserialize from

  • type – the GType to deserialize from

  • io_priority – the I/O priority of the operation

  • cancellable – optional GCancellable object

  • callback – callback to call when the operation is done

  • user_data – data to pass to the callback function

content_deserialize_finish(result: AsyncResult) tuple[bool, Any]

Finishes a content deserialization operation.

Parameters:

result – the GAsyncResult

Returns:

True if the operation was successful. In this case, value is set. False if an error occurred. In this case, error is set

content_formats_parse(string: str) ContentFormats | None
Parameters:

string

content_register_deserializer(mime_type: str, type: type, deserialize: Callable[[...], None], *data: Any) None

Registers a function to deserialize object of a given type.

Parameters:
  • mime_type – the mime type which the function can deserialize from

  • type – the type of objects that the function creates

  • deserialize – the callback

  • data – data that deserialize can access

content_register_serializer(type: type, mime_type: str, serialize: Callable[[...], None], *data: Any) None

Registers a function to serialize objects of a given type.

Parameters:
  • type – the type of objects that the function can serialize

  • mime_type – the mime type to serialize to

  • serialize – the callback

  • data – data that serialize can access

content_serialize_async(stream: OutputStream, mime_type: str, value: Any, io_priority: int, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Serialize content and write it to the given output stream, asynchronously.

The default I/O priority is %G_PRIORITY_DEFAULT (i.e. 0), and lower numbers indicate a higher priority.

When the operation is finished, callback will be called. You must then call content_serialize_finish to get the result of the operation.

Parameters:
  • stream – a GOutputStream to write the serialized content to

  • mime_type – the mime type to serialize to

  • value – the content to serialize

  • io_priority – the I/O priority of the operation

  • cancellable – optional GCancellable object

  • callback – callback to call when the operation is done

  • user_data – data to pass to the callback function

content_serialize_finish(result: AsyncResult) bool

Finishes a content serialization operation.

Parameters:

result – the GAsyncResult

Returns:

True if the operation was successful, False if an error occurred. In this case, error is set

dmabuf_error_quark() int
drag_action_is_unique(action: DragAction) bool
Parameters:

action

drag_surface_size_get_type() type
events_get_angle(event1: Event, event2: Event) tuple[bool, float]

Returns the relative angle from event1 to event2.

The relative angle is the angle between the X axis and the line through both events’ positions. The rotation direction for positive angles is from the positive X axis towards the positive Y axis.

This assumes that both events have X/Y information. If not, this function returns False.

Parameters:
  • event1 – first GdkEvent

  • event2 – second GdkEvent

Returns:

True if the angle could be calculated.

events_get_center(event1: Event, event2: Event) tuple[bool, float, float]

Returns the point halfway between the events’ positions.

This assumes that both events have X/Y information. If not, this function returns False.

Parameters:
  • event1 – first GdkEvent

  • event2 – second GdkEvent

Returns:

True if the center could be calculated.

events_get_distance(event1: Event, event2: Event) tuple[bool, float]

Returns the distance between the event locations.

This assumes that both events have X/Y information. If not, this function returns False.

Parameters:
  • event1 – first GdkEvent

  • event2 – second GdkEvent

Returns:

True if the distance could be calculated.

gl_error_quark() int
intern_mime_type(string: str) str | None

Canonicalizes the given mime type and interns the result.

If string is not a valid mime type, None is returned instead. See RFC 2048 for the syntax if mime types.

Parameters:

string – string of a potential mime type

Returns:

An interned string for the canonicalized mime type or None if the string wasn’t a valid mime type

keyval_convert_case(symbol: int) tuple[int, int]

Obtains the upper- and lower-case versions of the keyval symbol.

Examples of keyvals are GDK_KEY_a, GDK_KEY_Enter, GDK_KEY_F1, etc.

Parameters:

symbol – a keyval

keyval_from_name(keyval_name: str) int

Converts a key name to a key value.

The names are the same as those in the gdk/gdkkeysyms.h header file but without the leading “GDK_KEY_”.

Parameters:

keyval_name – a key name

Returns:

the corresponding key value, or KEY_VOIDSYMBOL if the key name is not a valid key

keyval_is_lower(keyval: int) bool

Returns True if the given key value is in lower case.

Parameters:

keyval – a key value.

Returns:

True if keyval is in lower case, or if keyval is not subject to case conversion.

keyval_is_upper(keyval: int) bool

Returns True if the given key value is in upper case.

Parameters:

keyval – a key value.

Returns:

True if keyval is in upper case, or if keyval is not subject to case conversion.

keyval_name(keyval: int) str | None

Converts a key value into a symbolic name.

The names are the same as those in the gdk/gdkkeysyms.h header file but without the leading “GDK_KEY_”.

Parameters:

keyval – a key value

Returns:

a string containing the name of the key

keyval_to_lower(keyval: int) int

Converts a key value to lower case, if applicable.

Parameters:

keyval – a key value.

Returns:

the lower case form of keyval, or keyval itself if it is already in lower case or it is not subject to case conversion.

keyval_to_unicode(keyval: int) int

Convert from a GDK key symbol to the corresponding Unicode character.

Note that the conversion does not take the current locale into consideration, which might be expected for particular keyvals, such as KEY_KP_DECIMAL.

Parameters:

keyval – a GDK key symbol

Returns:

the corresponding unicode character, or 0 if there is no corresponding character.

keyval_to_upper(keyval: int) int

Converts a key value to upper case, if applicable.

Parameters:

keyval – a key value.

Returns:

the upper case form of keyval, or keyval itself if it is already in upper case or it is not subject to case conversion.

paintable_new_empty(intrinsic_width: int, intrinsic_height: int) Paintable
Parameters:
  • intrinsic_width

  • intrinsic_height

pixbuf_get_from_surface(surface: Surface, src_x: int, src_y: int, width: int, height: int) Pixbuf | None

Transfers image data from a cairo_surface_t and converts it to a GdkPixbuf.

This allows you to efficiently read individual pixels from cairo surfaces.

This function will create an RGB pixbuf with 8 bits per channel. The pixbuf will contain an alpha channel if the surface contains one.

Deprecated since version 4.12: Use Texture and subclasses instead cairo surfaces and pixbufs

Parameters:
  • surface – surface to copy from

  • src_x – Source X coordinate within surface

  • src_y – Source Y coordinate within surface

  • width – Width in pixels of region to get

  • height – Height in pixels of region to get

Returns:

A newly-created pixbuf with a reference count of 1

pixbuf_get_from_texture(texture: Texture) Pixbuf | None

Creates a new pixbuf from texture.

This should generally not be used in newly written code as later stages will almost certainly convert the pixbuf back into a texture to draw it on screen.

Deprecated since version 4.12: Use Texture and subclasses instead cairo surfaces and pixbufs

Parameters:

texture – a GdkTexture

Returns:

a new GdkPixbuf

set_allowed_backends(backends: str) None

Sets a list of backends that GDK should try to use.

This can be useful if your application does not work with certain GDK backends.

By default, GDK tries all included backends.

For example:

gdk_set_allowed_backends ("wayland,macos,*");

instructs GDK to try the Wayland backend first, followed by the MacOs backend, and then all others.

If the GDK_BACKEND environment variable is set, it determines what backends are tried in what order, while still respecting the set of allowed backends that are specified by this function.

The possible backend names are:

  • broadway

  • macos

  • wayland.

  • win32

  • x11

You can also include a * in the list to try all remaining backends.

This call must happen prior to functions that open a display, such as open, gtk_init(), or gtk_init_check() in order to take effect.

Parameters:

backends – a comma-separated list of backends

texture_error_quark() int
toplevel_size_get_type() type
unicode_to_keyval(wc: int) int

Convert from a Unicode character to a key symbol.

Parameters:

wc – a Unicode character

Returns:

the corresponding GDK key symbol, if one exists. or, if there is no corresponding symbol, wc | 0x01000000

vulkan_error_quark() int