Skip to content

Mouse pointer is off on Mac OS Sequoia and program is not buildable #263

@kocicky

Description

@kocicky

Reason why is mouse pointer off is retina display. Correcting getMotionEvent helps:

MAEvent *getMotionEvent(int type, const SDL_Event *event) {
  auto *result = new MAEvent();
  result->type = type;

  // 1) vytáhnout x/y podle typu SDL eventu
  float x = 0.0f, y = 0.0f;
  SDL_WindowID wid = 0;

  switch (event->type) {
    case SDL_EVENT_MOUSE_MOTION:
      x = event->motion.x;
      y = event->motion.y;
      wid = event->motion.windowID;
      break;

    case SDL_EVENT_MOUSE_BUTTON_DOWN:
    case SDL_EVENT_MOUSE_BUTTON_UP:
      x = event->button.x;
      y = event->button.y;
      wid = event->button.windowID;
      break;

    default:
      // fallback (kdyby se sem dostalo něco neočekávaného)
      x = event->motion.x;
      y = event->motion.y;
      wid = event->motion.windowID;
      break;
  }

  // 2) spočítat scale (points -> pixels)
  float sx = 1.0f, sy = 1.0f;

  SDL_Window *win = nullptr;
  if (wid) win = SDL_GetWindowFromID(wid);
  if (!win) win = SDL_GetMouseFocus();
  if (!win) win = SDL_GetKeyboardFocus();

  if (win) {
    int ww = 0, wh = 0, pw = 0, ph = 0;
    SDL_GetWindowSize(win, &ww, &wh);
    SDL_GetWindowSizeInPixels(win, &pw, &ph);

    if (ww > 0 && wh > 0 && pw > 0 && ph > 0) {
      sx = (float)pw / (float)ww;
      sy = (float)ph / (float)wh;
    }
  }

  // 3) uložit do MAEvent (už v "pixel" souřadnicích pro hit-test)
  result->point.x = (int)lroundf(x * sx);
  result->point.y = (int)lroundf(y * sy);

  return result;
}

Project is also missing icon.h, so I made one:

#pragma once
#include <cstddef>
#include <cstdint>

// Minimal stub for macOS build: no embedded PNG icon.
// lodepng_decode32() will fail and the app will run without a custom window icon.
static const unsigned char sb_desktop_128x128_png[] = { 0 };
static const unsigned int sb_desktop_128x128_png_len = 0;

Also ui/image_codec.cpp is using #include <malloc.h> which doesn't exist on Mac.
so it's best to change it to:

#if defined(__APPLE__)
  #include <stdlib.h>
  // nebo pokud by někde bylo potřeba něco z malloc headeru:
  // #include <malloc/malloc.h>
#else
  #include <malloc.h>
#endif

It's also necessary to ad symlinks to fonts:

sudo ln -s "/System/Library/Fonts/Supplemental/Courier New.ttf" "/Library/Fonts/Courier New.ttf"
sudo ln -s "/System/Library/Fonts/Supplemental/Courier New Bold.ttf" "/Library/Fonts/Courier New Bold.ttf"

And last but not least, run it with opengl:
SDL_RENDER_DRIVER=opengl ./src/platform/sdl/sbasicg

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions