print glutin events if --print-events is passed
When debugging many issues, it's often very helpful to have the raw glutin events printed out to stderr as they come in. This does that. Note that since `glutin::Event` doesn't implement `Display`, we just use rust's debugging output for now via `{:?}`.
This commit is contained in:
parent
9e713189cc
commit
d7a5981048
|
@ -16,6 +16,7 @@ use index::{Line, Column};
|
||||||
|
|
||||||
/// Options specified on the command line
|
/// Options specified on the command line
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
|
pub print_events: bool,
|
||||||
pub ref_test: bool,
|
pub ref_test: bool,
|
||||||
pub columns: Column,
|
pub columns: Column,
|
||||||
pub lines: Line,
|
pub lines: Line,
|
||||||
|
@ -25,6 +26,7 @@ pub struct Options {
|
||||||
impl Default for Options {
|
impl Default for Options {
|
||||||
fn default() -> Options {
|
fn default() -> Options {
|
||||||
Options {
|
Options {
|
||||||
|
print_events: false,
|
||||||
ref_test: false,
|
ref_test: false,
|
||||||
columns: Column(80),
|
columns: Column(80),
|
||||||
lines: Line(24),
|
lines: Line(24),
|
||||||
|
@ -43,6 +45,7 @@ impl Options {
|
||||||
match &arg[..] {
|
match &arg[..] {
|
||||||
// Generate ref test
|
// Generate ref test
|
||||||
"--ref-test" => options.ref_test = true,
|
"--ref-test" => options.ref_test = true,
|
||||||
|
"--print-events" => options.print_events = true,
|
||||||
// Set dimensions
|
// Set dimensions
|
||||||
"-d" | "--dimensions" => {
|
"-d" | "--dimensions" => {
|
||||||
args_iter.next()
|
args_iter.next()
|
||||||
|
|
|
@ -9,6 +9,7 @@ use parking_lot::MutexGuard;
|
||||||
use glutin::{self, ElementState};
|
use glutin::{self, ElementState};
|
||||||
|
|
||||||
use config::Config;
|
use config::Config;
|
||||||
|
use cli::Options;
|
||||||
use display::OnResize;
|
use display::OnResize;
|
||||||
use index::{Line, Column, Side};
|
use index::{Line, Column, Side};
|
||||||
use input::{self, ActionContext, MouseBinding, KeyBinding};
|
use input::{self, ActionContext, MouseBinding, KeyBinding};
|
||||||
|
@ -58,6 +59,7 @@ impl Default for Mouse {
|
||||||
pub struct Processor<N> {
|
pub struct Processor<N> {
|
||||||
key_bindings: Vec<KeyBinding>,
|
key_bindings: Vec<KeyBinding>,
|
||||||
mouse_bindings: Vec<MouseBinding>,
|
mouse_bindings: Vec<MouseBinding>,
|
||||||
|
print_events: bool,
|
||||||
notifier: N,
|
notifier: N,
|
||||||
mouse: Mouse,
|
mouse: Mouse,
|
||||||
resize_tx: mpsc::Sender<(u32, u32)>,
|
resize_tx: mpsc::Sender<(u32, u32)>,
|
||||||
|
@ -83,6 +85,7 @@ impl<N: Notify> Processor<N> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
notifier: N,
|
notifier: N,
|
||||||
resize_tx: mpsc::Sender<(u32, u32)>,
|
resize_tx: mpsc::Sender<(u32, u32)>,
|
||||||
|
options: &Options,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
ref_test: bool,
|
ref_test: bool,
|
||||||
size_info: SizeInfo,
|
size_info: SizeInfo,
|
||||||
|
@ -90,6 +93,7 @@ impl<N: Notify> Processor<N> {
|
||||||
Processor {
|
Processor {
|
||||||
key_bindings: config.key_bindings().to_vec(),
|
key_bindings: config.key_bindings().to_vec(),
|
||||||
mouse_bindings: config.mouse_bindings().to_vec(),
|
mouse_bindings: config.mouse_bindings().to_vec(),
|
||||||
|
print_events: options.print_events,
|
||||||
notifier: notifier,
|
notifier: notifier,
|
||||||
resize_tx: resize_tx,
|
resize_tx: resize_tx,
|
||||||
ref_test: ref_test,
|
ref_test: ref_test,
|
||||||
|
@ -184,6 +188,9 @@ impl<N: Notify> Processor<N> {
|
||||||
// Convenience macro which curries most arguments to handle_event.
|
// Convenience macro which curries most arguments to handle_event.
|
||||||
macro_rules! process {
|
macro_rules! process {
|
||||||
($event:expr) => {
|
($event:expr) => {
|
||||||
|
if self.print_events {
|
||||||
|
err_println!("glutin event: {:?}", $event);
|
||||||
|
}
|
||||||
Processor::handle_event(
|
Processor::handle_event(
|
||||||
&mut processor,
|
&mut processor,
|
||||||
$event,
|
$event,
|
||||||
|
|
|
@ -118,6 +118,7 @@ fn run(mut config: Config, options: cli::Options) -> Result<(), Box<Error>> {
|
||||||
let mut processor = event::Processor::new(
|
let mut processor = event::Processor::new(
|
||||||
event_loop::Notifier(loop_tx),
|
event_loop::Notifier(loop_tx),
|
||||||
display.resize_channel(),
|
display.resize_channel(),
|
||||||
|
&options,
|
||||||
&config,
|
&config,
|
||||||
options.ref_test,
|
options.ref_test,
|
||||||
display.size().to_owned(),
|
display.size().to_owned(),
|
||||||
|
|
Loading…
Reference in New Issue