Skip to content

Commit 206962c

Browse files
committed
Window manager shortcuts
1 parent 8c00cc0 commit 206962c

2 files changed

Lines changed: 110 additions & 17 deletions

File tree

crates/display-server/src/main.rs

Lines changed: 97 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
736813
fn 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,

crates/init/src/main.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,26 @@ pub extern "C" fn main() {
3737

3838
for _ in 0..4 {
3939
let console_path = "console.elf".as_bytes();
40+
let shell_path = "shell".as_bytes();
41+
4042
spawn_elf(&ulib::sys::SpawnArgs {
4143
fd: ulib::sys::openat(root_fd, console_path, 0, 0).unwrap(),
4244
stdin: None,
4345
stdout: None,
4446
stderr: None,
45-
args: &[ArgStr {
46-
len: console_path.len(),
47-
ptr: console_path.as_ptr(),
48-
}],
47+
args: &[
48+
ArgStr {
49+
len: console_path.len(),
50+
ptr: console_path.as_ptr(),
51+
},
52+
ArgStr {
53+
len: shell_path.len(),
54+
ptr: shell_path.as_ptr(),
55+
},
56+
],
4957
})
5058
.unwrap();
59+
5160
unsafe { sys_sleep_ms(1000) };
5261
}
5362

0 commit comments

Comments
 (0)