1use crate::Key;
8use std::cell::Cell;
9use std::rc::Rc;
10
11#[derive(Clone, Debug)]
13pub struct KeyEvent {
14 key: Key,
15 shift_key: bool,
16 ctrl_key: bool,
17 alt_key: bool,
18 meta_key: bool,
19 consumed: Rc<Cell<bool>>,
20}
21
22impl KeyEvent {
23 pub fn new(key: Key, shift_key: bool, ctrl_key: bool, alt_key: bool, meta_key: bool) -> Self {
24 Self {
25 key,
26 shift_key,
27 ctrl_key,
28 alt_key,
29 meta_key,
30 consumed: Rc::new(Cell::new(false)),
31 }
32 }
33
34 pub fn key(&self) -> Key {
35 self.key
36 }
37
38 pub fn shift_key(&self) -> bool {
39 self.shift_key
40 }
41
42 pub fn ctrl_key(&self) -> bool {
43 self.ctrl_key
44 }
45
46 pub fn alt_key(&self) -> bool {
47 self.alt_key
48 }
49
50 pub fn meta_key(&self) -> bool {
51 self.meta_key
52 }
53
54 pub fn consume(&self) {
55 self.consumed.set(true);
56 }
57
58 pub fn consumed(&self) -> bool {
59 self.consumed.get()
60 }
61}
62
63#[derive(Clone, Debug, PartialEq)]
70pub struct FileDrop {
71 paths: Vec<String>,
72}
73
74impl FileDrop {
75 pub fn new(joined: &str) -> Self {
80 Self {
81 paths: joined
82 .split('\0')
83 .filter(|path| !path.is_empty())
84 .map(str::to_owned)
85 .collect(),
86 }
87 }
88
89 pub fn paths(&self) -> &[String] {
91 &self.paths
92 }
93}
94
95#[derive(Clone, Copy, Debug, Eq, PartialEq)]
97pub struct RangeRequest {
98 start: u32,
99 count: u32,
100}
101
102impl RangeRequest {
103 pub fn new(start: u32, count: u32) -> Self {
104 Self { start, count }
105 }
106
107 pub fn start(&self) -> usize {
108 self.start as usize
109 }
110
111 pub fn count(&self) -> usize {
112 self.count as usize
113 }
114}