Skip to content

Commit

Permalink
[awm2] Double clicking a shortcut launches the referred program
Browse files Browse the repository at this point in the history
  • Loading branch information
codyd51 committed Jan 1, 2023
1 parent f5bb3c3 commit 33e1f25
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
3 changes: 2 additions & 1 deletion rust_programs/awm2/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,8 @@ impl Desktop {
MouseInteractionState::ShortcutHover(old_shortcut) => {
// If we're transitioning out of a shortcut, inform it
let exited_shortcut = match &new_state {
MouseInteractionState::ShortcutHover(new_shortcut) => {
MouseInteractionState::ShortcutHover(new_shortcut)
| MouseInteractionState::ShortcutDrag(new_shortcut) => {
!Rc::ptr_eq(old_shortcut, new_shortcut)
}
_ => true,
Expand Down
12 changes: 12 additions & 0 deletions rust_programs/awm2/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use dock_messages::{
AwmDockWindowClosed, AwmDockWindowCreatedEvent, AwmDockWindowMinimizeRequestedEvent,
AwmDockWindowTitleUpdatedEvent, AWM_DOCK_SERVICE_NAME,
};
use file_manager_messages::{LaunchProgram, FILE_SERVER_SERVICE_NAME};

#[cfg(target_os = "axle")]
mod conditional_imports {
Expand Down Expand Up @@ -211,3 +212,14 @@ pub fn inform_dock_window_created(window_id: usize, owner_service: &str) {
println!("inform_dock_window_created({window_id})");
}
}

pub fn request_program_launch(path: &str) {
#[cfg(target_os = "axle")]
{
amc_message_send(FILE_SERVER_SERVICE_NAME, LaunchProgram::new(path));
}
#[cfg(not(target_os = "axle"))]
{
println!("request_program_launch({path})");
}
}
36 changes: 29 additions & 7 deletions rust_programs/awm2/src/shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::bitmap::BitmapImage;
use crate::desktop::{
Desktop, DesktopElement, DesktopElementZIndexCategory, MouseInteractionCallbackResult,
};
use crate::events::request_program_launch;
use crate::println;
use crate::utils::get_timestamp;
use agx_definitions::{
Expand Down Expand Up @@ -34,7 +35,7 @@ pub struct DesktopShortcut {
icon: BitmapImage,
path: String,
title: String,
//first_click_start_time: Option<usize>,
first_click_start_time: RefCell<Option<u64>>,
interaction_state: RefCell<ShortcutMouseInteractionState>,
desktop_background_slice: RefCell<Option<SingleFramebufferLayer>>,
desktop_gradient_background_color: RefCell<Option<Color>>,
Expand All @@ -51,7 +52,7 @@ impl DesktopShortcut {
icon: icon.clone(),
path: path.to_string(),
title: title.to_string(),
//first_click_start_time: None,
first_click_start_time: RefCell::new(None),
interaction_state: RefCell::new(ShortcutMouseInteractionState::Unhovered),
desktop_background_slice: RefCell::new(None),
desktop_gradient_background_color: RefCell::new(None),
Expand All @@ -74,11 +75,20 @@ impl DesktopShortcut {
}

fn is_in_soft_click(&self) -> bool {
//self.first_click_start_time.is_some()
matches!(
self.mouse_interaction_state(),
ShortcutMouseInteractionState::LeftClickUp(_)
)
self.first_click_start_time.borrow().is_some()
}

fn set_first_click_start_time(&self, timestamp: u64) {
*self.first_click_start_time.borrow_mut() = Some(timestamp)
}

fn first_click_start_time(&self) -> Option<u64> {
*self.first_click_start_time.borrow()
}

fn clear_soft_click_status(&self) {
println!("Clearing soft click status");
*self.first_click_start_time.borrow_mut() = None
}

pub fn copy_desktop_background_slice(
Expand Down Expand Up @@ -235,12 +245,24 @@ impl DesktopElement for DesktopShortcut {

fn handle_mouse_exited(&self) -> MouseInteractionCallbackResult {
self.set_mouse_interaction_state(ShortcutMouseInteractionState::Unhovered);
self.clear_soft_click_status();
self.render();
MouseInteractionCallbackResult::RedrawRequested
}

fn handle_left_click_began(&self, _mouse_pos: Point) -> MouseInteractionCallbackResult {
self.set_mouse_interaction_state(ShortcutMouseInteractionState::LeftClickDown);
if !self.is_in_soft_click() {
self.set_first_click_start_time(get_timestamp());
} else {
let double_click_duration = get_timestamp() - self.first_click_start_time().unwrap();
println!("Double click duration {double_click_duration}");
if double_click_duration <= 500 {
self.clear_soft_click_status();
// Quick double-click, launch the underlying program
request_program_launch(&self.path);
}
}
self.render();
MouseInteractionCallbackResult::RedrawRequested
}
Expand Down

0 comments on commit 33e1f25

Please sign in to comment.