From b12a3c62a11114914558dd00685e348adf6401de Mon Sep 17 00:00:00 2001 From: Phillip Tennen Date: Mon, 26 Dec 2022 13:07:51 +0000 Subject: [PATCH] [awm2] Initial communication with dock --- rust_programs/awm2/src/desktop.rs | 35 +++++++++++++++++++++++++- rust_programs/awm2/src/main_axle.rs | 31 ++++++++++++++++++++--- rust_programs/dock_messages/src/lib.rs | 28 ++++++++++++++++++++- 3 files changed, 89 insertions(+), 5 deletions(-) diff --git a/rust_programs/awm2/src/desktop.rs b/rust_programs/awm2/src/desktop.rs index fa120df39..179a6fb4b 100644 --- a/rust_programs/awm2/src/desktop.rs +++ b/rust_programs/awm2/src/desktop.rs @@ -19,7 +19,10 @@ use core::cmp::{max, min}; use mouse_driver_messages::MousePacket; use crate::animations::{Animation, WindowOpenAnimationParams}; -use dock_messages::AWM_DOCK_HEIGHT; +use dock_messages::{ + AwmDockTaskViewClicked, AwmDockWindowCreatedEvent, AwmDockWindowTitleUpdatedEvent, + AWM_DOCK_HEIGHT, AWM_DOCK_SERVICE_NAME, +}; use file_manager_messages::str_from_u8_nul_utf8_unchecked; use kb_driver_messages::{KeyEventType, KeyIdentifier, KeyboardPacket}; use preferences_messages::PreferencesUpdated; @@ -969,6 +972,15 @@ impl Desktop { ))); } + if !awm_service_is_dock(&source) { + #[cfg(target_os = "axle")] + { + // If this is a window other than the dock, inform the dock + let msg = AwmDockWindowCreatedEvent::new(new_window.id(), &source); + amc_message_send(AWM_DOCK_SERVICE_NAME, msg); + } + } + new_window } @@ -1507,6 +1519,13 @@ impl Desktop { Rc::clone(&window) as Rc, title_bar_frame, ); + + // Inform the dock + #[cfg(target_os = "axle")] + { + let dock_notification = AwmDockWindowTitleUpdatedEvent::new(window.id(), new_title); + amc_message_send(AWM_DOCK_SERVICE_NAME, dock_notification); + } } pub fn test(&mut self) { @@ -1532,6 +1551,20 @@ impl Desktop { self.draw_background(); self.compositor_state.queue_full_redraw(self.desktop_frame); } + + fn window_with_id(&self, window_id: usize) -> Option> { + for w in self.windows.iter() { + if w.id() == window_id { + return Some(Rc::clone(w)); + } + } + None + } + + pub fn handle_dock_task_view_clicked(&mut self, msg: &AwmDockTaskViewClicked) { + let window = self.window_with_id(msg.window_id as usize).unwrap(); + self.move_window_to_top(&window); + } } #[cfg(test)] diff --git a/rust_programs/awm2/src/main_axle.rs b/rust_programs/awm2/src/main_axle.rs index a7e218679..a3b189775 100644 --- a/rust_programs/awm2/src/main_axle.rs +++ b/rust_programs/awm2/src/main_axle.rs @@ -26,8 +26,13 @@ use awm_messages::{ AwmWindowRedrawReady, AwmWindowUpdateTitle, }; +use dock_messages::{ + AwmDockTaskViewClicked, AwmDockTaskViewHoverExited, AwmDockTaskViewHovered, + AWM_DOCK_SERVICE_NAME, +}; use kb_driver_messages::KB_DRIVER_SERVICE_NAME; use mouse_driver_messages::{MousePacket, MOUSE_DRIVER_SERVICE_NAME}; +use preferences_messages::PREFERENCES_SERVICE_NAME; use axle_rt::core_commands::{ AmcAwmMapFramebuffer, AmcAwmMapFramebufferResponse, AmcSharedMemoryCreateRequest, @@ -125,12 +130,35 @@ fn process_next_amc_message(desktop: &mut Desktop) { ); true } + PreferencesUpdated::EXPECTED_EVENT => { + desktop.handle_preferences_updated(body_as_type_unchecked(raw_body)); + true + } _ => { //println!("Ignoring unknown message from preferences"); false } } } + AWM_DOCK_SERVICE_NAME => { + match event { + AwmDockTaskViewHovered::EXPECTED_EVENT => { + // Do nothing + // Eventually, consider displaying a window preview like the original awm + true + } + AwmDockTaskViewHoverExited::EXPECTED_EVENT => { + // Eventually, dismiss hover preview + true + } + AwmDockTaskViewClicked::EXPECTED_EVENT => { + desktop.handle_dock_task_view_clicked(body_as_type_unchecked(raw_body)); + true + } + _ => false, + } + } + _ => false, }; if !consumed { // Unknown sender - probably a client wanting to interact with the window manager @@ -155,9 +183,6 @@ fn process_next_amc_message(desktop: &mut Desktop) { desktop .handle_window_updated_title(&msg_source, body_as_type_unchecked(raw_body)); } - PreferencesUpdated::EXPECTED_EVENT => { - desktop.handle_preferences_updated(body_as_type_unchecked(raw_body)) - } _ => { println!("Awm ignoring message with unknown event type: {event}"); } diff --git a/rust_programs/dock_messages/src/lib.rs b/rust_programs/dock_messages/src/lib.rs index 960950378..e7e2db669 100644 --- a/rust_programs/dock_messages/src/lib.rs +++ b/rust_programs/dock_messages/src/lib.rs @@ -3,7 +3,7 @@ extern crate alloc; use agx_definitions::{Rect, RectU32}; -use axle_rt::{ContainsEventField, ExpectsEventField}; +use axle_rt::{copy_str_into_sized_slice, ContainsEventField, ExpectsEventField}; use axle_rt_derive::ContainsEventField; // PT: Must match the definitions in the corresponding C header @@ -28,6 +28,19 @@ pub struct AwmDockWindowCreatedEvent { pub title: [u8; 64], } +impl AwmDockWindowCreatedEvent { + pub fn new(window_id: usize, title: &str) -> Self { + let mut title_buf = [0; 64]; + let title_len = copy_str_into_sized_slice(&mut title_buf, title); + Self { + event: Self::EXPECTED_EVENT, + window_id: window_id as u32, + title_len: title_len.try_into().unwrap(), + title: title_buf, + } + } +} + impl ExpectsEventField for AwmDockWindowCreatedEvent { const EXPECTED_EVENT: u32 = 817; } @@ -45,6 +58,19 @@ pub struct AwmDockWindowTitleUpdatedEvent { pub title: [u8; 64], } +impl AwmDockWindowTitleUpdatedEvent { + pub fn new(window_id: usize, title: &str) -> Self { + let mut title_buf = [0; 64]; + let title_len = copy_str_into_sized_slice(&mut title_buf, title); + Self { + event: Self::EXPECTED_EVENT, + window_id: window_id as u32, + title_len: title_len.try_into().unwrap(), + title: title_buf, + } + } +} + impl ExpectsEventField for AwmDockWindowTitleUpdatedEvent { const EXPECTED_EVENT: u32 = 818; }