Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.20.1 #189

Merged
merged 2 commits into from
Feb 3, 2025
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 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.0"
version = "0.20.1"
authors = ["4JX"]
edition = "2021"
homepage = "https://github.com/4JX/L5P-Keyboard-RGB"
Expand All @@ -17,7 +17,6 @@ clap = { version = "4.5.23", features = ["color", "cargo", "derive"] }

# Ui
eframe = { version = "0.30.0", features = ["x11", "wayland"] }
# tokio = { version = "1.41.1" }
egui-modal = "0.6.0"
# egui-modal = { git = "https://github.com/n00kii/egui-modal", rev = "8443238" }
egui_file = "0.20.0"
Expand Down
12 changes: 10 additions & 2 deletions app/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
profile::{self, Profile},
ManagerCreationError,
},
DENY_HIDING,
};

#[macro_export]
Expand Down Expand Up @@ -146,7 +147,7 @@ pub fn try_cli() -> Result<GuiCommand, CliError> {

match output_type {
CliOutput::Gui { hide_window, output_type } => {
if hide_window {
if *DENY_HIDING && hide_window {
println!("Window hiding is currently not supported. See https://github.com/4JX/L5P-Keyboard-RGB/issues/181");
}
Ok(GuiCommand::Start { hide_window, output_type })
Expand Down Expand Up @@ -222,7 +223,14 @@ fn parse_cli() -> Result<CliOutput, CliError> {
profile.save_profile(&filename).expect("Failed to save.");
}

return Ok(CliOutput::Cli(OutputType::Profile(profile)));
if cli.gui {
return Ok(CliOutput::Gui {
hide_window: cli.hide_window,
output_type: OutputType::Profile(profile),
});
} else {
return Ok(CliOutput::Cli(OutputType::Profile(profile)));
}
}
Commands::List => {
println!("List of available effects:");
Expand Down
9 changes: 4 additions & 5 deletions app/src/gui/menu_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ use std::{path::PathBuf, time::Duration};
use crate::{
gui::modals,
manager::{custom_effect::CustomEffect, profile::Profile},
DENY_HIDING,
};

use super::{GuiMessage, LoadedEffect};

pub struct MenuBarState {
// TODO: Re-enable when upstream fixes window visibility
#[allow(dead_code)]
gui_sender: Sender<GuiMessage>,
load_profile_dialog: FileDialog,
load_effect_dialog: FileDialog,
Expand Down Expand Up @@ -132,9 +131,9 @@ impl MenuBarState {
open::that("https://www.buymeacoffee.com/4JXdev").unwrap();
}

// if ui.button("Exit").clicked() {
// self.gui_sender.send(GuiMessage::Quit).unwrap();
// }
if !*DENY_HIDING && ui.button("Exit").clicked() {
self.gui_sender.send(GuiMessage::Quit).unwrap();
}

#[cfg(target_os = "windows")]
{
Expand Down
43 changes: 21 additions & 22 deletions app/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::{
manager::{self, custom_effect::CustomEffect, profile::Profile, EffectManager, ManagerCreationError},
persist::Settings,
tray::{QUIT_ID, SHOW_ID},
DENY_HIDING,
};

use self::{menu_bar::MenuBarState, saved_items::SavedItems, style::Theme};
Expand Down Expand Up @@ -153,7 +154,9 @@ impl App {
}

pub fn init(self, cc: &CreationContext<'_>) -> Self {
// cc.egui_ctx.send_viewport_cmd(ViewportCommand::Visible(self.visible));
if !*DENY_HIDING {
cc.egui_ctx.send_viewport_cmd(ViewportCommand::Visible(self.visible.load(Ordering::SeqCst)));
}

let egui_ctx = cc.egui_ctx.clone();
let gui_tx = self.gui_tx.clone();
Expand Down Expand Up @@ -218,8 +221,7 @@ impl eframe::App for App {
// Show active toast messages
self.toasts.show(ctx);

// TODO: Remove when upstream fixes window hiding
if !self.visible.load(Ordering::SeqCst) {
if *DENY_HIDING && !self.visible.load(Ordering::SeqCst) {
self.visible.store(true, Ordering::SeqCst);
self.toasts
.warning("Window hiding is currently not supported.\nSee https://github.com/4JX/L5P-Keyboard-RGB/issues/181")
Expand Down Expand Up @@ -250,7 +252,7 @@ impl eframe::App for App {
self.update_state();
}

// self.handle_close_request(ctx);
self.handle_close_request(ctx);
}

fn on_exit(&mut self, _gl: Option<&eframe::glow::Context>) {
Expand Down Expand Up @@ -400,22 +402,19 @@ impl App {
self.state_changed = false;
}

// fn handle_close_request(&mut self, ctx: &Context) {
// if ctx.input(|i| i.viewport().close_requested()) {
// #[cfg(target_os = "linux")]
// let is_wayland = std::env::var("WAYLAND_DISPLAY").is_ok();
// #[cfg(target_os = "linux")]
// if is_wayland {
// // Force close normally on wayland
// return;
// }

// if self.has_tray.load(Ordering::Relaxed) {
// ctx.send_viewport_cmd(ViewportCommand::CancelClose);
// ctx.send_viewport_cmd(ViewportCommand::Visible(false));
// } else {
// // Close normally
// }
// }
// }
fn handle_close_request(&mut self, ctx: &Context) {
if ctx.input(|i| i.viewport().close_requested()) {
if *DENY_HIDING {
// Force close normally on wayland
return;
}

if self.has_tray.load(Ordering::Relaxed) {
ctx.send_viewport_cmd(ViewportCommand::CancelClose);
ctx.send_viewport_cmd(ViewportCommand::Visible(false));
} else {
// Close normally
}
}
}
}
5 changes: 5 additions & 0 deletions app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod persist;
mod tray;
mod util;

use std::sync::LazyLock;
#[cfg(not(target_os = "linux"))]
use std::{cell::RefCell, rc::Rc};

Expand All @@ -26,6 +27,10 @@ use gui::App;

const APP_ICON: &[u8; 14987] = include_bytes!("../res/trayIcon.ico");
const WINDOW_SIZE: Vec2 = Vec2::new(500., 400.);
#[cfg(target_os = "linux")]
pub static DENY_HIDING: LazyLock<bool> = LazyLock::new(|| std::env::var("WAYLAND_DISPLAY").is_ok());
#[cfg(not(target_os = "linux"))]
pub static DENY_HIDING: LazyLock<bool> = LazyLock::new(|| true);

fn main() {
#[cfg(target_os = "windows")]
Expand Down
11 changes: 5 additions & 6 deletions app/src/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use tray_icon::{
Icon, TrayIcon, TrayIconBuilder,
};

use crate::APP_ICON;
use crate::{APP_ICON, DENY_HIDING};

pub const SHOW_ID: &str = "tray-show";
pub const QUIT_ID: &str = "tray-quit";
Expand All @@ -23,12 +23,11 @@ impl TrayMenuItems {
}
}

fn build_tray_menu(items: &TrayMenuItems, _has_gui: bool) -> Menu {
fn build_tray_menu(items: &TrayMenuItems, has_gui: bool) -> Menu {
let menu = Menu::new();
// TODO: Wait for upstream fix
// if has_gui {
// menu.append_items(&[&items.show]).unwrap();
// }
if has_gui && !*DENY_HIDING {
menu.append_items(&[&items.show]).unwrap();
}
menu.append_items(&[&items.quit]).unwrap();
menu
}
Expand Down
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
overlays = [ (import rust-overlay) ];
};

rustVersion = "1.81.0";
rustVersion = "1.84.0";

rust = pkgs.rust-bin.stable.${rustVersion}.default.override {
extensions = [
Expand Down
Loading