From: Mikko Rasa Date: Sun, 27 Nov 2022 14:18:31 +0000 (+0200) Subject: Avoid using std::list X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=72ed51af9656b47a331cf29565a0bdfd35f19847;p=libs%2Fgui.git Avoid using std::list --- diff --git a/source/graphics/android/display_platform.h b/source/graphics/android/display_platform.h index e07cb2e..6795f38 100644 --- a/source/graphics/android/display_platform.h +++ b/source/graphics/android/display_platform.h @@ -1,6 +1,7 @@ #ifndef MSP_GRAPHICS_DISPLAY_PLATFORM_H_ #define MSP_GRAPHICS_DISPLAY_PLATFORM_H_ +#include #include #include #include @@ -15,7 +16,7 @@ typedef void *DisplayHandle; struct PlatformDisplayPrivate: public sigc::trackable { AInputQueue *input_queue = nullptr; - std::list events; + std::deque events; Mutex event_mutex; WindowHandle native_window = nullptr; Mutex window_mutex; diff --git a/source/graphics/display.h b/source/graphics/display.h index f78aaff..23ab571 100644 --- a/source/graphics/display.h +++ b/source/graphics/display.h @@ -1,9 +1,9 @@ #ifndef MSP_GRAPHICS_DISPLAY_H_ #define MSP_GRAPHICS_DISPLAY_H_ -#include #include #include +#include #include #include "errordialog.h" #include "monitor.h" @@ -23,9 +23,9 @@ public: sigc::signal signal_lost_focus; private: - std::list monitors; + std::vector monitors; Monitor *primary_monitor = nullptr; - std::list modes; + std::vector modes; Private *priv = nullptr; ErrorDialog *err_dialog = nullptr; Window *focus_window = nullptr; @@ -39,8 +39,8 @@ public: void add_window(Window &); void remove_window(Window &); - const std::list &get_monitors() const { return monitors; } - const std::list &get_modes() const { return modes; } + const std::vector &get_monitors() const { return monitors; } + const std::vector &get_modes() const { return modes; } const VideoMode &get_desktop_mode() const; void set_mode(const VideoMode &, bool = false); void restore_mode(); diff --git a/source/graphics/imageloader.cpp b/source/graphics/imageloader.cpp index a938340..6403366 100644 --- a/source/graphics/imageloader.cpp +++ b/source/graphics/imageloader.cpp @@ -1,4 +1,5 @@ #include "imageloader.h" +#include #include #include #include @@ -57,7 +58,7 @@ ImageLoader *ImageLoader::open_io(IO::Seekable &io) if(registry.changed) { registry.changed = false; - registry.loaders.sort(signature_size_compare); + sort(registry.loaders, signature_size_compare); } if(registry.loaders.empty()) diff --git a/source/graphics/imageloader.h b/source/graphics/imageloader.h index ca69459..53c9e7b 100644 --- a/source/graphics/imageloader.h +++ b/source/graphics/imageloader.h @@ -53,7 +53,7 @@ protected: struct Registry { - std::list loaders; + std::vector loaders; bool changed = false; ~Registry(); diff --git a/source/graphics/monitor.h b/source/graphics/monitor.h index b74cea8..8d86d4e 100644 --- a/source/graphics/monitor.h +++ b/source/graphics/monitor.h @@ -1,8 +1,8 @@ #ifndef MSP_GRAPHICS_MONITOR_H_ #define MSP_GRAPHICS_MONITOR_H_ -#include #include +#include #include "videomode.h" namespace Msp { @@ -20,7 +20,7 @@ struct Monitor unsigned index = 0; std::string name; - std::list video_modes; + std::vector video_modes; Settings desktop_settings; Settings current_settings; const Monitor *next_left = nullptr; diff --git a/source/graphics/windows/display.cpp b/source/graphics/windows/display.cpp index bea18a6..09ca2e9 100644 --- a/source/graphics/windows/display.cpp +++ b/source/graphics/windows/display.cpp @@ -1,5 +1,6 @@ #include "display.h" #include "display_private.h" +#include #include using namespace std; @@ -12,6 +13,9 @@ Display::Display(const string &): { static ErrorDialog err_dlg(nullptr); + int primary_index = -1; + vector mode_monitor_indices; + vector desktop_mode_indices; for(unsigned i=0;; ++i) { DISPLAY_DEVICE adapter_dev; @@ -29,33 +33,54 @@ Display::Display(const string &): priv->monitors.push_back(adapter_dev.DeviceName); if(adapter_dev.StateFlags&DISPLAY_DEVICE_PRIMARY_DEVICE) - primary_monitor = &monitor; + primary_index = i; DEVMODE current; bool have_current = EnumDisplaySettings(adapter_dev.DeviceName, ENUM_CURRENT_SETTINGS, ¤t); + unsigned first_mode = modes.size(); + int desktop_mode_index = -1; for(unsigned j=0;; ++j) { DEVMODE info; if(!EnumDisplaySettings(adapter_dev.DeviceName, j, &info)) break; + if(any_of(modes.begin()+first_mode, modes.end(), [&info](const VideoMode &m){ + return (m.width==info.dmPelsWidth && m.height==info.dmPelsHeight && m.rate==info.dmDisplayFrequency); + })) + continue; + VideoMode mode(info.dmPelsWidth, info.dmPelsHeight); mode.index = modes.size(); - mode.monitor = &monitor; mode.rate = info.dmDisplayFrequency; - if(find_mode(mode)) - continue; modes.push_back(mode); - monitor.video_modes.push_back(&modes.back()); + mode_monitor_indices.push_back(monitor.index); if(have_current && info.dmPelsWidth==current.dmPelsWidth && info.dmPelsHeight==current.dmPelsHeight && info.dmDisplayFrequency==current.dmDisplayFrequency) - monitor.desktop_settings.mode = &modes.back(); + desktop_mode_index = mode.index; } + desktop_mode_indices.push_back(desktop_mode_index); + } - monitor.current_settings = monitor.desktop_settings; + for(unsigned i=0; i=0) + monitors[i].desktop_settings.mode = &modes[j]; + monitors[i].current_settings = monitors[i].desktop_settings; } + + for(unsigned i=0; i=0) + primary_monitor = &monitors[primary_index]; } Display::~Display() diff --git a/source/graphics/x11/display.cpp b/source/graphics/x11/display.cpp index fd60485..544f958 100644 --- a/source/graphics/x11/display.cpp +++ b/source/graphics/x11/display.cpp @@ -5,6 +5,7 @@ #ifdef WITH_XRANDR #include #endif +#include #include #include #include @@ -116,6 +117,9 @@ Display::Display(const string &disp_name): for(int i=0; inmode; ++i) modes_by_id[res->modes[i].id] = &res->modes[i]; + int primary_index = -1; + vector mode_monitor_indices; + vector desktop_mode_indices; for(int i=0; inoutput; ++i) { XRROutputInfo *output = XRRGetOutputInfo(priv->display, res, res->outputs[i]); @@ -159,8 +163,10 @@ Display::Display(const string &disp_name): } if(res->outputs[i]==primary) - primary_monitor = &monitor; + primary_index = monitor.index; + unsigned first_mode = modes.size(); + int desktop_mode_index = -1; for(int j=0; jnmode; ++j) { auto k = modes_by_id.find(output->modes[j]); @@ -168,23 +174,25 @@ Display::Display(const string &disp_name): continue; XRRModeInfo *info = k->second; + float rate = static_cast(info->dotClock)/(info->hTotal*info->vTotal); + + if(any_of(modes.begin()+first_mode, modes.end(), [&info, rate](const VideoMode &m){ + return (m.width==info->width && m.height==info->height && abs(m.rate-rate)<0.01f); + })) + continue; VideoMode mode(info->width, info->height); mode.index = modes.size(); - mode.monitor = &monitor; - mode.rate = static_cast(info->dotClock)/(info->hTotal*info->vTotal); - if(find_mode(mode, 0.01f)) - continue; + mode.rate = rate; modes.push_back(mode); priv->modes.push_back(info->id); - monitor.video_modes.push_back(&modes.back()); + mode_monitor_indices.push_back(monitor.index); if(crtc && info->id==crtc->mode) - monitor.desktop_settings.mode = &modes.back(); + desktop_mode_index = mode.index; } - - monitor.current_settings = monitor.desktop_settings; + desktop_mode_indices.push_back(desktop_mode_index); XRRFreeOutputInfo(output); if(crtc) @@ -193,7 +201,23 @@ Display::Display(const string &disp_name): XRRFreeScreenResources(res); - monitors.sort(monitor_x_compare); + for(unsigned i=0; i=0) + monitors[i].desktop_settings.mode = &modes[j]; + monitors[i].current_settings = monitors[i].desktop_settings; + } + + sort(monitors, monitor_x_compare); + + for(unsigned i=0; ivideo_modes.push_back(&modes[i]); + } + Monitor *prev_enabled = nullptr; for(Monitor &m: monitors) if(m.desktop_settings.mode) @@ -204,6 +228,9 @@ Display::Display(const string &disp_name): prev_enabled = &m; } + if(primary_index>=0) + primary_monitor = &*find_member(monitors, static_cast(primary_index), &Monitor::index); + if(!primary_monitor || !primary_monitor->desktop_settings.mode) { // XRandR didn't give a sensible primary monitor. Try to guess one.