2020-08-07 19:01:42 +00:00
/*
SPDX - FileCopyrightText : 2020 Vlad Zahorodnii < vlad . zahorodnii @ kde . org >
SPDX - License - Identifier : GPL - 2.0 - or - later
*/
# include "kwin_wayland_test.h"
2022-03-23 10:13:38 +00:00
2022-08-29 07:55:49 +00:00
# include "core/output.h"
wayland: Fix windows shrinking when output layout changes
When the output layout changes, the Workspace is going to update the
struts and then go through every window and see whether it should be
moved or resized.
On the other hand, the layer shell windows react to output changes on
a timer. Furthermore, it's not synchronized with the workspace rearranging
the managed windows. It means that when Workspace::desktopResized() runs,
the panel struts can be slightly outdated, i.e.
- An output layout change occurs
- Workspace::desktopResized() is called but the struts can be wrong
- some time later, LayerShellV1Integration::rearrange is called, it
fixes layer shell window geometries and struts
- after the layer shell integration has finished rearranging the
layer shell windows, it calls Workspace::desktopResized(), but the
damage had already been caused
With the proposed change, the Workspace and the LayerShellV1Integration
will rearrange the windows in sync.
CCBUG: 482361
2024-03-06 09:29:31 +00:00
# include "core/outputconfiguration.h"
2020-08-07 19:01:42 +00:00
# include "main.h"
2023-02-09 13:07:56 +00:00
# include "pointer_input.h"
2023-05-25 09:59:00 +00:00
# include "screenedge.h"
2020-08-07 19:01:42 +00:00
# include "wayland_server.h"
2022-04-22 17:39:12 +00:00
# include "window.h"
2020-08-07 19:01:42 +00:00
# include "workspace.h"
# include <KWayland/Client/output.h>
# include <KWayland/Client/surface.h>
Q_DECLARE_METATYPE ( QMargins )
Q_DECLARE_METATYPE ( KWin : : Layer )
namespace KWin
{
2022-04-22 17:46:41 +00:00
static const QString s_socketName = QStringLiteral ( " wayland_test_kwin_layershellv1window-0 " ) ;
2020-08-07 19:01:42 +00:00
2022-04-22 17:46:41 +00:00
class LayerShellV1WindowTest : public QObject
2020-08-07 19:01:42 +00:00
{
Q_OBJECT
private Q_SLOTS :
void initTestCase ( ) ;
void init ( ) ;
void cleanup ( ) ;
void testOutput_data ( ) ;
void testOutput ( ) ;
void testAnchor_data ( ) ;
void testAnchor ( ) ;
void testMargins_data ( ) ;
void testMargins ( ) ;
void testLayer_data ( ) ;
void testLayer ( ) ;
2023-05-13 11:25:53 +00:00
void testChangeLayer ( ) ;
2020-08-07 19:01:42 +00:00
void testPlacementArea_data ( ) ;
void testPlacementArea ( ) ;
wayland: Fix windows shrinking when output layout changes
When the output layout changes, the Workspace is going to update the
struts and then go through every window and see whether it should be
moved or resized.
On the other hand, the layer shell windows react to output changes on
a timer. Furthermore, it's not synchronized with the workspace rearranging
the managed windows. It means that when Workspace::desktopResized() runs,
the panel struts can be slightly outdated, i.e.
- An output layout change occurs
- Workspace::desktopResized() is called but the struts can be wrong
- some time later, LayerShellV1Integration::rearrange is called, it
fixes layer shell window geometries and struts
- after the layer shell integration has finished rearranging the
layer shell windows, it calls Workspace::desktopResized(), but the
damage had already been caused
With the proposed change, the Workspace and the LayerShellV1Integration
will rearrange the windows in sync.
CCBUG: 482361
2024-03-06 09:29:31 +00:00
void testPlacementAreaAfterOutputLayoutChange ( ) ;
2020-08-07 19:01:42 +00:00
void testFill_data ( ) ;
void testFill ( ) ;
void testStack ( ) ;
2023-10-26 14:03:27 +00:00
void testKeyboardInteractivityNone ( ) ;
void testKeyboardInteractivityOnDemand ( ) ;
2020-08-07 19:01:42 +00:00
void testActivate_data ( ) ;
void testActivate ( ) ;
void testUnmap ( ) ;
2024-01-24 10:30:43 +00:00
void testScreenEdge_data ( ) ;
2023-03-08 08:07:39 +00:00
void testScreenEdge ( ) ;
2020-08-07 19:01:42 +00:00
} ;
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : initTestCase ( )
2020-08-07 19:01:42 +00:00
{
QSignalSpy applicationStartedSpy ( kwinApp ( ) , & Application : : started ) ;
2020-12-09 13:06:15 +00:00
QVERIFY ( waylandServer ( ) - > init ( s_socketName ) ) ;
2023-05-08 10:16:00 +00:00
Test : : setOutputConfig ( {
QRect ( 0 , 0 , 1280 , 1024 ) ,
QRect ( 1280 , 0 , 1280 , 1024 ) ,
} ) ;
2020-08-07 19:01:42 +00:00
kwinApp ( ) - > start ( ) ;
QVERIFY ( applicationStartedSpy . wait ( ) ) ;
2022-07-11 10:41:15 +00:00
const auto outputs = workspace ( ) - > outputs ( ) ;
2021-08-31 07:03:05 +00:00
QCOMPARE ( outputs . count ( ) , 2 ) ;
QCOMPARE ( outputs [ 0 ] - > geometry ( ) , QRect ( 0 , 0 , 1280 , 1024 ) ) ;
QCOMPARE ( outputs [ 1 ] - > geometry ( ) , QRect ( 1280 , 0 , 1280 , 1024 ) ) ;
2020-08-07 19:01:42 +00:00
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : init ( )
2020-08-07 19:01:42 +00:00
{
2023-03-08 08:07:39 +00:00
QVERIFY ( Test : : setupWaylandConnection ( Test : : AdditionalWaylandInterface : : LayerShellV1 | Test : : AdditionalWaylandInterface : : ScreenEdgeV1 ) ) ;
2020-08-07 19:01:42 +00:00
2021-08-28 18:58:29 +00:00
workspace ( ) - > setActiveOutput ( QPoint ( 640 , 512 ) ) ;
2023-02-09 13:07:56 +00:00
input ( ) - > pointer ( ) - > warp ( QPoint ( 640 , 512 ) ) ;
2020-08-07 19:01:42 +00:00
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : cleanup ( )
2020-08-07 19:01:42 +00:00
{
Test : : destroyWaylandConnection ( ) ;
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : testOutput_data ( )
2020-08-07 19:01:42 +00:00
{
QTest : : addColumn < int > ( " screenId " ) ;
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " first output " ) < < 0 ;
2020-08-07 19:01:42 +00:00
QTest : : addRow ( " second output " ) < < 1 ;
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : testOutput ( )
2020-08-07 19:01:42 +00:00
{
// Fetch the wl_output object.
QFETCH ( int , screenId ) ;
KWayland : : Client : : Output * output = Test : : waylandOutputs ( ) . value ( screenId ) ;
QVERIFY ( output ) ;
// Create a layer shell surface.
2022-08-01 21:29:02 +00:00
std : : unique_ptr < KWayland : : Client : : Surface > surface ( Test : : createSurface ( ) ) ;
std : : unique_ptr < Test : : LayerSurfaceV1 > shellSurface ( Test : : createLayerSurfaceV1 ( surface . get ( ) , QStringLiteral ( " test " ) , output ) ) ;
2020-08-07 19:01:42 +00:00
// Set the initial state of the layer surface.
shellSurface - > set_size ( 280 , 124 ) ;
surface - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
// Wait for the compositor to position the surface.
2022-08-01 21:29:02 +00:00
QSignalSpy configureRequestedSpy ( shellSurface . get ( ) , & Test : : LayerSurfaceV1 : : configureRequested ) ;
2020-08-07 19:01:42 +00:00
QVERIFY ( configureRequestedSpy . wait ( ) ) ;
const QSize requestedSize = configureRequestedSpy . last ( ) . at ( 1 ) . toSize ( ) ;
// Map the layer surface.
shellSurface - > ack_configure ( configureRequestedSpy . last ( ) . at ( 0 ) . toUInt ( ) ) ;
2022-08-01 21:29:02 +00:00
Window * window = Test : : renderAndWaitForShown ( surface . get ( ) , requestedSize , Qt : : red ) ;
2022-04-23 19:51:16 +00:00
QVERIFY ( window ) ;
2020-08-07 19:01:42 +00:00
2022-04-23 19:51:16 +00:00
// Verify that the window is on the requested screen.
2022-05-16 20:13:39 +00:00
QVERIFY ( output - > geometry ( ) . contains ( window - > frameGeometry ( ) . toRect ( ) ) ) ;
2020-08-07 19:01:42 +00:00
2022-04-23 19:51:16 +00:00
// Destroy the window.
2020-08-07 19:01:42 +00:00
shellSurface . reset ( ) ;
2023-04-21 20:28:48 +00:00
QVERIFY ( Test : : waitForWindowClosed ( window ) ) ;
2020-08-07 19:01:42 +00:00
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : testAnchor_data ( )
2020-08-07 19:01:42 +00:00
{
QTest : : addColumn < int > ( " anchor " ) ;
2022-05-16 20:13:39 +00:00
QTest : : addColumn < QRectF > ( " expectedGeometry " ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " left " ) < < int ( Test : : LayerSurfaceV1 : : anchor_left )
2022-05-16 20:13:39 +00:00
< < QRectF ( 0 , 450 , 280 , 124 ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " top left " ) < < ( Test : : LayerSurfaceV1 : : anchor_top | Test : : LayerSurfaceV1 : : anchor_left )
2022-05-16 20:13:39 +00:00
< < QRectF ( 0 , 0 , 280 , 124 ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " top " ) < < int ( Test : : LayerSurfaceV1 : : anchor_top )
2022-05-16 20:13:39 +00:00
< < QRectF ( 500 , 0 , 280 , 124 ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " top right " ) < < ( Test : : LayerSurfaceV1 : : anchor_top | Test : : LayerSurfaceV1 : : anchor_right )
2022-05-16 20:13:39 +00:00
< < QRectF ( 1000 , 0 , 280 , 124 ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " right " ) < < int ( Test : : LayerSurfaceV1 : : anchor_right )
2022-05-16 20:13:39 +00:00
< < QRectF ( 1000 , 450 , 280 , 124 ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " bottom right " ) < < ( Test : : LayerSurfaceV1 : : anchor_bottom | Test : : LayerSurfaceV1 : : anchor_right )
2022-05-16 20:13:39 +00:00
< < QRectF ( 1000 , 900 , 280 , 124 ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " bottom " ) < < int ( Test : : LayerSurfaceV1 : : anchor_bottom )
2022-05-16 20:13:39 +00:00
< < QRectF ( 500 , 900 , 280 , 124 ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " bottom left " ) < < ( Test : : LayerSurfaceV1 : : anchor_bottom | Test : : LayerSurfaceV1 : : anchor_left )
2022-05-16 20:13:39 +00:00
< < QRectF ( 0 , 900 , 280 , 124 ) ;
2020-08-07 19:01:42 +00:00
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : testAnchor ( )
2020-08-07 19:01:42 +00:00
{
// Create a layer shell surface.
2022-08-01 21:29:02 +00:00
std : : unique_ptr < KWayland : : Client : : Surface > surface ( Test : : createSurface ( ) ) ;
std : : unique_ptr < Test : : LayerSurfaceV1 > shellSurface ( Test : : createLayerSurfaceV1 ( surface . get ( ) , QStringLiteral ( " test " ) ) ) ;
2020-08-07 19:01:42 +00:00
// Set the initial state of the layer surface.
QFETCH ( int , anchor ) ;
shellSurface - > set_anchor ( anchor ) ;
shellSurface - > set_size ( 280 , 124 ) ;
surface - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
// Wait for the compositor to position the surface.
2022-08-01 21:29:02 +00:00
QSignalSpy configureRequestedSpy ( shellSurface . get ( ) , & Test : : LayerSurfaceV1 : : configureRequested ) ;
2020-08-07 19:01:42 +00:00
QVERIFY ( configureRequestedSpy . wait ( ) ) ;
const QSize requestedSize = configureRequestedSpy . last ( ) . at ( 1 ) . toSize ( ) ;
QCOMPARE ( requestedSize , QSize ( 280 , 124 ) ) ;
// Map the layer surface.
shellSurface - > ack_configure ( configureRequestedSpy . last ( ) . at ( 0 ) . toUInt ( ) ) ;
2022-08-01 21:29:02 +00:00
Window * window = Test : : renderAndWaitForShown ( surface . get ( ) , QSize ( 280 , 124 ) , Qt : : red ) ;
2022-04-23 19:51:16 +00:00
QVERIFY ( window ) ;
2020-08-07 19:01:42 +00:00
2022-04-23 19:51:16 +00:00
// Verify that the window is placed at expected location.
QTEST ( window - > frameGeometry ( ) , " expectedGeometry " ) ;
2020-08-07 19:01:42 +00:00
2022-04-23 19:51:16 +00:00
// Destroy the window.
2020-08-07 19:01:42 +00:00
shellSurface . reset ( ) ;
2023-04-21 20:28:48 +00:00
QVERIFY ( Test : : waitForWindowClosed ( window ) ) ;
2020-08-07 19:01:42 +00:00
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : testMargins_data ( )
2020-08-07 19:01:42 +00:00
{
QTest : : addColumn < int > ( " anchor " ) ;
QTest : : addColumn < QMargins > ( " margins " ) ;
2022-05-16 20:13:39 +00:00
QTest : : addColumn < QRectF > ( " expectedGeometry " ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " left " ) < < int ( Test : : LayerSurfaceV1 : : anchor_left )
< < QMargins ( 100 , 0 , 0 , 0 )
2022-05-16 20:13:39 +00:00
< < QRectF ( 100 , 450 , 280 , 124 ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " top left " ) < < ( Test : : LayerSurfaceV1 : : anchor_top | Test : : LayerSurfaceV1 : : anchor_left )
< < QMargins ( 100 , 200 , 0 , 0 )
2022-05-16 20:13:39 +00:00
< < QRectF ( 100 , 200 , 280 , 124 ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " top " ) < < int ( Test : : LayerSurfaceV1 : : anchor_top )
< < QMargins ( 0 , 200 , 0 , 0 )
2022-05-16 20:13:39 +00:00
< < QRectF ( 500 , 200 , 280 , 124 ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " top right " ) < < ( Test : : LayerSurfaceV1 : : anchor_top | Test : : LayerSurfaceV1 : : anchor_right )
< < QMargins ( 0 , 200 , 300 , 0 )
2022-05-16 20:13:39 +00:00
< < QRectF ( 700 , 200 , 280 , 124 ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " right " ) < < int ( Test : : LayerSurfaceV1 : : anchor_right )
< < QMargins ( 0 , 0 , 300 , 0 )
2022-05-16 20:13:39 +00:00
< < QRectF ( 700 , 450 , 280 , 124 ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " bottom right " ) < < ( Test : : LayerSurfaceV1 : : anchor_bottom | Test : : LayerSurfaceV1 : : anchor_right )
2020-08-07 19:01:42 +00:00
< < QMargins ( 0 , 0 , 300 , 400 )
2022-05-16 20:13:39 +00:00
< < QRectF ( 700 , 500 , 280 , 124 ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " bottom " ) < < int ( Test : : LayerSurfaceV1 : : anchor_bottom )
< < QMargins ( 0 , 0 , 0 , 400 )
2022-05-16 20:13:39 +00:00
< < QRectF ( 500 , 500 , 280 , 124 ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " bottom left " ) < < ( Test : : LayerSurfaceV1 : : anchor_bottom | Test : : LayerSurfaceV1 : : anchor_left )
< < QMargins ( 100 , 0 , 0 , 400 )
2022-05-16 20:13:39 +00:00
< < QRectF ( 100 , 500 , 280 , 124 ) ;
2020-08-07 19:01:42 +00:00
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : testMargins ( )
2020-08-07 19:01:42 +00:00
{
// Create a layer shell surface.
2022-08-01 21:29:02 +00:00
std : : unique_ptr < KWayland : : Client : : Surface > surface ( Test : : createSurface ( ) ) ;
std : : unique_ptr < Test : : LayerSurfaceV1 > shellSurface ( Test : : createLayerSurfaceV1 ( surface . get ( ) , QStringLiteral ( " test " ) ) ) ;
2020-08-07 19:01:42 +00:00
// Set the initial state of the layer surface.
QFETCH ( QMargins , margins ) ;
QFETCH ( int , anchor ) ;
shellSurface - > set_anchor ( anchor ) ;
shellSurface - > set_margin ( margins . top ( ) , margins . right ( ) , margins . bottom ( ) , margins . left ( ) ) ;
shellSurface - > set_size ( 280 , 124 ) ;
surface - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
// Wait for the compositor to position the surface.
2022-08-01 21:29:02 +00:00
QSignalSpy configureRequestedSpy ( shellSurface . get ( ) , & Test : : LayerSurfaceV1 : : configureRequested ) ;
2020-08-07 19:01:42 +00:00
QVERIFY ( configureRequestedSpy . wait ( ) ) ;
const QSize requestedSize = configureRequestedSpy . last ( ) . at ( 1 ) . toSize ( ) ;
// Map the layer surface.
shellSurface - > ack_configure ( configureRequestedSpy . last ( ) . at ( 0 ) . toUInt ( ) ) ;
2022-08-01 21:29:02 +00:00
Window * window = Test : : renderAndWaitForShown ( surface . get ( ) , requestedSize , Qt : : red ) ;
2022-04-23 19:51:16 +00:00
QVERIFY ( window ) ;
2020-08-07 19:01:42 +00:00
2022-04-23 19:51:16 +00:00
// Verify that the window is placed at expected location.
QTEST ( window - > frameGeometry ( ) , " expectedGeometry " ) ;
2020-08-07 19:01:42 +00:00
2022-04-23 19:51:16 +00:00
// Destroy the window.
2020-08-07 19:01:42 +00:00
shellSurface . reset ( ) ;
2023-04-21 20:28:48 +00:00
QVERIFY ( Test : : waitForWindowClosed ( window ) ) ;
2020-08-07 19:01:42 +00:00
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : testLayer_data ( )
2020-08-07 19:01:42 +00:00
{
QTest : : addColumn < int > ( " protocolLayer " ) ;
QTest : : addColumn < Layer > ( " compositorLayer " ) ;
2024-01-18 13:13:55 +00:00
QTest : : addRow ( " overlay " ) < < int ( Test : : LayerShellV1 : : layer_overlay ) < < OverlayLayer ;
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " top " ) < < int ( Test : : LayerShellV1 : : layer_top ) < < AboveLayer ;
QTest : : addRow ( " bottom " ) < < int ( Test : : LayerShellV1 : : layer_bottom ) < < BelowLayer ;
2020-08-07 19:01:42 +00:00
QTest : : addRow ( " background " ) < < int ( Test : : LayerShellV1 : : layer_background ) < < DesktopLayer ;
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : testLayer ( )
2020-08-07 19:01:42 +00:00
{
// Create a layer shell surface.
2022-08-01 21:29:02 +00:00
std : : unique_ptr < KWayland : : Client : : Surface > surface ( Test : : createSurface ( ) ) ;
std : : unique_ptr < Test : : LayerSurfaceV1 > shellSurface ( Test : : createLayerSurfaceV1 ( surface . get ( ) , QStringLiteral ( " test " ) ) ) ;
2020-08-07 19:01:42 +00:00
// Set the initial state of the layer surface.
QFETCH ( int , protocolLayer ) ;
shellSurface - > set_layer ( protocolLayer ) ;
shellSurface - > set_size ( 280 , 124 ) ;
surface - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
// Wait for the compositor to position the surface.
2022-08-01 21:29:02 +00:00
QSignalSpy configureRequestedSpy ( shellSurface . get ( ) , & Test : : LayerSurfaceV1 : : configureRequested ) ;
2020-08-07 19:01:42 +00:00
QVERIFY ( configureRequestedSpy . wait ( ) ) ;
const QSize requestedSize = configureRequestedSpy . last ( ) . at ( 1 ) . toSize ( ) ;
// Map the layer surface.
shellSurface - > ack_configure ( configureRequestedSpy . last ( ) . at ( 0 ) . toUInt ( ) ) ;
2022-08-01 21:29:02 +00:00
Window * window = Test : : renderAndWaitForShown ( surface . get ( ) , requestedSize , Qt : : red ) ;
2022-04-23 19:51:16 +00:00
QVERIFY ( window ) ;
2020-08-07 19:01:42 +00:00
2022-04-23 19:51:16 +00:00
// Verify that the window is placed at expected location.
QTEST ( window - > layer ( ) , " compositorLayer " ) ;
2020-08-07 19:01:42 +00:00
2022-04-23 19:51:16 +00:00
// Destroy the window.
2020-08-07 19:01:42 +00:00
shellSurface . reset ( ) ;
2023-04-21 20:28:48 +00:00
QVERIFY ( Test : : waitForWindowClosed ( window ) ) ;
2020-08-07 19:01:42 +00:00
}
2023-05-13 11:25:53 +00:00
void LayerShellV1WindowTest : : testChangeLayer ( )
{
// This test verifies that set_layer requests are handled properly after the surface has
// been mapped on the screen.
// Create layer shell surfaces.
std : : unique_ptr < KWayland : : Client : : Surface > surface1 ( Test : : createSurface ( ) ) ;
std : : unique_ptr < Test : : LayerSurfaceV1 > shellSurface1 ( Test : : createLayerSurfaceV1 ( surface1 . get ( ) , QStringLiteral ( " test " ) ) ) ;
shellSurface1 - > set_layer ( Test : : LayerShellV1 : : layer_bottom ) ;
shellSurface1 - > set_size ( 200 , 100 ) ;
surface1 - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
std : : unique_ptr < KWayland : : Client : : Surface > surface2 ( Test : : createSurface ( ) ) ;
std : : unique_ptr < Test : : LayerSurfaceV1 > shellSurface2 ( Test : : createLayerSurfaceV1 ( surface2 . get ( ) , QStringLiteral ( " test " ) ) ) ;
shellSurface2 - > set_layer ( Test : : LayerShellV1 : : layer_bottom ) ;
shellSurface2 - > set_size ( 200 , 100 ) ;
surface2 - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
// Wait for the compositor to position the surfaces.
QSignalSpy configureRequestedSpy1 ( shellSurface1 . get ( ) , & Test : : LayerSurfaceV1 : : configureRequested ) ;
QSignalSpy configureRequestedSpy2 ( shellSurface2 . get ( ) , & Test : : LayerSurfaceV1 : : configureRequested ) ;
QVERIFY ( configureRequestedSpy2 . wait ( ) ) ;
const QSize requestedSize1 = configureRequestedSpy1 . last ( ) . at ( 1 ) . toSize ( ) ;
const QSize requestedSize2 = configureRequestedSpy2 . last ( ) . at ( 1 ) . toSize ( ) ;
// Map the layer surfaces.
shellSurface1 - > ack_configure ( configureRequestedSpy1 . last ( ) . at ( 0 ) . toUInt ( ) ) ;
Window * window1 = Test : : renderAndWaitForShown ( surface1 . get ( ) , requestedSize1 , Qt : : red ) ;
QVERIFY ( window1 ) ;
shellSurface2 - > ack_configure ( configureRequestedSpy2 . last ( ) . at ( 0 ) . toUInt ( ) ) ;
Window * window2 = Test : : renderAndWaitForShown ( surface2 . get ( ) , requestedSize2 , Qt : : red ) ;
QVERIFY ( window2 ) ;
// The first layer shell window is stacked below the second one.
QCOMPARE ( workspace ( ) - > stackingOrder ( ) , ( QList < Window * > { window1 , window2 } ) ) ;
// Move the first layer shell window to the top layer.
QSignalSpy stackingOrderChangedSpy ( workspace ( ) , & Workspace : : stackingOrderChanged ) ;
shellSurface1 - > set_layer ( Test : : LayerShellV1 : : layer_top ) ;
surface1 - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
QVERIFY ( stackingOrderChangedSpy . wait ( ) ) ;
// The first layer shell window should be on top now.
QCOMPARE ( workspace ( ) - > stackingOrder ( ) , ( QList < Window * > { window2 , window1 } ) ) ;
// Destroy the window.
shellSurface1 . reset ( ) ;
QVERIFY ( Test : : waitForWindowClosed ( window1 ) ) ;
shellSurface2 . reset ( ) ;
QVERIFY ( Test : : waitForWindowClosed ( window2 ) ) ;
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : testPlacementArea_data ( )
2020-08-07 19:01:42 +00:00
{
QTest : : addColumn < int > ( " anchor " ) ;
2023-09-08 09:01:06 +00:00
QTest : : addColumn < QMargins > ( " margins " ) ;
2020-08-07 19:01:42 +00:00
QTest : : addColumn < int > ( " exclusiveZone " ) ;
2024-01-26 11:55:13 +00:00
QTest : : addColumn < int > ( " exclusiveEdge " ) ;
2022-05-16 20:13:39 +00:00
QTest : : addColumn < QRectF > ( " placementArea " ) ;
2020-08-07 19:01:42 +00:00
2024-01-26 11:55:13 +00:00
QTest : : addRow ( " left " ) < < int ( Test : : LayerSurfaceV1 : : anchor_left ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < 0 < < QRectF ( 300 , 0 , 980 , 1024 ) ;
QTest : : addRow ( " top " ) < < int ( Test : : LayerSurfaceV1 : : anchor_top ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < 0 < < QRectF ( 0 , 300 , 1280 , 724 ) ;
QTest : : addRow ( " right " ) < < int ( Test : : LayerSurfaceV1 : : anchor_right ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < 0 < < QRectF ( 0 , 0 , 980 , 1024 ) ;
QTest : : addRow ( " bottom " ) < < int ( Test : : LayerSurfaceV1 : : anchor_bottom ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < 0 < < QRectF ( 0 , 0 , 1280 , 724 ) ;
QTest : : addRow ( " top | left " ) < < int ( Test : : LayerSurfaceV1 : : anchor_top | Test : : LayerSurfaceV1 : : anchor_left ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < 0 < < QRectF ( 0 , 0 , 1280 , 1024 ) ;
QTest : : addRow ( " top | right " ) < < int ( Test : : LayerSurfaceV1 : : anchor_top | Test : : LayerSurfaceV1 : : anchor_right ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < 0 < < QRectF ( 0 , 0 , 1280 , 1024 ) ;
QTest : : addRow ( " bottom | left " ) < < int ( Test : : LayerSurfaceV1 : : anchor_bottom | Test : : LayerSurfaceV1 : : anchor_left ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < 0 < < QRectF ( 0 , 0 , 1280 , 1024 ) ;
QTest : : addRow ( " bottom | right " ) < < int ( Test : : LayerSurfaceV1 : : anchor_bottom | Test : : LayerSurfaceV1 : : anchor_right ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < 0 < < QRectF ( 0 , 0 , 1280 , 1024 ) ;
QTest : : addRow ( " left, negative margin " ) < < int ( Test : : LayerSurfaceV1 : : anchor_left ) < < QMargins ( - 5 , 0 , 0 , 0 ) < < 300 < < 0 < < QRectF ( 295 , 0 , 985 , 1024 ) ;
QTest : : addRow ( " top, negative margin " ) < < int ( Test : : LayerSurfaceV1 : : anchor_top ) < < QMargins ( 0 , - 5 , 0 , 0 ) < < 300 < < 0 < < QRectF ( 0 , 295 , 1280 , 729 ) ;
QTest : : addRow ( " right, negative margin " ) < < int ( Test : : LayerSurfaceV1 : : anchor_right ) < < QMargins ( 0 , 0 , - 5 , 0 ) < < 300 < < 0 < < QRectF ( 0 , 0 , 985 , 1024 ) ;
QTest : : addRow ( " bottom, negative margin " ) < < int ( Test : : LayerSurfaceV1 : : anchor_bottom ) < < QMargins ( 0 , 0 , 0 , - 5 ) < < 300 < < 0 < < QRectF ( 0 , 0 , 1280 , 729 ) ;
QTest : : addRow ( " left, positive margin " ) < < int ( Test : : LayerSurfaceV1 : : anchor_left ) < < QMargins ( 5 , 0 , 0 , 0 ) < < 300 < < 0 < < QRectF ( 305 , 0 , 975 , 1024 ) ;
QTest : : addRow ( " top, positive margin " ) < < int ( Test : : LayerSurfaceV1 : : anchor_top ) < < QMargins ( 0 , 5 , 0 , 0 ) < < 300 < < 0 < < QRectF ( 0 , 305 , 1280 , 719 ) ;
QTest : : addRow ( " right, positive margin " ) < < int ( Test : : LayerSurfaceV1 : : anchor_right ) < < QMargins ( 0 , 0 , 5 , 0 ) < < 300 < < 0 < < QRectF ( 0 , 0 , 975 , 1024 ) ;
QTest : : addRow ( " bottom, positive margin " ) < < int ( Test : : LayerSurfaceV1 : : anchor_bottom ) < < QMargins ( 0 , 0 , 0 , 5 ) < < 300 < < 0 < < QRectF ( 0 , 0 , 1280 , 719 ) ;
QTest : : addRow ( " left + left exclusive edge " ) < < int ( Test : : LayerSurfaceV1 : : anchor_left ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < int ( Test : : LayerSurfaceV1 : : anchor_left ) < < QRectF ( 300 , 0 , 980 , 1024 ) ;
QTest : : addRow ( " top + top exclusive edge " ) < < int ( Test : : LayerSurfaceV1 : : anchor_top ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < int ( Test : : LayerSurfaceV1 : : anchor_top ) < < QRectF ( 0 , 300 , 1280 , 724 ) ;
QTest : : addRow ( " right + right exclusive edge " ) < < int ( Test : : LayerSurfaceV1 : : anchor_right ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < int ( Test : : LayerSurfaceV1 : : anchor_right ) < < QRectF ( 0 , 0 , 980 , 1024 ) ;
QTest : : addRow ( " bottom + bottom exclusive edge " ) < < int ( Test : : LayerSurfaceV1 : : anchor_bottom ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < int ( Test : : LayerSurfaceV1 : : anchor_bottom ) < < QRectF ( 0 , 0 , 1280 , 724 ) ;
QTest : : addRow ( " top | left + top exclusive edge " ) < < int ( Test : : LayerSurfaceV1 : : anchor_top | Test : : LayerSurfaceV1 : : anchor_left ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < int ( Test : : LayerSurfaceV1 : : anchor_top ) < < QRectF ( 0 , 300 , 1280 , 724 ) ;
QTest : : addRow ( " top | left + left exclusive edge " ) < < int ( Test : : LayerSurfaceV1 : : anchor_top | Test : : LayerSurfaceV1 : : anchor_left ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < int ( Test : : LayerSurfaceV1 : : anchor_left ) < < QRectF ( 300 , 0 , 980 , 1024 ) ;
QTest : : addRow ( " top | right + top exclusive edge " ) < < int ( Test : : LayerSurfaceV1 : : anchor_top | Test : : LayerSurfaceV1 : : anchor_right ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < int ( Test : : LayerSurfaceV1 : : anchor_top ) < < QRectF ( 0 , 300 , 1280 , 724 ) ;
QTest : : addRow ( " top | right + right exclusive edge " ) < < int ( Test : : LayerSurfaceV1 : : anchor_top | Test : : LayerSurfaceV1 : : anchor_right ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < int ( Test : : LayerSurfaceV1 : : anchor_right ) < < QRectF ( 0 , 0 , 980 , 1024 ) ;
QTest : : addRow ( " bottom | left + bottom exclusive edge " ) < < int ( Test : : LayerSurfaceV1 : : anchor_bottom | Test : : LayerSurfaceV1 : : anchor_left ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < int ( Test : : LayerSurfaceV1 : : anchor_bottom ) < < QRectF ( 0 , 0 , 1280 , 724 ) ;
QTest : : addRow ( " bottom | left + left exclusive edge " ) < < int ( Test : : LayerSurfaceV1 : : anchor_bottom | Test : : LayerSurfaceV1 : : anchor_left ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < int ( Test : : LayerSurfaceV1 : : anchor_left ) < < QRectF ( 300 , 0 , 980 , 1024 ) ;
QTest : : addRow ( " bottom | right + bottom exclusive edge " ) < < int ( Test : : LayerSurfaceV1 : : anchor_bottom | Test : : LayerSurfaceV1 : : anchor_right ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < int ( Test : : LayerSurfaceV1 : : anchor_bottom ) < < QRectF ( 0 , 0 , 1280 , 724 ) ;
QTest : : addRow ( " bottom | right + right exclusive edge " ) < < int ( Test : : LayerSurfaceV1 : : anchor_bottom | Test : : LayerSurfaceV1 : : anchor_right ) < < QMargins ( 0 , 0 , 0 , 0 ) < < 300 < < int ( Test : : LayerSurfaceV1 : : anchor_right ) < < QRectF ( 0 , 0 , 980 , 1024 ) ;
2020-08-07 19:01:42 +00:00
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : testPlacementArea ( )
2020-08-07 19:01:42 +00:00
{
// Create a layer shell surface.
2022-08-01 21:29:02 +00:00
std : : unique_ptr < KWayland : : Client : : Surface > surface ( Test : : createSurface ( ) ) ;
std : : unique_ptr < Test : : LayerSurfaceV1 > shellSurface ( Test : : createLayerSurfaceV1 ( surface . get ( ) , QStringLiteral ( " test " ) ) ) ;
2020-08-07 19:01:42 +00:00
// Set the initial state of the layer surface.
QFETCH ( int , anchor ) ;
2023-09-08 09:01:06 +00:00
QFETCH ( QMargins , margins ) ;
2020-08-07 19:01:42 +00:00
QFETCH ( int , exclusiveZone ) ;
2024-01-26 11:55:13 +00:00
QFETCH ( int , exclusiveEdge ) ;
2020-08-07 19:01:42 +00:00
shellSurface - > set_anchor ( anchor ) ;
2023-09-08 09:01:06 +00:00
shellSurface - > set_margin ( margins . top ( ) , margins . right ( ) , margins . bottom ( ) , margins . left ( ) ) ;
2020-08-07 19:01:42 +00:00
shellSurface - > set_exclusive_zone ( exclusiveZone ) ;
2024-01-26 11:55:13 +00:00
shellSurface - > set_exclusive_edge ( exclusiveEdge ) ;
2020-08-07 19:01:42 +00:00
shellSurface - > set_size ( 280 , 124 ) ;
surface - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
// Wait for the compositor to position the surface.
2022-08-01 21:29:02 +00:00
QSignalSpy configureRequestedSpy ( shellSurface . get ( ) , & Test : : LayerSurfaceV1 : : configureRequested ) ;
2020-08-07 19:01:42 +00:00
QVERIFY ( configureRequestedSpy . wait ( ) ) ;
const QSize requestedSize = configureRequestedSpy . last ( ) . at ( 1 ) . toSize ( ) ;
// Map the layer surface.
shellSurface - > ack_configure ( configureRequestedSpy . last ( ) . at ( 0 ) . toUInt ( ) ) ;
2022-08-01 21:29:02 +00:00
Window * window = Test : : renderAndWaitForShown ( surface . get ( ) , requestedSize , Qt : : red ) ;
2022-04-23 19:51:16 +00:00
QVERIFY ( window ) ;
2020-08-07 19:01:42 +00:00
// Verify that the work area has been adjusted.
2022-04-23 19:51:16 +00:00
QTEST ( workspace ( ) - > clientArea ( PlacementArea , window ) , " placementArea " ) ;
2020-08-07 19:01:42 +00:00
2022-04-23 19:51:16 +00:00
// Destroy the window.
2020-08-07 19:01:42 +00:00
shellSurface . reset ( ) ;
2023-04-21 20:28:48 +00:00
QVERIFY ( Test : : waitForWindowClosed ( window ) ) ;
2020-08-07 19:01:42 +00:00
}
wayland: Fix windows shrinking when output layout changes
When the output layout changes, the Workspace is going to update the
struts and then go through every window and see whether it should be
moved or resized.
On the other hand, the layer shell windows react to output changes on
a timer. Furthermore, it's not synchronized with the workspace rearranging
the managed windows. It means that when Workspace::desktopResized() runs,
the panel struts can be slightly outdated, i.e.
- An output layout change occurs
- Workspace::desktopResized() is called but the struts can be wrong
- some time later, LayerShellV1Integration::rearrange is called, it
fixes layer shell window geometries and struts
- after the layer shell integration has finished rearranging the
layer shell windows, it calls Workspace::desktopResized(), but the
damage had already been caused
With the proposed change, the Workspace and the LayerShellV1Integration
will rearrange the windows in sync.
CCBUG: 482361
2024-03-06 09:29:31 +00:00
void LayerShellV1WindowTest : : testPlacementAreaAfterOutputLayoutChange ( )
{
// This test verifies that layer shell windows correctly react to output layout changes.
// The output where the layer surface should be placed.
Output * output = workspace ( ) - > activeOutput ( ) ;
// Create a layer surface with an exclusive zone.
std : : unique_ptr < KWayland : : Client : : Surface > surface ( Test : : createSurface ( ) ) ;
std : : unique_ptr < Test : : LayerSurfaceV1 > shellSurface ( Test : : createLayerSurfaceV1 ( surface . get ( ) , QStringLiteral ( " dock " ) , Test : : waylandOutput ( output - > name ( ) ) ) ) ;
shellSurface - > set_layer ( Test : : LayerShellV1 : : layer_top ) ;
shellSurface - > set_anchor ( Test : : LayerSurfaceV1 : : anchor_bottom ) ;
shellSurface - > set_size ( 100 , 50 ) ;
shellSurface - > set_exclusive_edge ( Test : : LayerSurfaceV1 : : anchor_bottom ) ;
shellSurface - > set_exclusive_zone ( 50 ) ;
surface - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
// Wait for the compositor to position the layer surface.
QSignalSpy configureRequestedSpy ( shellSurface . get ( ) , & Test : : LayerSurfaceV1 : : configureRequested ) ;
QVERIFY ( configureRequestedSpy . wait ( ) ) ;
shellSurface - > ack_configure ( configureRequestedSpy . last ( ) . at ( 0 ) . toUInt ( ) ) ;
Window * window = Test : : renderAndWaitForShown ( surface . get ( ) , configureRequestedSpy . last ( ) . at ( 1 ) . toSize ( ) , Qt : : red ) ;
QVERIFY ( window ) ;
QCOMPARE ( workspace ( ) - > clientArea ( PlacementArea , window ) , output - > geometry ( ) . adjusted ( 0 , 0 , 0 , - 50 ) ) ;
// Move the output 100px down.
OutputConfiguration config1 ;
{
auto changeSet = config1 . changeSet ( output ) ;
changeSet - > pos = output - > geometry ( ) . topLeft ( ) + QPoint ( 0 , 100 ) ;
}
workspace ( ) - > applyOutputConfiguration ( config1 ) ;
QCOMPARE ( workspace ( ) - > clientArea ( PlacementArea , window ) , output - > geometry ( ) . adjusted ( 0 , 0 , 0 , - 50 ) ) ;
// Move the output back to its original position.
OutputConfiguration config2 ;
{
auto changeSet = config2 . changeSet ( output ) ;
changeSet - > pos = output - > geometry ( ) . topLeft ( ) - QPoint ( 0 , 100 ) ;
}
workspace ( ) - > applyOutputConfiguration ( config2 ) ;
QCOMPARE ( workspace ( ) - > clientArea ( PlacementArea , window ) , output - > geometry ( ) . adjusted ( 0 , 0 , 0 , - 50 ) ) ;
// Destroy the window.
shellSurface . reset ( ) ;
QVERIFY ( Test : : waitForWindowClosed ( window ) ) ;
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : testFill_data ( )
2020-08-07 19:01:42 +00:00
{
QTest : : addColumn < int > ( " anchor " ) ;
QTest : : addColumn < QSize > ( " desiredSize " ) ;
2022-05-16 20:13:39 +00:00
QTest : : addColumn < QRectF > ( " expectedGeometry " ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " horizontal " ) < < ( Test : : LayerSurfaceV1 : : anchor_left | Test : : LayerSurfaceV1 : : anchor_right )
2020-08-07 19:01:42 +00:00
< < QSize ( 0 , 124 )
2022-05-16 20:13:39 +00:00
< < QRectF ( 0 , 450 , 1280 , 124 ) ;
2020-08-07 19:01:42 +00:00
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " vertical " ) < < ( Test : : LayerSurfaceV1 : : anchor_top | Test : : LayerSurfaceV1 : : anchor_bottom )
< < QSize ( 280 , 0 )
2022-05-16 20:13:39 +00:00
< < QRectF ( 500 , 0 , 280 , 1024 ) ;
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " all " ) < < ( Test : : LayerSurfaceV1 : : anchor_left | Test : : LayerSurfaceV1 : : anchor_top | Test : : LayerSurfaceV1 : : anchor_right | Test : : LayerSurfaceV1 : : anchor_bottom )
< < QSize ( 0 , 0 )
2022-05-16 20:13:39 +00:00
< < QRectF ( 0 , 0 , 1280 , 1024 ) ;
2020-08-07 19:01:42 +00:00
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : testFill ( )
2020-08-07 19:01:42 +00:00
{
// Create a layer shell surface.
2022-08-01 21:29:02 +00:00
std : : unique_ptr < KWayland : : Client : : Surface > surface ( Test : : createSurface ( ) ) ;
std : : unique_ptr < Test : : LayerSurfaceV1 > shellSurface ( Test : : createLayerSurfaceV1 ( surface . get ( ) , QStringLiteral ( " test " ) ) ) ;
2020-08-07 19:01:42 +00:00
// Set the initial state of the layer surface.
QFETCH ( int , anchor ) ;
QFETCH ( QSize , desiredSize ) ;
shellSurface - > set_anchor ( anchor ) ;
shellSurface - > set_size ( desiredSize . width ( ) , desiredSize . height ( ) ) ;
surface - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
// Wait for the compositor to position the surface.
2022-08-01 21:29:02 +00:00
QSignalSpy configureRequestedSpy ( shellSurface . get ( ) , & Test : : LayerSurfaceV1 : : configureRequested ) ;
2020-08-07 19:01:42 +00:00
QVERIFY ( configureRequestedSpy . wait ( ) ) ;
const QSize requestedSize = configureRequestedSpy . last ( ) . at ( 1 ) . toSize ( ) ;
// Map the layer surface.
shellSurface - > ack_configure ( configureRequestedSpy . last ( ) . at ( 0 ) . toUInt ( ) ) ;
2022-08-01 21:29:02 +00:00
Window * window = Test : : renderAndWaitForShown ( surface . get ( ) , requestedSize , Qt : : red ) ;
2022-04-23 19:51:16 +00:00
QVERIFY ( window ) ;
2020-08-07 19:01:42 +00:00
2022-04-23 19:51:16 +00:00
// Verify that the window is placed at expected location.
QTEST ( window - > frameGeometry ( ) , " expectedGeometry " ) ;
2020-08-07 19:01:42 +00:00
2022-04-23 19:51:16 +00:00
// Destroy the window.
2020-08-07 19:01:42 +00:00
shellSurface . reset ( ) ;
2023-04-21 20:28:48 +00:00
QVERIFY ( Test : : waitForWindowClosed ( window ) ) ;
2020-08-07 19:01:42 +00:00
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : testStack ( )
2020-08-07 19:01:42 +00:00
{
// Create a layer shell surface.
2022-08-01 21:29:02 +00:00
std : : unique_ptr < KWayland : : Client : : Surface > surface1 ( Test : : createSurface ( ) ) ;
std : : unique_ptr < Test : : LayerSurfaceV1 > shellSurface1 ( Test : : createLayerSurfaceV1 ( surface1 . get ( ) , QStringLiteral ( " test " ) ) ) ;
2020-08-07 19:01:42 +00:00
2022-08-01 21:29:02 +00:00
std : : unique_ptr < KWayland : : Client : : Surface > surface2 ( Test : : createSurface ( ) ) ;
std : : unique_ptr < Test : : LayerSurfaceV1 > shellSurface2 ( Test : : createLayerSurfaceV1 ( surface2 . get ( ) , QStringLiteral ( " test " ) ) ) ;
2020-08-07 19:01:42 +00:00
// Set the initial state of the layer surface.
shellSurface1 - > set_anchor ( Test : : LayerSurfaceV1 : : anchor_left ) ;
shellSurface1 - > set_size ( 80 , 124 ) ;
shellSurface1 - > set_exclusive_zone ( 80 ) ;
surface1 - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
shellSurface2 - > set_anchor ( Test : : LayerSurfaceV1 : : anchor_left ) ;
shellSurface2 - > set_size ( 200 , 124 ) ;
shellSurface2 - > set_exclusive_zone ( 200 ) ;
surface2 - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
// Wait for the compositor to position the surfaces.
2022-08-01 21:29:02 +00:00
QSignalSpy configureRequestedSpy1 ( shellSurface1 . get ( ) , & Test : : LayerSurfaceV1 : : configureRequested ) ;
QSignalSpy configureRequestedSpy2 ( shellSurface2 . get ( ) , & Test : : LayerSurfaceV1 : : configureRequested ) ;
2020-08-07 19:01:42 +00:00
QVERIFY ( configureRequestedSpy2 . wait ( ) ) ;
const QSize requestedSize1 = configureRequestedSpy1 . last ( ) . at ( 1 ) . toSize ( ) ;
const QSize requestedSize2 = configureRequestedSpy2 . last ( ) . at ( 1 ) . toSize ( ) ;
// Map the layer surface.
shellSurface1 - > ack_configure ( configureRequestedSpy1 . last ( ) . at ( 0 ) . toUInt ( ) ) ;
2022-08-01 21:29:02 +00:00
Window * window1 = Test : : renderAndWaitForShown ( surface1 . get ( ) , requestedSize1 , Qt : : red ) ;
2022-04-23 19:51:16 +00:00
QVERIFY ( window1 ) ;
2020-08-07 19:01:42 +00:00
shellSurface2 - > ack_configure ( configureRequestedSpy2 . last ( ) . at ( 0 ) . toUInt ( ) ) ;
2022-08-01 21:29:02 +00:00
Window * window2 = Test : : renderAndWaitForShown ( surface2 . get ( ) , requestedSize2 , Qt : : red ) ;
2022-04-23 19:51:16 +00:00
QVERIFY ( window2 ) ;
2020-08-07 19:01:42 +00:00
// Check that the second layer surface is placed next to the first.
2022-04-23 19:51:16 +00:00
QCOMPARE ( window1 - > frameGeometry ( ) , QRect ( 0 , 450 , 80 , 124 ) ) ;
QCOMPARE ( window2 - > frameGeometry ( ) , QRect ( 80 , 450 , 200 , 124 ) ) ;
2020-08-07 19:01:42 +00:00
// Check that the work area has been adjusted accordingly.
2022-04-23 19:51:16 +00:00
QCOMPARE ( workspace ( ) - > clientArea ( PlacementArea , window1 ) , QRect ( 280 , 0 , 1000 , 1024 ) ) ;
QCOMPARE ( workspace ( ) - > clientArea ( PlacementArea , window2 ) , QRect ( 280 , 0 , 1000 , 1024 ) ) ;
2020-08-07 19:01:42 +00:00
2022-04-23 19:51:16 +00:00
// Destroy the window.
2020-08-07 19:01:42 +00:00
shellSurface1 . reset ( ) ;
2023-04-21 20:28:48 +00:00
QVERIFY ( Test : : waitForWindowClosed ( window1 ) ) ;
2020-08-07 19:01:42 +00:00
shellSurface2 . reset ( ) ;
2023-04-21 20:28:48 +00:00
QVERIFY ( Test : : waitForWindowClosed ( window2 ) ) ;
2020-08-07 19:01:42 +00:00
}
2023-10-26 14:03:27 +00:00
void LayerShellV1WindowTest : : testKeyboardInteractivityNone ( )
2020-08-07 19:01:42 +00:00
{
// Create a layer shell surface.
2022-08-01 21:29:02 +00:00
std : : unique_ptr < KWayland : : Client : : Surface > surface ( Test : : createSurface ( ) ) ;
std : : unique_ptr < Test : : LayerSurfaceV1 > shellSurface ( Test : : createLayerSurfaceV1 ( surface . get ( ) , QStringLiteral ( " test " ) ) ) ;
2020-08-07 19:01:42 +00:00
// Set the initial state of the layer surface.
2023-10-26 14:03:27 +00:00
shellSurface - > set_keyboard_interactivity ( 0 ) ;
shellSurface - > set_size ( 100 , 50 ) ;
2020-08-07 19:01:42 +00:00
surface - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
// Wait for the compositor to position the surface.
2022-08-01 21:29:02 +00:00
QSignalSpy configureRequestedSpy ( shellSurface . get ( ) , & Test : : LayerSurfaceV1 : : configureRequested ) ;
2020-08-07 19:01:42 +00:00
QVERIFY ( configureRequestedSpy . wait ( ) ) ;
const QSize requestedSize = configureRequestedSpy . last ( ) . at ( 1 ) . toSize ( ) ;
// Map the layer surface.
shellSurface - > ack_configure ( configureRequestedSpy . last ( ) . at ( 0 ) . toUInt ( ) ) ;
2022-08-01 21:29:02 +00:00
Window * window = Test : : renderAndWaitForShown ( surface . get ( ) , requestedSize , Qt : : red ) ;
2022-04-23 19:51:16 +00:00
QVERIFY ( window ) ;
2023-10-26 14:03:27 +00:00
QVERIFY ( ! window - > isActive ( ) ) ;
2020-08-07 19:01:42 +00:00
2023-10-26 14:03:27 +00:00
// Try to activate the surface.
workspace ( ) - > activateWindow ( window ) ;
QVERIFY ( ! window - > isActive ( ) ) ;
2020-08-07 19:01:42 +00:00
2022-04-23 19:51:16 +00:00
// Destroy the window.
2020-08-07 19:01:42 +00:00
shellSurface . reset ( ) ;
2023-04-21 20:28:48 +00:00
QVERIFY ( Test : : waitForWindowClosed ( window ) ) ;
2020-08-07 19:01:42 +00:00
}
2023-10-26 14:03:27 +00:00
void LayerShellV1WindowTest : : testKeyboardInteractivityOnDemand ( )
{
// Create a layer shell surface.
std : : unique_ptr < KWayland : : Client : : Surface > surface1 ( Test : : createSurface ( ) ) ;
std : : unique_ptr < Test : : LayerSurfaceV1 > shellSurface1 ( Test : : createLayerSurfaceV1 ( surface1 . get ( ) , QStringLiteral ( " test " ) ) ) ;
shellSurface1 - > set_keyboard_interactivity ( 1 ) ;
shellSurface1 - > set_size ( 280 , 124 ) ;
surface1 - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
QSignalSpy configureRequestedSpy1 ( shellSurface1 . get ( ) , & Test : : LayerSurfaceV1 : : configureRequested ) ;
QVERIFY ( configureRequestedSpy1 . wait ( ) ) ;
const QSize requestedSize1 = configureRequestedSpy1 . last ( ) . at ( 1 ) . toSize ( ) ;
shellSurface1 - > ack_configure ( configureRequestedSpy1 . last ( ) . at ( 0 ) . toUInt ( ) ) ;
Window * window1 = Test : : renderAndWaitForShown ( surface1 . get ( ) , requestedSize1 , Qt : : red ) ;
QVERIFY ( window1 ) ;
QVERIFY ( window1 - > isActive ( ) ) ;
// Create the second layer shell surface.
std : : unique_ptr < KWayland : : Client : : Surface > surface2 ( Test : : createSurface ( ) ) ;
std : : unique_ptr < Test : : LayerSurfaceV1 > shellSurface2 ( Test : : createLayerSurfaceV1 ( surface2 . get ( ) , QStringLiteral ( " test " ) ) ) ;
shellSurface2 - > set_keyboard_interactivity ( 1 ) ;
shellSurface2 - > set_size ( 280 , 124 ) ;
surface2 - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
QSignalSpy configureRequestedSpy2 ( shellSurface2 . get ( ) , & Test : : LayerSurfaceV1 : : configureRequested ) ;
QVERIFY ( configureRequestedSpy2 . wait ( ) ) ;
const QSize requestedSize2 = configureRequestedSpy2 . last ( ) . at ( 1 ) . toSize ( ) ;
shellSurface2 - > ack_configure ( configureRequestedSpy2 . last ( ) . at ( 0 ) . toUInt ( ) ) ;
Window * window2 = Test : : renderAndWaitForShown ( surface2 . get ( ) , requestedSize2 , Qt : : red ) ;
QVERIFY ( window2 ) ;
QVERIFY ( window2 - > isActive ( ) ) ;
QVERIFY ( ! window1 - > isActive ( ) ) ;
// Activate the first surface.
workspace ( ) - > activateWindow ( window1 ) ;
QVERIFY ( window1 - > isActive ( ) ) ;
QVERIFY ( ! window2 - > isActive ( ) ) ;
// Destroy the window.
shellSurface1 . reset ( ) ;
QVERIFY ( Test : : waitForWindowClosed ( window1 ) ) ;
shellSurface2 . reset ( ) ;
QVERIFY ( Test : : waitForWindowClosed ( window2 ) ) ;
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : testActivate_data ( )
2020-08-07 19:01:42 +00:00
{
QTest : : addColumn < int > ( " layer " ) ;
QTest : : addColumn < bool > ( " active " ) ;
2022-03-23 10:13:38 +00:00
QTest : : addRow ( " overlay " ) < < int ( Test : : LayerShellV1 : : layer_overlay ) < < true ;
QTest : : addRow ( " top " ) < < int ( Test : : LayerShellV1 : : layer_top ) < < true ;
QTest : : addRow ( " bottom " ) < < int ( Test : : LayerShellV1 : : layer_bottom ) < < false ;
2020-08-07 19:01:42 +00:00
QTest : : addRow ( " background " ) < < int ( Test : : LayerShellV1 : : layer_background ) < < false ;
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : testActivate ( )
2020-08-07 19:01:42 +00:00
{
// Create a layer shell surface.
2022-08-01 21:29:02 +00:00
std : : unique_ptr < KWayland : : Client : : Surface > surface ( Test : : createSurface ( ) ) ;
std : : unique_ptr < Test : : LayerSurfaceV1 > shellSurface ( Test : : createLayerSurfaceV1 ( surface . get ( ) , QStringLiteral ( " test " ) ) ) ;
2020-08-07 19:01:42 +00:00
// Set the initial state of the layer surface.
QFETCH ( int , layer ) ;
shellSurface - > set_layer ( layer ) ;
shellSurface - > set_size ( 280 , 124 ) ;
surface - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
// Wait for the compositor to position the surface.
2022-08-01 21:29:02 +00:00
QSignalSpy configureRequestedSpy ( shellSurface . get ( ) , & Test : : LayerSurfaceV1 : : configureRequested ) ;
2020-08-07 19:01:42 +00:00
QVERIFY ( configureRequestedSpy . wait ( ) ) ;
const QSize requestedSize = configureRequestedSpy . last ( ) . at ( 1 ) . toSize ( ) ;
// Map the layer surface.
shellSurface - > ack_configure ( configureRequestedSpy . last ( ) . at ( 0 ) . toUInt ( ) ) ;
2022-08-01 21:29:02 +00:00
Window * window = Test : : renderAndWaitForShown ( surface . get ( ) , requestedSize , Qt : : red ) ;
2022-04-23 19:51:16 +00:00
QVERIFY ( window ) ;
QVERIFY ( ! window - > isActive ( ) ) ;
2020-08-07 19:01:42 +00:00
// Try to activate the layer surface.
shellSurface - > set_keyboard_interactivity ( 1 ) ;
surface - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
2022-04-23 19:51:16 +00:00
QSignalSpy activeChangedSpy ( window , & Window : : activeChanged ) ;
2020-08-07 19:01:42 +00:00
QTEST ( activeChangedSpy . wait ( 1000 ) , " active " ) ;
2022-04-23 19:51:16 +00:00
// Destroy the window.
2020-08-07 19:01:42 +00:00
shellSurface . reset ( ) ;
2023-04-21 20:28:48 +00:00
QVERIFY ( Test : : waitForWindowClosed ( window ) ) ;
2020-08-07 19:01:42 +00:00
}
2022-04-22 17:46:41 +00:00
void LayerShellV1WindowTest : : testUnmap ( )
2020-08-07 19:01:42 +00:00
{
// Create a layer shell surface.
2022-08-01 21:29:02 +00:00
std : : unique_ptr < KWayland : : Client : : Surface > surface ( Test : : createSurface ( ) ) ;
std : : unique_ptr < Test : : LayerSurfaceV1 > shellSurface ( Test : : createLayerSurfaceV1 ( surface . get ( ) , QStringLiteral ( " test " ) ) ) ;
2020-08-07 19:01:42 +00:00
// Set the initial state of the layer surface.
shellSurface - > set_size ( 280 , 124 ) ;
surface - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
// Wait for the compositor to position the surface.
2022-08-01 21:29:02 +00:00
QSignalSpy configureRequestedSpy ( shellSurface . get ( ) , & Test : : LayerSurfaceV1 : : configureRequested ) ;
2020-08-07 19:01:42 +00:00
QVERIFY ( configureRequestedSpy . wait ( ) ) ;
// Map the layer surface.
shellSurface - > ack_configure ( configureRequestedSpy . last ( ) . at ( 0 ) . toUInt ( ) ) ;
2022-08-01 21:29:02 +00:00
Window * window = Test : : renderAndWaitForShown ( surface . get ( ) , QSize ( 280 , 124 ) , Qt : : red ) ;
2022-04-23 19:51:16 +00:00
QVERIFY ( window ) ;
2020-08-07 19:01:42 +00:00
// Unmap the layer surface.
surface - > attachBuffer ( KWayland : : Client : : Buffer : : Ptr ( ) ) ;
surface - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
2023-04-21 20:28:48 +00:00
QVERIFY ( Test : : waitForWindowClosed ( window ) ) ;
2020-08-07 19:01:42 +00:00
// Notify the compositor that we want to map the layer surface.
shellSurface - > set_size ( 280 , 124 ) ;
surface - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
// Wait for the configure event.
QVERIFY ( configureRequestedSpy . wait ( ) ) ;
// Map the layer surface back.
shellSurface - > ack_configure ( configureRequestedSpy . last ( ) . at ( 0 ) . toUInt ( ) ) ;
2022-08-01 21:29:02 +00:00
window = Test : : renderAndWaitForShown ( surface . get ( ) , QSize ( 280 , 124 ) , Qt : : red ) ;
2022-04-23 19:51:16 +00:00
QVERIFY ( window ) ;
2020-08-07 19:01:42 +00:00
2022-04-23 19:51:16 +00:00
// Destroy the window.
2020-08-07 19:01:42 +00:00
shellSurface . reset ( ) ;
2023-04-21 20:28:48 +00:00
QVERIFY ( Test : : waitForWindowClosed ( window ) ) ;
2020-08-07 19:01:42 +00:00
}
2024-01-24 10:30:43 +00:00
void LayerShellV1WindowTest : : testScreenEdge_data ( )
{
QTest : : addColumn < QMargins > ( " margins " ) ;
QTest : : addRow ( " normal " ) < < QMargins ( 0 , 0 , 0 , 0 ) ;
QTest : : addRow ( " with margin " ) < < QMargins ( 0 , 0 , 0 , 10 ) ;
}
2023-03-08 08:07:39 +00:00
void LayerShellV1WindowTest : : testScreenEdge ( )
{
2023-12-01 08:09:35 +00:00
auto config = kwinApp ( ) - > config ( ) ;
2024-01-16 16:29:58 +00:00
config - > group ( QStringLiteral ( " Windows " ) ) . writeEntry ( " ElectricBorderDelay " , 75 ) ;
2023-12-01 08:09:35 +00:00
config - > sync ( ) ;
workspace ( ) - > slotReconfigure ( ) ;
2023-03-08 08:07:39 +00:00
// Create a layer shell surface.
std : : unique_ptr < KWayland : : Client : : Surface > surface ( Test : : createSurface ( ) ) ;
std : : unique_ptr < Test : : LayerSurfaceV1 > shellSurface ( Test : : createLayerSurfaceV1 ( surface . get ( ) , QStringLiteral ( " test " ) ) ) ;
std : : unique_ptr < Test : : AutoHideScreenEdgeV1 > screenEdge ( Test : : createAutoHideScreenEdgeV1 ( surface . get ( ) , Test : : ScreenEdgeManagerV1 : : border_bottom ) ) ;
// Set the initial state of the layer surface.
2024-01-24 10:30:43 +00:00
QFETCH ( QMargins , margins ) ;
2023-03-08 08:07:39 +00:00
shellSurface - > set_layer ( Test : : LayerShellV1 : : layer_top ) ;
shellSurface - > set_anchor ( Test : : LayerSurfaceV1 : : anchor_bottom ) ;
shellSurface - > set_size ( 100 , 50 ) ;
2024-01-24 10:30:43 +00:00
shellSurface - > set_margin ( margins . top ( ) , margins . right ( ) , margins . bottom ( ) , margins . left ( ) ) ;
2023-03-08 08:07:39 +00:00
surface - > commit ( KWayland : : Client : : Surface : : CommitFlag : : None ) ;
// Wait for the compositor to position the surface.
QSignalSpy configureRequestedSpy ( shellSurface . get ( ) , & Test : : LayerSurfaceV1 : : configureRequested ) ;
QVERIFY ( configureRequestedSpy . wait ( ) ) ;
const QSize requestedSize = configureRequestedSpy . last ( ) . at ( 1 ) . toSize ( ) ;
// Map the layer surface.
shellSurface - > ack_configure ( configureRequestedSpy . last ( ) . at ( 0 ) . toUInt ( ) ) ;
Window * window = Test : : renderAndWaitForShown ( surface . get ( ) , requestedSize , Qt : : red ) ;
QVERIFY ( window ) ;
QVERIFY ( ! window - > isActive ( ) ) ;
2024-01-29 22:04:57 +00:00
QSignalSpy hiddenChangedSpy ( window , & Window : : hiddenChanged ) ;
2023-05-25 09:59:00 +00:00
quint32 timestamp = 0 ;
2023-03-08 08:07:39 +00:00
2023-05-25 09:59:00 +00:00
// The layer surface will be hidden and shown when the screen edge is activated or deactivated.
{
screenEdge - > activate ( ) ;
2024-01-29 22:04:57 +00:00
QVERIFY ( hiddenChangedSpy . wait ( ) ) ;
2023-05-25 09:59:00 +00:00
QVERIFY ( ! window - > isShown ( ) ) ;
2023-03-08 08:07:39 +00:00
2023-05-25 09:59:00 +00:00
screenEdge - > deactivate ( ) ;
2024-01-29 22:04:57 +00:00
QVERIFY ( hiddenChangedSpy . wait ( ) ) ;
2023-05-25 09:59:00 +00:00
QVERIFY ( window - > isShown ( ) ) ;
}
2023-03-08 08:07:39 +00:00
2023-05-25 09:59:00 +00:00
// The layer surface will be shown when the screen edge is triggered.
{
screenEdge - > activate ( ) ;
2024-01-29 22:04:57 +00:00
QVERIFY ( hiddenChangedSpy . wait ( ) ) ;
2023-05-25 09:59:00 +00:00
QVERIFY ( ! window - > isShown ( ) ) ;
2023-12-01 08:09:35 +00:00
Test : : pointerMotion ( QPointF ( 640 , 1023 ) , timestamp ) ;
timestamp + = 160 ;
Test : : pointerMotion ( QPointF ( 640 , 1023 ) , timestamp ) ;
timestamp + = 160 ;
Test : : pointerMotion ( QPointF ( 640 , 512 ) , timestamp ) ;
2024-01-29 22:04:57 +00:00
QVERIFY ( hiddenChangedSpy . wait ( ) ) ;
2023-05-25 09:59:00 +00:00
QVERIFY ( window - > isShown ( ) ) ;
}
// The approaching state will be reset if the window is shown manually.
{
QSignalSpy approachingSpy ( workspace ( ) - > screenEdges ( ) , & ScreenEdges : : approaching ) ;
screenEdge - > activate ( ) ;
2024-01-29 22:04:57 +00:00
QVERIFY ( hiddenChangedSpy . wait ( ) ) ;
2023-05-25 09:59:00 +00:00
QVERIFY ( ! window - > isShown ( ) ) ;
Test : : pointerMotion ( QPointF ( 640 , 1020 ) , timestamp + + ) ;
QVERIFY ( approachingSpy . last ( ) . at ( 1 ) . toReal ( ) = = 0.0 ) ;
Test : : pointerMotion ( QPointF ( 640 , 1021 ) , timestamp + + ) ;
QVERIFY ( approachingSpy . last ( ) . at ( 1 ) . toReal ( ) ! = 0.0 ) ;
screenEdge - > deactivate ( ) ;
2024-01-29 22:04:57 +00:00
QVERIFY ( hiddenChangedSpy . wait ( ) ) ;
2023-05-25 09:59:00 +00:00
QVERIFY ( window - > isShown ( ) ) ;
QVERIFY ( approachingSpy . last ( ) . at ( 1 ) . toReal ( ) = = 0.0 ) ;
Test : : pointerMotion ( QPointF ( 640 , 512 ) , timestamp + + ) ;
}
2023-03-08 08:07:39 +00:00
// The layer surface will be shown when the screen edge is destroyed.
2023-05-25 09:59:00 +00:00
{
screenEdge - > activate ( ) ;
2024-01-29 22:04:57 +00:00
QVERIFY ( hiddenChangedSpy . wait ( ) ) ;
2023-05-25 09:59:00 +00:00
QVERIFY ( ! window - > isShown ( ) ) ;
screenEdge . reset ( ) ;
2024-01-29 22:04:57 +00:00
QVERIFY ( hiddenChangedSpy . wait ( ) ) ;
2023-05-25 09:59:00 +00:00
QVERIFY ( window - > isShown ( ) ) ;
}
2023-03-08 08:07:39 +00:00
}
2020-08-07 19:01:42 +00:00
} // namespace KWin
2022-04-22 17:46:41 +00:00
WAYLANDTEST_MAIN ( KWin : : LayerShellV1WindowTest )
# include "layershellv1window_test.moc"