@@ -4,7 +4,7 @@ use std::{
44} ;
55use anyhow:: Error ;
66use cairo:: FontFace ;
7- use crate :: FunctionLayer ;
7+ use crate :: { FunctionLayer , Button } ;
88use crate :: fonts:: { FontConfig , Pattern } ;
99use freetype:: Library as FtLibrary ;
1010use input_linux:: Key ;
@@ -61,7 +61,7 @@ fn load_font(name: &str) -> FontFace {
6161 FontFace :: create_from_ft ( & face) . unwrap ( )
6262}
6363
64- fn load_config ( ) -> ( Config , [ FunctionLayer ; 2 ] ) {
64+ fn load_config ( width : u16 ) -> ( Config , [ FunctionLayer ; 2 ] ) {
6565 let mut base = toml:: from_str :: < ConfigProxy > ( & read_to_string ( "/usr/share/tiny-dfr/config.toml" ) . unwrap ( ) ) . unwrap ( ) ;
6666 let user = read_to_string ( USER_CFG_PATH ) . map_err :: < Error , _ > ( |e| e. into ( ) )
6767 . and_then ( |r| Ok ( toml:: from_str :: < ConfigProxy > ( & r) ?) ) ;
@@ -77,7 +77,12 @@ fn load_config() -> (Config, [FunctionLayer; 2]) {
7777 } ;
7878 let media_layer = FunctionLayer :: with_config ( base. media_layer_keys . unwrap ( ) ) ;
7979 let fkey_layer = FunctionLayer :: with_config ( base. primary_layer_keys . unwrap ( ) ) ;
80- let layers = if base. media_layer_default . unwrap ( ) { [ media_layer, fkey_layer] } else { [ fkey_layer, media_layer] } ;
80+ let mut layers = if base. media_layer_default . unwrap ( ) { [ media_layer, fkey_layer] } else { [ fkey_layer, media_layer] } ;
81+ if width >= 2170 {
82+ for layer in & mut layers {
83+ layer. buttons . insert ( 0 , Button :: new_text ( "esc" . to_string ( ) , Key :: Esc ) ) ;
84+ }
85+ }
8186 let cfg = Config {
8287 show_button_outlines : base. show_button_outlines . unwrap ( ) ,
8388 enable_pixel_shift : base. enable_pixel_shift . unwrap ( ) ,
@@ -110,10 +115,10 @@ impl ConfigManager {
110115 inotify_fd, watch_desc
111116 }
112117 }
113- pub fn load_config ( & self ) -> ( Config , [ FunctionLayer ; 2 ] ) {
114- load_config ( )
118+ pub fn load_config ( & self , width : u16 ) -> ( Config , [ FunctionLayer ; 2 ] ) {
119+ load_config ( width )
115120 }
116- pub fn update_config ( & mut self , cfg : & mut Config , layers : & mut [ FunctionLayer ; 2 ] ) -> bool {
121+ pub fn update_config ( & mut self , cfg : & mut Config , layers : & mut [ FunctionLayer ; 2 ] , width : u16 ) -> bool {
117122 if self . watch_desc . is_none ( ) {
118123 self . watch_desc = arm_inotify ( & self . inotify_fd ) ;
119124 return false ;
@@ -128,7 +133,7 @@ impl ConfigManager {
128133 if evt. wd != self . watch_desc . unwrap ( ) {
129134 continue
130135 }
131- let parts = load_config ( ) ;
136+ let parts = load_config ( width ) ;
132137 * cfg = parts. 0 ;
133138 * layers = parts. 1 ;
134139 ret = true ;
0 commit comments