Skip to content

Commit

Permalink
Use button instead of hotkey to trigger on-screen controls window
Browse files Browse the repository at this point in the history
  • Loading branch information
steinbro authored and Eh2406 committed Jun 2, 2023
1 parent d2f674d commit dd71aa2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 29 deletions.
5 changes: 1 addition & 4 deletions src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@ pub enum Action {
ReloadSettings,
ShowSettings,
ToggleWindowVisible,
ShowControls,
PlayPause,
RateDown,
RateUp,
}

pub const ACTION_LIST: [Action; 9] = [
pub const ACTION_LIST: [Action; 8] = [
Action::Read,
Action::Close,
Action::ReloadSettings,
Action::ShowSettings,
Action::ToggleWindowVisible,
Action::ShowControls,
Action::PlayPause,
Action::RateDown,
Action::RateUp,
Expand All @@ -44,7 +42,6 @@ impl ::std::fmt::Display for Action {
ReloadSettings => write!(f, "reload_settings"),
ShowSettings => write!(f, "show_settings"),
ToggleWindowVisible => write!(f, "toggle_window_visible"),
ShowControls => write!(f, "show_controls"),
PlayPause => write!(f, "play_pause"),
RateDown => write!(f, "rate_down"),
RateUp => write!(f, "rate_up"),
Expand Down
8 changes: 0 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ mod clean_text;
use crate::clean_text::*;

mod on_screen_control;
use crate::on_screen_control::*;

struct State {
voice: Box<SpVoice>,
settings: Box<SettingsWindow>,
controls: Box<OnScreenControlWindow>,
hk: Vec<HotKey>,
}

Expand Down Expand Up @@ -85,10 +83,6 @@ impl State {
self.settings.show_window();
}

fn show_controls(&mut self) {
self.controls.show_window();
}

fn toggle_window_visible(&mut self) {
self.voice.toggle_window_visible();
}
Expand All @@ -114,7 +108,6 @@ impl State {
Close => close(),
ReloadSettings => self.reload_settings(),
ShowSettings => self.show_settings(),
ShowControls => self.show_controls(),
ToggleWindowVisible => self.toggle_window_visible(),
PlayPause => self.play_pause(),
RateDown => self.rate_change(-1),
Expand Down Expand Up @@ -178,7 +171,6 @@ fn main() {
let mut state = State {
voice,
settings: SettingsWindow::new(settings, voices),
controls: OnScreenControlWindow::new(),
hk,
};

Expand Down
4 changes: 2 additions & 2 deletions src/on_screen_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ impl OnScreenControlWindow {
out
}

pub fn show_window(&self) -> bool {
show_window(self.window, wm::SW_SHOW)
pub fn toggle_controls_visible(&self) -> bool {
toggle_window_visible(self.window)
}
}

Expand Down
25 changes: 18 additions & 7 deletions src/sapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use std::ops::Range;
use std::ptr::null_mut;
use std::time::Instant;

use crate::on_screen_control::*;
use crate::window::*;

pub const WM_SAPI_EVENT: u32 = wm::WM_APP + 15;
Expand Down Expand Up @@ -50,9 +51,11 @@ pub struct SpVoice {
// https://msdn.microsoft.com/en-us/library/ms723602.aspx
voice: Speech::ISpVoice,
window: HWND,
controls: Box<OnScreenControlWindow>,
edit: HWND,
rate: HWND,
reload_settings: HWND,
show_controls: HWND,
nicon: Shell::NOTIFYICONDATAW,
last_read: WideString,
last_update: Option<(Instant, Range<usize>)>,
Expand All @@ -68,9 +71,11 @@ impl SpVoice {
voice: syscom::CoCreateInstance(&Speech::SpVoice, None, syscom::CLSCTX_ALL)
.expect("failed for SpVoice at CoCreateInstance"),
window: HWND(0),
controls: OnScreenControlWindow::new(),
edit: HWND(0),
rate: HWND(0),
reload_settings: HWND(0),
show_controls: HWND(0),
nicon: zeroed(),
last_read: WideString::new(),
last_update: None,
Expand Down Expand Up @@ -139,6 +144,7 @@ impl SpVoice {
);
out.rate = create_static_window(out.window, None);
out.reload_settings = create_button_window(out.window, w!("Show Settings"));
out.show_controls = create_button_window(out.window, w!("Show Controls"));
move_window(
out.window,
&RECT {
Expand Down Expand Up @@ -458,8 +464,10 @@ impl Windowed for SpVoice {
if (w_param.0 <= 2) && rect.right > 0 && rect.bottom > 0 {
let (up, down) = rect.inset(3).split_rows(25);
move_window(self.edit, &down.inset(3));
let (left, right) = up.split_columns(120);
move_window(self.reload_settings, &left.inset(3));
let (left, right) = up.split_columns(240);
let (left_button, right_button) = left.split_columns(120);
move_window(self.reload_settings, &left_button.inset(3));
move_window(self.show_controls, &right_button.inset(3));
unsafe {
Gdi::InvalidateRect(self.rate, None, true);
}
Expand All @@ -476,11 +484,14 @@ impl Windowed for SpVoice {
wm::WM_COMMAND => {
use crate::press_hotkey;
use crate::Action;
if self.reload_settings.0 == l_param.0
&& ((w_param.0 >> 16) & 0xffff) as u32 == wm::BN_CLICKED
{
press_hotkey(Action::ShowSettings);
return Some(LRESULT(0));
if ((w_param.0 >> 16) & 0xffff) as u32 == wm::BN_CLICKED {
if self.reload_settings.0 == l_param.0 {
press_hotkey(Action::ShowSettings);
return Some(LRESULT(0));
} else if self.show_controls.0 == l_param.0 {
self.controls.toggle_controls_visible();
return Some(LRESULT(0));
}
}
}
WM_APP_NOTIFICATION_ICON => {
Expand Down
13 changes: 5 additions & 8 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ use windows::Win32::{
Graphics::Gdi,
System::LibraryLoader,
UI::Controls,
UI::Input::KeyboardAndMouse::{
VK_ESCAPE, VK_OEM_2, VK_OEM_COMMA, VK_OEM_MINUS, VK_OEM_PERIOD, VK_OEM_PLUS,
},
UI::Input::KeyboardAndMouse::{VK_ESCAPE, VK_OEM_2, VK_OEM_MINUS, VK_OEM_PERIOD, VK_OEM_PLUS},
UI::WindowsAndMessaging as wm,
};

Expand All @@ -31,7 +29,7 @@ pub const TBM_GETPOS: u32 = Controls::TBM_SETPOS - 5;
pub struct Settings {
pub rate: i32,
pub voice: String,
pub hotkeys: [(u32, u32); 9],
pub hotkeys: [(u32, u32); 8],
pub cleaners: Vec<RegexCleanerPair>,
#[serde(default)]
pub time_estimater: [Variance; 21],
Expand All @@ -43,7 +41,7 @@ pub struct SettingsWindow {
window: HWND,
rate: (HWND, HWND),
voice: (HWND, HWND),
hotkeys: [(HWND, HWND); 9],
hotkeys: [(HWND, HWND); 8],
cleaners: Vec<(Option<bool>, HWND, HWND, HWND, HWND)>,
add_cleaner: HWND,
reset: HWND,
Expand All @@ -58,7 +56,7 @@ impl SettingsWindow {
window: HWND(0),
rate: (HWND(0), HWND(0)),
voice: (HWND(0), HWND(0)),
hotkeys: [(HWND(0), HWND(0)); 9],
hotkeys: [(HWND(0), HWND(0)); 8],
cleaners: Vec::new(),
add_cleaner: HWND(0),
reset: HWND(0),
Expand Down Expand Up @@ -313,7 +311,7 @@ impl SettingsWindow {
WideString::from_raw(buf).as_string()
}

pub fn get_inner_hotkeys(&self) -> [(u32, u32); 9] {
pub fn get_inner_hotkeys(&self) -> [(u32, u32); 8] {
for (&(a, b), hwnd) in self.settings.hotkeys.iter().zip(self.hotkeys.iter()) {
unsafe {
wm::SendMessageW(
Expand Down Expand Up @@ -594,7 +592,6 @@ impl Settings {
(7, 0x52 as u32), // ctrl-alt-shift-r
(7, 0x53 as u32), // ctrl-alt-shift-s
(3, VK_OEM_2.0.into()), // ctrl-alt-?
(3, VK_OEM_COMMA.0.into()), // ctrl-alt-,
(2, VK_OEM_PERIOD.0.into()), // ctrl-.
(3, VK_OEM_MINUS.0.into()), // ctrl-alt--
(3, VK_OEM_PLUS.0.into()), // ctrl-alt-=
Expand Down

0 comments on commit dd71aa2

Please sign in to comment.