Revision: 15865
          http://sourceforge.net/p/skim-app/code/15865
Author:   hofman
Date:     2025-12-13 18:43:05 +0000 (Sat, 13 Dec 2025)
Log Message:
-----------
let thumbnail image view observe app for effectiveAppearrance when inverting 
colors instead of relying on its own change method, as the latter may not be 
called for the overview in presentation as this is always has dark appearance

Modified Paths:
--------------
    trunk/SKThumbnailImageView.h
    trunk/SKThumbnailImageView.m

Modified: trunk/SKThumbnailImageView.h
===================================================================
--- trunk/SKThumbnailImageView.h        2025-12-13 17:17:15 UTC (rev 15864)
+++ trunk/SKThumbnailImageView.h        2025-12-13 18:43:05 UTC (rev 15865)
@@ -39,5 +39,7 @@
 #import <Cocoa/Cocoa.h>
 
 
-@interface SKThumbnailImageView : NSImageView
+@interface SKThumbnailImageView : NSImageView {
+    BOOL observingApp;
+}
 @end

Modified: trunk/SKThumbnailImageView.m
===================================================================
--- trunk/SKThumbnailImageView.m        2025-12-13 17:17:15 UTC (rev 15864)
+++ trunk/SKThumbnailImageView.m        2025-12-13 18:43:05 UTC (rev 15865)
@@ -41,6 +41,7 @@
 #import "NSGraphics_SKExtensions.h"
 
 static char SKThumbnailImageViewDefaultsObservationContext;
+static char SKThumbnailImageViewAppObservationContext;
 
 @implementation SKThumbnailImageView
 
@@ -57,6 +58,12 @@
     NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
     for (NSString *key in defaultKeysToObserve())
         [sud addObserver:self forKeyPath:key options:0 
context:&SKThumbnailImageViewDefaultsObservationContext];
+    if (@available(macOS 10.14, *)) {
+        if ([sud boolForKey:SKInvertColorsInDarkModeKey]) {
+            [NSApp addObserver:self forKeyPath:@"effectiveAppearance" 
options:0 context:&SKThumbnailImageViewAppObservationContext];
+            observingApp = YES;
+        }
+    }
 }
 
 - (instancetype)initWithFrame:(NSRect)frameRect {
@@ -74,6 +81,7 @@
     }
     return self;
 }
+
 - (void)dealloc {
     NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
     for (NSString *key in defaultKeysToObserve()) {
@@ -80,20 +88,32 @@
         @try { [sud removeObserver:self forKeyPath:key 
context:&SKThumbnailImageViewDefaultsObservationContext]; }
         @catch (id e) {}
     }
+    if (observingApp) {
+        @try { [NSApp removeObserver:self forKeyPath:@"effectiveAppearance" 
context:&SKThumbnailImageViewAppObservationContext]; }
+        @catch (id e) {}
+    }
 }
 
-- (void)viewDidChangeEffectiveAppearance {
-    if (@available(macOS 10.14, *))
-        [super viewDidChangeEffectiveAppearance];
-    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKInvertColorsInDarkModeKey])
-        [self setContentFilters:SKColorEffectFilters()];
-}
-
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object 
change:(NSDictionary *)change context:(void *)context {
-    if (context == &SKThumbnailImageViewDefaultsObservationContext)
+    if (context == &SKThumbnailImageViewDefaultsObservationContext) {
         [self setContentFilters:SKColorEffectFilters()];
-    else
+        if ([keyPath isEqualToString:SKInvertColorsInDarkModeKey]) {
+            if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKInvertColorsInDarkModeKey]) {
+                if (observingApp == NO) {
+                    [NSApp addObserver:self forKeyPath:@"effectiveAppearance" 
options:0 context:&SKThumbnailImageViewAppObservationContext];
+                    observingApp = YES;
+                }
+            } else if (observingApp) {
+                @try { [NSApp removeObserver:self 
forKeyPath:@"effectiveAppearance" 
context:&SKThumbnailImageViewAppObservationContext]; }
+                @catch (id e) {}
+                observingApp = NO;
+            }
+        }
+    } else if (context == &SKThumbnailImageViewAppObservationContext) {
+        [self setContentFilters:SKColorEffectFilters()];
+    } else {
         [super observeValueForKeyPath:keyPath ofObject:object change:change 
context:context];
+    }
 }
 
 @end

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to