[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kwin] /: Move screen inversion through XRandr into X11 standalone platform
From:       Martin_Flöser <null () kde ! org>
Date:       2017-09-01 16:06:14
Message-ID: E1dnoSU-0008Ko-0r () code ! kde ! org
[Download RAW message or body]

Git commit 51561052ec0342a6afe821c2a8c6074e2d59a914 by Martin Flöser.
Committed on 01/09/2017 at 16:04.
Pushed by graesslin into branch 'master'.

Move screen inversion through XRandr into X11 standalone platform

Summary:
By moving the functionality into the Platform API we can also implement
support on other platforms which support this in general (e.g. DRM once
Roman's color adjustment patches landed).

Reviewers: #kwin, #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D7447

M  +11   -0    platform.cpp
M  +6    -0    platform.h
M  +44   -0    plugins/platforms/x11/standalone/x11_platform.cpp
M  +2    -0    plugins/platforms/x11/standalone/x11_platform.h
M  +1    -48   useractions.cpp

https://commits.kde.org/kwin/51561052ec0342a6afe821c2a8c6074e2d59a914

diff --git a/platform.cpp b/platform.cpp
index 8400d4b09..b9bb859f0 100644
--- a/platform.cpp
+++ b/platform.cpp
@@ -22,6 +22,7 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  #include "abstract_egl_backend.h"
 #include "composite.h"
 #include "cursor.h"
+#include "effects.h"
 #include "input.h"
 #include "overlaywindow.h"
 #include "outline.h"
@@ -487,4 +488,14 @@ Decoration::Renderer \
*Platform::createDecorationRenderer(Decoration::DecoratedCl  return nullptr;
 }
 
+void Platform::invertScreen()
+{
+    if (effects) {
+        if (Effect *inverter = \
static_cast<EffectsHandlerImpl*>(effects)->provides(Effect::ScreenInversion)) { +     \
qCDebug(KWIN_CORE) << "inverting screen using Effect plugin"; +            \
QMetaObject::invokeMethod(inverter, "toggleScreenInversion", Qt::DirectConnection); + \
} +    }
+}
+
 }
diff --git a/platform.h b/platform.h
index 5c55480c5..4d9fc2716 100644
--- a/platform.h
+++ b/platform.h
@@ -338,6 +338,12 @@ public:
      **/
     virtual Decoration::Renderer \
*createDecorationRenderer(Decoration::DecoratedClientImpl *client);  
+    /**
+     * Platform specific way to invert the screen.
+     * Default implementation invokes the invert effect
+     **/
+    virtual void invertScreen();
+
 public Q_SLOTS:
     void pointerMotion(const QPointF &position, quint32 time);
     void pointerButtonPressed(quint32 button, quint32 time);
diff --git a/plugins/platforms/x11/standalone/x11_platform.cpp \
b/plugins/platforms/x11/standalone/x11_platform.cpp index 34cb91cd1..a2924d686 100644
--- a/plugins/platforms/x11/standalone/x11_platform.cpp
+++ b/plugins/platforms/x11/standalone/x11_platform.cpp
@@ -29,6 +29,7 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  #if HAVE_X11_XINPUT
 #include "xinputintegration.h"
 #endif
+#include "abstract_client.h"
 #include "eglonxbackend.h"
 #include "keyboard_input.h"
 #include "logging.h"
@@ -37,6 +38,7 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  #include "options.h"
 #include "overlaywindow_x11.h"
 #include "non_composited_outline.h"
+#include "workspace.h"
 #include "x11_decoration_renderer.h"
 
 #include <KConfigGroup>
@@ -356,4 +358,46 @@ Decoration::Renderer \
*X11StandalonePlatform::createDecorationRenderer(Decoration  return renderer;
 }
 
+void X11StandalonePlatform::invertScreen()
+{
+    using namespace Xcb::RandR;
+    bool succeeded = false;
+
+    if (Xcb::Extensions::self()->isRandrAvailable()) {
+        const auto active_client = workspace()->activeClient();
+        ScreenResources res((active_client && active_client->window() != \
XCB_WINDOW_NONE) ? active_client->window() : rootWindow()); +
+        if (!res.isNull()) {
+            for (int j = 0; j < res->num_crtcs; ++j) {
+                auto crtc = res.crtcs()[j];
+                CrtcGamma gamma(crtc);
+                if (gamma.isNull()) {
+                    continue;
+                }
+                if (gamma->size) {
+                    qCDebug(KWIN_CORE) << "inverting screen using \
xcb_randr_set_crtc_gamma"; +                    const int half = gamma->size / 2 + 1;
+
+                    uint16_t *red = gamma.red();
+                    uint16_t *green = gamma.green();
+                    uint16_t *blue = gamma.blue();
+                    for (int i = 0; i < half; ++i) {
+                        auto invert = [&gamma, i](uint16_t *ramp) {
+                            qSwap(ramp[i], ramp[gamma->size - 1 - i]);
+                        };
+                        invert(red);
+                        invert(green);
+                        invert(blue);
+                    }
+                    xcb_randr_set_crtc_gamma(connection(), crtc, gamma->size, red, \
green, blue); +                    succeeded = true;
+                }
+            }
+        }
+    }
+    if (!succeeded) {
+        Platform::invertScreen();
+    }
+}
+
 }
diff --git a/plugins/platforms/x11/standalone/x11_platform.h \
b/plugins/platforms/x11/standalone/x11_platform.h index 6f0022ffe..02a4ae15d 100644
--- a/plugins/platforms/x11/standalone/x11_platform.h
+++ b/plugins/platforms/x11/standalone/x11_platform.h
@@ -62,6 +62,8 @@ public:
     OutlineVisual *createOutline(Outline *outline) override;
     Decoration::Renderer *createDecorationRenderer(Decoration::DecoratedClientImpl \
*client) override;  
+    void invertScreen() override;
+
 protected:
     void doHideCursor() override;
     void doShowCursor() override;
diff --git a/useractions.cpp b/useractions.cpp
index 91bb925cb..124f9b3f8 100644
--- a/useractions.cpp
+++ b/useractions.cpp
@@ -1705,54 +1705,7 @@ void Workspace::slotWindowResize()
 
 void Workspace::slotInvertScreen()
 {
-    using namespace Xcb::RandR;
-    bool succeeded = false;
-
-    if (Xcb::Extensions::self()->isRandrAvailable()) {
-        ScreenResources res((active_client && active_client->window() != \
                XCB_WINDOW_NONE) ? active_client->window() : rootWindow());
-
-        if (!res.isNull()) {
-            for (int j = 0; j < res->num_crtcs; ++j) {
-                auto crtc = res.crtcs()[j];
-                CrtcGamma gamma(crtc);
-                if (gamma.isNull()) {
-                    continue;
-                }
-                if (gamma->size) {
-                    qCDebug(KWIN_CORE) << "inverting screen using \
                xcb_randr_set_crtc_gamma";
-                    const int half = gamma->size / 2 + 1;
-
-                    uint16_t *red = gamma.red();
-                    uint16_t *green = gamma.green();
-                    uint16_t *blue = gamma.blue();
-                    for (int i = 0; i < half; ++i) {
-                        auto invert = [&gamma, i](uint16_t *ramp) {
-                            qSwap(ramp[i], ramp[gamma->size - 1 - i]);
-                        };
-                        invert(red);
-                        invert(green);
-                        invert(blue);
-                    }
-                    xcb_randr_set_crtc_gamma(connection(), crtc, gamma->size, red, \
                green, blue);
-                    succeeded = true;
-                }
-            }
-        }
-    }
-    if (succeeded)
-        return;
-
-    //BEGIN effect plugin inversion - atm only works with OpenGL and has an overhead \
                to it
-    if (effects) {
-        if (Effect *inverter = \
                static_cast<EffectsHandlerImpl*>(effects)->provides(Effect::ScreenInversion)) \
                {
-            qCDebug(KWIN_CORE) << "inverting screen using Effect plugin";
-            QMetaObject::invokeMethod(inverter, "toggleScreenInversion", \
                Qt::DirectConnection);
-        }
-    }
-
-    if (!succeeded)
-        qCDebug(KWIN_CORE) << "sorry - neither Xrandr, nor XF86VidModeSetGammaRamp \
                worked and there's no inversion supplying effect plugin either";
-
+    kwinApp()->platform()->invertScreen();
 }
 
 #undef USABLE_ACTIVE_CLIENT


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic