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

WIP Migrate away from Rectangle::from_loc_and_size #1097

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
14 changes: 7 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@ inherits = "release"
lto = "fat"

[patch."https://github.com/Smithay/smithay.git"]
smithay = { git = "https://github.com/smithay//smithay", rev = "bc1d732" }
smithay = { git = "https://github.com/ids1024/smithay", branch = "geometry" }
11 changes: 4 additions & 7 deletions src/backend/kms/surface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl MirroringState {
.unwrap_or_default()
.to_logical(1)
.to_buffer(1, Transform::Normal);
let opaque_regions = vec![Rectangle::from_loc_and_size((0, 0), size)];
let opaque_regions = vec![Rectangle::from_size(size)];

let texture = Offscreen::<GlesTexture>::create_buffer(renderer, format, size)?;
let transform = output.current_transform();
Expand Down Expand Up @@ -517,10 +517,8 @@ fn surface_thread(

#[cfg(feature = "debug")]
let egui = {
let state = smithay_egui::EguiState::new(smithay::utils::Rectangle::from_loc_and_size(
(0, 0),
(400, 800),
));
let state =
smithay_egui::EguiState::new(smithay::utils::Rectangle::from_size((400, 800).into()));
let mut visuals: egui::style::Visuals = Default::default();
visuals.window_shadow = egui::Shadow::NONE;
state.context().set_visuals(visuals);
Expand Down Expand Up @@ -1149,8 +1147,7 @@ impl SurfaceThreadState {
elements = constrain_render_elements(
std::iter::once(texture_elem),
(0, 0),
Rectangle::from_loc_and_size(
(0, 0),
Rectangle::from_size(
self.output
.geometry()
.size
Expand Down
7 changes: 2 additions & 5 deletions src/backend/render/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl Element for DamageElement {
}

fn src(&self) -> Rectangle<f64, BufferCoords> {
Rectangle::from_loc_and_size((0.0, 0.0), (1.0, 1.0))
Rectangle::from_size((1.0, 1.0).into())
}

fn geometry(&self, scale: Scale<f64>) -> Rectangle<i32, Physical> {
Expand All @@ -391,10 +391,7 @@ impl Element for DamageElement {
scale: Scale<f64>,
_commit: Option<CommitCounter>,
) -> DamageSet<i32, Physical> {
DamageSet::from_slice(&[Rectangle::from_loc_and_size(
(0, 0),
self.geometry(scale).size,
)])
DamageSet::from_slice(&[Rectangle::from_size(self.geometry(scale).size).into()])
}
}

Expand Down
11 changes: 3 additions & 8 deletions src/backend/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,8 @@ where
renderer.glow_renderer_mut(),
state,
timings,
Rectangle::from_loc_and_size(
(0, 0),
(output_geo.size.w.min(400), output_geo.size.h.min(800)),
Rectangle::from_size(
(output_geo.size.w.min(400), output_geo.size.h.min(800)).into(),
),
scale,
)
Expand Down Expand Up @@ -615,11 +614,7 @@ where
.as_logical()
.to_physical_precise_round(scale);
let crop_to_output = |element: WorkspaceRenderElement<R>| {
CropRenderElement::from_element(
element.into(),
scale,
Rectangle::from_loc_and_size((0, 0), output_size),
)
CropRenderElement::from_element(element.into(), scale, Rectangle::from_size(output_size))
};

render_input_order(
Expand Down
4 changes: 2 additions & 2 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ impl State {
let location = global_pos + offset.as_global().to_f64();
let output = workspace.output();
let output_geo = output.geometry().to_local(output);
if Rectangle::from_loc_and_size(offset.as_local(), output_geo.size)
if Rectangle::new(offset.as_local(), output_geo.size)
.intersection(output_geo)
.is_some_and(|geometry| {
geometry.contains(global_pos.to_local(output).to_i32_round())
Expand All @@ -1965,7 +1965,7 @@ impl State {
let location = global_pos + offset.as_global().to_f64();
let output = workspace.output();
let output_geo = output.geometry().to_local(output);
if Rectangle::from_loc_and_size(offset.as_local(), output_geo.size)
if Rectangle::new(offset.as_local(), output_geo.size)
.intersection(output_geo)
.is_some_and(|geometry| {
geometry.contains(global_pos.to_local(output).to_i32_round())
Expand Down
12 changes: 6 additions & 6 deletions src/shell/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ impl CosmicMapped {
let win = stack.active();
let location = stack.offset();
let size = win.geometry().size;
Rectangle::from_loc_and_size(location, size)
Rectangle::new(location, size)
}
CosmicMappedInternal::Window(win) => {
let location = win.offset();
let size = win.geometry().size;
Rectangle::from_loc_and_size(location, size)
Rectangle::new(location, size)
}
_ => unreachable!(),
}
Expand Down Expand Up @@ -646,9 +646,9 @@ impl CosmicMapped {
pub fn set_debug(&self, flag: bool) {
let mut debug = self.debug.lock().unwrap();
if flag {
*debug = Some(smithay_egui::EguiState::new(Rectangle::from_loc_and_size(
(10, 10),
(100, 100),
*debug = Some(smithay_egui::EguiState::new(Rectangle::new(
(10, 10).into(),
(100, 100).into(),
)));
} else {
debug.take();
Expand Down Expand Up @@ -704,7 +704,7 @@ impl CosmicMapped {
let (min_size, max_size, size) =
(window.min_size(), window.max_size(), window.geometry().size);

let area = Rectangle::<i32, Logical>::from_loc_and_size(
let area = Rectangle::<i32, Logical>::new(
location.to_f64().to_logical(scale).to_i32_round(),
self.bbox().size,
);
Expand Down
8 changes: 4 additions & 4 deletions src/shell/element/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ impl CosmicStack {
let loc = (geo.loc.x, geo.loc.y + TAB_HEIGHT);
let size = (geo.size.w, geo.size.h - TAB_HEIGHT);

let win_geo = Rectangle::from_loc_and_size(loc, size);
let win_geo = Rectangle::new(loc.into(), size.into());
for window in p.windows.lock().unwrap().iter() {
window.set_geometry(win_geo, TAB_HEIGHT as u32);
}
Expand Down Expand Up @@ -989,9 +989,9 @@ impl Program for CosmicStackInternal {
theme: &Theme,
) {
if self.group_focused.load(Ordering::SeqCst) {
let border = Rectangle::from_loc_and_size(
(0, ((TAB_HEIGHT as f32 * scale) - scale).floor() as i32),
(pixels.width() as i32, scale.ceil() as i32),
let border = Rectangle::new(
(0, ((TAB_HEIGHT as f32 * scale) - scale).floor() as i32).into(),
(pixels.width() as i32, scale.ceil() as i32).into(),
);

let mut paint = tiny_skia::Paint::default();
Expand Down
2 changes: 1 addition & 1 deletion src/shell/element/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl CosmicWindow {
let loc = (geo.loc.x, geo.loc.y + ssd_height);
let size = (geo.size.w, std::cmp::max(geo.size.h - ssd_height, 0));
p.window
.set_geometry(Rectangle::from_loc_and_size(loc, size), ssd_height as u32);
.set_geometry(Rectangle::new(loc.into(), size.into()), ssd_height as u32);
});
}

Expand Down
16 changes: 8 additions & 8 deletions src/shell/grabs/menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl Program for ContextMenu {
let output = seat.active_output();
let position = [
// to the right -> down
Rectangle::from_loc_and_size(
Rectangle::new(
position
+ Point::from((
bounds.width.ceil() as i32,
Expand All @@ -258,7 +258,7 @@ impl Program for ContextMenu {
min_size.as_global(),
),
// to the right -> up
Rectangle::from_loc_and_size(
Rectangle::new(
position
+ Point::from((
bounds.width.ceil() as i32,
Expand All @@ -268,12 +268,12 @@ impl Program for ContextMenu {
min_size.as_global(),
),
// to the left -> down
Rectangle::from_loc_and_size(
Rectangle::new(
position + Point::from((-min_size.w, bounds.y.ceil() as i32)),
min_size.as_global(),
),
// to the left -> up
Rectangle::from_loc_and_size(
Rectangle::new(
position
+ Point::from((
-min_size.w,
Expand Down Expand Up @@ -669,16 +669,16 @@ impl MenuGrab {

let output = seat.active_output();
let position = [
Rectangle::from_loc_and_size(position, min_size.as_global()), // normal
Rectangle::from_loc_and_size(
Rectangle::new(position, min_size.as_global()), // normal
Rectangle::new(
position - Point::from((min_size.w, 0)),
min_size.as_global(),
), // flipped left
Rectangle::from_loc_and_size(
Rectangle::new(
position - Point::from((0, min_size.h)),
min_size.as_global(),
), // flipped up
Rectangle::from_loc_and_size(
Rectangle::new(
position - Point::from((min_size.w, min_size.h)),
min_size.as_global(),
), // flipped left & up
Expand Down
29 changes: 13 additions & 16 deletions src/shell/grabs/moving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl MoveGrabState {
CosmicMappedRenderElement::from(IndicatorShader::focus_element(
renderer,
Key::Window(Usage::MoveGrabIndicator, self.window.key()),
Rectangle::from_loc_and_size(
Rectangle::new(
render_location,
self.window
.geometry()
Expand Down Expand Up @@ -350,15 +350,15 @@ impl MoveGrab {
fn update_location(&mut self, state: &mut State, location: Point<f64, Logical>) {
let mut shell = state.common.shell.write().unwrap();

let Some(current_output) =
shell
.outputs()
.find(|output| {
output.geometry().as_logical().overlaps_or_touches(
Rectangle::from_loc_and_size(location.to_i32_floor(), (0, 0)),
)
})
.cloned()
let Some(current_output) = shell
.outputs()
.find(|output| {
output
.geometry()
.as_logical()
.overlaps_or_touches(Rectangle::new(location.to_i32_floor(), (0, 0).into()))
})
.cloned()
else {
return;
};
Expand Down Expand Up @@ -411,10 +411,7 @@ impl MoveGrab {
for output in &self.window_outputs {
element.output_enter(
output,
Rectangle::from_loc_and_size(
(0, 0),
output.geometry().size.as_logical(),
),
Rectangle::from_size(output.geometry().size.as_logical()),
);
}
(element, geo.loc.as_logical())
Expand Down Expand Up @@ -777,7 +774,7 @@ impl Drop for MoveGrab {

match previous {
ManagedLayer::Sticky => {
grab_state.window.set_geometry(Rectangle::from_loc_and_size(
grab_state.window.set_geometry(Rectangle::new(
window_location,
grab_state.window.geometry().size.as_global(),
));
Expand All @@ -796,7 +793,7 @@ impl Drop for MoveGrab {
Some((window, location.to_global(&output)))
}
_ => {
grab_state.window.set_geometry(Rectangle::from_loc_and_size(
grab_state.window.set_geometry(Rectangle::new(
window_location,
grab_state.window.geometry().size.as_global(),
));
Expand Down
4 changes: 2 additions & 2 deletions src/shell/layout/floating/grabs/resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl ResizeSurfaceGrab {
self.last_window_size = (new_window_width, new_window_height).into();

self.window.set_resizing(true);
self.window.set_geometry(Rectangle::from_loc_and_size(
self.window.set_geometry(Rectangle::new(
if let Some(s) = self.window.active_window().x11_surface() {
s.geometry().loc.as_global()
} else {
Expand Down Expand Up @@ -523,7 +523,7 @@ impl ResizeSurfaceGrab {
}

self.window.set_resizing(false);
self.window.set_geometry(Rectangle::from_loc_and_size(
self.window.set_geometry(Rectangle::new(
if let Some(x11_surface) = self.window.active_window().x11_surface() {
x11_surface.geometry().loc.as_global()
} else {
Expand Down
Loading