чување 4c2f3c5791755b6132f0802c7b957030156c1e44
родитељ adc22fa56fe1f181903d19cf6ab26a89084e2f3e
Аутор: Страхиња Радић <sr@strahinja.org>
Датум: Thu, 10 Jul 2025 16:47:53 +0200
Fix physical output size detection for mouse pointer hiding
Diffstat:
измењених датотека: 1, додавања: 20(+), брисања: 3(-)
diff --git a/lav-sdl.c b/lav-sdl.c
@@ -99,11 +99,13 @@ static struct Labyrinth labyrinth;
static int location_pointer = 0;
static SDL_Point* location_stack = NULL;
static SDL_FPoint pointer;
+static int display_width = DEFAULT_WIDTH; /* Physical, detected */
+static int display_height = DEFAULT_HEIGHT;
static int help_shown = 0;
static int redraw = 1;
static SDL_Renderer* renderer = NULL;
static int running = 1;
-static int screen_width = DEFAULT_WIDTH;
+static int screen_width = DEFAULT_WIDTH; /* Logical */
static int screen_height = DEFAULT_HEIGHT;
static SDL_Texture* sprites = NULL;
static int state = STATE_SEARCHING_PAUSED;
@@ -115,6 +117,7 @@ static float text_scale_factor = 2.0f;
void assign_pointIF(const SDL_Point* from, SDL_FPoint* to);
void assign_point_xyIF(const int x, const int y, SDL_FPoint* to);
void calculate_delta(void);
+void calculate_screen_size(void);
void cleanup(void);
void draw(void);
void draw_background(SDL_FRect* bg_rect, SDL_FRect* cell_rect,
@@ -171,6 +174,17 @@ calculate_delta(void)
}
void
+calculate_screen_size(void)
+{
+ if (!SDL_GetRenderOutputSize(renderer, &display_width, &display_height))
+ {
+ print_error("SDL_GetRenderOutputSize failed");
+ exit(1);
+ }
+ print_debug("output size: (%d, %d)", screen_width, screen_height);
+}
+
+void
cleanup(void)
{
free(location_stack);
@@ -524,6 +538,7 @@ handle_event(SDL_Event* event)
break;
case SDL_EVENT_WINDOW_RESIZED:
redraw = 1;
+ calculate_screen_size();
break;
case SDL_EVENT_KEY_DOWN:
print_debug("Got Keydown, key = %X, mod = %X", event->key.key,
@@ -568,8 +583,8 @@ handle_event(SDL_Event* event)
pointer.x = event->motion.x;
pointer.y = event->motion.y;
if (pointer.x <= 0 || pointer.y <= 0
- || pointer.x + 1 >= screen_width
- || pointer.y + 1 >= screen_height)
+ || pointer.x + 1 >= display_width
+ || pointer.y + 1 >= display_height)
SDL_ShowCursor();
else
SDL_HideCursor();
@@ -947,6 +962,8 @@ main(int argc, char** argv)
print_debug("factor = %0.2f", factor);
SDL_SetRenderScale(renderer, 1.0f, factor);*/
+ calculate_screen_size();
+
if (load_textures() < 0)
exit(1);