Fix issue where color sampler only gets color from app windows. Now can get color from the entire screen.

This commit is contained in:
Gregory John Casamento 2020-03-20 04:25:42 -04:00
parent bc47973133
commit ab5a52b59e

View file

@ -26,6 +26,7 @@
#import <Foundation/NSDate.h>
#import <Foundation/NSException.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSLock.h>
#import <AppKit/NSApplication.h>
#import <AppKit/NSBitmapImageRep.h>
@ -39,6 +40,9 @@
#import <GNUstepGUI/GSDisplayServer.h>
static NSLock *_gs_gui_color_sampler_lock = nil;
static NSColorSampler *_gs_gui_color_sampler = nil;
@interface NSWindow (private)
- (void) _captureMouse: sender;
- (void) _releaseMouse: sender;
@ -46,6 +50,31 @@
@implementation NSColorSampler
+ (void) initialize
{
if (self == [NSColorSampler class])
{
// Initial version
[self setVersion: 1];
_gs_gui_color_sampler_lock = [NSLock new];
}
}
- (instancetype) init
{
if (_gs_gui_color_sampler == nil)
{
_gs_gui_color_sampler = self;
}
else if (self != _gs_gui_color_sampler)
{
RELEASE(self);
return _gs_gui_color_sampler;
}
return self;
}
- (void) showSamplerWithSelectionHandler: (GSColorSampleHandler)selectionHandler
{
NSEvent *currentEvent;
@ -59,7 +88,9 @@
defer: NO
screen: nil];
NSColor *color = nil;
[_gs_gui_color_sampler_lock lock];
[w orderFront: nil];
[w _captureMouse: self];
@ -114,6 +145,8 @@
[NSCursor pop];
[w _releaseMouse: self];
[w close];
[_gs_gui_color_sampler_lock unlock];
}
@end