Git commit 1e13deaa1d5687482bfe87741659467226b4c331 by Martin Fl=C3=B6ser, = on behalf of Martin Gr=C3=A4=C3=9Flin. Committed on 01/09/2017 at 15:11. Pushed by graesslin into branch 'master'. Port some displayWidth/displayHeight usages to Screens::size() Summary: KWin::displayWidth and KWin::displayHeight are bound to X11 which doesn't make much sense on X11. In addition KWin internally knows the overall display dimensions through the Screens singleton class. Reviewers: #kwin Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D1798 M +5 -0 autotests/CMakeLists.txt M +8 -0 autotests/test_scripted_effectloader.cpp M +4 -3 effects.cpp M +18 -14 geometry.cpp M +10 -1 plugins/platforms/x11/standalone/screens_xrandr.cpp M +1 -0 plugins/platforms/x11/standalone/screens_xrandr.h M +6 -3 scene_xrender.cpp M +2 -2 screenedge.cpp M +5 -0 screens.cpp M +12 -0 screens.h M +3 -2 scripting/scriptedeffect.cpp M +3 -3 scripting/workspace_wrapper.cpp https://commits.kde.org/kwin/1e13deaa1d5687482bfe87741659467226b4c331 diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 85d9733b7..67d3e7299 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -152,12 +152,17 @@ ecm_mark_as_test(testBuiltInEffectLoader) include_directories(${KWIN_SOURCE_DIR}) set( testScriptedEffectLoader_SRCS test_scripted_effectloader.cpp + mock_abstract_client.cpp mock_effectshandler.cpp + mock_screens.cpp + mock_workspace.cpp ../effectloader.cpp ../scripting/scriptedeffect.cpp ../scripting/scriptingutils.cpp ../scripting/scripting_logging.cpp + ../screens.cpp ) +kconfig_add_kcfg_files(testScriptedEffectLoader_SRCS ../settings.kcfgc) add_executable( testScriptedEffectLoader ${testScriptedEffectLoader_SRCS}) = target_link_libraries(testScriptedEffectLoader diff --git a/autotests/test_scripted_effectloader.cpp b/autotests/test_scri= pted_effectloader.cpp index 1265e4c0f..8b9f0193d 100644 --- a/autotests/test_scripted_effectloader.cpp +++ b/autotests/test_scripted_effectloader.cpp @@ -21,6 +21,7 @@ along with this program. If not, see . #include "mock_effectshandler.h" #include "../scripting/scriptedeffect.h" // for mocking +#include "../cursor.h" #include "../input.h" #include "../screenedge.h" // KDE @@ -63,6 +64,13 @@ void registration(QScriptEngine *) } } = +static QPoint s_cursorPos =3D QPoint(); +QPoint Cursor::pos() +{ + return s_cursorPos; +} + + } = class TestScriptedEffectLoader : public QObject diff --git a/effects.cpp b/effects.cpp index d33ecf471..acc864feb 100644 --- a/effects.cpp +++ b/effects.cpp @@ -961,12 +961,12 @@ int EffectsHandlerImpl::desktopGridHeight() const = int EffectsHandlerImpl::workspaceWidth() const { - return desktopGridWidth() * displayWidth(); + return desktopGridWidth() * screens()->size().width(); } = int EffectsHandlerImpl::workspaceHeight() const { - return desktopGridHeight() * displayHeight(); + return desktopGridHeight() * screens()->size().height(); } = int EffectsHandlerImpl::desktopAtCoords(QPoint coords) const @@ -987,7 +987,8 @@ QPoint EffectsHandlerImpl::desktopCoords(int id) const QPoint coords =3D VirtualDesktopManager::self()->grid().gridCoords(id); if (coords.x() =3D=3D -1) return QPoint(-1, -1); - return QPoint(coords.x() * displayWidth(), coords.y() * displayHeight(= )); + const QSize displaySize =3D screens()->size(); + return QPoint(coords.x() * displaySize.width(), coords.y() * displaySi= ze.height()); } = int EffectsHandlerImpl::desktopAbove(int desktop, bool wrap) const diff --git a/geometry.cpp b/geometry.cpp index b32b0e3a7..85d582e54 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -90,7 +90,7 @@ void Workspace::desktopResized() = void Workspace::saveOldScreenSizes() { - olddisplaysize =3D QSize( displayWidth(), displayHeight()); + olddisplaysize =3D screens()->displaySize(); oldscreensizes.clear(); for( int i =3D 0; i < screens()->count(); @@ -355,6 +355,7 @@ QRect Workspace::clientArea(clientAreaOption opt, int s= creen, int desktop) const desktop =3D VirtualDesktopManager::self()->current(); if (screen =3D=3D -1) screen =3D screens()->current(); + const QSize displaySize =3D screens()->displaySize(); = QRect sarea, warea; = @@ -372,7 +373,7 @@ QRect Workspace::clientArea(clientAreaOption opt, int s= creen, int desktop) const ? screenarea[ desktop ][ screen ] : screens()->geometry(screen); warea =3D workarea[ desktop ].isNull() - ? QRect(0, 0, displayWidth(), displayHeight()) + ? QRect(0, 0, displaySize.width(), displaySize.height()) : workarea[ desktop ]; } = @@ -394,7 +395,7 @@ QRect Workspace::clientArea(clientAreaOption opt, int s= creen, int desktop) const else return warea; case FullArea: - return QRect(0, 0, displayWidth(), displayHeight()); + return QRect(0, 0, displaySize.width(), displaySize.height()); } abort(); } @@ -955,7 +956,7 @@ QRect Client::adjustedClientArea(const QRect &desktopAr= ea, const QRect& area) co // HACK: workarea handling is not xinerama aware, so if this strut // reserves place at a xinerama edge that's inside the virtual screen, // ignore the strut for workspace setting. - if (area =3D=3D QRect(0, 0, displayWidth(), displayHeight())) { + if (area =3D=3D QRect(QPoint(0, 0), screens()->displaySize())) { if (stareaL.left() < screenarea.left()) stareaL =3D QRect(); if (stareaR.right() > screenarea.right()) @@ -997,28 +998,29 @@ NETExtendedStrut Client::strut() const { NETExtendedStrut ext =3D info->extendedStrut(); NETStrut str =3D info->strut(); + const QSize displaySize =3D screens()->displaySize(); if (ext.left_width =3D=3D 0 && ext.right_width =3D=3D 0 && ext.top_wid= th =3D=3D 0 && ext.bottom_width =3D=3D 0 && (str.left !=3D 0 || str.right !=3D 0 || str.top !=3D 0 || s= tr.bottom !=3D 0)) { // build extended from simple if (str.left !=3D 0) { ext.left_width =3D str.left; ext.left_start =3D 0; - ext.left_end =3D displayHeight(); + ext.left_end =3D displaySize.height(); } if (str.right !=3D 0) { ext.right_width =3D str.right; ext.right_start =3D 0; - ext.right_end =3D displayHeight(); + ext.right_end =3D displaySize.height(); } if (str.top !=3D 0) { ext.top_width =3D str.top; ext.top_start =3D 0; - ext.top_end =3D displayWidth(); + ext.top_end =3D displaySize.width(); } if (str.bottom !=3D 0) { ext.bottom_width =3D str.bottom; ext.bottom_start =3D 0; - ext.bottom_end =3D displayWidth(); + ext.bottom_end =3D displaySize.width(); } } return ext; @@ -1027,6 +1029,7 @@ NETExtendedStrut Client::strut() const StrutRect Client::strutRect(StrutArea area) const { assert(area !=3D StrutAreaAll); // Not valid + const QSize displaySize =3D screens()->displaySize(); NETExtendedStrut strutArea =3D strut(); switch(area) { case StrutAreaTop: @@ -1039,14 +1042,14 @@ StrutRect Client::strutRect(StrutArea area) const case StrutAreaRight: if (strutArea.right_width !=3D 0) return StrutRect(QRect( - displayWidth() - strutArea.right_width, s= trutArea.right_start, + displaySize.width() - strutArea.right_wid= th, strutArea.right_start, strutArea.right_width, strutArea.right_en= d - strutArea.right_start ), StrutAreaRight); break; case StrutAreaBottom: if (strutArea.bottom_width !=3D 0) return StrutRect(QRect( - strutArea.bottom_start, displayHeight() -= strutArea.bottom_width, + strutArea.bottom_start, displaySize.heigh= t() - strutArea.bottom_width, strutArea.bottom_end - strutArea.bottom_s= tart, strutArea.bottom_width ), StrutAreaBottom); break; @@ -1148,6 +1151,7 @@ void AbstractClient::checkWorkspacePosition(QRect old= Geometry, int oldDesktop, Q QRect oldScreenArea; QRect oldGeomTall; QRect oldGeomWide; + const auto displaySize =3D screens()->displaySize(); if( workspace()->inUpdateClientArea()) { // we need to find the screen area as it was before the change oldScreenArea =3D QRect( 0, 0, workspace()->oldDisplayWidth(), wor= kspace()->oldDisplayHeight()); @@ -1163,8 +1167,8 @@ void AbstractClient::checkWorkspacePosition(QRect old= Geometry, int oldDesktop, Q } } else { oldScreenArea =3D workspace()->clientArea(ScreenArea, oldGeometry.= center(), oldDesktop); - oldGeomTall =3D QRect(oldGeometry.x(), 0, oldGeometry.width(), dis= playHeight()); // Full screen height - oldGeomWide =3D QRect(0, oldGeometry.y(), displayWidth(), oldGeome= try.height()); // Full screen width + oldGeomTall =3D QRect(oldGeometry.x(), 0, oldGeometry.width(), dis= playSize.height()); // Full screen height + oldGeomWide =3D QRect(0, oldGeometry.y(), displaySize.width(), old= Geometry.height()); // Full screen width } int oldTopMax =3D oldScreenArea.y(); int oldRightMax =3D oldScreenArea.x() + oldScreenArea.width(); @@ -1177,8 +1181,8 @@ void AbstractClient::checkWorkspacePosition(QRect old= Geometry, int oldDesktop, Q int leftMax =3D screenArea.x(); QRect newGeom =3D geometryRestore(); // geometry(); QRect newClientGeom =3D newGeom.adjusted(border[Left], border[Top], -b= order[Right], -border[Bottom]); - const QRect newGeomTall =3D QRect(newGeom.x(), 0, newGeom.width(), dis= playHeight()); // Full screen height - const QRect newGeomWide =3D QRect(0, newGeom.y(), displayWidth(), newG= eom.height()); // Full screen width + const QRect newGeomTall =3D QRect(newGeom.x(), 0, newGeom.width(), dis= playSize.height()); // Full screen height + const QRect newGeomWide =3D QRect(0, newGeom.y(), displaySize.width(),= newGeom.height()); // Full screen width // Get the max strut point for each side where the window is (E.g. Hig= hest point for // the bottom struts bounded by the window's left and right sides). = diff --git a/plugins/platforms/x11/standalone/screens_xrandr.cpp b/plugins/= platforms/x11/standalone/screens_xrandr.cpp index ca9c31146..eecc2409b 100644 --- a/plugins/platforms/x11/standalone/screens_xrandr.cpp +++ b/plugins/platforms/x11/standalone/screens_xrandr.cpp @@ -126,7 +126,7 @@ QRect XRandRScreens::geometry(int screen) const return QRect(); } return m_geometries.at(screen).isValid() ? m_geometries.at(screen) : - QRect(0, 0, displayWidth(), displayHeight()); // xinerama, lack= s RandR + QRect(QPoint(0, 0), displaySize()); // xinerama, lacks RandR } = QString XRandRScreens::name(int screen) const @@ -188,4 +188,13 @@ bool XRandRScreens::event(xcb_generic_event_t *event) return false; } = +QSize XRandRScreens::displaySize() const +{ + xcb_screen_t *screen =3D defaultScreen(); + if (!screen) { + return Screens::size(); + } + return QSize(screen->width_in_pixels, screen->height_in_pixels); +} + } // namespace diff --git a/plugins/platforms/x11/standalone/screens_xrandr.h b/plugins/pl= atforms/x11/standalone/screens_xrandr.h index e491ce00f..5a7a74879 100644 --- a/plugins/platforms/x11/standalone/screens_xrandr.h +++ b/plugins/platforms/x11/standalone/screens_xrandr.h @@ -40,6 +40,7 @@ public: int number(const QPoint& pos) const override; float refreshRate(int screen) const override; QSize size(int screen) const override; + QSize displaySize() const override; = using QObject::event; bool event(xcb_generic_event_t *event) override; diff --git a/scene_xrender.cpp b/scene_xrender.cpp index ead00b8c5..433480787 100644 --- a/scene_xrender.cpp +++ b/scene_xrender.cpp @@ -33,6 +33,7 @@ along with this program. If not, see . #include "main.h" #include "overlaywindow.h" #include "platform.h" +#include "screens.h" #include "xcbutils.h" #include "kwinxrenderutils.h" #include "decorations/decoratedclient.h" @@ -173,7 +174,8 @@ void X11XRenderBackend::init(bool createOverlay) void X11XRenderBackend::createBuffer() { xcb_pixmap_t pixmap =3D xcb_generate_id(connection()); - xcb_create_pixmap(connection(), Xcb::defaultDepth(), pixmap, rootWindo= w(), displayWidth(), displayHeight()); + const auto displaySize =3D screens()->displaySize(); + xcb_create_pixmap(connection(), Xcb::defaultDepth(), pixmap, rootWindo= w(), displaySize.width(), displaySize.height()); xcb_render_picture_t b =3D xcb_generate_id(connection()); xcb_render_create_picture(connection(), b, pixmap, m_format, 0, NULL); xcb_free_pixmap(connection(), pixmap); // The picture owns the pixma= p now @@ -182,6 +184,7 @@ void X11XRenderBackend::createBuffer() = void X11XRenderBackend::present(int mask, const QRegion &damage) { + const auto displaySize =3D screens()->displaySize(); if (mask & Scene::PAINT_SCREEN_REGION) { // Use the damage region as the clip region for the root window XFixesRegion frontRegion(damage); @@ -189,13 +192,13 @@ void X11XRenderBackend::present(int mask, const QRegi= on &damage) // copy composed buffer to the root window xcb_xfixes_set_picture_clip_region(connection(), buffer(), XCB_XFI= XES_REGION_NONE, 0, 0); xcb_render_composite(connection(), XCB_RENDER_PICT_OP_SRC, buffer(= ), XCB_RENDER_PICTURE_NONE, - m_front, 0, 0, 0, 0, 0, 0, displayWidth(), di= splayHeight()); + m_front, 0, 0, 0, 0, 0, 0, displaySize.width(= ), displaySize.height()); xcb_xfixes_set_picture_clip_region(connection(), m_front, XCB_XFIX= ES_REGION_NONE, 0, 0); xcb_flush(connection()); } else { // copy composed buffer to the root window xcb_render_composite(connection(), XCB_RENDER_PICT_OP_SRC, buffer(= ), XCB_RENDER_PICTURE_NONE, - m_front, 0, 0, 0, 0, 0, 0, displayWidth(), di= splayHeight()); + m_front, 0, 0, 0, 0, 0, 0, displaySize.width(= ), displaySize.height()); xcb_flush(connection()); } } diff --git a/screenedge.cpp b/screenedge.cpp index 6b32abbd6..1a1a88570 100644 --- a/screenedge.cpp +++ b/screenedge.cpp @@ -417,7 +417,7 @@ void Edge::switchDesktop(const QPoint &cursorPos) const uint interimDesktop =3D desktop; desktop =3D vds->toLeft(desktop, vds->isNavigationWrappingAround()= ); if (desktop !=3D interimDesktop) - pos.setX(displayWidth() - 1 - OFFSET); + pos.setX(screens()->size().width() - 1 - OFFSET); } else if (isRight()) { const uint interimDesktop =3D desktop; desktop =3D vds->toRight(desktop, vds->isNavigationWrappingAround(= )); @@ -428,7 +428,7 @@ void Edge::switchDesktop(const QPoint &cursorPos) const uint interimDesktop =3D desktop; desktop =3D vds->above(desktop, vds->isNavigationWrappingAround()); if (desktop !=3D interimDesktop) - pos.setY(displayHeight() - 1 - OFFSET); + pos.setY(screens()->size().height() - 1 - OFFSET); } else if (isBottom()) { const uint interimDesktop =3D desktop; desktop =3D vds->below(desktop, vds->isNavigationWrappingAround()); diff --git a/screens.cpp b/screens.cpp index 8f5b4782e..078bc9c57 100644 --- a/screens.cpp +++ b/screens.cpp @@ -185,6 +185,11 @@ int Screens::intersecting(const QRect &r) const return cnt; } = +QSize Screens::displaySize() const +{ + return size(); +} + BasicScreens::BasicScreens(Platform *backend, QObject *parent) : Screens(parent) , m_backend(backend) diff --git a/screens.h b/screens.h index 1e4b7988e..3dda15f2b 100644 --- a/screens.h +++ b/screens.h @@ -105,6 +105,18 @@ public: = int intersecting(const QRect &r) const; = + /** + * The virtual bounding size of all screens combined. + * The default implementation returns the same as @link{size} and that= is the + * method which should be preferred. + * + * This method is only for cases where the platform specific implement= ation needs + * to support different virtual sizes like on X11 with XRandR panning. + * + * @see size + **/ + virtual QSize displaySize() const; + public Q_SLOTS: void reconfigure(); = diff --git a/scripting/scriptedeffect.cpp b/scripting/scriptedeffect.cpp index 94d6b7681..a05ef02a3 100644 --- a/scripting/scriptedeffect.cpp +++ b/scripting/scriptedeffect.cpp @@ -22,6 +22,7 @@ along with this program. If not, see . #include "meta.h" #include "scriptingutils.h" #include "workspace_wrapper.h" +#include "../screens.h" #include "../screenedge.h" #include "scripting_logging.h" // KDE @@ -71,14 +72,14 @@ QScriptValue kwinEffectDisplayWidth(QScriptContext *con= text, QScriptEngine *engi { Q_UNUSED(context) Q_UNUSED(engine) - return displayWidth(); + return screens()->displaySize().width(); } = QScriptValue kwinEffectDisplayHeight(QScriptContext *context, QScriptEngin= e *engine) { Q_UNUSED(context) Q_UNUSED(engine) - return displayHeight(); + return screens()->displaySize().height(); } = QScriptValue kwinScriptGlobalShortcut(QScriptContext *context, QScriptEngi= ne *engine) diff --git a/scripting/workspace_wrapper.cpp b/scripting/workspace_wrapper.= cpp index ad7d1dfbe..1099a8525 100644 --- a/scripting/workspace_wrapper.cpp +++ b/scripting/workspace_wrapper.cpp @@ -226,17 +226,17 @@ QSize WorkspaceWrapper::workspaceSize() const = QSize WorkspaceWrapper::displaySize() const { - return QSize(KWin::displayWidth(), KWin::displayHeight()); + return screens()->displaySize(); } = int WorkspaceWrapper::displayWidth() const { - return KWin::displayWidth(); + return displaySize().width(); } = int WorkspaceWrapper::displayHeight() const { - return KWin::displayHeight(); + return displaySize().height(); } = QRect WorkspaceWrapper::clientArea(ClientAreaOption option, const QPoint &= p, int desktop) const