Skip to content

Commit

Permalink
0.4.4
Browse files Browse the repository at this point in the history
fix(linux): Remove decode_text function no longger required and remove dep strip-ansi-escapes
  • Loading branch information
miniben-90 committed Apr 1, 2023
1 parent 69b735c commit 5ca92a4
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 36 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ windows = { version = "0.48.0", features = [

[target.'cfg(target_os = "linux")'.dependencies]
xcb = "1.2"
strip-ansi-escapes = "0.1.1"

[target.'cfg(target_os = "linux")'.dependencies.x11]
version = "2.19.0"
Expand Down
2 changes: 1 addition & 1 deletion npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@miniben90/x-win-darwin-arm64",
"version": "0.4.3",
"version": "0.4.4",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/darwin-universal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@miniben90/x-win-darwin-universal",
"version": "0.4.3",
"version": "0.4.4",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@miniben90/x-win-darwin-x64",
"version": "0.4.3",
"version": "0.4.4",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@miniben90/x-win-linux-x64-gnu",
"version": "0.4.3",
"version": "0.4.4",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/win32-arm64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@miniben90/x-win-win32-arm64-msvc",
"version": "0.4.3",
"version": "0.4.4",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/win32-ia32-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@miniben90/x-win-win32-ia32-msvc",
"version": "0.4.3",
"version": "0.4.4",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@miniben90/x-win-win32-x64-msvc",
"version": "0.4.3",
"version": "0.4.4",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@miniben90/x-win",
"description": "This package allows you to retrieve precise information about active and open windows on Windows, MacOS, and Linux. You can obtain the position, size, title, and other memory of windows.",
"version": "0.4.3",
"version": "0.4.4",
"main": "index.js",
"types": "index.d.ts",
"files": [
Expand Down
28 changes: 1 addition & 27 deletions src/linux/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,31 +243,6 @@ fn get_window_position(conn: &xcb::Connection, window: x::Window) -> WindowPosit
position
}

fn decode_text(bytes: &[u8]) -> String {
let mut result = String::new();
let mut index = 0;
while index < bytes.len() {
let ch = bytes[index];
if ch < 128 {
result.push(ch as char);
index += 1;
} else {
let ch_utf8 = match std::str::from_utf8(&bytes[index..index+3]) {
Ok(ch) => ch.to_string(),
Err(_) => xcb::Lat1String::from_bytes(&bytes[index..index+3]).to_utf8().to_string(),
};

result.push_str(&ch_utf8);
index += 3;
}
}
if let Ok(result) = strip_ansi_escapes::strip(&result) {
return std::str::from_utf8(&result).unwrap().to_string();
} else {
return result;
}
}

/**
* Generate Atom of COMPOUND_TEXT value
*/
Expand Down Expand Up @@ -306,8 +281,7 @@ fn get_window_title(conn: &xcb::Connection, window: x::Window) -> String {
});
if let Ok(window_title) = conn.wait_for_reply(window_title) {
let window_title: &[u8] = window_title.value();
let window_title = decode_text(window_title);
return window_title;
return unsafe { std::str::from_utf8_unchecked(window_title).to_string() };
}
}
}
Expand Down

0 comments on commit 5ca92a4

Please sign in to comment.