From 3d384f3c90205f35fea445446903661c7c046514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Tue, 18 Jun 2019 20:28:04 +0200 Subject: [PATCH 1/2] glx: Prefer an sRGB capable fbconfig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prefer an sRGB capable fbconfig for the default framebuffer. CCBUG: 408594 Signed-off-by: Fredrik Höglund --- .../platforms/x11/standalone/glxbackend.cpp | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/plugins/platforms/x11/standalone/glxbackend.cpp b/plugins/platforms/x11/standalone/glxbackend.cpp index 70dba60003..1d31b447f9 100644 --- a/plugins/platforms/x11/standalone/glxbackend.cpp +++ b/plugins/platforms/x11/standalone/glxbackend.cpp @@ -416,9 +416,29 @@ bool GlxBackend::initFbConfig() 0 }; - // Try to find a double buffered configuration + const int attribs_srgb[] = { + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_ALPHA_SIZE, 0, + GLX_DEPTH_SIZE, 0, + GLX_STENCIL_SIZE, 0, + GLX_CONFIG_CAVEAT, GLX_NONE, + GLX_DOUBLEBUFFER, true, + GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB, true, + 0 + }; + + // Try to find a double buffered sRGB capable configuration int count = 0; - GLXFBConfig *configs = glXChooseFBConfig(display(), DefaultScreen(display()), attribs, &count); + GLXFBConfig *configs = glXChooseFBConfig(display(), DefaultScreen(display()), attribs_srgb, &count); + + if (count == 0) { + // Try to find a double buffered non-sRGB capable configuration + configs = glXChooseFBConfig(display(), DefaultScreen(display()), attribs, &count); + } struct FBConfig { GLXFBConfig config; @@ -452,7 +472,7 @@ bool GlxBackend::initFbConfig() if (candidates.size() > 0) { fbconfig = candidates.front().config; - int fbconfig_id, visual_id, red, green, blue, alpha, depth, stencil; + int fbconfig_id, visual_id, red, green, blue, alpha, depth, stencil, srgb; glXGetFBConfigAttrib(display(), fbconfig, GLX_FBCONFIG_ID, &fbconfig_id); glXGetFBConfigAttrib(display(), fbconfig, GLX_VISUAL_ID, &visual_id); glXGetFBConfigAttrib(display(), fbconfig, GLX_RED_SIZE, &red); @@ -461,9 +481,10 @@ bool GlxBackend::initFbConfig() glXGetFBConfigAttrib(display(), fbconfig, GLX_ALPHA_SIZE, &alpha); glXGetFBConfigAttrib(display(), fbconfig, GLX_DEPTH_SIZE, &depth); glXGetFBConfigAttrib(display(), fbconfig, GLX_STENCIL_SIZE, &stencil); + glXGetFBConfigAttrib(display(), fbconfig, GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB, &srgb); - qCDebug(KWIN_X11STANDALONE, "Choosing GLXFBConfig %#x X visual %#x depth %d RGBA %d:%d:%d:%d ZS %d:%d", - fbconfig_id, visual_id, visualDepth(visual_id), red, green, blue, alpha, depth, stencil); + qCDebug(KWIN_X11STANDALONE, "Choosing GLXFBConfig %#x X visual %#x depth %d RGBA %d:%d:%d:%d ZS %d:%d sRGB: %d", + fbconfig_id, visual_id, visualDepth(visual_id), red, green, blue, alpha, depth, stencil, srgb); } if (fbconfig == nullptr) { From 499eccb1c8d75f596bc736cef5ce53aa0eb16e16 Mon Sep 17 00:00:00 2001 From: Vlad Zagorodniy Date: Tue, 21 May 2019 14:41:27 +0300 Subject: [PATCH 2/2] [tabbox] Properly determine depressed modifiers on X11 Summary: A keysym can be assigned to several keycodes, so more proper way to determine whether given modifier is depressed is to iterate over all returned keycodes and see if any is pressed. If we check only the first keycode, then alternative mappings may not work, e.g. alt key mapped to win, etc. BUG: 407720 Reviewers: #kwin, davidedmundson Reviewed By: #kwin, davidedmundson Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D21302 --- tabbox/tabbox.cpp | 58 +++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/tabbox/tabbox.cpp b/tabbox/tabbox.cpp index a7cea59aa0..5911dac4d7 100644 --- a/tabbox/tabbox.cpp +++ b/tabbox/tabbox.cpp @@ -921,10 +921,8 @@ struct KeySymbolsDeleter /** * Handles alt-tab / control-tab **/ -static bool areKeySymXsDepressed(bool bAll, const uint keySyms[], int nKeySyms) { - - qCDebug(KWIN_TABBOX) << "areKeySymXsDepressed: " << (bAll ? "all of " : "any of ") << nKeySyms; - +static bool areKeySymXsDepressed(const uint keySyms[], int nKeySyms) +{ Xcb::QueryKeymap keys; QScopedPointer symbols(xcb_key_symbols_alloc(connection())); @@ -933,42 +931,38 @@ static bool areKeySymXsDepressed(bool bAll, const uint keySyms[], int nKeySyms) } const auto keymap = keys->keys; + bool depressed = false; for (int iKeySym = 0; iKeySym < nKeySyms; iKeySym++) { uint keySymX = keySyms[ iKeySym ]; xcb_keycode_t *keyCodes = xcb_key_symbols_get_keycode(symbols.data(), keySymX); if (!keyCodes) { continue; } - xcb_keycode_t keyCodeX = keyCodes[0]; + + int j = 0; + while (keyCodes[j] != XCB_NO_SYMBOL) { + const xcb_keycode_t keyCodeX = keyCodes[j++]; + int i = keyCodeX / 8; + char mask = 1 << (keyCodeX - (i * 8)); + + if (i < 0 || i >= 32) { + continue; + } + + qCDebug(KWIN_TABBOX) << iKeySym << ": keySymX=0x" << QString::number(keySymX, 16) + << " i=" << i << " mask=0x" << QString::number(mask, 16) + << " keymap[i]=0x" << QString::number(keymap[i], 16); + + if (keymap[i] & mask) { + depressed = true; + break; + } + } + free(keyCodes); - if (keyCodeX == XCB_NO_SYMBOL) { - continue; - } - int i = keyCodeX / 8; - char mask = 1 << (keyCodeX - (i * 8)); - - // Abort if bad index value, - if (i < 0 || i >= 32) - return false; - - qCDebug(KWIN_TABBOX) << iKeySym << ": keySymX=0x" << QString::number(keySymX, 16) - << " i=" << i << " mask=0x" << QString::number(mask, 16) - << " keymap[i]=0x" << QString::number(keymap[i], 16); - - // If ALL keys passed need to be depressed, - if (bAll) { - if ((keymap[i] & mask) == 0) - return false; - } else { - // If we are looking for ANY key press, and this key is depressed, - if (keymap[i] & mask) - return true; - } } - // If we were looking for ANY key press, then none was found, return false, - // If we were looking for ALL key presses, then all were found, return true. - return bAll; + return depressed; } static bool areModKeysDepressedX11(const QKeySequence &seq) @@ -999,7 +993,7 @@ static bool areModKeysDepressedX11(const QKeySequence &seq) rgKeySyms[nKeySyms++] = XK_Meta_R; } - return areKeySymXsDepressed(false, rgKeySyms, nKeySyms); + return areKeySymXsDepressed(rgKeySyms, nKeySyms); } static bool areModKeysDepressedWayland(const QKeySequence &seq)