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/gio"
12 "github.com/bnema/puregotk/v4/glib"
13 "github.com/bnema/puregotk/v4/gobject"
14 "github.com/bnema/puregotk/v4/gobject/types"
15)
16
17type ApplicationClass struct {
18 _ structs.HostLayout
19
20 ParentClass gio.ApplicationClass
21
22 xWindowAdded uintptr
23
24 xWindowRemoved uintptr
25
26 Padding [8]uintptr
27}
28
29func (x *ApplicationClass) GoPointer() uintptr {
30 return uintptr(unsafe.Pointer(x))
31}
32
33// OverrideWindowAdded sets the "window_added" callback function.
34// Signal emitted when a `GtkWindow` is added to
35//
36// application through gtk_application_add_window().
37func (x *ApplicationClass) OverrideWindowAdded(cb func(*Application, *Window)) {
38 if cb == nil {
39 x.xWindowAdded = 0
40 } else {
41 x.xWindowAdded = purego.NewCallback(func(ApplicationVarp uintptr, WindowVarp uintptr) {
42 cb(ApplicationNewFromInternalPtr(ApplicationVarp), WindowNewFromInternalPtr(WindowVarp))
43 })
44 }
45}
46
47// GetWindowAdded gets the "window_added" callback function.
48// Signal emitted when a `GtkWindow` is added to
49//
50// application through gtk_application_add_window().
51func (x *ApplicationClass) GetWindowAdded() func(*Application, *Window) {
52 if x.xWindowAdded == 0 {
53 return nil
54 }
55 var rawCallback func(ApplicationVarp uintptr, WindowVarp uintptr)
56 purego.RegisterFunc(&rawCallback, x.xWindowAdded)
57 return func(ApplicationVar *Application, WindowVar *Window) {
58 rawCallback(ApplicationVar.GoPointer(), WindowVar.GoPointer())
59 }
60}
61
62// OverrideWindowRemoved sets the "window_removed" callback function.
63// Signal emitted when a `GtkWindow` is removed from
64//
65// application, either as a side-effect of being destroyed or
66// explicitly through gtk_application_remove_window().
67func (x *ApplicationClass) OverrideWindowRemoved(cb func(*Application, *Window)) {
68 if cb == nil {
69 x.xWindowRemoved = 0
70 } else {
71 x.xWindowRemoved = purego.NewCallback(func(ApplicationVarp uintptr, WindowVarp uintptr) {
72 cb(ApplicationNewFromInternalPtr(ApplicationVarp), WindowNewFromInternalPtr(WindowVarp))
73 })
74 }
75}
76
77// GetWindowRemoved gets the "window_removed" callback function.
78// Signal emitted when a `GtkWindow` is removed from
79//
80// application, either as a side-effect of being destroyed or
81// explicitly through gtk_application_remove_window().
82func (x *ApplicationClass) GetWindowRemoved() func(*Application, *Window) {
83 if x.xWindowRemoved == 0 {
84 return nil
85 }
86 var rawCallback func(ApplicationVarp uintptr, WindowVarp uintptr)
87 purego.RegisterFunc(&rawCallback, x.xWindowRemoved)
88 return func(ApplicationVar *Application, WindowVar *Window) {
89 rawCallback(ApplicationVar.GoPointer(), WindowVar.GoPointer())
90 }
91}
92
93// Types of user actions that may be blocked by `GtkApplication`.
94//
95// See [method@Gtk.Application.inhibit].
96type ApplicationInhibitFlags int
97
98var xApplicationInhibitFlagsGLibType func() types.GType
99
100func ApplicationInhibitFlagsGLibType() types.GType {
101 return xApplicationInhibitFlagsGLibType()
102}
103
104const (
105
106 // Inhibit ending the user session
107 // by logging out or by shutting down the computer
108 ApplicationInhibitLogoutValue ApplicationInhibitFlags = 1
109 // Inhibit user switching
110 ApplicationInhibitSwitchValue ApplicationInhibitFlags = 2
111 // Inhibit suspending the
112 // session or computer
113 ApplicationInhibitSuspendValue ApplicationInhibitFlags = 4
114 // Inhibit the session being
115 // marked as idle (and possibly locked)
116 ApplicationInhibitIdleValue ApplicationInhibitFlags = 8
117)
118
119// A high-level API for writing applications.
120//
121// `GtkApplication` supports many aspects of writing a GTK application
122// in a convenient fashion, without enforcing a one-size-fits-all model.
123//
124// Currently, it handles GTK initialization, application uniqueness, session
125// management, provides some basic scriptability and desktop shell integration
126// by exporting actions and menus and manages a list of toplevel windows whose
127// life-cycle is automatically tied to the life-cycle of your application.
128//
129// While `GtkApplication` works fine with plain [class@Gtk.Window]s,
130// it is recommended to use it together with [class@Gtk.ApplicationWindow].
131//
132// ## Automatic resources
133//
134// `GtkApplication` will automatically load menus from the `GtkBuilder`
135// resource located at "gtk/menus.ui", relative to the application's
136// resource base path (see [method@Gio.Application.set_resource_base_path]).
137// The menu with the ID "menubar" is taken as the application's
138// menubar. Additional menus (most interesting submenus) can be named
139// and accessed via [method@Gtk.Application.get_menu_by_id] which allows for
140// dynamic population of a part of the menu structure.
141//
142// Note that automatic resource loading uses the resource base path
143// that is set at construction time and will not work if the resource
144// base path is changed at a later time.
145//
146// It is also possible to provide the menubar manually using
147// [method@Gtk.Application.set_menubar].
148//
149// `GtkApplication` will also automatically setup an icon search path for
150// the default icon theme by appending "icons" to the resource base
151// path. This allows your application to easily store its icons as
152// resources. See [method@Gtk.IconTheme.add_resource_path] for more
153// information.
154//
155// If there is a resource located at `gtk/help-overlay.ui` which
156// defines a [class@Gtk.ShortcutsWindow] with ID `help_overlay` then
157// `GtkApplication` associates an instance of this shortcuts window with
158// each [class@Gtk.ApplicationWindow] and sets up the keyboard accelerator
159// <kbd>Control</kbd>+<kbd>?</kbd> to open it. To create a menu item that
160// displays the shortcuts window, associate the item with the action
161// `win.show-help-overlay`.
162//
163// `GtkApplication` will also automatically set the application id as the
164// default window icon. Use [func@Gtk.Window.set_default_icon_name] or
165// [property@Gtk.Window:icon-name] to override that behavior.
166//
167// ## A simple application
168//
169// [A simple example](https://gitlab.gnome.org/GNOME/gtk/tree/main/examples/bp/bloatpad.c)
170// is available in the GTK source code repository
171//
172// `GtkApplication` registers with a session manager if possible and
173// offers various functionality related to the session life-cycle.
174//
175// An application can block various ways to end the session with
176// the [method@Gtk.Application.inhibit] function. Typical use cases for
177// this kind of inhibiting are long-running, uninterruptible operations,
178// such as burning a CD or performing a disk backup. The session
179// manager may not honor the inhibitor, but it can be expected to
180// inform the user about the negative consequences of ending the
181// session while inhibitors are present.
182//
183// ## See Also
184//
185// - [Using GtkApplication](https://developer.gnome.org/documentation/tutorials/application.html)
186// - [Getting Started with GTK: Basics](getting_started.html#basics)
187type Application struct {
188 gio.Application
189}
190
191var xApplicationGLibType func() types.GType
192
193func ApplicationGLibType() types.GType {
194 return xApplicationGLibType()
195}
196
197func ApplicationNewFromInternalPtr(ptr uintptr) *Application {
198 cls := &Application{}
199 cls.Ptr = ptr
200 return cls
201}
202
203var xNewApplication func(uintptr, gio.ApplicationFlags) uintptr
204
205// Creates a new application instance.
206//
207// When using `GtkApplication`, it is not necessary to call [func@Gtk.init]
208// manually. It is called as soon as the application gets registered as
209// the primary instance.
210//
211// Concretely, [func@Gtk.init] is called in the default handler for the
212// `GApplication::startup` signal. Therefore, `GtkApplication` subclasses
213// should always chain up in their [vfunc@GIO.Application.startup] handler
214// before using any GTK API.
215//
216// Note that commandline arguments are not passed to [func@Gtk.init].
217//
218// If `application_id` is not `NULL`, then it must be valid. See
219// [func@Gio.Application.id_is_valid].
220//
221// If no application ID is given then some features (most notably application
222// uniqueness) will be disabled.
223func NewApplication(ApplicationIdVar *string, FlagsVar gio.ApplicationFlags) *Application {
224 var cls *Application
225
226 ApplicationIdVarPtr := core.GStrdupNullable(ApplicationIdVar)
227 defer core.GFreeNullable(ApplicationIdVarPtr)
228
229 cret := xNewApplication(ApplicationIdVarPtr, FlagsVar)
230
231 if cret == 0 {
232 return nil
233 }
234 cls = &Application{}
235 cls.Ptr = cret
236 return cls
237}
238
239var xApplicationAddWindow func(uintptr, uintptr)
240
241// Adds a window to the application.
242//
243// This call can only happen after the application has started;
244// typically, you should add new application windows in response
245// to the emission of the [signal@GIO.Application::activate] signal.
246//
247// This call is equivalent to setting the [property@Gtk.Window:application]
248// property of the window to @application.
249//
250// Normally, the connection between the application and the window
251// will remain until the window is destroyed, but you can explicitly
252// remove it with [method@Gtk.Application.remove_window].
253//
254// GTK will keep the application running as long as it has any windows.
255func (x *Application) AddWindow(WindowVar *Window) {
256
257 xApplicationAddWindow(x.GoPointer(), WindowVar.GoPointer())
258
259}
260
261var xApplicationGetAccelsForAction func(uintptr, string) []string
262
263// Gets the accelerators that are currently associated with
264// the given action.
265func (x *Application) GetAccelsForAction(DetailedActionNameVar string) []string {
266
267 cret := xApplicationGetAccelsForAction(x.GoPointer(), DetailedActionNameVar)
268 return cret
269}
270
271var xApplicationGetActionsForAccel func(uintptr, string) []string
272
273// Returns the list of actions (possibly empty) that the accelerator maps to.
274//
275// Each item in the list is a detailed action name in the usual form.
276//
277// This might be useful to discover if an accel already exists in
278// order to prevent installation of a conflicting accelerator (from
279// an accelerator editor or a plugin system, for example). Note that
280// having more than one action per accelerator may not be a bad thing
281// and might make sense in cases where the actions never appear in the
282// same context.
283//
284// In case there are no actions for a given accelerator, an empty array
285// is returned. `NULL` is never returned.
286//
287// It is a programmer error to pass an invalid accelerator string.
288//
289// If you are unsure, check it with [func@Gtk.accelerator_parse] first.
290func (x *Application) GetActionsForAccel(AccelVar string) []string {
291
292 cret := xApplicationGetActionsForAccel(x.GoPointer(), AccelVar)
293 return cret
294}
295
296var xApplicationGetActiveWindow func(uintptr) uintptr
297
298// Gets the “active” window for the application.
299//
300// The active window is the one that was most recently focused
301// (within the application). This window may not have the focus
302// at the moment if another application has it — this is just
303// the most recently-focused window within this application.
304func (x *Application) GetActiveWindow() *Window {
305 var cls *Window
306
307 cret := xApplicationGetActiveWindow(x.GoPointer())
308
309 if cret == 0 {
310 return nil
311 }
312 gobject.IncreaseRef(cret)
313 cls = &Window{}
314 cls.Ptr = cret
315 return cls
316}
317
318var xApplicationGetMenuById func(uintptr, string) uintptr
319
320// Gets a menu from automatically loaded resources.
321//
322// See [the section on Automatic resources](class.Application.html#automatic-resources)
323// for more information.
324func (x *Application) GetMenuById(IdVar string) *gio.Menu {
325 var cls *gio.Menu
326
327 cret := xApplicationGetMenuById(x.GoPointer(), IdVar)
328
329 if cret == 0 {
330 return nil
331 }
332 gobject.IncreaseRef(cret)
333 cls = &gio.Menu{}
334 cls.Ptr = cret
335 return cls
336}
337
338var xApplicationGetMenubar func(uintptr) uintptr
339
340// Returns the menu model for the menu bar of the application.
341func (x *Application) GetMenubar() *gio.MenuModel {
342 var cls *gio.MenuModel
343
344 cret := xApplicationGetMenubar(x.GoPointer())
345
346 if cret == 0 {
347 return nil
348 }
349 gobject.IncreaseRef(cret)
350 cls = &gio.MenuModel{}
351 cls.Ptr = cret
352 return cls
353}
354
355var xApplicationGetWindowById func(uintptr, uint) uintptr
356
357// Returns the window with the given ID.
358//
359// The ID of a `GtkApplicationWindow` can be retrieved with
360// [method@Gtk.ApplicationWindow.get_id].
361func (x *Application) GetWindowById(IdVar uint) *Window {
362 var cls *Window
363
364 cret := xApplicationGetWindowById(x.GoPointer(), IdVar)
365
366 if cret == 0 {
367 return nil
368 }
369 gobject.IncreaseRef(cret)
370 cls = &Window{}
371 cls.Ptr = cret
372 return cls
373}
374
375var xApplicationGetWindows func(uintptr) *glib.List
376
377// Gets a list of the window associated with the application.
378//
379// The list is sorted by most recently focused window, such that the first
380// element is the currently focused window. (Useful for choosing a parent
381// for a transient window.)
382//
383// The list that is returned should not be modified in any way. It will
384// only remain valid until the next focus change or window creation or
385// deletion.
386func (x *Application) GetWindows() *glib.List {
387
388 cret := xApplicationGetWindows(x.GoPointer())
389 return cret
390}
391
392var xApplicationInhibit func(uintptr, uintptr, ApplicationInhibitFlags, uintptr) uint
393
394// Informs the session manager that certain types of actions should be
395// inhibited.
396//
397// This is not guaranteed to work on all platforms and for all types of
398// actions.
399//
400// Applications should invoke this method when they begin an operation
401// that should not be interrupted, such as creating a CD or DVD. The
402// types of actions that may be blocked are specified by the @flags
403// parameter. When the application completes the operation it should
404// call [method@Gtk.Application.uninhibit] to remove the inhibitor. Note
405// that an application can have multiple inhibitors, and all of them must
406// be individually removed. Inhibitors are also cleared when the
407// application exits.
408//
409// Applications should not expect that they will always be able to block
410// the action. In most cases, users will be given the option to force
411// the action to take place.
412//
413// The @reason message should be short and to the point.
414//
415// If a window is given, the session manager may point the user to
416// this window to find out more about why the action is inhibited.
417//
418// The cookie that is returned by this function should be used as an
419// argument to [method@Gtk.Application.uninhibit] in order to remove
420// the request.
421func (x *Application) Inhibit(WindowVar *Window, FlagsVar ApplicationInhibitFlags, ReasonVar *string) uint {
422
423 ReasonVarPtr := core.GStrdupNullable(ReasonVar)
424 defer core.GFreeNullable(ReasonVarPtr)
425
426 cret := xApplicationInhibit(x.GoPointer(), WindowVar.GoPointer(), FlagsVar, ReasonVarPtr)
427 return cret
428}
429
430var xApplicationListActionDescriptions func(uintptr) []string
431
432// Lists the detailed action names which have associated accelerators.
433//
434// See [method@Gtk.Application.set_accels_for_action].
435func (x *Application) ListActionDescriptions() []string {
436
437 cret := xApplicationListActionDescriptions(x.GoPointer())
438 return cret
439}
440
441var xApplicationRemoveWindow func(uintptr, uintptr)
442
443// Remove a window from the application.
444//
445// If the window belongs to the application then this call is
446// equivalent to setting the [property@Gtk.Window:application]
447// property of the window to `NULL`.
448//
449// The application may stop running as a result of a call to this
450// function, if the window was the last window of the application.
451func (x *Application) RemoveWindow(WindowVar *Window) {
452
453 xApplicationRemoveWindow(x.GoPointer(), WindowVar.GoPointer())
454
455}
456
457var xApplicationSetAccelsForAction func(uintptr, string, []string)
458
459// Sets zero or more keyboard accelerators that will trigger the
460// given action.
461//
462// The first item in @accels will be the primary accelerator,
463// which may be displayed in the UI.
464//
465// To remove all accelerators for an action, use an empty,
466// zero-terminated array for @accels.
467//
468// For the @detailed_action_name, see [func@Gio.Action.parse_detailed_name]
469// and [Gio.Action.print_detailed_name].
470func (x *Application) SetAccelsForAction(DetailedActionNameVar string, AccelsVar []string) {
471
472 xApplicationSetAccelsForAction(x.GoPointer(), DetailedActionNameVar, AccelsVar)
473
474}
475
476var xApplicationSetMenubar func(uintptr, uintptr)
477
478// Sets or unsets the menubar for windows of the application.
479//
480// This is a menubar in the traditional sense.
481//
482// This can only be done in the primary instance of the application,
483// after it has been registered. [vfunc@GIO.Application.startup] is
484// a good place to call this.
485//
486// Depending on the desktop environment, this may appear at the top of
487// each window, or at the top of the screen. In some environments, if
488// both the application menu and the menubar are set, the application
489// menu will be presented as if it were the first item of the menubar.
490// Other environments treat the two as completely separate — for example,
491// the application menu may be rendered by the desktop shell while the
492// menubar (if set) remains in each individual window.
493//
494// Use the base `GActionMap` interface to add actions, to respond to the
495// user selecting these menu items.
496func (x *Application) SetMenubar(MenubarVar *gio.MenuModel) {
497
498 xApplicationSetMenubar(x.GoPointer(), MenubarVar.GoPointer())
499
500}
501
502var xApplicationUninhibit func(uintptr, uint)
503
504// Removes an inhibitor that has been previously established.
505//
506// See [method@Gtk.Application.inhibit].
507//
508// Inhibitors are also cleared when the application exits.
509func (x *Application) Uninhibit(CookieVar uint) {
510
511 xApplicationUninhibit(x.GoPointer(), CookieVar)
512
513}
514
515func (c *Application) GoPointer() uintptr {
516 if c == nil {
517 return 0
518 }
519 return c.Ptr
520}
521
522func (c *Application) SetGoPointer(ptr uintptr) {
523 c.Ptr = ptr
524}
525
526// SetPropertyRegisterSession sets the "register-session" property.
527// Set this property to true to register with the session manager.
528//
529// This will make GTK track the session state (such as the
530// [property@Gtk.Application:screensaver-active] property).
531func (x *Application) SetPropertyRegisterSession(value bool) {
532 var v gobject.Value
533 v.Init(gobject.TypeBooleanVal)
534 v.SetBoolean(value)
535 x.SetProperty("register-session", &v)
536}
537
538// GetPropertyRegisterSession gets the "register-session" property.
539// Set this property to true to register with the session manager.
540//
541// This will make GTK track the session state (such as the
542// [property@Gtk.Application:screensaver-active] property).
543func (x *Application) GetPropertyRegisterSession() bool {
544 var v gobject.Value
545 x.GetProperty("register-session", &v)
546 return v.GetBoolean()
547}
548
549// GetPropertyScreensaverActive gets the "screensaver-active" property.
550// This property is true if GTK believes that the screensaver
551// is currently active.
552//
553// Tracking the screensaver state is currently only supported on
554// Linux.
555func (x *Application) GetPropertyScreensaverActive() bool {
556 var v gobject.Value
557 x.GetProperty("screensaver-active", &v)
558 return v.GetBoolean()
559}
560
561// Emitted when the session manager is about to end the session.
562//
563// Applications can connect to this signal and call
564// [method@Gtk.Application.inhibit] with [flags@Gtk.ApplicationInhibitFlags.logout]
565// to delay the end of the session until state has been saved.
566func (x *Application) ConnectQueryEnd(cb *func(Application)) uint {
567 cbPtr := uintptr(unsafe.Pointer(cb))
568 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
569 handlerID := gobject.SignalConnect(x.GoPointer(), "query-end", cbRefPtr)
570 glib.SaveHandlerMapping(handlerID, cbPtr)
571 return handlerID
572 }
573
574 fcb := func(clsPtr uintptr) {
575 fa := Application{}
576 fa.Ptr = clsPtr
577 cbFn := *cb
578
579 cbFn(fa)
580
581 }
582 cbRefPtr := purego.NewCallback(fcb)
583 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
584 handlerID := gobject.SignalConnect(x.GoPointer(), "query-end", cbRefPtr)
585 glib.SaveHandlerMapping(handlerID, cbPtr)
586 return handlerID
587}
588
589// Emitted when a window is added to an application.
590//
591// See [method@Gtk.Application.add_window].
592func (x *Application) ConnectWindowAdded(cb *func(Application, uintptr)) uint {
593 cbPtr := uintptr(unsafe.Pointer(cb))
594 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
595 handlerID := gobject.SignalConnect(x.GoPointer(), "window-added", cbRefPtr)
596 glib.SaveHandlerMapping(handlerID, cbPtr)
597 return handlerID
598 }
599
600 fcb := func(clsPtr uintptr, WindowVarp uintptr) {
601 fa := Application{}
602 fa.Ptr = clsPtr
603 cbFn := *cb
604
605 cbFn(fa, WindowVarp)
606
607 }
608 cbRefPtr := purego.NewCallback(fcb)
609 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
610 handlerID := gobject.SignalConnect(x.GoPointer(), "window-added", cbRefPtr)
611 glib.SaveHandlerMapping(handlerID, cbPtr)
612 return handlerID
613}
614
615// Emitted when a window is removed from an application.
616//
617// This can happen as a side-effect of the window being destroyed
618// or explicitly through [method@Gtk.Application.remove_window].
619func (x *Application) ConnectWindowRemoved(cb *func(Application, uintptr)) uint {
620 cbPtr := uintptr(unsafe.Pointer(cb))
621 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
622 handlerID := gobject.SignalConnect(x.GoPointer(), "window-removed", cbRefPtr)
623 glib.SaveHandlerMapping(handlerID, cbPtr)
624 return handlerID
625 }
626
627 fcb := func(clsPtr uintptr, WindowVarp uintptr) {
628 fa := Application{}
629 fa.Ptr = clsPtr
630 cbFn := *cb
631
632 cbFn(fa, WindowVarp)
633
634 }
635 cbRefPtr := purego.NewCallback(fcb)
636 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
637 handlerID := gobject.SignalConnect(x.GoPointer(), "window-removed", cbRefPtr)
638 glib.SaveHandlerMapping(handlerID, cbPtr)
639 return handlerID
640}
641
642// Emits the [signal@Gio.ActionGroup::action-added] signal on @action_group.
643//
644// This function should only be called by [type@Gio.ActionGroup] implementations.
645func (x *Application) ActionAdded(ActionNameVar string) {
646
647 gio.XGActionGroupActionAdded(x.GoPointer(), ActionNameVar)
648
649}
650
651// Emits the [signal@Gio.ActionGroup::action-enabled-changed] signal on @action_group.
652//
653// This function should only be called by [type@Gio.ActionGroup] implementations.
654func (x *Application) ActionEnabledChanged(ActionNameVar string, EnabledVar bool) {
655
656 gio.XGActionGroupActionEnabledChanged(x.GoPointer(), ActionNameVar, EnabledVar)
657
658}
659
660// Emits the [signal@Gio.ActionGroup::action-removed] signal on @action_group.
661//
662// This function should only be called by [type@Gio.ActionGroup] implementations.
663func (x *Application) ActionRemoved(ActionNameVar string) {
664
665 gio.XGActionGroupActionRemoved(x.GoPointer(), ActionNameVar)
666
667}
668
669// Emits the [signal@Gio.ActionGroup::action-state-changed] signal on @action_group.
670//
671// This function should only be called by [type@Gio.ActionGroup] implementations.
672func (x *Application) ActionStateChanged(ActionNameVar string, StateVar *glib.Variant) {
673
674 gio.XGActionGroupActionStateChanged(x.GoPointer(), ActionNameVar, StateVar)
675
676}
677
678// Activate the named action within @action_group.
679//
680// If the action is expecting a parameter, then the correct type of
681// parameter must be given as @parameter. If the action is expecting no
682// parameters then @parameter must be `NULL`. See
683// [method@Gio.ActionGroup.get_action_parameter_type].
684//
685// If the [type@Gio.ActionGroup] implementation supports asynchronous remote
686// activation over D-Bus, this call may return before the relevant
687// D-Bus traffic has been sent, or any replies have been received. In
688// order to block on such asynchronous activation calls,
689// [method@Gio.DBusConnection.flush] should be called prior to the code, which
690// depends on the result of the action activation. Without flushing
691// the D-Bus connection, there is no guarantee that the action would
692// have been activated.
693//
694// The following code which runs in a remote app instance, shows an
695// example of a ‘quit’ action being activated on the primary app
696// instance over D-Bus. Here [method@Gio.DBusConnection.flush] is called
697// before `exit()`. Without `g_dbus_connection_flush()`, the ‘quit’ action
698// may fail to be activated on the primary instance.
699//
700// ```c
701// // call ‘quit’ action on primary instance
702// g_action_group_activate_action (G_ACTION_GROUP (app), "quit", NULL);
703//
704// // make sure the action is activated now
705// g_dbus_connection_flush (…);
706//
707// g_debug ("Application has been terminated. Exiting.");
708//
709// exit (0);
710// ```
711func (x *Application) ActivateAction(ActionNameVar string, ParameterVar *glib.Variant) {
712
713 gio.XGActionGroupActivateAction(x.GoPointer(), ActionNameVar, ParameterVar)
714
715}
716
717// Request for the state of the named action within @action_group to be
718// changed to @value.
719//
720// The action must be stateful and @value must be of the correct type.
721// See [method@Gio.ActionGroup.get_action_state_type].
722//
723// This call merely requests a change. The action may refuse to change
724// its state or may change its state to something other than @value.
725// See [method@Gio.ActionGroup.get_action_state_hint].
726//
727// If the @value GVariant is floating, it is consumed.
728func (x *Application) ChangeActionState(ActionNameVar string, ValueVar *glib.Variant) {
729
730 gio.XGActionGroupChangeActionState(x.GoPointer(), ActionNameVar, ValueVar)
731
732}
733
734// Checks if the named action within @action_group is currently enabled.
735//
736// An action must be enabled in order to be activated or in order to
737// have its state changed from outside callers.
738func (x *Application) GetActionEnabled(ActionNameVar string) bool {
739
740 cret := gio.XGActionGroupGetActionEnabled(x.GoPointer(), ActionNameVar)
741 return cret
742}
743
744// Queries the type of the parameter that must be given when activating
745// the named action within @action_group.
746//
747// When activating the action using [method@Gio.ActionGroup.activate_action],
748// the [type@GLib.Variant] given to that function must be of the type returned
749// by this function.
750//
751// In the case that this function returns `NULL`, you must not give any
752// [type@GLib.Variant], but `NULL` instead.
753//
754// The parameter type of a particular action will never change but it is
755// possible for an action to be removed and for a new action to be added
756// with the same name but a different parameter type.
757func (x *Application) GetActionParameterType(ActionNameVar string) *glib.VariantType {
758
759 cret := gio.XGActionGroupGetActionParameterType(x.GoPointer(), ActionNameVar)
760 return cret
761}
762
763// Queries the current state of the named action within @action_group.
764//
765// If the action is not stateful then `NULL` will be returned. If the
766// action is stateful then the type of the return value is the type
767// given by [method@Gio.ActionGroup.get_action_state_type].
768//
769// The return value (if non-`NULL`) should be freed with
770// [method@GLib.Variant.unref] when it is no longer required.
771func (x *Application) GetActionState(ActionNameVar string) *glib.Variant {
772
773 cret := gio.XGActionGroupGetActionState(x.GoPointer(), ActionNameVar)
774 return cret
775}
776
777// Requests a hint about the valid range of values for the state of the
778// named action within @action_group.
779//
780// If `NULL` is returned it either means that the action is not stateful
781// or that there is no hint about the valid range of values for the
782// state of the action.
783//
784// If a [type@GLib.Variant] array is returned then each item in the array is a
785// possible value for the state. If a [type@GLib.Variant] pair (ie: two-tuple) is
786// returned then the tuple specifies the inclusive lower and upper bound
787// of valid values for the state.
788//
789// In any case, the information is merely a hint. It may be possible to
790// have a state value outside of the hinted range and setting a value
791// within the range may fail.
792//
793// The return value (if non-`NULL`) should be freed with
794// [method@GLib.Variant.unref] when it is no longer required.
795func (x *Application) GetActionStateHint(ActionNameVar string) *glib.Variant {
796
797 cret := gio.XGActionGroupGetActionStateHint(x.GoPointer(), ActionNameVar)
798 return cret
799}
800
801// Queries the type of the state of the named action within
802// @action_group.
803//
804// If the action is stateful then this function returns the
805// [type@GLib.VariantType] of the state. All calls to
806// [method@Gio.ActionGroup.change_action_state] must give a [type@GLib.Variant] of this
807// type and [method@Gio.ActionGroup.get_action_state] will return a [type@GLib.Variant]
808// of the same type.
809//
810// If the action is not stateful then this function will return `NULL`.
811// In that case, [method@Gio.ActionGroup.get_action_state] will return `NULL`
812// and you must not call [method@Gio.ActionGroup.change_action_state].
813//
814// The state type of a particular action will never change but it is
815// possible for an action to be removed and for a new action to be added
816// with the same name but a different state type.
817func (x *Application) GetActionStateType(ActionNameVar string) *glib.VariantType {
818
819 cret := gio.XGActionGroupGetActionStateType(x.GoPointer(), ActionNameVar)
820 return cret
821}
822
823// Checks if the named action exists within @action_group.
824func (x *Application) HasAction(ActionNameVar string) bool {
825
826 cret := gio.XGActionGroupHasAction(x.GoPointer(), ActionNameVar)
827 return cret
828}
829
830// Lists the actions contained within @action_group.
831//
832// The caller is responsible for freeing the list with [func@GLib.strfreev] when
833// it is no longer required.
834func (x *Application) ListActions() []string {
835
836 cret := gio.XGActionGroupListActions(x.GoPointer())
837 return cret
838}
839
840// Queries all aspects of the named action within an @action_group.
841//
842// This function acquires the information available from
843// [method@Gio.ActionGroup.has_action], [method@Gio.ActionGroup.get_action_enabled],
844// [method@Gio.ActionGroup.get_action_parameter_type],
845// [method@Gio.ActionGroup.get_action_state_type],
846// [method@Gio.ActionGroup.get_action_state_hint] and
847// [method@Gio.ActionGroup.get_action_state] with a single function call.
848//
849// This provides two main benefits.
850//
851// The first is the improvement in efficiency that comes with not having
852// to perform repeated lookups of the action in order to discover
853// different things about it. The second is that implementing
854// [type@Gio.ActionGroup] can now be done by only overriding this one virtual
855// function.
856//
857// The interface provides a default implementation of this function that
858// calls the individual functions, as required, to fetch the
859// information. The interface also provides default implementations of
860// those functions that call this function. All implementations,
861// therefore, must override either this function or all of the others.
862//
863// If the action exists, `TRUE` is returned and any of the requested
864// fields (as indicated by having a non-`NULL` reference passed in) are
865// filled. If the action doesn’t exist, `FALSE` is returned and the
866// fields may or may not have been modified.
867func (x *Application) QueryAction(ActionNameVar string, EnabledVar *bool, ParameterTypeVar **glib.VariantType, StateTypeVar **glib.VariantType, StateHintVar **glib.Variant, StateVar **glib.Variant) bool {
868
869 cret := gio.XGActionGroupQueryAction(x.GoPointer(), ActionNameVar, EnabledVar, ParameterTypeVar, StateTypeVar, StateHintVar, StateVar)
870 return cret
871}
872
873// Adds an action to the @action_map.
874//
875// If the action map already contains an action with the same name
876// as @action then the old action is dropped from the action map.
877//
878// The action map takes its own reference on @action.
879func (x *Application) AddAction(ActionVar gio.Action) {
880
881 gio.XGActionMapAddAction(x.GoPointer(), ActionVar.GoPointer())
882
883}
884
885// A convenience function for creating multiple [class@Gio.SimpleAction]
886// instances and adding them to a [iface@Gio.ActionMap].
887//
888// Each action is constructed as per one [struct@Gio.ActionEntry].
889//
890// ```c
891// static void
892// activate_quit (GSimpleAction *simple,
893//
894// GVariant *parameter,
895// gpointer user_data)
896//
897// {
898// exit (0);
899// }
900//
901// static void
902// activate_print_string (GSimpleAction *simple,
903//
904// GVariant *parameter,
905// gpointer user_data)
906//
907// {
908// g_print ("%s\n", g_variant_get_string (parameter, NULL));
909// }
910//
911// static GActionGroup *
912// create_action_group (void)
913//
914// {
915// const GActionEntry entries[] = {
916// { "quit", activate_quit },
917// { "print-string", activate_print_string, "s" }
918// };
919// GSimpleActionGroup *group;
920//
921// group = g_simple_action_group_new ();
922// g_action_map_add_action_entries (G_ACTION_MAP (group), entries, G_N_ELEMENTS (entries), NULL);
923//
924// return G_ACTION_GROUP (group);
925// }
926//
927// ```
928func (x *Application) AddActionEntries(EntriesVar []gio.ActionEntry, NEntriesVar int, UserDataVar uintptr) {
929
930 gio.XGActionMapAddActionEntries(x.GoPointer(), EntriesVar, NEntriesVar, UserDataVar)
931
932}
933
934// Looks up the action with the name @action_name in @action_map.
935//
936// If no such action exists, returns `NULL`.
937func (x *Application) LookupAction(ActionNameVar string) *gio.ActionBase {
938 var cls *gio.ActionBase
939
940 cret := gio.XGActionMapLookupAction(x.GoPointer(), ActionNameVar)
941
942 if cret == 0 {
943 return nil
944 }
945 gobject.IncreaseRef(cret)
946 cls = &gio.ActionBase{}
947 cls.Ptr = cret
948 return cls
949}
950
951// Removes the named action from the action map.
952//
953// If no action of this name is in the map then nothing happens.
954func (x *Application) RemoveAction(ActionNameVar string) {
955
956 gio.XGActionMapRemoveAction(x.GoPointer(), ActionNameVar)
957
958}
959
960// Remove actions from a [iface@Gio.ActionMap]. This is meant as the reverse of
961// [method@Gio.ActionMap.add_action_entries].
962//
963// ```c
964//
965// static const GActionEntry entries[] = {
966// { "quit", activate_quit },
967// { "print-string", activate_print_string, "s" }
968// };
969//
970// void
971// add_actions (GActionMap *map)
972//
973// {
974// g_action_map_add_action_entries (map, entries, G_N_ELEMENTS (entries), NULL);
975// }
976//
977// void
978// remove_actions (GActionMap *map)
979//
980// {
981// g_action_map_remove_action_entries (map, entries, G_N_ELEMENTS (entries));
982// }
983//
984// ```
985func (x *Application) RemoveActionEntries(EntriesVar []gio.ActionEntry, NEntriesVar int) {
986
987 gio.XGActionMapRemoveActionEntries(x.GoPointer(), EntriesVar, NEntriesVar)
988
989}
990
991func init() {
992 core.SetPackageName("GTK", "gtk4")
993 core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"})
994 var libs []uintptr
995 for _, libPath := range core.GetPaths("GTK") {
996 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
997 if err != nil {
998 panic(err)
999 }
1000 libs = append(libs, lib)
1001 }
1002
1003 core.PuregoSafeRegister(&xApplicationInhibitFlagsGLibType, libs, "gtk_application_inhibit_flags_get_type")
1004
1005 core.PuregoSafeRegister(&xApplicationGLibType, libs, "gtk_application_get_type")
1006
1007 core.PuregoSafeRegister(&xNewApplication, libs, "gtk_application_new")
1008
1009 core.PuregoSafeRegister(&xApplicationAddWindow, libs, "gtk_application_add_window")
1010 core.PuregoSafeRegister(&xApplicationGetAccelsForAction, libs, "gtk_application_get_accels_for_action")
1011 core.PuregoSafeRegister(&xApplicationGetActionsForAccel, libs, "gtk_application_get_actions_for_accel")
1012 core.PuregoSafeRegister(&xApplicationGetActiveWindow, libs, "gtk_application_get_active_window")
1013 core.PuregoSafeRegister(&xApplicationGetMenuById, libs, "gtk_application_get_menu_by_id")
1014 core.PuregoSafeRegister(&xApplicationGetMenubar, libs, "gtk_application_get_menubar")
1015 core.PuregoSafeRegister(&xApplicationGetWindowById, libs, "gtk_application_get_window_by_id")
1016 core.PuregoSafeRegister(&xApplicationGetWindows, libs, "gtk_application_get_windows")
1017 core.PuregoSafeRegister(&xApplicationInhibit, libs, "gtk_application_inhibit")
1018 core.PuregoSafeRegister(&xApplicationListActionDescriptions, libs, "gtk_application_list_action_descriptions")
1019 core.PuregoSafeRegister(&xApplicationRemoveWindow, libs, "gtk_application_remove_window")
1020 core.PuregoSafeRegister(&xApplicationSetAccelsForAction, libs, "gtk_application_set_accels_for_action")
1021 core.PuregoSafeRegister(&xApplicationSetMenubar, libs, "gtk_application_set_menubar")
1022 core.PuregoSafeRegister(&xApplicationUninhibit, libs, "gtk_application_uninhibit")
1023
1024}