diff --git a/README.md b/README.md index 2b36e04..97248e2 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,10 @@ The `-P` or `--preview-size` flag controls the size of the preview in pixels. So that the preview always has a center pixel this number must be odd, if an even number is passed then it will be changed to the next odd number. +## Position + +The `-p` or `--position` flag allows to also print out the position of the cursor. + ## Formatting By default, the color values will be printed in lowercase hexadecimal format. diff --git a/src/cli.rs b/src/cli.rs index 9b38af3..866846f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -52,4 +52,13 @@ pub fn get_cli() -> App<'static, 'static> { .value_name("PREVIEW_SIZE") .help("Size of preview, must be odd (defaults to 255)"), ) + .arg( + Arg::with_name("position") + .short("p") + .long("position") + .required(false) + .takes_value(false) + // .value_name("POSITION") + .help("Should xcolor also print out the position of the pointer"), + ) } diff --git a/src/main.rs b/src/main.rs index 9d2ac51..22c6bae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,6 +59,8 @@ fn run(args: &ArgMatches) -> Result<()> { let use_selection = selection.is_some(); let background = std::env::var("XCOLOR_FOREGROUND").is_err(); + let print_position = args.is_present("position"); + let mut in_parent = true; let (conn, screen) = Connection::connect_with_xlib_display()?; @@ -86,6 +88,10 @@ fn run(args: &ArgMatches) -> Result<()> { set_selection(&conn, root, &selection.unwrap(), &output)?; } } else { + if print_position { + let pos = xcb::xproto::query_pointer(&conn, root).get_reply()?; + println!("position: ({}, {})", pos.root_x(), pos.root_y()); + } println!("{}", output); } }