2019-09-15 16:29:11 +00:00
|
|
|
/*
|
|
|
|
* This file is part of espanso.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Federico Terzi
|
|
|
|
*
|
|
|
|
* espanso is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* espanso is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-09-07 20:23:04 +00:00
|
|
|
use widestring::U16CString;
|
|
|
|
use crate::bridge::windows::*;
|
|
|
|
|
|
|
|
pub struct WindowsSystemManager {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-10 16:23:27 +00:00
|
|
|
impl WindowsSystemManager {
|
|
|
|
pub fn new() -> WindowsSystemManager {
|
|
|
|
WindowsSystemManager{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-07 20:23:04 +00:00
|
|
|
impl super::SystemManager for WindowsSystemManager {
|
|
|
|
fn get_current_window_title(&self) -> Option<String> {
|
|
|
|
unsafe {
|
|
|
|
let mut buffer : [u16; 100] = [0; 100];
|
|
|
|
let res = get_active_window_name(buffer.as_mut_ptr(), buffer.len() as i32);
|
|
|
|
|
|
|
|
if res > 0 {
|
|
|
|
let c_string = U16CString::from_ptr_str(buffer.as_ptr());
|
|
|
|
|
|
|
|
let string = c_string.to_string_lossy();
|
|
|
|
return Some((*string).to_owned());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_current_window_class(&self) -> Option<String> {
|
|
|
|
self.get_current_window_executable()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_current_window_executable(&self) -> Option<String> {
|
|
|
|
unsafe {
|
|
|
|
let mut buffer : [u16; 250] = [0; 250];
|
|
|
|
let res = get_active_window_executable(buffer.as_mut_ptr(), buffer.len() as i32);
|
|
|
|
|
|
|
|
if res > 0 {
|
|
|
|
let c_string = U16CString::from_ptr_str(buffer.as_ptr());
|
|
|
|
|
|
|
|
let string = c_string.to_string_lossy();
|
|
|
|
return Some((*string).to_owned());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|