Struct gdk::Device [−][src]
pub struct Device(_);
Expand description
The Device
object represents a single input device, such
as a keyboard, a mouse, a touchpad, etc.
See the DeviceManager
documentation for more information
about the various kinds of master and slave devices, and their
relationships.
This is an Abstract Base Class, you cannot instantiate it.
Implementations
Returns the associated device to self
, if self
is of type
DeviceType::Master
, it will return the paired pointer or
keyboard.
If self
is of type DeviceType::Slave
, it will return
the master device to which self
is attached to.
If self
is of type DeviceType::Floating
, None
will be
returned, as there is no associated device.
Returns
The associated device, or
None
This is supported on crate feature v3_22
only.
v3_22
only.Returns the axes currently available on the device.
Gets information about which window the given pointer device is in, based on events
that have been received so far from the display server. If another application
has a pointer grab, or this application has a grab with owner_events = false
,
None
may be returned even if the pointer is physically over one of this
application’s windows.
Returns
the last window the device
Gets the current location of self
. As a slave device
coordinates are those of its master pointer, This function
may not be called on devices of type DeviceType::Slave
,
unless there is an ongoing grab on them, see grab()
.
Returns
screen
location to store the Screen
the self
is on, or None
.
x
location to store root window X coordinate of self
, or None
.
y
location to store root window Y coordinate of self
, or None
.
Gets the current location of self
in double precision. As a slave device’s
coordinates are those of its master pointer, this function
may not be called on devices of type DeviceType::Slave
,
unless there is an ongoing grab on them. See grab()
.
Returns
screen
location to store the Screen
the self
is on, or None
.
x
location to store root window X coordinate of self
, or None
.
y
location to store root window Y coordinate of self
, or None
.
Returns the product ID of this device, or None
if this information couldn’t
be obtained. This ID is retrieved from the device, and is thus constant for
it. See vendor_id()
for more information.
Returns
the product ID, or None
This is supported on crate feature v3_20
only.
v3_20
only.Returns the vendor ID of this device, or None
if this information couldn’t
be obtained. This ID is retrieved from the device, and is thus constant for
it.
This function, together with product_id()
, can be used to eg.
compose GSettings
paths to store settings for this device.
⚠️ The following code is in C ⚠️
static GSettings *
get_device_settings (GdkDevice *device)
{
const gchar *vendor, *product;
GSettings *settings;
GdkDevice *device;
gchar *path;
vendor = gdk_device_get_vendor_id (device);
product = gdk_device_get_product_id (device);
path = g_strdup_printf ("/org/example/app/devices/%s:%s/", vendor, product);
settings = g_settings_new_with_path (DEVICE_SCHEMA, path);
g_free (path);
return settings;
}
Returns
the vendor ID, or None
Obtains the window underneath self
, returning the location of the device in win_x
and win_y
. Returns
None
if the window tree under self
is not known to GDK (for example, belongs to another application).
As a slave device coordinates are those of its master pointer, This
function may not be called on devices of type DeviceType::Slave
,
unless there is an ongoing grab on them, see grab()
.
Returns
the Window
under the
device position, or None
.
win_x
return location for the X coordinate of the device location,
relative to the window origin, or None
.
win_y
return location for the Y coordinate of the device location,
relative to the window origin, or None
.
Obtains the window underneath self
, returning the location of the device in win_x
and win_y
in
double precision. Returns None
if the window tree under self
is not known to GDK (for example,
belongs to another application).
As a slave device coordinates are those of its master pointer, This
function may not be called on devices of type DeviceType::Slave
,
unless there is an ongoing grab on them, see grab()
.
Returns
the Window
under the
device position, or None
.
win_x
return location for the X coordinate of the device location,
relative to the window origin, or None
.
win_y
return location for the Y coordinate of the device location,
relative to the window origin, or None
.
pub fn grab(
&self,
window: &Window,
grab_ownership: GrabOwnership,
owner_events: bool,
event_mask: EventMask,
cursor: Option<&Cursor>,
time_: u32
) -> GrabStatus
pub fn grab(
&self,
window: &Window,
grab_ownership: GrabOwnership,
owner_events: bool,
event_mask: EventMask,
cursor: Option<&Cursor>,
time_: u32
) -> GrabStatus
Grabs the device so that all events coming from this device are passed to
this application until the device is ungrabbed with ungrab()
,
or the window becomes unviewable. This overrides any previous grab on the device
by this client.
Note that self
and window
need to be on the same display.
Device grabs are used for operations which need complete control over the given device events (either pointer or keyboard). For example in GTK+ this is used for Drag and Drop operations, popup menus and such.
Note that if the event mask of an X window has selected both button press
and button release events, then a button press event will cause an automatic
pointer grab until the button is released. X does this automatically since
most applications expect to receive button press and release events in pairs.
It is equivalent to a pointer grab on the window with owner_events
set to
true
.
If you set up anything at the time you take the grab that needs to be
cleaned up when the grab ends, you should handle the EventGrabBroken
events that are emitted when the grab ends unvoluntarily.
Deprecated since 3.20
Use Seat::grab()
instead.
window
the Window
which will own the grab (the grab window)
grab_ownership
specifies the grab ownership.
owner_events
if false
then all device events are reported with respect to
window
and are only reported if selected by event_mask
. If
true
then pointer events for this application are reported
as normal, but pointer events outside this application are
reported with respect to window
and only if selected by
event_mask
. In either mode, unreported events are discarded.
event_mask
specifies the event mask, which is used in accordance with
owner_events
.
cursor
the cursor to display while the grab is active if the device is
a pointer. If this is None
then the normal cursors are used for
window
and its descendants, and the cursor for window
is used
elsewhere.
time_
the timestamp of the event which led to this pointer grab. This
usually comes from the GdkEvent
struct, though GDK_CURRENT_TIME
can be used if the time isn’t known.
Returns
GrabStatus::Success
if the grab was successful.
Returns a GList
of GdkAtoms
, containing the labels for
the axes that self
currently has.
Returns
A GList
of GdkAtoms
, free with g_list_free()
.
If the device if of type DeviceType::Master
, it will return
the list of slave devices attached to it, otherwise it will return
None
Returns
the list of slave devices, or None
. The list must be
freed with g_list_free()
, the contents of the list are
owned by GTK+ and should not be freed.
Sets a the mode of an input device. The mode controls if the device is active and whether the device’s range is mapped to the entire screen or to a single window.
Note: This is only meaningful for floating devices, master devices (and slaves connected to these) drive the pointer cursor, which is not limited by the input mode.
mode
the input mode.
Returns
true
if the mode was successfully changed.
Release any grab on self
.
Deprecated since 3.20
Use Seat::ungrab()
instead.
time_
a timestap (e.g. GDK_CURRENT_TIME
).
Warps self
in display
to the point x
,y
on
the screen screen
, unless the device is confined
to a window by a grab, in which case it will be moved
as far as allowed by the grab. Warping the pointer
creates events as if the user had moved the mouse
instantaneously to the destination.
Note that the pointer should normally be under the
control of the user. This function was added to cover
some rare use cases like keyboard navigation support
for the color picker in the GtkColorSelectionDialog
.
screen
the screen to warp self
to.
x
the X coordinate of the destination.
y
the Y coordinate of the destination.
The DeviceManager
the Device
pertains to.
Source type for the device.
This is supported on crate feature v3_20
only.
v3_20
only.The maximal number of concurrent touches on a touch device. Will be 0 if the device is not a touch device or if the number of touches is unknown.
This is supported on crate feature v3_20
only.
v3_20
only.Seat
of this device.
v3_22
only.Device role in the device manager.
The ::changed signal is emitted either when the Device
has changed the number of either axes or keys. For example
In X this will normally happen when the slave device routing
events through the master device changes (for example, user
switches from the USB mouse to a tablet), in that case the
master device will change to reflect the new slave device
axes and keys.
pub fn connect_tool_changed<F: Fn(&Self, &DeviceTool) + 'static>(
&self,
f: F
) -> SignalHandlerId
This is supported on crate feature v3_22
only.
pub fn connect_tool_changed<F: Fn(&Self, &DeviceTool) + 'static>(
&self,
f: F
) -> SignalHandlerId
v3_22
only.The ::tool-changed signal is emitted on pen/eraser
GdkDevices
whenever tools enter or leave proximity.
tool
The new current tool
pub fn connect_associated_device_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
v3_22
only.v3_20
only.v3_22
only.Obtains the motion history for a pointer device; given a starting and
ending timestamp, return all events in the motion history for
the device in the given range of time. Some windowing systems
do not support motion history, in which case, false
will
be returned. (This is not distinguishable from the case where
motion history is supported and no events were found.)
Note that there is also Window::set_event_compression()
to get
more motion events delivered directly, independent of the windowing
system.
window
the window with respect to which which the event coordinates will be reported
start
starting timestamp for range of events to return
stop
ending timestamp for the range of events to return
Returns
true
if the windowing system supports motion history and
at least one event was found.
events
location to store a newly-allocated array of TimeCoord
, or
None
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Returns the type identifier of Self
.
Auto Trait Implementations
impl RefUnwindSafe for Device
impl UnwindSafe for Device
Blanket Implementations
Mutably borrows from an owned value. Read more
Upcasts an object to a superclass or interface T
. Read more
Upcasts an object to a reference of its superclass or interface T
. Read more
Tries to downcast to a subclass or interface implementor T
. Read more
Tries to downcast to a reference of its subclass or interface implementor T
. Read more
Tries to cast to an object of type T
. This handles upcasting, downcasting
and casting between interface and interface implementors. All checks are performed at
runtime, while downcast
and upcast
will do many checks at compile-time already. Read more
Tries to cast to reference to an object of type T
. This handles upcasting, downcasting
and casting between interface and interface implementors. All checks are performed at
runtime, while downcast
and upcast
will do many checks at compile-time already. Read more
Casts to T
unconditionally. Read more
Casts to &T
unconditionally. Read more
Returns true
if the object is an instance of (can be cast to) T
.
pub fn set_properties_from_value(
&self,
property_values: &[(&str, Value)]
) -> Result<(), BoolError>
pub fn set_property<'a, N, V>(
&self,
property_name: N,
value: V
) -> Result<(), BoolError> where
N: Into<&'a str>,
V: ToValue,
pub fn set_property_from_value<'a, N>(
&self,
property_name: N,
value: &Value
) -> Result<(), BoolError> where
N: Into<&'a str>,
Safety Read more
Safety Read more
Safety Read more
Safety Read more
pub fn connect_notify<F>(&self, name: Option<&str>, f: F) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec) + Send + Sync,
pub fn connect_notify_local<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec),
pub unsafe fn connect_notify_unsafe<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: Fn(&T, &ParamSpec),
pub fn has_property<'a, N>(&self, property_name: N, type_: Option<Type>) -> bool where
N: Into<&'a str>,
pub fn find_property<'a, N>(&self, property_name: N) -> Option<ParamSpec> where
N: Into<&'a str>,
pub fn connect<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
F: Fn(&[Value]) -> Option<Value> + Send + Sync + 'static,
N: Into<&'a str>,
Same as connect
but takes a SignalId
instead of a signal name.
pub fn connect_local<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
F: Fn(&[Value]) -> Option<Value> + 'static,
N: Into<&'a str>,
Same as connect_local
but takes a SignalId
instead of a signal name.
pub unsafe fn connect_unsafe<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
F: Fn(&[Value]) -> Option<Value>,
N: Into<&'a str>,
Same as connect_unsafe
but takes a SignalId
instead of a signal name.
Emit signal by signal id.
Emit signal with details by signal id.
Emit signal by it’s name.
pub fn bind_property<'a, O, N, M>(
&'a self,
source_property: N,
target: &'a O,
target_property: M
) -> BindingBuilder<'a> where
O: ObjectType,
M: Into<&'a str>,
N: Into<&'a str>,
Same as emit
but takes Value
for the arguments.
Same as emit_by_name
but takes Value
for the arguments.
Returns a SendValue
clone of self
.
impl<'a, T, C> FromValueOptional<'a> for T where
C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError>,
T: FromValue<'a, Checker = C>,