1// Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
2//
3// This file originated from: http://opensource.conformal.com/
4//
5// Permission to use, copy, modify, and distribute this software for any
6// purpose with or without fee is hereby granted, provided that the above
7// copyright notice and this permission notice appear in all copies.
8//
9// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17// Go bindings for GDK 3.  Supports version 3.6 and later.
18package gdk
19
20// #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
21// #include <gdk/gdk.h>
22// #include "gdk.go.h"
23import "C"
24import (
25	"errors"
26	"runtime"
27	"unsafe"
28
29	"github.com/gotk3/gotk3/cairo"
30	"github.com/gotk3/gotk3/glib"
31)
32
33func init() {
34	tm := []glib.TypeMarshaler{
35		// Enums
36		{glib.Type(C.gdk_drag_action_get_type()), marshalDragAction},
37		{glib.Type(C.gdk_colorspace_get_type()), marshalColorspace},
38		{glib.Type(C.gdk_event_type_get_type()), marshalEventType},
39		{glib.Type(C.gdk_interp_type_get_type()), marshalInterpType},
40		{glib.Type(C.gdk_modifier_type_get_type()), marshalModifierType},
41		{glib.Type(C.gdk_event_mask_get_type()), marshalEventMask},
42		{glib.Type(C.gdk_gravity_get_type()), marshalGravity},
43		{glib.Type(C.gdk_visual_type_get_type()), marshalVisualType},
44
45		// Objects/Interfaces
46		{glib.Type(C.gdk_device_get_type()), marshalDevice},
47		{glib.Type(C.gdk_display_manager_get_type()), marshalDisplayManager},
48		{glib.Type(C.gdk_cursor_get_type()), marshalCursor},
49		{glib.Type(C.gdk_device_manager_get_type()), marshalDeviceManager},
50		{glib.Type(C.gdk_display_get_type()), marshalDisplay},
51		{glib.Type(C.gdk_drag_context_get_type()), marshalDragContext},
52		{glib.Type(C.gdk_rgba_get_type()), marshalRGBA},
53		{glib.Type(C.gdk_screen_get_type()), marshalScreen},
54		{glib.Type(C.gdk_visual_get_type()), marshalVisual},
55		{glib.Type(C.gdk_window_get_type()), marshalWindow},
56
57		// Boxed
58		{glib.Type(C.gdk_event_get_type()), marshalEvent},
59	}
60	glib.RegisterGValueMarshalers(tm)
61}
62
63/*
64 * Type conversions
65 */
66
67func gbool(b bool) C.gboolean {
68	if b {
69		return C.gboolean(1)
70	}
71	return C.gboolean(0)
72}
73func gobool(b C.gboolean) bool {
74	if b != 0 {
75		return true
76	}
77	return false
78}
79
80/*
81 * Unexported vars
82 */
83
84var nilPtrErr = errors.New("cgo returned unexpected nil pointer")
85
86/*
87 * Constants
88 */
89
90// VisualType is a representation of GDK's GdkVisualType.
91type VisualType int
92
93const (
94	VISUAL_STATIC_GRAY  VisualType = C.GDK_VISUAL_STATIC_GRAY
95	VISUAL_GRAYSCALE    VisualType = C.GDK_VISUAL_GRAYSCALE
96	VISUAL_STATIC_COLOR VisualType = C.GDK_VISUAL_STATIC_COLOR
97	ISUAL_PSEUDO_COLOR  VisualType = C.GDK_VISUAL_PSEUDO_COLOR
98	VISUAL_TRUE_COLOR   VisualType = C.GDK_VISUAL_TRUE_COLOR
99	VISUAL_DIRECT_COLOR VisualType = C.GDK_VISUAL_DIRECT_COLOR
100)
101
102func marshalVisualType(p uintptr) (interface{}, error) {
103	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
104	return VisualType(c), nil
105}
106
107// DragAction is a representation of GDK's GdkDragAction.
108type DragAction int
109
110const (
111	ACTION_DEFAULT DragAction = C.GDK_ACTION_DEFAULT
112	ACTION_COPY    DragAction = C.GDK_ACTION_COPY
113	ACTION_MOVE    DragAction = C.GDK_ACTION_MOVE
114	ACTION_LINK    DragAction = C.GDK_ACTION_LINK
115	ACTION_PRIVATE DragAction = C.GDK_ACTION_PRIVATE
116	ACTION_ASK     DragAction = C.GDK_ACTION_ASK
117)
118
119func marshalDragAction(p uintptr) (interface{}, error) {
120	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
121	return DragAction(c), nil
122}
123
124// Colorspace is a representation of GDK's GdkColorspace.
125type Colorspace int
126
127const (
128	COLORSPACE_RGB Colorspace = C.GDK_COLORSPACE_RGB
129)
130
131func marshalColorspace(p uintptr) (interface{}, error) {
132	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
133	return Colorspace(c), nil
134}
135
136// InterpType is a representation of GDK's GdkInterpType.
137type InterpType int
138
139const (
140	INTERP_NEAREST  InterpType = C.GDK_INTERP_NEAREST
141	INTERP_TILES    InterpType = C.GDK_INTERP_TILES
142	INTERP_BILINEAR InterpType = C.GDK_INTERP_BILINEAR
143	INTERP_HYPER    InterpType = C.GDK_INTERP_HYPER
144)
145
146func marshalInterpType(p uintptr) (interface{}, error) {
147	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
148	return InterpType(c), nil
149}
150
151// ModifierType is a representation of GDK's GdkModifierType.
152type ModifierType uint
153
154const (
155	SHIFT_MASK    ModifierType = C.GDK_SHIFT_MASK
156	LOCK_MASK                  = C.GDK_LOCK_MASK
157	CONTROL_MASK               = C.GDK_CONTROL_MASK
158	MOD1_MASK                  = C.GDK_MOD1_MASK
159	MOD2_MASK                  = C.GDK_MOD2_MASK
160	MOD3_MASK                  = C.GDK_MOD3_MASK
161	MOD4_MASK                  = C.GDK_MOD4_MASK
162	MOD5_MASK                  = C.GDK_MOD5_MASK
163	BUTTON1_MASK               = C.GDK_BUTTON1_MASK
164	BUTTON2_MASK               = C.GDK_BUTTON2_MASK
165	BUTTON3_MASK               = C.GDK_BUTTON3_MASK
166	BUTTON4_MASK               = C.GDK_BUTTON4_MASK
167	BUTTON5_MASK               = C.GDK_BUTTON5_MASK
168	SUPER_MASK                 = C.GDK_SUPER_MASK
169	HYPER_MASK                 = C.GDK_HYPER_MASK
170	META_MASK                  = C.GDK_META_MASK
171	RELEASE_MASK               = C.GDK_RELEASE_MASK
172	MODIFIER_MASK              = C.GDK_MODIFIER_MASK
173)
174
175func marshalModifierType(p uintptr) (interface{}, error) {
176	c := C.g_value_get_flags((*C.GValue)(unsafe.Pointer(p)))
177	return ModifierType(c), nil
178}
179
180// Selections
181const (
182	SELECTION_PRIMARY       Atom = 1
183	SELECTION_SECONDARY     Atom = 2
184	SELECTION_CLIPBOARD     Atom = 69
185	TARGET_BITMAP           Atom = 5
186	TARGET_COLORMAP         Atom = 7
187	TARGET_DRAWABLE         Atom = 17
188	TARGET_PIXMAP           Atom = 20
189	TARGET_STRING           Atom = 31
190	SELECTION_TYPE_ATOM     Atom = 4
191	SELECTION_TYPE_BITMAP   Atom = 5
192	SELECTION_TYPE_COLORMAP Atom = 7
193	SELECTION_TYPE_DRAWABLE Atom = 17
194	SELECTION_TYPE_INTEGER  Atom = 19
195	SELECTION_TYPE_PIXMAP   Atom = 20
196	SELECTION_TYPE_WINDOW   Atom = 33
197	SELECTION_TYPE_STRING   Atom = 31
198)
199
200// added by terrak
201// EventMask is a representation of GDK's GdkEventMask.
202type EventMask int
203
204const (
205	EXPOSURE_MASK            EventMask = C.GDK_EXPOSURE_MASK
206	POINTER_MOTION_MASK      EventMask = C.GDK_POINTER_MOTION_MASK
207	POINTER_MOTION_HINT_MASK EventMask = C.GDK_POINTER_MOTION_HINT_MASK
208	BUTTON_MOTION_MASK       EventMask = C.GDK_BUTTON_MOTION_MASK
209	BUTTON1_MOTION_MASK      EventMask = C.GDK_BUTTON1_MOTION_MASK
210	BUTTON2_MOTION_MASK      EventMask = C.GDK_BUTTON2_MOTION_MASK
211	BUTTON3_MOTION_MASK      EventMask = C.GDK_BUTTON3_MOTION_MASK
212	BUTTON_PRESS_MASK        EventMask = C.GDK_BUTTON_PRESS_MASK
213	BUTTON_RELEASE_MASK      EventMask = C.GDK_BUTTON_RELEASE_MASK
214	KEY_PRESS_MASK           EventMask = C.GDK_KEY_PRESS_MASK
215	KEY_RELEASE_MASK         EventMask = C.GDK_KEY_RELEASE_MASK
216	ENTER_NOTIFY_MASK        EventMask = C.GDK_ENTER_NOTIFY_MASK
217	LEAVE_NOTIFY_MASK        EventMask = C.GDK_LEAVE_NOTIFY_MASK
218	FOCUS_CHANGE_MASK        EventMask = C.GDK_FOCUS_CHANGE_MASK
219	STRUCTURE_MASK           EventMask = C.GDK_STRUCTURE_MASK
220	PROPERTY_CHANGE_MASK     EventMask = C.GDK_PROPERTY_CHANGE_MASK
221	VISIBILITY_NOTIFY_MASK   EventMask = C.GDK_VISIBILITY_NOTIFY_MASK
222	PROXIMITY_IN_MASK        EventMask = C.GDK_PROXIMITY_IN_MASK
223	PROXIMITY_OUT_MASK       EventMask = C.GDK_PROXIMITY_OUT_MASK
224	SUBSTRUCTURE_MASK        EventMask = C.GDK_SUBSTRUCTURE_MASK
225	SCROLL_MASK              EventMask = C.GDK_SCROLL_MASK
226	TOUCH_MASK               EventMask = C.GDK_TOUCH_MASK
227	SMOOTH_SCROLL_MASK       EventMask = C.GDK_SMOOTH_SCROLL_MASK
228	ALL_EVENTS_MASK          EventMask = C.GDK_ALL_EVENTS_MASK
229)
230
231func marshalEventMask(p uintptr) (interface{}, error) {
232	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
233	return EventMask(c), nil
234}
235
236// added by lazyshot
237// ScrollDirection is a representation of GDK's GdkScrollDirection
238type ScrollDirection int
239
240const (
241	SCROLL_UP     ScrollDirection = C.GDK_SCROLL_UP
242	SCROLL_DOWN   ScrollDirection = C.GDK_SCROLL_DOWN
243	SCROLL_LEFT   ScrollDirection = C.GDK_SCROLL_LEFT
244	SCROLL_RIGHT  ScrollDirection = C.GDK_SCROLL_RIGHT
245	SCROLL_SMOOTH ScrollDirection = C.GDK_SCROLL_SMOOTH
246)
247
248// WindowEdge is a representation of GDK's GdkWindowEdge
249type WindowEdge int
250
251const (
252	WINDOW_EDGE_NORTH_WEST WindowEdge = C.GDK_WINDOW_EDGE_NORTH_WEST
253	WINDOW_EDGE_NORTH      WindowEdge = C.GDK_WINDOW_EDGE_NORTH
254	WINDOW_EDGE_NORTH_EAST WindowEdge = C.GDK_WINDOW_EDGE_NORTH_EAST
255	WINDOW_EDGE_WEST       WindowEdge = C.GDK_WINDOW_EDGE_WEST
256	WINDOW_EDGE_EAST       WindowEdge = C.GDK_WINDOW_EDGE_EAST
257	WINDOW_EDGE_SOUTH_WEST WindowEdge = C.GDK_WINDOW_EDGE_SOUTH_WEST
258	WINDOW_EDGE_SOUTH      WindowEdge = C.GDK_WINDOW_EDGE_SOUTH
259	WINDOW_EDGE_SOUTH_EAST WindowEdge = C.GDK_WINDOW_EDGE_SOUTH_EAST
260)
261
262// WindowState is a representation of GDK's GdkWindowState
263type WindowState int
264
265const (
266	WINDOW_STATE_WITHDRAWN  WindowState = C.GDK_WINDOW_STATE_WITHDRAWN
267	WINDOW_STATE_ICONIFIED  WindowState = C.GDK_WINDOW_STATE_ICONIFIED
268	WINDOW_STATE_MAXIMIZED  WindowState = C.GDK_WINDOW_STATE_MAXIMIZED
269	WINDOW_STATE_STICKY     WindowState = C.GDK_WINDOW_STATE_STICKY
270	WINDOW_STATE_FULLSCREEN WindowState = C.GDK_WINDOW_STATE_FULLSCREEN
271	WINDOW_STATE_ABOVE      WindowState = C.GDK_WINDOW_STATE_ABOVE
272	WINDOW_STATE_BELOW      WindowState = C.GDK_WINDOW_STATE_BELOW
273	WINDOW_STATE_FOCUSED    WindowState = C.GDK_WINDOW_STATE_FOCUSED
274	WINDOW_STATE_TILED      WindowState = C.GDK_WINDOW_STATE_TILED
275)
276
277// WindowTypeHint is a representation of GDK's GdkWindowTypeHint
278type WindowTypeHint int
279
280const (
281	WINDOW_TYPE_HINT_NORMAL        WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_NORMAL
282	WINDOW_TYPE_HINT_DIALOG        WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_DIALOG
283	WINDOW_TYPE_HINT_MENU          WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_MENU
284	WINDOW_TYPE_HINT_TOOLBAR       WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_TOOLBAR
285	WINDOW_TYPE_HINT_SPLASHSCREEN  WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_SPLASHSCREEN
286	WINDOW_TYPE_HINT_UTILITY       WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_UTILITY
287	WINDOW_TYPE_HINT_DOCK          WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_DOCK
288	WINDOW_TYPE_HINT_DESKTOP       WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_DESKTOP
289	WINDOW_TYPE_HINT_DROPDOWN_MENU WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU
290	WINDOW_TYPE_HINT_POPUP_MENU    WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_POPUP_MENU
291	WINDOW_TYPE_HINT_TOOLTIP       WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_TOOLTIP
292	WINDOW_TYPE_HINT_NOTIFICATION  WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_NOTIFICATION
293	WINDOW_TYPE_HINT_COMBO         WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_COMBO
294	WINDOW_TYPE_HINT_DND           WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_DND
295)
296
297// WindowHints is a representation of GDK's GdkWindowHints
298type WindowHints int
299
300const (
301	HINT_POS         WindowHints = C.GDK_HINT_POS
302	HINT_MIN_SIZE    WindowHints = C.GDK_HINT_MIN_SIZE
303	HINT_MAX_SIZE    WindowHints = C.GDK_HINT_MAX_SIZE
304	HINT_BASE_SIZE   WindowHints = C.GDK_HINT_BASE_SIZE
305	HINT_ASPECT      WindowHints = C.GDK_HINT_ASPECT
306	HINT_RESIZE_INC  WindowHints = C.GDK_HINT_RESIZE_INC
307	HINT_WIN_GRAVITY WindowHints = C.GDK_HINT_WIN_GRAVITY
308	HINT_USER_POS    WindowHints = C.GDK_HINT_USER_POS
309	HINT_USER_SIZE   WindowHints = C.GDK_HINT_USER_SIZE
310)
311
312// CURRENT_TIME is a representation of GDK_CURRENT_TIME
313
314const CURRENT_TIME = C.GDK_CURRENT_TIME
315
316// GrabStatus is a representation of GdkGrabStatus
317
318type GrabStatus int
319
320const (
321	GRAB_SUCCESS         GrabStatus = C.GDK_GRAB_SUCCESS
322	GRAB_ALREADY_GRABBED GrabStatus = C.GDK_GRAB_ALREADY_GRABBED
323	GRAB_INVALID_TIME    GrabStatus = C.GDK_GRAB_INVALID_TIME
324	GRAB_NOT_VIEWABLE    GrabStatus = C.GDK_GRAB_NOT_VIEWABLE
325	GRAB_FROZEN          GrabStatus = C.GDK_GRAB_FROZEN
326)
327
328// GrabOwnership is a representation of GdkGrabOwnership
329
330type GrabOwnership int
331
332const (
333	OWNERSHIP_NONE        GrabOwnership = C.GDK_OWNERSHIP_NONE
334	OWNERSHIP_WINDOW      GrabOwnership = C.GDK_OWNERSHIP_WINDOW
335	OWNERSHIP_APPLICATION GrabOwnership = C.GDK_OWNERSHIP_APPLICATION
336)
337
338// TODO:
339// GdkInputSource
340// GdkInputMode
341// GdkAxisUse
342// GdkAxisFlags
343// GdkDeviceToolType
344
345// DeviceType is a representation of GdkDeviceType
346
347type DeviceType int
348
349const (
350	DEVICE_TYPE_MASTER   DeviceType = C.GDK_DEVICE_TYPE_MASTER
351	DEVICE_TYPE_SLAVE    DeviceType = C.GDK_DEVICE_TYPE_SLAVE
352	DEVICE_TYPE_FLOATING DeviceType = C.GDK_DEVICE_TYPE_FLOATING
353)
354
355// TODO:
356// GdkColorspace
357// GdkVisualType
358// GdkTimeCoord
359
360// EventPropagation constants
361
362const (
363	GDK_EVENT_PROPAGATE bool = C.GDK_EVENT_PROPAGATE != 0
364	GDK_EVENT_STOP      bool = C.GDK_EVENT_STOP != 0
365)
366
367// Button constants
368type Button uint
369
370const (
371	BUTTON_PRIMARY   Button = C.GDK_BUTTON_PRIMARY
372	BUTTON_MIDDLE    Button = C.GDK_BUTTON_MIDDLE
373	BUTTON_SECONDARY Button = C.GDK_BUTTON_SECONDARY
374)
375
376// CrossingMode is a representation of GDK's GdkCrossingMode.
377
378type CrossingMode int
379
380const (
381	CROSSING_NORMAL        CrossingMode = C.GDK_CROSSING_NORMAL
382	CROSSING_GRAB          CrossingMode = C.GDK_CROSSING_GRAB
383	CROSSING_UNGRAB        CrossingMode = C.GDK_CROSSING_UNGRAB
384	CROSSING_GTK_GRAB      CrossingMode = C.GDK_CROSSING_GTK_GRAB
385	CROSSING_GTK_UNGRAB    CrossingMode = C.GDK_CROSSING_GTK_UNGRAB
386	CROSSING_STATE_CHANGED CrossingMode = C.GDK_CROSSING_STATE_CHANGED
387	CROSSING_TOUCH_BEGIN   CrossingMode = C.GDK_CROSSING_TOUCH_BEGIN
388	CROSSING_TOUCH_END     CrossingMode = C.GDK_CROSSING_TOUCH_END
389	CROSSING_DEVICE_SWITCH CrossingMode = C.GDK_CROSSING_DEVICE_SWITCH
390)
391
392// NotifyType is a representation of GDK's GdkNotifyType.
393
394type NotifyType int
395
396const (
397	NOTIFY_ANCESTOR          NotifyType = C.GDK_NOTIFY_ANCESTOR
398	NOTIFY_VIRTUAL           NotifyType = C.GDK_NOTIFY_VIRTUAL
399	NOTIFY_INFERIOR          NotifyType = C.GDK_NOTIFY_INFERIOR
400	NOTIFY_NONLINEAR         NotifyType = C.GDK_NOTIFY_NONLINEAR
401	NOTIFY_NONLINEAR_VIRTUAL NotifyType = C.GDK_NOTIFY_NONLINEAR_VIRTUAL
402	NOTIFY_UNKNOWN           NotifyType = C.GDK_NOTIFY_UNKNOWN
403)
404
405// EventType is a representation of GDK's GdkEventType.
406// Do not confuse these event types with the signals that GTK+ widgets emit
407type EventType int
408
409func marshalEventType(p uintptr) (interface{}, error) {
410	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
411	return EventType(c), nil
412}
413
414const (
415	EVENT_NOTHING             EventType = C.GDK_NOTHING
416	EVENT_DELETE              EventType = C.GDK_DELETE
417	EVENT_DESTROY             EventType = C.GDK_DESTROY
418	EVENT_EXPOSE              EventType = C.GDK_EXPOSE
419	EVENT_MOTION_NOTIFY       EventType = C.GDK_MOTION_NOTIFY
420	EVENT_BUTTON_PRESS        EventType = C.GDK_BUTTON_PRESS
421	EVENT_2BUTTON_PRESS       EventType = C.GDK_2BUTTON_PRESS
422	EVENT_DOUBLE_BUTTON_PRESS EventType = C.GDK_DOUBLE_BUTTON_PRESS
423	EVENT_3BUTTON_PRESS       EventType = C.GDK_3BUTTON_PRESS
424	EVENT_TRIPLE_BUTTON_PRESS EventType = C.GDK_TRIPLE_BUTTON_PRESS
425	EVENT_BUTTON_RELEASE      EventType = C.GDK_BUTTON_RELEASE
426	EVENT_KEY_PRESS           EventType = C.GDK_KEY_PRESS
427	EVENT_KEY_RELEASE         EventType = C.GDK_KEY_RELEASE
428	EVENT_ENTER_NOTIFY        EventType = C.GDK_ENTER_NOTIFY
429	EVENT_LEAVE_NOTIFY        EventType = C.GDK_LEAVE_NOTIFY
430	EVENT_FOCUS_CHANGE        EventType = C.GDK_FOCUS_CHANGE
431	EVENT_CONFIGURE           EventType = C.GDK_CONFIGURE
432	EVENT_MAP                 EventType = C.GDK_MAP
433	EVENT_UNMAP               EventType = C.GDK_UNMAP
434	EVENT_PROPERTY_NOTIFY     EventType = C.GDK_PROPERTY_NOTIFY
435	EVENT_SELECTION_CLEAR     EventType = C.GDK_SELECTION_CLEAR
436	EVENT_SELECTION_REQUEST   EventType = C.GDK_SELECTION_REQUEST
437	EVENT_SELECTION_NOTIFY    EventType = C.GDK_SELECTION_NOTIFY
438	EVENT_PROXIMITY_IN        EventType = C.GDK_PROXIMITY_IN
439	EVENT_PROXIMITY_OUT       EventType = C.GDK_PROXIMITY_OUT
440	EVENT_DRAG_ENTER          EventType = C.GDK_DRAG_ENTER
441	EVENT_DRAG_LEAVE          EventType = C.GDK_DRAG_LEAVE
442	EVENT_DRAG_MOTION         EventType = C.GDK_DRAG_MOTION
443	EVENT_DRAG_STATUS         EventType = C.GDK_DRAG_STATUS
444	EVENT_DROP_START          EventType = C.GDK_DROP_START
445	EVENT_DROP_FINISHED       EventType = C.GDK_DROP_FINISHED
446	EVENT_CLIENT_EVENT        EventType = C.GDK_CLIENT_EVENT
447	EVENT_VISIBILITY_NOTIFY   EventType = C.GDK_VISIBILITY_NOTIFY
448	EVENT_SCROLL              EventType = C.GDK_SCROLL
449	EVENT_WINDOW_STATE        EventType = C.GDK_WINDOW_STATE
450	EVENT_SETTING             EventType = C.GDK_SETTING
451	EVENT_OWNER_CHANGE        EventType = C.GDK_OWNER_CHANGE
452	EVENT_GRAB_BROKEN         EventType = C.GDK_GRAB_BROKEN
453	EVENT_DAMAGE              EventType = C.GDK_DAMAGE
454	EVENT_TOUCH_BEGIN         EventType = C.GDK_TOUCH_BEGIN
455	EVENT_TOUCH_UPDATE        EventType = C.GDK_TOUCH_UPDATE
456	EVENT_TOUCH_END           EventType = C.GDK_TOUCH_END
457	EVENT_TOUCH_CANCEL        EventType = C.GDK_TOUCH_CANCEL
458	EVENT_LAST                EventType = C.GDK_EVENT_LAST
459)
460
461/*
462 * General
463 */
464
465// TODO:
466// gdk_init().
467// gdk_init_check().
468// gdk_parse_args().
469// gdk_get_display_arg_name().
470// gdk_notify_startup_complete().
471// gdk_notify_startup_complete_with_id().
472// gdk_get_program_class().
473// gdk_set_program_class().
474// gdk_get_display(). deprecated since version 3.8
475// gdk_flush(). deprecated
476// gdk_screen_width(). deprecated since version 3.22
477// gdk_screen_height(). deprecated since version 3.22
478// gdk_screen_width_mm(). deprecated since version 3.22
479// gdk_screen_height_mm(). deprecated since version 3.22
480// gdk_set_double_click_time(). deprecated
481// gdk_beep(). deprecated
482// gdk_error_trap_push(). deprecated
483// gdk_error_trap_pop(). deprecated
484// gdk_error_trap_pop_ignored(). deprecated
485
486// SetAllowedBackends is a wrapper around gdk_set_allowed_backends
487func SetAllowedBackends(backends string) {
488	cstr := C.CString(backends)
489	defer C.free(unsafe.Pointer(cstr))
490	C.gdk_set_allowed_backends((*C.gchar)(cstr))
491}
492
493/*
494 * GdkAtom
495 */
496
497// Atom is a representation of GDK's GdkAtom.
498type Atom uintptr
499
500// native returns the underlying GdkAtom.
501func (v Atom) native() C.GdkAtom {
502	return C.toGdkAtom(unsafe.Pointer(uintptr(v)))
503}
504
505func (v Atom) Name() string {
506	c := C.gdk_atom_name(v.native())
507	defer C.g_free(C.gpointer(c))
508	return C.GoString((*C.char)(c))
509}
510
511// GdkAtomIntern is a wrapper around gdk_atom_intern
512func GdkAtomIntern(atomName string, onlyIfExists bool) Atom {
513	cstr := C.CString(atomName)
514	defer C.free(unsafe.Pointer(cstr))
515	c := C.gdk_atom_intern((*C.gchar)(cstr), gbool(onlyIfExists))
516	return Atom(uintptr(unsafe.Pointer(c)))
517}
518
519/*
520 * GdkDevice
521 */
522
523// Device is a representation of GDK's GdkDevice.
524type Device struct {
525	*glib.Object
526}
527
528// native returns a pointer to the underlying GdkDevice.
529func (v *Device) native() *C.GdkDevice {
530	if v == nil || v.GObject == nil {
531		return nil
532	}
533	p := unsafe.Pointer(v.GObject)
534	return C.toGdkDevice(p)
535}
536
537// Native returns a pointer to the underlying GdkDevice.
538func (v *Device) Native() uintptr {
539	return uintptr(unsafe.Pointer(v.native()))
540}
541
542func marshalDevice(p uintptr) (interface{}, error) {
543	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
544	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
545	return &Device{obj}, nil
546}
547
548func toDevice(d *C.GdkDevice) (*Device, error) {
549	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(d))}
550	return &Device{obj}, nil
551}
552
553func (v *Device) GetPosition(screen **Screen, x, y *int) error {
554	cs := (**C.GdkScreen)(unsafe.Pointer(uintptr(0)))
555	if screen != nil {
556		var cval *C.GdkScreen
557		cs = &cval
558	}
559
560	cx := (*C.gint)(unsafe.Pointer(uintptr(0)))
561	if x != nil {
562		var cval C.gint
563		cx = &cval
564	}
565
566	cy := (*C.gint)(unsafe.Pointer(uintptr(0)))
567	if y != nil {
568		var cval C.gint
569		cy = &cval
570	}
571	C.gdk_device_get_position(v.native(), cs, cx, cy)
572
573	if cs != (**C.GdkScreen)(unsafe.Pointer(uintptr(0))) {
574		ms, err := toScreen(*cs)
575		if err != nil {
576			return err
577		}
578		*screen = ms
579	}
580	if cx != (*C.gint)(unsafe.Pointer(uintptr(0))) {
581		*x = int(*cx)
582	}
583	if cy != (*C.gint)(unsafe.Pointer(uintptr(0))) {
584		*y = int(*cy)
585	}
586	return nil
587}
588
589// TODO:
590// gdk_device_get_name().
591// gdk_device_get_source().
592// gdk_device_set_mode().
593// gdk_device_get_mode().
594// gdk_device_set_key().
595// gdk_device_get_key().
596// gdk_device_set_axis_use().
597// gdk_device_get_axis_use().
598// gdk_device_get_associated_device().
599// gdk_device_list_slave_devices().
600// gdk_device_get_device_type().
601// gdk_device_get_display().
602// gdk_device_get_has_cursor().
603// gdk_device_get_n_axes().
604// gdk_device_get_n_keys().
605// gdk_device_warp().
606// gdk_device_get_state().
607// gdk_device_get_window_at_position().
608// gdk_device_get_window_at_position_double().
609// gdk_device_get_history().
610// gdk_device_free_history().
611// gdk_device_get_axis().
612// gdk_device_list_axes().
613// gdk_device_get_axis_value().
614
615/*
616 * GdkCursor
617 */
618
619// Cursor is a representation of GdkCursor.
620type Cursor struct {
621	*glib.Object
622}
623
624// CursorNewFromName is a wrapper around gdk_cursor_new_from_name().
625func CursorNewFromName(display *Display, name string) (*Cursor, error) {
626	cstr := C.CString(name)
627	defer C.free(unsafe.Pointer(cstr))
628	c := C.gdk_cursor_new_from_name(display.native(), (*C.gchar)(cstr))
629	if c == nil {
630		return nil, nilPtrErr
631	}
632
633	return &Cursor{glib.Take(unsafe.Pointer(c))}, nil
634}
635
636// native returns a pointer to the underlying GdkCursor.
637func (v *Cursor) native() *C.GdkCursor {
638	if v == nil || v.GObject == nil {
639		return nil
640	}
641	p := unsafe.Pointer(v.GObject)
642	return C.toGdkCursor(p)
643}
644
645// Native returns a pointer to the underlying GdkCursor.
646func (v *Cursor) Native() uintptr {
647	return uintptr(unsafe.Pointer(v.native()))
648}
649
650func marshalCursor(p uintptr) (interface{}, error) {
651	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
652	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
653	return &Cursor{obj}, nil
654}
655
656/*
657 * GdkDeviceManager
658 */
659
660// DeviceManager is a representation of GDK's GdkDeviceManager.
661type DeviceManager struct {
662	*glib.Object
663}
664
665// native returns a pointer to the underlying GdkDeviceManager.
666func (v *DeviceManager) native() *C.GdkDeviceManager {
667	if v == nil || v.GObject == nil {
668		return nil
669	}
670	p := unsafe.Pointer(v.GObject)
671	return C.toGdkDeviceManager(p)
672}
673
674// Native returns a pointer to the underlying GdkDeviceManager.
675func (v *DeviceManager) Native() uintptr {
676	return uintptr(unsafe.Pointer(v.native()))
677}
678
679func marshalDeviceManager(p uintptr) (interface{}, error) {
680	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
681	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
682	return &DeviceManager{obj}, nil
683}
684
685// GetDisplay() is a wrapper around gdk_device_manager_get_display().
686func (v *DeviceManager) GetDisplay() (*Display, error) {
687	c := C.gdk_device_manager_get_display(v.native())
688	if c == nil {
689		return nil, nilPtrErr
690	}
691
692	return &Display{glib.Take(unsafe.Pointer(c))}, nil
693}
694
695/*
696 * GdkDisplay
697 */
698
699// Display is a representation of GDK's GdkDisplay.
700type Display struct {
701	*glib.Object
702}
703
704// native returns a pointer to the underlying GdkDisplay.
705func (v *Display) native() *C.GdkDisplay {
706	if v == nil || v.GObject == nil {
707		return nil
708	}
709	p := unsafe.Pointer(v.GObject)
710	return C.toGdkDisplay(p)
711}
712
713// Native returns a pointer to the underlying GdkDisplay.
714func (v *Display) Native() uintptr {
715	return uintptr(unsafe.Pointer(v.native()))
716}
717
718func marshalDisplay(p uintptr) (interface{}, error) {
719	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
720	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
721	return &Display{obj}, nil
722}
723
724func toDisplay(s *C.GdkDisplay) (*Display, error) {
725	if s == nil {
726		return nil, nilPtrErr
727	}
728	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(s))}
729	return &Display{obj}, nil
730}
731
732// DisplayOpen is a wrapper around gdk_display_open().
733func DisplayOpen(displayName string) (*Display, error) {
734	cstr := C.CString(displayName)
735	defer C.free(unsafe.Pointer(cstr))
736	c := C.gdk_display_open((*C.gchar)(cstr))
737	if c == nil {
738		return nil, nilPtrErr
739	}
740
741	return &Display{glib.Take(unsafe.Pointer(c))}, nil
742}
743
744// DisplayGetDefault is a wrapper around gdk_display_get_default().
745func DisplayGetDefault() (*Display, error) {
746	c := C.gdk_display_get_default()
747	if c == nil {
748		return nil, nilPtrErr
749	}
750
751	return &Display{glib.Take(unsafe.Pointer(c))}, nil
752}
753
754// GetName is a wrapper around gdk_display_get_name().
755func (v *Display) GetName() (string, error) {
756	c := C.gdk_display_get_name(v.native())
757	if c == nil {
758		return "", nilPtrErr
759	}
760	return C.GoString((*C.char)(c)), nil
761}
762
763// GetDefaultScreen is a wrapper around gdk_display_get_default_screen().
764func (v *Display) GetDefaultScreen() (*Screen, error) {
765	c := C.gdk_display_get_default_screen(v.native())
766	if c == nil {
767		return nil, nilPtrErr
768	}
769
770	return &Screen{glib.Take(unsafe.Pointer(c))}, nil
771}
772
773// DeviceIsGrabbed is a wrapper around gdk_display_device_is_grabbed().
774func (v *Display) DeviceIsGrabbed(device *Device) bool {
775	c := C.gdk_display_device_is_grabbed(v.native(), device.native())
776	return gobool(c)
777}
778
779// Beep is a wrapper around gdk_display_beep().
780func (v *Display) Beep() {
781	C.gdk_display_beep(v.native())
782}
783
784// Sync is a wrapper around gdk_display_sync().
785func (v *Display) Sync() {
786	C.gdk_display_sync(v.native())
787}
788
789// Flush is a wrapper around gdk_display_flush().
790func (v *Display) Flush() {
791	C.gdk_display_flush(v.native())
792}
793
794// Close is a wrapper around gdk_display_close().
795func (v *Display) Close() {
796	C.gdk_display_close(v.native())
797}
798
799// IsClosed is a wrapper around gdk_display_is_closed().
800func (v *Display) IsClosed() bool {
801	c := C.gdk_display_is_closed(v.native())
802	return gobool(c)
803}
804
805// GetEvent is a wrapper around gdk_display_get_event().
806func (v *Display) GetEvent() (*Event, error) {
807	c := C.gdk_display_get_event(v.native())
808	if c == nil {
809		return nil, nilPtrErr
810	}
811
812	//The finalizer is not on the glib.Object but on the event.
813	e := &Event{c}
814	runtime.SetFinalizer(e, (*Event).free)
815	return e, nil
816}
817
818// PeekEvent is a wrapper around gdk_display_peek_event().
819func (v *Display) PeekEvent() (*Event, error) {
820	c := C.gdk_display_peek_event(v.native())
821	if c == nil {
822		return nil, nilPtrErr
823	}
824
825	//The finalizer is not on the glib.Object but on the event.
826	e := &Event{c}
827	runtime.SetFinalizer(e, (*Event).free)
828	return e, nil
829}
830
831// PutEvent is a wrapper around gdk_display_put_event().
832func (v *Display) PutEvent(event *Event) {
833	C.gdk_display_put_event(v.native(), event.native())
834}
835
836// HasPending is a wrapper around gdk_display_has_pending().
837func (v *Display) HasPending() bool {
838	c := C.gdk_display_has_pending(v.native())
839	return gobool(c)
840}
841
842// SetDoubleClickTime is a wrapper around gdk_display_set_double_click_time().
843func (v *Display) SetDoubleClickTime(msec uint) {
844	C.gdk_display_set_double_click_time(v.native(), C.guint(msec))
845}
846
847// SetDoubleClickDistance is a wrapper around gdk_display_set_double_click_distance().
848func (v *Display) SetDoubleClickDistance(distance uint) {
849	C.gdk_display_set_double_click_distance(v.native(), C.guint(distance))
850}
851
852// SupportsColorCursor is a wrapper around gdk_display_supports_cursor_color().
853func (v *Display) SupportsColorCursor() bool {
854	c := C.gdk_display_supports_cursor_color(v.native())
855	return gobool(c)
856}
857
858// SupportsCursorAlpha is a wrapper around gdk_display_supports_cursor_alpha().
859func (v *Display) SupportsCursorAlpha() bool {
860	c := C.gdk_display_supports_cursor_alpha(v.native())
861	return gobool(c)
862}
863
864// GetDefaultCursorSize is a wrapper around gdk_display_get_default_cursor_size().
865func (v *Display) GetDefaultCursorSize() uint {
866	c := C.gdk_display_get_default_cursor_size(v.native())
867	return uint(c)
868}
869
870// GetMaximalCursorSize is a wrapper around gdk_display_get_maximal_cursor_size().
871func (v *Display) GetMaximalCursorSize() (width, height uint) {
872	var w, h C.guint
873	C.gdk_display_get_maximal_cursor_size(v.native(), &w, &h)
874	return uint(w), uint(h)
875}
876
877// GetDefaultGroup is a wrapper around gdk_display_get_default_group().
878func (v *Display) GetDefaultGroup() (*Window, error) {
879	c := C.gdk_display_get_default_group(v.native())
880	if c == nil {
881		return nil, nilPtrErr
882	}
883
884	return &Window{glib.Take(unsafe.Pointer(c))}, nil
885}
886
887// SupportsSelectionNotification is a wrapper around gdk_display_supports_selection_notification().
888func (v *Display) SupportsSelectionNotification() bool {
889	c := C.gdk_display_supports_selection_notification(v.native())
890	return gobool(c)
891}
892
893// RequestSelectionNotification is a wrapper around gdk_display_request_selection_notification().
894func (v *Display) RequestSelectionNotification(selection Atom) bool {
895	c := C.gdk_display_request_selection_notification(v.native(),
896		selection.native())
897	return gobool(c)
898}
899
900// SupportsClipboardPersistence is a wrapper around gdk_display_supports_clipboard_persistence().
901func (v *Display) SupportsClipboardPersistence() bool {
902	c := C.gdk_display_supports_clipboard_persistence(v.native())
903	return gobool(c)
904}
905
906// TODO:
907// gdk_display_store_clipboard().
908// func (v *Display) StoreClipboard(clipboardWindow *Window, time uint32, targets ...Atom) {
909// 	panic("Not implemented")
910// }
911
912// SupportsShapes is a wrapper around gdk_display_supports_shapes().
913func (v *Display) SupportsShapes() bool {
914	c := C.gdk_display_supports_shapes(v.native())
915	return gobool(c)
916}
917
918// SupportsInputShapes is a wrapper around gdk_display_supports_input_shapes().
919func (v *Display) SupportsInputShapes() bool {
920	c := C.gdk_display_supports_input_shapes(v.native())
921	return gobool(c)
922}
923
924// TODO:
925// gdk_display_get_app_launch_context().
926// func (v *Display) GetAppLaunchContext() {
927// 	panic("Not implemented")
928// }
929
930// NotifyStartupComplete is a wrapper around gdk_display_notify_startup_complete().
931func (v *Display) NotifyStartupComplete(startupID string) {
932	cstr := C.CString(startupID)
933	defer C.free(unsafe.Pointer(cstr))
934	C.gdk_display_notify_startup_complete(v.native(), (*C.gchar)(cstr))
935}
936
937/*
938 * GdkDisplayManager
939 */
940// DisplayManager is a representation of GDK's GdkDisplayManager.
941type DisplayManager struct {
942	*glib.Object
943}
944
945// native returns a pointer to the underlying GdkDisplayManager.
946func (v *DisplayManager) native() *C.GdkDisplayManager {
947	if v == nil || v.GObject == nil {
948		return nil
949	}
950	p := unsafe.Pointer(v.GObject)
951	return C.toGdkDisplayManager(p)
952}
953
954// Native returns a pointer to the underlying GdkDisplayManager.
955func (v *DisplayManager) Native() uintptr {
956	return uintptr(unsafe.Pointer(v.native()))
957}
958
959func marshalDisplayManager(p uintptr) (interface{}, error) {
960	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
961	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
962	return &DisplayManager{obj}, nil
963}
964
965func wrapDisplayManager(obj *glib.Object) *DisplayManager {
966	if obj == nil {
967		return nil
968	}
969	return &DisplayManager{obj}
970}
971
972// DisplayManagerGet is a wrapper around gdk_display_manager_get().
973func DisplayManagerGet() (*DisplayManager, error) {
974	c := C.gdk_display_manager_get()
975	if c == nil {
976		return nil, nilPtrErr
977	}
978	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
979	return &DisplayManager{obj}, nil
980}
981
982// GetDefaultDisplay is a wrapper around gdk_display_manager_get_default_display().
983func (v *DisplayManager) GetDefaultDisplay() (*Display, error) {
984	c := C.gdk_display_manager_get_default_display(v.native())
985	if c == nil {
986		return nil, nilPtrErr
987	}
988	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
989	return &Display{obj}, nil
990}
991
992// SetDefaultDisplay is a wrapper around gdk_display_manager_set_default_display().
993func (v *DisplayManager) SetDefaultDisplay(display *Display) {
994	C.gdk_display_manager_set_default_display(v.native(), display.native())
995}
996
997// ListDisplays is a wrapper around gdk_display_manager_list_displays().
998func (v *DisplayManager) ListDisplays() *[]Display {
999
1000	clist := C.gdk_display_manager_list_displays(v.native())
1001	if clist == nil {
1002		return nil
1003	}
1004	dlist := glib.WrapSList(uintptr(unsafe.Pointer(clist)))
1005	defer dlist.Free()
1006
1007	var displays = make([]Display, 0, dlist.Length())
1008	for ; dlist.DataRaw() != nil; dlist = dlist.Next() {
1009		d := (*C.GdkDisplay)(dlist.DataRaw())
1010		obj := &glib.Object{glib.ToGObject(unsafe.Pointer(d))}
1011		displays = append(displays, Display{obj})
1012	}
1013	return &displays
1014}
1015
1016// OpenDisplay is a representation of gdk_display_manager_open_display().
1017func (v *DisplayManager) OpenDisplay(name string) (*Display, error) {
1018	cstr := (*C.gchar)(C.CString(name))
1019	defer C.free(unsafe.Pointer(cstr))
1020
1021	c := C.gdk_display_manager_open_display(v.native(), cstr)
1022	if c == nil {
1023		return nil, nilPtrErr
1024	}
1025	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1026	return &Display{obj}, nil
1027}
1028
1029/*
1030 * GdkKeymap
1031 */
1032
1033type Keymap struct {
1034	*glib.Object
1035}
1036
1037// native returns a pointer to the underlying GdkKeymap.
1038func (v *Keymap) native() *C.GdkKeymap {
1039	if v == nil || v.GObject == nil {
1040		return nil
1041	}
1042	p := unsafe.Pointer(v.GObject)
1043	return C.toGdkKeymap(p)
1044}
1045
1046// Native returns a pointer to the underlying GdkKeymap.
1047func (v *Keymap) Native() uintptr {
1048	return uintptr(unsafe.Pointer(v.native()))
1049}
1050
1051func marshalKeymap(p uintptr) (interface{}, error) {
1052	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
1053	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1054	return &Keymap{obj}, nil
1055}
1056
1057func wrapKeymap(obj *glib.Object) *Keymap {
1058	return &Keymap{obj}
1059}
1060
1061// GetKeymap is a wrapper around gdk_keymap_get_for_display().
1062func (v *Display) GetKeymap() (*Keymap, error) {
1063	c := C.gdk_keymap_get_for_display(v.native())
1064	if c == nil {
1065		return nil, nilPtrErr
1066	}
1067	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1068	return &Keymap{obj}, nil
1069}
1070
1071// TranslateKeyboardState is a wrapper around gdk_keymap_translate_keyboard_state().
1072func (v *Keymap) TranslateKeyboardState(hardwareKeycode uint, state ModifierType, group int) (bool, *uint, *int, *int, *ModifierType) {
1073
1074	var cKeyval C.guint
1075	var keyval *uint
1076	var cEffectiveGroup, cLevel C.gint
1077	var effectiveGroup, level *int
1078	var cConsumedModifiers C.GdkModifierType
1079	var consumedModifiers *ModifierType
1080
1081	c := C.gdk_keymap_translate_keyboard_state(
1082		v.native(),
1083		C.guint(hardwareKeycode),
1084		C.GdkModifierType(state),
1085		C.gint(group),
1086		&cKeyval,
1087		&cEffectiveGroup,
1088		&cLevel,
1089		&cConsumedModifiers,
1090	)
1091
1092	if &cKeyval == nil {
1093		keyval = nil
1094	} else {
1095		*keyval = uint(cKeyval)
1096	}
1097	if &cEffectiveGroup == nil {
1098		effectiveGroup = nil
1099	} else {
1100		*effectiveGroup = int(cEffectiveGroup)
1101	}
1102	if &cLevel == nil {
1103		level = nil
1104	} else {
1105		*level = int(cLevel)
1106	}
1107	if &cConsumedModifiers == nil {
1108		consumedModifiers = nil
1109	} else {
1110		*consumedModifiers = ModifierType(cConsumedModifiers)
1111	}
1112
1113	return gobool(c), keyval, effectiveGroup, level, consumedModifiers
1114}
1115
1116// HaveBidiLayouts is a wrapper around gdk_keymap_have_bidi_layouts().
1117func (v *Keymap) HaveBidiLayouts() bool {
1118	return gobool(C.gdk_keymap_have_bidi_layouts(v.native()))
1119}
1120
1121// GetCapsLockState is a wrapper around gdk_keymap_get_caps_lock_state().
1122func (v *Keymap) GetCapsLockState() bool {
1123	return gobool(C.gdk_keymap_get_caps_lock_state(v.native()))
1124}
1125
1126// GetNumLockState is a wrapper around gdk_keymap_get_num_lock_state().
1127func (v *Keymap) GetNumLockState() bool {
1128	return gobool(C.gdk_keymap_get_num_lock_state(v.native()))
1129}
1130
1131// GetModifierState is a wrapper around gdk_keymap_get_modifier_state().
1132func (v *Keymap) GetModifierState() uint {
1133	return uint(C.gdk_keymap_get_modifier_state(v.native()))
1134}
1135
1136// TODO:
1137// gdk_keymap_get_default(). deprecated since 3.22
1138// gdk_keymap_get_direction().
1139// gdk_keymap_add_virtual_modifiers().
1140// gdk_keymap_map_virtual_modifiers().
1141// gdk_keymap_get_modifier_mask().
1142
1143/*
1144 * GdkKeymapKey
1145 */
1146
1147// TODO:
1148// gdk_keymap_lookup_key().
1149// gdk_keymap_get_entries_for_keyval().
1150// gdk_keymap_get_entries_for_keycode().
1151
1152/*
1153 * GDK Keyval
1154 */
1155
1156// TODO:
1157// gdk_keyval_name().
1158
1159// KeyvalFromName() is a wrapper around gdk_keyval_from_name().
1160func KeyvalFromName(keyvalName string) uint {
1161	str := (*C.gchar)(C.CString(keyvalName))
1162	defer C.free(unsafe.Pointer(str))
1163	return uint(C.gdk_keyval_from_name(str))
1164}
1165
1166// KeyvalConvertCase is a wrapper around gdk_keyval_convert_case().
1167func KeyvalConvertCase(v uint) (lower, upper uint) {
1168	var l, u C.guint
1169	l = 0
1170	u = 0
1171	C.gdk_keyval_convert_case(C.guint(v), &l, &u)
1172	return uint(l), uint(u)
1173}
1174
1175// KeyvalIsLower is a wrapper around gdk_keyval_is_lower().
1176func KeyvalIsLower(v uint) bool {
1177	return gobool(C.gdk_keyval_is_lower(C.guint(v)))
1178}
1179
1180// KeyvalIsUpper is a wrapper around gdk_keyval_is_upper().
1181func KeyvalIsUpper(v uint) bool {
1182	return gobool(C.gdk_keyval_is_upper(C.guint(v)))
1183}
1184
1185// KeyvalToLower is a wrapper around gdk_keyval_to_lower().
1186func KeyvalToLower(v uint) uint {
1187	return uint(C.gdk_keyval_to_lower(C.guint(v)))
1188}
1189
1190// KeyvalToUpper is a wrapper around gdk_keyval_to_upper().
1191func KeyvalToUpper(v uint) uint {
1192	return uint(C.gdk_keyval_to_upper(C.guint(v)))
1193}
1194
1195// KeyvalToUnicode is a wrapper around gdk_keyval_to_unicode().
1196func KeyvalToUnicode(v uint) rune {
1197	return rune(C.gdk_keyval_to_unicode(C.guint(v)))
1198}
1199
1200// UnicodeToKeyval is a wrapper around gdk_unicode_to_keyval().
1201func UnicodeToKeyval(v rune) uint {
1202	return uint(C.gdk_unicode_to_keyval(C.guint32(v)))
1203}
1204
1205/*
1206 * GdkDragContext
1207 */
1208
1209// DragContext is a representation of GDK's GdkDragContext.
1210type DragContext struct {
1211	*glib.Object
1212}
1213
1214// native returns a pointer to the underlying GdkDragContext.
1215func (v *DragContext) native() *C.GdkDragContext {
1216	if v == nil || v.GObject == nil {
1217		return nil
1218	}
1219	p := unsafe.Pointer(v.GObject)
1220	return C.toGdkDragContext(p)
1221}
1222
1223// Native returns a pointer to the underlying GdkDragContext.
1224func (v *DragContext) Native() uintptr {
1225	return uintptr(unsafe.Pointer(v.native()))
1226}
1227
1228func marshalDragContext(p uintptr) (interface{}, error) {
1229	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
1230	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1231	return &DragContext{obj}, nil
1232}
1233
1234func (v *DragContext) ListTargets() *glib.List {
1235	clist := C.gdk_drag_context_list_targets(v.native())
1236	if clist == nil {
1237		return nil
1238	}
1239	return glib.WrapList(uintptr(unsafe.Pointer(clist)))
1240}
1241
1242/*
1243 * GdkEvent
1244 */
1245
1246// Event is a representation of GDK's GdkEvent.
1247type Event struct {
1248	GdkEvent *C.GdkEvent
1249}
1250
1251// native returns a pointer to the underlying GdkEvent.
1252func (v *Event) native() *C.GdkEvent {
1253	if v == nil {
1254		return nil
1255	}
1256	return v.GdkEvent
1257}
1258
1259// Native returns a pointer to the underlying GdkEvent.
1260func (v *Event) Native() uintptr {
1261	return uintptr(unsafe.Pointer(v.native()))
1262}
1263
1264func marshalEvent(p uintptr) (interface{}, error) {
1265	c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p)))
1266	return &Event{(*C.GdkEvent)(unsafe.Pointer(c))}, nil
1267}
1268
1269func (v *Event) free() {
1270	C.gdk_event_free(v.native())
1271}
1272
1273/*
1274 * GdkEventButton
1275 */
1276
1277// EventButton is a representation of GDK's GdkEventButton.
1278type EventButton struct {
1279	*Event
1280}
1281
1282func EventButtonNew() *EventButton {
1283	ee := (*C.GdkEvent)(unsafe.Pointer(&C.GdkEventButton{}))
1284	ev := Event{ee}
1285	return &EventButton{&ev}
1286}
1287
1288// EventButtonNewFromEvent returns an EventButton from an Event.
1289//
1290// Using widget.Connect() for a key related signal such as
1291// "button-press-event" results in a *Event being passed as
1292// the callback's second argument. The argument is actually a
1293// *EventButton. EventButtonNewFromEvent provides a means of creating
1294// an EventKey from the Event.
1295func EventButtonNewFromEvent(event *Event) *EventButton {
1296	ee := (*C.GdkEvent)(unsafe.Pointer(event.native()))
1297	ev := Event{ee}
1298	return &EventButton{&ev}
1299}
1300
1301// Native returns a pointer to the underlying GdkEventButton.
1302func (v *EventButton) Native() uintptr {
1303	return uintptr(unsafe.Pointer(v.native()))
1304}
1305
1306func (v *EventButton) native() *C.GdkEventButton {
1307	return (*C.GdkEventButton)(unsafe.Pointer(v.Event.native()))
1308}
1309
1310func (v *EventButton) X() float64 {
1311	c := v.native().x
1312	return float64(c)
1313}
1314
1315func (v *EventButton) Y() float64 {
1316	c := v.native().y
1317	return float64(c)
1318}
1319
1320// XRoot returns the x coordinate of the pointer relative to the root of the screen.
1321func (v *EventButton) XRoot() float64 {
1322	c := v.native().x_root
1323	return float64(c)
1324}
1325
1326// YRoot returns the y coordinate of the pointer relative to the root of the screen.
1327func (v *EventButton) YRoot() float64 {
1328	c := v.native().y_root
1329	return float64(c)
1330}
1331
1332func (v *EventButton) Button() Button {
1333	c := v.native().button
1334	return Button(c)
1335}
1336
1337func (v *EventButton) State() uint {
1338	c := v.native().state
1339	return uint(c)
1340}
1341
1342// Time returns the time of the event in milliseconds.
1343func (v *EventButton) Time() uint32 {
1344	c := v.native().time
1345	return uint32(c)
1346}
1347
1348func (v *EventButton) Type() EventType {
1349	c := v.native()._type
1350	return EventType(c)
1351}
1352
1353func (v *EventButton) MotionVal() (float64, float64) {
1354	x := v.native().x
1355	y := v.native().y
1356	return float64(x), float64(y)
1357}
1358
1359func (v *EventButton) MotionValRoot() (float64, float64) {
1360	x := v.native().x_root
1361	y := v.native().y_root
1362	return float64(x), float64(y)
1363}
1364
1365/*
1366 * GdkEventKey
1367 */
1368
1369// EventKey is a representation of GDK's GdkEventKey.
1370type EventKey struct {
1371	*Event
1372}
1373
1374func EventKeyNew() *EventKey {
1375	ee := (*C.GdkEvent)(unsafe.Pointer(&C.GdkEventKey{}))
1376	ev := Event{ee}
1377	return &EventKey{&ev}
1378}
1379
1380// EventKeyNewFromEvent returns an EventKey from an Event.
1381//
1382// Using widget.Connect() for a key related signal such as
1383// "key-press-event" results in a *Event being passed as
1384// the callback's second argument. The argument is actually a
1385// *EventKey. EventKeyNewFromEvent provides a means of creating
1386// an EventKey from the Event.
1387func EventKeyNewFromEvent(event *Event) *EventKey {
1388	ee := (*C.GdkEvent)(unsafe.Pointer(event.native()))
1389	ev := Event{ee}
1390	return &EventKey{&ev}
1391}
1392
1393// Native returns a pointer to the underlying GdkEventKey.
1394func (v *EventKey) Native() uintptr {
1395	return uintptr(unsafe.Pointer(v.native()))
1396}
1397
1398func (v *EventKey) native() *C.GdkEventKey {
1399	return (*C.GdkEventKey)(unsafe.Pointer(v.Event.native()))
1400}
1401
1402func (v *EventKey) KeyVal() uint {
1403	c := v.native().keyval
1404	return uint(c)
1405}
1406
1407func (v *EventKey) HardwareKeyCode() uint16 {
1408	c := v.native().hardware_keycode
1409	return uint16(c)
1410}
1411
1412func (v *EventKey) Type() EventType {
1413	c := v.native()._type
1414	return EventType(c)
1415}
1416
1417func (v *EventKey) State() uint {
1418	c := v.native().state
1419	return uint(c)
1420}
1421
1422/*
1423 * GdkEventMotion
1424 */
1425
1426type EventMotion struct {
1427	*Event
1428}
1429
1430func EventMotionNew() *EventMotion {
1431	ee := (*C.GdkEvent)(unsafe.Pointer(&C.GdkEventMotion{}))
1432	ev := Event{ee}
1433	return &EventMotion{&ev}
1434}
1435
1436// EventMotionNewFromEvent returns an EventMotion from an Event.
1437//
1438// Using widget.Connect() for a key related signal such as
1439// "button-press-event" results in a *Event being passed as
1440// the callback's second argument. The argument is actually a
1441// *EventMotion. EventMotionNewFromEvent provides a means of creating
1442// an EventKey from the Event.
1443func EventMotionNewFromEvent(event *Event) *EventMotion {
1444	ee := (*C.GdkEvent)(unsafe.Pointer(event.native()))
1445	ev := Event{ee}
1446	return &EventMotion{&ev}
1447}
1448
1449// Native returns a pointer to the underlying GdkEventMotion.
1450func (v *EventMotion) Native() uintptr {
1451	return uintptr(unsafe.Pointer(v.native()))
1452}
1453
1454func (v *EventMotion) native() *C.GdkEventMotion {
1455	return (*C.GdkEventMotion)(unsafe.Pointer(v.Event.native()))
1456}
1457
1458func (v *EventMotion) MotionVal() (float64, float64) {
1459	x := v.native().x
1460	y := v.native().y
1461	return float64(x), float64(y)
1462}
1463
1464func (v *EventMotion) MotionValRoot() (float64, float64) {
1465	x := v.native().x_root
1466	y := v.native().y_root
1467	return float64(x), float64(y)
1468}
1469
1470// Time returns the time of the event in milliseconds.
1471func (v *EventMotion) Time() uint32 {
1472	c := v.native().time
1473	return uint32(c)
1474}
1475
1476func (v *EventMotion) Type() EventType {
1477	c := v.native()._type
1478	return EventType(c)
1479}
1480
1481// A bit-mask representing the state of the modifier keys (e.g. Control, Shift
1482// and Alt) and the pointer buttons. See gdk.ModifierType constants.
1483func (v *EventMotion) State() ModifierType {
1484	c := v.native().state
1485	return ModifierType(c)
1486}
1487
1488/*
1489 * GdkEventCrossing
1490 */
1491
1492// EventCrossing is a representation of GDK's GdkEventCrossing.
1493type EventCrossing struct {
1494	*Event
1495}
1496
1497func EventCrossingNew() *EventCrossing {
1498	ee := (*C.GdkEvent)(unsafe.Pointer(&C.GdkEventCrossing{}))
1499	ev := Event{ee}
1500	return &EventCrossing{&ev}
1501}
1502
1503// EventCrossingNewFromEvent returns an EventCrossing from an Event.
1504//
1505// Using widget.Connect() for a key related signal such as
1506// "enter-notify-event" results in a *Event being passed as
1507// the callback's second argument. The argument is actually a
1508// *EventCrossing. EventCrossingNewFromEvent provides a means of creating
1509// an EventCrossing from the Event.
1510func EventCrossingNewFromEvent(event *Event) *EventCrossing {
1511	ee := (*C.GdkEvent)(unsafe.Pointer(event.native()))
1512	ev := Event{ee}
1513	return &EventCrossing{&ev}
1514}
1515
1516// Native returns a pointer to the underlying GdkEventCrossing.
1517func (v *EventCrossing) Native() uintptr {
1518	return uintptr(unsafe.Pointer(v.native()))
1519}
1520
1521func (v *EventCrossing) native() *C.GdkEventCrossing {
1522	return (*C.GdkEventCrossing)(unsafe.Pointer(v.Event.native()))
1523}
1524
1525func (v *EventCrossing) X() float64 {
1526	c := v.native().x
1527	return float64(c)
1528}
1529
1530func (v *EventCrossing) Y() float64 {
1531	c := v.native().y
1532	return float64(c)
1533}
1534
1535// XRoot returns the x coordinate of the pointer relative to the root of the screen.
1536func (v *EventCrossing) XRoot() float64 {
1537	c := v.native().x_root
1538	return float64(c)
1539}
1540
1541// YRoot returns the y coordinate of the pointer relative to the root of the screen.
1542func (v *EventCrossing) YRoot() float64 {
1543	c := v.native().y_root
1544	return float64(c)
1545}
1546
1547func (v *EventCrossing) State() uint {
1548	c := v.native().state
1549	return uint(c)
1550}
1551
1552// Time returns the time of the event in milliseconds.
1553func (v *EventCrossing) Time() uint32 {
1554	c := v.native().time
1555	return uint32(c)
1556}
1557
1558func (v *EventCrossing) Type() EventType {
1559	c := v.native()._type
1560	return EventType(c)
1561}
1562
1563func (v *EventCrossing) MotionVal() (float64, float64) {
1564	x := v.native().x
1565	y := v.native().y
1566	return float64(x), float64(y)
1567}
1568
1569func (v *EventCrossing) MotionValRoot() (float64, float64) {
1570	x := v.native().x_root
1571	y := v.native().y_root
1572	return float64(x), float64(y)
1573}
1574
1575func (v *EventCrossing) Mode() CrossingMode {
1576	c := v.native().mode
1577	return CrossingMode(c)
1578}
1579
1580func (v *EventCrossing) Detail() NotifyType {
1581	c := v.native().detail
1582	return NotifyType(c)
1583}
1584
1585func (v *EventCrossing) Focus() bool {
1586	c := v.native().focus
1587	return gobool(c)
1588}
1589
1590/*
1591 * GdkEventScroll
1592 */
1593
1594// EventScroll is a representation of GDK's GdkEventScroll.
1595type EventScroll struct {
1596	*Event
1597}
1598
1599func EventScrollNew() *EventScroll {
1600	ee := (*C.GdkEvent)(unsafe.Pointer(&C.GdkEventScroll{}))
1601	ev := Event{ee}
1602	return &EventScroll{&ev}
1603}
1604
1605// EventScrollNewFromEvent returns an EventScroll from an Event.
1606//
1607// Using widget.Connect() for a key related signal such as
1608// "button-press-event" results in a *Event being passed as
1609// the callback's second argument. The argument is actually a
1610// *EventScroll. EventScrollNewFromEvent provides a means of creating
1611// an EventKey from the Event.
1612func EventScrollNewFromEvent(event *Event) *EventScroll {
1613	ee := (*C.GdkEvent)(unsafe.Pointer(event.native()))
1614	ev := Event{ee}
1615	return &EventScroll{&ev}
1616}
1617
1618// Native returns a pointer to the underlying GdkEventScroll.
1619func (v *EventScroll) Native() uintptr {
1620	return uintptr(unsafe.Pointer(v.native()))
1621}
1622
1623func (v *EventScroll) native() *C.GdkEventScroll {
1624	return (*C.GdkEventScroll)(unsafe.Pointer(v.Event.native()))
1625}
1626
1627func (v *EventScroll) DeltaX() float64 {
1628	return float64(v.native().delta_x)
1629}
1630
1631func (v *EventScroll) DeltaY() float64 {
1632	return float64(v.native().delta_y)
1633}
1634
1635func (v *EventScroll) X() float64 {
1636	return float64(v.native().x)
1637}
1638
1639func (v *EventScroll) Y() float64 {
1640	return float64(v.native().y)
1641}
1642
1643func (v *EventScroll) Type() EventType {
1644	c := v.native()._type
1645	return EventType(c)
1646}
1647
1648func (v *EventScroll) Direction() ScrollDirection {
1649	c := v.native().direction
1650	return ScrollDirection(c)
1651}
1652
1653// A bit-mask representing the state of the modifier keys (e.g. Control, Shift
1654// and Alt) and the pointer buttons. See gdk.ModifierType constants.
1655func (v *EventScroll) State() ModifierType {
1656	c := v.native().state
1657	return ModifierType(c)
1658}
1659
1660/*
1661 * GdkEventWindowState
1662 */
1663
1664// EventWindowState is a representation of GDK's GdkEventWindowState.
1665type EventWindowState struct {
1666	*Event
1667}
1668
1669func EventWindowStateNew() *EventWindowState {
1670	ee := (*C.GdkEvent)(unsafe.Pointer(&C.GdkEventWindowState{}))
1671	ev := Event{ee}
1672	return &EventWindowState{&ev}
1673}
1674
1675// EventWindowStateNewFromEvent returns an EventWindowState from an Event.
1676//
1677// Using widget.Connect() for the
1678// "window-state-event" signal results in a *Event being passed as
1679// the callback's second argument. The argument is actually a
1680// *EventWindowState. EventWindowStateNewFromEvent provides a means of creating
1681// an EventWindowState from the Event.
1682func EventWindowStateNewFromEvent(event *Event) *EventWindowState {
1683	ee := (*C.GdkEvent)(unsafe.Pointer(event.native()))
1684	ev := Event{ee}
1685	return &EventWindowState{&ev}
1686}
1687
1688// Native returns a pointer to the underlying GdkEventWindowState.
1689func (v *EventWindowState) Native() uintptr {
1690	return uintptr(unsafe.Pointer(v.native()))
1691}
1692
1693func (v *EventWindowState) native() *C.GdkEventWindowState {
1694	return (*C.GdkEventWindowState)(unsafe.Pointer(v.Event.native()))
1695}
1696
1697func (v *EventWindowState) Type() EventType {
1698	c := v.native()._type
1699	return EventType(c)
1700}
1701
1702func (v *EventWindowState) ChangedMask() WindowState {
1703	c := v.native().changed_mask
1704	return WindowState(c)
1705}
1706
1707func (v *EventWindowState) NewWindowState() WindowState {
1708	c := v.native().new_window_state
1709	return WindowState(c)
1710}
1711
1712/*
1713 * GdkEventConfigure
1714 */
1715
1716// EventConfigure is a representation of GDK's GdkEventConfigure.
1717type EventConfigure struct {
1718	*Event
1719}
1720
1721func EventConfigureNew() *EventConfigure {
1722	ee := (*C.GdkEvent)(unsafe.Pointer(&C.GdkEventConfigure{}))
1723	ev := Event{ee}
1724	return &EventConfigure{&ev}
1725}
1726
1727// EventConfigureNewFromEvent returns an EventConfigure from an Event.
1728//
1729// Using widget.Connect() for the
1730// "configure-event" signal results in a *Event being passed as
1731// the callback's second argument. The argument is actually a
1732// *EventConfigure. EventConfigureNewFromEvent provides a means of creating
1733// an EventConfigure from the Event.
1734func EventConfigureNewFromEvent(event *Event) *EventConfigure {
1735	ee := (*C.GdkEvent)(unsafe.Pointer(event.native()))
1736	ev := Event{ee}
1737	return &EventConfigure{&ev}
1738}
1739
1740// Native returns a pointer to the underlying GdkEventConfigure.
1741func (v *EventConfigure) Native() uintptr {
1742	return uintptr(unsafe.Pointer(v.native()))
1743}
1744
1745func (v *EventConfigure) native() *C.GdkEventConfigure {
1746	return (*C.GdkEventConfigure)(unsafe.Pointer(v.Event.native()))
1747}
1748
1749func (v *EventConfigure) Type() EventType {
1750	c := v.native()._type
1751	return EventType(c)
1752}
1753
1754func (v *EventConfigure) X() int {
1755	c := v.native().x
1756	return int(c)
1757}
1758
1759func (v *EventConfigure) Y() int {
1760	c := v.native().y
1761	return int(c)
1762}
1763
1764func (v *EventConfigure) Width() int {
1765	c := v.native().width
1766	return int(c)
1767}
1768
1769func (v *EventConfigure) Height() int {
1770	c := v.native().height
1771	return int(c)
1772}
1773
1774/*
1775 * GdkGravity
1776 */
1777
1778type Gravity int
1779
1780const (
1781	GDK_GRAVITY_NORTH_WEST = C.GDK_GRAVITY_NORTH_WEST
1782	GDK_GRAVITY_NORTH      = C.GDK_GRAVITY_NORTH
1783	GDK_GRAVITY_NORTH_EAST = C.GDK_GRAVITY_NORTH_EAST
1784	GDK_GRAVITY_WEST       = C.GDK_GRAVITY_WEST
1785	GDK_GRAVITY_CENTER     = C.GDK_GRAVITY_CENTER
1786	GDK_GRAVITY_EAST       = C.GDK_GRAVITY_EAST
1787	GDK_GRAVITY_SOUTH_WEST = C.GDK_GRAVITY_SOUTH_WEST
1788	GDK_GRAVITY_SOUTH      = C.GDK_GRAVITY_SOUTH
1789	GDK_GRAVITY_SOUTH_EAST = C.GDK_GRAVITY_SOUTH_EAST
1790	GDK_GRAVITY_STATIC     = C.GDK_GRAVITY_STATIC
1791)
1792
1793func marshalGravity(p uintptr) (interface{}, error) {
1794	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
1795	return Gravity(c), nil
1796}
1797
1798/*
1799 * GdkRGBA
1800 */
1801// To create a GdkRGBA you have to use NewRGBA function.
1802type RGBA struct {
1803	rgba *C.GdkRGBA
1804}
1805
1806func marshalRGBA(p uintptr) (interface{}, error) {
1807	c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p)))
1808	return WrapRGBA(unsafe.Pointer(c)), nil
1809}
1810
1811func WrapRGBA(p unsafe.Pointer) *RGBA {
1812	return wrapRGBA((*C.GdkRGBA)(p))
1813}
1814
1815func wrapRGBA(cRgba *C.GdkRGBA) *RGBA {
1816	if cRgba == nil {
1817		return nil
1818	}
1819	return &RGBA{cRgba}
1820}
1821
1822func NewRGBA(values ...float64) *RGBA {
1823	cRgba := new(C.GdkRGBA)
1824	for i, value := range values {
1825		switch i {
1826		case 0:
1827			cRgba.red = C.gdouble(value)
1828		case 1:
1829			cRgba.green = C.gdouble(value)
1830		case 2:
1831			cRgba.blue = C.gdouble(value)
1832		case 3:
1833			cRgba.alpha = C.gdouble(value)
1834		}
1835	}
1836	return wrapRGBA(cRgba)
1837}
1838
1839func (c *RGBA) Floats() []float64 {
1840	return []float64{
1841		float64(c.rgba.red),
1842		float64(c.rgba.green),
1843		float64(c.rgba.blue),
1844		float64(c.rgba.alpha)}
1845}
1846
1847func (c *RGBA) Native() uintptr {
1848	return uintptr(unsafe.Pointer(c.rgba))
1849}
1850
1851// SetColors sets all colors values in the RGBA.
1852func (c *RGBA) SetColors(r, g, b, a float64) {
1853	c.rgba.red = C.gdouble(r)
1854	c.rgba.green = C.gdouble(g)
1855	c.rgba.blue = C.gdouble(b)
1856	c.rgba.alpha = C.gdouble(a)
1857}
1858
1859/*
1860 * The following methods (Get/Set) are made for
1861 * more convenient use of the GdkRGBA object
1862 */
1863// GetRed get red value from the RGBA.
1864func (c *RGBA) GetRed() float64 {
1865	return float64(c.rgba.red)
1866}
1867
1868// GetGreen get green value from the RGBA.
1869func (c *RGBA) GetGreen() float64 {
1870	return float64(c.rgba.green)
1871}
1872
1873// GetBlue get blue value from the RGBA.
1874func (c *RGBA) GetBlue() float64 {
1875	return float64(c.rgba.blue)
1876}
1877
1878// GetAlpha get alpha value from the RGBA.
1879func (c *RGBA) GetAlpha() float64 {
1880	return float64(c.rgba.alpha)
1881}
1882
1883// SetRed set red value in the RGBA.
1884func (c *RGBA) SetRed(red float64) {
1885	c.rgba.red = C.gdouble(red)
1886}
1887
1888// SetGreen set green value in the RGBA.
1889func (c *RGBA) SetGreen(green float64) {
1890	c.rgba.green = C.gdouble(green)
1891}
1892
1893// SetBlue set blue value in the RGBA.
1894func (c *RGBA) SetBlue(blue float64) {
1895	c.rgba.blue = C.gdouble(blue)
1896}
1897
1898// SetAlpha set alpha value in the RGBA.
1899func (c *RGBA) SetAlpha(alpha float64) {
1900	c.rgba.alpha = C.gdouble(alpha)
1901}
1902
1903// Parse is a representation of gdk_rgba_parse().
1904func (c *RGBA) Parse(spec string) bool {
1905	cstr := (*C.gchar)(C.CString(spec))
1906	defer C.free(unsafe.Pointer(cstr))
1907
1908	return gobool(C.gdk_rgba_parse(c.rgba, cstr))
1909}
1910
1911// String is a representation of gdk_rgba_to_string().
1912func (c *RGBA) String() string {
1913	return C.GoString((*C.char)(C.gdk_rgba_to_string(c.rgba)))
1914}
1915
1916// free is a representation of gdk_rgba_free().
1917func (c *RGBA) free() {
1918	C.gdk_rgba_free(c.rgba)
1919}
1920
1921// Copy is a representation of gdk_rgba_copy().
1922func (c *RGBA) Copy() (*RGBA, error) {
1923	cRgba := C.gdk_rgba_copy(c.rgba)
1924
1925	if c == nil {
1926		return nil, nilPtrErr
1927	}
1928	obj := wrapRGBA(cRgba)
1929
1930	runtime.SetFinalizer(obj, (*RGBA).free)
1931	return obj, nil
1932}
1933
1934// Equal is a representation of gdk_rgba_equal().
1935func (c *RGBA) Equal(rgba *RGBA) bool {
1936	return gobool(C.gdk_rgba_equal(
1937		C.gconstpointer(c.rgba),
1938		C.gconstpointer(rgba.rgba)))
1939}
1940
1941// Hash is a representation of gdk_rgba_hash().
1942func (c *RGBA) Hash() uint {
1943	return uint(C.gdk_rgba_hash(C.gconstpointer(c.rgba)))
1944}
1945
1946/*
1947 * GdkPoint
1948 */
1949
1950// Point is a representation of GDK's GdkPoint type.
1951type Point struct {
1952	GdkPoint C.GdkPoint
1953}
1954
1955func WrapPoint(p uintptr) *Point {
1956	return wrapPoint((*C.GdkPoint)(unsafe.Pointer(p)))
1957}
1958
1959func wrapPoint(obj *C.GdkPoint) *Point {
1960	if obj == nil {
1961		return nil
1962	}
1963	return &Point{*obj}
1964}
1965
1966// Native() returns a pointer to the underlying GdkPoint.
1967func (v *Point) native() *C.GdkPoint {
1968	return &v.GdkPoint
1969}
1970
1971// PointNew helper function to create a GdkPoint
1972func PointNew(x, y int) *Point {
1973	var p C.GdkPoint
1974	p.x = C.gint(x)
1975	p.y = C.gint(y)
1976	return &Point{p}
1977}
1978
1979// GetPointInt helper function to get GdkPoint values
1980func (v *Point) GetPointInt() (x, y int) {
1981	return int(v.native().x), int(v.native().y)
1982}
1983
1984// SetPointInt helper function to set GdkPoint values
1985func (v *Point) SetPointInt(x, y int) {
1986	v.native().x = C.gint(x)
1987	v.native().y = C.gint(y)
1988}
1989
1990// GetX returns x field of the underlying GdkPoint.
1991func (v *Point) GetX() int {
1992	return int(v.native().x)
1993}
1994
1995// SetX sets x field of the underlying GdkPoint.
1996func (v *Point) SetX(x int) {
1997	v.native().x = C.gint(x)
1998}
1999
2000// GetY returns y field of the underlying GdkPoint.
2001func (v *Point) GetY() int {
2002	return int(v.native().y)
2003}
2004
2005// SetY sets y field of the underlying GdkPoint.
2006func (v *Point) SetY(y int) {
2007	v.native().y = C.gint(y)
2008}
2009
2010/*
2011 * GdkRectangle
2012 */
2013
2014// Rectangle is a representation of GDK's GdkRectangle type.
2015type Rectangle struct {
2016	GdkRectangle C.GdkRectangle
2017}
2018
2019func WrapRectangle(p uintptr) *Rectangle {
2020	return wrapRectangle((*C.GdkRectangle)(unsafe.Pointer(p)))
2021}
2022
2023func wrapRectangle(obj *C.GdkRectangle) *Rectangle {
2024	if obj == nil {
2025		return nil
2026	}
2027	return &Rectangle{*obj}
2028}
2029
2030// Native() returns a pointer to the underlying GdkRectangle.
2031func (r *Rectangle) native() *C.GdkRectangle {
2032	return &r.GdkRectangle
2033}
2034
2035// RectangleIntersect is a wrapper around gdk_rectangle_intersect().
2036func (v *Rectangle) RectangleIntersect(rect *Rectangle) (*Rectangle, bool) {
2037	r := new(C.GdkRectangle)
2038	c := C.gdk_rectangle_intersect(v.native(), rect.native(), r)
2039	return wrapRectangle(r), gobool(c)
2040}
2041
2042// RectangleUnion is a wrapper around gdk_rectangle_union().
2043func (v *Rectangle) RectangleUnion(rect *Rectangle) *Rectangle {
2044	r := new(C.GdkRectangle)
2045	C.gdk_rectangle_union(v.native(), rect.native(), r)
2046	return wrapRectangle(r)
2047}
2048
2049// RectangleNew helper function to create a GdkRectanlge
2050func RectangleNew(x, y, width, height int) *Rectangle {
2051	var r C.GdkRectangle
2052	r.x = C.int(x)
2053	r.y = C.int(y)
2054	r.width = C.int(width)
2055	r.height = C.int(height)
2056	return &Rectangle{r}
2057}
2058
2059// SetRectangleInt helper function to set GdkRectanlge values
2060func (v *Rectangle) SetRectangleInt(x, y, width, height int) {
2061	v.native().x = C.int(x)
2062	v.native().y = C.int(y)
2063	v.native().width = C.int(width)
2064	v.native().height = C.int(height)
2065}
2066
2067// GetRectangleInt helper function to get GdkRectanlge values
2068func (v *Rectangle) GetRectangleInt() (x, y, width, height int) {
2069	return int(v.native().x),
2070		int(v.native().y),
2071		int(v.native().width),
2072		int(v.native().height)
2073}
2074
2075// GetX returns x field of the underlying GdkRectangle.
2076func (r *Rectangle) GetX() int {
2077	return int(r.native().x)
2078}
2079
2080// SetX sets x field of the underlying GdkRectangle.
2081func (r *Rectangle) SetX(x int) {
2082	r.native().x = C.int(x)
2083}
2084
2085// GetY returns y field of the underlying GdkRectangle.
2086func (r *Rectangle) GetY() int {
2087	return int(r.native().y)
2088}
2089
2090// SetY sets y field of the underlying GdkRectangle.
2091func (r *Rectangle) SetY(y int) {
2092	r.native().y = C.int(y)
2093}
2094
2095// GetWidth returns width field of the underlying GdkRectangle.
2096func (r *Rectangle) GetWidth() int {
2097	return int(r.native().width)
2098}
2099
2100// SetWidth sets width field of the underlying GdkRectangle.
2101func (r *Rectangle) SetWidth(width int) {
2102	r.native().width = C.int(width)
2103}
2104
2105// GetHeight returns height field of the underlying GdkRectangle.
2106func (r *Rectangle) GetHeight() int {
2107	return int(r.native().height)
2108}
2109
2110// SetHeight sets height field of the underlying GdkRectangle.
2111func (r *Rectangle) SetHeight(height int) {
2112	r.native().height = C.int(height)
2113}
2114
2115/*
2116 * GdkGeometry
2117 */
2118
2119type Geometry struct {
2120	GdkGeometry C.GdkGeometry
2121}
2122
2123func WrapGeometry(p uintptr) *Geometry {
2124	return wrapGeometry((*C.GdkGeometry)(unsafe.Pointer(p)))
2125}
2126
2127func wrapGeometry(obj *C.GdkGeometry) *Geometry {
2128	if obj == nil {
2129		return nil
2130	}
2131	return &Geometry{*obj}
2132}
2133
2134// native returns a pointer to the underlying GdkGeometry.
2135func (r *Geometry) native() *C.GdkGeometry {
2136	return &r.GdkGeometry
2137}
2138
2139// GetMinWidth returns min_width field of the underlying GdkGeometry.
2140func (r *Geometry) GetMinWidth() int {
2141	return int(r.native().min_width)
2142}
2143
2144// SetMinWidth sets min_width field of the underlying GdkGeometry.
2145func (r *Geometry) SetMinWidth(minWidth int) {
2146	r.native().min_width = C.gint(minWidth)
2147}
2148
2149// GetMinHeight returns min_height field of the underlying GdkGeometry.
2150func (r *Geometry) GetMinHeight() int {
2151	return int(r.native().min_height)
2152}
2153
2154// SetMinHeight sets min_height field of the underlying GdkGeometry.
2155func (r *Geometry) SetMinHeight(minHeight int) {
2156	r.native().min_height = C.gint(minHeight)
2157}
2158
2159// GetMaxWidth returns max_width field of the underlying GdkGeometry.
2160func (r *Geometry) GetMaxWidth() int {
2161	return int(r.native().max_width)
2162}
2163
2164// SetMaxWidth sets max_width field of the underlying GdkGeometry.
2165func (r *Geometry) SetMaxWidth(maxWidth int) {
2166	r.native().max_width = C.gint(maxWidth)
2167}
2168
2169// GetMaxHeight returns max_height field of the underlying GdkGeometry.
2170func (r *Geometry) GetMaxHeight() int {
2171	return int(r.native().max_height)
2172}
2173
2174// SetMaxHeight sets max_height field of the underlying GdkGeometry.
2175func (r *Geometry) SetMaxHeight(maxHeight int) {
2176	r.native().max_height = C.gint(maxHeight)
2177}
2178
2179// GetBaseWidth returns base_width field of the underlying GdkGeometry.
2180func (r *Geometry) GetBaseWidth() int {
2181	return int(r.native().base_width)
2182}
2183
2184// SetBaseWidth sets base_width field of the underlying GdkGeometry.
2185func (r *Geometry) SetBaseWidth(baseWidth int) {
2186	r.native().base_width = C.gint(baseWidth)
2187}
2188
2189// GetBaseHeight returns base_height field of the underlying GdkGeometry.
2190func (r *Geometry) GetBaseHeight() int {
2191	return int(r.native().base_height)
2192}
2193
2194// SetBaseHeight sets base_height field of the underlying GdkGeometry.
2195func (r *Geometry) SetBaseHeight(baseHeight int) {
2196	r.native().base_height = C.gint(baseHeight)
2197}
2198
2199// GetWidthInc returns width_inc field of the underlying GdkGeometry.
2200func (r *Geometry) GetWidthInc() int {
2201	return int(r.native().width_inc)
2202}
2203
2204// SetWidthInc sets width_inc field of the underlying GdkGeometry.
2205func (r *Geometry) SetWidthInc(widthInc int) {
2206	r.native().width_inc = C.gint(widthInc)
2207}
2208
2209// GetHeightInc returns height_inc field of the underlying GdkGeometry.
2210func (r *Geometry) GetHeightInc() int {
2211	return int(r.native().height_inc)
2212}
2213
2214// SetHeightInc sets height_inc field of the underlying GdkGeometry.
2215func (r *Geometry) SetHeightInc(heightInc int) {
2216	r.native().height_inc = C.gint(heightInc)
2217}
2218
2219// GetMinAspect returns min_aspect field of the underlying GdkGeometry.
2220func (r *Geometry) GetMinAspect() float64 {
2221	return float64(r.native().min_aspect)
2222}
2223
2224// SetMinAspect sets min_aspect field of the underlying GdkGeometry.
2225func (r *Geometry) SetMinAspect(minAspect float64) {
2226	r.native().min_aspect = C.gdouble(minAspect)
2227}
2228
2229// GetMaxAspect returns max_aspect field of the underlying GdkGeometry.
2230func (r *Geometry) GetMaxAspect() float64 {
2231	return float64(r.native().max_aspect)
2232}
2233
2234// SetMaxAspect sets max_aspect field of the underlying GdkGeometry.
2235func (r *Geometry) SetMaxAspect(maxAspect float64) {
2236	r.native().max_aspect = C.gdouble(maxAspect)
2237}
2238
2239// GetWinGravity returns win_gravity field of the underlying GdkGeometry.
2240func (r *Geometry) GetWinGravity() Gravity {
2241	return Gravity(r.native().win_gravity)
2242}
2243
2244// SetWinGravity sets win_gravity field of the underlying GdkGeometry.
2245func (r *Geometry) SetWinGravity(winGravity Gravity) {
2246	r.native().win_gravity = C.GdkGravity(winGravity)
2247}
2248
2249/*
2250 * GdkVisual
2251 */
2252
2253// Visual is a representation of GDK's GdkVisual.
2254type Visual struct {
2255	*glib.Object
2256}
2257
2258func (v *Visual) native() *C.GdkVisual {
2259	if v == nil || v.GObject == nil {
2260		return nil
2261	}
2262	p := unsafe.Pointer(v.GObject)
2263	return C.toGdkVisual(p)
2264}
2265
2266func (v *Visual) Native() uintptr {
2267	return uintptr(unsafe.Pointer(v.native()))
2268}
2269
2270func marshalVisual(p uintptr) (interface{}, error) {
2271	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
2272	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
2273	return &Visual{obj}, nil
2274}
2275
2276// GetBluePixelDetails is a wrapper around gdk_visual_get_blue_pixel_details().
2277func (v *Visual) GetBluePixelDetails() (*uint32, *int, *int) {
2278	var (
2279		m                *uint32 = nil
2280		s, p             *int    = nil, nil
2281		mask             C.guint32
2282		shift, precision C.gint
2283	)
2284	C.gdk_visual_get_blue_pixel_details(v.native(), &mask, &shift, &precision)
2285	if &mask != nil {
2286		m = new(uint32)
2287		*m = uint32(mask)
2288	}
2289	if &shift != nil {
2290		s = new(int)
2291		*s = int(shift)
2292	}
2293	if &precision != nil {
2294		p = new(int)
2295		*p = int(precision)
2296	}
2297	return m, s, p
2298}
2299
2300// GetDepth is a wrapper around gdk_visual_get_depth().
2301func (v *Visual) GetDepth() int {
2302	return int(C.gdk_visual_get_depth(v.native()))
2303}
2304
2305// GetGreenPixelDetails is a wrapper around gdk_visual_get_green_pixel_details().
2306func (v *Visual) GetGreenPixelDetails() (*uint32, *int, *int) {
2307	var (
2308		m                *uint32 = nil
2309		s, p             *int    = nil, nil
2310		mask             C.guint32
2311		shift, precision C.gint
2312	)
2313	C.gdk_visual_get_green_pixel_details(v.native(), &mask, &shift, &precision)
2314	if &mask != nil {
2315		m = new(uint32)
2316		*m = uint32(mask)
2317	}
2318	if &shift != nil {
2319		s = new(int)
2320		*s = int(shift)
2321	}
2322	if &precision != nil {
2323		p = new(int)
2324		*p = int(precision)
2325	}
2326	return m, s, p
2327}
2328
2329// GetRedPixelDetails is a wrapper around gdk_visual_get_red_pixel_details().
2330func (v *Visual) GetRedPixelDetails() (*uint32, *int, *int) {
2331	var (
2332		m                *uint32 = nil
2333		s, p             *int    = nil, nil
2334		mask             C.guint32
2335		shift, precision C.gint
2336	)
2337	C.gdk_visual_get_red_pixel_details(v.native(), &mask, &shift, &precision)
2338	if &mask != nil {
2339		m = new(uint32)
2340		*m = uint32(mask)
2341	}
2342	if &shift != nil {
2343		s = new(int)
2344		*s = int(shift)
2345	}
2346	if &precision != nil {
2347		p = new(int)
2348		*p = int(precision)
2349	}
2350	return m, s, p
2351}
2352
2353// GetVisualType is a wrapper around gdk_visual_get_visual_type().
2354func (v *Visual) GetVisualType() VisualType {
2355	return VisualType(C.gdk_visual_get_visual_type(v.native()))
2356}
2357
2358// GetScreen is a wrapper around gdk_visual_get_screen().
2359func (v *Visual) GetScreen() (*Screen, error) {
2360	return toScreen(C.gdk_visual_get_screen(v.native()))
2361}
2362
2363/*
2364 * GdkWindow
2365 */
2366
2367// Window is a representation of GDK's GdkWindow.
2368type Window struct {
2369	*glib.Object
2370}
2371
2372// SetCursor is a wrapper around gdk_window_set_cursor().
2373func (v *Window) SetCursor(cursor *Cursor) {
2374	C.gdk_window_set_cursor(v.native(), cursor.native())
2375}
2376
2377// native returns a pointer to the underlying GdkWindow.
2378func (v *Window) native() *C.GdkWindow {
2379	if v == nil || v.GObject == nil {
2380		return nil
2381	}
2382	p := unsafe.Pointer(v.GObject)
2383	return C.toGdkWindow(p)
2384}
2385
2386// Native returns a pointer to the underlying GdkWindow.
2387func (v *Window) Native() uintptr {
2388	return uintptr(unsafe.Pointer(v.native()))
2389}
2390
2391// WindowGetWidth is a wrapper around gdk_window_get_width()
2392func (v *Window) WindowGetWidth() (width int) {
2393	return int(C.gdk_window_get_width(v.native()))
2394}
2395
2396// WindowGetHeight is a wrapper around gdk_window_get_height()
2397func (v *Window) WindowGetHeight() (height int) {
2398	return int(C.gdk_window_get_height(v.native()))
2399}
2400
2401// CreateSimilarSurface is a wrapper around gdk_window_create_similar_surface().
2402func (v *Window) CreateSimilarSurface(content cairo.Content, w, h int) (*cairo.Surface, error) {
2403	surface := C.gdk_window_create_similar_surface(v.native(), C.cairo_content_t(content), C.gint(w), C.gint(h))
2404
2405	status := cairo.Status(C.cairo_surface_status(surface))
2406	if status != cairo.STATUS_SUCCESS {
2407		return nil, cairo.ErrorStatus(status)
2408	}
2409
2410	return cairo.NewSurface(uintptr(unsafe.Pointer(surface)), false), nil
2411}
2412
2413//PixbufGetFromWindow is a wrapper around gdk_pixbuf_get_from_window()
2414func (v *Window) PixbufGetFromWindow(x, y, w, h int) (*Pixbuf, error) {
2415	c := C.gdk_pixbuf_get_from_window(v.native(), C.gint(x), C.gint(y), C.gint(w), C.gint(h))
2416	if c == nil {
2417		return nil, nilPtrErr
2418	}
2419
2420	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
2421	p := &Pixbuf{obj}
2422	//obj.Ref()
2423	runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
2424	return p, nil
2425}
2426
2427// GetDevicePosition is a wrapper around gdk_window_get_device_position()
2428func (v *Window) GetDevicePosition(d *Device) (*Window, int, int, ModifierType) {
2429	var x C.gint
2430	var y C.gint
2431	var mt C.GdkModifierType
2432	underneathWindow := C.gdk_window_get_device_position(v.native(), d.native(), &x, &y, &mt)
2433	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(underneathWindow))}
2434	rw := &Window{obj}
2435	runtime.SetFinalizer(rw, func(_ interface{}) { obj.Unref() })
2436	return rw, int(x), int(y), ModifierType(mt)
2437}
2438
2439func PixbufGetFromSurface(surface *cairo.Surface, src_x, src_y, width, height int) (*Pixbuf, error) {
2440	c := C.gdk_pixbuf_get_from_surface((*C.cairo_surface_t)(unsafe.Pointer(surface.Native())), C.gint(src_x), C.gint(src_y), C.gint(width), C.gint(height))
2441	if c == nil {
2442		return nil, nilPtrErr
2443	}
2444
2445	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
2446	p := &Pixbuf{obj}
2447	//obj.Ref()
2448	runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
2449	return p, nil
2450}
2451
2452func marshalWindow(p uintptr) (interface{}, error) {
2453	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
2454	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
2455	return &Window{obj}, nil
2456}
2457
2458func toWindow(s *C.GdkWindow) (*Window, error) {
2459	if s == nil {
2460		return nil, nilPtrErr
2461	}
2462	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(s))}
2463	return &Window{obj}, nil
2464}
2465