@@ -7,7 +7,7 @@ use crate::{
77 cosmic_keystate_from_smithay, cosmic_modifiers_eq_smithay,
88 cosmic_modifiers_from_smithay,
99 } ,
10- Action , Config , PrivateAction ,
10+ Action , Config , PrivateAction , X11_KEYCODE_OFFSET ,
1111 } ,
1212 input:: gestures:: { GestureState , SwipeAction } ,
1313 shell:: {
@@ -35,8 +35,8 @@ use calloop::{
3535 RegistrationToken ,
3636} ;
3737use cosmic_comp_config:: { workspace:: WorkspaceLayout , NumlockState } ;
38- use cosmic_settings_config:: shortcuts;
3938use cosmic_settings_config:: shortcuts:: action:: { Direction , ResizeDirection } ;
39+ use cosmic_settings_config:: { shortcuts, Binding } ;
4040use smithay:: {
4141 backend:: input:: {
4242 AbsolutePositionEvent , Axis , AxisSource , Device , DeviceCapability , GestureBeginEvent ,
@@ -213,11 +213,32 @@ impl State {
213213 self . common . idle_notifier_state . notify_activity ( & seat) ;
214214
215215 let keycode = event. key_code ( ) ;
216+
216217 let state = event. state ( ) ;
217218 trace ! ( ?keycode, ?state, "key" ) ;
218219
219220 let serial = SERIAL_COUNTER . next_serial ( ) ;
220221 let time = Event :: time_msec ( & event) ;
222+
223+ const POWER_OFF : u32 = 116 ;
224+ // if power key is pressed, just use the system action for power off
225+ // this is a workaround for the fact that the power key is not
226+ // available in the keymap, so we cannot use the keymap to determine
227+ // if the key is pressed
228+ if keycode. raw ( ) == POWER_OFF + X11_KEYCODE_OFFSET && state == KeyState :: Pressed
229+ {
230+ self . handle_action (
231+ Action :: Shortcut ( shortcuts:: Action :: System (
232+ shortcuts:: action:: System :: PowerOff ,
233+ ) ) ,
234+ & seat,
235+ serial,
236+ time,
237+ Binding :: default ( ) ,
238+ None ,
239+ ) ;
240+ }
241+
221242 let keyboard = seat. get_keyboard ( ) . unwrap ( ) ;
222243 let previous_modifiers = keyboard. modifier_state ( ) ;
223244 if let Some ( ( action, pattern) ) = keyboard
0 commit comments