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
34 changes: 15 additions & 19 deletions .nix/deps/cef.nix
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
{ pkgs, inputs, ... }:

let
libcef = pkgs.libcef.overrideAttrs (
_: _: {
postInstall = ''
strip $out/lib/*
'';
}
);
cefPath = pkgs.runCommand "cef-path" { } ''
cef = pkgs.cef-binary.overrideAttrs (_: _: {
postInstall = ''
strip $out/Release/*.so*
'';
});

cefPath = pkgs.runCommand "cef-path" {} ''
mkdir -p $out

ln -s ${libcef}/include $out/include
find ${libcef}/lib -type f -name "*" -exec ln -s {} $out/ \;
find ${libcef}/libexec -type f -name "*" -exec ln -s {} $out/ \;
cp -r ${libcef}/share/cef/* $out/
ln -s ${cef}/include $out/include
find ${cef}/Release -name "*" -type f -exec ln -s {} $out/ \;
find ${cef}/Resources -name "*" -maxdepth 1 -exec ln -s {} $out/ \;

echo '${
builtins.toJSON {
type = "minimal";
name = builtins.baseNameOf libcef.src.url;
sha1 = "";
}
}' > $out/archive.json
echo '${builtins.toJSON {
type = "minimal";
name = builtins.baseNameOf cef.src.url;
sha1 = "";
}}' > $out/archive.json
'';
in
{
Expand Down
18 changes: 9 additions & 9 deletions .nix/flake.lock

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

40 changes: 27 additions & 13 deletions Cargo.lock

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

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,8 @@ iai-callgrind = { version = "0.16" }
ndarray = "0.16"
strum = { version = "0.27", features = ["derive"] }
dirs = "6.0"
# TODO: remove fork usage when https://github.com/tauri-apps/cef-rs/pull/272 is merged and published
cef = { git = "https://github.com/timon-schelling/cef-rs.git", rev = "98493a182928f1ff8d5bf8b9eea61483235df75d" }
cef-dll-sys = { git = "https://github.com/timon-schelling/cef-rs.git", rev = "98493a182928f1ff8d5bf8b9eea61483235df75d" }
cef = "142"
cef-dll-sys = "142"
include_dir = "0.7"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing = "0.1"
Expand Down Expand Up @@ -270,4 +269,3 @@ debug = true
[patch.crates-io]
# Force cargo to use only one version of the dpi crate (vendoring breaks without this)
dpi = { git = "https://github.com/rust-windowing/winit.git" }

2 changes: 1 addition & 1 deletion desktop/src/cef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl CefEventHandler for CefHandler {
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Bgra8UnormSrgb,
format: wgpu::TextureFormat::Bgra8Unorm,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
view_formats: &[],
});
Expand Down
6 changes: 3 additions & 3 deletions desktop/src/cef/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub(crate) fn handle_window_event(browser: &Browser, input_state: &mut InputStat
..Default::default()
};

key_event.modifiers = input_state.cef_modifiers(&event.location, event.repeat).raw();
key_event.modifiers = input_state.cef_modifiers(&event.location, event.repeat).into();

key_event.windows_key_code = match &event.logical_key {
winit::keyboard::Key::Named(named) => named.to_vk_bits(),
Expand Down Expand Up @@ -130,8 +130,8 @@ pub(crate) fn handle_window_event(browser: &Browser, input_state: &mut InputStat
let Some(host) = browser.host() else { return };

let mut mouse_event: MouseEvent = input_state.into();
mouse_event.modifiers |= cef_event_flags_t::EVENTFLAG_CONTROL_DOWN as u32;
mouse_event.modifiers |= cef_event_flags_t::EVENTFLAG_PRECISION_SCROLLING_DELTA as u32;
mouse_event.modifiers |= cef_event_flags_t::EVENTFLAG_CONTROL_DOWN.0 as u32;
mouse_event.modifiers |= cef_event_flags_t::EVENTFLAG_PRECISION_SCROLLING_DELTA.0 as u32;

let delta = (delta * PINCH_ZOOM_SPEED).round() as i32;

Expand Down
54 changes: 28 additions & 26 deletions desktop/src/cef/input/state.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
use cef::MouseEvent;
use cef::sys::cef_event_flags_t;
use std::time::Instant;
use winit::dpi::PhysicalPosition;
use winit::event::{ElementState, MouseButton};
use winit::keyboard::{KeyLocation, ModifiersState};

use crate::cef::consts::{MULTICLICK_ALLOWED_TRAVEL, MULTICLICK_TIMEOUT};

#[derive(Default)]
pub(crate) struct InputState {
modifiers: winit::keyboard::ModifiersState,
modifiers: ModifiersState,
mouse_position: MousePosition,
mouse_state: MouseState,
mouse_click_tracker: ClickTracker,
}
impl InputState {
pub(crate) fn modifiers_changed(&mut self, modifiers: &winit::keyboard::ModifiersState) {
pub(crate) fn modifiers_changed(&mut self, modifiers: &ModifiersState) {
self.modifiers = *modifiers;
}

Expand All @@ -31,26 +33,26 @@ impl InputState {
self.mouse_click_tracker.input(button, state, self.mouse_position)
}

pub(crate) fn cef_modifiers(&self, location: &winit::keyboard::KeyLocation, is_repeat: bool) -> CefModifiers {
pub(crate) fn cef_modifiers(&self, location: &KeyLocation, is_repeat: bool) -> CefModifiers {
CefModifiers::new(self, location, is_repeat)
}

pub(crate) fn cef_mouse_modifiers(&self) -> CefModifiers {
self.cef_modifiers(&winit::keyboard::KeyLocation::Standard, false)
self.cef_modifiers(&KeyLocation::Standard, false)
}
}

impl From<InputState> for CefModifiers {
fn from(val: InputState) -> Self {
CefModifiers::new(&val, &winit::keyboard::KeyLocation::Standard, false)
CefModifiers::new(&val, &KeyLocation::Standard, false)
}
}
impl From<&InputState> for MouseEvent {
fn from(val: &InputState) -> Self {
MouseEvent {
x: val.mouse_position.x as i32,
y: val.mouse_position.y as i32,
modifiers: val.cef_mouse_modifiers().raw(),
modifiers: val.cef_mouse_modifiers().into(),
}
}
}
Expand All @@ -59,7 +61,7 @@ impl From<&mut InputState> for MouseEvent {
MouseEvent {
x: val.mouse_position.x as i32,
y: val.mouse_position.y as i32,
modifiers: val.cef_mouse_modifiers().raw(),
modifiers: val.cef_mouse_modifiers().into(),
}
}
}
Expand Down Expand Up @@ -197,51 +199,51 @@ impl Default for ClickRecord {
}
}

pub(crate) struct CefModifiers(u32);
pub(crate) struct CefModifiers(cef_event_flags_t);
impl CefModifiers {
fn new(input_state: &InputState, location: &winit::keyboard::KeyLocation, is_repeat: bool) -> Self {
use cef::sys::cef_event_flags_t;

let mut inner = 0;
fn new(input_state: &InputState, location: &KeyLocation, is_repeat: bool) -> Self {
let mut inner = cef_event_flags_t::EVENTFLAG_NONE;

if input_state.modifiers.shift_key() {
inner |= cef_event_flags_t::EVENTFLAG_SHIFT_DOWN as u32;
inner |= cef_event_flags_t::EVENTFLAG_SHIFT_DOWN;
}
if input_state.modifiers.control_key() {
inner |= cef_event_flags_t::EVENTFLAG_CONTROL_DOWN as u32;
inner |= cef_event_flags_t::EVENTFLAG_CONTROL_DOWN;
}
if input_state.modifiers.alt_key() {
inner |= cef_event_flags_t::EVENTFLAG_ALT_DOWN as u32;
inner |= cef_event_flags_t::EVENTFLAG_ALT_DOWN;
}
if input_state.modifiers.meta_key() {
inner |= cef_event_flags_t::EVENTFLAG_COMMAND_DOWN as u32;
inner |= cef_event_flags_t::EVENTFLAG_COMMAND_DOWN;
}

if input_state.mouse_state.left {
inner |= cef_event_flags_t::EVENTFLAG_LEFT_MOUSE_BUTTON as u32;
inner |= cef_event_flags_t::EVENTFLAG_LEFT_MOUSE_BUTTON;
}
if input_state.mouse_state.right {
inner |= cef_event_flags_t::EVENTFLAG_RIGHT_MOUSE_BUTTON as u32;
inner |= cef_event_flags_t::EVENTFLAG_RIGHT_MOUSE_BUTTON;
}
if input_state.mouse_state.middle {
inner |= cef_event_flags_t::EVENTFLAG_MIDDLE_MOUSE_BUTTON as u32;
inner |= cef_event_flags_t::EVENTFLAG_MIDDLE_MOUSE_BUTTON;
}

if is_repeat {
inner |= cef_event_flags_t::EVENTFLAG_IS_REPEAT as u32;
inner |= cef_event_flags_t::EVENTFLAG_IS_REPEAT;
}

inner |= match location {
winit::keyboard::KeyLocation::Left => cef_event_flags_t::EVENTFLAG_IS_LEFT as u32,
winit::keyboard::KeyLocation::Right => cef_event_flags_t::EVENTFLAG_IS_RIGHT as u32,
winit::keyboard::KeyLocation::Numpad => cef_event_flags_t::EVENTFLAG_IS_KEY_PAD as u32,
winit::keyboard::KeyLocation::Standard => 0,
KeyLocation::Left => cef_event_flags_t::EVENTFLAG_IS_LEFT,
KeyLocation::Right => cef_event_flags_t::EVENTFLAG_IS_RIGHT,
KeyLocation::Numpad => cef_event_flags_t::EVENTFLAG_IS_KEY_PAD,
KeyLocation::Standard => cef_event_flags_t::EVENTFLAG_NONE,
};

Self(inner)
}
}

pub(crate) fn raw(&self) -> u32 {
self.0
impl Into<u32> for CefModifiers {
fn into(self) -> u32 {
self.0.0 as u32
}
}
Loading