Skip to content

Commit

Permalink
tree: add window-management mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mahkoh committed May 26, 2024
1 parent 1a73bbd commit 70a8f47
Show file tree
Hide file tree
Showing 20 changed files with 644 additions and 9 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.3.0

- Needs jay-algorithms release.
Expand Down
4 changes: 4 additions & 0 deletions jay-config/src/_private/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,10 @@ impl Client {
self.send(&ClientMessage::SetFocusFollowsMouseMode { seat, mode })
}

pub fn set_window_management_enabled(&self, seat: Seat, enabled: bool) {
self.send(&ClientMessage::SetWindowManagementEnabled { seat, enabled })
}

pub fn set_input_device_connector(&self, input_device: InputDevice, connector: Connector) {
self.send(&ClientMessage::SetInputDeviceConnector {
input_device,
Expand Down
4 changes: 4 additions & 0 deletions jay-config/src/_private/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,10 @@ pub enum ClientMessage<'a> {
RemoveInputMapping {
input_device: InputDevice,
},
SetWindowManagementEnabled {
seat: Seat,
enabled: bool,
},
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down
31 changes: 31 additions & 0 deletions jay-config/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,37 @@ impl Seat {
pub fn set_focus_follows_mouse_mode(self, mode: FocusFollowsMouseMode) {
get!().set_focus_follows_mouse_mode(self, mode);
}

/// Enables or disable window management mode.
///
/// In window management mode, floating windows can be moved by pressing the left
/// mouse button and all windows can be resize by pressing the right mouse button.
pub fn set_window_management_enabled(self, enabled: bool) {
get!().set_window_management_enabled(self, enabled);
}

/// Sets a key that enables window management mode while pressed.
///
/// This is a shorthand for
///
/// ```rust,ignore
/// self.bind(mod_sym, move || {
/// self.set_window_management_enabled(true);
/// self.forward();
/// self.latch(move || {
/// self.set_window_management_enabled(false);
/// });
/// });
/// ```
pub fn set_window_management_key<T: Into<ModifiedKeySym>>(self, mod_sym: T) {
self.bind(mod_sym, move || {
self.set_window_management_enabled(true);
self.forward();
self.latch(move || {
self.set_window_management_enabled(false);
});
});
}
}

/// A focus-follows-mouse mode.
Expand Down
2 changes: 2 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

- Add window management mode.

# 1.3.0 (2024-05-25)

- Add remaining layer-shell features.
Expand Down
13 changes: 13 additions & 0 deletions src/config/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,16 @@ impl ConfigProxyHandler {
Ok(())
}

fn handle_set_window_management_enabled(
&self,
seat: Seat,
enabled: bool,
) -> Result<(), CphError> {
let seat = self.get_seat(seat)?;
seat.set_window_management_enabled(enabled);
Ok(())
}

fn handle_set_input_device_connector(
&self,
input_device: InputDevice,
Expand Down Expand Up @@ -1816,6 +1826,9 @@ impl ConfigProxyHandler {
ClientMessage::RemoveInputMapping { input_device } => self
.handle_remove_input_mapping(input_device)
.wrn("remove_input_mapping")?,
ClientMessage::SetWindowManagementEnabled { seat, enabled } => self
.handle_set_window_management_enabled(seat, enabled)
.wrn("set_window_management_enabled")?,
}
Ok(())
}
Expand Down
5 changes: 5 additions & 0 deletions src/ifs/wl_seat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,11 @@ impl WlSeatGlobal {
pub fn set_focus_follows_mouse(&self, focus_follows_mouse: bool) {
self.focus_follows_mouse.set(focus_follows_mouse);
}

pub fn set_window_management_enabled(self: &Rc<Self>, enabled: bool) {
self.pointer_owner
.set_window_management_enabled(self, enabled);
}
}

impl CursorUserOwner for WlSeatGlobal {
Expand Down
2 changes: 1 addition & 1 deletion src/ifs/wl_seat/event_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl NodeSeatState {
seat.gesture_owner.revert_to_default(&seat);
}
while let Some((_, seat)) = self.pointer_grabs.pop() {
seat.pointer_owner.revert_to_default(&seat);
seat.pointer_owner.grab_node_removed(&seat);
}
let node_id = node.node_id();
while let Some((_, seat)) = self.dnd_targets.pop() {
Expand Down
Loading

0 comments on commit 70a8f47

Please sign in to comment.