Skip to content

Add option to change toolbar and title bar opacity #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,15 @@ sudo ./install-fedora-based.sh

`--on-change-hook [COMMAND]`  A script/command that will be executed on start or wallpaper/dark/light/settings change

`--sierra-breeze-buttons-color, -sbb`  Tint SierraBreeze decoration buttons
`--sierra-breeze-buttons-color, -sbb`  Tint Sierra Breeze decoration buttons

`--konsole-profile [KONSOLE_PROFILE], -kp [KONSOLE_PROFILE]`  The name of your (existing) Konsole profile that is going to be themed, you can check your current profiles with konsole --list-profiles

`--sbe-titlebar-opacity [OPACITY], -sbeto [OPACITY]`  Sierra Breeze Enhanced titlebar opacity (value from 0 to 100, default is None)

`--toolbar-opacity [OPACITY], -to [OPACITY]`  ToolBar opacity, needs Lightly Application Style (value from 0 to 100,
default is None)

# Startup script:

1. Copy the default configuration to ~/.config/kde-material-you-colors/config.conf:
Expand Down Expand Up @@ -211,7 +216,7 @@ ncolor = 0
# example below using https://github.com/vlevit/notify-send.sh to send a desktop notification:
#on_change_hook = notify-send.sh "kde-material-you-colors" "This is a test" -t 2000

# Tint SierraBreeze decoration buttons https://github.com/ishovkun/SierraBreeze
# Tint Sierra Breeze decoration buttons https://github.com/ishovkun/SierraBreeze
# Accepted values are True or False
# Default is False
# NOTE:
Expand All @@ -227,6 +232,20 @@ ncolor = 0
# WARNING:
# I recommend you to backup the ~/.local/share/konsole/ folder before trying this because it will edit your profiles
#konsole_profile = Profile 1

# Sierra Breeze Enhanced Title Bar opacity https://github.com/kupiqu/SierraBreezeEnhanced
# An integer between 0 and 100
# Default is commented (disabled)
# NOTE:
# This will reload KWin (screen will blink on x11)
#sbe_titlebar_opacity = 100

# ToolBar opacity needs Lightly Application Style to work https://github.com/Luwx/Lightly
# An integer between 0 and 100
# Default is commented (disabled)
# NOTE:
# kirigami ToolBar opacity is not affected by this option https://github.com/Luwx/Lightly/issues/128
#toolbar_opacity = 100
```

And run `kde-material-you-colors` with no arguments from terminal to test it.
Expand Down
28 changes: 28 additions & 0 deletions color_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ def blendColors(colorA, colorB, ratio):

return rgb2hex(r, g, b)

def hex2alpha(solid_color,opacity):
opacity = int(numpy.ceil(opacity*2.55))
aa = f'{opacity:x}'
if len(aa) == 1:
aa = f'0{aa}'
argb = solid_color.replace('#',f'#{aa}')
return argb

def rgb2alpha(rgb,opacity):
opacity = int(numpy.ceil(opacity*2.55))
rgba = (rgb[0],rgb[1],rgb[2],opacity)
return rgba

def hex2rgba(hex, opacity):
hex = hex.lstrip('#')
rgb = tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))
rgba = rgb2alpha(rgb,opacity)
return rgba

# Tests
if __name__ == '__main__':
# Test color blend
Expand All @@ -119,3 +138,12 @@ def blendColors(colorA, colorB, ratio):
print(blendColors('#ff0000', "#00ff00", .5))
print(blendColors('#ff0000', "#00ff00", .75))
print(blendColors('#ff0000', "#00ff00", .99))

print(hex2alpha('#ff0000',128))
color1hex = '#ff0000'
color1rgb = hex2rgb(color1hex)
color1rgb_alpha= rgb2alpha(color1rgb,200)
print(color1rgb_alpha)

color1rgba = hex2rgba(color1hex,200)
print(color1rgba)
12 changes: 9 additions & 3 deletions kde-material-you-colors
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ if __name__ == '__main__':
parser.add_argument('--on-change-hook', type=str,
help='A script/command that will be executed on start or wallpaper/dark/light/settings change',default=None)
parser.add_argument('--sierra-breeze-buttons-color', '-sbb', action='store_true',
help='Tint SierraBreeze decoration buttons')
help='Tint Sierra Breeze decoration buttons')
parser.add_argument('--konsole-profile', '-kp', type=str,
help='The name of your (existing) Konsole profile that is going to be themed, you can check your current profiles with konsole --list-profiles', default=None)
parser.add_argument('--sbe-titlebar-opacity', '-sbeto', type=int,
help='Sierra Breeze Enhanced titlebar opacity (value from 0 to 100, default is None)', default=None)
parser.add_argument('--toolbar-opacity', '-to', type=int,
help='ToolBar opacity, needs Lightly Application Style (value from 0 to 100, default is None)', default=None)

# Get arguments
args = parser.parse_args()
Expand Down Expand Up @@ -86,12 +90,13 @@ if __name__ == '__main__':
light = options_old['light']

if colors != None:
schemes = ThemeConfig(colors,wallpaper_old_data,light_blend_multiplier=options_old['lbm'], dark_blend_multiplier=options_old['dbm'])
schemes = ThemeConfig(colors,wallpaper_old_data,light_blend_multiplier=options_old['lbm'], dark_blend_multiplier=options_old['dbm'], toolbar_opacity=options_old['toolbar_opacity'])
utils.make_plasma_scheme(schemes=schemes)
utils.apply_color_schemes(
light=light)
if options_old['sierra_breeze_buttons_color'] == True:
utils.sierra_breeze_button_colors(schemes,light)
utils.sierra_breeze_enhanced_titlebar_opacity(options_old['sbe_titlebar_opacity'])
utils.set_icons(icons_light=options_old['iconslight'],
icons_dark=options_old['iconsdark'], light=options_old['light'])
utils.make_konsole_mirror_profile(konsole_profile_old)
Expand Down Expand Up @@ -152,7 +157,7 @@ if __name__ == '__main__':
logging.debug(f"New Config: {options_new}")
colors = utils.get_color_schemes(wallpaper_new,options_new['ncolor'])
if colors != None:
schemes = ThemeConfig(colors,wallpaper_new_data,light_blend_multiplier=options_new['lbm'], dark_blend_multiplier=options_new['dbm'])
schemes = ThemeConfig(colors,wallpaper_new_data,light_blend_multiplier=options_new['lbm'], dark_blend_multiplier=options_new['dbm'],toolbar_opacity=options_new['toolbar_opacity'])
utils.make_plasma_scheme(schemes=schemes)
if options_changed:
if icons_changed or light_changed:
Expand All @@ -162,6 +167,7 @@ if __name__ == '__main__':
utils.apply_color_schemes(light=light)
if options_new['sierra_breeze_buttons_color'] == True:
utils.sierra_breeze_button_colors(schemes,light)
utils.sierra_breeze_enhanced_titlebar_opacity(options_new['sbe_titlebar_opacity'])
utils.konsole_apply_color_scheme(light,options_new['pywal_light'],schemes,options_new['konsole_profile'])
utils.apply_pywal_schemes(
light=light, use_pywal=options_new['pywal'], pywal_light=options_new['pywal_light'], schemes=schemes)
Expand Down
16 changes: 15 additions & 1 deletion sample_config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ ncolor = 0
# example below using https://github.com/vlevit/notify-send.sh to send a desktop notification:
#on_change_hook = notify-send.sh "kde-material-you-colors" "This is a test" -t 2000

# Tint SierraBreeze decoration buttons https://github.com/ishovkun/SierraBreeze
# Tint Sierra Breeze decoration buttons https://github.com/ishovkun/SierraBreeze
# Accepted values are True or False
# Default is False
# NOTE:
Expand All @@ -86,3 +86,17 @@ ncolor = 0
# WARNING:
# I recommend you to backup the ~/.local/share/konsole/ folder before trying this because it will edit your profiles
#konsole_profile = Profile 1

# Sierra Breeze Enhanced Title Bar opacity https://github.com/kupiqu/SierraBreezeEnhanced
# An integer between 0 and 100
# Default is commented (disabled)
# NOTE:
# This will reload KWin (screen will blink on x11)
#sbe_titlebar_opacity = 100

# ToolBar opacity needs Lightly Application Style to work https://github.com/Luwx/Lightly
# An integer between 0 and 100
# Default is commented (disabled)
# NOTE:
# kirigami ToolBar opacity is not affected by this option https://github.com/Luwx/Lightly/issues/128
#toolbar_opacity = 100
16 changes: 9 additions & 7 deletions schemeconfigs.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from color_utils import blendColors, hex2rgb
from color_utils import blendColors, hex2rgb, hex2alpha
from utils import range_check, tup2str
class ThemeConfig:
def __init__(self, colors, wallpaper_data, light_blend_multiplier=1, dark_blend_multiplier=1):
def __init__(self, colors, wallpaper_data, light_blend_multiplier=1, dark_blend_multiplier=1, toolbar_opacity=100):
if toolbar_opacity == None:
toolbar_opacity = 100
colors_best = colors['bestColors']
tones_primary = colors['primaryTones']
tones_neutral = colors['neutralTones']

lbm = range_check(light_blend_multiplier,0,4)
dbm = range_check(dark_blend_multiplier,0,4)
toolbar_opacity = range_check(toolbar_opacity,0,100)
tone = 30

pywal_colors_dark = (blendColors(
Expand Down Expand Up @@ -261,10 +263,10 @@ def __init__(self, colors, wallpaper_data, light_blend_multiplier=1, dark_blend_
contrast=4

[WM]
activeBackground={extras['SurfaceLight3']}
activeBackground={hex2alpha(extras['SurfaceLight3'],toolbar_opacity)}
activeBlend=227,229,231
activeForeground={colors['light']['OnSurface']}
inactiveBackground={colors['light']['SecondaryContainer']}
inactiveBackground={hex2alpha(colors['light']['SecondaryContainer'],toolbar_opacity)}
inactiveBlend=239,240,241
inactiveForeground={colors['light']['OnSurfaceVariant']}
"""
Expand Down Expand Up @@ -414,10 +416,10 @@ def __init__(self, colors, wallpaper_data, light_blend_multiplier=1, dark_blend_
contrast=4

[WM]
activeBackground={extras['SurfaceDark3']}
activeBackground={hex2alpha(extras['SurfaceDark3'],toolbar_opacity)}
activeBlend=252,252,252
activeForeground={colors['dark']['OnSurface']}
inactiveBackground={colors['dark']['SecondaryContainer']}
inactiveBackground={hex2alpha(colors['dark']['SecondaryContainer'],toolbar_opacity)}
inactiveBlend=161,169,177
inactiveForeground={colors['dark']['OnSecondaryContainer']}
"""
Expand Down
62 changes: 58 additions & 4 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
PICTURE_OF_DAY_DEFAULT_PROVIDER = 'apod' # astronomy picture of the day
KDE_GLOBALS = HOME+"/.config/kdeglobals"
BREEZE_RC = HOME+"/.config/breezerc"
SBE_RC = HOME+"/.config/sierrabreezeenhancedrc"
KONSOLE_DIR = HOME+"/.local/share/konsole/"
KONSOLE_COLOR_SCHEME_PATH = KONSOLE_DIR+"MaterialYou.colorscheme"
KONSOLE_COLOR_SCHEME_ALT_PATH = KONSOLE_DIR+"MaterialYouAlt.colorscheme"
Expand Down Expand Up @@ -119,7 +120,7 @@ class Configs():
dict: Settings dictionary
"""
def __init__(self, args):
c_light = c_monitor = c_file = c_plugin = c_ncolor = c_iconsdark = c_iconslight = c_pywal = c_pywal_light = c_light_blend_multiplier = c_dark_blend_multiplier = c_on_change_hook = c_sierra_breeze_buttons_color = c_konsole_profile = None
c_light = c_monitor = c_file = c_plugin = c_ncolor = c_iconsdark = c_iconslight = c_pywal = c_pywal_light = c_light_blend_multiplier = c_dark_blend_multiplier = c_on_change_hook = c_sierra_breeze_buttons_color = c_konsole_profile = c_sbe_titlebar_opacity = c_toolbar_opacity = None
# User may just want to set the startup script / default config, do that only and exit
if args.autostart == True:
if not os.path.exists(USER_AUTOSTART_SCRIPT_PATH):
Expand Down Expand Up @@ -210,6 +211,18 @@ def __init__(self, args):

if 'konsole_profile' in custom:
c_konsole_profile = custom['konsole_profile']

if 'sbe_titlebar_opacity' in custom:
c_sbe_titlebar_opacity = custom.getint('sbe_titlebar_opacity')
if c_sbe_titlebar_opacity < 0 or c_sbe_titlebar_opacity > 100:
raise ValueError(
'Value for sbe_titlebar_opacity must be an integer betwritten 0 and 100, using default 100')

if 'toolbar_opacity' in custom:
c_toolbar_opacity = custom.getint('toolbar_opacity')
if c_toolbar_opacity < 0 or c_toolbar_opacity > 100:
raise ValueError(
'Value for toolbar_opacity must be an integer betwritten 0 and 100, using default 100')

except Exception as e:
logging.error(f"Please fix your settings file:\n{e}\n")
Expand Down Expand Up @@ -267,7 +280,7 @@ def __init__(self, args):
elif args.ncolor == None and c_ncolor == None:
c_ncolor = 0
else:
c_ncolor = c_ncolor
c_ncolor = c_ncolor

if args.plugin != None:
c_plugin = args.plugin
Expand Down Expand Up @@ -300,7 +313,24 @@ def __init__(self, args):
c_konsole_profile = args.konsole_profile
elif c_konsole_profile == None:
c_konsole_profile = args.konsole_profile


if args.sbe_titlebar_opacity != None:
if args.sbe_titlebar_opacity < 0 or args.sbe_titlebar_opacity > 100:
logging.error('Value for --sbe-titlebar-opacity must be an integer betwritten 0 and 100')
raise ValueError
else:
c_sbe_titlebar_opacity = args.sbe_titlebar_opacity
elif args.sbe_titlebar_opacity == None and c_sbe_titlebar_opacity == None:
c_sbe_titlebar_opacity = None

if args.toolbar_opacity != None:
if args.toolbar_opacity < 0 or args.toolbar_opacity > 100:
logging.error('Value for --toolbar-opacity must be an integer betwritten 0 and 100')
raise ValueError
else:
c_toolbar_opacity = args.toolbar_opacity
elif args.toolbar_opacity == None and c_toolbar_opacity == None:
c_toolbar_opacity = None

self._options = {
'light': c_light,
Expand All @@ -316,7 +346,9 @@ def __init__(self, args):
"dbm": c_dark_blend_multiplier,
"on_change_hook": c_on_change_hook,
"sierra_breeze_buttons_color" : c_sierra_breeze_buttons_color,
"konsole_profile" : c_konsole_profile
"konsole_profile" : c_konsole_profile,
"sbe_titlebar_opacity" : c_sbe_titlebar_opacity,
"toolbar_opacity" : c_toolbar_opacity
}

@property
Expand Down Expand Up @@ -939,3 +971,25 @@ def kwin_blend_changes():
except Exception as e:
logging.warning(f'Could not start blend effect (requires Plasma 5.25 or later):\n{e}')
return None

def sierra_breeze_enhanced_titlebar_opacity(opacity):
if opacity != None:
opacity = range_check(opacity,0,100)
sberc = configparser.ConfigParser()
# preserve case
sberc.optionxform = str
if os.path.exists(SBE_RC):
try:
sberc.read(SBE_RC)
if 'Windeco' in sberc:
sberc['Windeco']['BackgroundOpacity'] = str(int(opacity))
reload = True
else:
reload = False
if reload == True:
logging.info(f"Applying SierraBreezeEnhanced titlebar opacity")
with open(SBE_RC, 'w') as configfile:
sberc.write(configfile,space_around_delimiters=False)
kwin_reload()
except Exception as e:
logging.error(f"Error writing SierraBreezeEnhanced titlebar opacity:\n{e}")