gtkroot.go RawHistoryFolder
1// Package gtk was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gtk
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/gdk"
12 "github.com/bnema/puregotk/v4/gobject"
13 "github.com/bnema/puregotk/v4/gobject/types"
14)
15
16type RootInterface struct {
17 _ structs.HostLayout
18}
19
20func (x *RootInterface) GoPointer() uintptr {
21 return uintptr(unsafe.Pointer(x))
22}
23
24// An interface for widgets that can act as the root of a widget hierarchy.
25//
26// The root widget takes care of providing the connection to the windowing
27// system and manages layout, drawing and event delivery for its widget
28// hierarchy.
29//
30// The obvious example of a `GtkRoot` is `GtkWindow`.
31//
32// To get the display to which a `GtkRoot` belongs, use
33// [method@Gtk.Root.get_display].
34//
35// `GtkRoot` also maintains the location of keyboard focus inside its widget
36// hierarchy, with [method@Gtk.Root.set_focus] and [method@Gtk.Root.get_focus].
37type Root interface {
38 GoPointer() uintptr
39 SetGoPointer(uintptr)
40 GetDisplay() *gdk.Display
41 GetFocus() *Widget
42 SetFocus(FocusVar *Widget)
43}
44
45var xRootGLibType func() types.GType
46
47func RootGLibType() types.GType {
48 return xRootGLibType()
49}
50
51type RootBase struct {
52 Ptr uintptr
53}
54
55func (x *RootBase) GoPointer() uintptr {
56 if x == nil {
57 return 0
58 }
59 return x.Ptr
60}
61
62func (x *RootBase) SetGoPointer(ptr uintptr) {
63 x.Ptr = ptr
64}
65
66// Returns the display that this `GtkRoot` is on.
67func (x *RootBase) GetDisplay() *gdk.Display {
68 var cls *gdk.Display
69
70 cret := XGtkRootGetDisplay(x.GoPointer())
71
72 if cret == 0 {
73 return nil
74 }
75 gobject.IncreaseRef(cret)
76 cls = &gdk.Display{}
77 cls.Ptr = cret
78 return cls
79}
80
81// Retrieves the current focused widget within the root.
82//
83// Note that this is the widget that would have the focus
84// if the root is active; if the root is not focused then
85// `gtk_widget_has_focus (widget)` will be %FALSE for the
86// widget.
87func (x *RootBase) GetFocus() *Widget {
88 var cls *Widget
89
90 cret := XGtkRootGetFocus(x.GoPointer())
91
92 if cret == 0 {
93 return nil
94 }
95 gobject.IncreaseRef(cret)
96 cls = &Widget{}
97 cls.Ptr = cret
98 return cls
99}
100
101// If @focus is not the current focus widget, and is focusable, sets
102// it as the focus widget for the root.
103//
104// If @focus is %NULL, unsets the focus widget for the root.
105//
106// To set the focus to a particular widget in the root, it is usually
107// more convenient to use [method@Gtk.Widget.grab_focus] instead of
108// this function.
109func (x *RootBase) SetFocus(FocusVar *Widget) {
110
111 XGtkRootSetFocus(x.GoPointer(), FocusVar.GoPointer())
112
113}
114
115var XGtkRootGetDisplay func(uintptr) uintptr
116var XGtkRootGetFocus func(uintptr) uintptr
117var XGtkRootSetFocus func(uintptr, uintptr)
118
119func init() {
120 core.SetPackageName("GTK", "gtk4")
121 core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"})
122 var libs []uintptr
123 for _, libPath := range core.GetPaths("GTK") {
124 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
125 if err != nil {
126 panic(err)
127 }
128 libs = append(libs, lib)
129 }
130
131 core.PuregoSafeRegister(&xRootGLibType, libs, "gtk_root_get_type")
132
133 core.PuregoSafeRegister(&XGtkRootGetDisplay, libs, "gtk_root_get_display")
134 core.PuregoSafeRegister(&XGtkRootGetFocus, libs, "gtk_root_get_focus")
135 core.PuregoSafeRegister(&XGtkRootSetFocus, libs, "gtk_root_set_focus")
136
137}