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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from /nix/store/39vgdpiqy94qwa8rraha7q4wcd8hdwcj-dbusmenu-gtk3-gir
// from /nix/store/ahri9v0b3c1jyls6691sjfzf2s461fzz-source
// DO NOT EDIT
use crate::{Menuitem,Status,TextDirection};
use glib::{prelude::*,signal::{connect_raw, SignalHandlerId},translate::*};
use std::{boxed::Box as Box_,fmt,mem::transmute};
glib::wrapper! {
#[doc(alias = "DbusmenuClient")]
pub struct Client(Object<ffi::DbusmenuClient, ffi::DbusmenuClientClass>);
match fn {
type_ => || ffi::dbusmenu_client_get_type(),
}
}
impl Client {
pub const NONE: Option<&'static Client> = None;
/// This function creates a new client that connects to a specific
/// server on DBus. That server is at a specific location sharing
/// a known object. The interface is assumed by the code to be
/// the DBus menu interface. The newly created client will start
/// sending out events as it syncs up with the server.
/// ## `name`
/// The DBus name for the server to connect to
/// ## `object`
/// The object on the server to monitor
///
/// # Returns
///
/// A brand new [`Client`][crate::Client]
#[doc(alias = "dbusmenu_client_new")]
pub fn new(name: &str, object: &str) -> Client {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::dbusmenu_client_new(name.to_glib_none().0, object.to_glib_none().0))
}
}
}
/// Trait containing all [`struct@Client`] methods.
///
/// # Implementors
///
/// [`Client`][struct@crate::Client]
pub trait ClientExt: 'static {
/// This function connects into the type handling of the [`Client`][crate::Client].
/// Every new menuitem that comes in immediately gets asked for its
/// properties. When we get those properties we check the 'type'
/// property and look to see if it matches a handler that is known
/// by the client. If so, the `newfunc` function is executed on that
/// [`Menuitem`][crate::Menuitem]. If not, then the DbusmenuClient::new-menuitem
/// signal is sent.
///
/// In the future the known types will be sent to the server so that it
/// can make choices about the menu item types availble.
/// ## `type_`
/// A text string that will be matched with the 'type'
/// property on incoming menu items
/// ## `newfunc`
/// The function that will be executed with those new
/// items when they come in.
///
/// # Returns
///
/// If registering the new type was successful.
#[doc(alias = "dbusmenu_client_add_type_handler_full")]
fn add_type_handler_full<P: Fn(&Menuitem, &Menuitem, &Client) -> bool + 'static>(&self, type_: &str, newfunc: P) -> bool;
/// Gets the stored and exported icon paths from the client.
///
/// # Returns
///
/// A NULL-terminated list of icon paths with
/// memory managed by the client. Duplicate if you want
/// to keep them.
#[doc(alias = "dbusmenu_client_get_icon_paths")]
#[doc(alias = "get_icon_paths")]
fn icon_paths(&self) -> Vec<glib::GString>;
/// Grabs the root node for the specified client `self`. This
/// function may block. It will block if there is currently a
/// call to update the layout, it will block on that layout
/// updated and then return the newly updated layout. Chances
/// are that this update is in the queue for the mainloop as
/// it would have been requested some time ago, but in theory
/// it could block longer.
///
/// # Returns
///
/// A [`Menuitem`][crate::Menuitem] representing the root of
/// menu on the server. If there is no server or there is
/// an error receiving its layout it'll return [`None`].
#[doc(alias = "dbusmenu_client_get_root")]
#[doc(alias = "get_root")]
fn root(&self) -> Option<Menuitem>;
/// Gets the recommended current status that the server
/// is exporting for the menus. In situtations where the
/// value is [`Status::Notice`][crate::Status::Notice] it is recommended that
/// the client show the menus to the user an a more noticible
/// way.
///
/// Return value: Status being exported.
#[doc(alias = "dbusmenu_client_get_status")]
#[doc(alias = "get_status")]
fn status(&self) -> Status;
/// Gets the text direction that the server is exporting. If
/// the server is not exporting a direction then the value
/// [`TextDirection::None`][crate::TextDirection::None] will be returned.
///
/// Return value: Text direction being exported.
#[doc(alias = "dbusmenu_client_get_text_direction")]
#[doc(alias = "get_text_direction")]
fn text_direction(&self) -> TextDirection;
#[doc(alias = "dbus-name")]
fn dbus_name(&self) -> Option<glib::GString>;
#[doc(alias = "dbus-object")]
fn dbus_object(&self) -> Option<glib::GString>;
#[doc(alias = "group-events")]
fn is_group_events(&self) -> bool;
#[doc(alias = "group-events")]
fn set_group_events(&self, group_events: bool);
//#[doc(alias = "event-result")]
//fn connect_event_result<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId;
//#[doc(alias = "icon-theme-dirs-changed")]
//fn connect_icon_theme_dirs_changed<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId;
//#[doc(alias = "item-activate")]
//fn connect_item_activate<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId;
#[doc(alias = "layout-updated")]
fn connect_layout_updated<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
//#[doc(alias = "new-menuitem")]
//fn connect_new_menuitem<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId;
//#[doc(alias = "root-changed")]
//fn connect_root_changed<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId;
#[doc(alias = "group-events")]
fn connect_group_events_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<Client>> ClientExt for O {
fn add_type_handler_full<P: Fn(&Menuitem, &Menuitem, &Client) -> bool + 'static>(&self, type_: &str, newfunc: P) -> bool {
let newfunc_data: Box_<P> = Box_::new(newfunc);
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 {
let newitem = from_glib_borrow(newitem);
let parent = from_glib_borrow(parent);
let client = from_glib_borrow(client);
let callback: &P = &*(user_data as *mut _);
(*callback)(&newitem, &parent, &client)
.into_glib()
}
let newfunc = Some(newfunc_func::<P> as _);
unsafe extern "C" fn destroy_func_func<P: Fn(&Menuitem, &Menuitem, &Client) -> bool + 'static>(data: glib::ffi::gpointer) {
let _callback: Box_<P> = Box_::from_raw(data as *mut _);
}
let destroy_call4 = Some(destroy_func_func::<P> as _);
let super_callback0: Box_<P> = newfunc_data;
unsafe {
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))
}
}
fn icon_paths(&self) -> Vec<glib::GString> {
unsafe {
FromGlibPtrContainer::from_glib_none(ffi::dbusmenu_client_get_icon_paths(self.as_ref().to_glib_none().0))
}
}
fn root(&self) -> Option<Menuitem> {
unsafe {
from_glib_none(ffi::dbusmenu_client_get_root(self.as_ref().to_glib_none().0))
}
}
fn status(&self) -> Status {
unsafe {
from_glib(ffi::dbusmenu_client_get_status(self.as_ref().to_glib_none().0))
}
}
fn text_direction(&self) -> TextDirection {
unsafe {
from_glib(ffi::dbusmenu_client_get_text_direction(self.as_ref().to_glib_none().0))
}
}
fn dbus_name(&self) -> Option<glib::GString> {
glib::ObjectExt::property(self.as_ref(), "dbus-name")
}
fn dbus_object(&self) -> Option<glib::GString> {
glib::ObjectExt::property(self.as_ref(), "dbus-object")
}
fn is_group_events(&self) -> bool {
glib::ObjectExt::property(self.as_ref(), "group-events")
}
fn set_group_events(&self, group_events: bool) {
glib::ObjectExt::set_property(self.as_ref(),"group-events", group_events)
}
//fn connect_event_result<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
// Ignored object: GObject.Object
// Unimplemented p3: *.Pointer
//}
//fn connect_icon_theme_dirs_changed<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
// Unimplemented arg1: *.Pointer
//}
//fn connect_item_activate<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
// Ignored arg1: GObject.Object
//}
fn connect_layout_updated<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn layout_updated_trampoline<P: IsA<Client>, F: Fn(&P) + 'static>(this: *mut ffi::DbusmenuClient, f: glib::ffi::gpointer) {
let f: &F = &*(f as *const F);
f(Client::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"layout-updated\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(layout_updated_trampoline::<Self, F> as *const ())), Box_::into_raw(f))
}
}
//fn connect_new_menuitem<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
// Ignored arg1: GObject.Object
//}
//fn connect_root_changed<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
// Ignored arg1: GObject.Object
//}
fn connect_group_events_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
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) {
let f: &F = &*(f as *const F);
f(Client::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(self.as_ptr() as *mut _, b"notify::group-events\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(notify_group_events_trampoline::<Self, F> as *const ())), Box_::into_raw(f))
}
}
}
impl fmt::Display for Client {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("Client")
}
}