From b5e7078d93792171dc54b8aafa2751bec1b18b38 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Mon, 24 Jun 2019 17:37:05 +0200
Subject: [PATCH] fix(monitor): Remove realloc from get_monitors
Premature optimization that tried to cache monitors but the cache did
not take into account the parameter values.
The call `get_monitors(..., ..., false, true);` would get all connected
and unconncected monitors a subsequent call
`get_monitors(..., ..., true, false);` would get back the same list of
monitors even though it requested only connected monitors.
Additionally `get_monitors` is never called periodically so the
optimization really didn't help much.
---
include/x11/extensions/randr.hpp | 2 +-
src/components/screen.cpp | 2 +-
src/x11/extensions/randr.cpp | 10 ++--------
3 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/include/x11/extensions/randr.hpp b/include/x11/extensions/randr.hpp
index 29954159..1c8d1185 100644
--- a/include/x11/extensions/randr.hpp
+++ b/include/x11/extensions/randr.hpp
@@ -51,7 +51,7 @@ namespace randr_util {
monitor_t make_monitor(xcb_randr_output_t randr, string name, unsigned short int w, unsigned short int h, short int x, short int y,
bool primary);
- vector get_monitors(connection& conn, xcb_window_t root, bool connected_only = false, bool realloc = false);
+ vector get_monitors(connection& conn, xcb_window_t root, bool connected_only = false);
monitor_t match_monitor(vector monitors, const string& name, bool exact_match);
void get_backlight_range(connection& conn, const monitor_t& mon, backlight_values& dst);
diff --git a/src/components/screen.cpp b/src/components/screen.cpp
index 51e19101..a943ec98 100644
--- a/src/components/screen.cpp
+++ b/src/components/screen.cpp
@@ -101,7 +101,7 @@ void screen::handle(const evt::randr_screen_change_notify& evt) {
if (screen->width_in_pixels != m_size.w || screen->height_in_pixels != m_size.h) {
changed = true;
} else {
- auto monitors = randr_util::get_monitors(m_connection, m_root, true, true);
+ auto monitors = randr_util::get_monitors(m_connection, m_root, true);
for (size_t n = 0; n < monitors.size(); n++) {
if (n < m_monitors.size() && monitors[n]->output != m_monitors[n]->output) {
changed = true;
diff --git a/src/x11/extensions/randr.cpp b/src/x11/extensions/randr.cpp
index 36baedb5..cd195c27 100644
--- a/src/x11/extensions/randr.cpp
+++ b/src/x11/extensions/randr.cpp
@@ -80,14 +80,8 @@ namespace randr_util {
/**
* Create a list of all available randr outputs
*/
- vector get_monitors(connection& conn, xcb_window_t root, bool connected_only, bool realloc) {
- static vector monitors;
-
- if (realloc) {
- monitors.clear();
- } else if (!monitors.empty()) {
- return monitors;
- }
+ vector get_monitors(connection& conn, xcb_window_t root, bool connected_only) {
+ vector monitors;
#if WITH_XRANDR_MONITORS
if (check_monitor_support()) {