Skip to content

Commit

Permalink
Don't use dlsym with XRandr
Browse files Browse the repository at this point in the history
Since tdesktop links to XRandr statically, this has no sense
  • Loading branch information
ilya-fedin authored and john-preston committed Jun 27, 2021
1 parent f03ef05 commit 91d836d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
37 changes: 13 additions & 24 deletions src/modules/desktop_capture/linux/screen_capturer_x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <X11/extensions/Xdamage.h>
#include <X11/extensions/Xfixes.h>
#include <X11/extensions/damagewire.h>
#include <dlfcn.h>
#include <stdint.h>
#include <string.h>

Expand Down Expand Up @@ -155,26 +154,16 @@ void ScreenCapturerX11::InitXrandr() {
if (XRRQueryExtension(display(), &randr_event_base_, &error_base_ignored) &&
XRRQueryVersion(display(), &major_version, &minor_version)) {
if (major_version > 1 || (major_version == 1 && minor_version >= 5)) {
// Dynamically link XRRGetMonitors and XRRFreeMonitors as a workaround
// to avoid a dependency issue with Debian 8.
get_monitors_ = reinterpret_cast<get_monitors_func>(
dlsym(RTLD_DEFAULT, "XRRGetMonitors"));
free_monitors_ = reinterpret_cast<free_monitors_func>(
dlsym(RTLD_DEFAULT, "XRRFreeMonitors"));
if (get_monitors_ && free_monitors_) {
use_randr_ = true;
RTC_LOG(LS_INFO) << "Using XRandR extension v" << major_version << '.'
<< minor_version << '.';
monitors_ =
get_monitors_(display(), root_window_, true, &num_monitors_);

// Register for screen change notifications
XRRSelectInput(display(), root_window_, RRScreenChangeNotifyMask);
options_.x_display()->AddEventHandler(
randr_event_base_ + RRScreenChangeNotify, this);
} else {
RTC_LOG(LS_ERROR) << "Unable to link XRandR monitor functions.";
}
use_randr_ = true;
RTC_LOG(LS_INFO) << "Using XRandR extension v" << major_version << '.'
<< minor_version << '.';
monitors_ =
XRRGetMonitors(display(), root_window_, true, &num_monitors_);

// Register for screen change notifications
XRRSelectInput(display(), root_window_, RRScreenChangeNotifyMask);
options_.x_display()->AddEventHandler(
randr_event_base_ + RRScreenChangeNotify, this);
} else {
RTC_LOG(LS_ERROR) << "XRandR entension is older than v1.5.";
}
Expand All @@ -186,11 +175,11 @@ void ScreenCapturerX11::InitXrandr() {
RTC_NO_SANITIZE("cfi-icall")
void ScreenCapturerX11::UpdateMonitors() {
if (monitors_) {
free_monitors_(monitors_);
XRRFreeMonitors(monitors_);
monitors_ = nullptr;
}

monitors_ = get_monitors_(display(), root_window_, true, &num_monitors_);
monitors_ = XRRGetMonitors(display(), root_window_, true, &num_monitors_);

if (selected_monitor_name_) {
if (selected_monitor_name_ == static_cast<Atom>(kFullDesktopScreenId)) {
Expand Down Expand Up @@ -439,7 +428,7 @@ void ScreenCapturerX11::SynchronizeFrame() {
RTC_NO_SANITIZE("cfi-icall")
void ScreenCapturerX11::DeinitXlib() {
if (monitors_) {
free_monitors_(monitors_);
XRRFreeMonitors(monitors_);
monitors_ = nullptr;
}

Expand Down
4 changes: 0 additions & 4 deletions src/modules/desktop_capture/linux/screen_capturer_x11.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ class ScreenCapturerX11 : public DesktopCapturer,
// selected_monitor_rect_ should be updated as well.
// Setting it to kFullDesktopScreenId here might be misleading.
Atom selected_monitor_name_ = 0;
typedef XRRMonitorInfo* (*get_monitors_func)(Display*, Window, Bool, int*);
typedef void (*free_monitors_func)(XRRMonitorInfo*);
get_monitors_func get_monitors_ = nullptr;
free_monitors_func free_monitors_ = nullptr;

// XFixes.
bool has_xfixes_ = false;
Expand Down

0 comments on commit 91d836d

Please sign in to comment.