2019-09-07 11:35:45 +00:00
|
|
|
use std::os::raw::c_char;
|
|
|
|
|
2019-09-13 20:57:53 +00:00
|
|
|
use crate::bridge::linux::{get_active_window_name, get_active_window_class, get_active_window_executable};
|
2019-09-07 11:35:45 +00:00
|
|
|
use std::ffi::CStr;
|
|
|
|
|
2019-09-13 20:57:53 +00:00
|
|
|
pub struct LinuxSystemManager {}
|
2019-09-07 11:35:45 +00:00
|
|
|
|
|
|
|
impl super::SystemManager for LinuxSystemManager {
|
|
|
|
fn get_current_window_title(&self) -> Option<String> {
|
|
|
|
unsafe {
|
|
|
|
let mut buffer : [c_char; 100] = [0; 100];
|
|
|
|
let res = get_active_window_name(buffer.as_mut_ptr(), buffer.len() as i32);
|
|
|
|
|
|
|
|
if res > 0 {
|
|
|
|
let c_string = CStr::from_ptr(buffer.as_ptr());
|
|
|
|
|
|
|
|
let string = c_string.to_str();
|
|
|
|
if let Ok(string) = string {
|
|
|
|
return Some((*string).to_owned());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_current_window_class(&self) -> Option<String> {
|
|
|
|
unsafe {
|
|
|
|
let mut buffer : [c_char; 100] = [0; 100];
|
|
|
|
let res = get_active_window_class(buffer.as_mut_ptr(), buffer.len() as i32);
|
|
|
|
|
|
|
|
if res > 0 {
|
|
|
|
let c_string = CStr::from_ptr(buffer.as_ptr());
|
|
|
|
|
|
|
|
let string = c_string.to_str();
|
|
|
|
if let Ok(string) = string {
|
|
|
|
return Some((*string).to_owned());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_current_window_executable(&self) -> Option<String> {
|
2019-09-13 20:57:53 +00:00
|
|
|
unsafe {
|
|
|
|
let mut buffer : [c_char; 100] = [0; 100];
|
|
|
|
let res = get_active_window_executable(buffer.as_mut_ptr(), buffer.len() as i32);
|
|
|
|
|
|
|
|
if res > 0 {
|
|
|
|
let c_string = CStr::from_ptr(buffer.as_ptr());
|
|
|
|
|
|
|
|
let string = c_string.to_str();
|
|
|
|
if let Ok(string) = string {
|
|
|
|
return Some((*string).to_owned());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
2019-09-07 11:35:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl LinuxSystemManager {
|
2019-09-13 20:57:53 +00:00
|
|
|
pub fn new() -> LinuxSystemManager {
|
|
|
|
LinuxSystemManager{}
|
|
|
|
}
|
2019-09-07 11:35:45 +00:00
|
|
|
}
|