Skip to content

Commit

Permalink
Application window should remain within desktop bounds on initializat…
Browse files Browse the repository at this point in the history
…ion.
  • Loading branch information
indigodarkwolf committed Jan 25, 2024
1 parent c1bd3ad commit ab014be
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void display_video()
#endif
glBindTexture(GL_TEXTURE_2D, 0);

ImGui::SetCursorScreenPos(ImVec2(display_rect.x, display_rect.y));
ImGui::SetCursorScreenPos(ImVec2(display_rect.x, display_rect.y));
ImGui::BeginChild("display video", ImVec2(display_rect.z, display_rect.w), false, ImGuiWindowFlags_NoMove);
ImGui::Image((void *)(intptr_t)Video_framebuffer_texture_handle, ImVec2(display_rect.z, display_rect.w));
display_focused = ImGui::IsWindowFocused();
Expand Down Expand Up @@ -355,9 +355,42 @@ bool display_init()
}

// SDL_SetWindowTitle(Display_window, "Box16 Emulator for Commander X16");

if(Options.fullscreen)
display_toggle_fullscreen();

if (Options.fullscreen) {
display_toggle_fullscreen();
} else {
const int display_index = SDL_GetWindowDisplayIndex(Display_window);

SDL_Rect display_bounds;
SDL_GetDisplayUsableBounds(display_index, &display_bounds);

SDL_Point window_size;
SDL_GetWindowSize(Display_window, &window_size.x, &window_size.y);

SDL_Point borders_topleft, borders_bottomright;
SDL_GetWindowBordersSize(Display_window, &borders_topleft.y, &borders_topleft.x, &borders_bottomright.y, &borders_bottomright.x);

SDL_Point safe_size{
std::min(window_size.x, display_bounds.w - (borders_topleft.x + borders_bottomright.x)),
std::min(window_size.y, display_bounds.h - (borders_topleft.y + borders_bottomright.y))
};

if (window_size.x != safe_size.x || window_size.y != safe_size.y) {
SDL_SetWindowSize(Display_window, safe_size.x, safe_size.y);
}

SDL_Point window_position;
SDL_GetWindowPosition(Display_window, &window_position.x, &window_position.y);

SDL_Point safe_position{
std::max(window_position.x, display_bounds.x + borders_topleft.x),
std::max(window_position.y, display_bounds.y + borders_topleft.y)
};

if (window_position.x != safe_position.x || window_position.y != safe_position.y) {
SDL_SetWindowPosition(Display_window, safe_position.x, safe_position.y);
}
}
}
Initd_sdl_gl = true;

Expand Down Expand Up @@ -506,7 +539,7 @@ bool display_init()
SDL_ShowCursor(SDL_DISABLE);

if (Options.vsync_mode == vsync_mode_t::VSYNC_MODE_GET_SYNC || Options.vsync_mode == vsync_mode_t::VSYNC_MODE_WAIT_SYNC) {
if(glFenceSync == nullptr) {
if (glFenceSync == nullptr) {
Options.vsync_mode = vsync_mode_t::VSYNC_MODE_DISABLED;
} else {
Render_complete = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
Expand Down

0 comments on commit ab014be

Please sign in to comment.