@@ -230,15 +230,28 @@ impl WindowManager {
230230 self . active = Some ( window) ;
231231 }
232232
233- fn alt_tab ( & mut self ) {
233+ fn alt_tab ( & mut self , reverse : bool ) {
234234 if self . layering . is_empty ( ) {
235235 self . active = None ;
236236 } else {
237- let old = self . active . map ( |i| i. slot ( ) ) . unwrap_or ( 0 ) ;
238- for i in ( old + 1 ..self . windows . capacity ( ) as u32 ) . chain ( 0 ..=old) {
239- if let Some ( idx) = self . windows . contains_slot ( i) {
240- self . select_window ( idx) ;
241- break ;
237+ if reverse {
238+ let old = self . active . map ( |i| i. slot ( ) ) . unwrap_or ( 0 ) ;
239+ for i in ( 0 ..old)
240+ . rev ( )
241+ . chain ( ( old..self . windows . capacity ( ) as u32 ) . rev ( ) )
242+ {
243+ if let Some ( idx) = self . windows . contains_slot ( i) {
244+ self . select_window ( idx) ;
245+ break ;
246+ }
247+ }
248+ } else {
249+ let old = self . active . map ( |i| i. slot ( ) ) . unwrap_or ( 0 ) ;
250+ for i in ( old + 1 ..self . windows . capacity ( ) as u32 ) . chain ( 0 ..=old) {
251+ if let Some ( idx) = self . windows . contains_slot ( i) {
252+ self . select_window ( idx) ;
253+ break ;
254+ }
242255 }
243256 }
244257 // active = (active + 1) % clients.len();
@@ -390,7 +403,8 @@ fn handle_conns(mut fb: framebuffer::Framebuffer, server_socket: FileDesc) {
390403 window_manager. windows [ window] . client = idx;
391404 }
392405
393- intermediate_fb. fill ( 0 ) ;
406+ let bg_color = 0xFFC8FFFF ;
407+ intermediate_fb. fill ( 0x00000001000000010000000100000001 * bg_color) ;
394408
395409 // TODO: better scheduling for this
396410 loop {
@@ -405,10 +419,12 @@ fn handle_conns(mut fb: framebuffer::Framebuffer, server_socket: FileDesc) {
405419 let code = remap_keycode ( code) ;
406420
407421 match ( code, pressed) {
408- ( proto:: ScanCode :: TAB , true ) => {
409- // TODO: modifiers
410- window_manager. alt_tab ( ) ;
411- continue ;
422+ ( ScanCode :: TAB , true ) => {
423+ if modifiers. alt_pressed ( ) {
424+ let reverse = modifiers. shift_pressed ( ) ;
425+ window_manager. alt_tab ( reverse) ;
426+ continue ;
427+ }
412428 }
413429 ( ScanCode :: LEFT_SHIFT , p) => modifiers. set ( Modifiers :: L_SHIFT , p) ,
414430 ( ScanCode :: RIGHT_SHIFT , p) => modifiers. set ( Modifiers :: R_SHIFT , p) ,
@@ -418,9 +434,54 @@ fn handle_conns(mut fb: framebuffer::Framebuffer, server_socket: FileDesc) {
418434 ( ScanCode :: RIGHT_ALT , p) => modifiers. set ( Modifiers :: R_ALT , p) ,
419435 ( ScanCode :: LEFT_SUPER , p) => modifiers. set ( Modifiers :: L_SUPER , p) ,
420436 ( ScanCode :: RIGHT_SUPER , p) => modifiers. set ( Modifiers :: R_SUPER , p) ,
437+ ( ScanCode :: T , true ) if modifiers. ctrl_pressed ( ) && modifiers. alt_pressed ( ) => {
438+ spawn_console ( ) ;
439+ }
421440 _ => ( ) ,
422441 }
423442
443+ // TODO: key repeat???
444+
445+ if let Some ( active) = window_manager. active {
446+ let window = & mut window_manager. windows [ active] ;
447+
448+ let move_scale = if modifiers. shift_pressed ( ) {
449+ 128
450+ } else if modifiers. alt_pressed ( ) {
451+ 1
452+ } else {
453+ 16
454+ } ;
455+
456+ match ( code, pressed) {
457+ ( ScanCode :: LEFT , true ) if modifiers. super_pressed ( ) => {
458+ window. pos . x = window. pos . x . saturating_sub ( move_scale) ;
459+ continue ;
460+ }
461+ ( ScanCode :: RIGHT , true ) if modifiers. super_pressed ( ) => {
462+ window. pos . x = ( window. pos . x )
463+ . saturating_add ( move_scale)
464+ . min ( fb. width as u16 - 1 ) ;
465+ continue ;
466+ }
467+ ( ScanCode :: UP , true ) if modifiers. super_pressed ( ) => {
468+ window. pos . y = window. pos . y . saturating_sub ( move_scale) ;
469+ continue ;
470+ }
471+ ( ScanCode :: DOWN , true ) if modifiers. super_pressed ( ) => {
472+ window. pos . y = ( window. pos . y )
473+ . saturating_add ( move_scale)
474+ . min ( fb. height as u16 - 1 ) ;
475+ continue ;
476+ }
477+ ( ScanCode :: F4 , true ) if modifiers. alt_pressed ( ) => {
478+ window_manager. request_close . push ( active) ;
479+ continue ;
480+ }
481+ _ => ( ) ,
482+ } ;
483+ }
484+
424485 if let Some ( active) = window_manager. active {
425486 let window = & window_manager. windows [ active] ;
426487 let client = clients. get_mut ( window. client ) . unwrap ( ) ;
@@ -733,6 +794,22 @@ fn handle_conns(mut fb: framebuffer::Framebuffer, server_socket: FileDesc) {
733794 }
734795}
735796
797+ fn spawn_console ( ) {
798+ let path = b"/console.elf" ;
799+ let file = ulib:: sys:: openat ( 3 , path, 0 , 0 ) . unwrap ( ) ;
800+ ulib:: sys:: spawn_elf ( & ulib:: sys:: SpawnArgs {
801+ fd : file,
802+ stdin : None ,
803+ stdout : None ,
804+ stderr : None ,
805+ args : & [ ulib:: sys:: ArgStr {
806+ len : path. len ( ) ,
807+ ptr : path. as_ptr ( ) ,
808+ } ] ,
809+ } )
810+ . unwrap ( ) ;
811+ }
812+
736813fn remap_keycode ( code : isize ) -> proto:: ScanCode {
737814 use proto:: ScanCode ;
738815 match code {
@@ -794,9 +871,16 @@ fn remap_keycode(code: isize) -> proto::ScanCode {
794871 0x3A => ScanCode :: F1 ,
795872 0x3B => ScanCode :: F2 ,
796873 0x3C => ScanCode :: F3 ,
797- // ...
874+ 0x3D => ScanCode :: F4 ,
875+ 0x3E => ScanCode :: F5 ,
876+ 0x3F => ScanCode :: F6 ,
877+ 0x40 => ScanCode :: F7 ,
878+ 0x41 => ScanCode :: F8 ,
879+ 0x42 => ScanCode :: F9 ,
880+ 0x43 => ScanCode :: F10 ,
881+ 0x44 => ScanCode :: F11 ,
798882 0x45 => ScanCode :: F12 ,
799- // 0x46 => ScanCode::PRINT_SCREEN
883+ // 0x46 => ScanCode::PRINT_SCREEN,
800884 0x47 => ScanCode :: SCROLL_LOCK ,
801885 0x48 => ScanCode :: PAUSE ,
802886 0x49 => ScanCode :: INSERT ,
0 commit comments