layout: Cache scale and transform on the workspace
Browse files at this commit2ffa1ae705516b5b52e8bfaff36d208d76ae5e01Parent: fee72b83 changed files +49 -52
- src/layout/mod.rs +3 -2
- src/layout/monitor.rs +3 -1
- src/layout/workspace.rs +43 -49
src/layout/mod.rsmodified+3 -2
| @@ -923,12 +923,13 @@ impl<W: LayoutElement> Layout<W> { | |||
| 923 | 923 | ||
| 924 | for mon in monitors { | 924 | for mon in monitors { |
| 925 | if &mon.output == output { | 925 | if &mon.output == output { |
| 926 | + let scale = output.current_scale(); | ||
| 927 | + let transform = output.current_transform(); | ||
| 926 | let view_size = output_size(output); | 928 | let view_size = output_size(output); |
| 927 | let working_area = compute_working_area(output, self.options.struts); | 929 | let working_area = compute_working_area(output, self.options.struts); |
| 928 | 930 | ||
| 929 | for ws in &mut mon.workspaces { | 931 | for ws in &mut mon.workspaces { |
| 930 | - ws.set_view_size(view_size, working_area); | 932 | + ws.set_view_size(scale, transform, view_size, working_area); |
| 931 | - ws.update_output_scale_transform(); | ||
| 932 | } | 933 | } |
| 933 | 934 | ||
| 934 | break; | 935 | break; |
src/layout/monitor.rsmodified+3 -1
| @@ -681,11 +681,13 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 681 | } | 681 | } |
| 682 | 682 | ||
| 683 | if self.options.struts != options.struts { | 683 | if self.options.struts != options.struts { |
| 684 | + let scale = self.output.current_scale(); | ||
| 685 | + let transform = self.output.current_transform(); | ||
| 684 | let view_size = output_size(&self.output); | 686 | let view_size = output_size(&self.output); |
| 685 | let working_area = compute_working_area(&self.output, options.struts); | 687 | let working_area = compute_working_area(&self.output, options.struts); |
| 686 | 688 | ||
| 687 | for ws in &mut self.workspaces { | 689 | for ws in &mut self.workspaces { |
| 688 | - ws.set_view_size(view_size, working_area); | 690 | + ws.set_view_size(scale, transform, view_size, working_area); |
| 689 | } | 691 | } |
| 690 | } | 692 | } |
| 691 | 693 | ||
src/layout/workspace.rsmodified+43 -49
| @@ -10,7 +10,7 @@ use smithay::desktop::{layer_map_for_output, Window}; | |||
| 10 | use smithay::output::Output; | 10 | use smithay::output::Output; |
| 11 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; | 11 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; |
| 12 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; | 12 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; |
| 13 | -use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size}; | 13 | +use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size, Transform}; |
| 14 | 14 | ||
| 15 | use super::closing_window::{ClosingWindow, ClosingWindowRenderElement}; | 15 | use super::closing_window::{ClosingWindow, ClosingWindowRenderElement}; |
| 16 | use super::tile::{Tile, TileRenderElement}; | 16 | use super::tile::{Tile, TileRenderElement}; |
| @@ -38,6 +38,18 @@ pub struct Workspace<W: LayoutElement> { | |||
| 38 | /// Current output of this workspace. | 38 | /// Current output of this workspace. |
| 39 | output: Option<Output>, | 39 | output: Option<Output>, |
| 40 | 40 | ||
| 41 | + /// Latest known output scale for this workspace. | ||
| 42 | + /// | ||
| 43 | + /// This should be set from the current workspace output, or, if all outputs have been | ||
| 44 | + /// disconnected, preserved until a new output is connected. | ||
| 45 | + scale: smithay::output::Scale, | ||
| 46 | + | ||
| 47 | + /// Latest known output transform for this workspace. | ||
| 48 | + /// | ||
| 49 | + /// This should be set from the current workspace output, or, if all outputs have been | ||
| 50 | + /// disconnected, preserved until a new output is connected. | ||
| 51 | + transform: Transform, | ||
| 52 | + | ||
| 41 | /// Latest known view size for this workspace. | 53 | /// Latest known view size for this workspace. |
| 42 | /// | 54 | /// |
| 43 | /// This should be computed from the current workspace output size, or, if all outputs have | 55 | /// This should be computed from the current workspace output size, or, if all outputs have |
| @@ -332,6 +344,8 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 332 | let working_area = compute_working_area(&output, options.struts); | 344 | let working_area = compute_working_area(&output, options.struts); |
| 333 | Self { | 345 | Self { |
| 334 | original_output, | 346 | original_output, |
| 347 | + scale: output.current_scale(), | ||
| 348 | + transform: output.current_transform(), | ||
| 335 | view_size: output_size(&output), | 349 | view_size: output_size(&output), |
| 336 | working_area, | 350 | working_area, |
| 337 | output: Some(output), | 351 | output: Some(output), |
| @@ -362,6 +376,8 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 362 | ); | 376 | ); |
| 363 | Self { | 377 | Self { |
| 364 | output: None, | 378 | output: None, |
| 379 | + scale: smithay::output::Scale::Integer(1), | ||
| 380 | + transform: Transform::Normal, | ||
| 365 | original_output, | 381 | original_output, |
| 366 | view_size: Size::from((1280, 720)), | 382 | view_size: Size::from((1280, 720)), |
| 367 | working_area: Rectangle::from_loc_and_size((0, 0), (1280, 720)), | 383 | working_area: Rectangle::from_loc_and_size((0, 0), (1280, 720)), |
| @@ -488,8 +504,10 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 488 | self.output = output; | 504 | self.output = output; |
| 489 | 505 | ||
| 490 | if let Some(output) = &self.output { | 506 | if let Some(output) = &self.output { |
| 507 | + let scale = output.current_scale(); | ||
| 508 | + let transform = output.current_transform(); | ||
| 491 | let working_area = compute_working_area(output, self.options.struts); | 509 | let working_area = compute_working_area(output, self.options.struts); |
| 492 | - self.set_view_size(output_size(output), working_area); | 510 | + self.set_view_size(scale, transform, output_size(output), working_area); |
| 493 | 511 | ||
| 494 | for win in self.windows() { | 512 | for win in self.windows() { |
| 495 | self.enter_output_for_window(win); | 513 | self.enter_output_for_window(win); |
| @@ -499,41 +517,45 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 499 | 517 | ||
| 500 | fn enter_output_for_window(&self, window: &W) { | 518 | fn enter_output_for_window(&self, window: &W) { |
| 501 | if let Some(output) = &self.output { | 519 | if let Some(output) = &self.output { |
| 502 | - set_preferred_scale_transform(window, output); | 520 | + window.set_preferred_scale_transform(self.scale, self.transform); |
| 503 | window.output_enter(output); | 521 | window.output_enter(output); |
| 504 | } | 522 | } |
| 505 | } | 523 | } |
| 506 | 524 | ||
| 507 | pub fn set_view_size( | 525 | pub fn set_view_size( |
| 508 | &mut self, | 526 | &mut self, |
| 527 | + scale: smithay::output::Scale, | ||
| 528 | + transform: Transform, | ||
| 509 | size: Size<i32, Logical>, | 529 | size: Size<i32, Logical>, |
| 510 | working_area: Rectangle<i32, Logical>, | 530 | working_area: Rectangle<i32, Logical>, |
| 511 | ) { | 531 | ) { |
| 512 | - if self.view_size == size && self.working_area == working_area { | 532 | + let scale_transform_changed = self.transform != transform |
| 533 | + || self.scale.integer_scale() != scale.integer_scale() | ||
| 534 | + || self.scale.fractional_scale() != scale.fractional_scale(); | ||
| 535 | + if !scale_transform_changed && self.view_size == size && self.working_area == working_area { | ||
| 513 | return; | 536 | return; |
| 514 | } | 537 | } |
| 515 | 538 | ||
| 539 | + self.scale = scale; | ||
| 540 | + self.transform = transform; | ||
| 516 | self.view_size = size; | 541 | self.view_size = size; |
| 517 | self.working_area = working_area; | 542 | self.working_area = working_area; |
| 518 | 543 | ||
| 519 | for col in &mut self.columns { | 544 | for col in &mut self.columns { |
| 520 | col.set_view_size(self.view_size, self.working_area); | 545 | col.set_view_size(self.view_size, self.working_area); |
| 521 | } | 546 | } |
| 547 | + | ||
| 548 | + if scale_transform_changed { | ||
| 549 | + for window in self.windows() { | ||
| 550 | + window.set_preferred_scale_transform(self.scale, self.transform); | ||
| 551 | + } | ||
| 552 | + } | ||
| 522 | } | 553 | } |
| 523 | 554 | ||
| 524 | pub fn view_size(&self) -> Size<i32, Logical> { | 555 | pub fn view_size(&self) -> Size<i32, Logical> { |
| 525 | self.view_size | 556 | self.view_size |
| 526 | } | 557 | } |
| 527 | 558 | ||
| 528 | - pub fn update_output_scale_transform(&mut self) { | ||
| 529 | - let Some(output) = self.output.as_ref() else { | ||
| 530 | - return; | ||
| 531 | - }; | ||
| 532 | - for window in self.windows() { | ||
| 533 | - set_preferred_scale_transform(window, output); | ||
| 534 | - } | ||
| 535 | - } | ||
| 536 | - | ||
| 537 | fn toplevel_bounds(&self, rules: &ResolvedWindowRules) -> Size<i32, Logical> { | 559 | fn toplevel_bounds(&self, rules: &ResolvedWindowRules) -> Size<i32, Logical> { |
| 538 | let border_config = rules.border.resolve_against(self.options.border); | 560 | let border_config = rules.border.resolve_against(self.options.border); |
| 539 | compute_toplevel_bounds(border_config, self.working_area.size, self.options.gaps) | 561 | compute_toplevel_bounds(border_config, self.working_area.size, self.options.gaps) |
| @@ -585,13 +607,9 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 585 | width: Option<ColumnWidth>, | 607 | width: Option<ColumnWidth>, |
| 586 | rules: &ResolvedWindowRules, | 608 | rules: &ResolvedWindowRules, |
| 587 | ) { | 609 | ) { |
| 588 | - if let Some(output) = self.output.as_ref() { | 610 | + window.with_surfaces(|surface, data| { |
| 589 | - let scale = output.current_scale(); | 611 | + send_scale_transform(surface, data, self.scale, self.transform); |
| 590 | - let transform = output.current_transform(); | 612 | + }); |
| 591 | - window.with_surfaces(|surface, data| { | ||
| 592 | - send_scale_transform(surface, data, scale, transform); | ||
| 593 | - }); | ||
| 594 | - } | ||
| 595 | 613 | ||
| 596 | window | 614 | window |
| 597 | .toplevel() | 615 | .toplevel() |
| @@ -1367,14 +1385,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1367 | } | 1385 | } |
| 1368 | 1386 | ||
| 1369 | pub fn store_unmap_snapshot_if_empty(&mut self, renderer: &mut GlesRenderer, window: &W::Id) { | 1387 | pub fn store_unmap_snapshot_if_empty(&mut self, renderer: &mut GlesRenderer, window: &W::Id) { |
| 1370 | - // FIXME: workspaces should probably cache their last used scale so they can be correctly | 1388 | + let output_scale = Scale::from(self.scale.fractional_scale()); |
| 1371 | - // rendered even with no outputs connected. | ||
| 1372 | - let output_scale = self | ||
| 1373 | - .output | ||
| 1374 | - .as_ref() | ||
| 1375 | - .map(|o| Scale::from(o.current_scale().fractional_scale())) | ||
| 1376 | - .unwrap_or(Scale::from(1.)); | ||
| 1377 | - | ||
| 1378 | let view_size = self.view_size(); | 1389 | let view_size = self.view_size(); |
| 1379 | for (tile, tile_pos) in self.tiles_with_render_positions_mut() { | 1390 | for (tile, tile_pos) in self.tiles_with_render_positions_mut() { |
| 1380 | if tile.window().id() == window { | 1391 | if tile.window().id() == window { |
| @@ -1403,13 +1414,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1403 | renderer: &mut GlesRenderer, | 1414 | renderer: &mut GlesRenderer, |
| 1404 | window: &W::Id, | 1415 | window: &W::Id, |
| 1405 | ) { | 1416 | ) { |
| 1406 | - // FIXME: workspaces should probably cache their last used scale so they can be correctly | 1417 | + let output_scale = Scale::from(self.scale.fractional_scale()); |
| 1407 | - // rendered even with no outputs connected. | ||
| 1408 | - let output_scale = self | ||
| 1409 | - .output | ||
| 1410 | - .as_ref() | ||
| 1411 | - .map(|o| Scale::from(o.current_scale().fractional_scale())) | ||
| 1412 | - .unwrap_or(Scale::from(1.)); | ||
| 1413 | 1418 | ||
| 1414 | let (tile, mut tile_pos) = self | 1419 | let (tile, mut tile_pos) = self |
| 1415 | .tiles_with_render_positions_mut() | 1420 | .tiles_with_render_positions_mut() |
| @@ -1472,6 +1477,8 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1472 | pub fn verify_invariants(&self) { | 1477 | pub fn verify_invariants(&self) { |
| 1473 | assert!(self.view_size.w > 0); | 1478 | assert!(self.view_size.w > 0); |
| 1474 | assert!(self.view_size.h > 0); | 1479 | assert!(self.view_size.h > 0); |
| 1480 | + assert!(self.scale.fractional_scale() > 0.); | ||
| 1481 | + assert!(self.scale.fractional_scale().is_finite()); | ||
| 1475 | assert_eq!(self.columns.len(), self.data.len()); | 1482 | assert_eq!(self.columns.len(), self.data.len()); |
| 1476 | 1483 | ||
| 1477 | if !self.columns.is_empty() { | 1484 | if !self.columns.is_empty() { |
| @@ -2243,13 +2250,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 2243 | renderer: &mut R, | 2250 | renderer: &mut R, |
| 2244 | target: RenderTarget, | 2251 | target: RenderTarget, |
| 2245 | ) -> Vec<WorkspaceRenderElement<R>> { | 2252 | ) -> Vec<WorkspaceRenderElement<R>> { |
| 2246 | - // FIXME: workspaces should probably cache their last used scale so they can be correctly | 2253 | + let output_scale = Scale::from(self.scale.fractional_scale()); |
| 2247 | - // rendered even with no outputs connected. | ||
| 2248 | - let output_scale = self | ||
| 2249 | - .output | ||
| 2250 | - .as_ref() | ||
| 2251 | - .map(|o| Scale::from(o.current_scale().fractional_scale())) | ||
| 2252 | - .unwrap_or(Scale::from(1.)); | ||
| 2253 | 2254 | ||
| 2254 | let mut rv = vec![]; | 2255 | let mut rv = vec![]; |
| 2255 | 2256 | ||
| @@ -3386,13 +3387,6 @@ fn compute_new_view_offset( | |||
| 3386 | } | 3387 | } |
| 3387 | } | 3388 | } |
| 3388 | 3389 | ||
| 3389 | -fn set_preferred_scale_transform(window: &impl LayoutElement, output: &Output) { | ||
| 3390 | - // FIXME: cache this on the workspace. | ||
| 3391 | - let scale = output.current_scale(); | ||
| 3392 | - let transform = output.current_transform(); | ||
| 3393 | - window.set_preferred_scale_transform(scale, transform); | ||
| 3394 | -} | ||
| 3395 | - | ||
| 3396 | pub fn compute_working_area(output: &Output, struts: Struts) -> Rectangle<i32, Logical> { | 3390 | pub fn compute_working_area(output: &Output, struts: Struts) -> Rectangle<i32, Logical> { |
| 3397 | // Start with the layer-shell non-exclusive zone. | 3391 | // Start with the layer-shell non-exclusive zone. |
| 3398 | let mut working_area = layer_map_for_output(output).non_exclusive_zone(); | 3392 | let mut working_area = layer_map_for_output(output).non_exclusive_zone(); |