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
// 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::ApplicationInhibitFlags;
use crate::Window;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::StaticType;
use glib::ToValue;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
glib::wrapper! {
/// [`Application`][crate::Application] is a class that handles many important aspects
/// of a GTK+ application in a convenient fashion, without enforcing
/// a one-size-fits-all application model.
///
/// Currently, GtkApplication 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 GtkApplication works fine with plain `GtkWindows`, it is recommended
/// to use it together with [`ApplicationWindow`][crate::ApplicationWindow].
///
/// When GDK threads are enabled, GtkApplication will acquire the GDK
/// lock when invoking actions that arrive from other processes. The GDK
/// lock is not touched for local action invocations. In order to have
/// actions invoked in a predictable context it is therefore recommended
/// that the GDK lock be held while invoking actions locally with
/// [`ActionGroupExtManual::activate_action()`][crate::gio::prelude::ActionGroupExtManual::activate_action()]. The same applies to actions
/// associated with [`ApplicationWindow`][crate::ApplicationWindow] and to the “activate” and
/// “open” [`gio::Application`][crate::gio::Application] methods.
///
/// ## Automatic resources ## {`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 "app-menu" is taken as the application's app menu
/// and 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.
///
/// If the resources "gtk/menus-appmenu.ui" or "gtk/menus-traditional.ui" are
/// present then these files will be used in preference, depending on the value
/// of [`GtkApplicationExt::prefers_app_menu()`][crate::prelude::GtkApplicationExt::prefers_app_menu()]. If the resource "gtk/menus-common.ui"
/// is present it will be loaded as well. This is useful for storing items that
/// are referenced from both "gtk/menus-appmenu.ui" and
/// "gtk/menus-traditional.ui".
///
/// It is also possible to provide the menus manually using
/// [`GtkApplicationExt::set_app_menu()`][crate::prelude::GtkApplicationExt::set_app_menu()] and [`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 [`IconThemeExt::add_resource_path()`][crate::prelude::IconThemeExt::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 GtkApplication
/// associates an instance of this shortcuts window with each
/// [`ApplicationWindow`][crate::ApplicationWindow] and sets up keyboard accelerators (Control-F1
/// and Control-?) to open it. To create a menu item that displays the
/// shortcuts window, associate the item with the action win.show-help-overlay.
///
/// ## A simple application ## {`gtkapplication`}
///
/// [A simple example](https://git.gnome.org/browse/gtk+/tree/examples/bp/bloatpad.c)
///
/// GtkApplication optionally registers with a session manager
/// of the users session (if you set the `property::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 ## {`seealso`}
/// [HowDoI: Using GtkApplication](https://wiki.gnome.org/HowDoI/GtkApplication),
/// [Getting Started with GTK+: Basics](https://developer.gnome.org/gtk3/stable/gtk-getting-started.html`id`-1.2.3.3)
///
/// # Implements
///
/// [`GtkApplicationExt`][trait@crate::prelude::GtkApplicationExt], [`trait@gio::prelude::ApplicationExt`], [`trait@glib::ObjectExt`], [`trait@gio::prelude::ActionGroupExt`], [`trait@gio::prelude::ActionMapExt`], [`gio::ApplicationExtManual`][trait@crate::prelude::gio::ApplicationExtManual]
#[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::default()
}
}
#[derive(Clone, Default)]
// 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 {
app_menu: Option<gio::MenuModel>,
menubar: Option<gio::MenuModel>,
register_session: Option<bool>,
action_group: Option<gio::ActionGroup>,
application_id: Option<String>,
flags: Option<gio::ApplicationFlags>,
inactivity_timeout: Option<u32>,
resource_base_path: Option<String>,
}
impl ApplicationBuilder {
// rustdoc-stripper-ignore-next
/// Create a new [`ApplicationBuilder`].
pub fn new() -> Self {
Self::default()
}
// 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 mut properties: Vec<(&str, &dyn ToValue)> = vec![];
if let Some(ref app_menu) = self.app_menu {
properties.push(("app-menu", app_menu));
}
if let Some(ref menubar) = self.menubar {
properties.push(("menubar", menubar));
}
if let Some(ref register_session) = self.register_session {
properties.push(("register-session", register_session));
}
if let Some(ref action_group) = self.action_group {
properties.push(("action-group", action_group));
}
if let Some(ref application_id) = self.application_id {
properties.push(("application-id", application_id));
}
if let Some(ref flags) = self.flags {
properties.push(("flags", flags));
}
if let Some(ref inactivity_timeout) = self.inactivity_timeout {
properties.push(("inactivity-timeout", inactivity_timeout));
}
if let Some(ref resource_base_path) = self.resource_base_path {
properties.push(("resource-base-path", resource_base_path));
}
let ret = glib::Object::new::<Application>(&properties)
.expect("Failed to create an instance of Application");
{
Application::register_startup_hook(&ret);
}
ret
}
pub fn app_menu(mut self, app_menu: &impl IsA<gio::MenuModel>) -> Self {
self.app_menu = Some(app_menu.clone().upcast());
self
}
pub fn menubar(mut self, menubar: &impl IsA<gio::MenuModel>) -> Self {
self.menubar = Some(menubar.clone().upcast());
self
}
/// Set this property to [`true`] to register with the session manager.
pub fn register_session(mut self, register_session: bool) -> Self {
self.register_session = Some(register_session);
self
}
pub fn action_group(mut self, action_group: &impl IsA<gio::ActionGroup>) -> Self {
self.action_group = Some(action_group.clone().upcast());
self
}
pub fn application_id(mut self, application_id: &str) -> Self {
self.application_id = Some(application_id.to_string());
self
}
pub fn flags(mut self, flags: gio::ApplicationFlags) -> Self {
self.flags = Some(flags);
self
}
pub fn inactivity_timeout(mut self, inactivity_timeout: u32) -> Self {
self.inactivity_timeout = Some(inactivity_timeout);
self
}
pub fn resource_base_path(mut self, resource_base_path: &str) -> Self {
self.resource_base_path = Some(resource_base_path.to_string());
self
}
}
/// Trait containing all [`struct@Application`] methods.
///
/// # Implementors
///
/// [`Application`][struct@crate::Application]
pub trait GtkApplicationExt: 'static {
/// Adds a window to `self`.
///
/// This call can only happen after the `self` has started;
/// typically, you should add new application windows in response
/// to the emission of the `signal::gio::Application::activate` signal.
///
/// This call is equivalent to setting the `property::Window::application`
/// property of `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 `self` running as long as it has
/// any windows.
/// ## `window`
/// a [`Window`][crate::Window]
#[doc(alias = "gtk_application_add_window")]
fn add_window(&self, window: &impl IsA<Window>);
/// 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`, as
/// a [`None`]-terminated array. Free with `g_strfreev()` when no longer needed
#[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>;
/// Returns the list of actions (possibly empty) that `accel` 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. [`None`] 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
///
/// a [`None`]-terminated array of 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>;
/// 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, or [`None`] if
/// there isn't one.
#[doc(alias = "gtk_application_get_active_window")]
#[doc(alias = "get_active_window")]
fn active_window(&self) -> Option<Window>;
/// Returns the menu model that has been set with
/// [`set_app_menu()`][Self::set_app_menu()].
///
/// # Returns
///
/// the application menu of `self`
/// or [`None`] if no application menu has been set.
#[doc(alias = "gtk_application_get_app_menu")]
#[doc(alias = "get_app_menu")]
fn app_menu(&self) -> Option<gio::MenuModel>;
/// Gets a menu from automatically loaded resources.
/// See [Automatic resources][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>;
/// Returns the menu model that has been set with
/// [`set_menubar()`][Self::set_menubar()].
///
/// # Returns
///
/// the menubar for windows of `self`
#[doc(alias = "gtk_application_get_menubar")]
#[doc(alias = "get_menubar")]
fn menubar(&self) -> Option<gio::MenuModel>;
/// Returns the [`ApplicationWindow`][crate::ApplicationWindow] 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 with ID `id`, or
/// [`None`] if there is no window with this ID
#[doc(alias = "gtk_application_get_window_by_id")]
#[doc(alias = "get_window_by_id")]
fn window_by_id(&self, id: u32) -> Option<Window>;
/// Gets a list of the `GtkWindows` associated with `self`.
///
/// 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
///
/// a `GList` of [`Window`][crate::Window]
#[doc(alias = "gtk_application_get_windows")]
#[doc(alias = "get_windows")]
fn windows(&self) -> Vec<Window>;
/// Inform 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.
///
/// Reasons should be short and to the point.
///
/// If `window` is given, the session manager may point the user to
/// this window to find out more about why the action is inhibited.
/// ## `window`
/// a [`Window`][crate::Window], or [`None`]
/// ## `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
/// request. It should be used as an argument to [`uninhibit()`][Self::uninhibit()]
/// in order to remove the request. If the platform does not support
/// inhibiting or the request failed for some reason, 0 is returned.
#[doc(alias = "gtk_application_inhibit")]
fn inhibit(
&self,
window: Option<&impl IsA<Window>>,
flags: ApplicationInhibitFlags,
reason: Option<&str>,
) -> u32;
/// Determines if any of the actions specified in `flags` are
/// currently inhibited (possibly by another application).
///
/// Note that this information may not be available (for example
/// when the application is running in a sandbox).
/// ## `flags`
/// what types of actions should be queried
///
/// # Returns
///
/// [`true`] if any of the actions specified in `flags` are inhibited
#[doc(alias = "gtk_application_is_inhibited")]
fn is_inhibited(&self, flags: ApplicationInhibitFlags) -> bool;
/// Lists the detailed action names which have associated accelerators.
/// See [`set_accels_for_action()`][Self::set_accels_for_action()].
///
/// # Returns
///
/// a [`None`]-terminated array of strings,
/// free with `g_strfreev()` when done
#[doc(alias = "gtk_application_list_action_descriptions")]
fn list_action_descriptions(&self) -> Vec<glib::GString>;
/// Determines if the desktop environment in which the application is
/// running would prefer an application menu be shown.
///
/// If this function returns [`true`] then the application should call
/// [`set_app_menu()`][Self::set_app_menu()] with the contents of an application
/// menu, which will be shown by the desktop environment. If it returns
/// [`false`] then you should consider using an alternate approach, such as
/// a menubar.
///
/// The value returned by this function is purely advisory and you are
/// free to ignore it. If you call [`set_app_menu()`][Self::set_app_menu()] even
/// if the desktop environment doesn't support app menus, then a fallback
/// will be provided.
///
/// Applications are similarly free not to set an app menu even if the
/// desktop environment wants to show one. In that case, a fallback will
/// also be created by the desktop environment (GNOME, for example, uses
/// a menu with only a "Quit" item in it).
///
/// The value returned by this function never changes. Once it returns a
/// particular value, it is guaranteed to always return the same value.
///
/// You may only call this function after the application has been
/// registered and after the base startup handler has run. You're most
/// likely to want to use this from your own startup handler. It may
/// also make sense to consult this function while constructing UI (in
/// activate, open or an action activation handler) in order to determine
/// if you should show a gear menu or not.
///
/// This function will return [`false`] on Mac OS and a default app menu
/// will be created automatically with the "usual" contents of that menu
/// typical to most Mac OS applications. If you call
/// [`set_app_menu()`][Self::set_app_menu()] anyway, then this menu will be
/// replaced with your own.
///
/// # Returns
///
/// [`true`] if you should set an app menu
#[doc(alias = "gtk_application_prefers_app_menu")]
fn prefers_app_menu(&self) -> bool;
/// Remove a window from `self`.
///
/// If `window` belongs to `self` then this call is equivalent to
/// setting the `property::Window::application` property of `window` to
/// [`None`].
///
/// The application may stop running as a result of a call to this
/// function.
/// ## `window`
/// a [`Window`][crate::Window]
#[doc(alias = "gtk_application_remove_window")]
fn remove_window(&self, window: &impl IsA<Window>);
/// 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 `g_action_parse_detailed_name()` and
/// `g_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]);
/// Sets or unsets the application menu for `self`.
///
/// This can only be done in the primary instance of the application,
/// after it has been registered. `signal::gio::Application::startup` is a good place
/// to call this.
///
/// The application menu is a single menu containing items that typically
/// impact the application as a whole, rather than acting on a specific
/// window or document. For example, you would expect to see
/// “Preferences” or “Quit” in an application menu, but not “Save” or
/// “Print”.
///
/// If supported, the application menu will be rendered by the desktop
/// environment.
///
/// Use the base [`gio::ActionMap`][crate::gio::ActionMap] interface to add actions, to respond to the user
/// selecting these menu items.
/// ## `app_menu`
/// a [`gio::MenuModel`][crate::gio::MenuModel], or [`None`]
#[doc(alias = "gtk_application_set_app_menu")]
fn set_app_menu(&self, app_menu: Option<&impl IsA<gio::MenuModel>>);
/// Sets or unsets the menubar for windows of `self`.
///
/// 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. `signal::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 [`gio::ActionMap`][crate::gio::ActionMap] interface to add actions, to respond to the
/// user selecting these menu items.
/// ## `menubar`
/// a [`gio::MenuModel`][crate::gio::MenuModel], or [`None`]
#[doc(alias = "gtk_application_set_menubar")]
fn set_menubar(&self, menubar: Option<&impl IsA<gio::MenuModel>>);
/// Removes an inhibitor that has been established with [`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);
/// Set this property to [`true`] to register with the session manager.
#[doc(alias = "register-session")]
fn is_register_session(&self) -> bool;
/// Set this property to [`true`] to register with the session manager.
#[doc(alias = "register-session")]
fn set_register_session(&self, register_session: bool);
/// This property is [`true`] if GTK+ believes that the screensaver is
/// currently active. GTK+ only tracks session state (including this)
/// when `signal::Application::register-session` is set to [`true`].
///
/// Tracking the screensaver state is supported on Linux.
#[cfg(any(feature = "v3_24", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v3_24")))]
#[doc(alias = "screensaver-active")]
fn is_screensaver_active(&self) -> bool;
/// Emitted when the session manager is about to end the session, only
/// if `signal::Application::register-session` is [`true`]. Applications can
/// connect to this signal and call [`inhibit()`][Self::inhibit()] with
/// [`ApplicationInhibitFlags::LOGOUT`][crate::ApplicationInhibitFlags::LOGOUT] to delay the end of the session
/// until state has been saved.
#[cfg(any(feature = "v3_24_8", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v3_24_8")))]
#[doc(alias = "query-end")]
fn connect_query_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
/// Emitted when a [`Window`][crate::Window] is added to `application` through
/// [`add_window()`][Self::add_window()].
/// ## `window`
/// the newly-added [`Window`][crate::Window]
#[doc(alias = "window-added")]
fn connect_window_added<F: Fn(&Self, &Window) + 'static>(&self, f: F) -> SignalHandlerId;
/// Emitted when a [`Window`][crate::Window] is removed from `application`,
/// either as a side-effect of being destroyed or explicitly
/// through [`remove_window()`][Self::remove_window()].
/// ## `window`
/// the [`Window`][crate::Window] that is being removed
#[doc(alias = "window-removed")]
fn connect_window_removed<F: Fn(&Self, &Window) + 'static>(&self, f: F) -> SignalHandlerId;
#[doc(alias = "active-window")]
fn connect_active_window_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
#[doc(alias = "app-menu")]
fn connect_app_menu_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
#[doc(alias = "menubar")]
fn connect_menubar_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
#[doc(alias = "register-session")]
fn connect_register_session_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
#[cfg(any(feature = "v3_24", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v3_24")))]
#[doc(alias = "screensaver-active")]
fn connect_screensaver_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<Application>> GtkApplicationExt for O {
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,
);
}
}
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,
))
}
}
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,
))
}
}
fn active_window(&self) -> Option<Window> {
unsafe {
from_glib_none(ffi::gtk_application_get_active_window(
self.as_ref().to_glib_none().0,
))
}
}
fn app_menu(&self) -> Option<gio::MenuModel> {
unsafe {
from_glib_none(ffi::gtk_application_get_app_menu(
self.as_ref().to_glib_none().0,
))
}
}
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,
))
}
}
fn menubar(&self) -> Option<gio::MenuModel> {
unsafe {
from_glib_none(ffi::gtk_application_get_menubar(
self.as_ref().to_glib_none().0,
))
}
}
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,
))
}
}
fn windows(&self) -> Vec<Window> {
unsafe {
FromGlibPtrContainer::from_glib_none(ffi::gtk_application_get_windows(
self.as_ref().to_glib_none().0,
))
}
}
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,
)
}
}
fn is_inhibited(&self, flags: ApplicationInhibitFlags) -> bool {
unsafe {
from_glib(ffi::gtk_application_is_inhibited(
self.as_ref().to_glib_none().0,
flags.into_glib(),
))
}
}
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,
))
}
}
fn prefers_app_menu(&self) -> bool {
unsafe {
from_glib(ffi::gtk_application_prefers_app_menu(
self.as_ref().to_glib_none().0,
))
}
}
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,
);
}
}
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,
);
}
}
fn set_app_menu(&self, app_menu: Option<&impl IsA<gio::MenuModel>>) {
unsafe {
ffi::gtk_application_set_app_menu(
self.as_ref().to_glib_none().0,
app_menu.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
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,
);
}
}
fn uninhibit(&self, cookie: u32) {
unsafe {
ffi::gtk_application_uninhibit(self.as_ref().to_glib_none().0, cookie);
}
}
fn is_register_session(&self) -> bool {
glib::ObjectExt::property(self.as_ref(), "register-session")
}
fn set_register_session(&self, register_session: bool) {
glib::ObjectExt::set_property(self.as_ref(), "register-session", ®ister_session)
}
#[cfg(any(feature = "v3_24", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v3_24")))]
fn is_screensaver_active(&self) -> bool {
glib::ObjectExt::property(self.as_ref(), "screensaver-active")
}
#[cfg(any(feature = "v3_24_8", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v3_24_8")))]
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(transmute::<_, unsafe extern "C" fn()>(
query_end_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
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(transmute::<_, unsafe extern "C" fn()>(
window_added_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
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(transmute::<_, unsafe extern "C" fn()>(
window_removed_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
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(transmute::<_, unsafe extern "C" fn()>(
notify_active_window_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_app_menu_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_app_menu_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::app-menu\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_app_menu_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
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(transmute::<_, unsafe extern "C" fn()>(
notify_menubar_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
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(transmute::<_, unsafe extern "C" fn()>(
notify_register_session_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[cfg(any(feature = "v3_24", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v3_24")))]
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(transmute::<_, unsafe extern "C" fn()>(
notify_screensaver_active_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl fmt::Display for Application {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("Application")
}
}