Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » FULLSCREEN_WINDOW and display scaling on high DPI settings - Workaround

This thread is locked; no one can reply to it. rss feed Print
FULLSCREEN_WINDOW and display scaling on high DPI settings - Workaround
Vi_112
Member #15,539
March 2014

Sorry for the new thread, for some reason there is no any "reply" button in that thread.

The problem was:
Windows - when display scaling is enabled, al_get_mouse_state returns co-ordinates of the unscaled resolution, while the fullscreen window is created using the scaled resolution. This makes cursor being stuck in the upper-left corner of the screen.

To reproduce this, use ex_mouse with the FULLSCREEN_WINDOW display.

I've finally used a workaround to fix the problem.

I've added a static float DPIMult that is initialized in init_mouse in wmouse.c

#SelectExpand
1static bool init_mouse(void) 2{ 3 ALLEGRO_DISPLAY *display; 4 5 HDC screen; 6 int virtualWidth; 7 int physicalWidth; 8 9 if (installed) 10 return false; 11 12 if (!(al_get_new_display_flags() & ALLEGRO_FULLSCREEN) || (al_get_new_display_flags() & ALLEGRO_FULLSCREEN_WINDOW)) 13 { 14 screen = GetDC(0); 15 virtualWidth = GetDeviceCaps (screen, 8); 16 physicalWidth = GetDeviceCaps (screen, 118); 17 18 if (virtualWidth>0) 19 DPIMult = (float)physicalWidth / (float)virtualWidth; 20 else 21 DPIMult = 1.0f; 22 23 ReleaseDC (0, screen); 24 } 25 else 26 DPIMult = 1.0f; 27 28....

Then I use this value in generate_mouse_event

   event.mouse.x = DPIMult*(float)x;
   event.mouse.y = DPIMult*(float)y;

set_mouse_xy

   if (dx || dy) {
      mouse_state.x = (float)x/DPIMult;
      mouse_state.y = (float)y/DPIMult;

      generate_mouse_event(
         ALLEGRO_EVENT_MOUSE_WARPED,
         mouse_state.x, mouse_state.y, mouse_state.z, mouse_state.w,
         dx, dy, 0, 0,
         0, (void*)win_disp);
   }

and get_mouse_state

static void get_mouse_state(ALLEGRO_MOUSE_STATE *ret_state)
{
   _al_event_source_lock(&the_mouse.es);
   *ret_state = mouse_state;
  ret_state->x = DPIMult*(float)mouse_state.x;
  ret_state->y = DPIMult*(float)mouse_state.y;
   _al_event_source_unlock(&the_mouse.es);
}

After these modifications it works fine.

SiegeLord
Member #7,827
October 2006
avatar

Note that I recently made the change that disabled the scaling for Allegro apps to avoid this issue. I'll try out your fix and see if it fixes it to me, so that if you for some reason want to use scaling, at least it'll work ok.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Vi_112
Member #15,539
March 2014

I would better to disable scaling. Where I can find that piece of code? I need to retrofit it into 5.1.9...

SiegeLord
Member #7,827
October 2006
avatar

This is the commit: https://github.com/liballeg/allegro5/commit/66eb5e9c3482223e6898f4ee5be084d35fc35639

Also, I've been trying to reproduce your OSX fullscreen window issues without much success. Could you tell me what OSX version you were using and if your bug also happened with something like ex_projection2 example (press space to make it go fullscreen).

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Go to: