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

feat: Add acrylic blur option for background #2104

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 30 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ toml = "0.7.3"
tracy-client-sys = { version = "0.19.0", optional = true }
unicode-segmentation = "1.9.0"
which = "4.2.5"
window-vibrancy = "0.4.2"
winit = { version = "=0.29.2", features = ["serde"] }
xdg = "2.4.1"

Expand Down
2 changes: 1 addition & 1 deletion src/error_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ macro_rules! error_msg {
let msg = format!($($arg)+);
log::error!("{}", msg);
EVENT_AGGREGATOR.send(UiCommand::Parallel(ParallelCommand::ShowError {
lines: msg.split('\n').map(|s| s.to_string()).collect_vec(),
lines: itertools::Itertools::collect_vec(msg.split('\n').map(|s| s.to_string())),
Kethku marked this conversation as resolved.
Show resolved Hide resolved
}));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(not(test), windows_subsystem = "windows")]
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
// Test naming occasionally uses camelCase with underscores to separate sections of
// the test name.
#![cfg_attr(test, allow(non_snake_case))]
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/grid_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl GridRenderer {
Rect::new(x as f32, y as f32, (x + width) as f32, (y + height) as f32)
}

pub fn get_default_background(&self) -> Color {
pub fn default_background(&self) -> Color {
self.default_style.colors.background.unwrap().to_color()
}

Expand Down
8 changes: 6 additions & 2 deletions src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
};

use log::error;
use skia_safe::{Canvas, Point, Rect};
use skia_safe::{Canvas, Color, Point, Rect};
use tokio::sync::mpsc::UnboundedReceiver;
use winit::event::Event;

Expand Down Expand Up @@ -139,14 +139,18 @@ impl Renderer {
self.grid_renderer.font_names()
}

pub fn default_background(&self) -> Color {
self.grid_renderer.default_background()
}

/// Draws frame
///
/// # Returns
/// `bool` indicating whether or not font was changed during this frame.
#[allow(clippy::needless_collect)]
pub fn draw_frame(&mut self, root_canvas: &mut Canvas, dt: f32) {
tracy_zone!("renderer_draw_frame");
let default_background = self.grid_renderer.get_default_background();
let default_background = self.default_background();
let font_dimensions = self.grid_renderer.font_dimensions;

let transparency = { SETTINGS.get::<WindowSettings>().transparency };
Expand Down
8 changes: 4 additions & 4 deletions src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ pub fn create_window(

let cmd_line_settings = SETTINGS.get::<CmdLineSettings>();

let window_settings = load_last_window_settings().ok();
let persistent_window_settings = load_last_window_settings().ok();

let previous_position = match window_settings {
let previous_position = match persistent_window_settings {
Some(PersistentWindowSettings::Windowed { position, .. }) => Some(position),
_ => None,
};
Expand Down Expand Up @@ -201,7 +201,7 @@ pub enum WindowSize {

pub fn determine_window_size() -> WindowSize {
let cmd_line = SETTINGS.get::<CmdLineSettings>();
let window_settings = load_last_window_settings().ok();
let persistent_window_settings = load_last_window_settings().ok();

match cmd_line.geometry {
GeometryArgs {
Expand All @@ -218,7 +218,7 @@ pub fn determine_window_size() -> WindowSize {
GeometryArgs {
maximized: true, ..
} => WindowSize::Maximized,
_ => match window_settings {
_ => match persistent_window_settings {
Some(PersistentWindowSettings::Maximized) => WindowSize::Maximized,
Some(PersistentWindowSettings::Windowed {
pixel_size: Some(pixel_size),
Expand Down
54 changes: 28 additions & 26 deletions src/window/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,51 @@ use crate::{cmd_line::CmdLineSettings, settings::*};

#[derive(Clone, SettingGroup)]
pub struct WindowSettings {
pub refresh_rate: u64,
pub refresh_rate_idle: u64,
pub idle: bool,
pub transparency: f32,
pub scale_factor: f32,
pub fullscreen: bool,
pub iso_layout: bool,
pub remember_window_size: bool,
pub remember_window_position: bool,
pub hide_mouse_when_typing: bool,
pub touch_deadzone: f32,
pub touch_drag_timeout: f32,
pub background_color: String,
pub confirm_quit: bool,
pub padding_top: u32,
pub fullscreen: bool,
pub hide_mouse_when_typing: bool,
pub idle: bool,
pub iso_layout: bool,
pub os_blur: bool,
pub padding_bottom: u32,
pub padding_left: u32,
pub padding_right: u32,
pub padding_bottom: u32,
pub padding_top: u32,
pub refresh_rate: u64,
pub refresh_rate_idle: u64,
pub remember_window_position: bool,
pub remember_window_size: bool,
pub scale_factor: f32,
pub theme: String,
pub touch_deadzone: f32,
pub touch_drag_timeout: f32,
pub transparency: f32,
}

impl Default for WindowSettings {
fn default() -> Self {
Self {
transparency: 1.0,
scale_factor: 1.0,
background_color: "".to_string(),
confirm_quit: true,
fullscreen: false,
hide_mouse_when_typing: false,
idle: SETTINGS.get::<CmdLineSettings>().idle,
iso_layout: false,
os_blur: false,
padding_bottom: 0,
padding_left: 0,
padding_right: 0,
padding_top: 0,
refresh_rate: 60,
refresh_rate_idle: 5,
idle: SETTINGS.get::<CmdLineSettings>().idle,
remember_window_size: true,
remember_window_position: true,
hide_mouse_when_typing: false,
remember_window_size: true,
scale_factor: 1.0,
theme: "".to_string(),
touch_deadzone: 6.0,
touch_drag_timeout: 0.17,
background_color: "".to_string(),
confirm_quit: true,
padding_top: 0,
padding_left: 0,
padding_right: 0,
padding_bottom: 0,
theme: "".to_string(),
transparency: 1.0,
}
}
}
Expand Down
35 changes: 32 additions & 3 deletions src/window/window_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
bridge::{ParallelCommand, SerialCommand, UiCommand},
dimensions::Dimensions,
editor::EditorCommand,
error_msg,
event_aggregator::EVENT_AGGREGATOR,
profiling::{emit_frame_mark, tracy_gpu_collect, tracy_gpu_zone, tracy_zone},
renderer::{build_context, GlWindow, Renderer, VSync, WindowedContext},
Expand All @@ -17,7 +18,7 @@ use crate::{
};

use log::trace;
use skia_safe::{scalar, Rect};
use skia_safe::{scalar, Color, Rect};
use tokio::sync::mpsc::UnboundedReceiver;
use winit::{
dpi::{PhysicalPosition, PhysicalSize, Position},
Expand Down Expand Up @@ -55,6 +56,7 @@ pub struct WinitWindowWrapper {
mouse_manager: MouseManager,
title: String,
fullscreen: bool,
os_blur: Option<Color>,
font_changed_last_frame: bool,
saved_inner_size: PhysicalSize<u32>,
saved_grid_size: Option<Dimensions>,
Expand Down Expand Up @@ -112,6 +114,7 @@ impl WinitWindowWrapper {
mouse_manager: MouseManager::new(),
title: String::from("Neovide"),
fullscreen: false,
os_blur: None,
font_changed_last_frame: false,
saved_inner_size,
saved_grid_size: None,
Expand Down Expand Up @@ -158,18 +161,44 @@ impl WinitWindowWrapper {
self.windowed_context.window().set_ime_allowed(ime_enabled);
}

pub fn set_os_blur(&mut self, os_blur: Option<Color>) {
let window = self.windowed_context.window();
self.os_blur = os_blur;
let result = if let Some(blur_color) = self.os_blur {
let blur_color = (
blur_color.r(),
blur_color.g(),
blur_color.b(),
blur_color.a(),
);
#[cfg(target_os = "windows")]
window_vibrancy::apply_acrylic(window, Some(blur_color))
} else {
#[cfg(target_os = "windows")]
window_vibrancy::clear_acrylic(window)
Comment on lines +174 to +178
Copy link
Contributor

@MultisampledNight MultisampledNight Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like macOS could be supported as well, although we'd need someone with a macOS machine to confirm that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I mentioned this in the issue. I dont know how the macos arguments work and it was late so I just didnt bother. This PR isn't really mergeable as is and should probably be done with a winit upstream change anyway. I just threw it together as an example

};

if let Err(e) = result {
error_msg!("Failed to set OS blur: {}", e);
}
}

pub fn synchronize_settings(&mut self) {
let fullscreen = { SETTINGS.get::<WindowSettings>().fullscreen };

if self.fullscreen != fullscreen {
self.toggle_fullscreen();
}

let ime_enabled = { SETTINGS.get::<KeyboardSettings>().ime };

if self.ime_enabled != ime_enabled {
self.set_ime(ime_enabled);
}

let os_blur = { SETTINGS.get::<WindowSettings>().os_blur }
.then_some(self.renderer.default_background());
if self.os_blur != os_blur {
self.set_os_blur(os_blur);
}
}

#[allow(clippy::needless_collect)]
Expand Down
Loading