fmt commit
This commit is contained in:
parent
352c526e9e
commit
9e0a6e1b5f
25 changed files with 787 additions and 499 deletions
|
|
@ -1,27 +1,31 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::utils::prelude::*;
|
||||
use super::Shell;
|
||||
use crate::utils::prelude::*;
|
||||
|
||||
use cosmic_protocols::workspace::v1::server::zcosmic_workspace_handle_v1::State as WState;
|
||||
use smithay::{
|
||||
backend::renderer::{Renderer, ImportAll},
|
||||
desktop::{Kind, Window, draw_window, space::{RenderElement, SpaceOutputTuple}},
|
||||
backend::renderer::{ImportAll, Renderer},
|
||||
desktop::{
|
||||
draw_window,
|
||||
space::{RenderElement, SpaceOutputTuple},
|
||||
Kind, Window,
|
||||
},
|
||||
reexports::{
|
||||
wayland_protocols::xdg::shell::server::xdg_toplevel::State as XdgState,
|
||||
wayland_server::DisplayHandle,
|
||||
},
|
||||
utils::{IsAlive, Logical, Physical, Point, Rectangle, Scale},
|
||||
wayland::{
|
||||
output::Output,
|
||||
seat::{
|
||||
AxisFrame, ButtonEvent, MotionEvent, PointerGrab, PointerGrabStartData,
|
||||
PointerInnerHandle,
|
||||
},
|
||||
seat::{Seat, Focus},
|
||||
output::Output,
|
||||
seat::{Focus, Seat},
|
||||
Serial,
|
||||
},
|
||||
};
|
||||
use cosmic_protocols::workspace::v1::server::zcosmic_workspace_handle_v1::State as WState;
|
||||
use std::cell::RefCell;
|
||||
|
||||
impl Shell {
|
||||
|
|
@ -34,31 +38,37 @@ impl Shell {
|
|||
) {
|
||||
// TODO touch grab
|
||||
if let Some(pointer) = seat.get_pointer() {
|
||||
let workspace = self.space_for_window_mut(window.toplevel().wl_surface()).unwrap();
|
||||
let workspace = self
|
||||
.space_for_window_mut(window.toplevel().wl_surface())
|
||||
.unwrap();
|
||||
if workspace.fullscreen.values().any(|w| w == window) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let pos = pointer.current_location();
|
||||
let output = workspace.space.outputs_for_window(&window)
|
||||
let output = workspace
|
||||
.space
|
||||
.outputs_for_window(&window)
|
||||
.into_iter()
|
||||
.find(|o| o.geometry().contains(pos.to_i32_round()))
|
||||
.unwrap();
|
||||
let mut initial_window_location = workspace.space.window_location(&window).unwrap();
|
||||
|
||||
|
||||
let output = match &window.toplevel() {
|
||||
Kind::Xdg(surface) => {
|
||||
// If surface is maximized then unmaximize it
|
||||
let current_state = surface.current_state();
|
||||
if current_state.states.contains(XdgState::Maximized) {
|
||||
workspace.floating_layer.unmaximize_request(&mut workspace.space, window);
|
||||
workspace
|
||||
.floating_layer
|
||||
.unmaximize_request(&mut workspace.space, window);
|
||||
let new_size = surface.with_pending_state(|state| state.size);
|
||||
let ratio = pos.x / output.geometry().size.w as f64;
|
||||
|
||||
initial_window_location = new_size.map(|size| (
|
||||
pos.x - (size.w as f64 * ratio),
|
||||
pos.y,
|
||||
).into()).unwrap_or_else(|| pos).to_i32_round();
|
||||
initial_window_location = new_size
|
||||
.map(|size| (pos.x - (size.w as f64 * ratio), pos.y).into())
|
||||
.unwrap_or_else(|| pos)
|
||||
.to_i32_round();
|
||||
}
|
||||
|
||||
output
|
||||
|
|
@ -67,8 +77,8 @@ impl Shell {
|
|||
|
||||
let was_tiled = if workspace.tiling_layer.windows.contains(&window) {
|
||||
workspace
|
||||
.tiling_layer
|
||||
.unmap_window(&mut workspace.space, &window);
|
||||
.tiling_layer
|
||||
.unmap_window(&mut workspace.space, &window);
|
||||
true
|
||||
} else {
|
||||
workspace
|
||||
|
|
@ -76,19 +86,20 @@ impl Shell {
|
|||
.unmap_window(&mut workspace.space, &window);
|
||||
false
|
||||
};
|
||||
|
||||
|
||||
let workspace_handle = workspace.handle;
|
||||
let workspace_is_empty = workspace.space.windows().next().is_none();
|
||||
|
||||
if workspace_is_empty {
|
||||
self.workspace_state.update().add_workspace_state(&workspace_handle, WState::Hidden);
|
||||
self.workspace_state
|
||||
.update()
|
||||
.add_workspace_state(&workspace_handle, WState::Hidden);
|
||||
}
|
||||
self.toplevel_info_state
|
||||
.toplevel_leave_workspace(&window, &workspace_handle);
|
||||
self.toplevel_info_state
|
||||
.toplevel_leave_output(&window, &output);
|
||||
|
||||
|
||||
|
||||
let state = MoveGrabState {
|
||||
window: window.clone(),
|
||||
was_tiled,
|
||||
|
|
@ -97,25 +108,30 @@ impl Shell {
|
|||
};
|
||||
let grab = MoveSurfaceGrab::new(start_data, window.clone(), seat);
|
||||
|
||||
*seat.user_data().get::<SeatMoveGrabState>().unwrap().borrow_mut() = Some(state);
|
||||
*seat
|
||||
.user_data()
|
||||
.get::<SeatMoveGrabState>()
|
||||
.unwrap()
|
||||
.borrow_mut() = Some(state);
|
||||
pointer.set_grab(grab, serial, Focus::Clear);
|
||||
}
|
||||
}
|
||||
|
||||
fn drop_move(
|
||||
&mut self,
|
||||
dh: &DisplayHandle,
|
||||
seat: &Seat<State>,
|
||||
|
||||
output: &Output,
|
||||
) {
|
||||
if let Some(move_state) = seat.user_data().get::<SeatMoveGrabState>().unwrap().borrow_mut().take() {
|
||||
fn drop_move(&mut self, dh: &DisplayHandle, seat: &Seat<State>, output: &Output) {
|
||||
if let Some(move_state) = seat
|
||||
.user_data()
|
||||
.get::<SeatMoveGrabState>()
|
||||
.unwrap()
|
||||
.borrow_mut()
|
||||
.take()
|
||||
{
|
||||
let pointer = seat.get_pointer().unwrap();
|
||||
let window = move_state.window;
|
||||
|
||||
|
||||
if window.alive() {
|
||||
let delta = pointer.current_location() - move_state.initial_cursor_location;
|
||||
let window_location = (move_state.initial_window_location.to_f64() + delta).to_i32_round();
|
||||
let window_location =
|
||||
(move_state.initial_window_location.to_f64() + delta).to_i32_round();
|
||||
let surface = window.toplevel().wl_surface().clone();
|
||||
|
||||
let workspace_handle = self.active_space(output).handle;
|
||||
|
|
@ -137,9 +153,12 @@ impl Shell {
|
|||
focus_stack.iter(),
|
||||
);
|
||||
} else {
|
||||
workspace
|
||||
.floating_layer
|
||||
.map_window(&mut workspace.space, window, &seat, window_location);
|
||||
workspace.floating_layer.map_window(
|
||||
&mut workspace.space,
|
||||
window,
|
||||
&seat,
|
||||
window_location,
|
||||
);
|
||||
}
|
||||
|
||||
self.set_focus(dh, Some(&surface), &seat, None);
|
||||
|
|
@ -175,14 +194,15 @@ where
|
|||
fn id(&self) -> usize {
|
||||
self.seat_id
|
||||
}
|
||||
|
||||
|
||||
fn location(&self, scale: impl Into<Scale<f64>>) -> Point<f64, Physical> {
|
||||
(self.window_location - self.window.geometry().loc.to_f64()).to_physical(scale)
|
||||
}
|
||||
|
||||
fn geometry(&self, scale: impl Into<Scale<f64>>) -> Rectangle<i32, Physical> {
|
||||
let scale = scale.into();
|
||||
self.window.physical_bbox_with_popups(RenderElement::<R>::location(self, scale), scale)
|
||||
self.window
|
||||
.physical_bbox_with_popups(RenderElement::<R>::location(self, scale), scale)
|
||||
}
|
||||
|
||||
fn accumulated_damage(
|
||||
|
|
@ -191,15 +211,20 @@ where
|
|||
for_values: Option<SpaceOutputTuple<'_, '_>>,
|
||||
) -> Vec<Rectangle<i32, Physical>> {
|
||||
let scale = scale.into();
|
||||
self.window.accumulated_damage(RenderElement::<R>::location(self, scale), scale, for_values.map(|t| (t.0, t.1)))
|
||||
self.window.accumulated_damage(
|
||||
RenderElement::<R>::location(self, scale),
|
||||
scale,
|
||||
for_values.map(|t| (t.0, t.1)),
|
||||
)
|
||||
}
|
||||
|
||||
fn opaque_regions(
|
||||
fn opaque_regions(
|
||||
&self,
|
||||
scale: impl Into<Scale<f64>>,
|
||||
) -> Option<Vec<Rectangle<i32, Physical>>> {
|
||||
let scale = scale.into();
|
||||
self.window.opaque_regions(RenderElement::<R>::location(self, scale), scale)
|
||||
self.window
|
||||
.opaque_regions(RenderElement::<R>::location(self, scale), scale)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
@ -218,19 +243,20 @@ where
|
|||
impl MoveGrabState {
|
||||
pub fn render<I>(&self, seat: &Seat<State>, output: &Output) -> Option<I>
|
||||
where
|
||||
I: From<MoveGrabRenderElement>
|
||||
I: From<MoveGrabRenderElement>,
|
||||
{
|
||||
let cursor_at = seat.get_pointer().unwrap().current_location();
|
||||
let delta = cursor_at - self.initial_cursor_location;
|
||||
let mut window_geo = self.window.bbox();
|
||||
window_geo.loc += (self.initial_window_location.to_f64() + delta).to_i32_round();
|
||||
|
||||
|
||||
if !output.geometry().intersection(window_geo).is_some() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let delta = cursor_at - self.initial_cursor_location;
|
||||
let window_location = self.initial_window_location.to_f64() + delta - output.geometry().loc.to_f64();
|
||||
let window_location =
|
||||
self.initial_window_location.to_f64() + delta - output.geometry().loc.to_f64();
|
||||
Some(I::from(MoveGrabRenderElement {
|
||||
seat_id: seat.id(),
|
||||
window: self.window.clone(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue