gtk4/auto/application.rs
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 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::{ffi, ApplicationInhibitFlags, Window};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
/// A high-level API for writing applications.
///
/// [`Application`][crate::Application] supports many aspects of writing a GTK application
/// in a convenient fashion, without enforcing a one-size-fits-all model.
///
/// Currently, it handles GTK initialization, application uniqueness, session
/// management, provides some basic scriptability and desktop shell integration
/// by exporting actions and menus and manages a list of toplevel windows whose
/// life-cycle is automatically tied to the life-cycle of your application.
///
/// While [`Application`][crate::Application] works fine with plain [`Window`][crate::Window]s,
/// it is recommended to use it together with [`ApplicationWindow`][crate::ApplicationWindow].
///
/// ## Automatic resources
///
/// [`Application`][crate::Application] will automatically load menus from the [`Builder`][crate::Builder]
/// resource located at "gtk/menus.ui", relative to the application's
/// resource base path (see [`ApplicationExtManual::set_resource_base_path()`][crate::gio::prelude::ApplicationExtManual::set_resource_base_path()]).
/// The menu with the ID "menubar" is taken as the application's
/// menubar. Additional menus (most interesting submenus) can be named
/// and accessed via [`GtkApplicationExt::menu_by_id()`][crate::prelude::GtkApplicationExt::menu_by_id()] which allows for
/// dynamic population of a part of the menu structure.
///
/// Note that automatic resource loading uses the resource base path
/// that is set at construction time and will not work if the resource
/// base path is changed at a later time.
///
/// It is also possible to provide the menubar manually using
/// [`GtkApplicationExt::set_menubar()`][crate::prelude::GtkApplicationExt::set_menubar()].
///
/// [`Application`][crate::Application] will also automatically setup an icon search path for
/// the default icon theme by appending "icons" to the resource base
/// path. This allows your application to easily store its icons as
/// resources. See [`IconTheme::add_resource_path()`][crate::IconTheme::add_resource_path()] for more
/// information.
///
/// If there is a resource located at `gtk/help-overlay.ui` which
/// defines a [`ShortcutsWindow`][crate::ShortcutsWindow] with ID `help_overlay` then
/// [`Application`][crate::Application] associates an instance of this shortcuts window with
/// each [`ApplicationWindow`][crate::ApplicationWindow] and sets up the keyboard accelerator
/// <kbd>Control</kbd>+<kbd>?</kbd> to open it. To create a menu item that
/// displays the shortcuts window, associate the item with the action
/// `win.show-help-overlay`.
///
/// [`Application`][crate::Application] will also automatically set the application id as the
/// default window icon. Use [`Window::set_default_icon_name()`][crate::Window::set_default_icon_name()] or
/// [`icon-name`][struct@crate::Window#icon-name] to override that behavior.
///
/// ## A simple application
///
/// [A simple example](https://gitlab.gnome.org/GNOME/gtk/tree/main/examples/bp/bloatpad.c)
/// is available in the GTK source code repository
///
/// [`Application`][crate::Application] optionally registers with a session manager of the
/// users session (if you set the [`register-session`][struct@crate::Application#register-session]
/// property) and offers various functionality related to the session
/// life-cycle.
///
/// An application can block various ways to end the session with
/// the [`GtkApplicationExt::inhibit()`][crate::prelude::GtkApplicationExt::inhibit()] function. Typical use cases for
/// this kind of inhibiting are long-running, uninterruptible operations,
/// such as burning a CD or performing a disk backup. The session
/// manager may not honor the inhibitor, but it can be expected to
/// inform the user about the negative consequences of ending the
/// session while inhibitors are present.
///
/// ## See Also
///
/// - [Using GtkApplication](https://developer.gnome.org/documentation/tutorials/application.html)
/// - [Getting Started with GTK: Basics](getting_started.html#basics)
///
/// ## Properties
///
///
/// #### `active-window`
/// The currently focused window of the application.
///
/// Readable
///
///
/// #### `menubar`
/// The menu model to be used for the application's menu bar.
///
/// Readable | Writeable
///
///
/// #### `register-session`
/// Set this property to true to register with the session manager.
///
/// This will make GTK track the session state (such as the
/// [`screensaver-active`][struct@crate::Application#screensaver-active] property).
///
/// Readable | Writeable
///
///
/// #### `screensaver-active`
/// This property is true if GTK believes that the screensaver
/// is currently active.
///
/// GTK only tracks session state (including this) when
/// [`register-session`][struct@crate::Application#register-session] is set to true.
///
/// Tracking the screensaver state is currently only supported on
/// Linux.
///
/// Readable
/// <details><summary><h4>Application</h4></summary>
///
///
/// #### `action-group`
/// The group of actions that the application exports.
///
/// Writeable
///
///
/// #### `application-id`
/// The unique identifier for the application.
///
/// Readable | Writeable | Construct
///
///
/// #### `flags`
/// Flags specifying the behaviour of the application.
///
/// Readable | Writeable
///
///
/// #### `inactivity-timeout`
/// Time (in milliseconds) to stay alive after becoming idle.
///
/// Readable | Writeable
///
///
/// #### `is-busy`
/// Whether the application is currently marked as busy through
/// g_application_mark_busy() or g_application_bind_busy_property().
///
/// Readable
///
///
/// #### `is-registered`
/// Whether [`ApplicationExtManual::register()`][crate::gio::prelude::ApplicationExtManual::register()] has been called.
///
/// Readable
///
///
/// #### `is-remote`
/// Whether this application instance is remote.
///
/// Readable
///
///
/// #### `resource-base-path`
/// The base resource path for the application.
///
/// Readable | Writeable
///
///
/// #### `version`
/// The human-readable version number of the application.
///
/// Readable | Writeable
/// </details>
///
/// ## Signals
///
///
/// #### `query-end`
/// Emitted when the session manager is about to end the session.
///
/// This signal is only emitted if [`register-session`][struct@crate::Application#register-session]
/// is true. Applications can connect to this signal and call
/// [`GtkApplicationExt::inhibit()`][crate::prelude::GtkApplicationExt::inhibit()] with [flags@Gtk.ApplicationInhibitFlags.logout]
/// to delay the end of the session until state has been saved.
///
///
///
///
/// #### `window-added`
/// Emitted when a window is added to an application.
///
/// See [`GtkApplicationExt::add_window()`][crate::prelude::GtkApplicationExt::add_window()].
///
///
///
///
/// #### `window-removed`
/// Emitted when a window is removed from an application.
///
/// This can happen as a side-effect of the window being destroyed
/// or explicitly through [`GtkApplicationExt::remove_window()`][crate::prelude::GtkApplicationExt::remove_window()].
///
///
/// <details><summary><h4>Application</h4></summary>
///
///
/// #### `activate`
/// The ::activate signal is emitted on the primary instance when an
/// activation occurs. See g_application_activate().
///
///
///
///
/// #### `command-line`
/// The ::command-line signal is emitted on the primary instance when
/// a commandline is not handled locally. See g_application_run() and
/// the #GApplicationCommandLine documentation for more information.
///
///
///
///
/// #### `handle-local-options`
/// The ::handle-local-options signal is emitted on the local instance
/// after the parsing of the commandline options has occurred.
///
/// You can add options to be recognised during commandline option
/// parsing using g_application_add_main_option_entries() and
/// g_application_add_option_group().
///
/// Signal handlers can inspect @options (along with values pointed to
/// from the @arg_data of an installed #GOptionEntrys) in order to
/// decide to perform certain actions, including direct local handling
/// (which may be useful for options like --version).
///
/// In the event that the application is marked
/// [`gio::ApplicationFlags::HANDLES_COMMAND_LINE`][crate::gio::ApplicationFlags::HANDLES_COMMAND_LINE] the "normal processing" will
/// send the @options dictionary to the primary instance where it can be
/// read with g_application_command_line_get_options_dict(). The signal
/// handler can modify the dictionary before returning, and the
/// modified dictionary will be sent.
///
/// In the event that [`gio::ApplicationFlags::HANDLES_COMMAND_LINE`][crate::gio::ApplicationFlags::HANDLES_COMMAND_LINE] is not set,
/// "normal processing" will treat the remaining uncollected command
/// line arguments as filenames or URIs. If there are no arguments,
/// the application is activated by g_application_activate(). One or
/// more arguments results in a call to g_application_open().
///
/// If you want to handle the local commandline arguments for yourself
/// by converting them to calls to g_application_open() or
/// g_action_group_activate_action() then you must be sure to register
/// the application first. You should probably not call
/// g_application_activate() for yourself, however: just return -1 and
/// allow the default handler to do it for you. This will ensure that
/// the `--gapplication-service` switch works properly (i.e. no activation
/// in that case).
///
/// Note that this signal is emitted from the default implementation of
/// local_command_line(). If you override that function and don't
/// chain up then this signal will never be emitted.
///
/// You can override local_command_line() if you need more powerful
/// capabilities than what is provided here, but this should not
/// normally be required.
///
///
///
///
/// #### `name-lost`
/// The ::name-lost signal is emitted only on the registered primary instance
/// when a new instance has taken over. This can only happen if the application
/// is using the [`gio::ApplicationFlags::ALLOW_REPLACEMENT`][crate::gio::ApplicationFlags::ALLOW_REPLACEMENT] flag.
///
/// The default handler for this signal calls g_application_quit().
///
///
///
///
/// #### `open`
/// The ::open signal is emitted on the primary instance when there are
/// files to open. See g_application_open() for more information.
///
///
///
///
/// #### `shutdown`
/// The ::shutdown signal is emitted only on the registered primary instance
/// immediately after the main loop terminates.
///
///
///
///
/// #### `startup`
/// The ::startup signal is emitted on the primary instance immediately
/// after registration. See g_application_register().
///
///
/// </details>
/// <details><summary><h4>ActionGroup</h4></summary>
///
///
/// #### `action-added`
/// Signals that a new action was just added to the group.
///
/// This signal is emitted after the action has been added
/// and is now visible.
///
/// Detailed
///
///
/// #### `action-enabled-changed`
/// Signals that the enabled status of the named action has changed.
///
/// Detailed
///
///
/// #### `action-removed`
/// Signals that an action is just about to be removed from the group.
///
/// This signal is emitted before the action is removed, so the action
/// is still visible and can be queried from the signal handler.
///
/// Detailed
///
///
/// #### `action-state-changed`
/// Signals that the state of the named action has changed.
///
/// Detailed
/// </details>
///
/// # Implements
///
/// [`GtkApplicationExt`][trait@crate::prelude::GtkApplicationExt], [`trait@gio::prelude::ApplicationExt`], [`trait@glib::ObjectExt`], [`trait@gio::prelude::ActionGroupExt`], [`trait@gio::prelude::ActionMapExt`]
#[doc(alias = "GtkApplication")]
pub struct Application(Object<ffi::GtkApplication, ffi::GtkApplicationClass>) @extends gio::Application, @implements gio::ActionGroup, gio::ActionMap;
match fn {
type_ => || ffi::gtk_application_get_type(),
}
}
impl Application {
pub const NONE: Option<&'static Application> = None;
// rustdoc-stripper-ignore-next
/// Creates a new builder-pattern struct instance to construct [`Application`] objects.
///
/// This method returns an instance of [`ApplicationBuilder`](crate::builders::ApplicationBuilder) which can be used to create [`Application`] objects.
pub fn builder() -> ApplicationBuilder {
ApplicationBuilder::new()
}
}
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`Application`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct ApplicationBuilder {
builder: glib::object::ObjectBuilder<'static, Application>,
}
impl ApplicationBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
/// The menu model to be used for the application's menu bar.
pub fn menubar(self, menubar: &impl IsA<gio::MenuModel>) -> Self {
Self {
builder: self.builder.property("menubar", menubar.clone().upcast()),
}
}
/// Set this property to true to register with the session manager.
///
/// This will make GTK track the session state (such as the
/// [`screensaver-active`][struct@crate::Application#screensaver-active] property).
pub fn register_session(self, register_session: bool) -> Self {
Self {
builder: self.builder.property("register-session", register_session),
}
}
/// The unique identifier for the application.
pub fn application_id(self, application_id: impl Into<glib::GString>) -> Self {
Self {
builder: self
.builder
.property("application-id", application_id.into()),
}
}
/// Flags specifying the behaviour of the application.
pub fn flags(self, flags: gio::ApplicationFlags) -> Self {
Self {
builder: self.builder.property("flags", flags),
}
}
/// Time (in milliseconds) to stay alive after becoming idle.
pub fn inactivity_timeout(self, inactivity_timeout: u32) -> Self {
Self {
builder: self
.builder
.property("inactivity-timeout", inactivity_timeout),
}
}
/// The base resource path for the application.
pub fn resource_base_path(self, resource_base_path: impl Into<glib::GString>) -> Self {
Self {
builder: self
.builder
.property("resource-base-path", resource_base_path.into()),
}
}
/// The human-readable version number of the application.
#[cfg(feature = "gio_v2_80")]
#[cfg_attr(docsrs, doc(cfg(feature = "gio_v2_80")))]
pub fn version(self, version: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("version", version.into()),
}
}
// rustdoc-stripper-ignore-next
/// Build the [`Application`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> Application {
let ret = self.builder.build();
{
Application::register_startup_hook(&ret);
}
ret
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::Application>> Sealed for T {}
}
/// Trait containing all [`struct@Application`] methods.
///
/// # Implementors
///
/// [`Application`][struct@crate::Application]
pub trait GtkApplicationExt: IsA<Application> + sealed::Sealed + 'static {
/// 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`][struct@crate::Window#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()`][Self::remove_window()].
///
/// GTK will keep the application running as long as it has any windows.
/// ## `window`
/// a window
#[doc(alias = "gtk_application_add_window")]
fn add_window(&self, window: &impl IsA<Window>) {
unsafe {
ffi::gtk_application_add_window(
self.as_ref().to_glib_none().0,
window.as_ref().to_glib_none().0,
);
}
}
/// 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
#[doc(alias = "gtk_application_get_accels_for_action")]
#[doc(alias = "get_accels_for_action")]
fn accels_for_action(&self, detailed_action_name: &str) -> Vec<glib::GString> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::gtk_application_get_accels_for_action(
self.as_ref().to_glib_none().0,
detailed_action_name.to_glib_none().0,
))
}
}
/// 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()`][crate::accelerator_parse()] first.
/// ## `accel`
/// an accelerator that can be parsed by [`accelerator_parse()`][crate::accelerator_parse()]
///
/// # Returns
///
/// actions for @accel
#[doc(alias = "gtk_application_get_actions_for_accel")]
#[doc(alias = "get_actions_for_accel")]
fn actions_for_accel(&self, accel: &str) -> Vec<glib::GString> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::gtk_application_get_actions_for_accel(
self.as_ref().to_glib_none().0,
accel.to_glib_none().0,
))
}
}
/// 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
#[doc(alias = "gtk_application_get_active_window")]
#[doc(alias = "get_active_window")]
#[doc(alias = "active-window")]
fn active_window(&self) -> Option<Window> {
unsafe {
from_glib_none(ffi::gtk_application_get_active_window(
self.as_ref().to_glib_none().0,
))
}
}
/// Gets a menu from automatically loaded resources.
///
/// See [the section on Automatic resources](class.Application.html#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
#[doc(alias = "gtk_application_get_menu_by_id")]
#[doc(alias = "get_menu_by_id")]
fn menu_by_id(&self, id: &str) -> Option<gio::Menu> {
unsafe {
from_glib_none(ffi::gtk_application_get_menu_by_id(
self.as_ref().to_glib_none().0,
id.to_glib_none().0,
))
}
}
/// Returns the menu model for the menu bar of the application.
///
/// # Returns
///
/// the menubar for windows of the application
#[doc(alias = "gtk_application_get_menubar")]
#[doc(alias = "get_menubar")]
fn menubar(&self) -> Option<gio::MenuModel> {
unsafe {
from_glib_none(ffi::gtk_application_get_menubar(
self.as_ref().to_glib_none().0,
))
}
}
/// Returns the window with the given ID.
///
/// The ID of a [`ApplicationWindow`][crate::ApplicationWindow] can be retrieved with
/// [`ApplicationWindowExt::id()`][crate::prelude::ApplicationWindowExt::id()].
/// ## `id`
/// an identifier number
///
/// # Returns
///
/// the window for the given ID
#[doc(alias = "gtk_application_get_window_by_id")]
#[doc(alias = "get_window_by_id")]
fn window_by_id(&self, id: u32) -> Option<Window> {
unsafe {
from_glib_none(ffi::gtk_application_get_window_by_id(
self.as_ref().to_glib_none().0,
id,
))
}
}
/// 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
#[doc(alias = "gtk_application_get_windows")]
#[doc(alias = "get_windows")]
fn windows(&self) -> Vec<Window> {
unsafe {
FromGlibPtrContainer::from_glib_none(ffi::gtk_application_get_windows(
self.as_ref().to_glib_none().0,
))
}
}
/// 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()`][Self::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()`][Self::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
#[doc(alias = "gtk_application_inhibit")]
fn inhibit(
&self,
window: Option<&impl IsA<Window>>,
flags: ApplicationInhibitFlags,
reason: Option<&str>,
) -> u32 {
unsafe {
ffi::gtk_application_inhibit(
self.as_ref().to_glib_none().0,
window.map(|p| p.as_ref()).to_glib_none().0,
flags.into_glib(),
reason.to_glib_none().0,
)
}
}
/// Lists the detailed action names which have associated accelerators.
///
/// See [`set_accels_for_action()`][Self::set_accels_for_action()].
///
/// # Returns
///
/// the detailed action names
#[doc(alias = "gtk_application_list_action_descriptions")]
fn list_action_descriptions(&self) -> Vec<glib::GString> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::gtk_application_list_action_descriptions(
self.as_ref().to_glib_none().0,
))
}
}
/// Remove a window from the application.
///
/// If the window belongs to the application then this call is
/// equivalent to setting the [`application`][struct@crate::Window#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
#[doc(alias = "gtk_application_remove_window")]
fn remove_window(&self, window: &impl IsA<Window>) {
unsafe {
ffi::gtk_application_remove_window(
self.as_ref().to_glib_none().0,
window.as_ref().to_glib_none().0,
);
}
}
/// 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()`][crate::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()`][crate::accelerator_parse()]
#[doc(alias = "gtk_application_set_accels_for_action")]
fn set_accels_for_action(&self, detailed_action_name: &str, accels: &[&str]) {
unsafe {
ffi::gtk_application_set_accels_for_action(
self.as_ref().to_glib_none().0,
detailed_action_name.to_glib_none().0,
accels.to_glib_none().0,
);
}
}
/// 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.
/// ## `menubar`
/// a menu model
#[doc(alias = "gtk_application_set_menubar")]
#[doc(alias = "menubar")]
fn set_menubar(&self, menubar: Option<&impl IsA<gio::MenuModel>>) {
unsafe {
ffi::gtk_application_set_menubar(
self.as_ref().to_glib_none().0,
menubar.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
/// Removes an inhibitor that has been previously established.
///
/// See [`inhibit()`][Self::inhibit()].
///
/// Inhibitors are also cleared when the application exits.
/// ## `cookie`
/// a cookie that was returned by [`inhibit()`][Self::inhibit()]
#[doc(alias = "gtk_application_uninhibit")]
fn uninhibit(&self, cookie: u32) {
unsafe {
ffi::gtk_application_uninhibit(self.as_ref().to_glib_none().0, cookie);
}
}
/// Set this property to true to register with the session manager.
///
/// This will make GTK track the session state (such as the
/// [`screensaver-active`][struct@crate::Application#screensaver-active] property).
#[doc(alias = "register-session")]
fn is_register_session(&self) -> bool {
ObjectExt::property(self.as_ref(), "register-session")
}
/// Set this property to true to register with the session manager.
///
/// This will make GTK track the session state (such as the
/// [`screensaver-active`][struct@crate::Application#screensaver-active] property).
#[doc(alias = "register-session")]
fn set_register_session(&self, register_session: bool) {
ObjectExt::set_property(self.as_ref(), "register-session", register_session)
}
/// This property is true if GTK believes that the screensaver
/// is currently active.
///
/// GTK only tracks session state (including this) when
/// [`register-session`][struct@crate::Application#register-session] is set to true.
///
/// Tracking the screensaver state is currently only supported on
/// Linux.
#[doc(alias = "screensaver-active")]
fn is_screensaver_active(&self) -> bool {
ObjectExt::property(self.as_ref(), "screensaver-active")
}
/// Emitted when the session manager is about to end the session.
///
/// This signal is only emitted if [`register-session`][struct@crate::Application#register-session]
/// is true. Applications can connect to this signal and call
/// [`inhibit()`][Self::inhibit()] with [flags@Gtk.ApplicationInhibitFlags.logout]
/// to delay the end of the session until state has been saved.
#[doc(alias = "query-end")]
fn connect_query_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn query_end_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
this: *mut ffi::GtkApplication,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Application::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"query-end\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
query_end_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
/// Emitted when a window is added to an application.
///
/// See [`add_window()`][Self::add_window()].
/// ## `window`
/// the newly-added window
#[doc(alias = "window-added")]
fn connect_window_added<F: Fn(&Self, &Window) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn window_added_trampoline<
P: IsA<Application>,
F: Fn(&P, &Window) + 'static,
>(
this: *mut ffi::GtkApplication,
window: *mut ffi::GtkWindow,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(
Application::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(window),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"window-added\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
window_added_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
/// 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()`][Self::remove_window()].
/// ## `window`
/// the window that is being removed
#[doc(alias = "window-removed")]
fn connect_window_removed<F: Fn(&Self, &Window) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn window_removed_trampoline<
P: IsA<Application>,
F: Fn(&P, &Window) + 'static,
>(
this: *mut ffi::GtkApplication,
window: *mut ffi::GtkWindow,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(
Application::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(window),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"window-removed\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
window_removed_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "active-window")]
fn connect_active_window_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_active_window_trampoline<
P: IsA<Application>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GtkApplication,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Application::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::active-window\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_active_window_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "menubar")]
fn connect_menubar_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_menubar_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
this: *mut ffi::GtkApplication,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Application::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::menubar\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_menubar_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "register-session")]
fn connect_register_session_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_register_session_trampoline<
P: IsA<Application>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GtkApplication,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Application::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::register-session\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_register_session_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "screensaver-active")]
fn connect_screensaver_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_screensaver_active_trampoline<
P: IsA<Application>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GtkApplication,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(Application::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::screensaver-active\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_screensaver_active_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<Application>> GtkApplicationExt for O {}