FelixKratz / JankyBorders

A lightweight window border system for macOS
GNU General Public License v3.0
1k stars 18 forks source link

Customize Opacity #36

Closed slano-ls closed 8 months ago

slano-ls commented 8 months ago

Add an option to customize the opacity of the border so that the "strength" of the colour can be modified.

In an older project Honer, there was an option to modify the opacity of the drawn window.

The project is implemented in obj-c, but still for the sake of ease, I have attached it here

https://github.com/puffnfresh/Honer.app/blob/090c5a27a13b3aab4ed9505e1dfd963862fb3e1d/Honer/OverlayWindow.m#L23

#import "OverlayWindow.h"

@implementation OverlayWindow

- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)style backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag
{
    self = [super initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:bufferingType defer:flag];

    if ( self ) {
        [self setOpaque:NO];
        [self setBackgroundColor:[NSColor clearColor]];
        [self setLevel:NSPopUpMenuWindowLevel];
        [self setIgnoresMouseEvents:YES];

        [self updateAlpha:nil];
    }

    return self;
}

- (IBAction)updateAlpha:(id)sender
{
    NSInteger transparency = [[NSUserDefaults standardUserDefaults] doubleForKey:@"transparency"];
    CGFloat alpha = 1.0 - (transparency * 0.1);
    [self setAlphaValue:alpha];

    [self orderFront:sender];
}

- (void)awakeFromNib
{
}

@end
FelixKratz commented 8 months ago

You can change the alpha of all colors. It is encoded in the first two hex digits e.g.:

borders active_color=0x60ff0000