69
66
QSize initialSize = InitialSurfaceSizes::get(miral::pid_of(appInfo.application()));
71
68
if (initialSize.isValid() && surfaceType == mir_surface_type_normal) {
72
parameters.size() = Size{Width(initialSize.width()), Height(initialSize.height())};
69
parameters.size() = toMirSize(initialSize);
227
QRect WindowManagementPolicy::getConfinementRect(const QRect rect) const
229
QRect confinementRect;
230
for (const QRect r : m_confinementRegions) {
231
if (r.intersects(rect)) {
233
// TODO: What if there are multiple confinement regions and they intersect??
237
return confinementRect;
230
240
/* Following methods all called from the Qt GUI thread to deliver events to clients */
231
241
void WindowManagementPolicy::deliver_keyboard_event(const MirKeyboardEvent *event,
232
242
const miral::Window &window)
343
void WindowManagementPolicy::set_window_confinement_regions(const QVector<QRect> ®ions)
345
m_confinementRegions = regions;
347
// TODO: update window positions to respect new boundary.
350
void WindowManagementPolicy::set_window_margins(MirWindowType windowType, const QMargins &margins)
352
m_windowMargins[windowType] = margins;
354
// TODO: update window positions/sizes to respect new margins.
333
357
void WindowManagementPolicy::requestState(const miral::Window &window, const Mir::State state)
335
359
auto &windowInfo = m_tools.info_for(window);
382
Rectangle WindowManagementPolicy::confirm_inherited_move(miral::WindowInfo const& windowInfo, Displacement movement)
384
if (m_confinementRegions.isEmpty()) {
385
return CanonicalWindowManagerPolicy::confirm_inherited_move(windowInfo, movement);
388
auto window = windowInfo.window();
389
const QMargins windowMargins = m_windowMargins[windowInfo.type()];
390
QRect windowGeom(toQPoint(window.top_left()), toQSize(window.size()));
392
QRect geom = windowGeom.marginsAdded(windowMargins);
393
const QRect confinementRect = getConfinementRect(geom);
397
int moveX = movement.dx.as_int();
398
int moveY = movement.dy.as_int();
400
// If the child window is already partially beyond the available desktop area (most likely because the user
401
// explicitly moved it there) we won't pull it back, unless the inherited movement is this direction, but also won't
402
// push it even further astray. But if it currently is completely within the available desktop area boundaries
403
// we won't let go beyond it.
406
if (geom.right() < confinementRect.right()) {
407
x = qMin(x + moveX, confinementRect.right() + 1 - geom.width()); // +1 because QRect::right() weird
410
if (geom.x() > confinementRect.left()) {
411
x = qMax(x + moveX, confinementRect.left());
416
if (geom.bottom() < confinementRect.bottom()) {
417
y = qMin(y + moveY, confinementRect.bottom() + 1 - geom.height()); // +1 because QRect::bottom() weird
420
if (geom.y() > confinementRect.top()) {
421
y = qMax(y + moveY, confinementRect.top());
426
return toMirRectangle(geom.marginsRemoved(windowMargins));