mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-13 10:05:57 +01:00
xcursor stuff
This commit is contained in:
parent
590e706cde
commit
03eb7e37da
3 changed files with 42 additions and 48 deletions
|
@ -4,6 +4,7 @@
|
|||
#include "PointerManager.hpp"
|
||||
#include "../xwayland/XWayland.hpp"
|
||||
#include <cstring>
|
||||
#include "../helpers/CursorShapes.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <X11/Xcursor/Xcursor.h>
|
||||
|
@ -139,9 +140,14 @@ void CCursorManager::setXCursor(const std::string& name) {
|
|||
return;
|
||||
}
|
||||
|
||||
m_vCursorBuffers.emplace_back(makeShared<CCursorBuffer>(xcursor.defaultCursor->pixels.data(), xcursor.defaultCursor->size, xcursor.defaultCursor->hotspot));
|
||||
auto& icon = xcursor.defaultCursor;
|
||||
// try to get an icon we know if we have one
|
||||
if (xcursor.cursors.contains(name))
|
||||
icon = xcursor.cursors.at(name);
|
||||
|
||||
g_pPointerManager->setCursorBuffer(getCursorBuffer(), xcursor.defaultCursor->hotspot / scale, scale);
|
||||
m_vCursorBuffers.emplace_back(makeShared<CCursorBuffer>(icon->pixels.data(), icon->size, icon->hotspot));
|
||||
|
||||
g_pPointerManager->setCursorBuffer(getCursorBuffer(), icon->hotspot / scale, scale);
|
||||
if (m_vCursorBuffers.size() > 1)
|
||||
dropBufferRef(m_vCursorBuffers.at(0).get());
|
||||
|
||||
|
@ -300,8 +306,12 @@ bool CCursorManager::changeTheme(const std::string& name, const int size) {
|
|||
}
|
||||
|
||||
void CCursorManager::SXCursorManager::loadTheme(const std::string& name, int size) {
|
||||
themeLoaded = false;
|
||||
themeName = name.empty() ? "default" : name;
|
||||
if (lastLoadSize == size && themeName == name)
|
||||
return;
|
||||
|
||||
lastLoadSize = size;
|
||||
themeLoaded = false;
|
||||
themeName = name.empty() ? "default" : name;
|
||||
|
||||
auto img = XcursorShapeLoadImage(1, name.c_str(), size);
|
||||
|
||||
|
@ -323,4 +333,25 @@ void CCursorManager::SXCursorManager::loadTheme(const std::string& name, int siz
|
|||
std::memcpy(defaultCursor->pixels.data(), img->pixels, img->width * img->height);
|
||||
|
||||
themeLoaded = true;
|
||||
|
||||
// gather as many shapes as we can find.
|
||||
cursors.clear();
|
||||
|
||||
for (auto& shape : CURSOR_SHAPE_NAMES) {
|
||||
auto xImage = XcursorShapeLoadImage(1, shape, size);
|
||||
|
||||
if (!xImage) {
|
||||
Debug::log(LOG, "XCursor failed to find a shape with name {}, skipping", shape);
|
||||
continue;
|
||||
}
|
||||
|
||||
auto xcursor = makeShared<SXCursor>();
|
||||
xcursor->size = {(int)xImage->width, (int)xImage->height};
|
||||
xcursor->hotspot = {(int)xImage->xhot, (int)xImage->yhot};
|
||||
|
||||
xcursor->pixels.resize(xImage->width * xImage->height);
|
||||
std::memcpy(xcursor->pixels.data(), xImage->pixels, xImage->width * xImage->height);
|
||||
|
||||
cursors.emplace(std::string{shape}, xcursor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,11 +81,14 @@ class CCursorManager {
|
|||
};
|
||||
|
||||
struct SXCursorManager {
|
||||
void loadTheme(const std::string& name, int size);
|
||||
void loadTheme(const std::string& name, int size);
|
||||
|
||||
bool themeLoaded = false;
|
||||
std::string themeName = "";
|
||||
SP<SXCursor> defaultCursor;
|
||||
int lastLoadSize = 0;
|
||||
|
||||
bool themeLoaded = false;
|
||||
std::string themeName = "";
|
||||
SP<SXCursor> defaultCursor;
|
||||
std::unordered_map<std::string, SP<SXCursor>> cursors;
|
||||
} xcursor;
|
||||
};
|
||||
|
||||
|
|
|
@ -3,46 +3,6 @@
|
|||
|
||||
#define LOGM PROTO::cursorShape->protoLog
|
||||
|
||||
// clang-format off
|
||||
constexpr const char* SHAPE_NAMES[] = {
|
||||
"invalid",
|
||||
"default",
|
||||
"context-menu",
|
||||
"help",
|
||||
"pointer",
|
||||
"progress",
|
||||
"wait",
|
||||
"cell",
|
||||
"crosshair",
|
||||
"text",
|
||||
"vertical-text",
|
||||
"alias",
|
||||
"copy",
|
||||
"move",
|
||||
"no-drop",
|
||||
"not-allowed",
|
||||
"grab",
|
||||
"grabbing",
|
||||
"e-resize",
|
||||
"n-resize",
|
||||
"ne-resize",
|
||||
"nw-resize",
|
||||
"s-resize",
|
||||
"se-resize",
|
||||
"sw-resize",
|
||||
"w-resize",
|
||||
"ew-resize",
|
||||
"ns-resize",
|
||||
"nesw-resize",
|
||||
"nwse-resize",
|
||||
"col-resize",
|
||||
"row-resize",
|
||||
"all-scroll",
|
||||
"zoom-in",
|
||||
"zoom-out",
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
CCursorShapeProtocol::CCursorShapeProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
|
||||
;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue