Skip to content

Commit

Permalink
protocols: add wlr_data_control
Browse files Browse the repository at this point in the history
Also update smithay to the latest git hash.

Fixes #20.
  • Loading branch information
kchibisov authored and YaLTeR committed Oct 2, 2023
1 parent 2d3d0ce commit 9168f08
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 26 deletions.
13 changes: 10 additions & 3 deletions Cargo.lock

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

32 changes: 22 additions & 10 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ use smithay::reexports::wayland_server::protocol::wl_data_source::WlDataSource;
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
use smithay::reexports::wayland_server::Resource;
use smithay::utils::{Logical, Rectangle};
use smithay::wayland::data_device::{
use smithay::wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportError};
use smithay::wayland::input_method::{InputMethodHandler, PopupSurface};
use smithay::wayland::selection::data_device::{
set_data_device_focus, ClientDndGrabHandler, DataDeviceHandler, DataDeviceState,
ServerDndGrabHandler,
};
use smithay::wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportError};
use smithay::wayland::input_method::{InputMethodHandler, PopupSurface};
use smithay::wayland::primary_selection::{
use smithay::wayland::selection::primary_selection::{
set_primary_focus, PrimarySelectionHandler, PrimarySelectionState,
};
use smithay::wayland::selection::wlr_data_control::{DataControlHandler, DataControlState};
use smithay::wayland::selection::SelectionHandler;
use smithay::{
delegate_data_device, delegate_dmabuf, delegate_input_method_manager, delegate_output,
delegate_pointer_gestures, delegate_presentation, delegate_primary_selection, delegate_seat,
delegate_tablet_manager, delegate_text_input_manager, delegate_virtual_keyboard_manager,
delegate_data_control, delegate_data_device, delegate_dmabuf, delegate_input_method_manager,
delegate_output, delegate_pointer_gestures, delegate_presentation, delegate_primary_selection,
delegate_seat, delegate_tablet_manager, delegate_text_input_manager,
delegate_virtual_keyboard_manager,
};

use crate::niri::State;
Expand Down Expand Up @@ -72,8 +75,11 @@ impl InputMethodHandler for State {
delegate_input_method_manager!(State);
delegate_virtual_keyboard_manager!(State);

impl DataDeviceHandler for State {
impl SelectionHandler for State {
type SelectionUserData = ();
}

impl DataDeviceHandler for State {
fn data_device_state(&self) -> &DataDeviceState {
&self.niri.data_device_state
}
Expand Down Expand Up @@ -103,14 +109,20 @@ impl ServerDndGrabHandler for State {}
delegate_data_device!(State);

impl PrimarySelectionHandler for State {
type SelectionUserData = ();

fn primary_selection_state(&self) -> &PrimarySelectionState {
&self.niri.primary_selection_state
}
}
delegate_primary_selection!(State);

impl DataControlHandler for State {
fn data_control_state(&self) -> &DataControlState {
&self.niri.data_control_state
}
}

delegate_data_control!(State);

delegate_output!(State);

delegate_presentation!(State);
Expand Down
35 changes: 22 additions & 13 deletions src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ use smithay::wayland::compositor::{
with_states, with_surface_tree_downward, CompositorClientState, CompositorState, SurfaceData,
TraversalAction,
};
use smithay::wayland::data_device::DataDeviceState;
use smithay::wayland::dmabuf::DmabufFeedback;
use smithay::wayland::input_method::InputMethodManagerState;
use smithay::wayland::output::OutputManagerState;
use smithay::wayland::pointer_gestures::PointerGesturesState;
use smithay::wayland::presentation::PresentationState;
use smithay::wayland::primary_selection::PrimarySelectionState;
use smithay::wayland::selection::data_device::DataDeviceState;
use smithay::wayland::selection::primary_selection::PrimarySelectionState;
use smithay::wayland::selection::wlr_data_control::DataControlState;
use smithay::wayland::shell::kde::decoration::KdeDecorationState;
use smithay::wayland::shell::wlr_layer::{Layer, WlrLayerShellState};
use smithay::wayland::shell::xdg::decoration::XdgDecorationState;
Expand Down Expand Up @@ -121,6 +122,7 @@ pub struct Niri {
pub pointer_gestures_state: PointerGesturesState,
pub data_device_state: DataDeviceState,
pub primary_selection_state: PrimarySelectionState,
pub data_control_state: DataControlState,
pub popups: PopupManager,
pub presentation_state: PresentationState,

Expand Down Expand Up @@ -319,6 +321,11 @@ impl Niri {
let pointer_gestures_state = PointerGesturesState::new::<State>(&display_handle);
let data_device_state = DataDeviceState::new::<State>(&display_handle);
let primary_selection_state = PrimarySelectionState::new::<State>(&display_handle);
let data_control_state = DataControlState::new::<State, _>(
&display_handle,
Some(&primary_selection_state),
|_| true,
);
let presentation_state =
PresentationState::new::<State>(&display_handle, CLOCK_MONOTONIC as u32);

Expand Down Expand Up @@ -689,12 +696,13 @@ impl Niri {
pointer_gestures_state,
data_device_state,
primary_selection_state,
data_control_state,
popups: PopupManager::default(),
presentation_state,

seat,
default_cursor,
cursor_image: CursorImageStatus::Default,
cursor_image: CursorImageStatus::default_named(),
dnd_icon: None,

zbus_conn,
Expand Down Expand Up @@ -1019,7 +1027,7 @@ impl Niri {
.hotspot
})
} else {
self.cursor_image = CursorImageStatus::Default;
self.cursor_image = CursorImageStatus::default_named();
default_hotspot
}
} else {
Expand All @@ -1029,7 +1037,16 @@ impl Niri {

let mut pointer_elements = match &self.cursor_image {
CursorImageStatus::Hidden => vec![],
CursorImageStatus::Default => vec![OutputRenderElements::DefaultPointer(
CursorImageStatus::Surface(surface) => render_elements_from_surface_tree(
renderer,
surface,
pointer_pos,
output_scale,
1.,
Kind::Cursor,
),
// Default shape catch-all
_ => vec![OutputRenderElements::DefaultPointer(
TextureRenderElement::from_texture_buffer(
pointer_pos.to_f64(),
&default_buffer,
Expand All @@ -1039,14 +1056,6 @@ impl Niri {
Kind::Cursor,
),
)],
CursorImageStatus::Surface(surface) => render_elements_from_surface_tree(
renderer,
surface,
pointer_pos,
output_scale,
1.,
Kind::Cursor,
),
};

if let Some(dnd_icon) = &self.dnd_icon {
Expand Down

0 comments on commit 9168f08

Please sign in to comment.