Skip to content

Commit

Permalink
Merge pull request #278 from mahkoh/jorth/tile-drag
Browse files Browse the repository at this point in the history
Implement dragging of tiles and workspaces
  • Loading branch information
mahkoh authored Oct 2, 2024
2 parents 6ec2e9a + d8ee1ac commit 074c9f5
Show file tree
Hide file tree
Showing 34 changed files with 1,430 additions and 63 deletions.
4 changes: 4 additions & 0 deletions deploy-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Unreleased

- Needs jay-config release.
- Needs jay-toml-config release.
- Needs jay-compositor release.

# 1.6.0

- Needs jay-algorithms release.
Expand Down
8 changes: 8 additions & 0 deletions jay-config/src/_private/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,14 @@ impl Client {
self.send(&ClientMessage::SetFlipMargin { device, margin });
}

pub fn set_ui_drag_enabled(&self, enabled: bool) {
self.send(&ClientMessage::SetUiDragEnabled { enabled });
}

pub fn set_ui_drag_threshold(&self, threshold: i32) {
self.send(&ClientMessage::SetUiDragThreshold { threshold });
}

pub fn connector_connected(&self, connector: Connector) -> bool {
let res = self.send_with_response(&ClientMessage::ConnectorConnected { connector });
get_response!(res, false, ConnectorConnected { connected });
Expand Down
6 changes: 6 additions & 0 deletions jay-config/src/_private/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,12 @@ pub enum ClientMessage<'a> {
device: DrmDevice,
margin: Duration,
},
SetUiDragEnabled {
enabled: bool,
},
SetUiDragThreshold {
threshold: i32,
},
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down
14 changes: 14 additions & 0 deletions jay-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,17 @@ pub fn set_idle(timeout: Option<Duration>) {
pub fn set_explicit_sync_enabled(enabled: bool) {
get!().set_explicit_sync_enabled(enabled);
}

/// Enables or disables dragging of tiles and workspaces.
///
/// The default is `true`.
pub fn set_ui_drag_enabled(enabled: bool) {
get!().set_ui_drag_enabled(enabled);
}

/// Sets the distance at which ui dragging starts.
///
/// The default is `10`.
pub fn set_ui_drag_threshold(threshold: i32) {
get!().set_ui_drag_threshold(threshold);
}
3 changes: 3 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Unreleased

- Various bugfixes.
- Tiles and workspaces can now be dragged with the mouse.

# 1.6.0 (2024-09-25)

- Various bugfixes.
Expand Down
3 changes: 3 additions & 0 deletions src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ fn start_compositor2(
ei_clients: EiClients::new(),
slow_ei_clients: Default::default(),
cpu_worker,
ui_drag_enabled: Cell::new(true),
ui_drag_threshold_squared: Cell::new(10),
});
state.tracker.register(ClientId::from_raw(0));
create_dummy_output(&state);
Expand Down Expand Up @@ -558,6 +560,7 @@ fn create_dummy_output(state: &Rc<State>) {
status: Default::default(),
scroll: Default::default(),
pointer_positions: Default::default(),
pointer_down: Default::default(),
lock_surface: Default::default(),
hardware_cursor: Default::default(),
update_render_data_scheduled: Cell::new(false),
Expand Down
16 changes: 16 additions & 0 deletions src/config/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,16 @@ impl ConfigProxyHandler {
Ok(())
}

fn handle_set_ui_drag_enabled(&self, enabled: bool) {
self.state.ui_drag_enabled.set(enabled);
}

fn handle_set_ui_drag_threshold(&self, threshold: i32) {
let threshold = threshold.max(1);
let squared = threshold.saturating_mul(threshold);
self.state.ui_drag_threshold_squared.set(squared);
}

fn handle_set_direct_scanout_enabled(
&self,
device: Option<DrmDevice>,
Expand Down Expand Up @@ -882,8 +892,10 @@ impl ConfigProxyHandler {
Some(l) => l.to_ref(),
};
let config = WsMoveConfig {
make_visible_always: false,
make_visible_if_empty: true,
source_is_destroyed: false,
before: None,
};
move_ws_to_output(&link, &output, config);
ws.desired_output.set(output.global.output_id.clone());
Expand Down Expand Up @@ -1949,6 +1961,10 @@ impl ConfigProxyHandler {
ClientMessage::SetFlipMargin { device, margin } => self
.handle_set_flip_margin(device, margin)
.wrn("set_flip_margin")?,
ClientMessage::SetUiDragEnabled { enabled } => self.handle_set_ui_drag_enabled(enabled),
ClientMessage::SetUiDragThreshold { threshold } => {
self.handle_set_ui_drag_threshold(threshold)
}
}
Ok(())
}
Expand Down
3 changes: 3 additions & 0 deletions src/gfx_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,9 @@ pub fn create_render_pass(
}
}
}
if let Some(highlight) = seat.ui_drag_highlight() {
renderer.render_highlight(&highlight.move_(-rect.x1(), -rect.y1()));
}
if let Some(drag) = seat.toplevel_drag() {
drag.render(&mut renderer, &rect, x, y);
}
Expand Down
23 changes: 23 additions & 0 deletions src/ifs/wl_seat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ pub struct WlSeatGlobal {
cursor_user_group: Rc<CursorUserGroup>,
pointer_cursor: Rc<CursorUser>,
tree_changed: Rc<AsyncEvent>,
tree_changed_needs_layout: Cell<bool>,
selection: CloneCell<Option<Rc<dyn DynDataSource>>>,
selection_serial: Cell<u32>,
primary_selection: CloneCell<Option<Rc<dyn DynDataSource>>>,
Expand Down Expand Up @@ -198,6 +199,7 @@ pub struct WlSeatGlobal {
hold_bindings: PerClientBindings<ZwpPointerGestureHoldV1>,
tablet: TabletSeatData,
ei_seats: CopyHashMap<(ClientId, EiSeatId), Rc<EiSeat>>,
ui_drag_highlight: Cell<Option<Rect>>,
}

const CHANGE_CURSOR_MOVED: u32 = 1 << 0;
Expand Down Expand Up @@ -239,6 +241,7 @@ impl WlSeatGlobal {
cursor_user_group,
pointer_cursor: cursor_user,
tree_changed: Default::default(),
tree_changed_needs_layout: Default::default(),
selection: Default::default(),
selection_serial: Cell::new(0),
primary_selection: Default::default(),
Expand Down Expand Up @@ -267,12 +270,16 @@ impl WlSeatGlobal {
hold_bindings: Default::default(),
tablet: Default::default(),
ei_seats: Default::default(),
ui_drag_highlight: Default::default(),
});
slf.pointer_cursor.set_owner(slf.clone());
let seat = slf.clone();
let future = state.eng.spawn("seat handler", async move {
loop {
seat.tree_changed.triggered().await;
if seat.tree_changed_needs_layout.take() {
seat.state.eng.yield_now().await;
}
seat.state.tree_changed_sent.set(false);
seat.changes.or_assign(CHANGE_TREE);
// log::info!("tree_changed");
Expand Down Expand Up @@ -314,6 +321,10 @@ impl WlSeatGlobal {
self.pointer_owner.toplevel_drag()
}

pub fn ui_drag_highlight(&self) -> Option<Rect> {
self.ui_drag_highlight.get()
}

pub fn add_data_device(&self, device: &Rc<WlDataDevice>) {
let mut dd = self.data_devices.borrow_mut();
dd.entry(device.client.id)
Expand Down Expand Up @@ -764,6 +775,18 @@ impl WlSeatGlobal {
.start_drag(self, origin, source, icon, serial)
}

pub fn start_tile_drag(self: &Rc<Self>, tl: &Rc<dyn ToplevelNode>) {
if self.state.ui_drag_enabled.get() {
self.pointer_owner.start_tile_drag(self, tl);
}
}

pub fn start_workspace_drag(self: &Rc<Self>, ws: &Rc<WorkspaceNode>) {
if self.state.ui_drag_enabled.get() {
self.pointer_owner.start_workspace_drag(self, ws);
}
}

pub fn cancel_dnd(self: &Rc<Self>) {
self.pointer_owner.cancel_dnd(self);
}
Expand Down
17 changes: 16 additions & 1 deletion src/ifs/wl_seat/event_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub struct NodeSeatState {
dnd_targets: SmallMap<SeatId, Rc<WlSeatGlobal>, 1>,
tablet_pad_foci: SmallMap<TabletPadId, Rc<TabletPad>, 1>,
tablet_tool_foci: SmallMap<TabletToolId, Rc<TabletTool>, 1>,
ui_drags: SmallMap<SeatId, Rc<WlSeatGlobal>, 1>,
}

impl NodeSeatState {
Expand Down Expand Up @@ -101,6 +102,14 @@ impl NodeSeatState {
self.pointer_grabs.remove(&seat.id);
}

pub(super) fn add_ui_drag(&self, seat: &Rc<WlSeatGlobal>) {
self.ui_drags.insert(seat.id, seat.clone());
}

pub(super) fn remove_ui_drag(&self, seat: &WlSeatGlobal) {
self.ui_drags.remove(&seat.id);
}

pub(super) fn add_tablet_pad_focus(&self, pad: &Rc<TabletPad>) {
self.tablet_pad_foci.insert(pad.id, pad.clone());
}
Expand Down Expand Up @@ -176,6 +185,9 @@ impl NodeSeatState {
while let Some((_, seat)) = self.pointer_grabs.pop() {
seat.pointer_owner.grab_node_removed(&seat);
}
while let Some((_, seat)) = self.ui_drags.pop() {
seat.pointer_owner.revert_to_default(&seat);
}
let node_id = node.node_id();
while let Some((_, seat)) = self.dnd_targets.pop() {
seat.pointer_owner.dnd_target_removed(&seat);
Expand Down Expand Up @@ -1100,8 +1112,11 @@ impl WlSeatGlobal {
}
}

pub fn trigger_tree_changed(&self) {
pub fn trigger_tree_changed(&self, needs_layout: bool) {
// log::info!("trigger_tree_changed");
if needs_layout {
self.tree_changed_needs_layout.set(true);
}
self.tree_changed.trigger();
}

Expand Down
Loading

0 comments on commit 074c9f5

Please sign in to comment.