Merge pull request #71 from federico-terzi/dev

Version 0.2.4
This commit is contained in:
Federico Terzi 2019-10-04 22:22:35 +02:00 committed by GitHub
commit 7d3a01784b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 49 deletions

2
Cargo.lock generated
View File

@ -329,7 +329,7 @@ dependencies = [
[[package]]
name = "espanso"
version = "0.2.3"
version = "0.2.4"
dependencies = [
"backtrace 0.3.37 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -1,6 +1,6 @@
[package]
name = "espanso"
version = "0.2.3"
version = "0.2.4"
authors = ["Federico Terzi <federicoterzi96@gmail.com>"]
license = "GPL-3.0"
description = "Cross-platform Text Expander written in Rust"

View File

@ -5,5 +5,6 @@ steps:
tar czf "espanso-linux.tar.gz" espanso
cd ../..
cp target/release/espanso-*.gz .
sha256sum espanso-*.gz | awk '{ print $1 }' > espanso-linux-sha256.txt
ls -la
displayName: "Cargo build and packaging for Linux"

View File

@ -291,83 +291,96 @@ char *xwm_get_win_title(Display *disp, Window win)
}
int32_t get_active_window_name(char * buffer, int32_t size) {
Display *disp = XOpenDisplay(NULL);
xdo_t * x = xdo_new(NULL);
if (!disp) {
if (!x) {
return -1;
}
// Get the active window
Window win;
int revert_to_return;
XGetInputFocus(disp, &win, &revert_to_return);
int ret = xdo_get_active_window(x, &win);
int result = 1;
if (ret) {
fprintf(stderr, "xdo_get_active_window reported an error\n");
result = -2;
}else{
char * title = xwm_get_win_title(x->xdpy, win);
char * title = xwm_get_win_title(disp, win);
snprintf(buffer, size, "%s", title);
snprintf(buffer, size, "%s", title);
XFree(title);
}
XFree(title);
xdo_free(x);
XCloseDisplay(disp);
return 1;
return result;
}
int32_t get_active_window_class(char * buffer, int32_t size) {
Display *disp = XOpenDisplay(NULL);
xdo_t * x = xdo_new(NULL);
if (!disp) {
if (!x) {
return -1;
}
// Get the active window
Window win;
int revert_to_return;
XGetInputFocus(disp, &win, &revert_to_return);
int ret = xdo_get_active_window(x, &win);
int result = 1;
if (ret) {
fprintf(stderr, "xdo_get_active_window reported an error\n");
result = -2;
}else{
XClassHint hint;
XClassHint hint;
if (XGetClassHint(disp, win, &hint)) {
snprintf(buffer, size, "%s", hint.res_class);
XFree(hint.res_name);
XFree(hint.res_class);
if (XGetClassHint(x->xdpy, win, &hint)) {
snprintf(buffer, size, "%s", hint.res_class);
XFree(hint.res_name);
XFree(hint.res_class);
}
}
XCloseDisplay(disp);
xdo_free(x);
return 1;
return result;
}
int32_t get_active_window_executable(char *buffer, int32_t size) {
Display *disp = XOpenDisplay(NULL);
xdo_t * x = xdo_new(NULL);
if (!disp) {
if (!x) {
return -1;
}
// Get the active window
Window win;
int revert_to_return;
XGetInputFocus(disp, &win, &revert_to_return);
int ret = xdo_get_active_window(x, &win);
int result = 1;
if (ret) {
fprintf(stderr, "xdo_get_active_window reported an error\n");
result = -2;
}else{
// Get the window process PID
char *pid_raw = (char*)get_property(x->xdpy,win, XA_CARDINAL, "_NET_WM_PID", NULL);
if (pid_raw == NULL) {
result = -3;
}else{
int pid = pid_raw[0] | pid_raw[1] << 8 | pid_raw[2] << 16 | pid_raw[3] << 24;
// Get the window process PID
char *pid_raw = (char*)get_property(disp,win, XA_CARDINAL, "_NET_WM_PID", NULL);
if (pid_raw == NULL) {
return -2;
// Get the executable path from it
char proc_path[250];
snprintf(proc_path, 250, "/proc/%d/exe", pid);
readlink(proc_path, buffer, size);
XFree(pid_raw);
}
}
int pid = pid_raw[0] | pid_raw[1] << 8 | pid_raw[2] << 16 | pid_raw[3] << 24;
xdo_free(x);
// Get the executable path from it
char proc_path[250];
snprintf(proc_path, 250, "/proc/%d/exe", pid);
readlink(proc_path, buffer, size);
XFree(pid_raw);
XCloseDisplay(disp);
return 1;
return result;
}
int32_t is_current_window_terminal() {

View File

@ -72,6 +72,11 @@ fn main() {
.arg(Arg::with_name("package_name")
.help("Package name"));
let uninstall_subcommand = SubCommand::with_name("uninstall")
.about("Remove an installed package. Equivalent to 'espanso package uninstall'")
.arg(Arg::with_name("package_name")
.help("Package name"));
let mut clap_instance = App::new("espanso")
.version(VERSION)
.author("Federico Terzi")
@ -122,19 +127,18 @@ fn main() {
.subcommand(SubCommand::with_name("package")
.about("Espanso package manager commands")
.subcommand(install_subcommand.clone())
.subcommand(uninstall_subcommand.clone())
.subcommand(SubCommand::with_name("list")
.about("List all installed packages")
.arg(Arg::with_name("full")
.help("Print all package info")
.long("full")))
.subcommand(SubCommand::with_name("remove")
.about("Remove an installed package")
.arg(Arg::with_name("package_name")
.help("Package name")))
.subcommand(SubCommand::with_name("refresh")
.about("Update espanso package index"))
)
.subcommand(install_subcommand);
.subcommand(install_subcommand)
.subcommand(uninstall_subcommand);
let matches = clap_instance.clone().get_matches();
@ -223,12 +227,17 @@ fn main() {
return;
}
if let Some(matches) = matches.subcommand_matches("uninstall") {
remove_package_main(config_set, matches);
return;
}
if let Some(matches) = matches.subcommand_matches("package") {
if let Some(matches) = matches.subcommand_matches("install") {
install_main(config_set, matches);
return;
}
if let Some(matches) = matches.subcommand_matches("remove") {
if let Some(matches) = matches.subcommand_matches("uninstall") {
remove_package_main(config_set, matches);
return;
}