File indexing completed on 2025-03-02 05:11:58

0001 /*
0002     SPDX-FileCopyrightText: 2021 Dan Leinir Turthra Jensen <admin@leinir.dk>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006 
0007 #include "config-X11.h"
0008 
0009 #include "cursortheme.h"
0010 
0011 #include "../../krdb/krdb.h"
0012 
0013 #include <QFile>
0014 #include <private/qtx11extras_p.h>
0015 
0016 #include <X11/Xcursor/Xcursor.h>
0017 #ifdef HAVE_XFIXES
0018 #include <X11/extensions/Xfixes.h>
0019 #endif
0020 
0021 bool applyTheme(const CursorTheme *theme, const int size)
0022 {
0023     // Require the Xcursor version that shipped with X11R6.9 or greater, since
0024     // in previous versions the Xfixes code wasn't enabled due to a bug in the
0025     // build system (freedesktop bug #975).
0026 #if HAVE_XFIXES && XFIXES_MAJOR >= 2 && XCURSOR_LIB_VERSION >= 10105
0027     if (!theme) {
0028         return false;
0029     }
0030 
0031     // Update the Xcursor X resources
0032     runRdb(0);
0033 
0034     // Reload the standard cursors
0035     QStringList names;
0036 
0037     if (CursorTheme::haveXfixes()) {
0038         // Qt cursors
0039         names << "left_ptr"
0040               << "up_arrow"
0041               << "cross"
0042               << "wait"
0043               << "left_ptr_watch"
0044               << "ibeam"
0045               << "size_ver"
0046               << "size_hor"
0047               << "size_bdiag"
0048               << "size_fdiag"
0049               << "size_all"
0050               << "split_v"
0051               << "split_h"
0052               << "pointing_hand"
0053               << "openhand"
0054               << "closedhand"
0055               << "forbidden"
0056               << "whats_this"
0057               << "copy"
0058               << "move"
0059               << "link";
0060 
0061         // X core cursors
0062         names << "X_cursor"
0063               << "right_ptr"
0064               << "hand1"
0065               << "hand2"
0066               << "watch"
0067               << "xterm"
0068               << "crosshair"
0069               << "left_ptr_watch"
0070               << "center_ptr"
0071               << "sb_h_double_arrow"
0072               << "sb_v_double_arrow"
0073               << "fleur"
0074               << "top_left_corner"
0075               << "top_side"
0076               << "top_right_corner"
0077               << "right_side"
0078               << "bottom_right_corner"
0079               << "bottom_side"
0080               << "bottom_left_corner"
0081               << "left_side"
0082               << "question_arrow"
0083               << "pirate";
0084 
0085         foreach (const QString &name, names) {
0086             XFixesChangeCursorByName(QX11Info::display(), theme->loadCursor(name, size), QFile::encodeName(name));
0087         }
0088     }
0089 
0090     return true;
0091 #else
0092     Q_UNUSED(theme)
0093     Q_UNUSED(size)
0094     return false;
0095 #endif
0096 }