Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
4JX committed Sep 19, 2024
1 parent 7b19a1f commit 649ec7c
Show file tree
Hide file tree
Showing 12 changed files with 2,774 additions and 1,038 deletions.
3,554 changes: 2,670 additions & 884 deletions Cargo.lock

Large diffs are not rendered by default.

45 changes: 23 additions & 22 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,46 @@ license = "GPL-3.0"
legion-rgb-driver = { path = "../driver" }

# Cli
clap = { version = "4.1.2", features = ["color", "cargo", "derive"] }
clap = { version = "4.5.17", features = ["color", "cargo", "derive"] }

# Ui
eframe = "0.23.0"
egui-modal = "0.2.5"
eframe = "0.28.1"
egui-modal = "0.4.0"
# egui-modal = { git = "https://github.com/n00kii/egui-modal", rev = "8443238" }
egui_file = "0.11.0"
egui-notify = "0.10.0"
egui_file = "0.18.0"
egui-notify = "0.15.0"
# egui-notify = { git = "https://github.com/ItsEthra/egui-notify", rev = "bc5eb67" }

# App window, taskbar and tray icon loading
image = "0.24.5"
image = "0.25.2"

# AmbientLight effect
scrap = { git = "https://github.com/rustdesk/rustdesk", rev = "6c15dd6", features = [
scrap = { git = "https://github.com/rustdesk/rustdesk", rev = "40af9dc", features = [
"wayland",
"linux-pkg-config",
] }
fast_image_resize = "2.4.0"
fast_image_resize = "4.2.1"
# 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 = "3e8a2a6", default-features = false }
photon-rs = { git = "https://github.com/silvia-odwyer/photon", rev = "d084f68", default-features = false }


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

rand = "0.8.5"
strum = "0.25.0"
strum_macros = "0.25.2"
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.91"
color-eyre = "0.6.2"
sysinfo = "0.29.0"
crossbeam-channel = "0.5.8"
thiserror = "1.0.38"
strum = "0.26.3"
strum_macros = "0.26.4"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
color-eyre = "0.6.3"
sysinfo = "0.31.4"
crossbeam-channel = "0.5.13"
thiserror = "1.0.63"
single-instance = "0.3.3"
open = "5.0.0"
error-stack = "0.4.1"
open = "5.3.0"
error-stack = "0.5.0"
winapi = { version = "0.3.9", features = ["consoleapi", "wincon"] }

# Fix versions to stop cargo from yelling about dependency resolution
Expand All @@ -60,10 +61,10 @@ winapi = { version = "0.3.9", features = ["consoleapi", "wincon"] }


[target.'cfg(target_os = "windows")'.dependencies]
tray-item = { version = "0.8.0" }
tray-item = { version = "0.10.0" }

[target.'cfg(target_os = "linux")'.dependencies]
tray-item = { version = "0.8.0", features = ["ksni"] }
tray-item = { version = "0.10.0", features = ["ksni"] }

[build-dependencies]
windres = "0.2.2"
Expand Down
45 changes: 21 additions & 24 deletions app/src/effects/ambient.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
num::NonZeroU32,
sync::atomic::Ordering,
thread,
time::{Duration, Instant},
Expand All @@ -8,12 +7,12 @@ use std::{
use fast_image_resize as fr;

use fr::Resizer;
use scrap::{Capturer, Display, Frame, TraitCapturer};
use scrap::{Capturer, Display, Frame, TraitCapturer, TraitPixelBuffer};

#[derive(Clone, Copy)]
struct ScreenDimensions {
src: (NonZeroU32, NonZeroU32),
dest: (NonZeroU32, NonZeroU32),
src: (u32, u32),
dest: (u32, u32),
}

pub(super) struct AmbientLight;
Expand All @@ -24,15 +23,15 @@ impl AmbientLight {
//Display setup
let display = Display::all().unwrap().remove(0);

let mut capturer = Capturer::new(display, false).expect("Couldn't begin capture.");
let mut capturer = Capturer::new(display).expect("Couldn't begin capture.");

let dimensions = ScreenDimensions {
src: (NonZeroU32::new(capturer.width() as u32).unwrap(), NonZeroU32::new(capturer.height() as u32).unwrap()),
dest: (NonZeroU32::new(4).unwrap(), NonZeroU32::new(1).unwrap()),
src: (capturer.width() as u32, capturer.height() as u32),
dest: (4, 1),
};

let seconds_per_frame = Duration::from_nanos(1_000_000_000 / u64::from(fps));
let mut resizer = fr::Resizer::new(fr::ResizeAlg::Convolution(fr::FilterType::Box));
let mut resizer = fr::Resizer::new();

#[cfg(target_os = "windows")]
let mut try_gdi = 1;
Expand All @@ -43,7 +42,7 @@ impl AmbientLight {
#[allow(clippy::single_match)]
match capturer.frame(seconds_per_frame) {
Ok(frame) => {
let rgb = process_frame(&frame, dimensions, &mut resizer, saturation_boost);
let rgb = process_frame(frame, dimensions, &mut resizer, saturation_boost);

manager.keyboard.set_colors_to(&rgb).unwrap();
#[cfg(target_os = "windows")]
Expand Down Expand Up @@ -83,36 +82,34 @@ impl AmbientLight {
}
}

fn process_frame(frame: &Frame, dimensions: ScreenDimensions, resizer: &mut Resizer, saturation_boost: f32) -> [u8; 12] {
fn process_frame(frame: Frame, dimensions: ScreenDimensions, resizer: &mut Resizer, saturation_boost: f32) -> [u8; 12] {
// Adapted from https://github.com/Cykooz/fast_image_resize#resize-image
// Read source image from file

// HACK: Override opacity manually to ensure some kind of output because of jank elsewhere
let mut frame_vec = frame.to_vec();
let Frame::PixelBuffer(buf) = frame else {
unreachable!("Attempted to extract vec from Texture variant in the Ambient effect");
};

for rgba in frame_vec.chunks_exact_mut(4) {
rgba[3] = 255;
}

let mut src_image = fr::Image::from_vec_u8(dimensions.src.0, dimensions.src.1, frame_vec, fr::PixelType::U8x4).unwrap();
let frame_vec = buf.data().to_vec();
// for rgba in frame_vec.chunks_exact_mut(4) {
// rgba[3] = 255;
// }

// Create MulDiv instance
let alpha_mul_div: fr::MulDiv = fr::MulDiv::default();
// Multiple RGB channels of source image by alpha channel
alpha_mul_div.multiply_alpha_inplace(&mut src_image.view_mut()).unwrap();
let src_image = fr::images::Image::from_vec_u8(dimensions.src.0, dimensions.src.1, frame_vec, fr::PixelType::U8x4).unwrap();

// Create container for data of destination image
let mut dst_image = fr::Image::new(dimensions.dest.0, dimensions.dest.1, fr::PixelType::U8x4);
let mut dst_image = fr::images::Image::new(dimensions.dest.0, dimensions.dest.1, fr::PixelType::U8x4);

// Get mutable view of destination image data
let mut dst_view = dst_image.view_mut();
// let mut dst_view = dst_image.view_mut();

// Create Resizer instance and resize source image
// into buffer of destination image
resizer.resize(&src_image.view(), &mut dst_view).unwrap();
resizer.resize(&src_image, &mut dst_image, None).unwrap();

// Divide RGB channels of destination image by alpha
alpha_mul_div.divide_alpha_inplace(&mut dst_view).unwrap();
// alpha_mul_div.divide_alpha_inplace(&mut dst_view).unwrap();

let bgr_arr = dst_image.buffer();

Expand Down
2 changes: 1 addition & 1 deletion app/src/effects/ripple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Ripple {
Keycode::Z,
Keycode::X,
Keycode::LControl,
Keycode::Meta,
Keycode::LMeta,
Keycode::LAlt,
];
let keys_zone_2: [Keycode; 29] = [
Expand Down
6 changes: 4 additions & 2 deletions app/src/effects/temperature.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{sync::atomic::Ordering, thread, time::Duration};

use sysinfo::{ComponentExt, System, SystemExt};
use sysinfo::{Components, System};

pub(super) struct Temperature;

Expand All @@ -19,7 +19,9 @@ impl Temperature {
let mut sys = System::new_all();
sys.refresh_all();

for component in sys.components_mut() {
let mut components = Components::new_with_refreshed_list();

for component in components.iter_mut() {
if component.label().contains("Tctl") {
while !manager.stop_signals.manager_stop_signal.load(Ordering::SeqCst) {
component.refresh();
Expand Down
4 changes: 1 addition & 3 deletions app/src/gui/effect_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ impl EffectOptions {
}
});

ui.scope(|ui| {
ui.set_enabled(profile.effect.takes_direction());

ui.add_enabled_ui(profile.effect.takes_direction(), |ui| {
ComboBox::from_label("Direction")
.width(COMBOBOX_WIDTH)
.selected_text({
Expand Down
46 changes: 22 additions & 24 deletions app/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use device_query::{DeviceQuery, Keycode};
#[cfg(debug_assertions)]
use eframe::egui::style::DebugOptions;
use eframe::{
egui::{CentralPanel, Context, Frame, Layout, ScrollArea, Style, TopBottomPanel},
egui::{CentralPanel, Context, Frame, Layout, ScrollArea, Style, TopBottomPanel, ViewportCommand},
emath::Align,
epaint::{Color32, Rounding, Vec2},
CreationContext,
Expand Down Expand Up @@ -33,7 +33,6 @@ pub struct App {
settings: Settings,

instance_not_unique: bool,
hide_window: bool,
window_open_rx: Option<crossbeam_channel::Receiver<GuiMessage>>,
// The tray struct needs to be kept from being dropped for the tray to appear on windows
// If this is none it will be assumed there's no tray regardless of cause
Expand All @@ -51,7 +50,6 @@ pub struct App {
}

pub enum GuiMessage {
ShowWindow,
CycleProfiles,
Quit,
}
Expand All @@ -65,7 +63,7 @@ pub enum CustomEffectState {
}

impl App {
pub fn new(output: OutputType, hide_window: bool, tx: Sender<GuiMessage>, rx: Receiver<GuiMessage>) -> Self {
pub fn new(output: OutputType, tx: Sender<GuiMessage>, rx: Receiver<GuiMessage>) -> Self {
let manager_result = EffectManager::new(effects::OperationMode::Gui);

let instance_not_unique = if let Err(err) = &manager_result {
Expand All @@ -84,7 +82,6 @@ impl App {
settings,

instance_not_unique,
hide_window,
window_open_rx: Some(rx),
tray: None,

Expand All @@ -111,7 +108,9 @@ impl App {
app
}

pub fn init(mut self, cc: &CreationContext<'_>, gui_sender: Sender<GuiMessage>) -> Self {
pub fn init(mut self, cc: &CreationContext<'_>, gui_sender: Sender<GuiMessage>, hide_window: bool) -> Self {
cc.egui_ctx.send_viewport_cmd(ViewportCommand::Visible(!hide_window));

//Create the tray icon
#[cfg(target_os = "linux")]
let tray_icon = load_tray_icon(include_bytes!("../../res/trayIcon.ico"));
Expand All @@ -125,12 +124,13 @@ impl App {
self.tray = if let Ok(mut tray) = tray_result {
let mut is_err = false;

let show_sender = gui_sender.clone();
let egui_ctx = cc.egui_ctx.clone();
is_err |= tray
.add_menu_item("Show", move || {
egui_ctx.request_repaint();
show_sender.send(GuiMessage::ShowWindow).unwrap()

egui_ctx.send_viewport_cmd(ViewportCommand::Visible(true));
egui_ctx.send_viewport_cmd(ViewportCommand::Focus);
})
.is_err();

Expand Down Expand Up @@ -161,7 +161,7 @@ impl App {
loop {
let keys = state.get_keys();

if keys.contains(&Keycode::Meta) && keys.contains(&Keycode::RAlt) {
if keys.contains(&Keycode::LMeta) && keys.contains(&Keycode::RAlt) {
if !lock_switching {
let _ = gui_sender.send(GuiMessage::CycleProfiles);
ctx.request_repaint();
Expand All @@ -183,11 +183,10 @@ impl App {
}

impl eframe::App for App {
fn update(&mut self, ctx: &eframe::egui::Context, frame: &mut eframe::Frame) {
fn update(&mut self, ctx: &eframe::egui::Context, _frame: &mut eframe::Frame) {
if let Some(rx) = &self.window_open_rx {
if let Ok(message) = rx.try_recv() {
match message {
GuiMessage::ShowWindow => self.hide_window = false,
GuiMessage::CycleProfiles => self.cycle_profiles(),
GuiMessage::Quit => self.exit_app(),
}
Expand All @@ -203,7 +202,7 @@ impl eframe::App for App {
self.exit_app();
};

frame.set_visible(!self.hide_window);
// frame.set_visible(!self.hide_window);

TopBottomPanel::top("top-panel").show(ctx, |ui| {
self.menu_bar.show(ctx, ui, &mut self.settings.current_profile, &mut self.custom_effect, &mut self.profile_changed);
Expand All @@ -216,9 +215,9 @@ impl eframe::App for App {

ui.with_layout(Layout::left_to_right(Align::Center).with_cross_justify(true), |ui| {
ui.vertical(|ui| {
let res = ui.scope(|ui| {
ui.set_enabled(self.settings.current_profile.effect.takes_color_array() && matches!(self.custom_effect, CustomEffectState::None));
let can_tweak_colors = self.settings.current_profile.effect.takes_color_array() && matches!(self.custom_effect, CustomEffectState::None);

let res = ui.add_enabled_ui(can_tweak_colors, |ui| {
ui.style_mut().spacing.item_spacing.y = self.theme.spacing.medium;

let response = ui.horizontal(|ui| {
Expand All @@ -244,8 +243,7 @@ impl eframe::App for App {

ui.set_width(res.inner.rect.width());

ui.scope(|ui| {
ui.set_enabled(matches!(self.custom_effect, CustomEffectState::None));
ui.add_enabled_ui(matches!(self.custom_effect, CustomEffectState::None), |ui| {
self.effect_options.show(ui, &mut self.settings.current_profile, &mut self.profile_changed, &self.theme.spacing);
});

Expand Down Expand Up @@ -297,14 +295,14 @@ impl eframe::App for App {

self.profile_changed = false;
}
}

fn on_close_event(&mut self) -> bool {
if self.tray.is_some() {
self.hide_window = true;
false
} else {
true
if ctx.input(|i| i.viewport().close_requested()) {
if self.tray.is_some() {
ctx.send_viewport_cmd(ViewportCommand::CancelClose);
ctx.send_viewport_cmd(ViewportCommand::Visible(false));
} else {
// Close normally
}
}
}

Expand All @@ -328,8 +326,8 @@ impl App {
show_expand_width: false,
show_expand_height: false,
show_resize: false,
show_blocking_widget: false,
show_interactive_widgets: false,
show_widget_hits: false,
},
..Style::default()
};
Expand Down
3 changes: 1 addition & 2 deletions app/src/gui/profile_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ impl ProfileList {

modal.button(ui, "Cancel");

ui.scope(|ui| {
ui.set_enabled(!is_empty && !name_not_unique);
ui.add_enabled_ui(!is_empty && !name_not_unique, |ui| {
if modal.button(ui, "Save").clicked() {
current_profile.name = self.new_profile_name.clone();
self.profiles.push(current_profile.clone());
Expand Down
Loading

0 comments on commit 649ec7c

Please sign in to comment.