Skip to content
Open
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The most basic dynamic function row daemon possible
## Dependencies
cairo, libinput, freetype, fontconfig, uinput enabled in kernel config

Install the following packages on Fedora:

```
dnf install -y glib2-devel cairo-devel pango-devel cairo-gobject-devel libinput-devel gdk-pixbuf2-devel systemd-devel
```

## License

tiny-dfr is licensed under the MIT license, as included in the [LICENSE](LICENSE) file.
Expand Down
4 changes: 4 additions & 0 deletions share/tiny-dfr/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ AdaptiveBrightness = true
# Accepted values are 0-255
ActiveBrightness = 128

# Set this to true if you want to be able to switch the default layer
# (function or media keys) by pressing the Fn key
FnToggleLayers = false

# This key defines the contents of the primary layer
# (the one with F{number} keys)
# You can change the individual buttons, add, or remove them
Expand Down
4 changes: 4 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct Config {
pub font_face: FontFace,
pub adaptive_brightness: bool,
pub active_brightness: u32,
pub fn_toggle_layers: bool,
}

#[derive(Deserialize)]
Expand All @@ -33,6 +34,7 @@ struct ConfigProxy {
font_template: Option<String>,
adaptive_brightness: Option<bool>,
active_brightness: Option<u32>,
fn_toggle_layers: Option<bool>,
primary_layer_keys: Option<Vec<ButtonConfig>>,
media_layer_keys: Option<Vec<ButtonConfig>>
}
Expand Down Expand Up @@ -74,6 +76,7 @@ fn load_config() -> (Config, [FunctionLayer; 2]) {
base.media_layer_keys = user.media_layer_keys.or(base.media_layer_keys);
base.primary_layer_keys = user.primary_layer_keys.or(base.primary_layer_keys);
base.active_brightness = user.active_brightness.or(base.active_brightness);
base.fn_toggle_layers = user.fn_toggle_layers.or(base.fn_toggle_layers);
};
let media_layer = FunctionLayer::with_config(base.media_layer_keys.unwrap());
let fkey_layer = FunctionLayer::with_config(base.primary_layer_keys.unwrap());
Expand All @@ -82,6 +85,7 @@ fn load_config() -> (Config, [FunctionLayer; 2]) {
show_button_outlines: base.show_button_outlines.unwrap(),
enable_pixel_shift: base.enable_pixel_shift.unwrap(),
adaptive_brightness: base.adaptive_brightness.unwrap(),
fn_toggle_layers: base.fn_toggle_layers.unwrap(),
font_face: load_font(&base.font_template.unwrap()),
active_brightness: base.active_brightness.unwrap()
};
Expand Down
15 changes: 14 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ fn real_main(drm: &mut DrmBackend) {
let mut surface = ImageSurface::create(Format::ARgb32, DFR_STRIDE, DFR_WIDTH).unwrap();
let mut active_layer = 0;
let mut needs_complete_redraw = true;
let mut waiting_for_touch_event = false;

let mut input_tb = Libinput::new_with_udev(Interface);
let mut input_main = Libinput::new_with_udev(Interface);
Expand Down Expand Up @@ -434,7 +435,7 @@ fn real_main(drm: &mut DrmBackend) {
}
},
Event::Keyboard(KeyboardEvent::Key(key)) => {
if key.key() == Key::Fn as u32 {
if Key::from_code(key.key() as u16) == Ok(Key::Fn) {
let new_layer = match key.key_state() {
KeyState::Pressed => 1,
KeyState::Released => 0
Expand All @@ -443,12 +444,24 @@ fn real_main(drm: &mut DrmBackend) {
active_layer = new_layer;
needs_complete_redraw = true;
}
if cfg.fn_toggle_layers {
match key.key_state() {
KeyState::Pressed => waiting_for_touch_event = true,
KeyState::Released => if waiting_for_touch_event {
layers.swap(0, 1);
needs_complete_redraw = true;
}
};
}
}
},
Event::Touch(te) => {
if Some(te.device()) != digitizer || backlight.current_bl() == 0 {
continue
}
if cfg.fn_toggle_layers {
waiting_for_touch_event = false;
}
match te {
TouchEvent::Down(dn) => {
let x = dn.x_transformed(DFR_WIDTH as u32);
Expand Down