fix(borders): always validate border client area

This commit pushes up the calls to BeginPaint and EndPaint in the border
callback function to ensure that the client area of the border rect is
always validated after calls to InvalidateRect from the update fn.

The callback now also logs errors whenever it is not possible to get the
border rect to operate on for any reason.

There was a call at the end of this logic to ValidateRect which has been
removed as the validation is already handled by the call to BeginPaint.

re #862
This commit is contained in:
LGUG2Z
2024-06-12 08:05:56 -07:00
parent 67a3c3546f
commit d2d6484e38
2 changed files with 53 additions and 51 deletions
+10 -6
View File
@@ -32,7 +32,6 @@ use windows::Win32::Graphics::Gdi::InvalidateRect;
use windows::Win32::Graphics::Gdi::Rectangle; use windows::Win32::Graphics::Gdi::Rectangle;
use windows::Win32::Graphics::Gdi::RoundRect; use windows::Win32::Graphics::Gdi::RoundRect;
use windows::Win32::Graphics::Gdi::SelectObject; use windows::Win32::Graphics::Gdi::SelectObject;
use windows::Win32::Graphics::Gdi::ValidateRect;
use windows::Win32::Graphics::Gdi::PAINTSTRUCT; use windows::Win32::Graphics::Gdi::PAINTSTRUCT;
use windows::Win32::Graphics::Gdi::PS_INSIDEFRAME; use windows::Win32::Graphics::Gdi::PS_INSIDEFRAME;
use windows::Win32::Graphics::Gdi::PS_SOLID; use windows::Win32::Graphics::Gdi::PS_SOLID;
@@ -150,8 +149,12 @@ impl Border {
unsafe { unsafe {
match message { match message {
WM_PAINT => { WM_PAINT => {
let mut ps = PAINTSTRUCT::default();
let hdc = BeginPaint(window, &mut ps);
// With the rect that we set in Self::update // With the rect that we set in Self::update
if let Ok(rect) = WindowsApi::window_rect(window) { match WindowsApi::window_rect(window) {
Ok(rect) => {
// Grab the focus kind for this border // Grab the focus kind for this border
let focus_kind = { let focus_kind = {
FOCUS_STATE FOCUS_STATE
@@ -162,8 +165,6 @@ impl Border {
}; };
// Set up the brush to draw the border // Set up the brush to draw the border
let mut ps = PAINTSTRUCT::default();
let hdc = BeginPaint(window, &mut ps);
let hpen = CreatePen( let hpen = CreatePen(
PS_SOLID | PS_INSIDEFRAME, PS_SOLID | PS_INSIDEFRAME,
BORDER_WIDTH.load(Ordering::SeqCst), BORDER_WIDTH.load(Ordering::SeqCst),
@@ -201,12 +202,15 @@ impl Border {
Rectangle(hdc, 0, 0, rect.right, rect.bottom); Rectangle(hdc, 0, 0, rect.right, rect.bottom);
} }
} }
EndPaint(window, &ps);
DeleteObject(hpen); DeleteObject(hpen);
DeleteObject(hbrush); DeleteObject(hbrush);
ValidateRect(window, None); }
Err(error) => {
tracing::error!("could not get border rect: {}", error.to_string())
}
} }
EndPaint(window, &ps);
LRESULT(0) LRESULT(0)
} }
WM_DESTROY => { WM_DESTROY => {
+1 -3
View File
@@ -155,11 +155,9 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
} }
// handle the retile edge case // handle the retile edge case
if !should_process_notification { if !should_process_notification && BORDER_STATE.lock().is_empty() {
if BORDER_STATE.lock().is_empty() {
should_process_notification = true; should_process_notification = true;
} }
}
if !should_process_notification { if !should_process_notification {
tracing::trace!("monitor state matches latest snapshot, skipping notification"); tracing::trace!("monitor state matches latest snapshot, skipping notification");