From 955091ce129bb0bd5c90eaff827ded10c7ecb8bb Mon Sep 17 00:00:00 2001 From: SweetPPro Date: Mon, 13 Jun 2022 16:48:09 +0200 Subject: [PATCH] macOS - fix some window drawing issues (#3278) * macOS - fix some window drawing issues fixes an issue with torrent clipping when number of torrents displayed overflows the screen height --- macosx/Controller.mm | 16 +++-- macosx/ControllerWindowMethods.h | 1 + macosx/ControllerWindowMethods.mm | 108 +++++++++++++++++------------- 3 files changed, 70 insertions(+), 55 deletions(-) diff --git a/macosx/Controller.mm b/macosx/Controller.mm index dc6b02404..a02558cfe 100644 --- a/macosx/Controller.mm +++ b/macosx/Controller.mm @@ -1115,7 +1115,7 @@ static void removeKeRangerRansomware() } } - [self fullUpdateUI]; + [self drawMainWindow]; } - (void)askOpenConfirmed:(AddWindowController*)addController add:(BOOL)add @@ -1135,7 +1135,7 @@ static void removeKeRangerRansomware() } [self.fAddingTransfers addObject:torrent]; - [self fullUpdateUI]; + [self drawMainWindow]; } else { @@ -1209,7 +1209,7 @@ static void removeKeRangerRansomware() [self.fAddingTransfers addObject:torrent]; } - [self fullUpdateUI]; + [self drawMainWindow]; } - (void)askOpenMagnetConfirmed:(AddMagnetWindowController*)addController add:(BOOL)add @@ -1229,7 +1229,7 @@ static void removeKeRangerRansomware() } [self.fAddingTransfers addObject:torrent]; - [self fullUpdateUI]; + [self drawMainWindow]; } else { @@ -1726,6 +1726,8 @@ static void removeKeRangerRansomware() { [torrent closeRemoveTorrent:deleteData]; } + + [self drawMainWindow]; }; [self.fTableView beginUpdates]; @@ -1767,9 +1769,9 @@ static void removeKeRangerRansomware() { [torrent closeRemoveTorrent:deleteData]; } - } - [self fullUpdateUI]; + [self drawMainWindow]; + } } - (void)removeNoDelete:(id)sender @@ -4991,7 +4993,7 @@ static void removeKeRangerRansomware() } [self.fAddingTransfers addObject:torrent]; - [self fullUpdateUI]; + [self drawMainWindow]; } - (void)rpcRemoveTorrent:(Torrent*)torrent deleteData:(BOOL)deleteData diff --git a/macosx/ControllerWindowMethods.h b/macosx/ControllerWindowMethods.h index f8d517f67..a43b464ed 100644 --- a/macosx/ControllerWindowMethods.h +++ b/macosx/ControllerWindowMethods.h @@ -19,6 +19,7 @@ @property(nonatomic, readonly) CGFloat titlebarHeight; @property(nonatomic, readonly) CGFloat mainWindowComponentHeight; @property(nonatomic, readonly) CGFloat scrollViewHeight; +@property(nonatomic, readonly) CGFloat fullScreenScrollViewHeight; @property(nonatomic, readonly) CGFloat minWindowContentSizeAllowed; @property(nonatomic, readonly) BOOL isFullScreen; diff --git a/macosx/ControllerWindowMethods.mm b/macosx/ControllerWindowMethods.mm index 5b3a9d77e..aea7a8401 100644 --- a/macosx/ControllerWindowMethods.mm +++ b/macosx/ControllerWindowMethods.mm @@ -14,58 +14,60 @@ - (void)drawMainWindow { - NSView* contentView = self.fWindow.contentView; - NSSize const windowSize = [contentView convertSize:self.fWindow.frame.size fromView:nil]; - CGFloat originY = NSMaxY(contentView.frame); + dispatch_async(dispatch_get_main_queue(), ^{ + NSView* contentView = self.fWindow.contentView; + NSSize const windowSize = [contentView convertSize:self.fWindow.frame.size fromView:nil]; + CGFloat originY = NSMaxY(contentView.frame); - //remove all subviews - for (id view in contentView.subviews.copy) - { - [view removeFromSuperviewWithoutNeedingDisplay]; - } + //remove all subviews + for (id view in contentView.subviews.copy) + { + [view removeFromSuperviewWithoutNeedingDisplay]; + } - self.fStatusBar = nil; - self.fFilterBar = nil; + self.fStatusBar = nil; + self.fFilterBar = nil; - if ([self.fDefaults boolForKey:@"StatusBar"]) - { - self.fStatusBar = [[StatusBarController alloc] initWithLib:self.fLib]; + if ([self.fDefaults boolForKey:@"StatusBar"]) + { + self.fStatusBar = [[StatusBarController alloc] initWithLib:self.fLib]; - NSRect statusBarFrame = self.fStatusBar.view.frame; - statusBarFrame.size.width = windowSize.width; + NSRect statusBarFrame = self.fStatusBar.view.frame; + statusBarFrame.size.width = windowSize.width; - originY -= STATUS_BAR_HEIGHT; - statusBarFrame.origin.y = originY; - self.fStatusBar.view.frame = statusBarFrame; + originY -= STATUS_BAR_HEIGHT; + statusBarFrame.origin.y = originY; + self.fStatusBar.view.frame = statusBarFrame; - [contentView addSubview:self.fStatusBar.view]; - } + [contentView addSubview:self.fStatusBar.view]; + } - if ([self.fDefaults boolForKey:@"FilterBar"]) - { - self.fFilterBar = [[FilterBarController alloc] init]; + if ([self.fDefaults boolForKey:@"FilterBar"]) + { + self.fFilterBar = [[FilterBarController alloc] init]; - NSRect filterBarFrame = self.fFilterBar.view.frame; - filterBarFrame.size.width = windowSize.width; + NSRect filterBarFrame = self.fFilterBar.view.frame; + filterBarFrame.size.width = windowSize.width; - originY -= FILTER_BAR_HEIGHT; - filterBarFrame.origin.y = originY; - self.fFilterBar.view.frame = filterBarFrame; + originY -= FILTER_BAR_HEIGHT; + filterBarFrame.origin.y = originY; + self.fFilterBar.view.frame = filterBarFrame; - [contentView addSubview:self.fFilterBar.view]; - } + [contentView addSubview:self.fFilterBar.view]; + } - NSScrollView* scrollView = self.fTableView.enclosingScrollView; - [contentView addSubview:scrollView]; + NSScrollView* scrollView = self.fTableView.enclosingScrollView; + [contentView addSubview:scrollView]; - [contentView addSubview:self.fActionButton]; - [contentView addSubview:self.fSpeedLimitButton]; - [contentView addSubview:self.fClearCompletedButton]; - [contentView addSubview:self.fTotalTorrentsField]; + [contentView addSubview:self.fActionButton]; + [contentView addSubview:self.fSpeedLimitButton]; + [contentView addSubview:self.fClearCompletedButton]; + [contentView addSubview:self.fTotalTorrentsField]; - //window is updated and animated in fullUpdateUI --> applyFilter --> setWindowSizeToFit - [self fullUpdateUI]; - [self updateForAutoSize]; + //window is updated and animated in fullUpdateUI --> applyFilter --> setWindowSizeToFit + [self fullUpdateUI]; + [self updateForAutoSize]; + }); } - (void)setWindowSizeToFit @@ -131,8 +133,6 @@ //update scrollview NSRect scrollViewFrame = scrollView.frame; scrollViewFrame.size.height = scrollViewHeight; - scrollViewFrame.origin.y = BOTTOM_BAR_HEIGHT; - [scrollView setFrame:scrollViewFrame]; //we can't call minSize, since it might be set to the current size (auto size) CGFloat const minHeight = self.minWindowContentSizeAllowed + @@ -145,27 +145,34 @@ else { NSScreen* screen = self.fWindow.screen; - if (screen) + if (screen && !self.isFullScreen) { - NSSize maxSize = [scrollView convertSize:screen.visibleFrame.size fromView:nil]; - maxSize.height += titleBarHeight; - maxSize.height += BOTTOM_BAR_HEIGHT; + NSSize maxSize = screen.frame.size; + maxSize.height -= titleBarHeight; + maxSize.height -= BOTTOM_BAR_HEIGHT; if (self.fStatusBar) { - maxSize.height += STATUS_BAR_HEIGHT; + maxSize.height -= STATUS_BAR_HEIGHT; } if (self.fFilterBar) { - maxSize.height += FILTER_BAR_HEIGHT; + maxSize.height -= FILTER_BAR_HEIGHT; } if (windowSize.height > maxSize.height) { windowSize.height = maxSize.height; + + //recalculate scrollview height + scrollViewFrame.size.height = self.fullScreenScrollViewHeight; } } } + //commit scrollview changes + scrollViewFrame.origin.y = BOTTOM_BAR_HEIGHT; + [scrollView setFrame:scrollViewFrame]; + windowFrame.origin.y -= (windowSize.height - windowFrame.size.height); windowFrame.size.height = windowSize.height; return windowFrame; @@ -196,7 +203,7 @@ { if (self.isFullScreen) { - return self.fWindow.frame.size.height - self.titlebarHeight - self.mainWindowComponentHeight - BOTTOM_BAR_HEIGHT; + return self.fullScreenScrollViewHeight; } if ([self.fDefaults boolForKey:@"AutoSize"]) @@ -214,6 +221,11 @@ return NSHeight(self.fTableView.enclosingScrollView.frame); } +- (CGFloat)fullScreenScrollViewHeight +{ + return self.fWindow.frame.size.height - self.titlebarHeight - self.mainWindowComponentHeight - BOTTOM_BAR_HEIGHT; +} + - (CGFloat)minWindowContentSizeAllowed { CGFloat contentMinHeight = self.fTableView.rowHeight + self.fTableView.intercellSpacing.height +