diff options
Diffstat (limited to 'shell/src/lib.rs')
| -rw-r--r-- | shell/src/lib.rs | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/shell/src/lib.rs b/shell/src/lib.rs index 11f5786..6de056c 100644 --- a/shell/src/lib.rs +++ b/shell/src/lib.rs | |||
| @@ -1126,6 +1126,98 @@ fn abi_kernel_version(out: &mut rsapi::KernelVersion) { | |||
| 1126 | out.patch = patch; | 1126 | out.patch = patch; |
| 1127 | } | 1127 | } |
| 1128 | 1128 | ||
| 1129 | |||
| 1130 | /// ABI: create a window via the window manager. | ||
| 1131 | fn abi_wm_create(title: rsapi::Line, w: u32, h: u32) -> i32 { | ||
| 1132 | let s = title.as_str(); | ||
| 1133 | match rsnix::wm::create_window(s, w as usize, h as usize) { | ||
| 1134 | Some(id) => id as i32, | ||
| 1135 | None => -1, | ||
| 1136 | } | ||
| 1137 | } | ||
| 1138 | |||
| 1139 | /// ABI: get window pixel buffer info. | ||
| 1140 | fn abi_wm_buffer(id: i32, out: &mut rsapi::WindowInfo) -> bool { | ||
| 1141 | match rsnix::wm::buffer(id as usize) { | ||
| 1142 | Some((ptr, w, h)) => { | ||
| 1143 | out.ptr = ptr; | ||
| 1144 | out.w = w as u32; | ||
| 1145 | out.h = h as u32; | ||
| 1146 | true | ||
| 1147 | } | ||
| 1148 | None => false, | ||
| 1149 | } | ||
| 1150 | } | ||
| 1151 | |||
| 1152 | /// ABI: composite window to screen. | ||
| 1153 | fn abi_wm_flush(id: i32) { | ||
| 1154 | rsnix::wm::flush(id as usize); | ||
| 1155 | } | ||
| 1156 | |||
| 1157 | /// ABI: destroy a window. | ||
| 1158 | fn abi_wm_destroy(id: i32) { | ||
| 1159 | rsnix::wm::destroy(id as usize); | ||
| 1160 | } | ||
| 1161 | |||
| 1162 | /// ABI: non-blocking receive of one WM event. | ||
| 1163 | fn abi_wm_recv(out: &mut rsapi::WmEvent) -> bool { | ||
| 1164 | use rsnix::ps2::KeyEvent; | ||
| 1165 | match rsnix::sched::recv() { | ||
| 1166 | None => false, | ||
| 1167 | Some(msg) => { | ||
| 1168 | match msg { | ||
| 1169 | rsnix::sched::TaskMsg::Key(k) => { | ||
| 1170 | out.kind = 0; | ||
| 1171 | match k { | ||
| 1172 | KeyEvent::Char(c) => { | ||
| 1173 | out.key_kind = rsapi::WmKeyKind::Char; | ||
| 1174 | out.key_char = c as u8; | ||
| 1175 | } | ||
| 1176 | KeyEvent::Enter => { out.key_kind = rsapi::WmKeyKind::Enter; } | ||
| 1177 | KeyEvent::Backspace => { out.key_kind = rsapi::WmKeyKind::Backspace; } | ||
| 1178 | KeyEvent::Tab => { out.key_kind = rsapi::WmKeyKind::Tab; } | ||
| 1179 | KeyEvent::Escape => { out.key_kind = rsapi::WmKeyKind::Escape; } | ||
| 1180 | KeyEvent::Ctrl('c') => { out.key_kind = rsapi::WmKeyKind::CtrlC; } | ||
| 1181 | KeyEvent::ArrowUp => { out.key_kind = rsapi::WmKeyKind::ArrowUp; } | ||
| 1182 | KeyEvent::ArrowDown => { out.key_kind = rsapi::WmKeyKind::ArrowDown; } | ||
| 1183 | KeyEvent::ArrowLeft => { out.key_kind = rsapi::WmKeyKind::ArrowLeft; } | ||
| 1184 | KeyEvent::ArrowRight => { out.key_kind = rsapi::WmKeyKind::ArrowRight; } | ||
| 1185 | KeyEvent::Home => { out.key_kind = rsapi::WmKeyKind::Home; } | ||
| 1186 | KeyEvent::End => { out.key_kind = rsapi::WmKeyKind::End; } | ||
| 1187 | KeyEvent::PageUp => { out.key_kind = rsapi::WmKeyKind::PageUp; } | ||
| 1188 | KeyEvent::PageDown => { out.key_kind = rsapi::WmKeyKind::PageDown; } | ||
| 1189 | KeyEvent::Delete => { out.key_kind = rsapi::WmKeyKind::Delete; } | ||
| 1190 | KeyEvent::F(1) => { out.key_kind = rsapi::WmKeyKind::F1; } | ||
| 1191 | KeyEvent::F(2) => { out.key_kind = rsapi::WmKeyKind::F2; } | ||
| 1192 | KeyEvent::F(3) => { out.key_kind = rsapi::WmKeyKind::F3; } | ||
| 1193 | KeyEvent::F(4) => { out.key_kind = rsapi::WmKeyKind::F4; } | ||
| 1194 | _ => { out.key_kind = rsapi::WmKeyKind::Unknown; } | ||
| 1195 | } | ||
| 1196 | out.key_char = 0; | ||
| 1197 | true | ||
| 1198 | } | ||
| 1199 | rsnix::sched::TaskMsg::AppMouse(m) => { | ||
| 1200 | out.kind = 1; | ||
| 1201 | out.mouse.x = m.x; | ||
| 1202 | out.mouse.y = m.y; | ||
| 1203 | out.mouse.buttons = m.buttons; | ||
| 1204 | true | ||
| 1205 | } | ||
| 1206 | rsnix::sched::TaskMsg::Focus(f) => { | ||
| 1207 | out.kind = 2; | ||
| 1208 | out.focused = f; | ||
| 1209 | true | ||
| 1210 | } | ||
| 1211 | rsnix::sched::TaskMsg::Close => { | ||
| 1212 | out.kind = 3; | ||
| 1213 | true | ||
| 1214 | } | ||
| 1215 | _ => false, | ||
| 1216 | } | ||
| 1217 | } | ||
| 1218 | } | ||
| 1219 | } | ||
| 1220 | |||
| 1129 | /// Construct the Exports table for this invocation. v2 fields are | 1221 | /// Construct the Exports table for this invocation. v2 fields are |
| 1130 | /// populated at runtime (binary callbacks → shell → kernel). | 1222 | /// populated at runtime (binary callbacks → shell → kernel). |
| 1131 | fn build_exports() -> rsapi::Exports { | 1223 | fn build_exports() -> rsapi::Exports { |
| @@ -1150,6 +1242,11 @@ fn build_exports() -> rsapi::Exports { | |||
| 1150 | pci_device: abi_pci_device, | 1242 | pci_device: abi_pci_device, |
| 1151 | klog_dump: abi_klog_dump, | 1243 | klog_dump: abi_klog_dump, |
| 1152 | kernel_version: abi_kernel_version, | 1244 | kernel_version: abi_kernel_version, |
| 1245 | wm_create: abi_wm_create, | ||
| 1246 | wm_buffer: abi_wm_buffer, | ||
| 1247 | wm_flush: abi_wm_flush, | ||
| 1248 | wm_destroy: abi_wm_destroy, | ||
| 1249 | wm_recv: abi_wm_recv, | ||
| 1153 | } | 1250 | } |
| 1154 | } | 1251 | } |
| 1155 | 1252 | ||
