From b323780460e3666b82257f947ce67715ad4e958e Mon Sep 17 00:00:00 2001 From: RoshniUG <148745853+RoshniUG@users.noreply.github.com> Date: Sat, 8 Feb 2025 12:20:53 +0530 Subject: [PATCH] Merge pull request #26662 from RoshniUG:4.x Update window_cocoa.mm #26662 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake - [x ] Added reference to the original bug report (#26661). - [x]Updated the code as per the reviewer's suggestion to use a ternary operator. - [x] Verified that the feature is properly documented and can be built with CMake. --- modules/highgui/src/window_cocoa.mm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/highgui/src/window_cocoa.mm b/modules/highgui/src/window_cocoa.mm index f5948951a2..71b5c6fb9a 100644 --- a/modules/highgui/src/window_cocoa.mm +++ b/modules/highgui/src/window_cocoa.mm @@ -784,6 +784,7 @@ void cvSetPropTopmost_COCOA( const char* name, const bool topmost ) void setWindowTitle_COCOA(const cv::String& winname, const cv::String& title) { + @autoreleasepool{ CVWindow *window = cvGetWindow(winname.c_str()); @@ -799,6 +800,7 @@ void setWindowTitle_COCOA(const cv::String& winname, const cv::String& title) NSString *windowTitle = [NSString stringWithFormat:@"%s", title.c_str()]; [window setTitle:windowTitle]; } + } static NSSize constrainAspectRatio(NSSize base, NSSize constraint) { @@ -874,8 +876,19 @@ static NSSize constrainAspectRatio(NSSize base, NSSize constraint) { if([event modifierFlags] & NSControlKeyMask) flags |= CV_EVENT_FLAG_CTRLKEY; if([event modifierFlags] & NSAlternateKeyMask) flags |= CV_EVENT_FLAG_ALTKEY; - if([event type] == NSLeftMouseDown) {[self cvSendMouseEvent:event type:CV_EVENT_LBUTTONDOWN flags:flags | CV_EVENT_FLAG_LBUTTON];} - if([event type] == NSLeftMouseUp) {[self cvSendMouseEvent:event type:CV_EVENT_LBUTTONUP flags:flags | CV_EVENT_FLAG_LBUTTON];} + //modified code using ternary operator: + if ([event type] == NSLeftMouseDown) { + [self cvSendMouseEvent:event + type:([event modifierFlags] & NSControlKeyMask) ? CV_EVENT_RBUTTONDOWN : CV_EVENT_LBUTTONDOWN + flags:flags | (([event modifierFlags] & NSControlKeyMask) ? CV_EVENT_FLAG_RBUTTON : CV_EVENT_FLAG_LBUTTON)]; +} + +if ([event type] == NSLeftMouseUp) { + [self cvSendMouseEvent:event + type:([event modifierFlags] & NSControlKeyMask) ? CV_EVENT_RBUTTONUP : CV_EVENT_LBUTTONUP + flags:flags | (([event modifierFlags] & NSControlKeyMask) ? CV_EVENT_FLAG_RBUTTON : CV_EVENT_FLAG_LBUTTON)]; +} + if([event type] == NSRightMouseDown){[self cvSendMouseEvent:event type:CV_EVENT_RBUTTONDOWN flags:flags | CV_EVENT_FLAG_RBUTTON];} if([event type] == NSRightMouseUp) {[self cvSendMouseEvent:event type:CV_EVENT_RBUTTONUP flags:flags | CV_EVENT_FLAG_RBUTTON];} if([event type] == NSOtherMouseDown){[self cvSendMouseEvent:event type:CV_EVENT_MBUTTONDOWN flags:flags];}