Changeset View
Changeset View
Standalone View
Standalone View
kcms/cursortheme/xcursor/xcursortheme.cpp
Show All 15 Lines | |||||
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | * Boston, MA 02110-1301, USA. | 17 | * Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include <KLocalizedString> | 20 | #include <KLocalizedString> | ||
21 | #include <KConfig> | 21 | #include <KConfig> | ||
22 | #include <KConfigGroup> | 22 | #include <KConfigGroup> | ||
23 | 23 | | |||
24 | #include <QGuiApplication> | | |||
25 | #include <QScreen> | | |||
26 | #include <QCursor> | 24 | #include <QCursor> | ||
27 | #include <QImage> | 25 | #include <QImage> | ||
28 | #include <QDir> | 26 | #include <QDir> | ||
29 | #include <QX11Info> | 27 | #include <QX11Info> | ||
30 | 28 | | |||
31 | #include <X11/Xlib.h> | 29 | #include <X11/Xlib.h> | ||
32 | #include <X11/Xcursor/Xcursor.h> | 30 | #include <X11/Xcursor/Xcursor.h> | ||
33 | 31 | | |||
34 | #include <KWindowSystem/fixx11h.h> | | |||
35 | #include "xcursortheme.h" | 32 | #include "xcursortheme.h" | ||
36 | 33 | | |||
37 | 34 | | |||
38 | // Static variable holding alternative names for some cursors | 35 | // Static variable holding alternative names for some cursors | ||
39 | QHash<QString, QString> XCursorTheme::alternatives; | 36 | QHash<QString, QString> XCursorTheme::alternatives; | ||
40 | 37 | | |||
41 | XCursorTheme::XCursorTheme(const QDir &themeDir) | 38 | XCursorTheme::XCursorTheme(const QDir &themeDir) | ||
42 | : CursorTheme(themeDir.dirName()) | 39 | : CursorTheme(themeDir.dirName()) | ||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Line(s) | |||||
147 | { | 144 | { | ||
148 | QByteArray cursorName = QFile::encodeName(image); | 145 | QByteArray cursorName = QFile::encodeName(image); | ||
149 | QByteArray themeName = QFile::encodeName(name()); | 146 | QByteArray themeName = QFile::encodeName(name()); | ||
150 | 147 | | |||
151 | return XcursorLibraryLoadImages(cursorName, themeName, size); | 148 | return XcursorLibraryLoadImages(cursorName, themeName, size); | ||
152 | } | 149 | } | ||
153 | 150 | | |||
154 | 151 | | |||
155 | int XCursorTheme::autodetectCursorSize() const | 152 | int XCursorTheme::defaultCursorSize() const | ||
156 | { | 153 | { | ||
157 | if (!QX11Info::isPlatformX11()) { | | |||
158 | if (QScreen *s = QGuiApplication::primaryScreen()) { | | |||
159 | return s->logicalDotsPerInchY() * 16 / 72; | | |||
160 | } | | |||
161 | // some default value | | |||
162 | return 16; | | |||
163 | } | | |||
164 | /* This code is basically borrowed from display.c of the XCursor library | 154 | /* This code is basically borrowed from display.c of the XCursor library | ||
165 | We can't use "int XcursorGetDefaultSize(Display *dpy)" because if | 155 | We can't use "int XcursorGetDefaultSize(Display *dpy)" because if | ||
166 | previously the cursor size was set to a custom value, it would return | 156 | previously the cursor size was set to a custom value, it would return | ||
167 | this custom value. */ | 157 | this custom value. */ | ||
168 | int size = 0; | 158 | int size = 0; | ||
169 | int dpi = 0; | 159 | int dpi = 0; | ||
170 | Display *dpy = QX11Info::display(); | 160 | Display *dpy = QX11Info::display(); | ||
171 | // The string "v" is owned and will be destroyed by Xlib | 161 | // The string "v" is owned and will be destroyed by Xlib | ||
Show All 15 Lines | 168 | { | |||
187 | size = dim / 48; | 177 | size = dim / 48; | ||
188 | } | 178 | } | ||
189 | return size; | 179 | return size; | ||
190 | } | 180 | } | ||
191 | 181 | | |||
192 | qulonglong XCursorTheme::loadCursor(const QString &name, int size) const | 182 | qulonglong XCursorTheme::loadCursor(const QString &name, int size) const | ||
193 | { | 183 | { | ||
194 | if (size <= 0) | 184 | if (size <= 0) | ||
195 | size = autodetectCursorSize(); | 185 | size = defaultCursorSize(); | ||
196 | 186 | | |||
197 | // Load the cursor images | 187 | // Load the cursor images | ||
198 | XcursorImages *images = xcLoadImages(name, size); | 188 | XcursorImages *images = xcLoadImages(name, size); | ||
199 | 189 | | |||
200 | if (!images) | 190 | if (!images) | ||
201 | images = xcLoadImages(findAlternative(name), size); | 191 | images = xcLoadImages(findAlternative(name), size); | ||
202 | 192 | | |||
203 | if (!images) | 193 | if (!images) | ||
204 | return None; | 194 | return None; | ||
205 | 195 | | |||
206 | // Create the cursor | 196 | // Create the cursor | ||
207 | Cursor handle = XcursorImagesLoadCursor(QX11Info::display(), images); | 197 | Cursor handle = XcursorImagesLoadCursor(QX11Info::display(), images); | ||
208 | XcursorImagesDestroy(images); | 198 | XcursorImagesDestroy(images); | ||
209 | 199 | | |||
210 | setCursorName(handle, name); | 200 | setCursorName(handle, name); | ||
211 | return handle; | 201 | return handle; | ||
212 | } | 202 | } | ||
213 | 203 | | |||
214 | 204 | | |||
215 | QImage XCursorTheme::loadImage(const QString &name, int size) const | 205 | QImage XCursorTheme::loadImage(const QString &name, int size) const | ||
216 | { | 206 | { | ||
217 | if (size <= 0) | 207 | if (size <= 0) | ||
218 | size = autodetectCursorSize(); | 208 | size = defaultCursorSize(); | ||
219 | 209 | | |||
220 | // Load the image | 210 | // Load the image | ||
221 | XcursorImage *xcimage = xcLoadImage(name, size); | 211 | XcursorImage *xcimage = xcLoadImage(name, size); | ||
222 | 212 | | |||
223 | if (!xcimage) | 213 | if (!xcimage) | ||
224 | xcimage = xcLoadImage(findAlternative(name), size); | 214 | xcimage = xcLoadImage(findAlternative(name), size); | ||
225 | 215 | | |||
226 | if (!xcimage) { | 216 | if (!xcimage) { | ||
Show All 13 Lines |