Use atomic fetch-and-add for unique window classes

This commit is contained in:
Robbert van der Helm
2020-12-31 14:12:14 +01:00
parent c3c0f96585
commit fa0753f520
4 changed files with 12 additions and 21 deletions
+9 -4
View File
@@ -45,6 +45,12 @@ constexpr uint32_t xembed_focus_in_msg = 4;
constexpr uint32_t xembed_focus_first = 1;
/**
* Used to generate a globally unique identifier for a window class. This is
* needed because every window's window class name should be unique.
*/
std::atomic_size_t window_class_id{};
/**
* Find the topmost window (i.e. the window before the root window in the window
* tree) starting from a certain window.
@@ -94,13 +100,12 @@ WindowClass::~WindowClass() {
UnregisterClass(reinterpret_cast<LPCSTR>(atom), GetModuleHandle(nullptr));
}
Editor::Editor(const Configuration& config,
const std::string& window_class_name,
const size_t parent_window_handle)
Editor::Editor(const Configuration& config, const size_t parent_window_handle)
: use_xembed(config.editor_xembed),
x11_connection(xcb_connect(nullptr, nullptr), xcb_disconnect),
client_area(get_maximum_screen_dimensions(*x11_connection)),
window_class(window_class_name),
window_class("yabridge plugin " +
std::to_string(window_class_id.fetch_add(1))),
// Create a window without any decoratiosn for easy embedding. The
// combination of `WS_EX_TOOLWINDOW` and `WS_POPUP` causes the window to
// be drawn without any decorations (making resizes behave as you'd