Skip to content

Commit 252b7c9

Browse files
author
adrerl
committed
cargo fmt
1 parent e1510ea commit 252b7c9

37 files changed

Lines changed: 840 additions & 379 deletions

channel/src/lib.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use core::{
99
/// Single-producer, single-consumer ring buffer.
1010
/// N MUST be a power of 2. enforced at compile time via const assertion.
1111
pub struct Channel<T, const N: usize> {
12-
buf: [UnsafeCell<MaybeUninit<T>>; N],
12+
buf: [UnsafeCell<MaybeUninit<T>>; N],
1313
head: AtomicUsize, // producer advances
1414
tail: AtomicUsize, // consumer advances
1515
}
@@ -29,10 +29,7 @@ impl<T, const N: usize> Channel<T, N> {
2929
let _ = Self::ASSERT_POWER_OF_2;
3030
// SAFETY: MaybeUninit arrays can be zero-initialized.
3131
Self {
32-
buf: unsafe {
33-
MaybeUninit::<[UnsafeCell<MaybeUninit<T>>; N]>::zeroed()
34-
.assume_init()
35-
},
32+
buf: unsafe { MaybeUninit::<[UnsafeCell<MaybeUninit<T>>; N]>::zeroed().assume_init() },
3633
head: AtomicUsize::new(0),
3734
tail: AtomicUsize::new(0),
3835
}
@@ -61,9 +58,7 @@ impl<T, const N: usize> Channel<T, N> {
6158
if tail == head {
6259
return None;
6360
}
64-
let msg = unsafe {
65-
(*self.buf[tail & (N - 1)].get()).assume_init_read()
66-
};
61+
let msg = unsafe { (*self.buf[tail & (N - 1)].get()).assume_init_read() };
6762
self.tail.store(tail.wrapping_add(1), Ordering::Release);
6863
Some(msg)
6964
}

compd/src/islands/focus.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ pub fn process_msgs(state: &mut CompState) {
1010
InputMsg::WindowClosed { idx, .. } => {
1111
if state.focused == Some(idx as usize) {
1212
// refocus next z1 window. desktop (z0) is not focusable.
13-
state.focused = state.windows.iter().enumerate()
13+
state.focused = state
14+
.windows
15+
.iter()
16+
.enumerate()
1417
.find(|(_, w)| w.as_ref().map(|w| w.z_layer == 1).unwrap_or(false))
1518
.map(|(i, _)| i);
1619
}

compd/src/islands/input.rs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
extern crate alloc;
22

3-
use libmorpheus::{compositor as compsys, hw, io, process};
4-
use crate::islands::{CompState, HitRegion, MouseCapture, TITLE_H, BORDER, PANEL_H, MAX_WINDOWS};
3+
use crate::islands::{CompState, HitRegion, MouseCapture, BORDER, MAX_WINDOWS, PANEL_H, TITLE_H};
54
use crate::messages::InputMsg;
5+
use libmorpheus::{compositor as compsys, hw, io, process};
66

77
const CTRL_BRACKET: u8 = 0x1D; // Ctrl+] — focus cycle scancode
88

@@ -14,8 +14,14 @@ pub fn poll(state: &mut CompState) {
1414
fn poll_keyboard(state: &mut CompState) {
1515
let mut kb = [0u8; 32];
1616
let avail = io::stdin_available();
17-
let n = if avail > 0 { io::read_stdin(&mut kb) } else { 0 };
18-
if n == 0 { return; }
17+
let n = if avail > 0 {
18+
io::read_stdin(&mut kb)
19+
} else {
20+
0
21+
};
22+
if n == 0 {
23+
return;
24+
}
1925

2026
let mut has_cycle = false;
2127
for b in kb.iter_mut().take(n) {
@@ -143,7 +149,13 @@ fn poll_mouse(state: &mut CompState) {
143149
}
144150
route_to_child = false;
145151
}
146-
MouseCapture::Resize { idx, start_mx, start_my, start_w, start_h } => {
152+
MouseCapture::Resize {
153+
idx,
154+
start_mx,
155+
start_my,
156+
start_w,
157+
start_h,
158+
} => {
147159
if let Some(ref mut win) = state.windows[idx] {
148160
let dx = state.mouse_x - start_mx;
149161
let dy = state.mouse_y - start_my;
@@ -204,15 +216,19 @@ fn hit_test(state: &CompState, mx: i32, my: i32) -> Option<(usize, HitRegion)> {
204216
for &c in &candidates[..cn] {
205217
if let Some(idx) = c {
206218
if let Some(ref win) = state.windows[idx] {
207-
if win.z_layer != 1 { continue; }
219+
if win.z_layer != 1 {
220+
continue;
221+
}
208222

209223
let outer_x = win.x - BORDER as i32;
210224
let outer_y = win.y - TITLE_H as i32 - BORDER as i32;
211225
let outer_w = win.w as i32 + BORDER as i32 * 2;
212226
let outer_h = win.h as i32 + TITLE_H as i32 + BORDER as i32 * 2;
213227

214-
if mx < outer_x || mx >= outer_x + outer_w
215-
|| my < outer_y || my >= outer_y + outer_h
228+
if mx < outer_x
229+
|| mx >= outer_x + outer_w
230+
|| my < outer_y
231+
|| my >= outer_y + outer_h
216232
{
217233
continue;
218234
}
@@ -223,8 +239,10 @@ fn hit_test(state: &CompState, mx: i32, my: i32) -> Option<(usize, HitRegion)> {
223239
let tb_w = win.w as i32;
224240
let close_x = tb_x + tb_w - 34;
225241
let close_w = 30;
226-
if my >= tb_y && my < tb_y + TITLE_H as i32
227-
&& mx >= close_x && mx < close_x + close_w
242+
if my >= tb_y
243+
&& my < tb_y + TITLE_H as i32
244+
&& mx >= close_x
245+
&& mx < close_x + close_w
228246
{
229247
return Some((idx, HitRegion::Close));
230248
}
@@ -242,8 +260,10 @@ fn hit_test(state: &CompState, mx: i32, my: i32) -> Option<(usize, HitRegion)> {
242260
}
243261

244262
// content area
245-
if mx >= win.x && mx < win.x + win.w as i32
246-
&& my >= win.y && my < win.y + win.h as i32
263+
if mx >= win.x
264+
&& mx < win.x + win.w as i32
265+
&& my >= win.y
266+
&& my < win.y + win.h as i32
247267
{
248268
return Some((idx, HitRegion::Content));
249269
}

compd/src/islands/mod.rs

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
pub mod vsync;
1+
pub mod focus;
2+
pub mod input;
23
pub mod renderer;
34
pub mod surface_mgr;
4-
pub mod input;
5-
pub mod focus;
5+
pub mod vsync;
66

7-
use libmorpheus::compositor as compsys;
8-
use channel::Channel;
97
use crate::messages::*;
8+
use channel::Channel;
9+
use libmorpheus::compositor as compsys;
1010

1111
pub const MAX_WINDOWS: usize = 16;
1212
pub const TITLE_H: u32 = 22;
@@ -26,26 +26,30 @@ pub const CURSOR_RGB: (u8, u8, u8) = (255, 255, 255);
2626
pub const PANEL_H: u32 = 30;
2727

2828
pub struct ChildWindow {
29-
pub pid: u32,
30-
pub surface_ptr: *const u32,
31-
pub mapped: bool,
29+
pub pid: u32,
30+
pub surface_ptr: *const u32,
31+
pub mapped: bool,
3232
pub surface_vaddr: u64,
3333
pub surface_pages: u64,
34-
pub x: i32,
35-
pub y: i32,
36-
pub w: u32,
37-
pub h: u32,
38-
pub src_w: u32,
39-
pub src_h: u32,
40-
pub src_stride: u32, // in pixels. not bytes. the framebuffer stride IS bytes. yes again.
41-
pub title: [u8; 64],
42-
pub title_len: usize,
43-
pub z_layer: u8, // 0=desktop background, 1=normal window, 3=overlay
34+
pub x: i32,
35+
pub y: i32,
36+
pub w: u32,
37+
pub h: u32,
38+
pub src_w: u32,
39+
pub src_h: u32,
40+
pub src_stride: u32, // in pixels. not bytes. the framebuffer stride IS bytes. yes again.
41+
pub title: [u8; 64],
42+
pub title_len: usize,
43+
pub z_layer: u8, // 0=desktop background, 1=normal window, 3=overlay
4444
}
4545

4646
#[derive(Clone, Copy)]
4747
pub enum MouseCapture {
48-
Move { idx: usize, off_x: i32, off_y: i32 },
48+
Move {
49+
idx: usize,
50+
off_x: i32,
51+
off_y: i32,
52+
},
4953
Resize {
5054
idx: usize,
5155
start_mx: i32,
@@ -65,26 +69,26 @@ pub enum HitRegion {
6569

6670
pub struct CompState {
6771
// --- renderer island owns these ---
68-
pub fb_ptr: *mut u32,
69-
pub fb_w: u32,
70-
pub fb_h: u32,
72+
pub fb_ptr: *mut u32,
73+
pub fb_w: u32,
74+
pub fb_h: u32,
7175
pub fb_stride: u32, // stride in PIXELS (fb_info.stride / 4). yes confusing. no we can't change it.
72-
pub is_bgrx: bool,
76+
pub is_bgrx: bool,
7377

7478
// --- surface_mgr island owns these ---
75-
pub windows: [Option<ChildWindow>; MAX_WINDOWS],
76-
pub cascade_n: i32,
79+
pub windows: [Option<ChildWindow>; MAX_WINDOWS],
80+
pub cascade_n: i32,
7781
pub surface_buf: [compsys::SurfaceEntry; MAX_WINDOWS],
7882
pub desktop_idx: Option<usize>, // slot index of shelld's desktop surface (z_layer 0)
7983

8084
// --- focus island owns these ---
8185
pub focused: Option<usize>,
8286

8387
// --- input island owns these ---
84-
pub mouse_x: i32,
85-
pub mouse_y: i32,
88+
pub mouse_x: i32,
89+
pub mouse_y: i32,
8690
pub last_buttons: u8,
87-
pub capture: Option<MouseCapture>,
91+
pub capture: Option<MouseCapture>,
8892

8993
// --- channels (SPSC) ---
9094
pub ch_input_to_focus: Channel<InputMsg, 16>,
@@ -99,15 +103,15 @@ impl CompState {
99103
fb_h,
100104
fb_stride: fb_stride_px,
101105
is_bgrx,
102-
windows: [NONE; MAX_WINDOWS],
103-
cascade_n: 0,
106+
windows: [NONE; MAX_WINDOWS],
107+
cascade_n: 0,
104108
surface_buf: [zeroed_surface_entry(); MAX_WINDOWS],
105109
desktop_idx: None,
106-
focused: None,
107-
mouse_x: (fb_w / 2) as i32,
108-
mouse_y: (fb_h / 2) as i32,
110+
focused: None,
111+
mouse_x: (fb_w / 2) as i32,
112+
mouse_y: (fb_h / 2) as i32,
109113
last_buttons: 0,
110-
capture: None,
114+
capture: None,
111115
ch_input_to_focus: Channel::new(),
112116
}
113117
}

0 commit comments

Comments
 (0)