diff --git a/scripts/app-theme.py b/scripts/app-theme.py index 1d3acc8..9afa3af 100644 --- a/scripts/app-theme.py +++ b/scripts/app-theme.py @@ -24,7 +24,7 @@ def integrate(path,line,state,enabled): def migrate_thunar(path,state): # Migrate only unchanged bundled versions; preserve user-edited CSS. # OTA preserves application configs, including users' own CSS changes. - if not path.is_symlink() and path.exists() and hashlib.sha256(path.read_bytes()).hexdigest() in {'06f3268dbda4afead19facbbc10bc4276323a49707c9d14fc0e77beeec0452aa','c54aacc5240c3467a9653fc1f49c83893895592f19a6ec85e85755a3af2bc3e4'}: + if not path.is_symlink() and path.exists() and hashlib.sha256(path.read_bytes()).hexdigest() in {'06f3268dbda4afead19facbbc10bc4276323a49707c9d14fc0e77beeec0452aa','c54aacc5240c3467a9653fc1f49c83893895592f19a6ec85e85755a3af2bc3e4','58df7b6b5e5b9a1a2c7de5d426782a00b01c46bce4c62c0ac90f9c899c7bd5af','d416067c81f6762ce3391af2fb1dff7a356157a81ebb2c98de35189300ca8774'}: backup(path,state) write(path,(Path(__file__).resolve().parents[1]/'setup/config/gtk-3.0/thunar.css').read_text()) diff --git a/setup/config/gtk-3.0/thunar.css b/setup/config/gtk-3.0/thunar.css index fbfc0f0..cbeb9d4 100644 --- a/setup/config/gtk-3.0/thunar.css +++ b/setup/config/gtk-3.0/thunar.css @@ -23,9 +23,8 @@ /* Paned separator between sidebar and main view */ .thunar paned > separator { - min-width: 4px; - margin-right: -7px; - margin-left: -7px; + min-width: 1px; + margin: 0; background: none; background-image: none; box-shadow: none; @@ -34,13 +33,11 @@ /* Main file view frame */ .thunar .frame.standard-view { - padding: 10px; - margin: 10px 15px 0 0; - border-radius: 15px; - background-color: @view_bg_color; - animation: fading 400ms ease forwards; - opacity: 0; - animation-delay: 250ms; + padding: 4px; + margin: 0; + border: none; + border-radius: 0; + background-color: @window_bg_color; } .thunar .standard-view .view:not(:selected):not(.rubberband), @@ -66,16 +63,15 @@ /* Tabs */ .thunar header.top { background: none; - padding: 0 10px 0 0; - margin: 3px 0 -3px -2px; + padding: 0 6px; + margin: 0; } .thunar header.top tabs .reorderable-page { margin: 0; - transition: all ease 300ms; } .thunar header.top tabs .reorderable-page + .reorderable-page { - margin: 0 0 0 10px; + margin-left: 4px; } .thunar header.top tabs .reorderable-page:hover { @@ -93,18 +89,14 @@ ============================================================================= */ .thunar .sidebar { - padding: 0 20px; - background: none; - animation: fading 600ms ease forwards; - animation-delay: 100ms; - opacity: 0; + padding: 6px 8px; + background: @view_bg_color; } .thunar .sidebar .view { - padding: 8px 4px; - border-radius: 10px; + padding: 6px 4px; + border-radius: 4px; background: none; - transition: all ease 300ms; } .thunar .sidebar .view:hover { @@ -112,58 +104,69 @@ } .thunar .sidebar .view:selected { - background: alpha(@accent_color, 0.15); - color: @window_fg_color; + background: alpha(@accent_color, 0.10); + color: @accent_color; } /* ============================================================================= Path Bar & Location Buttons ============================================================================= */ +.thunar .location-button, .thunar .path-bar-button { + min-height: 24px; margin: 0; - padding: 8px 5px; - transition: all ease 0.4s; + padding: 4px 8px; + border: 1px solid transparent; + border-radius: 6px; + background: alpha(@accent_color, 0.04); + box-shadow: none; +} + +.thunar .location-button:hover, +.thunar .path-bar-button:hover { + background: alpha(@accent_color, 0.08); } .thunar .location-button.toggle:checked, .thunar .path-bar-button.toggle:checked { - padding: 8px 25px; background: alpha(@accent_color, 0.15); color: @window_fg_color; - box-shadow: none; } -.thunar .location-button.path-bar-button:not(:checked) { - background-color: @view_bg_color; +.thunar .titlebar { + padding: 6px 0 4px; } -.thunar .location-button.path-bar-button:not(:checked):hover { - background: alpha(@accent_color, 0.08); - color: @window_fg_color; -} +/* ============================================================================= + Toolbar + ============================================================================= */ -.thunar .location-button.toggle+.location-button.toggle:checked { - margin-left: 0px; - padding: 0 25px; +.thunar toolbar { + padding: 4px 6px; + border: none; + background: @window_bg_color; + box-shadow: none; } -.thunar .titlebar { - padding: 15px 0 5px 0; +.thunar toolbar button.image-button { + min-width: 24px; + min-height: 24px; + padding: 4px; + margin: 0; + border: 1px solid transparent; + border-radius: 6px; + background: none; + box-shadow: none; } -/* ============================================================================= - Buttons - ============================================================================= */ - -.thunar button.toggle:checked { - color: @window_fg_color; +.thunar toolbar button.image-button:hover { + background: alpha(@accent_color, 0.08); } -.thunar .image-button { - padding: 8px; - margin: 0 0 0 8px; - transition: all ease 0.4s; +.thunar toolbar button.image-button:checked { + background: alpha(@accent_color, 0.15); + color: @window_fg_color; } /* ============================================================================= @@ -171,10 +174,10 @@ ============================================================================= */ .thunar statusbar { - background-color: @view_bg_color; - border-radius: 15px; - padding: 10px 10px; - margin: 15px 5px 15px -10px; + background-color: @window_bg_color; + border-radius: 0; + padding: 4px 8px; + margin: 0; color: @window_fg_color; } @@ -187,13 +190,31 @@ margin: 15px; } +.thunar toolbar entry { + min-height: 30px; + margin: 0 8px; + padding: 2px 10px; + border: 1px solid transparent; + border-radius: 7px; + background: alpha(@window_fg_color, 0.07); + color: @window_fg_color; + box-shadow: none; +} -/* ============================================================================= - Animation - ============================================================================= */ +.thunar toolbar entry:focus { + border-color: alpha(@accent_color, 0.65); +} -@keyframes fading { - to { - opacity: 1; - } +.thunar .standard-view treeview.view { + font-size: 14px; +} + +.thunar .standard-view treeview.view header button { + min-height: 24px; + padding: 0 8px; + border: none; + background: transparent; + color: alpha(@window_fg_color, 0.55); + box-shadow: none; + font-weight: normal; } diff --git a/tests/fixtures/thunar-inset.css b/tests/fixtures/thunar-inset.css new file mode 100644 index 0000000..fbfc0f0 --- /dev/null +++ b/tests/fixtures/thunar-inset.css @@ -0,0 +1,199 @@ +/* Thunar theme */ + +/* ============================================================================= + Window & Background + ============================================================================= */ + +.thunar.background { + background: @window_bg_color; + color: @window_fg_color; +} + +.thunar .titlebar { + background: inherit; +} + +.thunar .titlebutton.close { + margin: 0 15px 0 0; +} + +/* ============================================================================= + Layout Containers + ============================================================================= */ + +/* Paned separator between sidebar and main view */ +.thunar paned > separator { + min-width: 4px; + margin-right: -7px; + margin-left: -7px; + background: none; + background-image: none; + box-shadow: none; +} + + +/* Main file view frame */ +.thunar .frame.standard-view { + padding: 10px; + margin: 10px 15px 0 0; + border-radius: 15px; + background-color: @view_bg_color; + animation: fading 400ms ease forwards; + opacity: 0; + animation-delay: 250ms; +} + +.thunar .standard-view .view:not(:selected):not(.rubberband), +.thunar .standard-view .view *:not(:selected):not(.rubberband):not(rubberband) { + background-color: transparent; +} + +/* Keep labels opaque over a subtle palette tint in both icon and list views. */ +.thunar .standard-view iconview cell:selected, +.thunar .standard-view .view:selected, +.thunar .standard-view .view *:selected { + background-color: @theme_selected_bg_color; + color: @theme_selected_fg_color; +} + +.thunar .rubberband, +.thunar rubberband { + background-color: alpha(@accent_color, 0.15); + border: 1px solid @accent_color; +} + + +/* Tabs */ +.thunar header.top { + background: none; + padding: 0 10px 0 0; + margin: 3px 0 -3px -2px; +} + +.thunar header.top tabs .reorderable-page { + margin: 0; + transition: all ease 300ms; +} +.thunar header.top tabs .reorderable-page + .reorderable-page { + margin: 0 0 0 10px; +} + +.thunar header.top tabs .reorderable-page:hover { + background-color: alpha(@accent_color, 0.08); + +} +.thunar header.top tabs .reorderable-page:checked { + color: @window_fg_color; + background-color: alpha(@accent_color, 0.15); + +} + +/* ============================================================================= + Sidebar Navigation + ============================================================================= */ + +.thunar .sidebar { + padding: 0 20px; + background: none; + animation: fading 600ms ease forwards; + animation-delay: 100ms; + opacity: 0; +} + +.thunar .sidebar .view { + padding: 8px 4px; + border-radius: 10px; + background: none; + transition: all ease 300ms; +} + +.thunar .sidebar .view:hover { + background: alpha(@window_fg_color, 0.1); +} + +.thunar .sidebar .view:selected { + background: alpha(@accent_color, 0.15); + color: @window_fg_color; +} + +/* ============================================================================= + Path Bar & Location Buttons + ============================================================================= */ + +.thunar .path-bar-button { + margin: 0; + padding: 8px 5px; + transition: all ease 0.4s; +} + +.thunar .location-button.toggle:checked, +.thunar .path-bar-button.toggle:checked { + padding: 8px 25px; + background: alpha(@accent_color, 0.15); + color: @window_fg_color; + box-shadow: none; +} + +.thunar .location-button.path-bar-button:not(:checked) { + background-color: @view_bg_color; +} + +.thunar .location-button.path-bar-button:not(:checked):hover { + background: alpha(@accent_color, 0.08); + color: @window_fg_color; +} + +.thunar .location-button.toggle+.location-button.toggle:checked { + margin-left: 0px; + padding: 0 25px; +} + +.thunar .titlebar { + padding: 15px 0 5px 0; +} + +/* ============================================================================= + Buttons + ============================================================================= */ + +.thunar button.toggle:checked { + color: @window_fg_color; +} + +.thunar .image-button { + padding: 8px; + margin: 0 0 0 8px; + transition: all ease 0.4s; +} + +/* ============================================================================= + Status Bar + ============================================================================= */ + +.thunar statusbar { + background-color: @view_bg_color; + border-radius: 15px; + padding: 10px 10px; + margin: 15px 5px 15px -10px; + color: @window_fg_color; +} + + +/* ============================================================================= + Image preview + ============================================================================= */ + +.thunar box.vertical .image { + margin: 15px; +} + + +/* ============================================================================= + Animation + ============================================================================= */ + +@keyframes fading { + to { + opacity: 1; + } +} diff --git a/tests/fixtures/thunar-pass1.css b/tests/fixtures/thunar-pass1.css new file mode 100644 index 0000000..43e4396 --- /dev/null +++ b/tests/fixtures/thunar-pass1.css @@ -0,0 +1,191 @@ +/* Thunar theme */ + +/* ============================================================================= + Window & Background + ============================================================================= */ + +.thunar.background { + background: @window_bg_color; + color: @window_fg_color; +} + +.thunar .titlebar { + background: inherit; +} + +.thunar .titlebutton.close { + margin: 0 15px 0 0; +} + +/* ============================================================================= + Layout Containers + ============================================================================= */ + +/* Paned separator between sidebar and main view */ +.thunar paned > separator { + min-width: 1px; + margin: 0; + background: none; + background-image: none; + box-shadow: none; +} + + +/* Main file view frame */ +.thunar .frame.standard-view { + padding: 4px; + margin: 0; + border: none; + border-radius: 0; + background-color: @view_bg_color; +} + +.thunar .standard-view .view:not(:selected):not(.rubberband), +.thunar .standard-view .view *:not(:selected):not(.rubberband):not(rubberband) { + background-color: transparent; +} + +/* Keep labels opaque over a subtle palette tint in both icon and list views. */ +.thunar .standard-view iconview cell:selected, +.thunar .standard-view .view:selected, +.thunar .standard-view .view *:selected { + background-color: @theme_selected_bg_color; + color: @theme_selected_fg_color; +} + +.thunar .rubberband, +.thunar rubberband { + background-color: alpha(@accent_color, 0.15); + border: 1px solid @accent_color; +} + + +/* Tabs */ +.thunar header.top { + background: none; + padding: 0 6px; + margin: 0; +} + +.thunar header.top tabs .reorderable-page { + margin: 0; +} +.thunar header.top tabs .reorderable-page + .reorderable-page { + margin-left: 4px; +} + +.thunar header.top tabs .reorderable-page:hover { + background-color: alpha(@accent_color, 0.08); + +} +.thunar header.top tabs .reorderable-page:checked { + color: @window_fg_color; + background-color: alpha(@accent_color, 0.15); + +} + +/* ============================================================================= + Sidebar Navigation + ============================================================================= */ + +.thunar .sidebar { + padding: 0 6px; + background: none; +} + +.thunar .sidebar .view { + padding: 5px 4px; + border-radius: 6px; + background: none; +} + +.thunar .sidebar .view:hover { + background: alpha(@window_fg_color, 0.1); +} + +.thunar .sidebar .view:selected { + background: alpha(@accent_color, 0.15); + color: @window_fg_color; +} + +/* ============================================================================= + Path Bar & Location Buttons + ============================================================================= */ + +.thunar .location-button, +.thunar .path-bar-button { + min-height: 24px; + margin: 0; + padding: 4px 8px; + border: 1px solid transparent; + border-radius: 6px; + background: alpha(@accent_color, 0.04); + box-shadow: none; +} + +.thunar .location-button:hover, +.thunar .path-bar-button:hover { + background: alpha(@accent_color, 0.08); +} + +.thunar .location-button.toggle:checked, +.thunar .path-bar-button.toggle:checked { + background: alpha(@accent_color, 0.15); + color: @window_fg_color; +} + +.thunar .titlebar { + padding: 6px 0 4px; +} + +/* ============================================================================= + Toolbar + ============================================================================= */ + +.thunar toolbar { + padding: 4px 6px; + border: none; + background: @window_bg_color; + box-shadow: none; +} + +.thunar toolbar button.image-button { + min-width: 24px; + min-height: 24px; + padding: 4px; + margin: 0; + border: 1px solid transparent; + border-radius: 6px; + background: none; + box-shadow: none; +} + +.thunar toolbar button.image-button:hover { + background: alpha(@accent_color, 0.08); +} + +.thunar toolbar button.image-button:checked { + background: alpha(@accent_color, 0.15); + color: @window_fg_color; +} + +/* ============================================================================= + Status Bar + ============================================================================= */ + +.thunar statusbar { + background-color: @window_bg_color; + border-radius: 0; + padding: 4px 8px; + margin: 0; + color: @window_fg_color; +} + + +/* ============================================================================= + Image preview + ============================================================================= */ + +.thunar box.vertical .image { + margin: 15px; +} diff --git a/tests/gtk-theme.py b/tests/gtk-theme.py index 47043fd..9a2d1bd 100644 --- a/tests/gtk-theme.py +++ b/tests/gtk-theme.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 """Generate real GTK palettes and parse the shipped Thunar CSS without a display.""" import json +from itertools import product import os from pathlib import Path import subprocess @@ -44,8 +45,8 @@ def isolated_run(command, **kwargs): text='#242a38', subtext='#5a6374', green='#35683b', yellow='#7e611f', red='#aa3856')), ] for mode, colors in profiles: - for source in ('midnight', 'wallpaper'): - fixture = ROOT/'tests/fixtures'/('thunar-solid.css' if source == 'wallpaper' else 'thunar-legacy.css') + for source, revision in product(('midnight', 'wallpaper'), ('legacy', 'solid', 'inset', 'pass1')): + fixture = ROOT/'tests/fixtures'/f'thunar-{revision}.css' with tempfile.TemporaryDirectory(prefix='modesty-gtk-check-') as temporary: directory = Path(temporary) config = directory/'config' @@ -64,6 +65,7 @@ def isolated_run(command, **kwargs): 'on_surface_variant':'subtext', 'outline':'subtext', 'outline_variant':'subtext', 'shadow':'bg', 'secondary':'yellow', 'tertiary':'green', 'error':'red'} data['wallpaperData'] = {'colors':{role:{mode:{'color':colors[key]}} for role, key in roles.items()}} + data['wallpaperData']['colors']['surface_container_lowest'][mode]['color'] = '#09090c' if mode == 'dark' else '#ffffff' with patch.dict(os.environ, XDG_CONFIG_HOME=str(config)), patch.object(appearance.subprocess, 'run', side_effect=isolated_run): appearance.apply(data, directory/'state') generated = json.loads((directory/'state/matugen/input.json').read_text()) @@ -80,12 +82,14 @@ def isolated_run(command, **kwargs): provider = Gtk.CssProvider() provider.connect('parsing-error', lambda provider, section, error: errors.append(str(error))) provider.load_from_path(str(gtk/'gtk.css')) - assert not errors, (mode, source, errors) + assert not errors, (mode, source, revision, errors) assert (gtk/'gtk.css').read_text().count('modesty-generated.css') == 1 if '--live' in sys.argv: # Query actual GTK style resolution, not a CSS substring. No # window is shown and no desktop settings or state are changed. from gi.repository import Gdk + def hex_color(rgba): + return '#'+''.join(f'{round(channel*255):02x}' for channel in (rgba.red,rgba.green,rgba.blue)) Gtk.init([]) settings = Gtk.Settings.get_default() settings.props.gtk_enable_animations = False @@ -96,7 +100,9 @@ def isolated_run(command, **kwargs): border = rubberband.get_style_context().get_border_color(Gtk.StateFlags.NORMAL) assert border.alpha == 1, 'Drag-selection border became translucent' window.remove(rubberband) - frame = Gtk.ScrolledWindow(); frame.get_style_context().add_class('standard-view'); window.add(frame) + frame = Gtk.ScrolledWindow(); frame.get_style_context().add_class('standard-view'); frame.get_style_context().add_class('frame'); window.add(frame) + background = frame.get_style_context().get_background_color(Gtk.StateFlags.NORMAL) + assert background.alpha == 1 and hex_color(background) == colors['bg'], (mode, source, background.to_string()) for kind in (Gtk.IconView, Gtk.TreeView): view = kind(); view.get_style_context().add_class('view'); frame.add(view) # ExoIconView adds the cell class while painting each item. @@ -113,8 +119,6 @@ def isolated_run(command, **kwargs): context.set_state(state) text = context.get_color(state) background = context.get_background_color(state) - def hex_color(rgba): - return '#'+''.join(f'{round(channel*255):02x}' for channel in (rgba.red,rgba.green,rgba.blue)) assert hex_color(text) == colors['text'], (mode, kind, state, text.to_string()) assert hex_color(background) == colors['accent'] and abs(background.alpha-.18)<.001, (mode, kind, state, background.to_string()) rgb = [int(colors['bg'][i:i+2],16) for i in (1,3,5)] @@ -125,12 +129,13 @@ def hex_color(rgba): sidebar = Gtk.Box(); sidebar.get_style_context().add_class('sidebar'); window.add(sidebar) tree = Gtk.TreeView(); tree.get_style_context().add_class('view'); sidebar.add(tree) context = tree.get_style_context(); context.set_state(Gtk.StateFlags.SELECTED) - assert hex_color(context.get_color(Gtk.StateFlags.SELECTED)) == colors['text'] + text = context.get_color(Gtk.StateFlags.SELECTED) + assert text.alpha == 1 and hex_color(text) == colors['accent'] background = context.get_background_color(Gtk.StateFlags.SELECTED) - for base in (colors['bg'], colors['surface']): - rgb = [int(base[i:i+2],16) for i in (1,3,5)] - blended = '#'+''.join(f'{round(c*255*background.alpha+b*(1-background.alpha)):02x}' for c,b in zip((background.red,background.green,background.blue),rgb)) - assert contrast(colors['text'], blended) >= 4.5 + base = sidebar.get_style_context().get_background_color(Gtk.StateFlags.NORMAL) + assert base.alpha == 1 and hex_color(base) == generated['colors']['surface_container_lowest']['default']['color'] + blended = '#'+''.join(f'{round((c*background.alpha+b*(1-background.alpha))*255):02x}' for c,b in zip((background.red,background.green,background.blue),(base.red,base.green,base.blue))) + assert contrast(hex_color(text), blended) >= 4.5, (mode, source, hex_color(text), blended) window.destroy() Gtk.StyleContext.remove_provider_for_screen(Gdk.Screen.get_default(), provider) # A user-modified stylesheet must survive subsequent palette changes. @@ -149,4 +154,4 @@ def hex_color(rgba): with patch.dict(os.environ, XDG_CONFIG_HOME=str(config)), patch.object(appearance.subprocess, 'run', side_effect=isolated_run): appearance.apply(data, directory/'state') assert custom.is_symlink() and linked.read_bytes() == original -print('PASS GTK palette generation, named/wallpaper selection foreground, dark/light contrast and Thunar CSS parsing'+('; native icon/list selection states' if '--live' in sys.argv else '')) +print('PASS GTK palette generation, named/wallpaper selection foreground, dark/light contrast, legacy/solid/inset/pass1 migrations and Thunar CSS parsing'+('; native icon/list selection states and sidebar contrast' if '--live' in sys.argv else ''))