nativeshell 0.1.16

NativeShell Rust package
Documentation
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
use std::collections::HashMap;

use crate::codec::Value;

use super::{status_item_manager::StatusItemHandle, HotKeyHandle, MenuHandle, Point, Rect, Size};

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub enum GeometryPreference {
    PreferFrame,
    PreferContent,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Default)]
#[serde(rename_all = "camelCase")]
pub struct WindowGeometry {
    pub frame_origin: Option<Point>,
    pub frame_size: Option<Size>,
    pub content_origin: Option<Point>,
    pub content_size: Option<Size>,

    pub min_frame_size: Option<Size>,
    pub max_frame_size: Option<Size>,
    pub min_content_size: Option<Size>,
    pub max_content_size: Option<Size>,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WindowGeometryRequest {
    pub geometry: WindowGeometry,
    pub preference: GeometryPreference,
}

impl WindowGeometryRequest {
    // Returns geometry with redundand fields removed (useful when caller
    // supports all fields)
    pub fn filtered_by_preference(self) -> WindowGeometry {
        let mut geometry = self.geometry;

        match self.preference {
            GeometryPreference::PreferFrame => {
                if geometry.frame_origin.is_some() {
                    geometry.content_origin = None;
                }
                if geometry.frame_size.is_some() {
                    geometry.content_size = None;
                }
                if geometry.min_frame_size.is_some() {
                    geometry.min_content_size = None;
                }
                if geometry.max_frame_size.is_some() {
                    geometry.max_content_size = None;
                }
            }
            GeometryPreference::PreferContent => {
                if geometry.content_origin.is_some() {
                    geometry.frame_origin = None;
                }
                if geometry.content_size.is_some() {
                    geometry.frame_size = None;
                }
                if geometry.min_content_size.is_some() {
                    geometry.min_frame_size = None;
                }
                if geometry.max_content_size.is_some() {
                    geometry.max_frame_size = None;
                }
            }
        }

        geometry
    }
}

#[derive(serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WindowActivateRequest {
    pub activate_application: bool,
}

#[derive(serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WindowDeactivateRequest {
    pub deactivate_application: bool,
}

#[derive(serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PopupMenuRequest {
    pub handle: MenuHandle,
    pub position: Point,

    // Windows only, used for menu bar implementation; is specified this
    // rect will keep receiving mouse events
    pub tracking_rect: Option<Rect>,

    // Windows only, menu will not obscure the specified rect
    pub item_rect: Option<Rect>,

    // Windows only, first item will be pre-selected; Use during keyboard navigation
    // in menubar
    pub preselect_first: bool,
}

#[derive(serde::Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PopupMenuResponse {
    pub item_selected: bool,
}

#[derive(serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct HidePopupMenuRequest {
    pub handle: MenuHandle,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct WindowGeometryFlags {
    pub frame_origin: bool,
    pub frame_size: bool,
    pub content_origin: bool,
    pub content_size: bool,
    pub min_frame_size: bool,
    pub max_frame_size: bool,
    pub min_content_size: bool,
    pub max_content_size: bool,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Default)]
#[serde(rename_all = "camelCase")]
pub struct DragData {
    pub properties: HashMap<String, Value>,
}

#[derive(Debug, serde::Serialize, serde::Deserialize, Copy, Clone, PartialEq, Eq)]
pub enum DragEffect {
    None,
    Copy,
    Link,
    Move,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct DraggingInfo {
    pub location: Point,
    pub data: DragData,
    pub allowed_effects: Vec<DragEffect>,
}
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct DragResult {
    pub effect: DragEffect,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ImageData {
    pub width: i32,
    pub height: i32,
    pub bytes_per_row: i32,
    #[serde(with = "serde_bytes")]
    pub data: Vec<u8>,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct DragRequest {
    pub image: ImageData,
    pub rect: Rect,
    pub allowed_effects: Vec<DragEffect>,
    pub data: DragData,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub enum WindowFrame {
    Regular,
    NoTitle,
    NoFrame,
}

impl Default for WindowFrame {
    fn default() -> Self {
        WindowFrame::Regular
    }
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Default)]
#[serde(rename_all = "camelCase")]
pub struct WindowStyle {
    pub frame: WindowFrame,
    pub can_resize: bool,
    pub can_close: bool,
    pub can_minimize: bool,
    pub can_maximize: bool,
    pub can_full_screen: bool,
    pub always_on_top: bool,
    pub always_on_top_level: Option<i64>,
    pub traffic_light_offset: Option<Point>,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
pub enum BoolTransition {
    No,
    NoToYes,
    Yes,
    YesToNo,
}

impl Default for BoolTransition {
    fn default() -> Self {
        BoolTransition::No
    }
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Default, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct WindowStateFlags {
    pub maximized: BoolTransition,
    pub minimized: BoolTransition,
    pub full_screen: BoolTransition,
    pub active: bool,
}

impl WindowStateFlags {
    pub fn is_minimized(&self) -> bool {
        self.minimized == BoolTransition::Yes || self.minimized == BoolTransition::NoToYes
    }
    pub fn is_maximized(&self) -> bool {
        self.maximized == BoolTransition::Yes || self.maximized == BoolTransition::NoToYes
    }
    pub fn is_full_screen(&self) -> bool {
        self.full_screen == BoolTransition::Yes || self.full_screen == BoolTransition::NoToYes
    }
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Default)]
#[serde(rename_all = "camelCase")]
pub struct WindowCollectionBehavior {
    pub can_join_all_spaces: bool,
    pub move_to_active_space: bool,
    pub managed: bool,
    pub transient: bool,
    pub stationary: bool,
    pub participates_in_cycle: bool,
    pub ignores_cycle: bool,
    pub full_screen_primary: bool,
    pub full_screen_auxiliary: bool,
    pub full_screen_none: bool,
    pub allows_tiling: bool,
    pub disallows_tiling: bool,
}

//
// Menu
//

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub enum MenuItemRole {
    About,
    Hide,
    HideOtherApplications,
    ShowAll,
    QuitApplication,
    MinimizeWindow,
    ZoomWindow,
    BringAllToFront,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub enum MenuRole {
    Window,
    Services,
}

#[derive(serde::Serialize, serde::Deserialize, Default, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Accelerator {
    pub label: String,
    pub alt: bool,
    pub shift: bool,
    pub meta: bool,
    pub control: bool,
}

#[derive(serde::Serialize, serde::Deserialize, PartialEq, Eq, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub enum CheckStatus {
    None,
    CheckOn,
    CheckOff,
    RadioOn,
    RadioOff,
}

impl Default for CheckStatus {
    fn default() -> Self {
        CheckStatus::None
    }
}

#[derive(serde::Serialize, serde::Deserialize, Default, Debug)]
#[serde(rename_all = "camelCase")]
pub struct MenuItem {
    pub id: i64,
    pub title: String,
    pub enabled: bool,
    pub separator: bool,
    pub check_status: CheckStatus,
    pub role: Option<MenuItemRole>,
    pub submenu: Option<MenuHandle>,
    pub accelerator: Option<Accelerator>,
}

impl PartialEq for MenuItem {
    fn eq(&self, other: &Self) -> bool {
        self.id == other.id
    }
}

#[derive(serde::Deserialize, Default, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Menu {
    pub role: Option<MenuRole>,
    pub items: Vec<MenuItem>,
}
#[derive(serde::Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct MenuCreateRequest {
    pub handle: Option<MenuHandle>,
    pub menu: Menu,
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MenuDestroyRequest {
    pub handle: MenuHandle,
}

#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct MenuAction {
    pub handle: MenuHandle,
    pub id: i64,
}

#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct MenuOpen {
    pub handle: MenuHandle,
}

#[derive(serde::Serialize, serde::Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct SetMenuRequest {
    pub handle: Option<MenuHandle>,
}

#[derive(serde::Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Key {
    pub platform: i64,
    pub physical: i64,
    pub logical: Option<i64>,
    pub logical_shift: Option<i64>,
    pub logical_alt: Option<i64>,
    pub logical_alt_shift: Option<i64>,
    pub logical_meta: Option<i64>,
}

#[derive(serde::Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct KeyboardMap {
    pub keys: Vec<Key>,
}

#[derive(serde::Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct HotKeyCreateRequest {
    pub accelerator: Accelerator,
    pub platform_key: i64,
}

#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct HotKeyDestroyRequest {
    pub handle: HotKeyHandle,
}

#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct HotKeyPressed {
    pub handle: HotKeyHandle,
}

#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Screen {
    pub id: i64,
    pub frame: Rect,
    pub work_area: Rect,
    pub scaling_factor: f64,
}

//
// StatusItem
//
#[derive(serde::Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct StatusItemCreateRequest {}

#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StatusItemDestroyRequest {
    pub handle: StatusItemHandle,
}

#[derive(serde::Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct StatusItemSetImageRequest {
    pub handle: StatusItemHandle,
    pub image: Vec<ImageData>,
}

#[derive(serde::Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct StatusItemSetHintRequest {
    pub handle: StatusItemHandle,
    pub hint: String,
}

#[derive(serde::Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct StatusItemSetHighlightedRequest {
    pub handle: StatusItemHandle,
    pub highlighted: bool,
}

#[derive(serde::Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct StatusItemShowMenuRequest {
    pub handle: StatusItemHandle,
    pub menu: MenuHandle,
    pub offset: Point,
}

#[derive(serde::Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct StatusItemGetGeometryRequest {
    pub handle: StatusItemHandle,
}

#[derive(serde::Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct StatusItemGetScreenIdRequest {
    pub handle: StatusItemHandle,
}

#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub enum StatusItemActionType {
    LeftMouseDown,
    LeftMouseUp,
    RightMouseDown,
    RightMouseUp,
}

#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct StatusItemAction {
    pub handle: StatusItemHandle,
    pub action: StatusItemActionType,
    pub position: Point,
}