mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:02:45 +00:00 
			
		
		
		
	WindowServer+LibGUI: Implement basic color theming
Color themes are loaded from .ini files in /res/themes/
The theme can be switched from the "Themes" section in the system menu.
The basic mechanism is that WindowServer broadcasts a SharedBuffer with
all of the color values of the current theme. Clients receive this with
the response to their initial WindowServer::Greet handshake.
When the theme is changed, WindowServer tells everyone by sending out
an UpdateSystemTheme message with a new SharedBuffer to use.
This does feel somewhat bloated somehow, but I'm sure we can iterate on
it over time and improve things.
To get one of the theme colors, use the Color(SystemColor) constructor:
    painter.fill_rect(rect, SystemColor::HoverHighlight);
Some things don't work 100% right without a reboot. Specifically, when
constructing a GWidget, it will set its own background and foreground
colors based on the current SystemColor::Window and SystemColor::Text.
The widget is then stuck with these values, and they don't update on
system theme change, only on app restart.
All in all though, this is pretty cool. Merry Christmas! :^)
			
			
This commit is contained in:
		
							parent
							
								
									7c8bbea995
								
							
						
					
					
						commit
						411058b2a3
					
				
					 50 changed files with 525 additions and 178 deletions
				
			
		
							
								
								
									
										73
									
								
								Libraries/LibDraw/SystemTheme.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								Libraries/LibDraw/SystemTheme.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,73 @@ | |||
| #include <LibCore/CConfigFile.h> | ||||
| #include <LibDraw/SystemTheme.h> | ||||
| 
 | ||||
| static SystemTheme dummy_theme; | ||||
| static const SystemTheme* theme_page = &dummy_theme; | ||||
| static RefPtr<SharedBuffer> theme_buffer; | ||||
| 
 | ||||
| const SystemTheme& current_system_theme() | ||||
| { | ||||
|     ASSERT(theme_page); | ||||
|     return *theme_page; | ||||
| } | ||||
| 
 | ||||
| int current_system_theme_buffer_id() | ||||
| { | ||||
|     ASSERT(theme_buffer); | ||||
|     return theme_buffer->shared_buffer_id(); | ||||
| } | ||||
| 
 | ||||
| void set_system_theme(SharedBuffer& buffer) | ||||
| { | ||||
|     theme_buffer = buffer; | ||||
|     theme_page = (SystemTheme*)theme_buffer->data(); | ||||
| } | ||||
| 
 | ||||
| RefPtr<SharedBuffer> load_system_theme(const String& path) | ||||
| { | ||||
|     auto file = CConfigFile::open(path); | ||||
|     auto buffer = SharedBuffer::create_with_size(sizeof(SystemTheme)); | ||||
| 
 | ||||
|     dbg() << "Created shared buffer with id " << buffer->shared_buffer_id(); | ||||
| 
 | ||||
|     auto* data = (SystemTheme*)buffer->data(); | ||||
| 
 | ||||
|     auto get = [&](auto& name) { | ||||
|         auto color_string = file->read_entry("Colors", name); | ||||
|         auto color = Color::from_string(color_string); | ||||
|         if (!color.has_value()) | ||||
|             return Color(Color::Black); | ||||
|         dbg() << "Parsed system color '" << name << "' = " << color.value(); | ||||
|         return color.value(); | ||||
|     }; | ||||
| 
 | ||||
|     data->desktop_background = get("DesktopBackground"); | ||||
|     data->threed_highlight = get("ThreedHighlight"); | ||||
|     data->threed_shadow1 = get("ThreedShadow1"); | ||||
|     data->threed_shadow2 = get("ThreedShadow2"); | ||||
|     data->hover_highlight = get("HoverHighlight"); | ||||
|     data->window = get("Window"); | ||||
|     data->text = get("Text"); | ||||
|     data->base = get("Base"); | ||||
|     data->desktop_background = get("DesktopBackground"); | ||||
|     data->active_window_border1 = get("ActiveWindowBorder1"); | ||||
|     data->active_window_border2 = get("ActiveWindowBorder2"); | ||||
|     data->active_window_title = get("ActiveWindowTitle"); | ||||
|     data->inactive_window_border1 = get("InactiveWindowBorder1"); | ||||
|     data->inactive_window_border2 = get("InactiveWindowBorder2"); | ||||
|     data->inactive_window_title = get("InactiveWindowTitle"); | ||||
|     data->moving_window_border1 = get("MovingWindowBorder1"); | ||||
|     data->moving_window_border2 = get("MovingWindowBorder2"); | ||||
|     data->moving_window_title = get("MovingWindowTitle"); | ||||
|     data->highlight_window_border1 = get("HighlightWindowBorder1"); | ||||
|     data->highlight_window_border2 = get("HighlightWindowBorder2"); | ||||
|     data->highlight_window_title = get("HighlightWindowTitle"); | ||||
|     data->menu_stripe = get("MenuStripe"); | ||||
|     data->menu_base = get("MenuBase"); | ||||
|     data->menu_selection = get("MenuSelection"); | ||||
| 
 | ||||
|     buffer->seal(); | ||||
|     buffer->share_globally(); | ||||
| 
 | ||||
|     return buffer; | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling