4 Commits
6 changed files with 280 additions and 131 deletions
Generated
+100 -25
View File
@@ -23,6 +23,10 @@ name = "accesskit"
version = "0.11.2" version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76eb1adf08c5bcaa8490b9851fd53cca27fa9880076f178ea9d29f05196728a8" checksum = "76eb1adf08c5bcaa8490b9851fd53cca27fa9880076f178ea9d29f05196728a8"
dependencies = [
"enumn",
"serde",
]
[[package]] [[package]]
name = "accesskit_consumer" name = "accesskit_consumer"
@@ -101,6 +105,7 @@ checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"once_cell", "once_cell",
"serde",
"version_check", "version_check",
] ]
@@ -294,12 +299,6 @@ version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1181e1e0d1fce796a03db1ae795d67167da795f9cf4a39c37589e85ef57f26d3" checksum = "1181e1e0d1fce796a03db1ae795d67167da795f9cf4a39c37589e85ef57f26d3"
[[package]]
name = "atomic_refcell"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "112ef6b3f6cb3cb6fc5b6b494ef7a848492cff1ab0ef4de10b0f7d572861c905"
[[package]] [[package]]
name = "atspi" name = "atspi"
version = "0.10.1" version = "0.10.1"
@@ -723,18 +722,19 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]] [[package]]
name = "ecolor" name = "ecolor"
version = "0.22.0" version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e479a7fa3f23d4e794f8b2f8b3568dd4e47886ad1b12c9c095e141cb591eb63" checksum = "cfdf4e52dbbb615cfd30cf5a5265335c217b5fd8d669593cea74a517d9c605af"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"serde",
] ]
[[package]] [[package]]
name = "eframe" name = "eframe"
version = "0.22.0" version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf4596583a2c680c55b6feaa748f74890c4f9cb9c7cb69d6117110444cb65b2f" checksum = "26d9efede6c8905d3fc51a5ec9a506d4da4011bbcae0253d0304580fe40af3f5"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"cocoa", "cocoa",
@@ -748,8 +748,10 @@ dependencies = [
"js-sys", "js-sys",
"log", "log",
"objc", "objc",
"parking_lot",
"percent-encoding", "percent-encoding",
"raw-window-handle", "raw-window-handle",
"static_assertions",
"thiserror", "thiserror",
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-futures", "wasm-bindgen-futures",
@@ -760,41 +762,45 @@ dependencies = [
[[package]] [[package]]
name = "egui" name = "egui"
version = "0.22.0" version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3aef8ec3ae1b772f340170c65bf27d5b8c28f543a0116c844d2ac08d01123e7" checksum = "8bd69fed5fcf4fbb8225b24e80ea6193b61e17a625db105ef0c4d71dde6eb8b7"
dependencies = [ dependencies = [
"accesskit", "accesskit",
"ahash", "ahash",
"epaint", "epaint",
"log", "log",
"nohash-hasher", "nohash-hasher",
"serde",
] ]
[[package]] [[package]]
name = "egui-winit" name = "egui-winit"
version = "0.22.0" version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a49155fd4a0a4fb21224407a91de0030847972ef90fc64edb63621caea61cb2" checksum = "c15479a96d9fadccf5dac690bdc6373b97b8e1c0dd28367058f25a5298da0195"
dependencies = [ dependencies = [
"accesskit_winit", "accesskit_winit",
"arboard", "arboard",
"egui", "egui",
"instant",
"log", "log",
"raw-window-handle", "raw-window-handle",
"smithay-clipboard", "smithay-clipboard",
"web-time",
"webbrowser", "webbrowser",
"winit", "winit",
] ]
[[package]] [[package]]
name = "egui_extras" name = "egui_extras"
version = "0.22.0" version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9278f4337b526f0d57e5375e5a7340a311fa6ee8f9fcc75721ac50af13face02" checksum = "68ffe3fe5c00295f91c2a61a74ee271c32f74049c94ba0b1cea8f26eb478bc07"
dependencies = [ dependencies = [
"egui", "egui",
"enum-map",
"log",
"mime_guess",
"resvg", "resvg",
"serde", "serde",
"tiny-skia", "tiny-skia",
@@ -803,9 +809,9 @@ dependencies = [
[[package]] [[package]]
name = "egui_glow" name = "egui_glow"
version = "0.22.0" version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f8c2752cdf1b0ef5fcda59a898cacabad974d4f5880e92a420b2c917022da64" checksum = "ce6726c08798822280038bbad2e32f4fc3cbed800cd51c6e34e99cd2d60cc1bc"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"egui", "egui",
@@ -818,11 +824,33 @@ dependencies = [
[[package]] [[package]]
name = "emath" name = "emath"
version = "0.22.0" version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3857d743a6e0741cdd60b622a74c7a36ea75f5f8f11b793b41d905d2c9721a4b" checksum = "1ef2b29de53074e575c18b694167ccbe6e5191f7b25fe65175a0d905a32eeec0"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"serde",
]
[[package]]
name = "enum-map"
version = "2.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c188012f8542dee7b3996e44dd89461d64aa471b0a7c71a1ae2f595d259e96e5"
dependencies = [
"enum-map-derive",
"serde",
]
[[package]]
name = "enum-map-derive"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04d0b288e3bb1d861c4403c1774a6f7a798781dfc519b3647df2a3dd4ae95f25"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.37",
] ]
[[package]] [[package]]
@@ -847,20 +875,31 @@ dependencies = [
] ]
[[package]] [[package]]
name = "epaint" name = "enumn"
version = "0.22.0" version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09333964d4d57f40a85338ba3ca5ed4716070ab184dcfed966b35491c5c64f3b" checksum = "c2ad8cef1d801a4686bfd8919f0b30eac4c8e48968c437a6405ded4fb5272d2b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.37",
]
[[package]]
name = "epaint"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58067b840d009143934d91d8dcb8ded054d8301d7c11a517ace0a99bb1e1595e"
dependencies = [ dependencies = [
"ab_glyph", "ab_glyph",
"ahash", "ahash",
"atomic_refcell",
"bytemuck", "bytemuck",
"ecolor", "ecolor",
"emath", "emath",
"log", "log",
"nohash-hasher", "nohash-hasher",
"parking_lot", "parking_lot",
"serde",
] ]
[[package]] [[package]]
@@ -1390,6 +1429,22 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "mime"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "mime_guess"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
dependencies = [
"mime",
"unicase",
]
[[package]] [[package]]
name = "minimal-lexical" name = "minimal-lexical"
version = "0.2.1" version = "0.2.1"
@@ -2346,6 +2401,15 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "unicase"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89"
dependencies = [
"version_check",
]
[[package]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
version = "0.3.13" version = "0.3.13"
@@ -2593,6 +2657,17 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "web-time"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19353897b48e2c4d849a2d73cb0aeb16dc2be4e00c565abfc11eb65a806e47de"
dependencies = [
"js-sys",
"once_cell",
"wasm-bindgen",
]
[[package]] [[package]]
name = "webbrowser" name = "webbrowser"
version = "0.8.11" version = "0.8.11"
+3 -3
View File
@@ -6,8 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
eframe = "0.22.0" eframe = "0.23.0"
egui = "0.22.0" egui = "0.23.0"
[dependencies.confy] [dependencies.confy]
version = "0.5.1" version = "0.5.1"
@@ -19,5 +19,5 @@ version = "1.0.188"
features = ["derive"] features = ["derive"]
[dependencies.egui_extras] [dependencies.egui_extras]
version = "0.22.0" version = "0.23.0"
features = ["svg"] features = ["svg"]
+7
View File
@@ -3,5 +3,12 @@ A GUI client to interact with my (private for now) fork of the 3rd party linux [
The client mainly supports controlling the keyboard RGB for now, but there's plans for fan control as well (maybe. depends on how busy I am and how complicated this gets) The client mainly supports controlling the keyboard RGB for now, but there's plans for fan control as well (maybe. depends on how busy I am and how complicated this gets)
## Screenshots
Dynamic lighting control
![dynamic](https://github.com/illusionman1212/predator-ng/blob/master/docs/screenshots/dynamic_kb.png?raw=true)
Static lighting control
![static](https://github.com/illusionman1212/predator-ng/blob/master/docs/screenshots/static_kb.png?raw=true)
## Disclaimer ## Disclaimer
This client is primarily made for use with my PT314-52s and custom changes of the kernel module and is not guaranteed to work with other models. Use at your own risk. This client is primarily made for use with my PT314-52s and custom changes of the kernel module and is not guaranteed to work with other models. Use at your own risk.
Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

+106 -39
View File
@@ -105,7 +105,7 @@ fn update_dynamic(dynamic_dev: &mut File, cfg: Config) {
dynamic_data[7] = cfg.kb.color[2]; dynamic_data[7] = cfg.kb.color[2];
dynamic_data[9] = 1; dynamic_data[9] = 1;
dynamic_dev.write(&dynamic_data).expect("Failed to write to dynamic device"); dynamic_dev.write_all(&dynamic_data).expect("Failed to write to dynamic device");
} }
fn change_brightness(dynamic_dev: &mut File, cfg: Config) { fn change_brightness(dynamic_dev: &mut File, cfg: Config) {
@@ -119,7 +119,7 @@ fn change_brightness(dynamic_dev: &mut File, cfg: Config) {
dynamic_data[7] = if cfg.kb.mode == KBLightMode::Static {0} else {cfg.kb.color[2]}; dynamic_data[7] = if cfg.kb.mode == KBLightMode::Static {0} else {cfg.kb.color[2]};
dynamic_data[9] = 1; dynamic_data[9] = 1;
dynamic_dev.write(&dynamic_data).expect("Failed to write to dynamic device"); dynamic_dev.write_all(&dynamic_data).expect("Failed to write to dynamic device");
} }
fn switch_to_static(static_dev: &mut File, dynamic_dev: &mut File, cfg: Config) { fn switch_to_static(static_dev: &mut File, dynamic_dev: &mut File, cfg: Config) {
@@ -130,7 +130,7 @@ fn switch_to_static(static_dev: &mut File, dynamic_dev: &mut File, cfg: Config)
dynamic_data[2] = cfg.kb.brightness; dynamic_data[2] = cfg.kb.brightness;
dynamic_data[9] = 1; // This is needed for PT314-52s and possibly other models dynamic_data[9] = 1; // This is needed for PT314-52s and possibly other models
dynamic_dev.write(&dynamic_data).expect("Failed to write to static device"); dynamic_dev.write_all(&dynamic_data).expect("Failed to write to static device");
} }
} }
@@ -149,7 +149,7 @@ fn write_to_static_dev(static_dev: &mut File, cfg: Config, zone: usize) {
cfg.kb.zones[1].enabled as u8, cfg.kb.zones[1].enabled as u8,
cfg.kb.zones[2].enabled as u8 cfg.kb.zones[2].enabled as u8
]; ];
static_dev.write(&static_data).expect("Failed to write to static device"); static_dev.write_all(&static_data).expect("Failed to write to static device");
} }
fn toggle_zone(static_dev: &mut File, cfg: Config, zone_num: usize) { fn toggle_zone(static_dev: &mut File, cfg: Config, zone_num: usize) {
@@ -165,7 +165,7 @@ fn toggle_zone(static_dev: &mut File, cfg: Config, zone_num: usize) {
cfg.kb.zones[2].enabled as u8 // Zone 3 enabled cfg.kb.zones[2].enabled as u8 // Zone 3 enabled
]; ];
static_dev.write(&static_data).expect("Failed to write to static device"); static_dev.write_all(&static_data).expect("Failed to write to static device");
} }
fn show_dynamic_kb_lighting_pane(ui: &mut egui::Ui, dynamic_dev: &mut File, cfg: &mut Config, config_path: PathBuf) { fn show_dynamic_kb_lighting_pane(ui: &mut egui::Ui, dynamic_dev: &mut File, cfg: &mut Config, config_path: PathBuf) {
@@ -259,13 +259,37 @@ fn show_dynamic_kb_lighting_pane(ui: &mut egui::Ui, dynamic_dev: &mut File, cfg:
let _ = confy::store_path(config_path.clone(), &cfg); let _ = confy::store_path(config_path.clone(), &cfg);
} }
}); });
ui.vertical(|ui| {
ui.label("Custom Color");
if ui.color_edit_button_srgb(&mut cfg.kb.color).changed() {
update_dynamic(dynamic_dev, *cfg);
let _ = confy::store_path(config_path.clone(), &cfg);
}
ui.horizontal(|ui| {
let r = ui.label("R");
if ui.add(egui::DragValue::new(&mut cfg.kb.color[0])).labelled_by(r.id).changed() {
update_dynamic(dynamic_dev, *cfg);
let _ = confy::store_path(config_path.clone(), &cfg);
}
let g = ui.label("G");
if ui.add(egui::DragValue::new(&mut cfg.kb.color[1])).labelled_by(g.id).changed() {
update_dynamic(dynamic_dev, *cfg);
let _ = confy::store_path(config_path.clone(), &cfg);
}
let b = ui.label("B");
if ui.add(egui::DragValue::new(&mut cfg.kb.color[2])).labelled_by(b.id).changed() {
update_dynamic(dynamic_dev, *cfg);
let _ = confy::store_path(config_path.clone(), &cfg);
}
});
});
} }
fn show_static_kb_lighting_pane(ui: &mut egui::Ui, static_dev: &mut File, cfg: &mut Config, config_path: PathBuf, prohibit_tex: TextureHandle) { fn show_static_kb_lighting_pane(ui: &mut egui::Ui, static_dev: &mut File, cfg: &mut Config, config_path: PathBuf, prohibit_tex: TextureHandle) {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.vertical(|ui| { ui.vertical(|ui| {
ui.label("Zone 1"); ui.label("Zone 1");
ui.horizontal(|ui| { ui.horizontal_wrapped(|ui| {
let mut picker_rect = ui.available_rect_before_wrap(); let mut picker_rect = ui.available_rect_before_wrap();
if ui.add(toggle(&mut cfg.kb.zones[0].enabled)).changed() { if ui.add(toggle(&mut cfg.kb.zones[0].enabled)).changed() {
@@ -282,29 +306,34 @@ fn show_static_kb_lighting_pane(ui: &mut egui::Ui, static_dev: &mut File, cfg: &
}); });
if !cfg.kb.zones[0].enabled { if !cfg.kb.zones[0].enabled {
let pos = [egui::pos2(picker_rect.max.x - 2.0, picker_rect.max.y - 7.0)]; let pos = [egui::pos2(picker_rect.max.x - 2.0, picker_rect.max.y - 7.0)];
ui.put(egui::Rect::from_points(&pos), egui::Image::new(prohibit_tex.id(), egui::vec2(10.0, 10.0))); ui.put(egui::Rect::from_points(&pos), egui::Image::new(&prohibit_tex).max_size(egui::Vec2::new(14.0, 14.0)));
} }
}); });
ui.add_space(10.0); ui.add_space(10.0);
ui.add_enabled_ui(cfg.kb.zones[0].enabled, |ui| {
ui.horizontal(|ui| { ui.horizontal(|ui| {
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[0].color[0])).changed() { let r = ui.label("R");
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[0].color[0])).labelled_by(r.id).changed() {
write_to_static_dev(static_dev, *cfg, 1); write_to_static_dev(static_dev, *cfg, 1);
let _ = confy::store_path(config_path.clone(), &cfg); let _ = confy::store_path(config_path.clone(), &cfg);
} }
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[0].color[1])).changed() { let g = ui.label("G");
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[0].color[1])).labelled_by(g.id).changed() {
write_to_static_dev(static_dev, *cfg, 1); write_to_static_dev(static_dev, *cfg, 1);
let _ = confy::store_path(config_path.clone(), &cfg); let _ = confy::store_path(config_path.clone(), &cfg);
} }
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[0].color[2])).changed() { let b = ui.label("B");
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[0].color[2])).labelled_by(b.id).changed() {
write_to_static_dev(static_dev, *cfg, 1); write_to_static_dev(static_dev, *cfg, 1);
let _ = confy::store_path(config_path.clone(), &cfg); let _ = confy::store_path(config_path.clone(), &cfg);
} }
}); });
})
}); });
ui.separator(); ui.separator();
ui.vertical(|ui| { ui.vertical(|ui| {
ui.label("Zone 2"); ui.label("Zone 2");
ui.horizontal(|ui| { ui.horizontal_wrapped(|ui| {
let mut picker_rect = ui.available_rect_before_wrap(); let mut picker_rect = ui.available_rect_before_wrap();
if ui.add(toggle(&mut cfg.kb.zones[1].enabled)).changed() { if ui.add(toggle(&mut cfg.kb.zones[1].enabled)).changed() {
@@ -321,29 +350,34 @@ fn show_static_kb_lighting_pane(ui: &mut egui::Ui, static_dev: &mut File, cfg: &
}); });
if !cfg.kb.zones[1].enabled { if !cfg.kb.zones[1].enabled {
let pos = [egui::pos2(picker_rect.max.x - 2.0, picker_rect.max.y - 7.0)]; let pos = [egui::pos2(picker_rect.max.x - 2.0, picker_rect.max.y - 7.0)];
ui.put(egui::Rect::from_points(&pos), egui::Image::new(prohibit_tex.id(), egui::vec2(10.0, 10.0))); ui.put(egui::Rect::from_points(&pos), egui::Image::new(&prohibit_tex).max_size(egui::Vec2::new(14.0, 14.0)));
} }
}); });
ui.add_space(10.0); ui.add_space(10.0);
ui.add_enabled_ui(cfg.kb.zones[1].enabled, |ui| {
ui.horizontal(|ui| { ui.horizontal(|ui| {
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[1].color[0])).changed() { let r = ui.label("R");
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[1].color[0])).labelled_by(r.id).changed() {
write_to_static_dev(static_dev, *cfg, 2); write_to_static_dev(static_dev, *cfg, 2);
let _ = confy::store_path(config_path.clone(), &cfg); let _ = confy::store_path(config_path.clone(), &cfg);
} }
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[1].color[1])).changed() { let g = ui.label("G");
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[1].color[1])).labelled_by(g.id).changed() {
write_to_static_dev(static_dev, *cfg, 2); write_to_static_dev(static_dev, *cfg, 2);
let _ = confy::store_path(config_path.clone(), &cfg); let _ = confy::store_path(config_path.clone(), &cfg);
} }
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[1].color[2])).changed() { let b = ui.label("B");
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[1].color[2])).labelled_by(b.id).changed() {
write_to_static_dev(static_dev, *cfg, 2); write_to_static_dev(static_dev, *cfg, 2);
let _ = confy::store_path(config_path.clone(), &cfg); let _ = confy::store_path(config_path.clone(), &cfg);
} }
}); });
}); });
});
ui.separator(); ui.separator();
ui.vertical(|ui| { ui.vertical(|ui| {
ui.label("Zone 3"); ui.label("Zone 3");
ui.horizontal(|ui| { ui.horizontal_wrapped(|ui| {
let mut picker_rect = ui.available_rect_before_wrap(); let mut picker_rect = ui.available_rect_before_wrap();
if ui.add(toggle(&mut cfg.kb.zones[2].enabled)).changed() { if ui.add(toggle(&mut cfg.kb.zones[2].enabled)).changed() {
@@ -360,26 +394,65 @@ fn show_static_kb_lighting_pane(ui: &mut egui::Ui, static_dev: &mut File, cfg: &
}); });
if !cfg.kb.zones[2].enabled { if !cfg.kb.zones[2].enabled {
let pos = [egui::pos2(picker_rect.max.x - 2.0, picker_rect.max.y - 7.0)]; let pos = [egui::pos2(picker_rect.max.x - 2.0, picker_rect.max.y - 7.0)];
ui.put(egui::Rect::from_points(&pos), egui::Image::new(prohibit_tex.id(), egui::vec2(10.0, 10.0))); ui.put(egui::Rect::from_points(&pos), egui::Image::new(&prohibit_tex).max_size(egui::Vec2::new(10.0, 10.0)));
} }
}); });
ui.add_space(10.0); ui.add_space(10.0);
ui.add_enabled_ui(cfg.kb.zones[2].enabled, |ui| {
ui.horizontal(|ui| { ui.horizontal(|ui| {
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[2].color[0])).changed() { let r = ui.label("R");
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[2].color[0])).labelled_by(r.id).changed() {
write_to_static_dev(static_dev, *cfg, 3); write_to_static_dev(static_dev, *cfg, 3);
let _ = confy::store_path(config_path.clone(), &cfg); let _ = confy::store_path(config_path.clone(), &cfg);
} }
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[2].color[1])).changed() { let g = ui.label("G");
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[2].color[1])).labelled_by(g.id).changed() {
write_to_static_dev(static_dev, *cfg, 3); write_to_static_dev(static_dev, *cfg, 3);
let _ = confy::store_path(config_path.clone(), &cfg); let _ = confy::store_path(config_path.clone(), &cfg);
} }
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[2].color[2])).changed() { let b = ui.label("B");
if ui.add(egui::DragValue::new(&mut cfg.kb.zones[2].color[2])).labelled_by(b.id).changed() {
write_to_static_dev(static_dev, *cfg, 3); write_to_static_dev(static_dev, *cfg, 3);
let _ = confy::store_path(config_path.clone(), &cfg); let _ = confy::store_path(config_path.clone(), &cfg);
} }
}); });
}); });
}); });
});
}
fn check_devices(options: &eframe::NativeOptions) -> Result<(File, File), String> {
let static_dev = OpenOptions::new()
.write(true)
.create(false)
.open("/dev/acer-gkbbl-static-0");
let dynamic_dev = OpenOptions::new()
.write(true)
.create(false)
.open("/dev/acer-gkbbl-0");
match static_dev.is_err() || dynamic_dev.is_err() {
true => {
eprintln!("[ERROR]: Could not open device files");
let _ = eframe::run_simple_native("Predator-ng", options.clone(), move |ctx, _frame| {
egui::CentralPanel::default().show(ctx, |ui| {
ui.colored_label(egui::Color32::RED, egui::RichText::new("Error: could not open device files").heading());
ui.horizontal_wrapped(|ui| {
ui.label("Please make sure you have the kernel module loaded, and that both");
ui.label(egui::RichText::new("/dev/acer-gkbbl-0").code());
ui.label("and");
ui.label(egui::RichText::new("/dev/acer-gkbbl-static-0").code());
ui.label("exist");
});
});
});
Err("Could not open device files".to_string())
}
false => Ok((static_dev.unwrap(), dynamic_dev.unwrap())),
}
} }
fn initial_load(config_path: PathBuf, static_dev: &mut File, dynamic_dev: &mut File) -> Result<Config, confy::ConfyError> { fn initial_load(config_path: PathBuf, static_dev: &mut File, dynamic_dev: &mut File) -> Result<Config, confy::ConfyError> {
@@ -395,29 +468,20 @@ fn initial_load(config_path: PathBuf, static_dev: &mut File, dynamic_dev: &mut F
} }
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut static_dev = OpenOptions::new() let options = eframe::NativeOptions {
.write(true) initial_window_size: Some(egui::vec2(640.0, 480.0)),
.create(false) //min_window_size: Some(egui::vec2(620.0, 400.0)),
.open("/dev/acer-gkbbl-static-0") ..Default::default()
.expect("No static device found. Please make sure the kernel module is loaded first."); };
let mut dynamic_dev = OpenOptions::new()
.write(true)
.create(false)
.open("/dev/acer-gkbbl-0")
.expect("No dynamic device found. Please make sure the kernel module is loaded first.");
match check_devices(&options) {
Ok((mut static_dev, mut dynamic_dev)) => {
let config_home = var("XDG_CONFIG_HOME") let config_home = var("XDG_CONFIG_HOME")
.or_else(|_| var("HOME").map(|home|format!("{}/.config", home))).unwrap(); .or_else(|_| var("HOME").map(|home|format!("{}/.config", home))).unwrap();
let config_path = Path::new(&config_home).join("predator-ng").to_path_buf(); let config_path = Path::new(&config_home).join("predator-ng").to_path_buf();
let mut cfg = initial_load(config_path.clone(), &mut static_dev, &mut dynamic_dev)?; let mut cfg = initial_load(config_path.clone(), &mut static_dev, &mut dynamic_dev)?;
let options = eframe::NativeOptions {
initial_window_size: Some(egui::vec2(640.0, 480.0)),
..Default::default()
};
let prohibit_svg_bytes = include_bytes!("../assets/prohibit.svg"); let prohibit_svg_bytes = include_bytes!("../assets/prohibit.svg");
let _ = eframe::run_simple_native("Predator-ng", options, move |ctx, _frame| { let _ = eframe::run_simple_native("Predator-ng", options, move |ctx, _frame| {
@@ -429,16 +493,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
ui.label("Keyboard Lighting Mode: "); ui.label("Keyboard Lighting Mode: ");
if ui.radio_value(&mut cfg.kb.mode, KBLightMode::Static, "Static").clicked() { if ui.radio_value(&mut cfg.kb.mode, KBLightMode::Static, "Static").clicked() {
switch_to_static(&mut static_dev, &mut dynamic_dev, cfg); switch_to_static(&mut static_dev, &mut dynamic_dev, cfg);
let _ = confy::store_path(config_path.clone(), &cfg); let _ = confy::store_path(config_path.clone(), cfg);
} }
if ui.radio_value(&mut cfg.kb.mode, KBLightMode::Dynamic, "Dynamic").clicked() { if ui.radio_value(&mut cfg.kb.mode, KBLightMode::Dynamic, "Dynamic").clicked() {
update_dynamic(&mut dynamic_dev, cfg); update_dynamic(&mut dynamic_dev, cfg);
let _ = confy::store_path(config_path.clone(), &cfg); let _ = confy::store_path(config_path.clone(), cfg);
} }
ui.label("Keyboard Brightness: "); ui.label("Keyboard Brightness: ");
if ui.add(egui::Slider::new(&mut cfg.kb.brightness, 0..=100).show_value(false).step_by(25.0)).changed() { if ui.add(egui::Slider::new(&mut cfg.kb.brightness, 0..=100).show_value(false).step_by(25.0)).changed() {
change_brightness(&mut dynamic_dev, cfg); change_brightness(&mut dynamic_dev, cfg);
let _ = confy::store_path(config_path.clone(), &cfg); let _ = confy::store_path(config_path.clone(), cfg);
} }
}); });
ui.add_space(15.0); ui.add_space(15.0);
@@ -456,4 +520,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}); });
Ok(()) Ok(())
}
Err(_) => Ok(())
}
} }