Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
}
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down Expand Up @@ -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);
}
}
Expand Down