Skip to content

Commit

Permalink
Fix mouse resize on macOS
Browse files Browse the repository at this point in the history
This is a very hacky solution that I don't like. I couldn't find a way
to detect whether the pointer is on the resize border of the window
using Cocoa. I also couldn't find any documentation for any default
border sizes.

What I found in my testing was that the left and right borders were
active 3 pixels inside of the Viewport (and probably 3px outside as
well). For the bottom left corner, there seems to be a 12x12 box, and
the bottom right seems to be 15x15. If the pointer is on the resize
border, the Viewport will not receive the input and they will go the
system instead, which will then trigger a resize.

This seems to be the way to go if there aren't any coca API calls that
can check this. An alternative to this solution would be to implement
XBUTTON1/2 detection for win32 in upstream FLTK, which means we can rely
entirely on FLTK's mouse input handling to do what we need.
  • Loading branch information
adamhalim committed Sep 6, 2024
1 parent 0311f9f commit cfe40cc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions vncviewer/cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ int cocoa_get_mouse_coordinates(const void *event, int *x, int *y)
NSView* view;
NSRect frame;

const int BORDER_SIZE = 3;
const int BOTTOM_LEFT_BORDER_SIZE = 12;
const int BOTTOM_RIGHT_BORDER_SIZE = 15;

nsevent = (NSEvent*)event;

window = [nsevent window];
Expand All @@ -505,6 +509,18 @@ int cocoa_get_mouse_coordinates(const void *event, int *x, int *y)
view = [window contentView];
frame = [view frame];

// Check if pointer is on resize border
if (pt.x <= BORDER_SIZE ||
pt.x >= frame.size.width - BORDER_SIZE ||
pt.y <= BORDER_SIZE)
return 1;
if (pt.x <= BOTTOM_LEFT_BORDER_SIZE &&
pt.y <= BOTTOM_LEFT_BORDER_SIZE)
return 1;
if (pt.x >= frame.size.width - BOTTOM_RIGHT_BORDER_SIZE &&
pt.y <= BOTTOM_RIGHT_BORDER_SIZE)
return 1;

// FIXME: Should these be rounded or truncated?
*x = round(pt.x);
*y = round(frame.size.height - pt.y); // macOS has bottom-left origin
Expand Down

0 comments on commit cfe40cc

Please sign in to comment.