diff --git a/src/ui/painter.rs b/src/ui/painter.rs index 8f7f4d0..436bb9f 100644 --- a/src/ui/painter.rs +++ b/src/ui/painter.rs @@ -79,7 +79,7 @@ impl<'a> Painter<'a> { // draw text ctx.move_to(x + 0.2, y); - ctx.theme_text(&input, false, &[], &self.theme); + ctx.theme_text(&input, false, &[], 800, &self.theme); } pub fn result_box( @@ -109,15 +109,15 @@ impl<'a> Painter<'a> { // draw text //source ctx.move_to(x + 0.2, y); - ctx.theme_text(&source, selected, &[], &self.theme); + ctx.theme_text(&source, selected, &[], 200, &self.theme); // category ctx.move_to(x + 3.5, y); - ctx.theme_text(result[0], selected, indices, &self.theme); + ctx.theme_text(result[0], selected, indices, 200, &self.theme); // title - ctx.move_to(x + 3.5 + 10.0, y); - ctx.theme_text(result[1], selected, indices, &self.theme); + ctx.move_to(x + 3.5 + 8.0, y); + ctx.theme_text(result[1], selected, indices, 500, &self.theme); } pub fn divider(&self, x: T, y: T) diff --git a/src/ui/theme.rs b/src/ui/theme.rs index 14ca444..8242b3c 100644 --- a/src/ui/theme.rs +++ b/src/ui/theme.rs @@ -61,7 +61,7 @@ pub trait ThemedContextExt { fn theme_border(&self, theme: &Theme); fn theme_divider(&self, theme: &Theme); - fn theme_text(&self, text: &str, selected: bool, indices: &[usize], theme: &Theme); + fn theme_text(&self, text: &str, selected: bool, indices: &[usize], width: i32, theme: &Theme); fn device_to_user_point(&self, point: f64) -> f64; } @@ -94,7 +94,7 @@ impl ThemedContextExt for cairo::Context { self.set_source_rgba(r, g, b, a); } - fn theme_text(&self, text: &str, selected: bool, indices: &[usize], theme: &Theme) { + fn theme_text(&self, text: &str, selected: bool, indices: &[usize], width: i32, theme: &Theme) { self.save().unwrap(); self.identity_matrix(); // this is extremely important otherwise pango @@ -126,7 +126,7 @@ impl ThemedContextExt for cairo::Context { font.set_size(theme.font.1 * pango::SCALE); layout.set_font_description(Some(&font)); - layout.set_width(200 * pango::SCALE); + layout.set_width(width * pango::SCALE); layout.set_spacing(0); layout.set_ellipsize(EllipsizeMode::End); diff --git a/src/window.rs b/src/window.rs index 0c7f369..5731e6a 100644 --- a/src/window.rs +++ b/src/window.rs @@ -13,9 +13,11 @@ //! directly interact with the underlying windowing framework for fine-tuning. use std::mem; +use std::time::Duration; use anyhow::{anyhow, Result}; use log::{debug, trace}; +use nix::sys; use winit::event_loop::EventLoop; use winit::platform::unix::{WindowBuilderExtUnix, WindowExtUnix}; use winit::window::{Window, WindowBuilder}; @@ -118,15 +120,29 @@ fn postprocess_window(window: &Window) -> Result<()> { trace! {"Map window"} xcb_con.send_and_check_request(&xcb::x::MapWindow { window: xcb_window })?; + xcb_con.flush()?; + trace! {"Grab keyboard"} - let req = xcb::x::GrabKeyboard { - owner_events: true, - grab_window: xcb_window, - time: xcb::x::CURRENT_TIME, - pointer_mode: GrabMode::Async, - keyboard_mode: GrabMode::Async, - }; - xcb_con.send_request(&req); + let mut retries = 0; + let mut grabbed = false; + while !grabbed && retries < 100 { + let cookie = xcb_con.send_request(&xcb::x::GrabKeyboard { + owner_events: true, + grab_window: xcb_window, + time: xcb::x::CURRENT_TIME, + pointer_mode: GrabMode::Async, + keyboard_mode: GrabMode::Async, + }); + + let reply: xcb::x::GrabKeyboardReply = xcb_con.wait_for_reply(cookie)?; + + if reply.status() != xcb::x::GrabStatus::Success { + retries += 1; + std::thread::sleep(Duration::from_millis(5)); + } else { + grabbed = true; + } + } xcb_con.flush()?; Ok(())