@@ -11,6 +11,7 @@ use std::iter::Iterator;
11
11
use std:: rc:: { Rc , Weak } ;
12
12
13
13
use crate :: color:: Rgb ;
14
+ use crate :: daemon:: Daemon ;
14
15
15
16
const DBUS_NAME : & ' static str = "com.system76.PowerDaemon" ;
16
17
const DBUS_KEYBOARD_IFACE : & ' static str = "com.system76.PowerDaemon.Keyboard" ;
@@ -32,6 +33,10 @@ enum KeyboardImplementation {
32
33
Dummy {
33
34
properties : HashMap < & ' static str , RefCell < Variant > > ,
34
35
} ,
36
+ Daemon {
37
+ daemon : Rc < dyn Daemon > ,
38
+ board : usize ,
39
+ }
35
40
}
36
41
37
42
struct KeyboardInner {
@@ -144,7 +149,14 @@ impl Keyboard {
144
149
keyboard
145
150
}
146
151
147
- fn new_dummy ( ) -> Self {
152
+ pub ( crate ) fn new_daemon ( daemon : Rc < dyn Daemon > , board : usize ) -> Self {
153
+ Self :: new ( KeyboardImplementation :: Daemon {
154
+ daemon,
155
+ board,
156
+ } )
157
+ }
158
+
159
+ pub ( crate ) fn new_dummy ( ) -> Self {
148
160
let mut properties = HashMap :: new ( ) ;
149
161
properties. insert ( "max_brightness" , RefCell :: new ( 100i32 . to_variant ( ) ) ) ;
150
162
properties. insert ( "brightness" , RefCell :: new ( 0i32 . to_variant ( ) ) ) ;
@@ -179,6 +191,7 @@ impl Keyboard {
179
191
. unwrap ( ) ;
180
192
}
181
193
KeyboardImplementation :: Dummy { .. } => { }
194
+ KeyboardImplementation :: Daemon { .. } => { }
182
195
}
183
196
}
184
197
@@ -191,6 +204,15 @@ impl Keyboard {
191
204
KeyboardImplementation :: Dummy { properties } => {
192
205
Ok ( Some ( properties. get ( name) . unwrap ( ) . borrow ( ) . clone ( ) ) )
193
206
}
207
+ KeyboardImplementation :: Daemon { ref daemon, board } => {
208
+ match name {
209
+ "max-brightness" => daemon. max_brightness ( * board) . map ( |b| Some ( b. to_variant ( ) ) ) . map_err ( Error :: msg) ,
210
+ "brightness" => daemon. brightness ( * board) . map ( |b| Some ( b. to_variant ( ) ) ) . map_err ( Error :: msg) ,
211
+ "color" => daemon. color ( * board) . map ( |b| Some ( b. to_string ( ) . to_variant ( ) ) ) . map_err ( Error :: msg) ,
212
+ "name" => Ok ( Some ( "" . to_variant ( ) ) ) ,
213
+ _ => unreachable ! ( ) ,
214
+ }
215
+ }
194
216
}
195
217
}
196
218
@@ -205,6 +227,13 @@ impl Keyboard {
205
227
KeyboardImplementation :: Dummy { properties } => {
206
228
* properties. get ( name) . unwrap ( ) . borrow_mut ( ) = value;
207
229
}
230
+ KeyboardImplementation :: Daemon { ref daemon, board } => {
231
+ match name {
232
+ "brightness" => daemon. set_brightness ( * board, value. get ( ) . unwrap ( ) ) . map_err ( Error :: msg) ?,
233
+ "color" => daemon. set_color ( * board, Rgb :: parse ( & value. get :: < String > ( ) . unwrap ( ) ) . unwrap ( ) ) . map_err ( Error :: msg) ?,
234
+ _ => unreachable ! ( ) ,
235
+ } ;
236
+ }
208
237
}
209
238
Ok ( ( ) )
210
239
}
0 commit comments