cosmic-screencopy-v2
This commit is contained in:
parent
973cfed87b
commit
b40d153809
27 changed files with 3647 additions and 2743 deletions
|
|
@ -12,7 +12,7 @@ use crate::{
|
|||
iced::{IcedElement, Program},
|
||||
prelude::*,
|
||||
},
|
||||
wayland::handlers::screencopy::ScreencopySessions,
|
||||
wayland::handlers::screencopy::SessionHolder,
|
||||
};
|
||||
use calloop::LoopHandle;
|
||||
use cosmic::{
|
||||
|
|
@ -22,7 +22,6 @@ use cosmic::{
|
|||
iced_widget::scrollable::AbsoluteOffset,
|
||||
theme, widget as cosmic_widget, Apply, Element as CosmicElement,
|
||||
};
|
||||
use cosmic_protocols::screencopy::v1::server::zcosmic_screencopy_session_v1::InputType;
|
||||
use once_cell::sync::Lazy;
|
||||
use smithay::{
|
||||
backend::{
|
||||
|
|
@ -48,7 +47,7 @@ use smithay::{
|
|||
},
|
||||
output::Output,
|
||||
render_elements,
|
||||
utils::{Buffer, IsAlive, Logical, Physical, Point, Rectangle, Scale, Serial, Size},
|
||||
utils::{Buffer, IsAlive, Logical, Physical, Point, Rectangle, Scale, Serial, Size, Transform},
|
||||
wayland::seat::WaylandFocus,
|
||||
};
|
||||
use std::{
|
||||
|
|
@ -59,6 +58,7 @@ use std::{
|
|||
atomic::{AtomicBool, AtomicU8, AtomicUsize, Ordering},
|
||||
Arc, Mutex,
|
||||
},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
mod tab;
|
||||
|
|
@ -494,17 +494,28 @@ impl CosmicStack {
|
|||
if previous != active {
|
||||
let windows = p.windows.lock().unwrap();
|
||||
if let Some(previous) = windows.get(previous) {
|
||||
if let Some(sessions) = previous.user_data().get::<ScreencopySessions>() {
|
||||
for session in &*sessions.0.borrow() {
|
||||
session.cursor_leave(seat, InputType::Pointer)
|
||||
}
|
||||
for session in previous.cursor_sessions() {
|
||||
session.set_cursor_pos(None);
|
||||
}
|
||||
PointerTarget::leave(previous, seat, data, serial, time);
|
||||
}
|
||||
|
||||
if let Some(sessions) = windows[active].user_data().get::<ScreencopySessions>() {
|
||||
for session in &*sessions.0.borrow() {
|
||||
session.cursor_enter(seat, InputType::Pointer)
|
||||
for session in windows[active].cursor_sessions() {
|
||||
session.set_cursor_pos(Some(
|
||||
location
|
||||
.to_buffer(
|
||||
1.0,
|
||||
Transform::Normal,
|
||||
&windows[active].geometry().size.to_f64(),
|
||||
)
|
||||
.to_i32_round(),
|
||||
));
|
||||
if let Some((_, hotspot)) =
|
||||
seat.cursor_geometry((0.0, 0.0), Duration::from_millis(time as u64).into())
|
||||
{
|
||||
session.set_cursor_hotspot(hotspot);
|
||||
} else {
|
||||
session.set_cursor_hotspot((0, 0));
|
||||
}
|
||||
}
|
||||
PointerTarget::enter(
|
||||
|
|
@ -1121,12 +1132,6 @@ impl PointerTarget<State> for CosmicStack {
|
|||
let mut event = event.clone();
|
||||
if self.0.with_program(|p| {
|
||||
let active_window = &p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)];
|
||||
if let Some(sessions) = active_window.user_data().get::<ScreencopySessions>() {
|
||||
for session in &*sessions.0.borrow() {
|
||||
session.cursor_enter(seat, InputType::Pointer)
|
||||
}
|
||||
}
|
||||
|
||||
let geo = active_window.geometry();
|
||||
let loc = event.location.to_i32_round::<i32>();
|
||||
let (old_focus, shape) = if loc.y - geo.loc.y < 0 && loc.x - geo.loc.x < 0 {
|
||||
|
|
@ -1170,11 +1175,33 @@ impl PointerTarget<State> for CosmicStack {
|
|||
p.previous_pointer.store(active, Ordering::SeqCst);
|
||||
|
||||
PointerTarget::enter(active_window, seat, data, &event);
|
||||
|
||||
for session in active_window.cursor_sessions() {
|
||||
session.set_cursor_pos(Some(
|
||||
event
|
||||
.location
|
||||
.to_buffer(1.0, Transform::Normal, &geo.size.to_f64())
|
||||
.to_i32_round(),
|
||||
));
|
||||
if let Some((_, hotspot)) = seat.cursor_geometry(
|
||||
(0.0, 0.0),
|
||||
Duration::from_millis(event.time as u64).into(),
|
||||
) {
|
||||
session.set_cursor_hotspot(hotspot);
|
||||
} else {
|
||||
session.set_cursor_hotspot((0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
if old_focus == Focus::Window {
|
||||
PointerTarget::leave(active_window, seat, data, event.serial, event.time);
|
||||
|
||||
for session in active_window.cursor_sessions() {
|
||||
session.set_cursor_pos(None);
|
||||
}
|
||||
}
|
||||
|
||||
let cursor_state = seat.user_data().get::<CursorState>().unwrap();
|
||||
|
|
@ -1203,17 +1230,6 @@ impl PointerTarget<State> for CosmicStack {
|
|||
|
||||
let (previous, next) = self.0.with_program(|p| {
|
||||
let active_window = &p.windows.lock().unwrap()[active];
|
||||
if let Some(sessions) = active_window.user_data().get::<ScreencopySessions>() {
|
||||
for session in &*sessions.0.borrow() {
|
||||
let buffer_loc = (event.location.x, event.location.y); // we always screencast windows at 1x1 scale
|
||||
if let Some((geo, hotspot)) =
|
||||
seat.cursor_geometry(buffer_loc, data.common.clock.now())
|
||||
{
|
||||
session.cursor_info(seat, InputType::Pointer, geo, hotspot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let geo = active_window.geometry();
|
||||
let loc = event.location.to_i32_round::<i32>();
|
||||
let (next, shape) = if loc.y - geo.loc.y < 0 && loc.x - geo.loc.x < 0 {
|
||||
|
|
@ -1247,12 +1263,33 @@ impl PointerTarget<State> for CosmicStack {
|
|||
PointerTarget::motion(active_window, seat, data, &event);
|
||||
}
|
||||
|
||||
for session in active_window.cursor_sessions() {
|
||||
session.set_cursor_pos(Some(
|
||||
event
|
||||
.location
|
||||
.to_buffer(1.0, Transform::Normal, &geo.size.to_f64())
|
||||
.to_i32_round(),
|
||||
));
|
||||
if let Some((_, hotspot)) = seat.cursor_geometry(
|
||||
(0.0, 0.0),
|
||||
Duration::from_millis(event.time as u64).into(),
|
||||
) {
|
||||
session.set_cursor_hotspot(hotspot);
|
||||
} else {
|
||||
session.set_cursor_hotspot((0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
return (previous, Focus::Window);
|
||||
};
|
||||
|
||||
let previous = p.swap_focus(next);
|
||||
if previous == Focus::Window {
|
||||
PointerTarget::leave(active_window, seat, data, event.serial, event.time);
|
||||
|
||||
for session in active_window.cursor_sessions() {
|
||||
session.set_cursor_pos(None);
|
||||
}
|
||||
}
|
||||
|
||||
let cursor_state = seat.user_data().get::<CursorState>().unwrap();
|
||||
|
|
@ -1468,13 +1505,10 @@ impl PointerTarget<State> for CosmicStack {
|
|||
}
|
||||
|
||||
let previous = self.0.with_program(|p| {
|
||||
if let Some(sessions) = p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)]
|
||||
.user_data()
|
||||
.get::<ScreencopySessions>()
|
||||
for session in
|
||||
p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)].cursor_sessions()
|
||||
{
|
||||
for session in &*sessions.0.borrow() {
|
||||
session.cursor_leave(seat, InputType::Pointer)
|
||||
}
|
||||
session.set_cursor_pos(None);
|
||||
}
|
||||
|
||||
let cursor_state = seat.user_data().get::<CursorState>().unwrap();
|
||||
|
|
|
|||
|
|
@ -9,11 +9,10 @@ use crate::{
|
|||
iced::{IcedElement, Program},
|
||||
prelude::*,
|
||||
},
|
||||
wayland::handlers::screencopy::ScreencopySessions,
|
||||
wayland::handlers::screencopy::SessionHolder,
|
||||
};
|
||||
use calloop::LoopHandle;
|
||||
use cosmic::{iced::Command, widget::mouse_area, Apply};
|
||||
use cosmic_protocols::screencopy::v1::server::zcosmic_screencopy_session_v1::InputType;
|
||||
use smithay::{
|
||||
backend::{
|
||||
input::KeyState,
|
||||
|
|
@ -39,7 +38,7 @@ use smithay::{
|
|||
output::Output,
|
||||
reexports::wayland_server::protocol::wl_surface::WlSurface,
|
||||
render_elements,
|
||||
utils::{Buffer as BufferCoords, IsAlive, Logical, Point, Rectangle, Serial, Size},
|
||||
utils::{Buffer as BufferCoords, IsAlive, Logical, Point, Rectangle, Serial, Size, Transform},
|
||||
wayland::seat::WaylandFocus,
|
||||
};
|
||||
use std::{
|
||||
|
|
@ -50,6 +49,7 @@ use std::{
|
|||
atomic::{AtomicBool, AtomicU8, Ordering},
|
||||
Arc, Mutex,
|
||||
},
|
||||
time::Duration,
|
||||
};
|
||||
use wayland_backend::server::ObjectId;
|
||||
|
||||
|
|
@ -576,12 +576,6 @@ impl PointerTarget<State> for CosmicWindow {
|
|||
fn enter(&self, seat: &Seat<State>, data: &mut State, event: &MotionEvent) {
|
||||
let mut event = event.clone();
|
||||
if self.0.with_program(|p| {
|
||||
if let Some(sessions) = p.window.user_data().get::<ScreencopySessions>() {
|
||||
for session in &*sessions.0.borrow() {
|
||||
session.cursor_enter(seat, InputType::Pointer)
|
||||
}
|
||||
}
|
||||
|
||||
if p.has_ssd(false) {
|
||||
let geo = p.window.geometry();
|
||||
let loc = event.location.to_i32_round::<i32>();
|
||||
|
|
@ -624,6 +618,27 @@ impl PointerTarget<State> for CosmicWindow {
|
|||
let mut event = event.clone();
|
||||
event.location.y -= SSD_HEIGHT as f64;
|
||||
PointerTarget::enter(&p.window, seat, data, &event);
|
||||
|
||||
for session in p.window.cursor_sessions() {
|
||||
session.set_cursor_pos(Some(
|
||||
event
|
||||
.location
|
||||
.to_buffer(
|
||||
1.0,
|
||||
Transform::Normal,
|
||||
&p.window.geometry().size.to_f64(),
|
||||
)
|
||||
.to_i32_round(),
|
||||
));
|
||||
if let Some((_, hotspot)) = seat.cursor_geometry(
|
||||
(0.0, 0.0),
|
||||
Duration::from_millis(event.time as u64).into(),
|
||||
) {
|
||||
session.set_cursor_hotspot(hotspot);
|
||||
} else {
|
||||
session.set_cursor_hotspot((0, 0));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
|
@ -640,6 +655,22 @@ impl PointerTarget<State> for CosmicWindow {
|
|||
} else {
|
||||
p.swap_focus(Focus::Window);
|
||||
PointerTarget::enter(&p.window, seat, data, &event);
|
||||
for session in p.window.cursor_sessions() {
|
||||
session.set_cursor_pos(Some(
|
||||
event
|
||||
.location
|
||||
.to_buffer(1.0, Transform::Normal, &p.window.geometry().size.to_f64())
|
||||
.to_i32_round(),
|
||||
));
|
||||
if let Some((_, hotspot)) = seat.cursor_geometry(
|
||||
(0.0, 0.0),
|
||||
Duration::from_millis(event.time as u64).into(),
|
||||
) {
|
||||
session.set_cursor_hotspot(hotspot);
|
||||
} else {
|
||||
session.set_cursor_hotspot((0, 0));
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}) {
|
||||
|
|
@ -651,17 +682,6 @@ impl PointerTarget<State> for CosmicWindow {
|
|||
fn motion(&self, seat: &Seat<State>, data: &mut State, event: &MotionEvent) {
|
||||
let mut event = event.clone();
|
||||
if let Some((previous, next)) = self.0.with_program(|p| {
|
||||
if let Some(sessions) = p.window.user_data().get::<ScreencopySessions>() {
|
||||
for session in &*sessions.0.borrow() {
|
||||
let buffer_loc = (event.location.x, event.location.y); // we always screencast windows at 1x1 scale
|
||||
if let Some((geo, hotspot)) =
|
||||
seat.cursor_geometry(buffer_loc, data.common.clock.now())
|
||||
{
|
||||
session.cursor_info(seat, InputType::Pointer, geo, hotspot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if p.has_ssd(false) {
|
||||
let geo = p.window.geometry();
|
||||
let loc = event.location.to_i32_round::<i32>();
|
||||
|
|
@ -693,6 +713,27 @@ impl PointerTarget<State> for CosmicWindow {
|
|||
PointerTarget::motion(&p.window, seat, data, &event);
|
||||
}
|
||||
|
||||
for session in p.window.cursor_sessions() {
|
||||
session.set_cursor_pos(Some(
|
||||
event
|
||||
.location
|
||||
.to_buffer(
|
||||
1.0,
|
||||
Transform::Normal,
|
||||
&p.window.geometry().size.to_f64(),
|
||||
)
|
||||
.to_i32_round(),
|
||||
));
|
||||
if let Some((_, hotspot)) = seat.cursor_geometry(
|
||||
(0.0, 0.0),
|
||||
Duration::from_millis(event.time as u64).into(),
|
||||
) {
|
||||
session.set_cursor_hotspot(hotspot);
|
||||
} else {
|
||||
session.set_cursor_hotspot((0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
return Some((previous, Focus::Window));
|
||||
};
|
||||
|
||||
|
|
@ -713,6 +754,24 @@ impl PointerTarget<State> for CosmicWindow {
|
|||
} else {
|
||||
p.swap_focus(Focus::Window);
|
||||
PointerTarget::motion(&p.window, seat, data, &event);
|
||||
|
||||
for session in p.window.cursor_sessions() {
|
||||
session.set_cursor_pos(Some(
|
||||
event
|
||||
.location
|
||||
.to_buffer(1.0, Transform::Normal, &p.window.geometry().size.to_f64())
|
||||
.to_i32_round(),
|
||||
));
|
||||
if let Some((_, hotspot)) = seat.cursor_geometry(
|
||||
(0.0, 0.0),
|
||||
Duration::from_millis(event.time as u64).into(),
|
||||
) {
|
||||
session.set_cursor_hotspot(hotspot);
|
||||
} else {
|
||||
session.set_cursor_hotspot((0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}) {
|
||||
|
|
@ -801,10 +860,8 @@ impl PointerTarget<State> for CosmicWindow {
|
|||
|
||||
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {
|
||||
let previous = self.0.with_program(|p| {
|
||||
if let Some(sessions) = p.window.user_data().get::<ScreencopySessions>() {
|
||||
for session in &*sessions.0.borrow() {
|
||||
session.cursor_leave(seat, InputType::Pointer)
|
||||
}
|
||||
for session in p.window.cursor_sessions() {
|
||||
session.set_cursor_pos(None);
|
||||
}
|
||||
|
||||
let cursor_state = seat.user_data().get::<CursorState>().unwrap();
|
||||
|
|
|
|||
|
|
@ -10,9 +10,8 @@ use crate::{
|
|||
state::State,
|
||||
utils::{prelude::*, tween::EaseRectangle},
|
||||
wayland::{
|
||||
handlers::screencopy::DropableSession,
|
||||
handlers::screencopy::ScreencopySessions,
|
||||
protocols::{
|
||||
screencopy::{BufferParams, Session as ScreencopySession},
|
||||
toplevel_info::ToplevelInfoState,
|
||||
workspace::{WorkspaceHandle, WorkspaceUpdateGuard},
|
||||
},
|
||||
|
|
@ -83,8 +82,7 @@ pub struct Workspace {
|
|||
|
||||
pub handle: WorkspaceHandle,
|
||||
pub focus_stack: FocusStacks,
|
||||
pub pending_buffers: Vec<(ScreencopySession, BufferParams)>,
|
||||
pub screencopy_sessions: Vec<DropableSession>,
|
||||
pub screencopy: ScreencopySessions,
|
||||
pub output_stack: VecDeque<String>,
|
||||
pub pending_tokens: HashSet<XdgActivationToken>,
|
||||
pub(super) backdrop_id: Id,
|
||||
|
|
@ -272,8 +270,7 @@ impl Workspace {
|
|||
fullscreen: None,
|
||||
handle,
|
||||
focus_stack: FocusStacks::default(),
|
||||
pending_buffers: Vec::new(),
|
||||
screencopy_sessions: Vec::new(),
|
||||
screencopy: ScreencopySessions::default(),
|
||||
output_stack: {
|
||||
let mut queue = VecDeque::new();
|
||||
queue.push_back(output_name);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue