From 00d66f97123706d8baf381ffcf7112065bc2a7a5 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Wed, 6 Jan 2021 13:16:13 -0600 Subject: [PATCH] draw 2 rectangles to prevent the white rectangle from being invisible on white backgrounds --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/gui.rs | 28 ++++++++++++++++++++++++---- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 23cce7c..e96f72f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -250,7 +250,7 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "leanshot" -version = "0.4.0-rc" +version = "0.4.0" dependencies = [ "anyhow", "image", diff --git a/Cargo.toml b/Cargo.toml index 5881e40..2a0db11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "leanshot" description = "Screenshot capture for Linux." -version = "0.4.0-rc" +version = "0.4.0" repository = "https://git.mzhang.io/michael/leanshot" license-file = "LICENSE" edition = "2018" diff --git a/src/gui.rs b/src/gui.rs index 637a817..ba93410 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -140,7 +140,7 @@ impl Gui { &[ (xcb::GC_FOREGROUND, screen.white_pixel()), (xcb::GC_BACKGROUND, screen.white_pixel()), - (xcb::GC_LINE_WIDTH, 3), + (xcb::GC_LINE_WIDTH, 1), ], ); @@ -175,18 +175,38 @@ impl Gui { let mut state = State::default(); let mut cancelled = false; - let redraw = |state: &State| { + let redraw = |state: &State| -> Result<()> { xcb_image::put(&self.conn, window_id, window_gc, &image.image, 0, 0); if state.dragging { let rect = state.rect(); + xproto::change_gc( + &self.conn, + window_gc, + &[(xcb::GC_FOREGROUND, screen.black_pixel())], + ); xproto::poly_rectangle(&self.conn, window_id, window_gc, &[rect]); + + let rect2 = Rectangle::new( + rect.x() + 1, + rect.y() + 1, + rect.width() - 2, + rect.height() - 2, + ); + xproto::change_gc( + &self.conn, + window_gc, + &[(xcb::GC_FOREGROUND, screen.white_pixel())], + ); + xproto::poly_rectangle(&self.conn, window_id, window_gc, &[rect2]); } self.conn.flush(); + + Ok(()) }; - redraw(&state); + redraw(&state)?; while let Some(evt) = self.conn.wait_for_event() { match evt.response_type() { @@ -234,7 +254,7 @@ impl Gui { } } - redraw(&state); + redraw(&state)?; } info!("Loop exited, cleaning up...");