Commit ad63f7bc authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

[XProto] Obtain Xcursor path from libXcursor

Some distros (eg. Gentoo) use a non-default libXcursor path, so the
path (which was previously hardcoded) must now be obtained from
libXcursor.  This patch uses dlopen()/dlsym() to get the path when
available.

BUG=1127712
R=sky

Change-Id: Ib99dff0448c521c1a6cf8ad03bfe981572b9627c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2410305
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Auto-Submit: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807158}
parent e87c7992
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ui/base/x/x11_cursor_loader.h" #include "ui/base/x/x11_cursor_loader.h"
#include <dlfcn.h>
#include <limits> #include <limits>
#include <string> #include <string>
...@@ -13,6 +15,7 @@ ...@@ -13,6 +15,7 @@
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/no_destructor.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
...@@ -28,6 +31,10 @@ ...@@ -28,6 +31,10 @@
#include "ui/gfx/x/connection.h" #include "ui/gfx/x/connection.h"
#include "ui/gfx/x/xproto.h" #include "ui/gfx/x/xproto.h"
extern "C" {
const char* XcursorLibraryPath(void);
}
namespace ui { namespace ui {
namespace { namespace {
...@@ -120,14 +127,41 @@ std::string GetEnv(const std::string& var) { ...@@ -120,14 +127,41 @@ std::string GetEnv(const std::string& var) {
return value; return value;
} }
std::string CursorPath() { std::string CursorPathFromLibXcursor() {
struct DlCloser {
void operator()(void* ptr) const { dlclose(ptr); }
};
std::unique_ptr<void, DlCloser> lib(dlopen("libXcursor.so.1", RTLD_LAZY));
if (!lib)
return "";
if (auto* sym = reinterpret_cast<decltype(&XcursorLibraryPath)>(
dlsym(lib.get(), "XcursorLibraryPath"))) {
if (const char* path = sym())
return path;
}
return "";
}
std::string CursorPathImpl() {
constexpr const char kDefaultPath[] = constexpr const char kDefaultPath[] =
"~/.local/share/icons:~/.icons:/usr/share/icons:/usr/share/pixmaps:" "~/.local/share/icons:~/.icons:/usr/share/icons:/usr/share/pixmaps:"
"/usr/X11R6/lib/X11/icons"; "/usr/X11R6/lib/X11/icons";
auto libxcursor_path = CursorPathFromLibXcursor();
if (!libxcursor_path.empty())
return libxcursor_path;
std::string path = GetEnv("XCURSOR_PATH"); std::string path = GetEnv("XCURSOR_PATH");
return path.empty() ? kDefaultPath : path; return path.empty() ? kDefaultPath : path;
} }
const std::string& CursorPath() {
static base::NoDestructor<std::string> path(CursorPathImpl());
return *path;
}
x11::Render::PictFormat GetRenderARGBFormat( x11::Render::PictFormat GetRenderARGBFormat(
const x11::Render::QueryPictFormatsReply& formats) { const x11::Render::QueryPictFormatsReply& formats) {
for (const auto& format : formats.formats) { for (const auto& format : formats.formats) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment