Skip to content

Commit

Permalink
[awm2] Initial communication with dock
Browse files Browse the repository at this point in the history
  • Loading branch information
codyd51 committed Dec 26, 2022
1 parent de9d941 commit b12a3c6
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 5 deletions.
35 changes: 34 additions & 1 deletion rust_programs/awm2/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -1507,6 +1519,13 @@ impl Desktop {
Rc::clone(&window) as Rc<dyn DesktopElement>,
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) {
Expand All @@ -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<Rc<Window>> {
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)]
Expand Down
31 changes: 28 additions & 3 deletions rust_programs/awm2/src/main_axle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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}");
}
Expand Down
28 changes: 27 additions & 1 deletion rust_programs/dock_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit b12a3c6

Please sign in to comment.