class Gdk::Cursor

Overview

Gdk::Cursor is used to create and destroy cursors.

Cursors are immutable objects, so once you created them, there is no way to modify them later. You should create a new cursor when you want to change something about it.

Cursors by themselves are not very interesting: they must be bound to a window for users to see them. This is done with Gdk::Surface#cursor= or Gdk::Surface#device_cursor=. Applications will typically use higher-level GTK functions such as Gtk::Widget#cursor= instead.

Cursors are not bound to a given Gdk::Display, so they can be shared. However, the appearance of cursors may vary when used on different platforms.

Named and texture cursors

There are multiple ways to create cursors. The platform's own cursors can be created with Gdk::Cursor#new_from_name. That function lists the commonly available names that are shared with the CSS specification. Other names may be available, depending on the platform in use. On some platforms, what images are used for named cursors may be influenced by the cursor theme.

Another option to create a cursor is to use Gdk::Cursor#new_from_texture and provide an image to use for the cursor.

To ease work with unsupported cursors, a fallback cursor can be provided. If a Gdk::Surface cannot use a cursor because of the reasons mentioned above, it will try the fallback cursor. Fallback cursors can themselves have fallback cursors again, so it is possible to provide a chain of progressively easier to support cursors. If none of the provided cursors can be supported, the default cursor will be the ultimate fallback.

Defined in:

lib/gi-crystal/src/auto/gdk-4.0/cursor.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class GObject::Object

==(other : self) ==, bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void) | Nil data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, hash(hasher) hash, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void) | Nil qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void) | Nil) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void) | Nil steal_data, steal_qdata(quark : UInt32) : Pointer(Void) | Nil steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, new(pointer : Pointer(Void), transfer : GICrystal::Transfer)
new
new
, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

cast?(obj : GObject::Object) : self | Nil cast?, compat_control(what : UInt64, data : Pointer(Void) | Nil) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Macros inherited from class GObject::Object

previous_vfunc(*args) previous_vfunc, previous_vfunc!(*args) previous_vfunc!, signal(signature) signal

Constructor Detail

def self.new #

Initialize a new Cursor.


[View source]
def self.new(*, fallback : Gdk::Cursor | Nil = nil, hotspot_x : Int32 | Nil = nil, hotspot_y : Int32 | Nil = nil, name : String | Nil = nil, texture : Gdk::Texture | Nil = nil) #

[View source]
def self.new_from_texture(texture : Gdk::Texture, hotspot_x : Int32, hotspot_y : Int32, fallback : Gdk::Cursor | Nil) : self #

Creates a new cursor from a Gdk::Texture.


[View source]

Class Method Detail

def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


[View source]
def self.new_from_name(name : String, fallback : Gdk::Cursor | Nil) : self | Nil #

Creates a new cursor by looking up name in the current cursor theme.

A recommended set of cursor names that will work across different platforms can be found in the CSS specification:

| | | | | | --- | --- | ---- | --- | | "none" | "default" | "help" | "pointer" | | "context-menu" | "progress" | "wait" | "cell" | | "crosshair" | "text" | "vertical-text" | "alias" | | "copy" | "no-drop" | "move" | "not-allowed" | | "grab" | "grabbing" | "all-scroll" | "col-resize" | | "row-resize" | "n-resize" | "e-resize" | "s-resize" | | "w-resize" | "ne-resize" | "nw-resize" | "sw-resize" | | "se-resize" | "ew-resize" | "ns-resize" | "nesw-resize" | | "nwse-resize" | "zoom-in" | "zoom-out" | |


[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


def fallback : Gdk::Cursor | Nil #

Returns the fallback for this cursor.

The fallback will be used if this cursor is not available on a given Gdk::Display. For named cursors, this can happen when using nonstandard names or when using an incomplete cursor theme. For textured cursors, this can happen when the texture is too large or when the Gdk::Display it is used on does not support textured cursors.


[View source]
def fallback=(value : Gdk::Cursor | Nil) : Gdk::Cursor | Nil #

[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


def hotspot_x : Int32 #

Returns the horizontal offset of the hotspot.

The hotspot indicates the pixel that will be directly above the cursor.

Note that named cursors may have a nonzero hotspot, but this function will only return the hotspot position for cursors created with Gdk::Cursor#new_from_texture.


[View source]
def hotspot_x=(value : Int32) : Int32 #

[View source]
def hotspot_y : Int32 #

Returns the vertical offset of the hotspot.

The hotspot indicates the pixel that will be directly above the cursor.

Note that named cursors may have a nonzero hotspot, but this function will only return the hotspot position for cursors created with Gdk::Cursor#new_from_texture.


[View source]
def hotspot_y=(value : Int32) : Int32 #

[View source]
def name : String | Nil #

Returns the name of the cursor.

If the cursor is not a named cursor, nil will be returned.


[View source]
def name=(value : String) : String #

[View source]
def texture : Gdk::Texture | Nil #

Returns the texture for the cursor.

If the cursor is a named cursor, nil will be returned.


[View source]
def texture=(value : Gdk::Texture | Nil) : Gdk::Texture | Nil #

[View source]