Fix bug that prevented espanso from working with Emacs #122

This commit is contained in:
Federico Terzi 2019-12-13 22:05:56 +01:00
parent 284482e2d5
commit db2ff8c6ca
4 changed files with 11 additions and 7 deletions

View File

@ -453,7 +453,7 @@ int32_t get_active_window_executable(char *buffer, int32_t size) {
return result; return result;
} }
int32_t is_current_window_terminal() { int32_t is_current_window_special() {
char class_buffer[250]; char class_buffer[250];
int res = get_active_window_class(class_buffer, 250); int res = get_active_window_class(class_buffer, 250);
if (res > 0) { if (res > 0) {
@ -477,6 +477,8 @@ int32_t is_current_window_terminal() {
return 1; return 1;
}else if (strstr(class_buffer, "Alacritty") != NULL) { // Alacritty terminal }else if (strstr(class_buffer, "Alacritty") != NULL) { // Alacritty terminal
return 1; return 1;
}else if (strstr(class_buffer, "Emacs") != NULL) { // Emacs
return 3;
} }
} }

View File

@ -111,8 +111,8 @@ extern "C" int32_t get_active_window_class(char * buffer, int32_t size);
extern "C" int32_t get_active_window_executable(char * buffer, int32_t size); extern "C" int32_t get_active_window_executable(char * buffer, int32_t size);
/* /*
* Return 1 if the current window is a terminal window, 0 otherwise. * Return a value greater than 0 if the current window needs a special paste combination, 0 otherwise.
*/ */
extern "C" int32_t is_current_window_terminal(); extern "C" int32_t is_current_window_special();
#endif //ESPANSO_BRIDGE_H #endif //ESPANSO_BRIDGE_H

View File

@ -31,7 +31,7 @@ extern {
pub fn get_active_window_name(buffer: *mut c_char, size: i32) -> i32; pub fn get_active_window_name(buffer: *mut c_char, size: i32) -> i32;
pub fn get_active_window_class(buffer: *mut c_char, size: i32) -> i32; pub fn get_active_window_class(buffer: *mut c_char, size: i32) -> i32;
pub fn get_active_window_executable(buffer: *mut c_char, size: i32) -> i32; pub fn get_active_window_executable(buffer: *mut c_char, size: i32) -> i32;
pub fn is_current_window_terminal() -> i32; pub fn is_current_window_special() -> i32;
// Keyboard // Keyboard
pub fn register_keypress_callback(cb: extern fn(_self: *mut c_void, *const u8, pub fn register_keypress_callback(cb: extern fn(_self: *mut c_void, *const u8,

View File

@ -42,14 +42,16 @@ impl super::KeyboardManager for LinuxKeyboardManager {
unsafe { unsafe {
match shortcut { match shortcut {
PasteShortcut::Default => { PasteShortcut::Default => {
let is_terminal = is_current_window_terminal(); let is_special = is_current_window_special();
// Terminals use a different keyboard combination to paste from clipboard, // Terminals use a different keyboard combination to paste from clipboard,
// so we need to check the correct situation. // so we need to check the correct situation.
if is_terminal == 0 { if is_special == 0 {
trigger_paste(); trigger_paste();
}else if is_terminal == 2 { // Special case for stterm }else if is_special == 2 { // Special case for stterm
trigger_alt_shift_ins_paste(); trigger_alt_shift_ins_paste();
}else if is_special == 3 { // Special case for Emacs
trigger_shift_ins_paste();
}else{ }else{
trigger_terminal_paste(); trigger_terminal_paste();
} }