Skip to content

Commit

Permalink
Don't fight the window manager
Browse files Browse the repository at this point in the history
This code assumed that the user had exclusive control over the
size and position of all windows. While this is generally true of most
window managers, for users with a tiling window manager, this meant
that the code was constantly fighting the window manager for control,
causing the window to flash back and forth between multiple places.

The fix is to not assume that m_is_resized == (window->size !=
m_prev_size), and instead only try to set the size once when
m_is_resized is set to true, and the same for m_is_repositioned and positions.
  • Loading branch information
HazardousPeach committed Oct 11, 2024
1 parent 3f418e1 commit 7ecd7c1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/gui/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,20 @@ namespace Toolbox::UI {

// Establish window constraints
if (window) {
if (window->Size != m_prev_size) {
if (window->Size != m_prev_size && m_is_resized) {
if (m_next_size.x >= 0.0f && m_next_size.y >= 0.0f) {
GUIApplication::instance().dispatchEvent<WindowEvent, true>(
getUUID(), EVENT_WINDOW_RESIZE, window->Size);
}
ImGui::SetWindowSize(window, m_prev_size, ImGuiCond_Always);
m_is_resized = false;
}

if (window->Pos != m_prev_pos) {
if (window->Pos != m_prev_pos && m_is_repositioned) {
GUIApplication::instance().dispatchEvent<WindowEvent, true>(
getUUID(), EVENT_WINDOW_MOVE, window->Pos);
ImGui::SetWindowPos(window, m_prev_pos, ImGuiCond_Always);
m_is_repositioned = false;
}
}

Expand Down

1 comment on commit 7ecd7c1

@JoshuaMKW
Copy link
Owner

@JoshuaMKW JoshuaMKW commented on 7ecd7c1 Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem I see here is that m_is_resized and m_is_repositioned are never actually set elsewhere in code so in order to make this change useful we need to define those cases to properly track resizes and repositions that get dispatched as events.

Please sign in to comment.