forge
Explore
Log in

Don't you dare go Hollow

Add basic fullscreen impl

Browse files at this commit

6494df398d926d53f18c7c4ef1f496136e8e73f0Ivan MolodetskikhParent: d96daf6
src/handlers/xdg_shell.rsmodified+21 -38
@@ -2,6 +2,7 @@ use smithay::delegate_xdg_shell;
2 use smithay::desktop::{find_popup_root_surface, PopupKind, Window};2 use smithay::desktop::{find_popup_root_surface, PopupKind, Window};
3 use smithay::input::pointer::{Focus, GrabStartData as PointerGrabStartData};3 use smithay::input::pointer::{Focus, GrabStartData as PointerGrabStartData};
4 use smithay::input::Seat;4 use smithay::input::Seat;
5+use smithay::output::Output;
5 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;6 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
6 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;7 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
7 use smithay::reexports::wayland_server::protocol::{wl_output, wl_seat};8 use smithay::reexports::wayland_server::protocol::{wl_output, wl_seat};
@@ -180,32 +181,22 @@ impl XdgShellHandler for Niri {
180 .capabilities181 .capabilities
181 .contains(xdg_toplevel::WmCapabilities::Fullscreen)182 .contains(xdg_toplevel::WmCapabilities::Fullscreen)
182 {183 {
183- // // NOTE: This is only one part of the solution. We can set the184+ // NOTE: This is only one part of the solution. We can set the
184- // // location and configure size here, but the surface should be rendered fullscreen185+ // location and configure size here, but the surface should be rendered fullscreen
185- // // independently from its buffer size186+ // independently from its buffer size
186- // let wl_surface = surface.wl_surface();187+ if let Some((window, current_output)) = self
187-188+ .monitor_set
188- // let output = wl_output189+ .find_window_and_output(surface.wl_surface())
189- // .as_ref()190+ {
190- // .and_then(Output::from_resource)191+ if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) {
191- // .or_else(|| {192+ if requested_output != current_output {
192- // self.monitor_set193+ self.monitor_set
193- // .find_window_and_space(wl_surface)194+ .move_window_to_output(window.clone(), &requested_output);
194- // .and_then(|(_window, space)| space.outputs().next().cloned())195+ }
195- // });196+ }
196-197+
197- // if let Some(output) = output {198+ self.monitor_set.set_fullscreen(&window, true);
198- // let (window, space) =199+ }
199- // self.monitor_set.find_window_and_space(wl_surface).unwrap();
200- // let geometry = space.output_geometry(&output).unwrap();
201-
202- // surface.with_pending_state(|state| {
203- // state.states.set(xdg_toplevel::State::Fullscreen);
204- // state.size = Some(geometry.size);
205- // });
206-
207- // space.map_element(window.clone(), geometry.loc, true);
208- // }
209 }200 }
210 201
211 // The protocol demands us to always reply with a configure,202 // The protocol demands us to always reply with a configure,
@@ -214,20 +205,12 @@ impl XdgShellHandler for Niri {
214 }205 }
215 206
216 fn unfullscreen_request(&mut self, surface: ToplevelSurface) {207 fn unfullscreen_request(&mut self, surface: ToplevelSurface) {
217- if !surface208+ if let Some((window, _)) = self
218- .current_state()209+ .monitor_set
219- .states210+ .find_window_and_output(surface.wl_surface())
220- .contains(xdg_toplevel::State::Fullscreen)
221 {211 {
222- return;212+ self.monitor_set.set_fullscreen(&window, false);
223 }213 }
224-
225- surface.with_pending_state(|state| {
226- state.states.unset(xdg_toplevel::State::Fullscreen);
227- state.size = None;
228- });
229-
230- surface.send_pending_configure();
231 }214 }
232 215
233 fn toplevel_destroyed(&mut self, surface: ToplevelSurface) {216 fn toplevel_destroyed(&mut self, surface: ToplevelSurface) {
src/input.rsmodified+3 -2
@@ -178,8 +178,9 @@ impl Niri {
178 }178 }
179 }179 }
180 Action::ToggleFullscreen => {180 Action::ToggleFullscreen => {
181- if let Some(window) = self.monitor_set.focus() {181+ let focus = self.monitor_set.focus().cloned();
182- // FIXME182+ if let Some(window) = focus {
183+ self.monitor_set.toggle_fullscreen(&window);
183 }184 }
184 }185 }
185 Action::MoveLeft => {186 Action::MoveLeft => {
src/layout.rsmodified+154 -6
@@ -42,6 +42,7 @@ use smithay::backend::renderer::gles::GlesRenderer;
42 use smithay::desktop::space::SpaceElement;42 use smithay::desktop::space::SpaceElement;
43 use smithay::desktop::Window;43 use smithay::desktop::Window;
44 use smithay::output::Output;44 use smithay::output::Output;
45+use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
45 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;46 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
46 use smithay::utils::{Logical, Point, Rectangle, Scale, Size};47 use smithay::utils::{Logical, Point, Rectangle, Scale, Size};
47 use smithay::wayland::compositor::{with_states, SurfaceData};48 use smithay::wayland::compositor::{with_states, SurfaceData};
@@ -65,6 +66,7 @@ pub type MonitorRenderElement<R> =
65 66
66 pub trait LayoutElement: SpaceElement + PartialEq + Clone {67 pub trait LayoutElement: SpaceElement + PartialEq + Clone {
67 fn request_size(&self, size: Size<i32, Logical>);68 fn request_size(&self, size: Size<i32, Logical>);
69+ fn request_fullscreen(&self, size: Size<i32, Logical>);
68 fn min_size(&self) -> Size<i32, Logical>;70 fn min_size(&self) -> Size<i32, Logical>;
69 fn is_wl_surface(&self, wl_surface: &WlSurface) -> bool;71 fn is_wl_surface(&self, wl_surface: &WlSurface) -> bool;
70 fn send_frame<T, F>(72 fn send_frame<T, F>(
@@ -161,6 +163,9 @@ struct Column<W: LayoutElement> {
161 163
162 /// Desired width of this column.164 /// Desired width of this column.
163 width: ColumnWidth,165 width: ColumnWidth,
166+
167+ /// Whether this column contains a single full-screened window.
168+ is_fullscreen: bool,
164 }169 }
165 170
166 impl OutputId {171 impl OutputId {
@@ -171,8 +176,17 @@ impl OutputId {
171 176
172 impl LayoutElement for Window {177 impl LayoutElement for Window {
173 fn request_size(&self, size: Size<i32, Logical>) {178 fn request_size(&self, size: Size<i32, Logical>) {
174- self.toplevel()179+ self.toplevel().with_pending_state(|state| {
175- .with_pending_state(|state| state.size = Some(size));180+ state.size = Some(size);
181+ state.states.unset(xdg_toplevel::State::Fullscreen);
182+ });
183+ }
184+
185+ fn request_fullscreen(&self, size: Size<i32, Logical>) {
186+ self.toplevel().with_pending_state(|state| {
187+ state.size = Some(size);
188+ state.states.set(xdg_toplevel::State::Fullscreen);
189+ });
176 }190 }
177 191
178 fn min_size(&self) -> Size<i32, Logical> {192 fn min_size(&self) -> Size<i32, Logical> {
@@ -421,7 +435,7 @@ impl<W: LayoutElement> MonitorSet<W> {
421 for ws in &mut mon.workspaces {435 for ws in &mut mon.workspaces {
422 if ws.has_window(window) {436 if ws.has_window(window) {
423 ws.update_window(window);437 ws.update_window(window);
424- break;438+ return;
425 }439 }
426 }440 }
427 }441 }
@@ -430,7 +444,7 @@ impl<W: LayoutElement> MonitorSet<W> {
430 for ws in workspaces {444 for ws in workspaces {
431 if ws.has_window(window) {445 if ws.has_window(window) {
432 ws.update_window(window);446 ws.update_window(window);
433- break;447+ return;
434 }448 }
435 }449 }
436 }450 }
@@ -818,6 +832,67 @@ impl<W: LayoutElement> MonitorSet<W> {
818 self.add_window(new_idx, workspace_idx, window, true);832 self.add_window(new_idx, workspace_idx, window, true);
819 }833 }
820 }834 }
835+
836+ pub fn move_window_to_output(&mut self, window: W, output: &Output) {
837+ self.remove_window(&window);
838+
839+ if let MonitorSet::Normal { monitors, .. } = self {
840+ let new_idx = monitors
841+ .iter()
842+ .position(|mon| &mon.output == output)
843+ .unwrap();
844+
845+ let workspace_idx = monitors[new_idx].active_workspace_idx;
846+ // FIXME: activate only if it was already active and focused.
847+ self.add_window(new_idx, workspace_idx, window, true);
848+ }
849+ }
850+
851+ pub fn set_fullscreen(&mut self, window: &W, is_fullscreen: bool) {
852+ match self {
853+ MonitorSet::Normal { monitors, .. } => {
854+ for mon in monitors {
855+ for ws in &mut mon.workspaces {
856+ if ws.has_window(window) {
857+ ws.set_fullscreen(window, is_fullscreen);
858+ return;
859+ }
860+ }
861+ }
862+ }
863+ MonitorSet::NoOutputs(workspaces) => {
864+ for ws in workspaces {
865+ if ws.has_window(window) {
866+ ws.set_fullscreen(window, is_fullscreen);
867+ return;
868+ }
869+ }
870+ }
871+ }
872+ }
873+
874+ pub fn toggle_fullscreen(&mut self, window: &W) {
875+ match self {
876+ MonitorSet::Normal { monitors, .. } => {
877+ for mon in monitors {
878+ for ws in &mut mon.workspaces {
879+ if ws.has_window(window) {
880+ ws.toggle_fullscreen(window);
881+ return;
882+ }
883+ }
884+ }
885+ }
886+ MonitorSet::NoOutputs(workspaces) => {
887+ for ws in workspaces {
888+ if ws.has_window(window) {
889+ ws.toggle_fullscreen(window);
890+ return;
891+ }
892+ }
893+ }
894+ }
895+ }
821 }896 }
822 897
823 impl MonitorSet<Window> {898 impl MonitorSet<Window> {
@@ -1432,7 +1507,12 @@ impl<W: LayoutElement> Workspace<W> {
1432 let geom = win.geometry();1507 let geom = win.geometry();
1433 1508
1434 // x, y point at the top-left of the window geometry.1509 // x, y point at the top-left of the window geometry.
1435- let win_pos = Point::from((x, y)) - geom.loc;1510+ let mut win_pos = Point::from((x, y)) - geom.loc;
1511+ if col.is_fullscreen {
1512+ // FIXME: fullscreen windows are missing left padding
1513+ win_pos.x -= PADDING;
1514+ win_pos.y -= PADDING;
1515+ }
1436 if win.is_in_input_region(&(pos - win_pos.to_f64())) {1516 if win.is_in_input_region(&(pos - win_pos.to_f64())) {
1437 let mut win_pos_within_output = win_pos;1517 let mut win_pos_within_output = win_pos;
1438 win_pos_within_output.x -= view_pos;1518 win_pos_within_output.x -= view_pos;
@@ -1463,6 +1543,51 @@ impl<W: LayoutElement> Workspace<W> {
1463 1543
1464 self.columns[self.active_column_idx].toggle_full_width(self.view_size);1544 self.columns[self.active_column_idx].toggle_full_width(self.view_size);
1465 }1545 }
1546+
1547+ pub fn set_fullscreen(&mut self, window: &W, is_fullscreen: bool) {
1548+ let (mut col_idx, win_idx) = self
1549+ .columns
1550+ .iter()
1551+ .enumerate()
1552+ .find_map(|(col_idx, col)| {
1553+ col.windows
1554+ .iter()
1555+ .position(|w| w == window)
1556+ .map(|win_idx| (col_idx, win_idx))
1557+ })
1558+ .unwrap();
1559+
1560+ let mut col = &mut self.columns[col_idx];
1561+
1562+ if is_fullscreen && col.windows.len() > 1 {
1563+ // This wasn't the only window in its column; extract it into a separate column.
1564+ let target_window_was_focused =
1565+ self.active_column_idx == col_idx && col.active_window_idx == win_idx;
1566+ let window = col.windows.remove(win_idx);
1567+ col.active_window_idx = min(col.active_window_idx, col.windows.len() - 1);
1568+ col.update_window_sizes(self.view_size);
1569+
1570+ col_idx += 1;
1571+ self.columns
1572+ .insert(col_idx, Column::new(window, self.view_size));
1573+ if self.active_column_idx >= col_idx || target_window_was_focused {
1574+ self.active_column_idx += 1;
1575+ }
1576+ col = &mut self.columns[col_idx];
1577+ }
1578+
1579+ col.set_fullscreen(self.view_size, is_fullscreen);
1580+ }
1581+
1582+ pub fn toggle_fullscreen(&mut self, window: &W) {
1583+ let col = self
1584+ .columns
1585+ .iter_mut()
1586+ .find(|col| col.windows.contains(window))
1587+ .unwrap();
1588+ let value = !col.is_fullscreen;
1589+ self.set_fullscreen(window, value);
1590+ }
1466 }1591 }
1467 1592
1468 impl Workspace<Window> {1593 impl Workspace<Window> {
@@ -1490,7 +1615,13 @@ impl Workspace<Window> {
1490 for win in &col.windows {1615 for win in &col.windows {
1491 let geom = win.geometry();1616 let geom = win.geometry();
1492 1617
1493- let win_pos = Point::from((x - view_pos, y)) - geom.loc;1618+ let mut win_pos = Point::from((x - view_pos, y)) - geom.loc;
1619+ if col.is_fullscreen {
1620+ // FIXME: fullscreen windows are missing left padding
1621+ win_pos.x -= PADDING;
1622+ win_pos.y -= PADDING;
1623+ }
1624+
1494 rv.extend(win.render_elements(1625 rv.extend(win.render_elements(
1495 renderer,1626 renderer,
1496 win_pos.to_physical(1),1627 win_pos.to_physical(1),
@@ -1513,6 +1644,7 @@ impl<W: LayoutElement> Column<W> {
1513 windows: vec![],1644 windows: vec![],
1514 active_window_idx: 0,1645 active_window_idx: 0,
1515 width: ColumnWidth::default(),1646 width: ColumnWidth::default(),
1647+ is_fullscreen: false,
1516 };1648 };
1517 1649
1518 rv.add_window(view_size, window);1650 rv.add_window(view_size, window);
@@ -1539,11 +1671,17 @@ impl<W: LayoutElement> Column<W> {
1539 }1671 }
1540 1672
1541 fn add_window(&mut self, view_size: Size<i32, Logical>, window: W) {1673 fn add_window(&mut self, view_size: Size<i32, Logical>, window: W) {
1674+ self.is_fullscreen = false;
1542 self.windows.push(window);1675 self.windows.push(window);
1543 self.update_window_sizes(view_size);1676 self.update_window_sizes(view_size);
1544 }1677 }
1545 1678
1546 fn update_window_sizes(&mut self, view_size: Size<i32, Logical>) {1679 fn update_window_sizes(&mut self, view_size: Size<i32, Logical>) {
1680+ if self.is_fullscreen {
1681+ self.windows[0].request_fullscreen(view_size);
1682+ return;
1683+ }
1684+
1547 let min_width = self1685 let min_width = self
1548 .windows1686 .windows
1549 .iter()1687 .iter()
@@ -1610,6 +1748,10 @@ impl<W: LayoutElement> Column<W> {
1610 fn verify_invariants(&self) {1748 fn verify_invariants(&self) {
1611 assert!(!self.windows.is_empty(), "columns can't be empty");1749 assert!(!self.windows.is_empty(), "columns can't be empty");
1612 assert!(self.active_window_idx < self.windows.len());1750 assert!(self.active_window_idx < self.windows.len());
1751+
1752+ if self.is_fullscreen {
1753+ assert_eq!(self.windows.len(), 1);
1754+ }
1613 }1755 }
1614 1756
1615 fn toggle_width(&mut self, view_size: Size<i32, Logical>) {1757 fn toggle_width(&mut self, view_size: Size<i32, Logical>) {
@@ -1637,6 +1779,12 @@ impl<W: LayoutElement> Column<W> {
1637 };1779 };
1638 self.set_width(view_size, width);1780 self.set_width(view_size, width);
1639 }1781 }
1782+
1783+ fn set_fullscreen(&mut self, view_size: Size<i32, Logical>, is_fullscreen: bool) {
1784+ assert_eq!(self.windows.len(), 1);
1785+ self.is_fullscreen = is_fullscreen;
1786+ self.update_window_sizes(view_size);
1787+ }
1640 }1788 }
1641 1789
1642 pub fn output_size(output: &Output) -> Size<i32, Logical> {1790 pub fn output_size(output: &Output) -> Size<i32, Logical> {