Im currently writting my own terminal emulator for fun and im currently in the work of implementing utf-8 input support, for this i need to use Xutf8LookupString()
, this function requires that i use XCreateIC
to create a input context.
The problem is that XCreateIC returns a null pointer when i pass the same arguments as in x.c - st - simple terminal (except XNDestroyCallback which shouldnt matter).
this happends either when "A required argument was not set", "A read-only argument was set", "The argument name is not recognized" or "The input method encountered an input method implementation-dependent error" but i cant seem find any of these problems in my code.
I found a similar issue here but it doesnt seem to fix any of my issues.
Example code bellow:
pub fn open() -> Result<Display, Box<dyn std::error::Error>> {
let dpy = unsafe { xlib::XOpenDisplay(ptr::null()) };
if dpy.is_null() {
Err("failed to open display".into())
} else {
unsafe {
let bg = Color::new(0, 0, 0).encode();
let window = xlib::XCreateSimpleWindow(
dpy,
xlib::XDefaultRootWindow(dpy),
0,
0,
500,
500,
0,
bg,
bg
);
let screen = xlib::XDefaultScreen(dpy);
let mut values: xlib::XGCValues = mem::zeroed();
let gc = xlib::XCreateGC(dpy, window, 0, &mut values);
let back_buffer = xlib::XCreatePixmap(dpy, window, 945, 1020, 24);
let draw = xft::XftDrawCreate(dpy, back_buffer, xlib::XDefaultVisual(dpy, screen), xlib::XDefaultColormap(dpy, screen));
xlib::XSetLocaleModifiers("\0".as_ptr() as *const i8);
let xim = xlib::XOpenIM(dpy, 0 as xlib::XrmDatabase, 0 as *mut ffi::c_char, 0 as *mut ffi::c_char);
println!("xim: {:?}", xim);
let xn_input_style = ffi::CString::new(xlib::XNInputStyle)?;
let xn_client_window = ffi::CString::new(xlib::XNClientWindow)?;
let xic = xlib::XCreateIC(
xim,
xn_input_style.as_ptr(), xlib::XIMPreeditNone | xlib::XIMStatusNothing,
xn_client_window.as_ptr(), window as ffi::c_ulong,
ptr::null_mut::<ffi::c_void>()
);
println!("xic: {:?}", xic);
xlib::XSync(dpy, xlib::False);
Ok(Display {
dpy,
gc,
xim,
xic,
draw,
back_buffer,
window,
screen,
})
}
}
}