Spam GrabKeyboard requests
This commit is contained in:
parent
c5ca08f556
commit
192aab3012
3 changed files with 32 additions and 16 deletions
|
@ -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<T>(
|
||||
|
@ -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<T>(&self, x: T, y: T)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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(())
|
||||
|
|
Loading…
Reference in a new issue