forge
Explore
Log in

Don't you dare go Hollow

layout: Refactor to support window decorations, add border and fullscreen backdrop

Browse files at this commit

c21805bf705bd36a6eb7f79039b759e9af79dfcbIvan MolodetskikhParent: bfc2418
Windows are now wrapped in Tiles, which keep track of window-specific
decorations. Particularly, I implemented a black fullscreen backdrop,
which finally brings fullscreened windows smaller than the screen in
line with how the Wayland protocol says they should look—centered in a
black rectangle. I also implemented window borders, which are similar to
the focus ring, but always visible (and hence affect the layout and
sizing).
resources/default-config.kdlmodified+11 -0
@@ -89,6 +89,17 @@ focus-ring {
89 inactive-color 80 80 80 25589 inactive-color 80 80 80 255
90 }90 }
91 91
92+// You can also add a border. It's similar to the focus ring, but always visible.
93+border {
94+ // The settings are the same as for the focus ring.
95+ // If you enable the border, you probably want to disable the focus ring.
96+ off
97+
98+ width 4
99+ active-color 255 200 127 255
100+ inactive-color 80 80 80 255
101+}
102+
92 cursor {103 cursor {
93 // Change the theme and size of the cursor as well as set the104 // Change the theme and size of the cursor as well as set the
94 // `XCURSOR_THEME` and `XCURSOR_SIZE` env variables.105 // `XCURSOR_THEME` and `XCURSOR_SIZE` env variables.
src/config.rsmodified+34 -1
@@ -18,6 +18,8 @@ pub struct Config {
18 pub spawn_at_startup: Vec<SpawnAtStartup>,18 pub spawn_at_startup: Vec<SpawnAtStartup>,
19 #[knuffel(child, default)]19 #[knuffel(child, default)]
20 pub focus_ring: FocusRing,20 pub focus_ring: FocusRing,
21+ #[knuffel(child, default = default_border())]
22+ pub border: FocusRing,
21 #[knuffel(child, default)]23 #[knuffel(child, default)]
22 pub prefer_no_csd: bool,24 pub prefer_no_csd: bool,
23 #[knuffel(child, default)]25 #[knuffel(child, default)]
@@ -190,6 +192,15 @@ impl Default for FocusRing {
190 }192 }
191 }193 }
192 194
195+pub const fn default_border() -> FocusRing {
196+ FocusRing {
197+ off: true,
198+ width: 4,
199+ active_color: Color::new(255, 200, 127, 255),
200+ inactive_color: Color::new(80, 80, 80, 255),
201+ }
202+}
203+
193 #[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)]204 #[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)]
194 pub struct Color {205 pub struct Color {
195 #[knuffel(argument)]206 #[knuffel(argument)]
@@ -203,7 +214,7 @@ pub struct Color {
203 }214 }
204 215
205 impl Color {216 impl Color {
206- pub fn new(r: u8, g: u8, b: u8, a: u8) -> Self {217+ pub const fn new(r: u8, g: u8, b: u8, a: u8) -> Self {
207 Self { r, g, b, a }218 Self { r, g, b, a }
208 }219 }
209 }220 }
@@ -590,6 +601,12 @@ mod tests {
590 inactive-color 255 200 100 0601 inactive-color 255 200 100 0
591 }602 }
592 603
604+ border {
605+ width 3
606+ active-color 0 100 200 255
607+ inactive-color 255 200 100 0
608+ }
609+
593 prefer-no-csd610 prefer-no-csd
594 611
595 cursor {612 cursor {
@@ -680,6 +697,22 @@ mod tests {
680 a: 0,697 a: 0,
681 },698 },
682 },699 },
700+ border: FocusRing {
701+ off: false,
702+ width: 3,
703+ active_color: Color {
704+ r: 0,
705+ g: 100,
706+ b: 200,
707+ a: 255,
708+ },
709+ inactive_color: Color {
710+ r: 255,
711+ g: 200,
712+ b: 100,
713+ a: 0,
714+ },
715+ },
683 prefer_no_csd: true,716 prefer_no_csd: true,
684 cursor: Cursor {717 cursor: Cursor {
685 xcursor_theme: String::from("breeze_cursors"),718 xcursor_theme: String::from("breeze_cursors"),
src/layout/focus_ring.rsmodified+8 -0
@@ -105,4 +105,12 @@ impl FocusRing {
105 105
106 rv.into_iter()106 rv.into_iter()
107 }107 }
108+
109+ pub fn width(&self) -> i32 {
110+ self.width
111+ }
112+
113+ pub fn is_off(&self) -> bool {
114+ self.is_off
115+ }
108 }116 }
src/layout/mod.rsmodified+21 -1
@@ -56,6 +56,7 @@ use crate::utils::output_size;
56 56
57 mod focus_ring;57 mod focus_ring;
58 mod monitor;58 mod monitor;
59+mod tile;
59 mod workspace;60 mod workspace;
60 61
61 pub trait LayoutElement: PartialEq {62 pub trait LayoutElement: PartialEq {
@@ -97,6 +98,11 @@ pub trait LayoutElement: PartialEq {
97 fn set_preferred_scale_transform(&self, scale: i32, transform: Transform);98 fn set_preferred_scale_transform(&self, scale: i32, transform: Transform);
98 fn output_enter(&self, output: &Output);99 fn output_enter(&self, output: &Output);
99 fn output_leave(&self, output: &Output);100 fn output_leave(&self, output: &Output);
101+
102+ /// Whether the element is currently fullscreen.
103+ ///
104+ /// This will *not* switch immediately after a [`LayoutElement::request_fullscreen()`] call.
105+ fn is_fullscreen(&self) -> bool;
100 }106 }
101 107
102 #[derive(Debug)]108 #[derive(Debug)]
@@ -132,6 +138,7 @@ pub struct Options {
132 /// Extra padding around the working area in logical pixels.138 /// Extra padding around the working area in logical pixels.
133 struts: Struts,139 struts: Struts,
134 focus_ring: config::FocusRing,140 focus_ring: config::FocusRing,
141+ border: config::FocusRing,
135 /// Column widths that `toggle_width()` switches between.142 /// Column widths that `toggle_width()` switches between.
136 preset_widths: Vec<ColumnWidth>,143 preset_widths: Vec<ColumnWidth>,
137 /// Initial width for new windows.144 /// Initial width for new windows.
@@ -144,6 +151,7 @@ impl Default for Options {
144 gaps: 16,151 gaps: 16,
145 struts: Default::default(),152 struts: Default::default(),
146 focus_ring: Default::default(),153 focus_ring: Default::default(),
154+ border: config::default_border(),
147 preset_widths: vec![155 preset_widths: vec![
148 ColumnWidth::Proportion(1. / 3.),156 ColumnWidth::Proportion(1. / 3.),
149 ColumnWidth::Proportion(0.5),157 ColumnWidth::Proportion(0.5),
@@ -180,6 +188,7 @@ impl Options {
180 gaps: config.gaps.into(),188 gaps: config.gaps.into(),
181 struts: config.struts,189 struts: config.struts,
182 focus_ring: config.focus_ring,190 focus_ring: config.focus_ring,
191+ border: config.border,
183 preset_widths,192 preset_widths,
184 default_width,193 default_width,
185 }194 }
@@ -269,6 +278,13 @@ impl LayoutElement for Window {
269 fn output_leave(&self, output: &Output) {278 fn output_leave(&self, output: &Output) {
270 SpaceElement::output_leave(self, output)279 SpaceElement::output_leave(self, output)
271 }280 }
281+
282+ fn is_fullscreen(&self) -> bool {
283+ self.toplevel()
284+ .current_state()
285+ .states
286+ .contains(xdg_toplevel::State::Fullscreen)
287+ }
272 }288 }
273 289
274 impl<W: LayoutElement> Layout<W> {290 impl<W: LayoutElement> Layout<W> {
@@ -701,7 +717,7 @@ impl<W: LayoutElement> Layout<W> {
701 }717 }
702 718
703 let col = &ws.columns[ws.active_column_idx];719 let col = &ws.columns[ws.active_column_idx];
704- Some((&col.windows[col.active_window_idx], &mon.output))720+ Some((&col.windows[col.active_window_idx].window(), &mon.output))
705 }721 }
706 722
707 pub fn windows_for_output(&self, output: &Output) -> impl Iterator<Item = &W> + '_ {723 pub fn windows_for_output(&self, output: &Output) -> impl Iterator<Item = &W> + '_ {
@@ -1458,6 +1474,10 @@ mod tests {
1458 fn output_enter(&self, _output: &Output) {}1474 fn output_enter(&self, _output: &Output) {}
1459 1475
1460 fn output_leave(&self, _output: &Output) {}1476 fn output_leave(&self, _output: &Output) {}
1477+
1478+ fn is_fullscreen(&self) -> bool {
1479+ false
1480+ }
1461 }1481 }
1462 1482
1463 fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> {1483 fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> {
src/layout/monitor.rsmodified+1 -1
@@ -345,7 +345,7 @@ impl<W: LayoutElement> Monitor<W> {
345 }345 }
346 346
347 let column = &workspace.columns[workspace.active_column_idx];347 let column = &workspace.columns[workspace.active_column_idx];
348- Some(&column.windows[column.active_window_idx])348+ Some(column.windows[column.active_window_idx].window())
349 }349 }
350 350
351 pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {351 pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {
src/layout/tile.rsadded+267 -0
@@ -0,0 +1,267 @@
1+use std::cmp::max;
2+use std::rc::Rc;
3+use std::time::Duration;
4+
5+use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
6+use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement};
7+use smithay::backend::renderer::element::Kind;
8+use smithay::backend::renderer::{ImportAll, Renderer};
9+use smithay::utils::{Logical, Point, Scale, Size};
10+
11+use super::focus_ring::FocusRing;
12+use super::workspace::WorkspaceRenderElement;
13+use super::{LayoutElement, Options};
14+
15+/// Toplevel window with decorations.
16+#[derive(Debug)]
17+pub struct Tile<W: LayoutElement> {
18+ /// The toplevel window itself.
19+ window: W,
20+
21+ /// The border around the window.
22+ border: FocusRing,
23+
24+ /// Whether this tile is fullscreen.
25+ ///
26+ /// This will update only when the `window` actually goes fullscreen, rather than right away,
27+ /// to avoid black backdrop flicker before the window has had a chance to resize.
28+ is_fullscreen: bool,
29+
30+ /// The black backdrop for fullscreen windows.
31+ fullscreen_backdrop: SolidColorBuffer,
32+
33+ /// The size we were requested to fullscreen into.
34+ fullscreen_size: Size<i32, Logical>,
35+
36+ /// Configurable properties of the layout.
37+ options: Rc<Options>,
38+}
39+
40+impl<W: LayoutElement> Tile<W> {
41+ pub fn new(window: W, options: Rc<Options>) -> Self {
42+ Self {
43+ window,
44+ border: FocusRing::new(options.border),
45+ is_fullscreen: false, // FIXME: up-to-date fullscreen right away, but we need size.
46+ fullscreen_backdrop: SolidColorBuffer::new((0, 0), [0., 0., 0., 1.]),
47+ fullscreen_size: Default::default(),
48+ options,
49+ }
50+ }
51+
52+ pub fn update_config(&mut self, options: Rc<Options>) {
53+ self.border.update_config(options.border);
54+ self.options = options;
55+ }
56+
57+ pub fn advance_animations(&mut self, _current_time: Duration, is_active: bool) {
58+ let width = self.border.width();
59+ self.border.update(
60+ (width, width).into(),
61+ self.window.size(),
62+ self.window.has_ssd(),
63+ );
64+ self.border.set_active(is_active);
65+
66+ // FIXME: remove when we can get a fullscreen size right away.
67+ if self.fullscreen_size != Size::from((0, 0)) {
68+ self.is_fullscreen = self.window.is_fullscreen();
69+ }
70+ }
71+
72+ pub fn window(&self) -> &W {
73+ &self.window
74+ }
75+
76+ pub fn into_window(self) -> W {
77+ self.window
78+ }
79+
80+ /// Returns `None` if the border is hidden and `Some(width)` if it should be shown.
81+ fn effective_border_width(&self) -> Option<i32> {
82+ if self.is_fullscreen {
83+ return None;
84+ }
85+
86+ if self.border.is_off() {
87+ return None;
88+ }
89+
90+ Some(self.border.width())
91+ }
92+
93+ /// Returns the location of the window's visual geometry within this Tile.
94+ fn window_loc(&self) -> Point<i32, Logical> {
95+ let mut loc = Point::from((0, 0));
96+
97+ // In fullscreen, center the window in the given size.
98+ if self.is_fullscreen {
99+ let window_size = self.window.size();
100+ let target_size = self.fullscreen_size;
101+
102+ // Windows aren't supposed to be larger than the fullscreen size, but in case we get
103+ // one, leave it at the top-left as usual.
104+ if window_size.w < target_size.w {
105+ loc.x += (target_size.w - window_size.w) / 2;
106+ }
107+ if window_size.h < target_size.h {
108+ loc.y += (target_size.h - window_size.h) / 2;
109+ }
110+ }
111+
112+ if let Some(width) = self.effective_border_width() {
113+ loc += (width, width).into();
114+ }
115+
116+ loc
117+ }
118+
119+ pub fn tile_size(&self) -> Size<i32, Logical> {
120+ let mut size = self.window.size();
121+
122+ if self.is_fullscreen {
123+ // Normally we'd just return the fullscreen size here, but this makes things a bit
124+ // nicer if a fullscreen window is bigger than the fullscreen size for some reason.
125+ size.w = max(size.w, self.fullscreen_size.w);
126+ size.h = max(size.h, self.fullscreen_size.h);
127+ return size;
128+ }
129+
130+ if let Some(width) = self.effective_border_width() {
131+ size += (width * 2, width * 2).into();
132+ }
133+
134+ size
135+ }
136+
137+ pub fn window_size(&self) -> Size<i32, Logical> {
138+ self.window.size()
139+ }
140+
141+ pub fn buf_loc(&self) -> Point<i32, Logical> {
142+ let mut loc = Point::from((0, 0));
143+ loc += self.window_loc();
144+ loc += self.window.buf_loc();
145+ loc
146+ }
147+
148+ pub fn is_in_input_region(&self, mut point: Point<f64, Logical>) -> bool {
149+ point -= self.window_loc().to_f64();
150+ self.window.is_in_input_region(point)
151+ }
152+
153+ pub fn request_tile_size(&mut self, mut size: Size<i32, Logical>) {
154+ // Can't go through effective_border_width() because we might be fullscreen.
155+ if !self.border.is_off() {
156+ let width = self.border.width();
157+ size.w = max(1, size.w - width * 2);
158+ size.h = max(1, size.h - width * 2);
159+ }
160+
161+ self.window.request_size(size);
162+ }
163+
164+ pub fn tile_width_for_window_width(&self, size: i32) -> i32 {
165+ if self.border.is_off() {
166+ size
167+ } else {
168+ size + self.border.width() * 2
169+ }
170+ }
171+
172+ pub fn tile_height_for_window_height(&self, size: i32) -> i32 {
173+ if self.border.is_off() {
174+ size
175+ } else {
176+ size + self.border.width() * 2
177+ }
178+ }
179+
180+ pub fn window_height_for_tile_height(&self, size: i32) -> i32 {
181+ if self.border.is_off() {
182+ size
183+ } else {
184+ size - self.border.width() * 2
185+ }
186+ }
187+
188+ pub fn request_fullscreen(&mut self, size: Size<i32, Logical>) {
189+ self.fullscreen_backdrop.resize(size);
190+ self.fullscreen_size = size;
191+ self.window.request_fullscreen(size);
192+ }
193+
194+ pub fn min_size(&self) -> Size<i32, Logical> {
195+ let mut size = self.window.min_size();
196+
197+ if let Some(width) = self.effective_border_width() {
198+ size.w = max(1, size.w);
199+ size.h = max(1, size.h);
200+ size += (width * 2, width * 2).into();
201+ }
202+
203+ size
204+ }
205+
206+ pub fn max_size(&self) -> Size<i32, Logical> {
207+ let mut size = self.window.max_size();
208+
209+ if let Some(width) = self.effective_border_width() {
210+ if size.w > 0 {
211+ size.w += width * 2;
212+ }
213+ if size.h > 0 {
214+ size.h += width * 2;
215+ }
216+ }
217+
218+ size
219+ }
220+
221+ pub fn has_ssd(&self) -> bool {
222+ self.effective_border_width().is_some() || self.window.has_ssd()
223+ }
224+
225+ pub fn render<R: Renderer + ImportAll>(
226+ &self,
227+ renderer: &mut R,
228+ location: Point<i32, Logical>,
229+ scale: Scale<f64>,
230+ ) -> Vec<WorkspaceRenderElement<R>>
231+ where
232+ <R as Renderer>::TextureId: 'static,
233+ {
234+ let mut rv = Vec::new();
235+
236+ let window_pos = location + self.window_loc();
237+ rv.extend(self.window.render(renderer, window_pos, scale));
238+
239+ if self.effective_border_width().is_some() {
240+ rv.extend(
241+ self.border
242+ .render(scale)
243+ .map(|elem| {
244+ RelocateRenderElement::from_element(
245+ elem,
246+ location.to_physical_precise_round(scale),
247+ Relocate::Relative,
248+ )
249+ })
250+ .map(Into::into),
251+ );
252+ }
253+
254+ if self.is_fullscreen {
255+ let elem = SolidColorRenderElement::from_buffer(
256+ &self.fullscreen_backdrop,
257+ location.to_physical_precise_round(scale),
258+ scale,
259+ 1.,
260+ Kind::Unspecified,
261+ );
262+ rv.push(elem.into());
263+ }
264+
265+ rv
266+ }
267+}
src/layout/workspace.rsmodified+112 -41
@@ -4,6 +4,7 @@ use std::rc::Rc;
4 use std::time::Duration;4 use std::time::Duration;
5 5
6 use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;6 use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;
7+use smithay::backend::renderer::element::utils::RelocateRenderElement;
7 use smithay::backend::renderer::gles::GlesRenderer;8 use smithay::backend::renderer::gles::GlesRenderer;
8 use smithay::backend::renderer::ImportAll;9 use smithay::backend::renderer::ImportAll;
9 use smithay::desktop::space::SpaceElement;10 use smithay::desktop::space::SpaceElement;
@@ -14,6 +15,7 @@ use smithay::render_elements;
14 use smithay::utils::{Logical, Point, Rectangle, Scale, Size};15 use smithay::utils::{Logical, Point, Rectangle, Scale, Size};
15 16
16 use super::focus_ring::{FocusRing, FocusRingRenderElement};17 use super::focus_ring::{FocusRing, FocusRingRenderElement};
18+use super::tile::Tile;
17 use super::{LayoutElement, Options};19 use super::{LayoutElement, Options};
18 use crate::animation::Animation;20 use crate::animation::Animation;
19 use crate::config::{PresetWidth, SizeChange, Struts};21 use crate::config::{PresetWidth, SizeChange, Struts};
@@ -83,6 +85,7 @@ render_elements! {
83 pub WorkspaceRenderElement<R> where R: ImportAll;85 pub WorkspaceRenderElement<R> where R: ImportAll;
84 Wayland = WaylandSurfaceRenderElement<R>,86 Wayland = WaylandSurfaceRenderElement<R>,
85 FocusRing = FocusRingRenderElement,87 FocusRing = FocusRingRenderElement,
88+ Border = RelocateRenderElement<FocusRingRenderElement>,
86 }89 }
87 90
88 /// Width of a column.91 /// Width of a column.
@@ -121,17 +124,19 @@ pub enum WindowHeight {
121 124
122 #[derive(Debug)]125 #[derive(Debug)]
123 pub struct Column<W: LayoutElement> {126 pub struct Column<W: LayoutElement> {
124- /// Windows in this column.127+ /// Tiles in this column.
125 ///128 ///
126 /// Must be non-empty.129 /// Must be non-empty.
127- pub windows: Vec<W>,130+ pub windows: Vec<Tile<W>>,
128 131
129 /// Heights of the windows.132 /// Heights of the windows.
130 ///133 ///
131 /// Must have the same number of elements as `windows`.134 /// Must have the same number of elements as `windows`.
135+ ///
136+ /// These heights are window heights, so they exclude tile decorations, if any.
132 heights: Vec<WindowHeight>,137 heights: Vec<WindowHeight>,
133 138
134- /// Index of the currently active window.139+ /// Index of the currently active tile.
135 pub active_window_idx: usize,140 pub active_window_idx: usize,
136 141
137 /// Desired width of this column.142 /// Desired width of this column.
@@ -231,11 +236,20 @@ impl<W: LayoutElement> Workspace<W> {
231 236
232 let view_pos = self.view_pos();237 let view_pos = self.view_pos();
233 238
239+ for (col_idx, col) in self.columns.iter_mut().enumerate() {
240+ for (win_idx, tile) in col.windows.iter_mut().enumerate() {
241+ let is_active = is_active
242+ && col_idx == self.active_column_idx
243+ && win_idx == col.active_window_idx;
244+ tile.advance_animations(current_time, is_active);
245+ }
246+ }
247+
234 // This shall one day become a proper animation.248 // This shall one day become a proper animation.
235 if !self.columns.is_empty() {249 if !self.columns.is_empty() {
236 let col = &self.columns[self.active_column_idx];250 let col = &self.columns[self.active_column_idx];
237 let active_win = &col.windows[col.active_window_idx];251 let active_win = &col.windows[col.active_window_idx];
238- let size = active_win.size();252+ let size = active_win.tile_size();
239 let has_ssd = active_win.has_ssd();253 let has_ssd = active_win.has_ssd();
240 254
241 let win_pos = Point::from((255 let win_pos = Point::from((
@@ -264,7 +278,10 @@ impl<W: LayoutElement> Workspace<W> {
264 }278 }
265 279
266 pub fn windows(&self) -> impl Iterator<Item = &W> + '_ {280 pub fn windows(&self) -> impl Iterator<Item = &W> + '_ {
267- self.columns.iter().flat_map(|col| col.windows.iter())281+ self.columns
282+ .iter()
283+ .flat_map(|col| col.windows.iter())
284+ .map(Tile::window)
268 }285 }
269 286
270 pub fn set_output(&mut self, output: Option<Output>) {287 pub fn set_output(&mut self, output: Option<Output>) {
@@ -315,20 +332,33 @@ impl<W: LayoutElement> Workspace<W> {
315 }332 }
316 333
317 fn toplevel_bounds(&self) -> Size<i32, Logical> {334 fn toplevel_bounds(&self) -> Size<i32, Logical> {
335+ let mut border = 0;
336+ if !self.options.border.off {
337+ border = self.options.border.width as i32 * 2;
338+ }
339+
318 Size::from((340 Size::from((
319- max(self.working_area.size.w - self.options.gaps * 2, 1),341+ max(self.working_area.size.w - self.options.gaps * 2 - border, 1),
320- max(self.working_area.size.h - self.options.gaps * 2, 1),342+ max(self.working_area.size.h - self.options.gaps * 2 - border, 1),
321 ))343 ))
322 }344 }
323 345
324 pub fn configure_new_window(&self, window: &Window) {346 pub fn configure_new_window(&self, window: &Window) {
325 let width = if let Some(width) = self.options.default_width {347 let width = if let Some(width) = self.options.default_width {
326- max(1, width.resolve(&self.options, self.working_area.size.w))348+ let mut width = width.resolve(&self.options, self.working_area.size.w);
349+ if !self.options.border.off {
350+ width -= self.options.border.width as i32 * 2;
351+ }
352+ max(1, width)
327 } else {353 } else {
328 0354 0
329 };355 };
330 356
331- let height = self.working_area.size.h - self.options.gaps * 2;357+ let mut height = self.working_area.size.h - self.options.gaps * 2;
358+ if !self.options.border.off {
359+ height -= self.options.border.width as i32 * 2;
360+ }
361+
332 let size = Size::from((width, max(height, 1)));362 let size = Size::from((width, max(height, 1)));
333 363
334 let bounds = self.toplevel_bounds();364 let bounds = self.toplevel_bounds();
@@ -478,7 +508,7 @@ impl<W: LayoutElement> Workspace<W> {
478 508
479 pub fn remove_window_by_idx(&mut self, column_idx: usize, window_idx: usize) -> W {509 pub fn remove_window_by_idx(&mut self, column_idx: usize, window_idx: usize) -> W {
480 let column = &mut self.columns[column_idx];510 let column = &mut self.columns[column_idx];
481- let window = column.windows.remove(window_idx);511+ let window = column.windows.remove(window_idx).into_window();
482 column.heights.remove(window_idx);512 column.heights.remove(window_idx);
483 513
484 if let Some(output) = &self.output {514 if let Some(output) = &self.output {
@@ -746,20 +776,20 @@ impl<W: LayoutElement> Workspace<W> {
746 col.window_y(col.active_window_idx),776 col.window_y(col.active_window_idx),
747 ));777 ));
748 if active_win.is_in_input_region(pos - win_pos.to_f64()) {778 if active_win.is_in_input_region(pos - win_pos.to_f64()) {
749- return Some((active_win, win_pos + active_win.buf_loc()));779+ return Some((active_win.window(), win_pos + active_win.buf_loc()));
750 }780 }
751 781
752 let mut x = -view_pos;782 let mut x = -view_pos;
753 for col in &self.columns {783 for col in &self.columns {
754 for (win, y) in zip(&col.windows, col.window_ys()) {784 for (win, y) in zip(&col.windows, col.window_ys()) {
755- if win == active_win {785+ if win.window() == active_win.window() {
756 // Already handled it above.786 // Already handled it above.
757 continue;787 continue;
758 }788 }
759 789
760 let win_pos = Point::from((x, y));790 let win_pos = Point::from((x, y));
761 if win.is_in_input_region(pos - win_pos.to_f64()) {791 if win.is_in_input_region(pos - win_pos.to_f64()) {
762- return Some((win, win_pos + win.buf_loc()));792+ return Some((win.window(), win_pos + win.buf_loc()));
763 }793 }
764 }794 }
765 795
@@ -815,7 +845,7 @@ impl<W: LayoutElement> Workspace<W> {
815 // This wasn't the only window in its column; extract it into a separate column.845 // This wasn't the only window in its column; extract it into a separate column.
816 let target_window_was_focused =846 let target_window_was_focused =
817 self.active_column_idx == col_idx && col.active_window_idx == win_idx;847 self.active_column_idx == col_idx && col.active_window_idx == win_idx;
818- let window = col.windows.remove(win_idx);848+ let window = col.windows.remove(win_idx).into_window();
819 col.heights.remove(win_idx);849 col.heights.remove(win_idx);
820 col.active_window_idx = min(col.active_window_idx, col.windows.len() - 1);850 col.active_window_idx = min(col.active_window_idx, col.windows.len() - 1);
821 col.update_window_sizes();851 col.update_window_sizes();
@@ -872,7 +902,8 @@ impl Workspace<Window> {
872 let bounds = self.toplevel_bounds();902 let bounds = self.toplevel_bounds();
873 903
874 for (col_idx, col) in self.columns.iter().enumerate() {904 for (col_idx, col) in self.columns.iter().enumerate() {
875- for (win_idx, win) in col.windows.iter().enumerate() {905+ for (win_idx, tile) in col.windows.iter().enumerate() {
906+ let win = tile.window();
876 let active = self.active_column_idx == col_idx && col.active_window_idx == win_idx;907 let active = self.active_column_idx == col_idx && col.active_window_idx == win_idx;
877 win.set_activated(active);908 win.set_activated(active);
878 909
@@ -922,7 +953,7 @@ impl Workspace<Window> {
922 let mut x = -view_pos;953 let mut x = -view_pos;
923 for col in &self.columns {954 for col in &self.columns {
924 for (win, y) in zip(&col.windows, col.window_ys()) {955 for (win, y) in zip(&col.windows, col.window_ys()) {
925- if win == active_win {956+ if win.window() == active_win.window() {
926 // Already handled it above.957 // Already handled it above.
927 continue;958 continue;
928 }959 }
@@ -989,6 +1020,16 @@ impl<W: LayoutElement> Column<W> {
989 update_sizes = true;1020 update_sizes = true;
990 }1021 }
991 1022
1023+ if self.options.border.off != options.border.off
1024+ || self.options.border.width != options.border.width
1025+ {
1026+ update_sizes = true;
1027+ }
1028+
1029+ for tile in &mut self.windows {
1030+ tile.update_config(options.clone());
1031+ }
1032+
992 self.options = options;1033 self.options = options;
993 1034
994 if update_sizes {1035 if update_sizes {
@@ -1003,11 +1044,17 @@ impl<W: LayoutElement> Column<W> {
1003 }1044 }
1004 1045
1005 pub fn contains(&self, window: &W) -> bool {1046 pub fn contains(&self, window: &W) -> bool {
1006- self.windows.iter().any(|win| win == window)1047+ self.windows
1048+ .iter()
1049+ .map(Tile::window)
1050+ .any(|win| win == window)
1007 }1051 }
1008 1052
1009 pub fn position(&self, window: &W) -> Option<usize> {1053 pub fn position(&self, window: &W) -> Option<usize> {
1010- self.windows.iter().position(|win| win == window)1054+ self.windows
1055+ .iter()
1056+ .map(Tile::window)
1057+ .position(|win| win == window)
1011 }1058 }
1012 1059
1013 fn activate_window(&mut self, window: &W) {1060 fn activate_window(&mut self, window: &W) {
@@ -1016,8 +1063,9 @@ impl<W: LayoutElement> Column<W> {
1016 }1063 }
1017 1064
1018 fn add_window(&mut self, window: W) {1065 fn add_window(&mut self, window: W) {
1066+ let tile = Tile::new(window, self.options.clone());
1019 self.is_fullscreen = false;1067 self.is_fullscreen = false;
1020- self.windows.push(window);1068+ self.windows.push(tile);
1021 self.heights.push(WindowHeight::Auto);1069 self.heights.push(WindowHeight::Auto);
1022 self.update_window_sizes();1070 self.update_window_sizes();
1023 }1071 }
@@ -1028,8 +1076,8 @@ impl<W: LayoutElement> Column<W> {
1028 return;1076 return;
1029 }1077 }
1030 1078
1031- let min_size: Vec<_> = self.windows.iter().map(LayoutElement::min_size).collect();1079+ let min_size: Vec<_> = self.windows.iter().map(Tile::min_size).collect();
1032- let max_size: Vec<_> = self.windows.iter().map(LayoutElement::max_size).collect();1080+ let max_size: Vec<_> = self.windows.iter().map(Tile::max_size).collect();
1033 1081
1034 // Compute the column width.1082 // Compute the column width.
1035 let min_width = min_size1083 let min_width = min_size
@@ -1067,8 +1115,15 @@ impl<W: LayoutElement> Column<W> {
1067 let width = width.resolve(&self.options, self.working_area.size.w);1115 let width = width.resolve(&self.options, self.working_area.size.w);
1068 let width = max(min(width, max_width), min_width);1116 let width = max(min(width, max_width), min_width);
1069 1117
1070- // Compute the window heights.1118+ // Compute the window heights. Start by converting window heights to tile heights.
1071- let mut heights = self.heights.clone();1119+ let mut heights = zip(&self.windows, &self.heights)
1120+ .map(|(tile, height)| match *height {
1121+ WindowHeight::Auto => WindowHeight::Auto,
1122+ WindowHeight::Fixed(height) => {
1123+ WindowHeight::Fixed(tile.tile_height_for_window_height(height))
1124+ }
1125+ })
1126+ .collect::<Vec<_>>();
1072 let mut height_left = self.working_area.size.h - self.options.gaps;1127 let mut height_left = self.working_area.size.h - self.options.gaps;
1073 let mut auto_windows_left = self.windows.len();1128 let mut auto_windows_left = self.windows.len();
1074 1129
@@ -1162,18 +1217,22 @@ impl<W: LayoutElement> Column<W> {
1162 assert_eq!(auto_windows_left, 0);1217 assert_eq!(auto_windows_left, 0);
1163 }1218 }
1164 1219
1165- for (win, h) in zip(&self.windows, heights) {1220+ for (tile, h) in zip(&mut self.windows, heights) {
1166 let WindowHeight::Fixed(height) = h else {1221 let WindowHeight::Fixed(height) = h else {
1167 unreachable!()1222 unreachable!()
1168 };1223 };
1169 1224
1170 let size = Size::from((width, height));1225 let size = Size::from((width, height));
1171- win.request_size(size);1226+ tile.request_tile_size(size);
1172 }1227 }
1173 }1228 }
1174 1229
1175 fn width(&self) -> i32 {1230 fn width(&self) -> i32 {
1176- self.windows.iter().map(|win| win.size().w).max().unwrap()1231+ self.windows
1232+ .iter()
1233+ .map(|win| win.tile_size().w)
1234+ .max()
1235+ .unwrap()
1177 }1236 }
1178 1237
1179 fn focus_up(&mut self) {1238 fn focus_up(&mut self) {
@@ -1265,7 +1324,13 @@ impl<W: LayoutElement> Column<W> {
1265 const MAX_F: f64 = 10000.;1324 const MAX_F: f64 = 10000.;
1266 1325
1267 let width = match (current, change) {1326 let width = match (current, change) {
1268- (_, SizeChange::SetFixed(fixed)) => ColumnWidth::Fixed(fixed.clamp(1, MAX_PX)),1327+ (_, SizeChange::SetFixed(fixed)) => {
1328+ // As a special case, setting a fixed column width will compute it in such a way
1329+ // that the active window gets that width. This is the intention behind the ability
1330+ // to set a fixed size.
1331+ let tile = &self.windows[self.active_window_idx];
1332+ ColumnWidth::Fixed(tile.tile_width_for_window_width(fixed).clamp(1, MAX_PX))
1333+ }
1269 (_, SizeChange::SetProportion(proportion)) => {1334 (_, SizeChange::SetProportion(proportion)) => {
1270 ColumnWidth::Proportion((proportion / 100.).clamp(0., MAX_F))1335 ColumnWidth::Proportion((proportion / 100.).clamp(0., MAX_F))
1271 }1336 }
@@ -1291,45 +1356,51 @@ impl<W: LayoutElement> Column<W> {
1291 1356
1292 fn set_window_height(&mut self, change: SizeChange) {1357 fn set_window_height(&mut self, change: SizeChange) {
1293 let current = self.heights[self.active_window_idx];1358 let current = self.heights[self.active_window_idx];
1294- let current_px = match current {1359+ let tile = &self.windows[self.active_window_idx];
1295- WindowHeight::Auto => self.windows[self.active_window_idx].size().h,1360+ let current_window_px = match current {
1361+ WindowHeight::Auto => tile.window_size().h,
1296 WindowHeight::Fixed(height) => height,1362 WindowHeight::Fixed(height) => height,
1297 };1363 };
1298- let current_prop = (current_px + self.options.gaps) as f641364+ let current_tile_px = tile.tile_height_for_window_height(current_window_px);
1365+ let current_prop = (current_tile_px + self.options.gaps) as f64
1299 / (self.working_area.size.h - self.options.gaps) as f64;1366 / (self.working_area.size.h - self.options.gaps) as f64;
1300 1367
1301 // FIXME: fix overflows then remove limits.1368 // FIXME: fix overflows then remove limits.
1302 const MAX_PX: i32 = 100000;1369 const MAX_PX: i32 = 100000;
1303 1370
1304- let mut height = match change {1371+ let mut window_height = match change {
1305 SizeChange::SetFixed(fixed) => fixed,1372 SizeChange::SetFixed(fixed) => fixed,
1306 SizeChange::SetProportion(proportion) => {1373 SizeChange::SetProportion(proportion) => {
1307- ((self.working_area.size.h - self.options.gaps) as f64 * proportion1374+ let tile_height = ((self.working_area.size.h - self.options.gaps) as f64
1375+ * proportion
1308 - self.options.gaps as f64)1376 - self.options.gaps as f64)
1309- .round() as i321377+ .round() as i32;
1378+ tile.window_height_for_tile_height(tile_height)
1310 }1379 }
1311- SizeChange::AdjustFixed(delta) => current_px.saturating_add(delta),1380+ SizeChange::AdjustFixed(delta) => current_window_px.saturating_add(delta),
1312 SizeChange::AdjustProportion(delta) => {1381 SizeChange::AdjustProportion(delta) => {
1313 let proportion = current_prop + delta / 100.;1382 let proportion = current_prop + delta / 100.;
1314- ((self.working_area.size.h - self.options.gaps) as f64 * proportion1383+ let tile_height = ((self.working_area.size.h - self.options.gaps) as f64
1384+ * proportion
1315 - self.options.gaps as f64)1385 - self.options.gaps as f64)
1316- .round() as i321386+ .round() as i32;
1387+ tile.window_height_for_tile_height(tile_height)
1317 }1388 }
1318 };1389 };
1319 1390
1320 // Clamp it against the window height constraints.1391 // Clamp it against the window height constraints.
1321- let win = &self.windows[self.active_window_idx];1392+ let win = &self.windows[self.active_window_idx].window();
1322 let min_h = win.min_size().h;1393 let min_h = win.min_size().h;
1323 let max_h = win.max_size().h;1394 let max_h = win.max_size().h;
1324 1395
1325 if max_h > 0 {1396 if max_h > 0 {
1326- height = height.min(max_h);1397+ window_height = window_height.min(max_h);
1327 }1398 }
1328 if min_h > 0 {1399 if min_h > 0 {
1329- height = height.max(min_h);1400+ window_height = window_height.max(min_h);
1330 }1401 }
1331 1402
1332- self.heights[self.active_window_idx] = WindowHeight::Fixed(height.clamp(1, MAX_PX));1403+ self.heights[self.active_window_idx] = WindowHeight::Fixed(window_height.clamp(1, MAX_PX));
1333 self.update_window_sizes();1404 self.update_window_sizes();
1334 }1405 }
1335 1406
@@ -1352,7 +1423,7 @@ impl<W: LayoutElement> Column<W> {
1352 1423
1353 self.windows.iter().map(move |win| {1424 self.windows.iter().map(move |win| {
1354 let pos = y;1425 let pos = y;
1355- y += win.size().h + self.options.gaps;1426+ y += win.tile_size().h + self.options.gaps;
1356 pos1427 pos
1357 })1428 })
1358 }1429 }