gtk4::prelude

Trait GtkApplicationExt

Source
pub trait GtkApplicationExt: IsA<Application> + 'static {
Show 24 methods // Provided methods fn add_window(&self, window: &impl IsA<Window>) { ... } fn accels_for_action(&self, detailed_action_name: &str) -> Vec<GString> { ... } fn actions_for_accel(&self, accel: &str) -> Vec<GString> { ... } fn active_window(&self) -> Option<Window> { ... } fn menu_by_id(&self, id: &str) -> Option<Menu> { ... } fn menubar(&self) -> Option<MenuModel> { ... } fn window_by_id(&self, id: u32) -> Option<Window> { ... } fn windows(&self) -> Vec<Window> { ... } fn inhibit( &self, window: Option<&impl IsA<Window>>, flags: ApplicationInhibitFlags, reason: Option<&str>, ) -> u32 { ... } fn list_action_descriptions(&self) -> Vec<GString> { ... } fn remove_window(&self, window: &impl IsA<Window>) { ... } fn set_accels_for_action(&self, detailed_action_name: &str, accels: &[&str]) { ... } fn set_menubar(&self, menubar: Option<&impl IsA<MenuModel>>) { ... } fn uninhibit(&self, cookie: u32) { ... } fn is_register_session(&self) -> bool { ... } fn set_register_session(&self, register_session: bool) { ... } fn is_screensaver_active(&self) -> bool { ... } fn connect_query_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { ... } fn connect_window_added<F: Fn(&Self, &Window) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_window_removed<F: Fn(&Self, &Window) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_active_window_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_menubar_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_register_session_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_screensaver_active_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... }
}
Expand description

Trait containing all Application methods.

§Implementors

Application

Provided Methods§

Source

fn add_window(&self, window: &impl IsA<Window>)

Adds a window to the application.

This call can only happen after the application has started; typically, you should add new application windows in response to the emission of the [activate][struct@crate::GIO::Application#activate] signal.

This call is equivalent to setting the application property of the window to @self.

Normally, the connection between the application and the window will remain until the window is destroyed, but you can explicitly remove it with remove_window().

GTK will keep the application running as long as it has any windows.

§window

a window

Source

fn accels_for_action(&self, detailed_action_name: &str) -> Vec<GString>

Gets the accelerators that are currently associated with the given action.

§detailed_action_name

a detailed action name, specifying an action and target to obtain accelerators for

§Returns

accelerators for @detailed_action_name

Source

fn actions_for_accel(&self, accel: &str) -> Vec<GString>

Returns the list of actions (possibly empty) that the accelerator maps to.

Each item in the list is a detailed action name in the usual form.

This might be useful to discover if an accel already exists in order to prevent installation of a conflicting accelerator (from an accelerator editor or a plugin system, for example). Note that having more than one action per accelerator may not be a bad thing and might make sense in cases where the actions never appear in the same context.

In case there are no actions for a given accelerator, an empty array is returned. NULL is never returned.

It is a programmer error to pass an invalid accelerator string.

If you are unsure, check it with accelerator_parse() first.

§accel

an accelerator that can be parsed by accelerator_parse()

§Returns

actions for @accel

Source

fn active_window(&self) -> Option<Window>

Gets the “active” window for the application.

The active window is the one that was most recently focused (within the application). This window may not have the focus at the moment if another application has it — this is just the most recently-focused window within this application.

§Returns

the active window

Source

fn menu_by_id(&self, id: &str) -> Option<Menu>

Gets a menu from automatically loaded resources.

See the section on Automatic resources for more information.

§id

the ID of the menu to look up

§Returns

Gets the menu with the given ID from the automatically loaded resources

Source

fn menubar(&self) -> Option<MenuModel>

Returns the menu model for the menu bar of the application.

§Returns

the menubar for windows of the application

Source

fn window_by_id(&self, id: u32) -> Option<Window>

Returns the window with the given ID.

The ID of a ApplicationWindow can be retrieved with ApplicationWindowExt::id().

§id

an identifier number

§Returns

the window for the given ID

Source

fn windows(&self) -> Vec<Window>

Gets a list of the window associated with the application.

The list is sorted by most recently focused window, such that the first element is the currently focused window. (Useful for choosing a parent for a transient window.)

The list that is returned should not be modified in any way. It will only remain valid until the next focus change or window creation or deletion.

§Returns

the list of windows

Source

fn inhibit( &self, window: Option<&impl IsA<Window>>, flags: ApplicationInhibitFlags, reason: Option<&str>, ) -> u32

Informs the session manager that certain types of actions should be inhibited.

This is not guaranteed to work on all platforms and for all types of actions.

Applications should invoke this method when they begin an operation that should not be interrupted, such as creating a CD or DVD. The types of actions that may be blocked are specified by the @flags parameter. When the application completes the operation it should call uninhibit() to remove the inhibitor. Note that an application can have multiple inhibitors, and all of them must be individually removed. Inhibitors are also cleared when the application exits.

Applications should not expect that they will always be able to block the action. In most cases, users will be given the option to force the action to take place.

The @reason message should be short and to the point.

If a window is given, the session manager may point the user to this window to find out more about why the action is inhibited.

The cookie tha tis returned by this function should be used as an argument to uninhibit() in order to remove the request.

§window

a window

§flags

what types of actions should be inhibited

§reason

a short, human-readable string that explains why these operations are inhibited

§Returns

A non-zero cookie that is used to uniquely identify this, or 0 if the platform does not support inhibiting or the request failed for some reason

Source

fn list_action_descriptions(&self) -> Vec<GString>

Lists the detailed action names which have associated accelerators.

See set_accels_for_action().

§Returns

the detailed action names

Source

fn remove_window(&self, window: &impl IsA<Window>)

Remove a window from the application.

If the window belongs to the application then this call is equivalent to setting the application property of the window to NULL.

The application may stop running as a result of a call to this function, if the window was the last window of the application.

§window

a window

Source

fn set_accels_for_action(&self, detailed_action_name: &str, accels: &[&str])

Sets zero or more keyboard accelerators that will trigger the given action.

The first item in @accels will be the primary accelerator, which may be displayed in the UI.

To remove all accelerators for an action, use an empty, zero-terminated array for @accels.

For the @detailed_action_name, see gio::Action::parse_detailed_name() and [Gio.Action.print_detailed_name].

§detailed_action_name

a detailed action name, specifying an action and target to associate accelerators with

§accels

a list of accelerators in the format understood by accelerator_parse()

Source

fn set_menubar(&self, menubar: Option<&impl IsA<MenuModel>>)

Sets or unsets the menubar for windows of the application.

This is a menubar in the traditional sense.

This can only be done in the primary instance of the application, after it has been registered. vfunc::GIO::Application::startup is a good place to call this.

Depending on the desktop environment, this may appear at the top of each window, or at the top of the screen. In some environments, if both the application menu and the menubar are set, the application menu will be presented as if it were the first item of the menubar. Other environments treat the two as completely separate — for example, the application menu may be rendered by the desktop shell while the menubar (if set) remains in each individual window.

Use the base GActionMap interface to add actions, to respond to the user selecting these menu items.

a menu model

Source

fn uninhibit(&self, cookie: u32)

Removes an inhibitor that has been previously established.

See inhibit().

Inhibitors are also cleared when the application exits.

a cookie that was returned by inhibit()

Source

fn is_register_session(&self) -> bool

Set this property to true to register with the session manager.

This will make GTK track the session state (such as the screensaver-active property).

Source

fn set_register_session(&self, register_session: bool)

Set this property to true to register with the session manager.

This will make GTK track the session state (such as the screensaver-active property).

Source

fn is_screensaver_active(&self) -> bool

This property is true if GTK believes that the screensaver is currently active.

GTK only tracks session state (including this) when register-session is set to true.

Tracking the screensaver state is currently only supported on Linux.

Source

fn connect_query_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId

Emitted when the session manager is about to end the session.

This signal is only emitted if register-session is true. Applications can connect to this signal and call inhibit() with [flags@Gtk.ApplicationInhibitFlags.logout] to delay the end of the session until state has been saved.

Source

fn connect_window_added<F: Fn(&Self, &Window) + 'static>( &self, f: F, ) -> SignalHandlerId

Emitted when a window is added to an application.

See add_window().

§window

the newly-added window

Source

fn connect_window_removed<F: Fn(&Self, &Window) + 'static>( &self, f: F, ) -> SignalHandlerId

Emitted when a window is removed from an application.

This can happen as a side-effect of the window being destroyed or explicitly through remove_window().

§window

the window that is being removed

Source

fn connect_active_window_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

Source

fn connect_menubar_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

Source

fn connect_register_session_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

Source

fn connect_screensaver_active_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§