dbusmenu_glib/auto/
client.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from /nix/store/39vgdpiqy94qwa8rraha7q4wcd8hdwcj-dbusmenu-gtk3-gir
3// from /nix/store/ahri9v0b3c1jyls6691sjfzf2s461fzz-source
4// DO NOT EDIT
5
6use crate::{Menuitem,Status,TextDirection};
7use glib::{prelude::*,signal::{connect_raw, SignalHandlerId},translate::*};
8use std::{boxed::Box as Box_,fmt,mem::transmute};
9
10glib::wrapper! {
11    #[doc(alias = "DbusmenuClient")]
12    pub struct Client(Object<ffi::DbusmenuClient, ffi::DbusmenuClientClass>);
13
14    match fn {
15        type_ => || ffi::dbusmenu_client_get_type(),
16    }
17}
18
19impl Client {
20        pub const NONE: Option<&'static Client> = None;
21    
22
23    /// This function creates a new client that connects to a specific
24    /// server on DBus. That server is at a specific location sharing
25    /// a known object. The interface is assumed by the code to be
26    /// the DBus menu interface. The newly created client will start
27    /// sending out events as it syncs up with the server.
28    /// ## `name`
29    /// The DBus name for the server to connect to
30    /// ## `object`
31    /// The object on the server to monitor
32    ///
33    /// # Returns
34    ///
35    /// A brand new [`Client`][crate::Client]
36    #[doc(alias = "dbusmenu_client_new")]
37    pub fn new(name: &str, object: &str) -> Client {
38        assert_initialized_main_thread!();
39        unsafe {
40            from_glib_full(ffi::dbusmenu_client_new(name.to_glib_none().0, object.to_glib_none().0))
41        }
42    }
43}
44
45/// Trait containing all [`struct@Client`] methods.
46///
47/// # Implementors
48///
49/// [`Client`][struct@crate::Client]
50pub trait ClientExt: 'static {
51    /// This function connects into the type handling of the [`Client`][crate::Client].
52    /// Every new menuitem that comes in immediately gets asked for its
53    /// properties. When we get those properties we check the 'type'
54    /// property and look to see if it matches a handler that is known
55    /// by the client. If so, the `newfunc` function is executed on that
56    /// [`Menuitem`][crate::Menuitem]. If not, then the DbusmenuClient::new-menuitem
57    /// signal is sent.
58    ///
59    /// In the future the known types will be sent to the server so that it
60    /// can make choices about the menu item types availble.
61    /// ## `type_`
62    /// A text string that will be matched with the 'type'
63    ///  property on incoming menu items
64    /// ## `newfunc`
65    /// The function that will be executed with those new
66    ///  items when they come in.
67    ///
68    /// # Returns
69    ///
70    /// If registering the new type was successful.
71    #[doc(alias = "dbusmenu_client_add_type_handler_full")]
72    fn add_type_handler_full<P: Fn(&Menuitem, &Menuitem, &Client) -> bool + 'static>(&self, type_: &str, newfunc: P) -> bool;
73
74    /// Gets the stored and exported icon paths from the client.
75    ///
76    /// # Returns
77    ///
78    /// A NULL-terminated list of icon paths with
79    ///  memory managed by the client. Duplicate if you want
80    ///  to keep them.
81    #[doc(alias = "dbusmenu_client_get_icon_paths")]
82    #[doc(alias = "get_icon_paths")]
83    fn icon_paths(&self) -> Vec<glib::GString>;
84
85    /// Grabs the root node for the specified client `self`. This
86    /// function may block. It will block if there is currently a
87    /// call to update the layout, it will block on that layout
88    /// updated and then return the newly updated layout. Chances
89    /// are that this update is in the queue for the mainloop as
90    /// it would have been requested some time ago, but in theory
91    /// it could block longer.
92    ///
93    /// # Returns
94    ///
95    /// A [`Menuitem`][crate::Menuitem] representing the root of
96    ///     menu on the server. If there is no server or there is
97    ///     an error receiving its layout it'll return [`None`].
98    #[doc(alias = "dbusmenu_client_get_root")]
99    #[doc(alias = "get_root")]
100    fn root(&self) -> Option<Menuitem>;
101
102    /// Gets the recommended current status that the server
103    ///     is exporting for the menus. In situtations where the
104    ///     value is [`Status::Notice`][crate::Status::Notice] it is recommended that
105    ///     the client show the menus to the user an a more noticible
106    ///     way.
107    ///
108    /// Return value: Status being exported.
109    #[doc(alias = "dbusmenu_client_get_status")]
110    #[doc(alias = "get_status")]
111    fn status(&self) -> Status;
112
113    /// Gets the text direction that the server is exporting. If
114    ///     the server is not exporting a direction then the value
115    ///     [`TextDirection::None`][crate::TextDirection::None] will be returned.
116    ///
117    /// Return value: Text direction being exported.
118    #[doc(alias = "dbusmenu_client_get_text_direction")]
119    #[doc(alias = "get_text_direction")]
120    fn text_direction(&self) -> TextDirection;
121
122    #[doc(alias = "dbus-name")]
123    fn dbus_name(&self) -> Option<glib::GString>;
124
125    #[doc(alias = "dbus-object")]
126    fn dbus_object(&self) -> Option<glib::GString>;
127
128    #[doc(alias = "group-events")]
129    fn is_group_events(&self) -> bool;
130
131    #[doc(alias = "group-events")]
132    fn set_group_events(&self, group_events: bool);
133
134    //#[doc(alias = "event-result")]
135    //fn connect_event_result<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId;
136
137    //#[doc(alias = "icon-theme-dirs-changed")]
138    //fn connect_icon_theme_dirs_changed<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId;
139
140    //#[doc(alias = "item-activate")]
141    //fn connect_item_activate<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId;
142
143    #[doc(alias = "layout-updated")]
144    fn connect_layout_updated<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
145
146    //#[doc(alias = "new-menuitem")]
147    //fn connect_new_menuitem<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId;
148
149    //#[doc(alias = "root-changed")]
150    //fn connect_root_changed<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId;
151
152    #[doc(alias = "group-events")]
153    fn connect_group_events_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
154}
155
156impl<O: IsA<Client>> ClientExt for O {
157    fn add_type_handler_full<P: Fn(&Menuitem, &Menuitem, &Client) -> bool + 'static>(&self, type_: &str, newfunc: P) -> bool {
158        let newfunc_data: Box_<P> = Box_::new(newfunc);
159        unsafe extern "C" fn newfunc_func<P: Fn(&Menuitem, &Menuitem, &Client) -> bool + 'static>(newitem: *mut ffi::DbusmenuMenuitem, parent: *mut ffi::DbusmenuMenuitem, client: *mut ffi::DbusmenuClient, user_data: glib::ffi::gpointer) -> glib::ffi::gboolean {
160            let newitem = from_glib_borrow(newitem);
161            let parent = from_glib_borrow(parent);
162            let client = from_glib_borrow(client);
163            let callback: &P = &*(user_data as *mut _);
164            (*callback)(&newitem, &parent, &client)
165            .into_glib()
166        }
167        let newfunc = Some(newfunc_func::<P> as _);
168        unsafe extern "C" fn destroy_func_func<P: Fn(&Menuitem, &Menuitem, &Client) -> bool + 'static>(data: glib::ffi::gpointer) {
169            let _callback: Box_<P> = Box_::from_raw(data as *mut _);
170        }
171        let destroy_call4 = Some(destroy_func_func::<P> as _);
172        let super_callback0: Box_<P> = newfunc_data;
173        unsafe {
174            from_glib(ffi::dbusmenu_client_add_type_handler_full(self.as_ref().to_glib_none().0, type_.to_glib_none().0, newfunc, Box_::into_raw(super_callback0) as *mut _, destroy_call4))
175        }
176    }
177
178    fn icon_paths(&self) -> Vec<glib::GString> {
179        unsafe {
180            FromGlibPtrContainer::from_glib_none(ffi::dbusmenu_client_get_icon_paths(self.as_ref().to_glib_none().0))
181        }
182    }
183
184    fn root(&self) -> Option<Menuitem> {
185        unsafe {
186            from_glib_none(ffi::dbusmenu_client_get_root(self.as_ref().to_glib_none().0))
187        }
188    }
189
190    fn status(&self) -> Status {
191        unsafe {
192            from_glib(ffi::dbusmenu_client_get_status(self.as_ref().to_glib_none().0))
193        }
194    }
195
196    fn text_direction(&self) -> TextDirection {
197        unsafe {
198            from_glib(ffi::dbusmenu_client_get_text_direction(self.as_ref().to_glib_none().0))
199        }
200    }
201
202    fn dbus_name(&self) -> Option<glib::GString> {
203        glib::ObjectExt::property(self.as_ref(), "dbus-name")
204    }
205
206    fn dbus_object(&self) -> Option<glib::GString> {
207        glib::ObjectExt::property(self.as_ref(), "dbus-object")
208    }
209
210    fn is_group_events(&self) -> bool {
211        glib::ObjectExt::property(self.as_ref(), "group-events")
212    }
213
214    fn set_group_events(&self, group_events: bool) {
215        glib::ObjectExt::set_property(self.as_ref(),"group-events", group_events)
216    }
217
218    //fn connect_event_result<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
219    //    Ignored object: GObject.Object
220    //    Unimplemented p3: *.Pointer
221    //}
222
223    //fn connect_icon_theme_dirs_changed<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
224    //    Unimplemented arg1: *.Pointer
225    //}
226
227    //fn connect_item_activate<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
228    //    Ignored arg1: GObject.Object
229    //}
230
231    fn connect_layout_updated<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
232        unsafe extern "C" fn layout_updated_trampoline<P: IsA<Client>, F: Fn(&P) + 'static>(this: *mut ffi::DbusmenuClient, f: glib::ffi::gpointer) {
233            let f: &F = &*(f as *const F);
234            f(Client::from_glib_borrow(this).unsafe_cast_ref())
235        }
236        unsafe {
237            let f: Box_<F> = Box_::new(f);
238            connect_raw(self.as_ptr() as *mut _, b"layout-updated\0".as_ptr() as *const _,
239                Some(transmute::<_, unsafe extern "C" fn()>(layout_updated_trampoline::<Self, F> as *const ())), Box_::into_raw(f))
240        }
241    }
242
243    //fn connect_new_menuitem<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
244    //    Ignored arg1: GObject.Object
245    //}
246
247    //fn connect_root_changed<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
248    //    Ignored arg1: GObject.Object
249    //}
250
251    fn connect_group_events_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
252        unsafe extern "C" fn notify_group_events_trampoline<P: IsA<Client>, F: Fn(&P) + 'static>(this: *mut ffi::DbusmenuClient, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
253            let f: &F = &*(f as *const F);
254            f(Client::from_glib_borrow(this).unsafe_cast_ref())
255        }
256        unsafe {
257            let f: Box_<F> = Box_::new(f);
258            connect_raw(self.as_ptr() as *mut _, b"notify::group-events\0".as_ptr() as *const _,
259                Some(transmute::<_, unsafe extern "C" fn()>(notify_group_events_trampoline::<Self, F> as *const ())), Box_::into_raw(f))
260        }
261    }
262}
263
264impl fmt::Display for Client {
265    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
266        f.write_str("Client")
267    }
268}