1// Package gdk was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gdk
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/glib"
12 "github.com/bnema/puregotk/v4/gobject"
13 "github.com/bnema/puregotk/v4/gobject/types"
14 "github.com/bnema/puregotk/v4/pango"
15)
16
17// Stores a single event in a motion history.
18//
19// To check whether an axis is present, check whether the corresponding
20// flag from the [flags@Gdk.AxisFlags] enumeration is set in the @flags
21// To access individual axis values, use the values of the values of
22// the [enum@Gdk.AxisUse] enumerations as indices.
23type TimeCoord struct {
24 _ structs.HostLayout
25
26 Time uint32
27
28 Flags AxisFlags
29
30 Axes [12]float64
31}
32
33func (x *TimeCoord) GoPointer() uintptr {
34 return uintptr(unsafe.Pointer(x))
35}
36
37// An enumeration describing the type of an input device in general terms.
38type InputSource int
39
40var xInputSourceGLibType func() types.GType
41
42func InputSourceGLibType() types.GType {
43 return xInputSourceGLibType()
44}
45
46const (
47
48 // the device is a mouse. (This will be reported for the core
49 // pointer, even if it is something else, such as a trackball.)
50 SourceMouseValue InputSource = 0
51 // the device is a stylus of a graphics tablet or similar device.
52 SourcePenValue InputSource = 1
53 // the device is a keyboard.
54 SourceKeyboardValue InputSource = 2
55 // the device is a direct-input touch device, such
56 // as a touchscreen or tablet
57 SourceTouchscreenValue InputSource = 3
58 // the device is an indirect touch device, such
59 // as a touchpad
60 SourceTouchpadValue InputSource = 4
61 // the device is a trackpoint
62 SourceTrackpointValue InputSource = 5
63 // the device is a "pad", a collection of buttons,
64 // rings and strips found in drawing tablets
65 SourceTabletPadValue InputSource = 6
66)
67
68// Represents an input device, such as a keyboard, mouse or touchpad.
69//
70// See the [class@Gdk.Seat] documentation for more information
71// about the various kinds of devices, and their relationships.
72type Device struct {
73 gobject.Object
74}
75
76var xDeviceGLibType func() types.GType
77
78func DeviceGLibType() types.GType {
79 return xDeviceGLibType()
80}
81
82func DeviceNewFromInternalPtr(ptr uintptr) *Device {
83 cls := &Device{}
84 cls.Ptr = ptr
85 return cls
86}
87
88var xDeviceGetActiveLayoutIndex func(uintptr) int
89
90// Retrieves the index of the active layout of the keyboard.
91//
92// If there is no valid active layout for the `GdkDevice`, this function will
93// return -1;
94//
95// This is only relevant for keyboard devices.
96func (x *Device) GetActiveLayoutIndex() int {
97
98 cret := xDeviceGetActiveLayoutIndex(x.GoPointer())
99 return cret
100}
101
102var xDeviceGetCapsLockState func(uintptr) bool
103
104// Retrieves whether the Caps Lock modifier of the keyboard is locked.
105//
106// This is only relevant for keyboard devices.
107func (x *Device) GetCapsLockState() bool {
108
109 cret := xDeviceGetCapsLockState(x.GoPointer())
110 return cret
111}
112
113var xDeviceGetDeviceTool func(uintptr) uintptr
114
115// Retrieves the current tool for @device.
116func (x *Device) GetDeviceTool() *DeviceTool {
117 var cls *DeviceTool
118
119 cret := xDeviceGetDeviceTool(x.GoPointer())
120
121 if cret == 0 {
122 return nil
123 }
124 gobject.IncreaseRef(cret)
125 cls = &DeviceTool{}
126 cls.Ptr = cret
127 return cls
128}
129
130var xDeviceGetDirection func(uintptr) pango.Direction
131
132// Returns the direction of effective layout of the keyboard.
133//
134// This is only relevant for keyboard devices.
135//
136// The direction of a layout is the direction of the majority
137// of its symbols. See [func@Pango.unichar_direction].
138func (x *Device) GetDirection() pango.Direction {
139
140 cret := xDeviceGetDirection(x.GoPointer())
141 return cret
142}
143
144var xDeviceGetDisplay func(uintptr) uintptr
145
146// Returns the `GdkDisplay` to which @device pertains.
147func (x *Device) GetDisplay() *Display {
148 var cls *Display
149
150 cret := xDeviceGetDisplay(x.GoPointer())
151
152 if cret == 0 {
153 return nil
154 }
155 gobject.IncreaseRef(cret)
156 cls = &Display{}
157 cls.Ptr = cret
158 return cls
159}
160
161var xDeviceGetHasCursor func(uintptr) bool
162
163// Determines whether the pointer follows device motion.
164//
165// This is not meaningful for keyboard devices, which
166// don't have a pointer.
167func (x *Device) GetHasCursor() bool {
168
169 cret := xDeviceGetHasCursor(x.GoPointer())
170 return cret
171}
172
173var xDeviceGetLayoutNames func(uintptr) []string
174
175// Retrieves the names of the layouts of the keyboard.
176//
177// This is only relevant for keyboard devices.
178func (x *Device) GetLayoutNames() []string {
179
180 cret := xDeviceGetLayoutNames(x.GoPointer())
181 return cret
182}
183
184var xDeviceGetModifierState func(uintptr) ModifierType
185
186// Retrieves the current modifier state of the keyboard.
187//
188// This is only relevant for keyboard devices.
189func (x *Device) GetModifierState() ModifierType {
190
191 cret := xDeviceGetModifierState(x.GoPointer())
192 return cret
193}
194
195var xDeviceGetName func(uintptr) string
196
197// The name of the device, suitable for showing in a user interface.
198func (x *Device) GetName() string {
199
200 cret := xDeviceGetName(x.GoPointer())
201 return cret
202}
203
204var xDeviceGetNumLockState func(uintptr) bool
205
206// Retrieves whether the Num Lock modifier of the keyboard is locked.
207//
208// This is only relevant for keyboard devices.
209func (x *Device) GetNumLockState() bool {
210
211 cret := xDeviceGetNumLockState(x.GoPointer())
212 return cret
213}
214
215var xDeviceGetNumTouches func(uintptr) uint
216
217// Retrieves the number of touch points associated to @device.
218func (x *Device) GetNumTouches() uint {
219
220 cret := xDeviceGetNumTouches(x.GoPointer())
221 return cret
222}
223
224var xDeviceGetProductId func(uintptr) string
225
226// Returns the product ID of this device.
227//
228// This ID is retrieved from the device, and does not change.
229// See [method@Gdk.Device.get_vendor_id] for more information.
230func (x *Device) GetProductId() string {
231
232 cret := xDeviceGetProductId(x.GoPointer())
233 return cret
234}
235
236var xDeviceGetScrollLockState func(uintptr) bool
237
238// Retrieves whether the Scroll Lock modifier of the keyboard is locked.
239//
240// This is only relevant for keyboard devices.
241func (x *Device) GetScrollLockState() bool {
242
243 cret := xDeviceGetScrollLockState(x.GoPointer())
244 return cret
245}
246
247var xDeviceGetSeat func(uintptr) uintptr
248
249// Returns the `GdkSeat` the device belongs to.
250func (x *Device) GetSeat() *Seat {
251 var cls *Seat
252
253 cret := xDeviceGetSeat(x.GoPointer())
254
255 if cret == 0 {
256 return nil
257 }
258 gobject.IncreaseRef(cret)
259 cls = &Seat{}
260 cls.Ptr = cret
261 return cls
262}
263
264var xDeviceGetSource func(uintptr) InputSource
265
266// Determines the type of the device.
267func (x *Device) GetSource() InputSource {
268
269 cret := xDeviceGetSource(x.GoPointer())
270 return cret
271}
272
273var xDeviceGetSurfaceAtPosition func(uintptr, *float64, *float64) uintptr
274
275// Obtains the surface underneath @device, returning the location of the
276// device in @win_x and @win_y.
277//
278// Returns %NULL if the surface tree under @device is not known to GDK
279// (for example, belongs to another application).
280func (x *Device) GetSurfaceAtPosition(WinXVar *float64, WinYVar *float64) *Surface {
281 var cls *Surface
282
283 cret := xDeviceGetSurfaceAtPosition(x.GoPointer(), WinXVar, WinYVar)
284
285 if cret == 0 {
286 return nil
287 }
288 gobject.IncreaseRef(cret)
289 cls = &Surface{}
290 cls.Ptr = cret
291 return cls
292}
293
294var xDeviceGetTimestamp func(uintptr) uint32
295
296// Returns the timestamp of the last activity for this device.
297//
298// In practice, this means the timestamp of the last event that was
299// received from the OS for this device. (GTK may occasionally produce
300// events for a device that are not received from the OS, and will not
301// update the timestamp).
302func (x *Device) GetTimestamp() uint32 {
303
304 cret := xDeviceGetTimestamp(x.GoPointer())
305 return cret
306}
307
308var xDeviceGetVendorId func(uintptr) string
309
310// Returns the vendor ID of this device.
311//
312// This ID is retrieved from the device, and does not change.
313//
314// This function, together with [method@Gdk.Device.get_product_id],
315// can be used to eg. compose `GSettings` paths to store settings
316// for this device.
317//
318// ```c
319//
320// static GSettings *
321// get_device_settings (GdkDevice *device)
322// {
323// const char *vendor, *product;
324// GSettings *settings;
325// GdkDevice *device;
326// char *path;
327//
328// vendor = gdk_device_get_vendor_id (device);
329// product = gdk_device_get_product_id (device);
330//
331// path = g_strdup_printf ("/org/example/app/devices/%s:%s/", vendor, product);
332// settings = g_settings_new_with_path (DEVICE_SCHEMA, path);
333// g_free (path);
334//
335// return settings;
336// }
337//
338// ```
339func (x *Device) GetVendorId() string {
340
341 cret := xDeviceGetVendorId(x.GoPointer())
342 return cret
343}
344
345var xDeviceHasBidiLayouts func(uintptr) bool
346
347// Determines if layouts for both right-to-left and
348// left-to-right languages are in use on the keyboard.
349//
350// This is only relevant for keyboard devices.
351func (x *Device) HasBidiLayouts() bool {
352
353 cret := xDeviceHasBidiLayouts(x.GoPointer())
354 return cret
355}
356
357func (c *Device) GoPointer() uintptr {
358 if c == nil {
359 return 0
360 }
361 return c.Ptr
362}
363
364func (c *Device) SetGoPointer(ptr uintptr) {
365 c.Ptr = ptr
366}
367
368// GetPropertyActiveLayoutIndex gets the "active-layout-index" property.
369// The index of the keyboard active layout of a `GdkDevice`.
370//
371// Will be -1 if there is no valid active layout.
372//
373// This is only relevant for keyboard devices.
374func (x *Device) GetPropertyActiveLayoutIndex() int {
375 var v gobject.Value
376 x.GetProperty("active-layout-index", &v)
377 return v.GetInt()
378}
379
380// GetPropertyCapsLockState gets the "caps-lock-state" property.
381// Whether Caps Lock is on.
382//
383// This is only relevant for keyboard devices.
384func (x *Device) GetPropertyCapsLockState() bool {
385 var v gobject.Value
386 x.GetProperty("caps-lock-state", &v)
387 return v.GetBoolean()
388}
389
390// GetPropertyHasBidiLayouts gets the "has-bidi-layouts" property.
391// Whether the device has both right-to-left and left-to-right layouts.
392//
393// This is only relevant for keyboard devices.
394func (x *Device) GetPropertyHasBidiLayouts() bool {
395 var v gobject.Value
396 x.GetProperty("has-bidi-layouts", &v)
397 return v.GetBoolean()
398}
399
400// SetPropertyHasCursor sets the "has-cursor" property.
401// Whether the device is represented by a cursor on the screen.
402func (x *Device) SetPropertyHasCursor(value bool) {
403 var v gobject.Value
404 v.Init(gobject.TypeBooleanVal)
405 v.SetBoolean(value)
406 x.SetProperty("has-cursor", &v)
407}
408
409// GetPropertyHasCursor gets the "has-cursor" property.
410// Whether the device is represented by a cursor on the screen.
411func (x *Device) GetPropertyHasCursor() bool {
412 var v gobject.Value
413 x.GetProperty("has-cursor", &v)
414 return v.GetBoolean()
415}
416
417// GetPropertyLayoutNames gets the "layout-names" property.
418// The names of the keyboard layouts of a `GdkDevice`.
419//
420// This is only relevant for keyboard devices.
421func (x *Device) GetPropertyLayoutNames() []string {
422 var v gobject.Value
423 x.GetProperty("layout-names", &v)
424 return core.GoStringSlice(v.GetBoxed())
425}
426
427// GetPropertyNAxes gets the "n-axes" property.
428// Number of axes in the device.
429func (x *Device) GetPropertyNAxes() uint {
430 var v gobject.Value
431 x.GetProperty("n-axes", &v)
432 return v.GetUint()
433}
434
435// SetPropertyName sets the "name" property.
436// The device name.
437func (x *Device) SetPropertyName(value string) {
438 var v gobject.Value
439 v.Init(gobject.TypeStringVal)
440 v.SetString(&value)
441 x.SetProperty("name", &v)
442}
443
444// GetPropertyName gets the "name" property.
445// The device name.
446func (x *Device) GetPropertyName() string {
447 var v gobject.Value
448 x.GetProperty("name", &v)
449 return v.GetString()
450}
451
452// GetPropertyNumLockState gets the "num-lock-state" property.
453// Whether Num Lock is on.
454//
455// This is only relevant for keyboard devices.
456func (x *Device) GetPropertyNumLockState() bool {
457 var v gobject.Value
458 x.GetProperty("num-lock-state", &v)
459 return v.GetBoolean()
460}
461
462// SetPropertyNumTouches sets the "num-touches" property.
463// The maximal number of concurrent touches on a touch device.
464//
465// Will be 0 if the device is not a touch device or if the number
466// of touches is unknown.
467func (x *Device) SetPropertyNumTouches(value uint) {
468 var v gobject.Value
469 v.Init(gobject.TypeUintVal)
470 v.SetUint(value)
471 x.SetProperty("num-touches", &v)
472}
473
474// GetPropertyNumTouches gets the "num-touches" property.
475// The maximal number of concurrent touches on a touch device.
476//
477// Will be 0 if the device is not a touch device or if the number
478// of touches is unknown.
479func (x *Device) GetPropertyNumTouches() uint {
480 var v gobject.Value
481 x.GetProperty("num-touches", &v)
482 return v.GetUint()
483}
484
485// SetPropertyProductId sets the "product-id" property.
486// Product ID of this device.
487//
488// See [method@Gdk.Device.get_product_id].
489func (x *Device) SetPropertyProductId(value string) {
490 var v gobject.Value
491 v.Init(gobject.TypeStringVal)
492 v.SetString(&value)
493 x.SetProperty("product-id", &v)
494}
495
496// GetPropertyProductId gets the "product-id" property.
497// Product ID of this device.
498//
499// See [method@Gdk.Device.get_product_id].
500func (x *Device) GetPropertyProductId() string {
501 var v gobject.Value
502 x.GetProperty("product-id", &v)
503 return v.GetString()
504}
505
506// GetPropertyScrollLockState gets the "scroll-lock-state" property.
507// Whether Scroll Lock is on.
508//
509// This is only relevant for keyboard devices.
510func (x *Device) GetPropertyScrollLockState() bool {
511 var v gobject.Value
512 x.GetProperty("scroll-lock-state", &v)
513 return v.GetBoolean()
514}
515
516// SetPropertyVendorId sets the "vendor-id" property.
517// Vendor ID of this device.
518//
519// See [method@Gdk.Device.get_vendor_id].
520func (x *Device) SetPropertyVendorId(value string) {
521 var v gobject.Value
522 v.Init(gobject.TypeStringVal)
523 v.SetString(&value)
524 x.SetProperty("vendor-id", &v)
525}
526
527// GetPropertyVendorId gets the "vendor-id" property.
528// Vendor ID of this device.
529//
530// See [method@Gdk.Device.get_vendor_id].
531func (x *Device) GetPropertyVendorId() string {
532 var v gobject.Value
533 x.GetProperty("vendor-id", &v)
534 return v.GetString()
535}
536
537// Emitted either when the number of either axes or keys changes.
538//
539// On X11 this will normally happen when the physical device
540// routing events through the logical device changes (for
541// example, user switches from the USB mouse to a tablet); in
542// that case the logical device will change to reflect the axes
543// and keys on the new physical device.
544func (x *Device) ConnectChanged(cb *func(Device)) uint {
545 cbPtr := uintptr(unsafe.Pointer(cb))
546 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
547 handlerID := gobject.SignalConnect(x.GoPointer(), "changed", cbRefPtr)
548 glib.SaveHandlerMapping(handlerID, cbPtr)
549 return handlerID
550 }
551
552 fcb := func(clsPtr uintptr) {
553 fa := Device{}
554 fa.Ptr = clsPtr
555 cbFn := *cb
556
557 cbFn(fa)
558
559 }
560 cbRefPtr := purego.NewCallback(fcb)
561 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
562 handlerID := gobject.SignalConnect(x.GoPointer(), "changed", cbRefPtr)
563 glib.SaveHandlerMapping(handlerID, cbPtr)
564 return handlerID
565}
566
567// Emitted on pen/eraser devices whenever tools enter or leave proximity.
568func (x *Device) ConnectToolChanged(cb *func(Device, uintptr)) uint {
569 cbPtr := uintptr(unsafe.Pointer(cb))
570 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
571 handlerID := gobject.SignalConnect(x.GoPointer(), "tool-changed", cbRefPtr)
572 glib.SaveHandlerMapping(handlerID, cbPtr)
573 return handlerID
574 }
575
576 fcb := func(clsPtr uintptr, ToolVarp uintptr) {
577 fa := Device{}
578 fa.Ptr = clsPtr
579 cbFn := *cb
580
581 cbFn(fa, ToolVarp)
582
583 }
584 cbRefPtr := purego.NewCallback(fcb)
585 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
586 handlerID := gobject.SignalConnect(x.GoPointer(), "tool-changed", cbRefPtr)
587 glib.SaveHandlerMapping(handlerID, cbPtr)
588 return handlerID
589}
590
591func init() {
592 core.SetPackageName("GDK", "gtk4")
593 core.SetSharedLibraries("GDK", []string{"libgtk-4.so.1"})
594 var libs []uintptr
595 for _, libPath := range core.GetPaths("GDK") {
596 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
597 if err != nil {
598 panic(err)
599 }
600 libs = append(libs, lib)
601 }
602
603 core.PuregoSafeRegister(&xInputSourceGLibType, libs, "gdk_input_source_get_type")
604
605 core.PuregoSafeRegister(&xDeviceGLibType, libs, "gdk_device_get_type")
606
607 core.PuregoSafeRegister(&xDeviceGetActiveLayoutIndex, libs, "gdk_device_get_active_layout_index")
608 core.PuregoSafeRegister(&xDeviceGetCapsLockState, libs, "gdk_device_get_caps_lock_state")
609 core.PuregoSafeRegister(&xDeviceGetDeviceTool, libs, "gdk_device_get_device_tool")
610 core.PuregoSafeRegister(&xDeviceGetDirection, libs, "gdk_device_get_direction")
611 core.PuregoSafeRegister(&xDeviceGetDisplay, libs, "gdk_device_get_display")
612 core.PuregoSafeRegister(&xDeviceGetHasCursor, libs, "gdk_device_get_has_cursor")
613 core.PuregoSafeRegister(&xDeviceGetLayoutNames, libs, "gdk_device_get_layout_names")
614 core.PuregoSafeRegister(&xDeviceGetModifierState, libs, "gdk_device_get_modifier_state")
615 core.PuregoSafeRegister(&xDeviceGetName, libs, "gdk_device_get_name")
616 core.PuregoSafeRegister(&xDeviceGetNumLockState, libs, "gdk_device_get_num_lock_state")
617 core.PuregoSafeRegister(&xDeviceGetNumTouches, libs, "gdk_device_get_num_touches")
618 core.PuregoSafeRegister(&xDeviceGetProductId, libs, "gdk_device_get_product_id")
619 core.PuregoSafeRegister(&xDeviceGetScrollLockState, libs, "gdk_device_get_scroll_lock_state")
620 core.PuregoSafeRegister(&xDeviceGetSeat, libs, "gdk_device_get_seat")
621 core.PuregoSafeRegister(&xDeviceGetSource, libs, "gdk_device_get_source")
622 core.PuregoSafeRegister(&xDeviceGetSurfaceAtPosition, libs, "gdk_device_get_surface_at_position")
623 core.PuregoSafeRegister(&xDeviceGetTimestamp, libs, "gdk_device_get_timestamp")
624 core.PuregoSafeRegister(&xDeviceGetVendorId, libs, "gdk_device_get_vendor_id")
625 core.PuregoSafeRegister(&xDeviceHasBidiLayouts, libs, "gdk_device_has_bidi_layouts")
626
627}