Add system backend for MacOS
This commit is contained in:
parent
fbd053f67d
commit
90dd708014
|
@ -42,7 +42,19 @@ void send_vkey(int32_t vk);
|
||||||
/*
|
/*
|
||||||
* Send the backspace keypress, *count* times.
|
* Send the backspace keypress, *count* times.
|
||||||
*/
|
*/
|
||||||
extern "C" void delete_string(int32_t count);
|
void delete_string(int32_t count);
|
||||||
|
|
||||||
|
// SYSTEM
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the active NSRunningApplication path
|
||||||
|
*/
|
||||||
|
int32_t get_active_app_bundle(char * buffer, int32_t size);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the active NSRunningApplication bundle identifier
|
||||||
|
*/
|
||||||
|
int32_t get_active_app_identifier(char * buffer, int32_t size);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -97,3 +97,23 @@ void send_vkey(int32_t vk) {
|
||||||
usleep(2000);
|
usleep(2000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t get_active_app_bundle(char * buffer, int32_t size) {
|
||||||
|
NSRunningApplication *frontApp = [[NSWorkspace sharedWorkspace] frontmostApplication];
|
||||||
|
NSString *bundlePath = [frontApp bundleURL].path;
|
||||||
|
const char * path = [bundlePath UTF8String];
|
||||||
|
|
||||||
|
snprintf(buffer, size, "%s", path);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t get_active_app_identifier(char * buffer, int32_t size) {
|
||||||
|
NSRunningApplication *frontApp = [[NSWorkspace sharedWorkspace] frontmostApplication];
|
||||||
|
NSString *bundlePath = frontApp.bundleIdentifier;
|
||||||
|
const char * path = [bundlePath UTF8String];
|
||||||
|
|
||||||
|
snprintf(buffer, size, "%s", path);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
|
@ -3,6 +3,11 @@ use std::os::raw::{c_void, c_char};
|
||||||
#[allow(improper_ctypes)]
|
#[allow(improper_ctypes)]
|
||||||
#[link(name="macbridge", kind="static")]
|
#[link(name="macbridge", kind="static")]
|
||||||
extern {
|
extern {
|
||||||
|
// System
|
||||||
|
pub fn get_active_app_bundle(buffer: *mut c_char, size: i32) -> i32;
|
||||||
|
pub fn get_active_app_identifier(buffer: *mut c_char, size: i32) -> i32;
|
||||||
|
|
||||||
|
// Keyboard
|
||||||
pub fn register_keypress_callback(s: *const c_void,
|
pub fn register_keypress_callback(s: *const c_void,
|
||||||
cb: extern fn(_self: *mut c_void, *const u8,
|
cb: extern fn(_self: *mut c_void, *const u8,
|
||||||
i32, i32, i32));
|
i32, i32, i32));
|
||||||
|
|
|
@ -240,6 +240,24 @@ impl <S: SystemManager> ConfigManager for RuntimeConfigManager<S> {
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let active_calss = self.system_manager.get_current_window_class();
|
||||||
|
|
||||||
|
if let Some(class) = active_calss {
|
||||||
|
debug!("=> Class: '{}'", class);
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
/*for (i, regex) in self.title_regexps.iter().enumerate() {
|
||||||
|
if let Some(regex) = regex {
|
||||||
|
if regex.is_match(&title) {
|
||||||
|
debug!("Matched 'filter_title' for '{}' config, using custom settings.",
|
||||||
|
self.set.specific[i].name);
|
||||||
|
|
||||||
|
return &self.set.specific[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
// No matches, return the default mapping
|
// No matches, return the default mapping
|
||||||
debug!("No matches for custom configs, using default settings.");
|
debug!("No matches for custom configs, using default settings.");
|
||||||
&self.set.default
|
&self.set.default
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::os::raw::c_char;
|
use std::os::raw::c_char;
|
||||||
|
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
|
use crate::bridge::macos::{get_active_app_bundle, get_active_app_identifier};
|
||||||
|
|
||||||
pub struct MacSystemManager {
|
pub struct MacSystemManager {
|
||||||
|
|
||||||
|
@ -8,15 +9,43 @@ pub struct MacSystemManager {
|
||||||
|
|
||||||
impl super::SystemManager for MacSystemManager {
|
impl super::SystemManager for MacSystemManager {
|
||||||
fn get_current_window_title(&self) -> Option<String> {
|
fn get_current_window_title(&self) -> Option<String> {
|
||||||
unimplemented!()
|
self.get_current_window_class()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_current_window_class(&self) -> Option<String> {
|
fn get_current_window_class(&self) -> Option<String> {
|
||||||
unimplemented!();
|
unsafe {
|
||||||
|
let mut buffer : [c_char; 250] = [0; 250];
|
||||||
|
let res = get_active_app_identifier(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> {
|
fn get_current_window_executable(&self) -> Option<String> {
|
||||||
unimplemented!()
|
unsafe {
|
||||||
|
let mut buffer : [c_char; 250] = [0; 250];
|
||||||
|
let res = get_active_app_bundle(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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user