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

Update smithay, with cursor/selection changes #197

Merged
merged 1 commit into from
Oct 11, 2023
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
74 changes: 13 additions & 61 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ debug = true
lto = "fat"

[patch."https://github.com/Smithay/smithay.git"]
smithay = { git = "https://github.com/smithay//smithay", rev = "74ef59a3f" }
smithay = { git = "https://github.com/smithay//smithay", rev = "d60b1b83e" }

[patch.crates-io]
calloop = { git = "https://github.com/Smithay/calloop", rev = "71b6e633b1" }
calloop = { git = "https://github.com/Smithay/calloop", rev = "71b6e633b1" }
7 changes: 4 additions & 3 deletions src/backend/render/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,17 @@ where
let mut cursor_status = cell.borrow_mut();
if let CursorImageStatus::Surface(ref surface) = *cursor_status {
if !surface.alive() {
*cursor_status = CursorImageStatus::Default;
*cursor_status = CursorImageStatus::default_named();
}
}
cursor_status.clone()
})
.unwrap_or(CursorImageStatus::Default);
.unwrap_or(CursorImageStatus::default_named());

if let CursorImageStatus::Surface(ref wl_surface) = cursor_status {
return draw_surface_cursor(renderer, wl_surface, location.to_i32_round(), scale);
} else if draw_default && CursorImageStatus::Default == cursor_status {
// TODO: Handle other named cursors
} else if draw_default && CursorImageStatus::default_named() == cursor_status {
let integer_scale = scale.x.max(scale.y).ceil() as u32;

let seat_userdata = seat.user_data();
Expand Down
2 changes: 1 addition & 1 deletion src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub fn add_seat(
userdata.insert_if_missing(SeatMoveGrabState::default);
userdata.insert_if_missing(CursorState::default);
userdata.insert_if_missing(|| ActiveOutput(RefCell::new(output.clone())));
userdata.insert_if_missing(|| RefCell::new(CursorImageStatus::Default));
userdata.insert_if_missing(|| RefCell::new(CursorImageStatus::default_named()));

// A lot of clients bind keyboard and pointer unconditionally once on launch..
// Initial clients might race the compositor on adding periheral and
Expand Down
7 changes: 3 additions & 4 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,16 @@ use smithay::{
utils::{Clock, IsAlive, Monotonic},
wayland::{
compositor::{CompositorClientState, CompositorState},
data_device::DataDeviceState,
dmabuf::{DmabufFeedback, DmabufState},
fractional_scale::{with_fractional_scale, FractionalScaleManagerState},
keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitState,
output::OutputManagerState,
pointer_constraints::PointerConstraintsState,
pointer_gestures::PointerGesturesState,
presentation::PresentationState,
primary_selection::PrimarySelectionState,
seat::WaylandFocus,
security_context::{SecurityContext, SecurityContextState},
selection::{data_device::DataDeviceState, primary_selection::PrimarySelectionState},
shell::{kde::decoration::KdeDecorationState, xdg::decoration::XdgDecorationState},
shm::ShmState,
viewporter::ViewporterState,
Expand Down Expand Up @@ -465,12 +464,12 @@ impl Common {
let mut cursor_status = cell.borrow_mut();
if let CursorImageStatus::Surface(ref surface) = *cursor_status {
if !surface.alive() {
*cursor_status = CursorImageStatus::Default;
*cursor_status = CursorImageStatus::default_named();
}
}
cursor_status.clone()
})
.unwrap_or(CursorImageStatus::Default);
.unwrap_or(CursorImageStatus::default_named());

if let CursorImageStatus::Surface(wl_surface) = cursor_status {
send_frames_surface_tree(
Expand Down
12 changes: 8 additions & 4 deletions src/utils/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
use smithay::{
desktop::utils::bbox_from_surface_tree,
input::{
pointer::{CursorImageAttributes, CursorImageStatus},
pointer::{CursorIcon, CursorImageAttributes, CursorImageStatus},
Seat,
},
output::Output,
Expand Down Expand Up @@ -86,12 +86,12 @@ impl SeatExt for Seat<State> {
let mut cursor_status = cell.borrow_mut();
if let CursorImageStatus::Surface(ref surface) = *cursor_status {
if !surface.alive() {
*cursor_status = CursorImageStatus::Default;
*cursor_status = CursorImageStatus::default_named();
}
}
cursor_status.clone()
})
.unwrap_or(CursorImageStatus::Default);
.unwrap_or(CursorImageStatus::default_named());

match cursor_status {
CursorImageStatus::Surface(surface) => {
Expand All @@ -111,7 +111,7 @@ impl SeatExt for Seat<State> {
);
Some((buffer_geo, (hotspot.x, hotspot.y).into()))
}
CursorImageStatus::Default => {
CursorImageStatus::Named(CursorIcon::Default) => {
let seat_userdata = self.user_data();
seat_userdata.insert_if_missing(CursorState::default);
let state = seat_userdata.get::<CursorState>().unwrap();
Expand All @@ -129,6 +129,10 @@ impl SeatExt for Seat<State> {
(frame.xhot as i32, frame.yhot as i32).into(),
))
}
CursorImageStatus::Named(_) => {
// TODO: Handle for `cursor_shape_v1` protocol
None
}
CursorImageStatus::Hidden => None,
}
}
Expand Down
54 changes: 3 additions & 51 deletions src/wayland/handlers/data_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ use smithay::{
input::Seat,
reexports::wayland_server::protocol::{wl_data_source::WlDataSource, wl_surface::WlSurface},
utils::IsAlive,
wayland::data_device::{
with_source_metadata, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState,
ServerDndGrabHandler,
wayland::selection::data_device::{
ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, ServerDndGrabHandler,
},
xwayland::xwm::{SelectionType, XwmId},
};
use std::{cell::RefCell, os::unix::io::OwnedFd};
use tracing::warn;
use std::cell::RefCell;

pub struct DnDIcon {
surface: RefCell<Option<WlSurface>>,
Expand Down Expand Up @@ -51,54 +48,9 @@ impl ClientDndGrabHandler for State {
}
impl ServerDndGrabHandler for State {}
impl DataDeviceHandler for State {
type SelectionUserData = XwmId;

fn data_device_state(&self) -> &DataDeviceState {
&self.common.data_device_state
}

fn new_selection(&mut self, source: Option<WlDataSource>, _seat: Seat<State>) {
if let Some(state) = self.common.xwayland_state.as_mut() {
if let Some(xwm) = state.xwm.as_mut() {
if let Some(source) = &source {
if let Ok(Err(err)) = with_source_metadata(source, |metadata| {
xwm.new_selection(
SelectionType::Clipboard,
Some(metadata.mime_types.clone()),
)
}) {
warn!(?err, "Failed to set Xwayland clipboard selection.");
}
} else if let Err(err) = xwm.new_selection(SelectionType::Clipboard, None) {
warn!(?err, "Failed to clear Xwayland clipboard selection.");
}
}
}
}

fn send_selection(
&mut self,
mime_type: String,
fd: OwnedFd,
_seat: Seat<State>,
_user_data: &Self::SelectionUserData,
) {
if let Some(xwm) = self
.common
.xwayland_state
.as_mut()
.and_then(|xstate| xstate.xwm.as_mut())
{
if let Err(err) = xwm.send_selection(
SelectionType::Clipboard,
mime_type,
fd,
self.common.event_loop_handle.clone(),
) {
warn!(?err, "Failed to send clipboard (X11 -> Wayland).");
}
}
}
}

delegate_data_device!(State);
1 change: 1 addition & 0 deletions src/wayland/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod relative_pointer;
pub mod screencopy;
pub mod seat;
pub mod security_context;
pub mod selection;
pub mod shm;
pub mod toplevel_info;
pub mod toplevel_management;
Expand Down
47 changes: 1 addition & 46 deletions src/wayland/handlers/primary_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,13 @@
use crate::state::State;
use smithay::{
delegate_primary_selection,
wayland::primary_selection::{PrimarySelectionHandler, PrimarySelectionState, with_source_metadata}, xwayland::xwm::{XwmId, SelectionType}, reexports::wayland_protocols::wp::primary_selection::zv1::server::zwp_primary_selection_source_v1::ZwpPrimarySelectionSourceV1, input::Seat,
wayland::selection::primary_selection::{PrimarySelectionHandler, PrimarySelectionState},
};
use tracing::warn;

use std::os::unix::io::OwnedFd;

impl PrimarySelectionHandler for State {
type SelectionUserData = XwmId;

fn primary_selection_state(&self) -> &PrimarySelectionState {
&self.common.primary_selection_state
}

fn new_selection(&mut self, source: Option<ZwpPrimarySelectionSourceV1>, _seat: Seat<State>) {
if let Some(state) = self.common.xwayland_state.as_mut() {
if let Some(xwm) = state.xwm.as_mut() {
if let Some(source) = &source {
if let Ok(Err(err)) = with_source_metadata(source, |metadata| {
xwm.new_selection(SelectionType::Primary, Some(metadata.mime_types.clone()))
}) {
warn!(?err, "Failed to set Xwayland primary selection");
}
} else if let Err(err) = xwm.new_selection(SelectionType::Primary, None) {
warn!(?err, "Failed to clear Xwayland primary selection");
}
}
}
}

fn send_selection(
&mut self,
mime_type: String,
fd: OwnedFd,
_seat: Seat<State>,
_user_data: &Self::SelectionUserData,
) {
if let Some(xwm) = self
.common
.xwayland_state
.as_mut()
.and_then(|xstate| xstate.xwm.as_mut())
{
if let Err(err) = xwm.send_selection(
SelectionType::Primary,
mime_type,
fd,
self.common.event_loop_handle.clone(),
) {
warn!(?err, "Failed to send primary selection (X11 -> Wayland).");
}
}
}
}

delegate_primary_selection!(State);
4 changes: 2 additions & 2 deletions src/wayland/handlers/seat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use smithay::{
input::{pointer::CursorImageStatus, SeatHandler, SeatState},
reexports::wayland_server::Resource,
wayland::{
data_device::set_data_device_focus, primary_selection::set_primary_focus,
seat::WaylandFocus,
seat::WaylandFocus, selection::data_device::set_data_device_focus,
selection::primary_selection::set_primary_focus,
},
};
use std::cell::RefCell;
Expand Down
Loading