Skip to content

Commit

Permalink
Set numlock_mask in XcbConnection::new
Browse files Browse the repository at this point in the history
- Removed set_numlock_mask
- Updated all examples
  • Loading branch information
Danacus committed Sep 15, 2020
1 parent 0765b69 commit 750ac7f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/draw/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn bar_draw() -> Result<()> {
)?;

let config = Config::default();
let conn = XcbConnection::new().unwrap();
let conn = XcbConnection::new(None).unwrap();
let mut wm = WindowManager::init(config, &conn);
bar.startup(&mut wm); // ensure widgets are initialised correctly

Expand Down
4 changes: 3 additions & 1 deletion examples/dynamic_workspaces/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use penrose::contrib::actions::create_or_switch_to_workspace;
use penrose::contrib::extensions::Scratchpad;
use penrose::contrib::hooks::{DefaultWorkspace, LayoutSymbolAsRootName, RemoveEmptyWorkspaces};
use penrose::contrib::layouts::paper;
use penrose::helpers::modifiers_from_xmodmap;

use simplelog::{LevelFilter, SimpleLogger};
use std::env;
Expand Down Expand Up @@ -97,7 +98,8 @@ fn main() {
}
};

let conn = XcbConnection::new().unwrap();
let modifier_map = modifiers_from_xmodmap();
let conn = XcbConnection::new(modifier_map.get("Num_Lock").map(|m| *m)).unwrap();
let mut wm = WindowManager::init(config, &conn);
wm.grab_keys_and_run(key_bindings);
}
2 changes: 1 addition & 1 deletion examples/minimal/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn main() {
}
};

let conn = XcbConnection::new().unwrap();
let conn = XcbConnection::new(None).unwrap();
let mut wm = WindowManager::init(config, &conn);
wm.grab_keys_and_run(key_bindings);
}
10 changes: 3 additions & 7 deletions examples/simple_config_with_hooks/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,13 @@ fn main() {
}
};

let modifier_map = modifiers_from_xmodmap();

// The underlying connection to the X server is handled as a trait: XConn. XcbConnection is the
// reference implementation of this trait that uses the XCB library to communicate with the X
// server. You are free to provide your own implementation if you wish, see xconnection.rs for
// details of the required methods and expected behaviour.
let mut conn = XcbConnection::new().unwrap();

let modifier_map = modifiers_from_xmodmap();

if let Some(&numlock_mask) = modifier_map.get("Num_Lock") {
conn.set_numlock_mask(numlock_mask);
}
let conn = XcbConnection::new(modifier_map.get("Num_Lock").map(|m| *m)).unwrap();

// Create the WindowManager instance with the config we have built and a connection to the X
// server. Before calling grab_keys_and_run, it is possible to run additional start-up actions
Expand Down
9 changes: 2 additions & 7 deletions src/core/xconnection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ pub struct XcbConnection {

impl XcbConnection {
/// Establish a new connection to the running X server. Fails if unable to connect
pub fn new() -> Result<XcbConnection> {
pub fn new(numlock_mask: Option<u16>) -> Result<XcbConnection> {
let (conn, _) = match xcb::Connection::connect(None) {
Err(e) => return Err(anyhow!("unable to establish connection to X server: {}", e)),
Ok(conn) => conn,
Expand Down Expand Up @@ -528,15 +528,10 @@ impl XcbConnection {
atoms,
auto_float_types,
randr_base,
numlock_mask: None,
numlock_mask,
})
}

/// Set the numlock mask, allowing it to be ignored
pub fn set_numlock_mask(&mut self, mask: u16) {
self.numlock_mask = Some(mask);
}

// Return the cached atom if it's one we know, falling back to interning the atom if we need to.
fn atom(&self, name: &str) -> Result<u32> {
Ok(match self.atoms.get(name) {
Expand Down

0 comments on commit 750ac7f

Please sign in to comment.