Skip to content

Commit

Permalink
Merge branch 'main' into fsundvik/wgpu-winit-0.30
Browse files Browse the repository at this point in the history
  • Loading branch information
fredizzimo committed Jul 21, 2024
2 parents 1f57bb0 + 3960baa commit 3e53e43
Show file tree
Hide file tree
Showing 15 changed files with 1,193 additions and 370 deletions.
350 changes: 279 additions & 71 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ dirs = "5.0.0"
glamour = { version = "0.11.1", features = ["serde"] }
flexi_logger = { version = "0.28.0", default-features = false }
futures = "0.3.21"
glutin = "0.31.1"
glutin-winit = "0.4.2"
glutin = "0.32.0"
glutin-winit = "0.5.0"
image = { version = "0.25.0", default-features = false, features = ["ico"] }
indoc = "2.0.5"
itertools = "0.13.0"
Expand All @@ -52,9 +52,9 @@ num = "0.4.1"
nvim-rs = { version = "0.7.0", features = ["use_tokio"] }
palette = "0.7.6"
parking_lot = "0.12.0"
parley = { git = "https://github.com/linebender/parley" }
parley = { git = "https://github.com/linebender/parley", rev="5b60803d1256ab821f79eaa06721a3112de7202a" }
rand = "0.8.5"
raw-window-handle = "0.5.0"
raw-window-handle = "0.6.0"
rmpv = "1.0.0"
rust-embed = "8.2.0"
serde = { version = "1.0.136", features = ["derive"] }
Expand All @@ -75,9 +75,9 @@ tracy-client-sys = { version = "0.22.0", optional = true, default-features = fal
"fibers",
] }
unicode-segmentation = "1.9.0"
vide = { git = "https://github.com/neovide/vide", rev="61239a676e89e561c4f3c19b8aec32947c818340" }
vide = { path = "../vide" }
which = "6.0.1"
winit = { version = "=0.29.15", features = ["serde"] }
winit = { version = "=0.30.3", features = ["serde"] }
xdg = "2.4.1"
notify-debouncer-full = "0.3.1"
regex = "1.10.3"
Expand Down Expand Up @@ -109,6 +109,7 @@ icrate = { version = "0.0.4", features = [
"apple",
"Foundation",
"Foundation_NSThread",
"Foundation_NSProcessInfo",
"AppKit",
"AppKit_NSColor",
"AppKit_NSEvent",
Expand Down
77 changes: 77 additions & 0 deletions macos-builder/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Neovide Packaging for macOS

This script is designed to build (if needed) and package the Neovide application packaging it into a macOS `.app` bundle, and then creating a `.dmg` disk image for distribution.

## Prerequisites

Before running the script, ensure you have the following dependencies installed:

- [cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html)
- [create-dmg](https://github.com/create-dmg/create-dmg)
- [codesign](https://developer.apple.com/documentation/security/notarizing_macos_software_before_distribution)

**Run the Script**:

```bash
./macos-builder/run aarch64-apple-darwin
```

### Steps

**Set Up Release Directory**:
The script sets the `RELEASE_DIR` based on the `TARGET_ARCHITECTURE` environment variable. If `TARGET_ARCHITECTURE` is not set, it defaults to `target/release`.

```bash
RELEASE_DIR=${TARGET_ARCHITECTURE:+target/${TARGET_ARCHITECTURE}/release}
RELEASE_DIR=${RELEASE_DIR:-target/release}
```

**Build the Project**:
If the release directory does not exist, the script runs the `cargo build --release` command to build the project.

_*This is for local development purposes since you would typically build the project beforehand.*_

```bash
if [ ! -d "${RELEASE_DIR}" ]; then
cargo build --release ${TARGET_ARCHITECTURE:+--target "${TARGET_ARCHITECTURE}"}
fi
```

**Prepare the Application Bundle**:

- Sets up directories for the `.app` bundle.
- Copies the built binary and other necessary resources into the bundle.
- Signs the application using `codesign`.

```bash
mkdir -p "${APP_BINARY_DIR}"
mkdir -p "${APP_EXTRAS_DIR}"
cp -fRp "${APP_TEMPLATE}" "${APP_DIR}"
cp -fp "${APP_BINARY}" "${APP_BINARY_DIR}"
touch -r "${APP_BINARY}" "${APP_DIR}/${APP_NAME}"
codesign --remove-signature "${APP_DIR}/${APP_NAME}"
codesign --force --deep --sign - "${APP_DIR}/${APP_NAME}"
```

**Create the Disk Image**:
Uses `create-dmg` to create a `.dmg` file for the application.

```bash
create-dmg \
--filesystem "${DMG_FILESYSTEM}" \
--format "${DMG_FORMAT}" \
--volname "${DMG_VOLNAME}" \
--volicon "${DMG_ICNS}" \
--background "${DMG_BACKGROUND}" \
--window-size 650 470 \
--icon-size 80 \
--icon Neovide.app 240 320 \
--app-drop-link 410 320 \
"${APP_DIR}/${DMG_NAME}" \
"${APP_DIR}/${APP_NAME}"
```

## Notes

- Ensure all paths and filenames are correct and that the necessary files (like `Neovide.icns` and `neovide-dmg-background.tiff`) are present in their respective directories.
- The script assumes a macOS environment with the necessary tools installed.
16 changes: 14 additions & 2 deletions macos-builder/run
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@

set -e

if [ -n "$1" ]; then
TARGET_ARCHITECTURE=$1
fi

RELEASE_DIR=${TARGET_ARCHITECTURE:+target/${TARGET_ARCHITECTURE}/release}
RELEASE_DIR=${RELEASE_DIR:-target/release}

if [ ! -d "${RELEASE_DIR}" ]; then
echo "Release directory '${RELEASE_DIR}' does not exist."
echo "Running 'cargo build --release${TARGET_ARCHITECTURE:+ --target ${TARGET_ARCHITECTURE}}' ..."
cargo build --release ${TARGET_ARCHITECTURE:+--target "${TARGET_ARCHITECTURE}"}
fi

TARGET="neovide"
EXTRAS_DIR="extra"
ASSETS_DIR="assets"
RELEASE_DIR="target/$1/release"
BUNDLE_DIR="${RELEASE_DIR}/bundle"

APP_NAME="Neovide.app"
Expand All @@ -15,7 +27,7 @@ APP_BINARY="${RELEASE_DIR}/${TARGET}"
APP_BINARY_DIR="${APP_DIR}/${APP_NAME}/Contents/MacOS"
APP_EXTRAS_DIR="${APP_DIR}/${APP_NAME}/Contents/Resources"

DMG_NAME="Neovide-$1.dmg"
DMG_NAME="Neovide${TARGET_ARCHITECTURE:+-${TARGET_ARCHITECTURE}}.dmg"
DMG_VOLNAME="Neovide"
DMG_FILESYSTEM="HFS+"
DMG_FORMAT="UDZO"
Expand Down
44 changes: 24 additions & 20 deletions src/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use copypasta::{
};
use copypasta::{ClipboardContext, ClipboardProvider};
use parking_lot::Mutex;
use raw_window_handle::HasRawDisplayHandle;
use raw_window_handle::HasDisplayHandle;
#[cfg(target_os = "linux")]
use raw_window_handle::{RawDisplayHandle, WaylandDisplayHandle};
use winit::event_loop::EventLoop;
Expand All @@ -27,26 +27,30 @@ static CLIPBOARD: OnceLock<Mutex<Clipboard>> = OnceLock::new();

pub fn init(event_loop: &EventLoop<UserEvent>) {
CLIPBOARD
.set(Mutex::new(match event_loop.raw_display_handle() {
#[cfg(target_os = "linux")]
RawDisplayHandle::Wayland(WaylandDisplayHandle { display, .. }) => unsafe {
let (selection, clipboard) =
wayland_clipboard::create_clipboards_from_external(display);
Clipboard {
clipboard: Box::new(clipboard),
selection: Box::new(selection),
}
.set(Mutex::new(
match event_loop.display_handle().unwrap().as_raw() {
#[cfg(target_os = "linux")]
RawDisplayHandle::Wayland(WaylandDisplayHandle { mut display, .. }) => unsafe {
let (selection, clipboard) =
wayland_clipboard::create_clipboards_from_external(display.as_mut());
Clipboard {
clipboard: Box::new(clipboard),
selection: Box::new(selection),
}
},
#[cfg(target_os = "linux")]
_ => Clipboard {
clipboard: Box::new(ClipboardContext::new().unwrap()),
selection: Box::new(
X11ClipboardContext::<X11SelectionClipboard>::new().unwrap(),
),
},
#[cfg(not(target_os = "linux"))]
_ => Clipboard {
clipboard: Box::new(ClipboardContext::new().unwrap()),
},
},
#[cfg(target_os = "linux")]
_ => Clipboard {
clipboard: Box::new(ClipboardContext::new().unwrap()),
selection: Box::new(X11ClipboardContext::<X11SelectionClipboard>::new().unwrap()),
},
#[cfg(not(target_os = "linux"))]
_ => Clipboard {
clipboard: Box::new(ClipboardContext::new().unwrap()),
},
}))
))
.ok();
}

Expand Down
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use renderer::{cursor_renderer::CursorSettings, RendererSettings};
#[cfg_attr(target_os = "windows", allow(unused_imports))]
use settings::SETTINGS;
use window::{
create_event_loop, determine_window_size, main_loop, UserEvent, WindowSettings, WindowSize,
create_event_loop, determine_window_size, UpdateLoop, UserEvent, WindowSettings, WindowSize,
};

pub use channel_utils::*;
Expand Down Expand Up @@ -95,7 +95,10 @@ fn main() -> NeovideExitCode {
match setup(event_loop.create_proxy()) {
Err(err) => handle_startup_errors(err, event_loop).into(),
Ok((window_size, font_settings, _runtime)) => {
main_loop(window_size, font_settings, event_loop).into()
let mut update_loop =
UpdateLoop::new(window_size, font_settings);

event_loop.run_app(&mut update_loop).into()
}
}
}
Expand Down
15 changes: 4 additions & 11 deletions src/renderer/cursor_renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod cursor_vfx;

use std::collections::HashMap;

use winit::event::{Event, WindowEvent};
use winit::event::WindowEvent;

use crate::{
bridge::EditorMode,
Expand All @@ -12,7 +12,7 @@ use crate::{
renderer::{animation_utils::*, GridRenderer, RenderedWindow},
settings::{ParseFromValue, SETTINGS},
units::{GridPos, GridScale, PixelPos, PixelSize},
window::{ShouldRender, UserEvent},
window::ShouldRender,
};

use blink::*;
Expand Down Expand Up @@ -191,16 +191,9 @@ impl CursorRenderer {
renderer
}

pub fn handle_event(&mut self, event: &Event<UserEvent>) -> bool {
if let Event::WindowEvent {
event: WindowEvent::Focused(is_focused),
..
} = event
{
pub fn handle_event(&mut self, event: &WindowEvent) {
if let WindowEvent::Focused(is_focused) = event {
self.window_has_focus = *is_focused;
true
} else {
false
}
}

Expand Down
16 changes: 11 additions & 5 deletions src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use itertools::Itertools;
use log::{error, warn};
use palette::{LinSrgba, WithAlpha};

use winit::{event::Event, window::Window};
use winit::{event::WindowEvent, window::Window};

use vide::{Layer, Scene, WinitRenderer};

Expand All @@ -31,7 +31,7 @@ use crate::{
renderer::rendered_layer::{group_windows, FloatingLayer},
settings::*,
units::{GridPos, GridRect, GridSize, PixelPos},
window::{ShouldRender, UserEvent},
window::ShouldRender,
WindowSettings,
};

Expand Down Expand Up @@ -173,9 +173,11 @@ impl Renderer {
self.wgpu_renderer = Some(block_on(create_renderer(window)));
}

pub fn handle_event(&mut self, event: &Event<UserEvent>) -> bool {
pub fn handle_event(&mut self, event: &WindowEvent) {
if let Some(wgpu_renderer) = self.wgpu_renderer.as_mut() {
wgpu_renderer.handle_event(event);
if let WindowEvent::Resized(new_size) = event {
wgpu_renderer.resize(new_size.width, new_size.height);
}
}
self.cursor_renderer.handle_event(event)
}
Expand Down Expand Up @@ -469,7 +471,11 @@ impl Renderer {
DEFAULT_GRID_SIZE
}
}
}

pub fn exit(&mut self) {
self.wgpu_renderer = None;
}
}

/// Defines how floating windows are sorted.
fn floating_sort(window_a: &&mut RenderedWindow, window_b: &&mut RenderedWindow) -> Ordering {
Expand Down
Loading

0 comments on commit 3e53e43

Please sign in to comment.