Skip to content
Merged
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
801 changes: 490 additions & 311 deletions Cargo.lock

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "legion-kb-rgb"
version = "0.20.2"
version = "0.20.3"
authors = ["4JX"]
edition = "2021"
homepage = "https://github.com/4JX/L5P-Keyboard-RGB"
Expand All @@ -13,14 +13,14 @@ license = "GPL-3.0"
legion-rgb-driver = { path = "../driver" }

# Cli
clap = { version = "4.5.23", features = ["color", "cargo", "derive"] }
clap = { version = "4.5.30", features = ["color", "cargo", "derive"] }

# Ui
eframe = { version = "0.30.0", features = ["x11", "wayland"] }
egui-modal = "0.6.0"
# egui-modal = { git = "https://github.com/n00kii/egui-modal", rev = "8443238" }
egui_file = "0.20.0"
egui-notify = "0.18.0"
eframe = { version = "0.31.0", features = ["x11", "wayland"] }
# egui-modal = "0.6.0"
egui-modal = { git = "https://github.com/n00kii/egui-modal", rev = "74add2407bb945992bd15c79fcedc2af2ee0fb4a" }
egui_file = "0.22.0"
egui-notify = "0.19.0"
# egui-notify = { git = "https://github.com/ItsEthra/egui-notify", rev = "bc5eb67" }

# App window, taskbar and tray icon loading
Expand All @@ -31,37 +31,37 @@ scrap = { git = "https://github.com/rustdesk/rustdesk", rev = "40af9dc", feature
"wayland",
# "linux-pkg-config",
] }
fast_image_resize = "5.1.0"
fast_image_resize = "5.1.2"
# default-features = false just removes the use_wasm feature that removes a lot of unecessary slack
# since this app wont ever use the web
# photon-rs = { version = "0.3.2", default-features = false }
photon-rs = { git = "https://github.com/silvia-odwyer/photon", rev = "d084f68", default-features = false }


# Keyboard and mouse grabbing
device_query = "2.1.0"
device_query = "3.0.0"

rand = "0.8.5"
strum = "0.26.3"
strum_macros = "0.26.4"
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.128"
rand = "0.9.0"
strum = "0.27.1"
strum_macros = "0.27.1"
serde = { version = "1.0.218", features = ["derive"] }
serde_json = "1.0.139"
color-eyre = "0.6.3"
sysinfo = "0.33.1"
crossbeam-channel = "0.5.14"
thiserror = "1.0.63"
thiserror = "2.0.11"
single-instance = "0.3.3"
open = "5.3.1"
open = "5.3.2"
error-stack = "0.5.0"
winapi = { version = "0.3.9", features = ["consoleapi", "wincon"] }

# Tray icon
[target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies]
tray-icon = { version = "0.19.1", default-features = false }
tray-icon = { version = "0.20.0", default-features = false }

[target.'cfg(target_os = "linux")'.dependencies]
tray-icon = "0.19.1"
gtk = "0.18.1"
tray-icon = "0.20.0"
gtk = "0.18.2"

# Fix versions to stop cargo from yelling about dependency resolution

Expand Down
5 changes: 1 addition & 4 deletions app/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ pub fn try_cli() -> Result<GuiCommand, CliError> {

fn handle_cli_output(output_type: OutputType) -> Result<GuiCommand, CliError> {
let manager_result = manager::EffectManager::new(manager::OperationMode::Cli);
let instance_not_unique = manager_result
.as_ref()
.err()
.map_or(false, |err| &ManagerCreationError::InstanceAlreadyRunning == err.current_context());
let instance_not_unique = manager_result.as_ref().err().is_some_and(|err| &ManagerCreationError::InstanceAlreadyRunning == err.current_context());

if matches!(output_type, OutputType::Profile(..) | OutputType::Custom(..)) && instance_not_unique {
println!("Another instance of the program is already running, please close it before starting a new one.");
Expand Down
21 changes: 17 additions & 4 deletions app/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,28 @@ pub enum Effects {
fps: u8,
saturation_boost: f32,
},
SmoothWave,
Swipe,
SmoothWave {
mode: SwipeMode,
clean_with_black: bool,
},
Swipe {
mode: SwipeMode,
clean_with_black: bool,
},
Disco,
Christmas,
Fade,
Temperature,
Ripple,
}

#[derive(Default, Debug, Clone, Copy, Serialize, Deserialize, EnumIter, EnumString, PartialEq)]
pub enum SwipeMode {
#[default]
Change,
Fill,
}

impl PartialEq for Effects {
fn eq(&self, other: &Self) -> bool {
core::mem::discriminant(self) == core::mem::discriminant(other)
Expand All @@ -36,13 +49,13 @@ impl Effects {
}

pub fn takes_direction(self) -> bool {
matches!(self, Self::Wave | Self::SmoothWave | Self::Swipe { .. })
matches!(self, Self::Wave | Self::SmoothWave { .. } | Self::Swipe { .. })
}

pub fn takes_speed(self) -> bool {
matches!(
self,
Self::Breath | Self::Smooth | Self::Wave | Self::Lightning | Self::SmoothWave | Self::Swipe | Self::Disco | Self::Fade | Self::Ripple
Self::Breath | Self::Smooth | Self::Wave | Self::Lightning | Self::SmoothWave { .. } | Self::Swipe { .. } | Self::Disco | Self::Fade | Self::Ripple
)
}

Expand Down
13 changes: 6 additions & 7 deletions app/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use device_query::{DeviceQuery, Keycode};
#[cfg(debug_assertions)]
use eframe::egui::style::DebugOptions;
use eframe::{
egui::{CentralPanel, Context, Frame, Layout, ScrollArea, Style, TopBottomPanel, ViewportCommand},
egui::{CentralPanel, Context, CornerRadius, Frame, Layout, ScrollArea, Style, TopBottomPanel, ViewportCommand},
emath::Align,
epaint::{Color32, Rounding, Vec2},
epaint::{Color32, Vec2},
CreationContext,
};

Expand All @@ -22,7 +22,7 @@ use tray_icon::menu::MenuEvent;
use crate::{
cli::OutputType,
enums::Effects,
manager::{self, custom_effect::CustomEffect, profile::Profile, EffectManager, ManagerCreationError},
manager::{self, custom_effect::CustomEffect, profile::Profile, show_effect_ui, EffectManager, ManagerCreationError},
persist::Settings,
tray::{QUIT_ID, SHOW_ID},
DENY_HIDING,
Expand Down Expand Up @@ -242,7 +242,7 @@ impl eframe::App for App {
});

CentralPanel::default()
.frame(Frame::none().inner_margin(self.theme.spacing.large).fill(Color32::from_gray(26)))
.frame(Frame::new().inner_margin(self.theme.spacing.large).fill(Color32::from_gray(26)))
.show(ctx, |ui| {
ui.style_mut().spacing.item_spacing = Vec2::splat(self.theme.spacing.large);
self.show_ui_elements(ctx, ui);
Expand Down Expand Up @@ -358,7 +358,7 @@ impl App {
}

Frame {
rounding: Rounding::same(6.0),
corner_radius: CornerRadius::same(6),
fill: Color32::from_gray(20),
..Frame::default()
}
Expand All @@ -382,8 +382,7 @@ impl App {

fn show_effect_ui(&mut self, ui: &mut eframe::egui::Ui) {
ui.add_enabled_ui(self.loaded_effect.is_none(), |ui| {
let mut effect = self.current_profile.effect;
effect.show_ui(ui, &mut self.current_profile, &mut self.state_changed, &self.theme);
show_effect_ui(ui, &mut self.current_profile, &mut self.state_changed, &self.theme);
});
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/gui/modals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn manager_error(ctx: &Context) -> bool {

if let Ok(list) = legion_rgb_driver::find_possible_keyboards() {
modal.body(ui, "Please attach the following list of identifiers when making an issue:");
Frame::none().fill(Color32::from_gray(20)).inner_margin(5.0).rounding(6.0).show(ui, |ui| {
Frame::new().fill(Color32::from_gray(20)).inner_margin(5.0).corner_radius(6.0).show(ui, |ui| {
ScrollArea::vertical().show(ui, |ui| {
if list.is_empty() {
ui.label("No candidates found");
Expand Down
15 changes: 5 additions & 10 deletions app/src/gui/saved_items.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use eframe::{
egui::{Context, Frame, RichText, ScrollArea, Ui},
epaint::{Color32, Rounding},
};
use eframe::egui::{Color32, Context, CornerRadius, Frame, RichText, ScrollArea, Ui};
use egui_modal::Modal;

use crate::manager::{custom_effect::CustomEffect, profile::Profile};
Expand Down Expand Up @@ -113,11 +110,9 @@ impl SavedItems {
}
}
Tab::CustomEffects => {
if loaded_effect.is_playing() {
if ui.button("+").clicked() {
self.new_item_name.clear();
effect_modal.open();
}
if loaded_effect.is_playing() && ui.button("+").clicked() {
self.new_item_name.clear();
effect_modal.open();
}

if ui.button("-").clicked() {
Expand All @@ -136,7 +131,7 @@ impl SavedItems {
});

Frame {
rounding: Rounding::same(6.0),
corner_radius: CornerRadius::same(6),
fill: Color32::from_gray(20),
..Frame::default()
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use eframe::{egui::IconData, epaint::Vec2};
use gui::App;

const APP_ICON: &[u8; 14987] = include_bytes!("../res/trayIcon.ico");
const WINDOW_SIZE: Vec2 = Vec2::new(500., 400.);
const WINDOW_SIZE: Vec2 = Vec2::new(500., 460.);
#[cfg(target_os = "linux")]
pub static DENY_HIDING: LazyLock<bool> = LazyLock::new(|| std::env::var("WAYLAND_DISPLAY").is_ok());
#[cfg(not(target_os = "linux"))]
Expand Down Expand Up @@ -123,7 +123,7 @@ fn start_ui(output_type: OutputType, hide_window: bool) {
#[cfg(not(target_os = "linux"))]
let tray_c = _tray_icon.clone();

let app = App::new(output_type, has_tray.clone(), visible.clone());
let app = App::new(output_type, has_tray, visible);

eframe::run_native(
"Legion RGB",
Expand Down
2 changes: 1 addition & 1 deletion app/src/manager/custom_effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ impl CustomEffect {
}
}

impl<'a> StorageTrait<'a> for CustomEffect {}
impl StorageTrait<'_> for CustomEffect {}
57 changes: 22 additions & 35 deletions app/src/manager/effects/christmas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use rand::Rng;

use crate::manager::Inner;

pub fn play(manager: &mut Inner, thread_rng: &mut rand::rngs::ThreadRng) {
pub fn play(manager: &mut Inner, rng: &mut rand::rngs::ThreadRng) {
let xmas_color_array = [[255, 10, 10], [255, 255, 20], [30, 255, 30], [70, 70, 255]];
let subeffect_count = 4;
let mut last_subeffect = -1;
while !manager.stop_signals.manager_stop_signal.load(Ordering::SeqCst) {
let mut subeffect = thread_rng.gen_range(0..subeffect_count);
let mut subeffect = rng.random_range(0..subeffect_count);
while last_subeffect == subeffect {
subeffect = thread_rng.gen_range(0..subeffect_count);
subeffect = rng.random_range(0..subeffect_count);
}
last_subeffect = subeffect;

Expand All @@ -25,12 +25,12 @@ pub fn play(manager: &mut Inner, thread_rng: &mut rand::rngs::ThreadRng) {
}
}
1 => {
let color_1_index = thread_rng.gen_range(0..4);
let color_1_index = rng.random_range(0..4);
let used_colors_1: [u8; 3] = xmas_color_array[color_1_index];

let mut color_2_index = thread_rng.gen_range(0..4);
let mut color_2_index = rng.random_range(0..4);
while color_1_index == color_2_index {
color_2_index = thread_rng.gen_range(0..4);
color_2_index = rng.random_range(0..4);
}
let used_colors_2: [u8; 3] = xmas_color_array[color_2_index];

Expand All @@ -45,36 +45,23 @@ pub fn play(manager: &mut Inner, thread_rng: &mut rand::rngs::ThreadRng) {
let steps = 100;
manager.keyboard.transition_colors_to(&[0; 12], steps, 1).unwrap();
let mut used_colors_array: [u8; 12] = [0; 12];
let left_or_right = thread_rng.gen_range(0..2);
if left_or_right == 0 {
for color in xmas_color_array {
for j in (0..12).step_by(3) {
used_colors_array[j] = color[0];
used_colors_array[j + 1] = color[1];
used_colors_array[j + 2] = color[2];
manager.keyboard.transition_colors_to(&used_colors_array, steps, 1).unwrap();
}
for j in (0..12).step_by(3) {
used_colors_array[j] = 0;
used_colors_array[j + 1] = 0;
used_colors_array[j + 2] = 0;
manager.keyboard.transition_colors_to(&used_colors_array, steps, 1).unwrap();
}
let left_or_right = rng.random_range(0..2);

// A little hacky to avoid type mismatch errors, but you gotta do what you gotta do
let range: Vec<usize> = if left_or_right == 0 { (0..4).collect() } else { (0..4).rev().collect() };

for color in xmas_color_array {
for j in range.clone() {
used_colors_array[j * 3] = color[0];
used_colors_array[j * 3 + 1] = color[1];
used_colors_array[j * 3 + 2] = color[2];
manager.keyboard.transition_colors_to(&used_colors_array, steps, 1).unwrap();
}
} else {
for i in 0..4 {
for j in (0..12).step_by(3) {
used_colors_array[11 - j] = xmas_color_array[3 - i][0];
used_colors_array[11 - (j + 1)] = xmas_color_array[3 - i][1];
used_colors_array[11 - (j + 2)] = xmas_color_array[3 - i][2];
manager.keyboard.transition_colors_to(&used_colors_array, steps, 1).unwrap();
}
for j in (0..12).step_by(3) {
used_colors_array[11 - j] = 0;
used_colors_array[11 - (j + 1)] = 0;
used_colors_array[11 - (j + 2)] = 0;
manager.keyboard.transition_colors_to(&used_colors_array, steps, 1).unwrap();
}
for j in range.clone() {
used_colors_array[j * 3] = 0;
used_colors_array[j * 3 + 1] = 0;
used_colors_array[j * 3 + 2] = 0;
manager.keyboard.transition_colors_to(&used_colors_array, steps, 1).unwrap();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/manager/effects/disco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use rand::Rng;

use crate::manager::{profile::Profile, Inner};

pub fn play(manager: &mut Inner, p: &Profile, thread_rng: &mut rand::rngs::ThreadRng) {
pub fn play(manager: &mut Inner, p: &Profile, rng: &mut rand::rngs::ThreadRng) {
while !manager.stop_signals.manager_stop_signal.load(Ordering::SeqCst) {
let colors = [[255, 0, 0], [255, 255, 0], [0, 255, 0], [0, 255, 255], [0, 0, 255], [255, 0, 255]];
let colors_index = thread_rng.gen_range(0..6);
let colors_index = rng.random_range(0..6);
let new_values = colors[colors_index];

let zone_index = thread_rng.gen_range(0..4);
let zone_index = rng.random_range(0..4);
manager.keyboard.set_zone_by_index(zone_index, new_values).unwrap();
thread::sleep(Duration::from_millis(2000 / (u64::from(p.speed) * 4)));
}
Expand Down
8 changes: 4 additions & 4 deletions app/src/manager/effects/lightning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use rand::{rngs::ThreadRng, Rng};

use crate::manager::{profile::Profile, Inner};

pub fn play(manager: &mut Inner, p: &Profile, thread_rng: &mut ThreadRng) {
pub fn play(manager: &mut Inner, p: &Profile, rng: &mut ThreadRng) {
while !manager.stop_signals.manager_stop_signal.load(Ordering::SeqCst) {
let profile_array = p.rgb_array();

if manager.stop_signals.manager_stop_signal.load(Ordering::SeqCst) {
break;
}
let zone_index = thread_rng.gen_range(0..4);
let steps = thread_rng.gen_range(50..=200);
let zone_index = rng.random_range(0..4);
let steps = rng.random_range(50..=200);

let mut arr = [0; 12];
let zone_start = zone_index * 3;
Expand All @@ -23,7 +23,7 @@ pub fn play(manager: &mut Inner, p: &Profile, thread_rng: &mut ThreadRng) {

manager.keyboard.set_colors_to(&arr).unwrap();
manager.keyboard.transition_colors_to(&[0; 12], steps / p.speed, 5).unwrap();
let sleep_time = thread_rng.gen_range(100..=2000);
let sleep_time = rng.random_range(100..=2000);
thread::sleep(Duration::from_millis(sleep_time));
}
}
Loading
Loading