Skip to content

Commit

Permalink
toplevel-views: be more careful when mapping views (#2393)
Browse files Browse the repository at this point in the history
Depending on their state, we might want different things.
  • Loading branch information
ammen99 authored Jun 27, 2024
1 parent 0583157 commit 68d5772
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 33 deletions.
30 changes: 30 additions & 0 deletions src/view/view-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "wayfire/unstable/wlr-surface-node.hpp"
#include "wayfire/view.hpp"
#include "wayfire/output-layout.hpp"
#include "wayfire/window-manager.hpp"
#include "wayfire/workarea.hpp"
#include "wayfire/workspace-set.hpp"
#include <memory>
#include <wayfire/util/log.hpp>
Expand Down Expand Up @@ -437,3 +439,31 @@ void wf::fini_desktop_apis()
fini_layer_shell();
// xwayland destroyed separately by core
}

void wf::adjust_view_pending_geometry_on_start_map(wf::toplevel_view_interface_t *self,
wf::geometry_t map_geometry_client, bool map_fs, bool map_maximized)
{
if (map_fs)
{
self->toplevel()->pending().fullscreen = true;
wf::get_core().default_wm->fullscreen_request(self, self->get_output(), true);
} else if (map_maximized)
{
self->toplevel()->pending().tiled_edges = wf::TILED_EDGES_ALL;
if (self->get_output())
{
self->toplevel()->pending().geometry = self->get_output()->workarea->get_workarea();
}
} else
{
auto map_geometry = wf::expand_geometry_by_margins(map_geometry_client,
self->toplevel()->pending().margins);

if (self->get_output())
{
map_geometry = wf::clamp(map_geometry, self->get_output()->workarea->get_workarea());
}

self->toplevel()->pending().geometry = map_geometry;
}
}
2 changes: 2 additions & 0 deletions src/view/view-impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class view_interface_t::view_priv_impl
void adjust_geometry_for_gravity(wf::toplevel_state_t& desired_state, wf::dimensions_t actual_size);

void adjust_view_output_on_map(wf::toplevel_view_interface_t *self);
void adjust_view_pending_geometry_on_start_map(wf::toplevel_view_interface_t *self,
wf::geometry_t map_geometry_client, bool map_fs, bool map_maximized);

/** Emit the map signal for the given view */
void init_xdg_shell();
Expand Down
6 changes: 4 additions & 2 deletions src/view/xdg-shell/xdg-toplevel-view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,14 @@ void wf::xdg_toplevel_view_t::start_map_tx()
LOGC(VIEWS, "Start mapping ", self());
wlr_box box;
wlr_xdg_surface_get_geometry(xdg_toplevel->base, &box);

auto margins = wtoplevel->pending().margins;
box.x = wtoplevel->pending().geometry.x + margins.left;
box.y = wtoplevel->pending().geometry.y + margins.top;

wtoplevel->pending().mapped = true;
wtoplevel->pending().geometry.width = box.width + margins.left + margins.right;
wtoplevel->pending().geometry.height = box.height + margins.top + margins.bottom;
priv->set_mapped_surface_contents(main_surface);
adjust_view_pending_geometry_on_start_map(this, box, pending_fullscreen(), pending_tiled_edges());
wf::get_core().tx_manager->schedule_object(wtoplevel);
}

Expand Down
45 changes: 14 additions & 31 deletions src/view/xwayland/xwayland-toplevel-view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,44 +337,27 @@ class wayfire_xwayland_view : public wf::toplevel_view_interface_t, public wayfi
toplevel->set_main_surface(main_surface);
toplevel->pending().mapped = true;

if (xw->fullscreen)
{
store_xw_geometry_unmapped();
toplevel->pending().fullscreen = true;
if (get_output())
{
toplevel->pending().geometry = get_output()->workarea->get_workarea();
}
bool map_maximized = xw->maximized_horz || xw->maximized_vert;
bool map_fs = xw->fullscreen;

wf::get_core().default_wm->fullscreen_request({this}, get_output(), true);
} else if (xw->maximized_horz && xw->maximized_vert)
if (map_maximized || map_fs)
{
store_xw_geometry_unmapped();
toplevel->pending().tiled_edges = wf::TILED_EDGES_ALL;
if (get_output())
{
toplevel->pending().geometry = get_output()->workarea->get_workarea();
}
} else
{
wf::geometry_t desired_geometry = {
xw->x,
xw->y,
xw->surface->current.width,
xw->surface->current.height
};
}

if (get_output())
{
desired_geometry = desired_geometry + -wf::origin(get_output()->get_layout_geometry());
desired_geometry =
wf::expand_geometry_by_margins(desired_geometry, toplevel->pending().margins);
desired_geometry = wf::clamp(desired_geometry, get_output()->workarea->get_workarea());
}
wf::geometry_t desired_geometry = {
xw->x,
xw->y,
xw->surface->current.width,
xw->surface->current.height
};

toplevel->pending().geometry = desired_geometry;
if (get_output())
{
desired_geometry = desired_geometry + -wf::origin(get_output()->get_layout_geometry());
}

wf::adjust_view_pending_geometry_on_start_map(this, desired_geometry, map_fs, map_maximized);
wf::get_core().tx_manager->schedule_object(toplevel);
}

Expand Down

0 comments on commit 68d5772

Please sign in to comment.