Skip to content

Commit 03a8e1b

Browse files
Display an escape key on Macs without a physical one
1 parent 448689b commit 03a8e1b

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

share/tiny-dfr/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ PrimaryLayerKeys = [
5252
# if both are present, the behavior is undefined.
5353
# For the list of supported key codes see
5454
# https://docs.rs/input-linux/latest/input_linux/enum.Key.html
55+
# Note that the escape key is not specified here, as it is added
56+
# automatically on Macs without a physical one
5557
{ Text = "F1", Action = "F1" },
5658
{ Text = "F2", Action = "F2" },
5759
{ Text = "F3", Action = "F3" },

src/config.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
};
55
use anyhow::Error;
66
use cairo::FontFace;
7-
use crate::FunctionLayer;
7+
use crate::{FunctionLayer, Button};
88
use crate::fonts::{FontConfig, Pattern};
99
use freetype::Library as FtLibrary;
1010
use 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;

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ fn real_main(drm: &mut DrmBackend) {
341341
let mut uinput = UInputHandle::new(OpenOptions::new().write(true).open("/dev/uinput").unwrap());
342342
let mut backlight = BacklightManager::new();
343343
let mut cfg_mgr = ConfigManager::new();
344-
let (mut cfg, mut layers) = cfg_mgr.load_config();
344+
let (mut cfg, mut layers) = cfg_mgr.load_config(width);
345345
let mut pixel_shift = PixelShiftManager::new();
346346

347347
// drop privileges to input and video group
@@ -391,7 +391,7 @@ fn real_main(drm: &mut DrmBackend) {
391391
let mut digitizer: Option<InputDevice> = None;
392392
let mut touches = HashMap::new();
393393
loop {
394-
if cfg_mgr.update_config(&mut cfg, &mut layers) {
394+
if cfg_mgr.update_config(&mut cfg, &mut layers, width) {
395395
active_layer = 0;
396396
needs_complete_redraw = true;
397397
}

0 commit comments

Comments
 (0)