Add troubleshooting messages for X11

pull/39/head
Takashi Kokubun 2 years ago
parent 4b0e3ceb36
commit a6be4f00bd
No known key found for this signature in database
GPG Key ID: 6FFC433B12EE23DD

@ -1 +1,2 @@
max_width = 120 max_width = 120
fn_call_width = 100

@ -1,5 +1,5 @@
use zbus::Connection;
use crate::client::Client; use crate::client::Client;
use zbus::Connection;
pub struct GnomeClient { pub struct GnomeClient {
connection: Option<Connection>, connection: Option<Connection>,
@ -7,9 +7,7 @@ pub struct GnomeClient {
impl GnomeClient { impl GnomeClient {
pub fn new() -> GnomeClient { pub fn new() -> GnomeClient {
GnomeClient { GnomeClient { connection: None }
connection: None,
}
} }
fn connect(&mut self) { fn connect(&mut self) {
@ -48,7 +46,7 @@ impl Client for GnomeClient {
) { ) {
if let Ok((_actor, json)) = message.body::<(bool, String)>() { if let Ok((_actor, json)) = message.body::<(bool, String)>() {
if let Ok(wm_class) = serde_json::from_str::<String>(&json) { if let Ok(wm_class) = serde_json::from_str::<String>(&json) {
return Some(wm_class) return Some(wm_class);
} }
} }
} }

@ -24,14 +24,10 @@ impl WMClient {
if let None = self.supported { if let None = self.supported {
let supported = self.client.supported(); let supported = self.client.supported();
self.supported = Some(supported); self.supported = Some(supported);
println!( println!("application-client: {} (supported: {})", self.name, supported);
"application-client: {} (supported: {})",
self.name,
supported
);
} }
if !self.supported.unwrap() { if !self.supported.unwrap() {
return None return None;
} }
let result = self.client.current_application(); let result = self.client.current_application();

@ -10,9 +10,7 @@ pub struct SwayClient {
impl SwayClient { impl SwayClient {
pub fn new() -> SwayClient { pub fn new() -> SwayClient {
SwayClient { SwayClient { connection: None }
connection: None,
}
} }
fn connect(&mut self) { fn connect(&mut self) {

@ -1,4 +1,5 @@
use crate::client::Client; use crate::client::Client;
use std::env;
use x11_rs::xlib; use x11_rs::xlib;
pub struct X11Client { pub struct X11Client {
@ -7,16 +8,25 @@ pub struct X11Client {
impl X11Client { impl X11Client {
pub fn new() -> X11Client { pub fn new() -> X11Client {
X11Client { X11Client { display: None }
display: None,
}
} }
fn connect(&mut self) -> *mut xlib::Display { fn connect(&mut self) -> *mut xlib::Display {
match self.display { match self.display {
Some(display) => display, Some(display) => display,
None => { None => {
if let Err(env::VarError::NotPresent) = env::var("DISPLAY") {
println!("$DISPLAY is not set. Defaulting to DISPLAY=:0");
env::set_var("DISPLAY", ":0");
}
let display = unsafe { xlib::XOpenDisplay(std::ptr::null()) }; let display = unsafe { xlib::XOpenDisplay(std::ptr::null()) };
if display.is_null() {
let var = env::var("DISPLAY").unwrap();
println!("warning: Failed to connect to X11.");
println!("If you saw \"No protocol specified\", try running `xhost +SI:localuser:root`.");
println!("If not, make sure `echo $DISPLAY` outputs xremap's $DISPLAY ({}).", var);
}
self.display = Some(display); self.display = Some(display);
display display
} }
@ -77,14 +87,7 @@ impl Client for X11Client {
let mut parent: xlib::Window = 0; let mut parent: xlib::Window = 0;
let mut children: *mut xlib::Window = &mut 0; let mut children: *mut xlib::Window = &mut 0;
unsafe { unsafe {
if xlib::XQueryTree( if xlib::XQueryTree(display, focused_window, &mut root, &mut parent, &mut children, &mut nchildren) == 0
display,
focused_window,
&mut root,
&mut parent,
&mut children,
&mut nchildren,
) == 0
{ {
break; break;
} }

@ -140,7 +140,8 @@ fn is_keyboard(device: &Device) -> bool {
keys.contains(Key::KEY_SPACE) keys.contains(Key::KEY_SPACE)
&& keys.contains(Key::KEY_A) && keys.contains(Key::KEY_A)
&& keys.contains(Key::KEY_Z) && keys.contains(Key::KEY_Z)
&& !keys.contains(Key::BTN_LEFT) // BTN_MOUSE // BTN_MOUSE
&& !keys.contains(Key::BTN_LEFT)
} }
None => false, None => false,
} }

Loading…
Cancel
Save