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
9 changes: 1 addition & 8 deletions src/embedder/backend/drm_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1274,18 +1274,11 @@ impl State<DrmBackend> {
None => return,
};

let size = match self.space.output_geometry(output) {
Some(geometry) => geometry.to_f64().size,
None => return,
};
let elements = get_render_elements(
renderer,
output,
slot,
Rectangle {
loc: (0.0, 0.0).into(),
size: size,
},
self.space.output_geometry(output).unwrap().to_f64(),
self.clock.now(),
&self.cursor_image_status,
&self.cursor_state,
Expand Down
5 changes: 4 additions & 1 deletion src/embedder/backend/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ where
flutter_texture_buffer,
Point::from((0.0, 0.0)),
1.,
Some(output_geometry),
Some(Rectangle {
loc: (0., 0.).into(),
size: output_geometry.size,
}),
None,
Kind::Unspecified,
);
Expand Down
51 changes: 36 additions & 15 deletions src/embedder/input_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use smithay::backend::input::{
use smithay::input::pointer::{AxisFrame, ButtonEvent, MotionEvent, RelativeMotionEvent};
use smithay::reexports::wayland_server::protocol::wl_pointer;
use smithay::utils::{Logical, Point, SERIAL_COUNTER};
use tracing::info;
use tracing::{debug, info};

use crate::backend::Backend;
use crate::flutter_engine::embedder::{
Expand Down Expand Up @@ -35,7 +35,6 @@ impl<BackendData: Backend> State<BackendData> {
{
let pointer: smithay::input::pointer::PointerHandle<State<BackendData>> =
self.pointer.clone();

let mut pointer_location = self.pointer.current_location();

pointer.relative_motion(
Expand Down Expand Up @@ -67,8 +66,8 @@ impl<BackendData: Backend> State<BackendData> {
if self.meta_window_state.meta_window_in_gaming_mode.is_some() {
return;
}

self.send_motion_event(pointer_location, device_id, view_id)
let relative_location: Point<f64, Logical> = self.relative_pointer_location();
self.send_motion_event(relative_location, device_id, view_id)
}

pub fn on_pointer_motion_absolute<B: InputBackend>(
Expand Down Expand Up @@ -113,7 +112,8 @@ impl<BackendData: Backend> State<BackendData> {
if self.meta_window_state.meta_window_in_gaming_mode.is_some() {
return;
}
self.send_motion_event(pointer_location, device_id, view_id)
let relative_location: Point<f64, Logical> = self.relative_pointer_location();
self.send_motion_event(relative_location, device_id, view_id)
}

pub fn on_pointer_button<B: InputBackend>(
Expand Down Expand Up @@ -176,13 +176,15 @@ impl<BackendData: Backend> State<BackendData> {
.unwrap()
.current_scale()
.fractional_scale();

let pointer_location = self.relative_pointer_location();
self.flutter_engine()
.send_pointer_event(FlutterPointerEvent {
struct_size: size_of::<FlutterPointerEvent>(),
phase,
timestamp: FlutterEngine::<BackendData>::current_time_us() as usize,
x: self.pointer.current_location().x * scale,
y: self.pointer.current_location().y * scale,
x: pointer_location.x * scale,
y: pointer_location.y * scale,
device: device_id,
signal_kind: FlutterPointerSignalKind_kFlutterPointerSignalKindNone,
scroll_delta_x: 0.0,
Expand Down Expand Up @@ -247,6 +249,7 @@ impl<BackendData: Backend> State<BackendData> {
let pointer = self.pointer.clone();
pointer.axis(self, frame);
self.register_frame();
let pointer_location = self.relative_pointer_location();

// Flutter distinguish Mouse and Trackpad scrolls, so we need to send a separate event for each
if event.source() == AxisSource::Wheel || event.source() == AxisSource::WheelTilt {
Expand All @@ -263,8 +266,8 @@ impl<BackendData: Backend> State<BackendData> {
FlutterPointerPhase_kDown
},
timestamp: FlutterEngine::<BackendData>::current_time_us() as usize,
x: self.pointer.current_location().x,
y: self.pointer.current_location().y,
x: pointer_location.x,
y: pointer_location.y,
device: device_id,
signal_kind: FlutterPointerSignalKind_kFlutterPointerSignalKindScroll,
scroll_delta_x: frame.axis.0 * 58.,
Expand Down Expand Up @@ -295,8 +298,8 @@ impl<BackendData: Backend> State<BackendData> {

self.send_pointer_pan_zoom_event(
device_id,
self.pointer.current_location().x,
self.pointer.current_location().y,
pointer_location.x,
pointer_location.y,
FlutterPointerPhase_kPanZoomEnd,
0.,
0.,
Expand All @@ -314,8 +317,8 @@ impl<BackendData: Backend> State<BackendData> {
.start_scrolling();
self.send_pointer_pan_zoom_event(
device_id,
self.pointer.current_location().x,
self.pointer.current_location().y,
pointer_location.x,
pointer_location.y,
FlutterPointerPhase_kPanZoomStart,
0.,
0.,
Expand All @@ -331,8 +334,8 @@ impl<BackendData: Backend> State<BackendData> {
);
self.send_pointer_pan_zoom_event(
device_id,
self.pointer.current_location().x,
self.pointer.current_location().y,
pointer_location.x,
pointer_location.y,
FlutterPointerPhase_kPanZoomUpdate,
self.flutter_engine().trackpad_scrolling_manager.pan_x,
self.flutter_engine().trackpad_scrolling_manager.pan_y,
Expand Down Expand Up @@ -443,6 +446,23 @@ impl<BackendData: Backend> State<BackendData> {
}
}

fn relative_pointer_location(&mut self) -> Point<f64, Logical> {
let location = self.pointer.current_location();
let output_under_pointer_location = self
.space
.output_under(location)
.next()
.or_else(|| self.space.outputs().next())
.unwrap()
.current_location()
.to_f64();
(
location.x - output_under_pointer_location.x,
location.y - output_under_pointer_location.y,
)
.into()
}

fn send_motion_event(&mut self, location: Point<f64, Logical>, device_id: i32, view_id: i64)
where
BackendData: Backend + 'static,
Expand All @@ -454,6 +474,7 @@ impl<BackendData: Backend> State<BackendData> {
.unwrap()
.current_scale()
.fractional_scale();

self.flutter_engine()
.send_pointer_event(FlutterPointerEvent {
struct_size: size_of::<FlutterPointerEvent>(),
Expand Down
61 changes: 39 additions & 22 deletions src/shell/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:shell/meta_window/provider/meta_window_manager.dart';
import 'package:shell/monitor/provider/connected_monitor_list.dart';
Expand Down Expand Up @@ -49,36 +48,54 @@ void main() async {

final GlobalKey<State<StatefulWidget>> globalVeshellKey = GlobalKey();

class Veshell extends HookConsumerWidget {
class Veshell extends ConsumerStatefulWidget {
const Veshell({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
ConsumerState<Veshell> createState() => _VeshellState();
}

class _VeshellState extends ConsumerState<Veshell> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);

ref.read(platformManagerProvider.notifier)
..request(
GetEnvironmentVariablesRequest(
message: GetEnvironmentVariablesMessage(),
),
)
..request(
GetMonitorLayoutRequest(
message: GetMonitorLayoutMessage(),
),
)
..request(const ShellReadyRequest());
}

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}

@override
void didChangeMetrics() {
print('didChangeMetrics');
setState(() {});
}

@override
Widget build(BuildContext context) {
final views = RendererBinding.instance.platformDispatcher.views
.where(
(view) =>
view != RendererBinding.instance.platformDispatcher.implicitView,
)
.toList();

useEffect(
() {
ref.read(platformManagerProvider.notifier)
..request(
GetEnvironmentVariablesRequest(
message: GetEnvironmentVariablesMessage(),
),
)
..request(
GetMonitorLayoutRequest(
message: GetMonitorLayoutMessage(),
),
)
..request(const ShellReadyRequest());
return null;
},
[],
);
print('views: $views');

return VeshellShortcutManager(
child: ViewCollection(
Expand Down