Skip to content

Commit

Permalink
char::from is a little nicer, then give up for now
Browse files Browse the repository at this point in the history
  • Loading branch information
ntBre committed Dec 7, 2024
1 parent ec1305a commit e0849a2
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! tiling window manager based on dwm
use std::char::REPLACEMENT_CHARACTER;
use std::cmp::max;
use std::ffi::{c_int, c_uint, c_ulong, CStr};
use std::io::Read;
Expand Down Expand Up @@ -1630,16 +1629,16 @@ fn gettextprop(
// doesn't work for larger characters like ў (cyrillic short u).
// actually `list` doesn't even contain the right characters for the
// short u. it just starts at the space after it, as demonstrated by
// using libc::printf to try to print it
// using libc::printf to try to print it.
//
// Looks like my encoding is different. Getting 238 in Rust vs 287
// in C. Using XGetAtomName shows 238 is UTF8_STRING, while 287 is
// _NET_WM_WINDOW_TYPE_POPUP_MENU (??). In dwm in the VM, 287 is
// also UTF8_STRING
*text = String::new();
let mut c = *list;
while *c != 0 {
text.push(char::from_u32(*c as u8 as u32).unwrap_or_else(
|| {
log::error!("failed to decode {}", *c);
REPLACEMENT_CHARACTER
},
));
text.push(char::from(*c as u8));
c = c.offset(1);
}
xlib::XFreeStringList(list);
Expand Down

0 comments on commit e0849a2

Please sign in to comment.