forked from GNOME/gtk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdkdevice.c
1932 lines (1680 loc) · 55.6 KB
/
gdkdevice.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* GDK - The GIMP Drawing Kit
* Copyright (C) 2009 Carlos Garnacho <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <math.h>
#include "gdkdeviceprivate.h"
#include "gdkdevicetool.h"
#include "gdkdisplayprivate.h"
#include "gdkinternals.h"
#include "gdkintl.h"
/* for the use of round() */
#include "fallback-c89.c"
/**
* SECTION:gdkdevice
* @Short_description: Object representing an input device
* @Title: GdkDevice
* @See_also: #GdkSeat
*
* The #GdkDevice object represents a single input device, such
* as a keyboard, a mouse, a touchpad, etc.
*
* See the #GdkSeat documentation for more information
* about the various kinds of master and slave devices, and their
* relationships.
*/
/**
* GdkDevice:
*
* The GdkDevice struct contains only private fields and
* should not be accessed directly.
*/
typedef struct _GdkAxisInfo GdkAxisInfo;
struct _GdkAxisInfo
{
char *label;
GdkAxisUse use;
gdouble min_axis;
gdouble max_axis;
gdouble min_value;
gdouble max_value;
gdouble resolution;
};
enum {
CHANGED,
TOOL_CHANGED,
LAST_SIGNAL
};
static guint signals [LAST_SIGNAL] = { 0 };
static void gdk_device_finalize (GObject *object);
static void gdk_device_dispose (GObject *object);
static void gdk_device_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gdk_device_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
G_DEFINE_ABSTRACT_TYPE (GdkDevice, gdk_device, G_TYPE_OBJECT)
enum {
PROP_0,
PROP_DISPLAY,
PROP_NAME,
PROP_ASSOCIATED_DEVICE,
PROP_TYPE,
PROP_INPUT_SOURCE,
PROP_INPUT_MODE,
PROP_HAS_CURSOR,
PROP_N_AXES,
PROP_VENDOR_ID,
PROP_PRODUCT_ID,
PROP_SEAT,
PROP_NUM_TOUCHES,
PROP_AXES,
PROP_TOOL,
LAST_PROP
};
static GParamSpec *device_props[LAST_PROP] = { NULL, };
static void
gdk_device_class_init (GdkDeviceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gdk_device_finalize;
object_class->dispose = gdk_device_dispose;
object_class->set_property = gdk_device_set_property;
object_class->get_property = gdk_device_get_property;
/**
* GdkDevice:display:
*
* The #GdkDisplay the #GdkDevice pertains to.
*/
device_props[PROP_DISPLAY] =
g_param_spec_object ("display",
P_("Device Display"),
P_("Display which the device belongs to"),
GDK_TYPE_DISPLAY,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
/**
* GdkDevice:name:
*
* The device name.
*/
device_props[PROP_NAME] =
g_param_spec_string ("name",
P_("Device name"),
P_("Device name"),
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
/**
* GdkDevice:type:
*
* Device role in the device manager.
*/
device_props[PROP_TYPE] =
g_param_spec_enum ("type",
P_("Device type"),
P_("Device role in the device manager"),
GDK_TYPE_DEVICE_TYPE,
GDK_DEVICE_TYPE_MASTER,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
/**
* GdkDevice:associated-device:
*
* Associated pointer or keyboard with this device, if any. Devices of type #GDK_DEVICE_TYPE_MASTER
* always come in keyboard/pointer pairs. Other device types will have a %NULL associated device.
*/
device_props[PROP_ASSOCIATED_DEVICE] =
g_param_spec_object ("associated-device",
P_("Associated device"),
P_("Associated pointer or keyboard with this device"),
GDK_TYPE_DEVICE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GdkDevice:input-source:
*
* Source type for the device.
*/
device_props[PROP_INPUT_SOURCE] =
g_param_spec_enum ("input-source",
P_("Input source"),
P_("Source type for the device"),
GDK_TYPE_INPUT_SOURCE,
GDK_SOURCE_MOUSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
/*
* GdkDevice:input-mode:
*
* Input mode for the device.
*/
device_props[PROP_INPUT_MODE] =
g_param_spec_enum ("input-mode",
P_("Input mode for the device"),
P_("Input mode for the device"),
GDK_TYPE_INPUT_MODE,
GDK_MODE_DISABLED,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
/**
* GdkDevice:has-cursor:
*
* Whether the device is represented by a cursor on the screen. Devices of type
* %GDK_DEVICE_TYPE_MASTER will have %TRUE here.
*/
device_props[PROP_HAS_CURSOR] =
g_param_spec_boolean ("has-cursor",
P_("Whether the device has a cursor"),
P_("Whether there is a visible cursor following device motion"),
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
/**
* GdkDevice:n-axes:
*
* Number of axes in the device.
*/
device_props[PROP_N_AXES] =
g_param_spec_uint ("n-axes",
P_("Number of axes in the device"),
P_("Number of axes in the device"),
0, G_MAXUINT,
0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GdkDevice:vendor-id:
*
* Vendor ID of this device, see gdk_device_get_vendor_id().
*/
device_props[PROP_VENDOR_ID] =
g_param_spec_string ("vendor-id",
P_("Vendor ID"),
P_("Vendor ID"),
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
/**
* GdkDevice:product-id:
*
* Product ID of this device, see gdk_device_get_product_id().
*/
device_props[PROP_PRODUCT_ID] =
g_param_spec_string ("product-id",
P_("Product ID"),
P_("Product ID"),
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
/**
* GdkDevice:seat:
*
* #GdkSeat of this device.
*/
device_props[PROP_SEAT] =
g_param_spec_object ("seat",
P_("Seat"),
P_("Seat"),
GDK_TYPE_SEAT,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
/**
* GdkDevice:num-touches:
*
* 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.
*/
device_props[PROP_NUM_TOUCHES] =
g_param_spec_uint ("num-touches",
P_("Number of concurrent touches"),
P_("Number of concurrent touches"),
0, G_MAXUINT,
0,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
/**
* GdkDevice:axes:
*
* The axes currently available for this device.
*/
device_props[PROP_AXES] =
g_param_spec_flags ("axes",
P_("Axes"),
P_("Axes"),
GDK_TYPE_AXIS_FLAGS, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
device_props[PROP_TOOL] =
g_param_spec_object ("tool",
P_("Tool"),
P_("The tool that is currently used with this device"),
GDK_TYPE_DEVICE_TOOL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, LAST_PROP, device_props);
/**
* GdkDevice::changed:
* @device: the #GdkDevice that changed.
*
* The ::changed signal is emitted either when the #GdkDevice
* 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.
*/
signals[CHANGED] =
g_signal_new (g_intern_static_string ("changed"),
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* GdkDevice::tool-changed:
* @device: the #GdkDevice that changed.
* @tool: The new current tool
*
* The ::tool-changed signal is emitted on pen/eraser
* #GdkDevices whenever tools enter or leave proximity.
*/
signals[TOOL_CHANGED] =
g_signal_new (g_intern_static_string ("tool-changed"),
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, GDK_TYPE_DEVICE_TOOL);
}
static void
gdk_device_axis_info_clear (gpointer data)
{
GdkAxisInfo *info = data;
g_free (info->label);
}
static void
gdk_device_init (GdkDevice *device)
{
device->axes = g_array_new (FALSE, TRUE, sizeof (GdkAxisInfo));
g_array_set_clear_func (device->axes, gdk_device_axis_info_clear);
}
static void
gdk_device_finalize (GObject *object)
{
GdkDevice *device = GDK_DEVICE (object);
if (device->axes)
{
g_array_free (device->axes, TRUE);
device->axes = NULL;
}
g_clear_pointer (&device->name, g_free);
g_clear_pointer (&device->keys, g_free);
g_clear_pointer (&device->vendor_id, g_free);
g_clear_pointer (&device->product_id, g_free);
G_OBJECT_CLASS (gdk_device_parent_class)->finalize (object);
}
static void
gdk_device_dispose (GObject *object)
{
GdkDevice *device = GDK_DEVICE (object);
GdkDevice *associated = device->associated;
if (associated && device->type == GDK_DEVICE_TYPE_SLAVE)
_gdk_device_remove_slave (associated, device);
if (associated)
{
device->associated = NULL;
if (device->type == GDK_DEVICE_TYPE_MASTER &&
associated->associated == device)
_gdk_device_set_associated_device (associated, NULL);
g_object_unref (associated);
}
g_clear_object (&device->last_tool);
G_OBJECT_CLASS (gdk_device_parent_class)->dispose (object);
}
static void
gdk_device_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GdkDevice *device = GDK_DEVICE (object);
switch (prop_id)
{
case PROP_DISPLAY:
device->display = g_value_get_object (value);
break;
case PROP_NAME:
g_free (device->name);
device->name = g_value_dup_string (value);
break;
case PROP_TYPE:
device->type = g_value_get_enum (value);
break;
case PROP_INPUT_SOURCE:
device->source = g_value_get_enum (value);
break;
case PROP_INPUT_MODE:
gdk_device_set_mode (device, g_value_get_enum (value));
break;
case PROP_HAS_CURSOR:
device->has_cursor = g_value_get_boolean (value);
break;
case PROP_VENDOR_ID:
device->vendor_id = g_value_dup_string (value);
break;
case PROP_PRODUCT_ID:
device->product_id = g_value_dup_string (value);
break;
case PROP_SEAT:
device->seat = g_value_get_object (value);
break;
case PROP_NUM_TOUCHES:
device->num_touches = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gdk_device_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GdkDevice *device = GDK_DEVICE (object);
switch (prop_id)
{
case PROP_DISPLAY:
g_value_set_object (value, device->display);
break;
case PROP_ASSOCIATED_DEVICE:
g_value_set_object (value, device->associated);
break;
case PROP_NAME:
g_value_set_string (value, device->name);
break;
case PROP_TYPE:
g_value_set_enum (value, device->type);
break;
case PROP_INPUT_SOURCE:
g_value_set_enum (value, device->source);
break;
case PROP_INPUT_MODE:
g_value_set_enum (value, device->mode);
break;
case PROP_HAS_CURSOR:
g_value_set_boolean (value, device->has_cursor);
break;
case PROP_N_AXES:
g_value_set_uint (value, device->axes->len);
break;
case PROP_VENDOR_ID:
g_value_set_string (value, device->vendor_id);
break;
case PROP_PRODUCT_ID:
g_value_set_string (value, device->product_id);
break;
case PROP_SEAT:
g_value_set_object (value, device->seat);
break;
case PROP_NUM_TOUCHES:
g_value_set_uint (value, device->num_touches);
break;
case PROP_AXES:
g_value_set_flags (value, device->axis_flags);
break;
case PROP_TOOL:
g_value_set_object (value, device->last_tool);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/**
* gdk_device_get_state: (skip)
* @device: a #GdkDevice.
* @window: a #GdkWindow.
* @axes: (nullable) (array): an array of doubles to store the values of
* the axes of @device in, or %NULL.
* @mask: (optional) (out): location to store the modifiers, or %NULL.
*
* Gets the current state of a pointer device relative to @window. As a slave
* device’s coordinates are those of its master pointer, this
* function may not be called on devices of type %GDK_DEVICE_TYPE_SLAVE,
* unless there is an ongoing grab on them. See gdk_device_grab().
*/
void
gdk_device_get_state (GdkDevice *device,
GdkWindow *window,
gdouble *axes,
GdkModifierType *mask)
{
g_return_if_fail (GDK_IS_DEVICE (device));
g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
g_return_if_fail (GDK_IS_WINDOW (window));
g_return_if_fail (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_SLAVE ||
gdk_display_device_is_grabbed (gdk_device_get_display (device), device));
if (GDK_DEVICE_GET_CLASS (device)->get_state)
GDK_DEVICE_GET_CLASS (device)->get_state (device, window, axes, mask);
}
/**
* gdk_device_get_position_double:
* @device: pointer device to query status about.
* @x: (out) (allow-none): location to store root window X coordinate of @device, or %NULL.
* @y: (out) (allow-none): location to store root window Y coordinate of @device, or %NULL.
*
* Gets the current location of @device 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 %GDK_DEVICE_TYPE_SLAVE,
* unless there is an ongoing grab on them. See gdk_device_grab().
**/
void
gdk_device_get_position_double (GdkDevice *device,
gdouble *x,
gdouble *y)
{
GdkDisplay *display;
gdouble tmp_x, tmp_y;
g_return_if_fail (GDK_IS_DEVICE (device));
g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
display = gdk_device_get_display (device);
g_return_if_fail (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_SLAVE ||
gdk_display_device_is_grabbed (display, device));
_gdk_device_query_state (device,
NULL,
NULL,
&tmp_x, &tmp_y,
NULL, NULL, NULL);
if (x)
*x = tmp_x;
if (y)
*y = tmp_y;
}
/**
* gdk_device_get_position:
* @device: pointer device to query status about.
* @x: (out) (allow-none): location to store root window X coordinate of @device, or %NULL.
* @y: (out) (allow-none): location to store root window Y coordinate of @device, or %NULL.
*
* Gets the current location of @device. As a slave device
* coordinates are those of its master pointer, This function
* may not be called on devices of type %GDK_DEVICE_TYPE_SLAVE,
* unless there is an ongoing grab on them, see gdk_device_grab().
**/
void
gdk_device_get_position (GdkDevice *device,
gint *x,
gint *y)
{
gdouble tmp_x, tmp_y;
gdk_device_get_position_double (device, &tmp_x, &tmp_y);
if (x)
*x = round (tmp_x);
if (y)
*y = round (tmp_y);
}
/**
* gdk_device_get_window_at_position_double:
* @device: pointer #GdkDevice to query info to.
* @win_x: (out) (allow-none): return location for the X coordinate of the device location,
* relative to the window origin, or %NULL.
* @win_y: (out) (allow-none): return location for the Y coordinate of the device location,
* relative to the window origin, or %NULL.
*
* Obtains the window underneath @device, returning the location of the device in @win_x and @win_y in
* double precision. Returns %NULL if the window tree under @device 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 %GDK_DEVICE_TYPE_SLAVE,
* unless there is an ongoing grab on them, see gdk_device_grab().
*
* Returns: (nullable) (transfer none): the #GdkWindow under the
* device position, or %NULL.
**/
GdkWindow *
gdk_device_get_window_at_position_double (GdkDevice *device,
gdouble *win_x,
gdouble *win_y)
{
gdouble tmp_x, tmp_y;
GdkWindow *window;
g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
g_return_val_if_fail (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_SLAVE ||
gdk_display_device_is_grabbed (gdk_device_get_display (device), device), NULL);
window = _gdk_device_window_at_position (device, &tmp_x, &tmp_y, NULL, FALSE);
/* This might need corrections, as the native window returned
may contain client side children */
if (window)
window = _gdk_window_find_descendant_at (window,
tmp_x, tmp_y,
&tmp_x, &tmp_y);
if (win_x)
*win_x = tmp_x;
if (win_y)
*win_y = tmp_y;
return window;
}
/**
* gdk_device_get_window_at_position:
* @device: pointer #GdkDevice to query info to.
* @win_x: (out) (allow-none): return location for the X coordinate of the device location,
* relative to the window origin, or %NULL.
* @win_y: (out) (allow-none): return location for the Y coordinate of the device location,
* relative to the window origin, or %NULL.
*
* Obtains the window underneath @device, returning the location of the device in @win_x and @win_y. Returns
* %NULL if the window tree under @device 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 %GDK_DEVICE_TYPE_SLAVE,
* unless there is an ongoing grab on them, see gdk_device_grab().
*
* Returns: (nullable) (transfer none): the #GdkWindow under the
* device position, or %NULL.
**/
GdkWindow *
gdk_device_get_window_at_position (GdkDevice *device,
gint *win_x,
gint *win_y)
{
gdouble tmp_x, tmp_y;
GdkWindow *window;
window =
gdk_device_get_window_at_position_double (device, &tmp_x, &tmp_y);
if (win_x)
*win_x = round (tmp_x);
if (win_y)
*win_y = round (tmp_y);
return window;
}
/**
* gdk_device_get_history: (skip)
* @device: a #GdkDevice
* @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
* @events: (array length=n_events) (out) (transfer full) (optional):
* location to store a newly-allocated array of #GdkTimeCoord, or
* %NULL
* @n_events: (out) (optional): location to store the length of
* @events, or %NULL
*
* 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 gdk_window_set_event_compression() to get
* more motion events delivered directly, independent of the windowing
* system.
*
* Returns: %TRUE if the windowing system supports motion history and
* at least one event was found.
**/
gboolean
gdk_device_get_history (GdkDevice *device,
GdkWindow *window,
guint32 start,
guint32 stop,
GdkTimeCoord ***events,
gint *n_events)
{
g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, FALSE);
g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
if (n_events)
*n_events = 0;
if (events)
*events = NULL;
if (GDK_WINDOW_DESTROYED (window))
return FALSE;
if (!GDK_DEVICE_GET_CLASS (device)->get_history)
return FALSE;
return GDK_DEVICE_GET_CLASS (device)->get_history (device, window,
start, stop,
events, n_events);
}
GdkTimeCoord **
_gdk_device_allocate_history (GdkDevice *device,
gint n_events)
{
GdkTimeCoord **result = g_new (GdkTimeCoord *, n_events);
gint i;
for (i = 0; i < n_events; i++)
result[i] = g_malloc (sizeof (GdkTimeCoord) -
sizeof (double) * (GDK_MAX_TIMECOORD_AXES - device->axes->len));
return result;
}
/**
* gdk_device_free_history: (skip)
* @events: (array length=n_events): an array of #GdkTimeCoord.
* @n_events: the length of the array.
*
* Frees an array of #GdkTimeCoord that was returned by gdk_device_get_history().
*/
void
gdk_device_free_history (GdkTimeCoord **events,
gint n_events)
{
gint i;
for (i = 0; i < n_events; i++)
g_free (events[i]);
g_free (events);
}
/**
* gdk_device_get_name:
* @device: a #GdkDevice
*
* Determines the name of the device.
*
* Returns: a name
**/
const gchar *
gdk_device_get_name (GdkDevice *device)
{
g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
return device->name;
}
/**
* gdk_device_get_has_cursor:
* @device: a #GdkDevice
*
* Determines whether the pointer follows device motion.
* This is not meaningful for keyboard devices, which don't have a pointer.
*
* Returns: %TRUE if the pointer follows device motion
**/
gboolean
gdk_device_get_has_cursor (GdkDevice *device)
{
g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
return device->has_cursor;
}
/**
* gdk_device_get_source:
* @device: a #GdkDevice
*
* Determines the type of the device.
*
* Returns: a #GdkInputSource
**/
GdkInputSource
gdk_device_get_source (GdkDevice *device)
{
g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
return device->source;
}
/**
* gdk_device_get_mode:
* @device: a #GdkDevice
*
* Determines the mode of the device.
*
* Returns: a #GdkInputSource
**/
GdkInputMode
gdk_device_get_mode (GdkDevice *device)
{
g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
return device->mode;
}
/**
* gdk_device_set_mode:
* @device: a #GdkDevice.
* @mode: the input mode.
*
* 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.
*
* Returns: %TRUE if the mode was successfully changed.
**/
gboolean
gdk_device_set_mode (GdkDevice *device,
GdkInputMode mode)
{
g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
if (device->mode == mode)
return TRUE;
if (mode == GDK_MODE_DISABLED &&
gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER)
return FALSE;
device->mode = mode;
g_object_notify_by_pspec (G_OBJECT (device), device_props[PROP_INPUT_MODE]);
return TRUE;
}
/**
* gdk_device_get_n_keys:
* @device: a #GdkDevice
*
* Returns the number of keys the device currently has.
*
* Returns: the number of keys.
**/
gint
gdk_device_get_n_keys (GdkDevice *device)
{
g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
return device->num_keys;
}
/**
* gdk_device_get_key:
* @device: a #GdkDevice.
* @index_: the index of the macro button to get.
* @keyval: (out): return value for the keyval.
* @modifiers: (out): return value for modifiers.
*
* If @index_ has a valid keyval, this function will return %TRUE
* and fill in @keyval and @modifiers with the keyval settings.
*
* Returns: %TRUE if keyval is set for @index.
**/
gboolean
gdk_device_get_key (GdkDevice *device,
guint index_,
guint *keyval,
GdkModifierType *modifiers)
{
g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
g_return_val_if_fail (index_ < device->num_keys, FALSE);
if (!device->keys[index_].keyval &&
!device->keys[index_].modifiers)
return FALSE;
if (keyval)
*keyval = device->keys[index_].keyval;
if (modifiers)
*modifiers = device->keys[index_].modifiers;
return TRUE;
}
/**
* gdk_device_set_key:
* @device: a #GdkDevice
* @index_: the index of the macro button to set
* @keyval: the keyval to generate
* @modifiers: the modifiers to set
*
* Specifies the X key event to generate when a macro button of a device
* is pressed.
**/
void
gdk_device_set_key (GdkDevice *device,
guint index_,
guint keyval,
GdkModifierType modifiers)
{
g_return_if_fail (GDK_IS_DEVICE (device));
g_return_if_fail (index_ < device->num_keys);
device->keys[index_].keyval = keyval;
device->keys[index_].modifiers = modifiers;
}
/**
* gdk_device_get_axis_use:
* @device: a pointer #GdkDevice.
* @index_: the index of the axis.
*
* Returns the axis use for @index_.
*
* Returns: a #GdkAxisUse specifying how the axis is used.
**/
GdkAxisUse
gdk_device_get_axis_use (GdkDevice *device,
guint index_)
{
GdkAxisInfo *info;
g_return_val_if_fail (GDK_IS_DEVICE (device), GDK_AXIS_IGNORE);
g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, GDK_AXIS_IGNORE);
g_return_val_if_fail (index_ < device->axes->len, GDK_AXIS_IGNORE);
info = &g_array_index (device->axes, GdkAxisInfo, index_);
return info->use;
}
/**
* gdk_device_set_axis_use:
* @device: a pointer #GdkDevice
* @index_: the index of the axis
* @use: specifies how the axis is used
*
* Specifies how an axis of a device is used.
**/
void
gdk_device_set_axis_use (GdkDevice *device,
guint index_,
GdkAxisUse use)
{
GdkAxisInfo *info;
g_return_if_fail (GDK_IS_DEVICE (device));
g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
g_return_if_fail (index_ < device->axes->len);
info = &g_array_index (device->axes, GdkAxisInfo, index_);
info->use = use;
switch ((guint) use)
{
case GDK_AXIS_X:
case GDK_AXIS_Y:
info->min_axis = 0;
info->max_axis = 0;
break;
case GDK_AXIS_XTILT:
case GDK_AXIS_YTILT:
info->min_axis = -1;
info->max_axis = 1;
break;
default:
info->min_axis = 0;