From 0faf2fbcf8645b8affb9501e353dcdd61ad10644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 28 Jan 2015 14:49:27 +0100 Subject: [PATCH] Use xcb_cursor library instead of Xlib based one in Cursor Straight forward port from XLib based XCursor library to the xcb variant which is considerably new. The xcb variant only allows to create xcb_cursor_t for the default theme and size. Which suits the needs in Cursor quite well, but means it's not a replacement for the usage in zoom effect. REVIEW: 122290 --- CMakeLists.txt | 13 ++++++++++++- config-kwin.h.cmake | 1 + cursor.cpp | 23 ++++++++++++++--------- kcmkwin/kwinrules/CMakeLists.txt | 5 ++++- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f3da09e41c..732a7b68e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,6 +173,7 @@ find_package(XCB GLX OPTIONAL_COMPONENTS ICCCM + CURSOR ) set_package_properties(XCB PROPERTIES TYPE REQUIRED) @@ -181,6 +182,7 @@ if (XCB_ICCCM_VERSION VERSION_LESS "0.4") set(XCB_ICCCM_FOUND FALSE) endif() add_feature_info("XCB-ICCCM" XCB_ICCCM_FOUND "Required for building test applications for KWin") +add_feature_info("XCB-CURSOR" XCB_CURSOR_FOUND "Required for XCursor support") feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) @@ -260,6 +262,12 @@ else() set(HAVE_WAYLAND_EGL FALSE) endif() +if(XCB_CURSOR_FOUND) + set(HAVE_XCB_CURSOR ${XCB_CURSOR_FOUND}) +else() + set(HAVE_XCB_CURSOR FALSE) +endif() + include(CheckIncludeFiles) check_include_files(unistd.h HAVE_UNISTD_H) check_include_files(malloc.h HAVE_MALLOC_H) @@ -464,7 +472,6 @@ set(kwin_KDE_LIBS set(kwin_XLIB_LIBS ${X11_X11_LIB} ${X11_Xext_LIB} - ${X11_Xcursor_LIB} ${X11_ICE_LIB} ${X11_SM_LIB} ) @@ -500,6 +507,10 @@ if(KWIN_BUILD_ACTIVITIES) set(kwin_KDE_LIBS ${kwin_KDE_LIBS} KF5::Activities) endif() +if(HAVE_XCB_CURSOR) + set(kwin_XCB_LIBS ${kwin_XCB_LIBS} XCB::CURSOR) +endif() + set(kwinLibs ${kwin_OWN_LIBS} ${kwin_QT_LIBS} diff --git a/config-kwin.h.cmake b/config-kwin.h.cmake index 98cf1da568..cf6cac2aea 100644 --- a/config-kwin.h.cmake +++ b/config-kwin.h.cmake @@ -13,6 +13,7 @@ #cmakedefine01 HAVE_WAYLAND_EGL #cmakedefine01 HAVE_XKB #cmakedefine01 HAVE_INPUT +#cmakedefine01 HAVE_XCB_CURSOR /* Define to 1 if you have the header file. */ #cmakedefine HAVE_UNISTD_H 1 diff --git a/cursor.cpp b/cursor.cpp index 15caaa9a1d..bdd2126376 100644 --- a/cursor.cpp +++ b/cursor.cpp @@ -33,11 +33,11 @@ along with this program. If not, see . #include #include #include -// Xlib -#include -#include // xcb #include +#if HAVE_XCB_CURSOR +#include +#endif namespace KWin { @@ -353,15 +353,20 @@ xcb_cursor_t X11Cursor::createCursor(const QByteArray &name) if (name.isEmpty()) { return XCB_CURSOR_NONE; } - // XCursor is an XLib only lib - XcursorImage *ximg = XcursorLibraryLoadImage(name.constData(), themeName().toUtf8().constData(), themeSize()); - if (!ximg) { +#if HAVE_XCB_CURSOR + xcb_cursor_context_t *ctx; + if (xcb_cursor_context_new(connection(), defaultScreen(), &ctx) < 0) { return XCB_CURSOR_NONE; } - xcb_cursor_t cursor = XcursorImageLoadCursor(display(), ximg); - XcursorImageDestroy(ximg); - m_cursors.insert(name, cursor); + const xcb_cursor_t cursor = xcb_cursor_load_cursor(ctx, name.constData()); + if (cursor != XCB_CURSOR_NONE) { + m_cursors.insert(name, cursor); + } + xcb_cursor_context_free(ctx); return cursor; +#else + return XCB_CURSOR_NONE; +#endif } QByteArray Cursor::cursorName(Qt::CursorShape shape) const diff --git a/kcmkwin/kwinrules/CMakeLists.txt b/kcmkwin/kwinrules/CMakeLists.txt index 3f64dccb5e..9d004d6031 100644 --- a/kcmkwin/kwinrules/CMakeLists.txt +++ b/kcmkwin/kwinrules/CMakeLists.txt @@ -16,7 +16,6 @@ kf5_add_kdeinit_executable( kwin_rules_dialog ${kwin_rules_dialog_KDEINIT_SRCS}) set(kwin_kcm_rules_XCB_LIBS XCB::XCB XCB::XFIXES - ${X11_Xcursor_LIB} ) set(kcm_libs @@ -35,6 +34,10 @@ if(KWIN_BUILD_ACTIVITIES) set(kcm_libs ${kcm_libs} KF5::Activities) endif() +if(HAVE_XCB_CURSOR) + set(kwin_kcm_rules_XCB_LIBS ${kwin_kcm_rules_XCB_LIBS} XCB::CURSOR) +endif() + target_link_libraries(kdeinit_kwin_rules_dialog ${kcm_libs} ${kwin_kcm_rules_XCB_LIBS}) install(TARGETS kdeinit_kwin_rules_dialog ${INSTALL_TARGETS_DEFAULT_ARGS} )