forked from conformal/gotk3
/
gdk.go
914 lines (784 loc) · 24.7 KB
/
gdk.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
// Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
//
// This file originated from: http://opensource.conformal.com/
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
// Go bindings for GDK 3. Supports version 3.6 and later.
package gdk
// #cgo pkg-config: gdk-3.0
// #include <gdk/gdk.h>
// #include "gdk.go.h"
import "C"
import (
"errors"
"reflect"
"runtime"
"unsafe"
"github.com/visionect/gotk3/glib"
"github.com/visionect/gotk3/cairo"
)
func init() {
tm := []glib.TypeMarshaler{
// Enums
{glib.Type(C.gdk_colorspace_get_type()), marshalColorspace},
{glib.Type(C.gdk_interp_type_get_type()), marshalInterpType},
{glib.Type(C.gdk_pixbuf_alpha_mode_get_type()), marshalPixbufAlphaMode},
// Objects/Interfaces
{glib.Type(C.gdk_device_get_type()), marshalDevice},
{glib.Type(C.gdk_device_manager_get_type()), marshalDeviceManager},
{glib.Type(C.gdk_display_get_type()), marshalDisplay},
{glib.Type(C.gdk_pixbuf_get_type()), marshalPixbuf},
{glib.Type(C.gdk_screen_get_type()), marshalScreen},
{glib.Type(C.gdk_visual_get_type()), marshalVisual},
{glib.Type(C.gdk_window_get_type()), marshalWindow},
// Boxed
{glib.Type(C.gdk_event_get_type()), marshalEvent},
}
glib.RegisterGValueMarshalers(tm)
}
/*
* Type conversions
*/
func gbool(b bool) C.gboolean {
if b {
return C.gboolean(1)
}
return C.gboolean(0)
}
func gobool(b C.gboolean) bool {
if b != 0 {
return true
}
return false
}
/*
* Unexported vars
*/
var nilPtrErr = errors.New("cgo returned unexpected nil pointer")
/*
* Constants
*/
// Colorspace is a representation of GDK's GdkColorspace.
type Colorspace int
const (
COLORSPACE_RGB Colorspace = C.GDK_COLORSPACE_RGB
)
func marshalColorspace(p uintptr) (interface{}, error) {
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
return Colorspace(c), nil
}
// InterpType is a representation of GDK's GdkInterpType.
type InterpType int
const (
INTERP_NEAREST InterpType = C.GDK_INTERP_NEAREST
INTERP_TILES InterpType = C.GDK_INTERP_TILES
INTERP_BILINEAR InterpType = C.GDK_INTERP_BILINEAR
INTERP_HYPER InterpType = C.GDK_INTERP_HYPER
)
// PixbufRotation is a representation of GDK's GdkPixbufRotation.
type PixbufRotation int
const (
PIXBUF_ROTATE_NONE PixbufRotation = C.GDK_PIXBUF_ROTATE_NONE
PIXBUF_ROTATE_COUNTERCLOCKWISE PixbufRotation = C.GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE
PIXBUF_ROTATE_UPSIDEDOWN PixbufRotation = C.GDK_PIXBUF_ROTATE_UPSIDEDOWN
PIXBUF_ROTATE_CLOCKWISE PixbufRotation = C.GDK_PIXBUF_ROTATE_CLOCKWISE
)
func marshalInterpType(p uintptr) (interface{}, error) {
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
return InterpType(c), nil
}
// PixbufAlphaMode is a representation of GDK's GdkPixbufAlphaMode.
type PixbufAlphaMode int
const (
GDK_PIXBUF_ALPHA_BILEVEL PixbufAlphaMode = C.GDK_PIXBUF_ALPHA_BILEVEL
GDK_PIXBUF_ALPHA_FULL PixbufAlphaMode = C.GDK_PIXBUF_ALPHA_FULL
)
func marshalPixbufAlphaMode(p uintptr) (interface{}, error) {
c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
return PixbufAlphaMode(c), nil
}
// Selections
const (
SELECTION_PRIMARY Atom = 1
SELECTION_SECONDARY Atom = 2
SELECTION_CLIPBOARD Atom = 69
TARGET_BITMAP Atom = 5
TARGET_COLORMAP Atom = 7
TARGET_DRAWABLE Atom = 17
TARGET_PIXMAP Atom = 20
TARGET_STRING Atom = 31
SELECTION_TYPE_ATOM Atom = 4
SELECTION_TYPE_BITMAP Atom = 5
SELECTION_TYPE_COLORMAP Atom = 7
SELECTION_TYPE_DRAWABLE Atom = 17
SELECTION_TYPE_INTEGER Atom = 19
SELECTION_TYPE_PIXMAP Atom = 20
SELECTION_TYPE_WINDOW Atom = 33
SELECTION_TYPE_STRING Atom = 31
)
/*At this moment VISIONECT specific*/
type EventMask uint
/*At this moment VISIONECT specific*/
// Event masks
const (
EXPOSURE_MASK EventMask = C.GDK_EXPOSURE_MASK
POINTER_MOTION_MASK = C.GDK_POINTER_MOTION_MASK
POINTER_MOTION_HINT = C.GDK_POINTER_MOTION_HINT_MASK
BUTTON_MOTION_MASK = C.GDK_BUTTON_MOTION_MASK
BUTTON1_MOTION_MASK = C.GDK_BUTTON1_MOTION_MASK
BUTTON2_MOTION_MASK = C.GDK_BUTTON2_MOTION_MASK
BUTTON3_MOTION_MASK = C.GDK_BUTTON3_MOTION_MASK
BUTTON_PRESS_MASK = C.GDK_BUTTON_PRESS_MASK
BUTTON_RELEASE_MASK = C.GDK_BUTTON_RELEASE_MASK
KEY_PRESS_MASK = C.GDK_KEY_PRESS_MASK
KEY_RELEASE_MASK = C.GDK_KEY_RELEASE_MASK
ENTER_NOTIFY_MASK = C.GDK_ENTER_NOTIFY_MASK
LEAVE_NOTIFY_MASK = C.GDK_LEAVE_NOTIFY_MASK
FOCUS_CHANGE_MASK = C.GDK_FOCUS_CHANGE_MASK
STRUCTURE_MASK = C.GDK_STRUCTURE_MASK
PROPERTY_CHANGE_MASK = C.GDK_PROPERTY_CHANGE_MASK
VISIBILITY_NOTIFY_MASK = C.GDK_VISIBILITY_NOTIFY_MASK
PROXIMITY_IN_MASK = C.GDK_PROXIMITY_IN_MASK
PROXIMITY_OUT_MASK = C.GDK_PROXIMITY_OUT_MASK
SUBSTRUCTURE_MASK = C.GDK_SUBSTRUCTURE_MASK
SCROLL_MASK = C.GDK_SCROLL_MASK
ALL_EVENTS_MASK = C.GDK_ALL_EVENTS_MASK
)
/*
* GdkAtom
*/
// Atom is a representation of GDK's GdkAtom.
type Atom uintptr
// native returns the underlying GdkAtom.
func (v Atom) native() C.GdkAtom {
return C.toGdkAtom(unsafe.Pointer(uintptr(v)))
}
/*
* GdkDevice
*/
// Device is a representation of GDK's GdkDevice.
type Device struct {
*glib.Object
}
// native returns a pointer to the underlying GdkDevice.
func (v *Device) native() *C.GdkDevice {
if v == nil || v.GObject == nil {
return nil
}
p := unsafe.Pointer(v.GObject)
return C.toGdkDevice(p)
}
// Native returns a pointer to the underlying GdkDevice.
func (v *Device) Native() uintptr {
return uintptr(unsafe.Pointer(v.native()))
}
func marshalDevice(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
return &Device{obj}, nil
}
/*
* GdkDeviceManager
*/
// DeviceManager is a representation of GDK's GdkDeviceManager.
type DeviceManager struct {
*glib.Object
}
// native returns a pointer to the underlying GdkDeviceManager.
func (v *DeviceManager) native() *C.GdkDeviceManager {
if v == nil || v.GObject == nil {
return nil
}
p := unsafe.Pointer(v.GObject)
return C.toGdkDeviceManager(p)
}
// Native returns a pointer to the underlying GdkDeviceManager.
func (v *DeviceManager) Native() uintptr {
return uintptr(unsafe.Pointer(v.native()))
}
func marshalDeviceManager(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
return &DeviceManager{obj}, nil
}
/*
* GdkDisplay
*/
// Display is a representation of GDK's GdkDisplay.
type Display struct {
*glib.Object
}
// native returns a pointer to the underlying GdkDisplay.
func (v *Display) native() *C.GdkDisplay {
if v == nil || v.GObject == nil {
return nil
}
p := unsafe.Pointer(v.GObject)
return C.toGdkDisplay(p)
}
// Native returns a pointer to the underlying GdkDisplay.
func (v *Display) Native() uintptr {
return uintptr(unsafe.Pointer(v.native()))
}
func marshalDisplay(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
return &Display{obj}, nil
}
// DisplayOpen() is a wrapper around gdk_display_open().
func DisplayOpen(displayName string) (*Display, error) {
cstr := C.CString(displayName)
defer C.free(unsafe.Pointer(cstr))
c := C.gdk_display_open((*C.gchar)(cstr))
if c == nil {
return nil, nilPtrErr
}
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
d := &Display{obj}
obj.Ref()
runtime.SetFinalizer(obj, (*glib.Object).Unref)
return d, nil
}
// DisplayGetDefault() is a wrapper around gdk_display_get_default().
func DisplayGetDefault() (*Display, error) {
c := C.gdk_display_get_default()
if c == nil {
return nil, nilPtrErr
}
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
d := &Display{obj}
obj.Ref()
runtime.SetFinalizer(obj, (*glib.Object).Unref)
return d, nil
}
func CairoCreate(window *Window) *cairo.Context {
ctx := C.gdk_cairo_create(window.native())
if ctx == nil {
return nil
}
return cairo.WrapContext(unsafe.Pointer(ctx))
}
// GetName() is a wrapper around gdk_display_get_name().
func (v *Display) GetName() (string, error) {
c := C.gdk_display_get_name(v.native())
if c == nil {
return "", nilPtrErr
}
return C.GoString((*C.char)(c)), nil
}
// GetScreen() is a wrapper around gdk_display_get_screen().
func (v *Display) GetScreen(screenNum int) (*Screen, error) {
c := C.gdk_display_get_screen(v.native(), C.gint(screenNum))
if c == nil {
return nil, nilPtrErr
}
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
s := &Screen{obj}
obj.Ref()
runtime.SetFinalizer(obj, (*glib.Object).Unref)
return s, nil
}
// GetDefaultScreen() is a wrapper around gdk_display_get_default_screen().
func (v *Display) GetDefaultScreen() (*Screen, error) {
c := C.gdk_display_get_default_screen(v.native())
if c == nil {
return nil, nilPtrErr
}
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
s := &Screen{obj}
obj.Ref()
runtime.SetFinalizer(obj, (*glib.Object).Unref)
return s, nil
}
// GetDeviceManager() is a wrapper around gdk_display_get_device_manager().
func (v *Display) GetDeviceManager() (*DeviceManager, error) {
c := C.gdk_display_get_device_manager(v.native())
if c == nil {
return nil, nilPtrErr
}
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
d := &DeviceManager{obj}
obj.Ref()
runtime.SetFinalizer(obj, (*glib.Object).Unref)
return d, nil
}
// DeviceIsGrabbed() is a wrapper around gdk_display_device_is_grabbed().
func (v *Display) DeviceIsGrabbed(device *Device) bool {
c := C.gdk_display_device_is_grabbed(v.native(), device.native())
return gobool(c)
}
// Beep() is a wrapper around gdk_display_beep().
func (v *Display) Beep() {
C.gdk_display_beep(v.native())
}
// Sync() is a wrapper around gdk_display_sync().
func (v *Display) Sync() {
C.gdk_display_sync(v.native())
}
// Flush() is a wrapper around gdk_display_flush().
func (v *Display) Flush() {
C.gdk_display_flush(v.native())
}
// Close() is a wrapper around gdk_display_close().
func (v *Display) Close() {
C.gdk_display_close(v.native())
}
// IsClosed() is a wrapper around gdk_display_is_closed().
func (v *Display) IsClosed() bool {
c := C.gdk_display_is_closed(v.native())
return gobool(c)
}
// GetEvent() is a wrapper around gdk_display_get_event().
func (v *Display) GetEvent() (*Event, error) {
c := C.gdk_display_get_event(v.native())
if c == nil {
return nil, nilPtrErr
}
e := &Event{c}
runtime.SetFinalizer(e, (*Event).free)
return e, nil
}
// PeekEvent() is a wrapper around gdk_display_peek_event().
func (v *Display) PeekEvent() (*Event, error) {
c := C.gdk_display_peek_event(v.native())
if c == nil {
return nil, nilPtrErr
}
e := &Event{c}
runtime.SetFinalizer(e, (*Event).free)
return e, nil
}
// PutEvent() is a wrapper around gdk_display_put_event().
func (v *Display) PutEvent(event *Event) {
C.gdk_display_put_event(v.native(), event.native())
}
// HasPending() is a wrapper around gdk_display_has_pending().
func (v *Display) HasPending() bool {
c := C.gdk_display_has_pending(v.native())
return gobool(c)
}
// SetDoubleClickTime() is a wrapper around gdk_display_set_double_click_time().
func (v *Display) SetDoubleClickTime(msec uint) {
C.gdk_display_set_double_click_time(v.native(), C.guint(msec))
}
// SetDoubleClickDistance() is a wrapper around gdk_display_set_double_click_distance().
func (v *Display) SetDoubleClickDistance(distance uint) {
C.gdk_display_set_double_click_distance(v.native(), C.guint(distance))
}
// SupportsColorCursor() is a wrapper around gdk_display_supports_cursor_color().
func (v *Display) SupportsColorCursor() bool {
c := C.gdk_display_supports_cursor_color(v.native())
return gobool(c)
}
// SupportsCursorAlpha() is a wrapper around gdk_display_supports_cursor_alpha().
func (v *Display) SupportsCursorAlpha() bool {
c := C.gdk_display_supports_cursor_alpha(v.native())
return gobool(c)
}
// GetDefaultCursorSize() is a wrapper around gdk_display_get_default_cursor_size().
func (v *Display) GetDefaultCursorSize() uint {
c := C.gdk_display_get_default_cursor_size(v.native())
return uint(c)
}
// GetMaximalCursorSize() is a wrapper around gdk_display_get_maximal_cursor_size().
func (v *Display) GetMaximalCursorSize() (width, height uint) {
var w, h C.guint
C.gdk_display_get_maximal_cursor_size(v.native(), &w, &h)
return uint(w), uint(h)
}
// GetDefaultGroup() is a wrapper around gdk_display_get_default_group().
func (v *Display) GetDefaultGroup() (*Window, error) {
c := C.gdk_display_get_default_group(v.native())
if c == nil {
return nil, nilPtrErr
}
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
w := &Window{obj}
obj.Ref()
runtime.SetFinalizer(obj, (*glib.Object).Unref)
return w, nil
}
// SupportsSelectionNotification() is a wrapper around
// gdk_display_supports_selection_notification().
func (v *Display) SupportsSelectionNotification() bool {
c := C.gdk_display_supports_selection_notification(v.native())
return gobool(c)
}
// RequestSelectionNotification() is a wrapper around
// gdk_display_request_selection_notification().
func (v *Display) RequestSelectionNotification(selection Atom) bool {
c := C.gdk_display_request_selection_notification(v.native(),
selection.native())
return gobool(c)
}
// SupportsClipboardPersistence() is a wrapper around
// gdk_display_supports_clipboard_persistence().
func (v *Display) SupportsClipboardPersistence() bool {
c := C.gdk_display_supports_clipboard_persistence(v.native())
return gobool(c)
}
// TODO(jrick)
func (v *Display) StoreClipboard(clipboardWindow *Window, time uint32, targets ...Atom) {
}
// SupportsShapes() is a wrapper around gdk_display_supports_shapes().
func (v *Display) SupportsShapes() bool {
c := C.gdk_display_supports_shapes(v.native())
return gobool(c)
}
// SupportsInputShapes() is a wrapper around gdk_display_supports_input_shapes().
func (v *Display) SupportsInputShapes() bool {
c := C.gdk_display_supports_input_shapes(v.native())
return gobool(c)
}
// SupportsComposite() is a wrapper around gdk_display_supports_composite().
func (v *Display) SupportsComposite() bool {
c := C.gdk_display_supports_composite(v.native())
return gobool(c)
}
// TODO(jrick) glib.AppLaunchContext GdkAppLaunchContext
func (v *Display) GetAppLaunchContext() {
}
// NotifyStartupComplete() is a wrapper around gdk_display_notify_startup_complete().
func (v *Display) NotifyStartupComplete(startupID string) {
cstr := C.CString(startupID)
defer C.free(unsafe.Pointer(cstr))
C.gdk_display_notify_startup_complete(v.native(), (*C.gchar)(cstr))
}
/*
* GdkEvent
*/
type EventType int
const (
ButtonPress EventType = C.GDK_BUTTON_PRESS
)
type EventAny struct {
Type EventType
Window *Window
SendEvent int8
}
type EventButton struct {
EventAny
Time uint32
X float64
Y float64
Axes *float64
State uint32
Button uint32
Device *Device
XRoot, YRoot float64
}
// Event is a representation of GDK's GdkEvent.
type Event struct {
GdkEvent *C.GdkEvent
}
// Marshall returns a native go structor for event v.
func (v *Event) Marshall() interface{} {
evType := C.gdk_event_get_event_type(v.GdkEvent)
switch evType {
case C.GDK_BUTTON_PRESS:
evButton := &EventButton{}
evButton.Type = ButtonPress
evButton.Time = uint32(C.gdk_event_get_time(v.GdkEvent))
xPtr := (*C.gdouble)(unsafe.Pointer(&evButton.X))
yPtr := (*C.gdouble)(unsafe.Pointer(&evButton.Y))
C.gdk_event_get_coords(v.GdkEvent, xPtr, yPtr)
return evButton
}
return nil
}
// native returns a pointer to the underlying GdkEvent.
func (v *Event) native() *C.GdkEvent {
if v == nil {
return nil
}
return v.GdkEvent
}
// Native returns a pointer to the underlying GdkEvent.
func (v *Event) Native() uintptr {
return uintptr(unsafe.Pointer(v.native()))
}
func marshalEvent(p uintptr) (interface{}, error) {
c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p)))
return &Event{(*C.GdkEvent)(unsafe.Pointer(c))}, nil
}
func (v *Event) free() {
C.gdk_event_free(v.native())
}
/*
* GdkEventKey
*/
// EventKey is a representation of GDK's GdkEventKey.
type EventKey struct {
*Event
}
// Native returns a pointer to the underlying GdkEventKey.
func (v *EventKey) Native() uintptr {
return uintptr(unsafe.Pointer(v.native()))
}
func (v *EventKey) native() *C.GdkEventKey {
return (*C.GdkEventKey)(unsafe.Pointer(v.Event.native()))
}
func (v *EventKey) KeyVal() uint {
c := v.native().keyval
return uint(c)
}
/*
* GdkPixbuf
*/
// Pixbuf is a representation of GDK's GdkPixbuf.
type Pixbuf struct {
*glib.Object
}
// native returns a pointer to the underlying GdkPixbuf.
func (v *Pixbuf) native() *C.GdkPixbuf {
if v == nil || v.GObject == nil {
return nil
}
p := unsafe.Pointer(v.GObject)
return C.toGdkPixbuf(p)
}
// Native returns a pointer to the underlying GdkPixbuf.
func (v *Pixbuf) Native() uintptr {
return uintptr(unsafe.Pointer(v.native()))
}
func marshalPixbuf(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
return &Pixbuf{obj}, nil
}
// GetColorspace is a wrapper around gdk_pixbuf_get_colorspace().
func (v *Pixbuf) GetColorspace() Colorspace {
c := C.gdk_pixbuf_get_colorspace(v.native())
return Colorspace(c)
}
// GetNChannels is a wrapper around gdk_pixbuf_get_n_channels().
func (v *Pixbuf) GetNChannels() int {
c := C.gdk_pixbuf_get_n_channels(v.native())
return int(c)
}
// GetHasAlpha is a wrapper around gdk_pixbuf_get_has_alpha().
func (v *Pixbuf) GetHasAlpha() bool {
c := C.gdk_pixbuf_get_has_alpha(v.native())
return gobool(c)
}
// GetBitsPerSample is a wrapper around gdk_pixbuf_get_bits_per_sample().
func (v *Pixbuf) GetBitsPerSample() int {
c := C.gdk_pixbuf_get_bits_per_sample(v.native())
return int(c)
}
// GetPixels is a wrapper around gdk_pixbuf_get_pixels_with_length().
// A Go slice is used to represent the underlying Pixbuf data array, one
// byte per channel.
func (v *Pixbuf) GetPixels() (channels []byte) {
var length C.guint
c := C.gdk_pixbuf_get_pixels_with_length(v.native(), &length)
sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&channels))
sliceHeader.Data = uintptr(unsafe.Pointer(c))
sliceHeader.Len = int(length)
sliceHeader.Cap = int(length)
// To make sure the slice doesn't outlive the Pixbuf, add a reference
v.Ref()
runtime.SetFinalizer(&channels, func(_ *[]byte) {
v.Unref()
})
return
}
// GetWidth is a wrapper around gdk_pixbuf_get_width().
func (v *Pixbuf) GetWidth() int {
c := C.gdk_pixbuf_get_width(v.native())
return int(c)
}
// GetHeight is a wrapper around gdk_pixbuf_get_height().
func (v *Pixbuf) GetHeight() int {
c := C.gdk_pixbuf_get_height(v.native())
return int(c)
}
// GetRowstride is a wrapper around gdk_pixbuf_get_rowstride().
func (v *Pixbuf) GetRowstride() int {
c := C.gdk_pixbuf_get_rowstride(v.native())
return int(c)
}
// GetByteLength is a wrapper around gdk_pixbuf_get_byte_length().
func (v *Pixbuf) GetByteLength() int {
c := C.gdk_pixbuf_get_byte_length(v.native())
return int(c)
}
// GetOption is a wrapper around gdk_pixbuf_get_option(). ok is true if
// the key has an associated value.
func (v *Pixbuf) GetOption(key string) (value string, ok bool) {
cstr := C.CString(key)
defer C.free(unsafe.Pointer(cstr))
c := C.gdk_pixbuf_get_option(v.native(), (*C.gchar)(cstr))
if c == nil {
return "", false
}
return C.GoString((*C.char)(c)), true
}
// PixbufNew is a wrapper around gdk_pixbuf_new().
func PixbufNew(colorspace Colorspace, hasAlpha bool, bitsPerSample, width, height int) (*Pixbuf, error) {
c := C.gdk_pixbuf_new(C.GdkColorspace(colorspace), gbool(hasAlpha),
C.int(bitsPerSample), C.int(width), C.int(height))
if c == nil {
return nil, nilPtrErr
}
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
p := &Pixbuf{obj}
obj.Ref()
runtime.SetFinalizer(obj, (*glib.Object).Unref)
return p, nil
}
// PixbufNewFromFile is a wrapper around gdk_pixbuf_new_from_file().
func PixbufNewFromFile(filename string) (*Pixbuf, error) {
cstr := C.CString(filename)
defer C.free(unsafe.Pointer(cstr))
var err *C.GError
res := C.gdk_pixbuf_new_from_file((*C.char)(cstr), &err)
if res == nil {
defer C.g_error_free(err)
return nil, errors.New(C.GoString((*C.char)(err.message)))
}
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(res))}
p := &Pixbuf{obj}
obj.Ref()
runtime.SetFinalizer(obj, (*glib.Object).Unref)
return p, nil
}
// ScaleSimple is a wrapper around gdk_pixbuf_scale_simple().
func (v *Pixbuf) ScaleSimple(destWidth, destHeight int, interpType InterpType) (*Pixbuf, error) {
c := C.gdk_pixbuf_scale_simple(v.native(), C.int(destWidth),
C.int(destHeight), C.GdkInterpType(interpType))
if c == nil {
return nil, nilPtrErr
}
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
p := &Pixbuf{obj}
obj.Ref()
runtime.SetFinalizer(obj, (*glib.Object).Unref)
return p, nil
}
// RotateSimple is a wrapper around gdk_pixbuf_rotate_simple().
func (v *Pixbuf) RotateSimple(angle PixbufRotation) (*Pixbuf, error) {
c := C.gdk_pixbuf_rotate_simple(v.native(), C.GdkPixbufRotation(angle))
if c == nil {
return nil, nilPtrErr
}
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
p := &Pixbuf{obj}
obj.Ref()
runtime.SetFinalizer(obj, (*glib.Object).Unref)
return p, nil
}
/*
* GdkScreen
*/
// Screen is a representation of GDK's GdkScreen.
type Screen struct {
*glib.Object
}
// native returns a pointer to the underlying GdkScreen.
func (v *Screen) native() *C.GdkScreen {
if v == nil || v.GObject == nil {
return nil
}
p := unsafe.Pointer(v.GObject)
return C.toGdkScreen(p)
}
// Native returns a pointer to the underlying GdkScreen.
func (v *Screen) Native() uintptr {
return uintptr(unsafe.Pointer(v.native()))
}
func marshalScreen(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
return &Screen{obj}, nil
}
// GetRGBAVisual is a wrapper around gdk_screen_get_rgba_visual().
func (v *Screen) GetRGBAVisual() (*Visual, error) {
c := C.gdk_screen_get_rgba_visual(v.native())
if c == nil {
return nil, nilPtrErr
}
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
visual := &Visual{obj}
obj.Ref()
runtime.SetFinalizer(obj, (*glib.Object).Unref)
return visual, nil
}
// GetSystemVisual is a wrapper around gdk_screen_get_system_visual().
func (v *Screen) GetSystemVisual() (*Visual, error) {
c := C.gdk_screen_get_system_visual(v.native())
if c == nil {
return nil, nilPtrErr
}
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
visual := &Visual{obj}
obj.Ref()
runtime.SetFinalizer(obj, (*glib.Object).Unref)
return visual, nil
}
// GetWidth is a wrapper around gdk_screen_get_width().
func (v *Screen) GetWidth() int {
c := C.gdk_screen_get_width(v.native())
return int(c)
}
// GetHeight is a wrapper around gdk_screen_get_height().
func (v *Screen) GetHeight() int {
c := C.gdk_screen_get_height(v.native())
return int(c)
}
/*
* GdkVisual
*/
// Visual is a representation of GDK's GdkVisual.
type Visual struct {
*glib.Object
}
func (v *Visual) native() *C.GdkVisual {
if v == nil || v.GObject == nil {
return nil
}
p := unsafe.Pointer(v.GObject)
return C.toGdkVisual(p)
}
func (v *Visual) Native() uintptr {
return uintptr(unsafe.Pointer(v.native()))
}
func marshalVisual(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
return &Visual{obj}, nil
}
/*
* GdkWindow
*/
// Window is a representation of GDK's GdkWindow.
type Window struct {
*glib.Object
}
// native returns a pointer to the underlying GdkWindow.
func (v *Window) native() *C.GdkWindow {
if v == nil || v.GObject == nil {
return nil
}
p := unsafe.Pointer(v.GObject)
return C.toGdkWindow(p)
}
// Native returns a pointer to the underlying GdkWindow.
func (v *Window) Native() uintptr {
return uintptr(unsafe.Pointer(v.native()))
}
func marshalWindow(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
return &Window{obj}, nil
}