I could not find any information about having such an information. I need this for two things:
1. If a window changes the monitor (the game window moved to another monitor) than I should recalculate the fps and so on based on the monitor's refresh rate.
2. If a window has changed it's position then I may want to do something.
Why does not the love2d api have such an API? Also, why don't we have an API to get all available monitors information, like getMode() but for all displays?
Callback on window position change
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Callback on window position change
Hi and welcome to the forums!
There's actually a way; SDL2 has a function to get the "global" position of the window's top-left corner; you could in theory create a neat layout of your active monitors/screens with that, but you'll need to use the FFI to access that function.
I do have code for this, but it's a bit unclean;i'll try to clean it up soon (after wednesday next week) and share it. (It won't be a callback though, but one can add it as a callback to löve via ways i'm just a bit unfamiliar with)
(Not sure if you would get events continuously if you moved the window by its top bar though, but for my needs (dragging a borderless window) it worked nicely.
There's actually a way; SDL2 has a function to get the "global" position of the window's top-left corner; you could in theory create a neat layout of your active monitors/screens with that, but you'll need to use the FFI to access that function.
I do have code for this, but it's a bit unclean;i'll try to clean it up soon (after wednesday next week) and share it. (It won't be a callback though, but one can add it as a callback to löve via ways i'm just a bit unfamiliar with)
(Not sure if you would get events continuously if you moved the window by its top bar though, but for my needs (dragging a borderless window) it worked nicely.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
- slime
- Solid Snayke
- Posts: 3160
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Callback on window position change
You can query love.window.getPosition, which internally calls the SDL2 function zorg is talking about I believe. love.window.getFullscreenMode and love.window.getDesktopDimensions can also accept a display index to query information for a particular display.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Callback on window position change
I think i mixed it up a bit; SDL2 has a function to get the mouse position relative to the topleft of the desktop, not the window position.slime wrote: ↑Sat Nov 11, 2017 9:09 pm You can query love.window.getPosition, which internally calls the SDL2 function zorg is talking about I believe. love.window.getFullscreenMode and love.window.getDesktopDimensions can also accept a display index to query information for a particular display.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: Callback on window position change
Thank you for your response.zorg wrote: ↑Sat Nov 11, 2017 7:05 pm Hi and welcome to the forums!
There's actually a way; SDL2 has a function to get the "global" position of the window's top-left corner; you could in theory create a neat layout of your active monitors/screens with that, but you'll need to use the FFI to access that function.
I do have code for this, but it's a bit unclean;i'll try to clean it up soon (after wednesday next week) and share it. (It won't be a callback though, but one can add it as a callback to löve via ways i'm just a bit unfamiliar with)
(Not sure if you would get events continuously if you moved the window by its top bar though, but for my needs (dragging a borderless window) it worked nicely.
Yes, I know I can do things via SDL2 but I asked about an API in the love2d It would be much better to have such a functionality right inside the love2d as we have `keypressed` and other callbacks there. There is a real need in this - people have now multiple monitors setup and if their monitors are different they may have different refresh rate. I have turned off the `vsync` and implemented my own fps cap algorithm based on the `love2d wiki` (thanks much for this). So, then the user runs my game on one monitor, I get the refreshrate for fps limiting from the current monitor, for example, it is 120 hertz so I limit the fps to 120 also. But if the user wants to play on another monitor, it may have another value of refresh rate, for example, 60, or 75, or 85, or 144, and so on. I must reset my fps limiting value too. But I can't hook such a situtation because we don't have any callbacks for this in love2d. Your solutions require getting modes of the current display everytime, like in `update` or `draw` but this is wrong, you know it, especially for such an easy thing.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Callback on window position change
Well, as slime probably wanted to write, you can use love.window.getMode, since it does return the refresh rate of the current monitor you're on, which you can use to dynamically adjust the vsync. Moving the window through multiple screens is not something that would usually trigger a callback, since the whole desktop space is technically one unified surface.vityafx wrote: ↑Mon Nov 13, 2017 7:04 am Yes, I know I can do things via SDL2 but I asked about an API in the love2d It would be much better to have such a functionality right inside the love2d as we have `keypressed` and other callbacks there. There is a real need in this - people have now multiple monitors setup and if their monitors are different they may have different refresh rate. I have turned off the `vsync` and implemented my own fps cap algorithm based on the `love2d wiki` (thanks much for this). So, then the user runs my game on one monitor, I get the refreshrate for fps limiting from the current monitor, for example, it is 120 hertz so I limit the fps to 120 also. But if the user wants to play on another monitor, it may have another value of refresh rate, for example, 60, or 75, or 85, or 144, and so on. I must reset my fps limiting value too. But I can't hook such a situtation because we don't have any callbacks for this in love2d. Your solutions require getting modes of the current display everytime, like in `update` or `draw` but this is wrong, you know it, especially for such an easy thing.
Besides, let me give you a nice counterexample for why it doesn't matter: I have 6 monitors hooked up to 2 video cards; one runs at 60 Hz, one at 140 Hz, one at 120 Hz, one at 85 Hz and two at 75 Hz (of which one fried, but that's irrelevant). But the actual values reported back are wrong for some of the screens: one screen reports back 4 Hz for instance, so whether i have the builtin vsync enabled, or use my own, i can't use the returned value since that would force löve to redraw 4 times a second...
Also, nothing's ever an "easy" thing; that's what people said about artificial intelligence in 4 separate places in the U.K. before the winter hit.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: Callback on window position change
Okay, I think there is a better solution: let the user decide what the fps limit he wants or use 60 as minimum.zorg wrote: ↑Mon Nov 13, 2017 9:46 amWell, as slime probably wanted to write, you can use love.window.getMode, since it does return the refresh rate of the current monitor you're on, which you can use to dynamically adjust the vsync. Moving the window through multiple screens is not something that would usually trigger a callback, since the whole desktop space is technically one unified surface.vityafx wrote: ↑Mon Nov 13, 2017 7:04 am Yes, I know I can do things via SDL2 but I asked about an API in the love2d It would be much better to have such a functionality right inside the love2d as we have `keypressed` and other callbacks there. There is a real need in this - people have now multiple monitors setup and if their monitors are different they may have different refresh rate. I have turned off the `vsync` and implemented my own fps cap algorithm based on the `love2d wiki` (thanks much for this). So, then the user runs my game on one monitor, I get the refreshrate for fps limiting from the current monitor, for example, it is 120 hertz so I limit the fps to 120 also. But if the user wants to play on another monitor, it may have another value of refresh rate, for example, 60, or 75, or 85, or 144, and so on. I must reset my fps limiting value too. But I can't hook such a situtation because we don't have any callbacks for this in love2d. Your solutions require getting modes of the current display everytime, like in `update` or `draw` but this is wrong, you know it, especially for such an easy thing.
Besides, let me give you a nice counterexample for why it doesn't matter: I have 6 monitors hooked up to 2 video cards; one runs at 60 Hz, one at 140 Hz, one at 120 Hz, one at 85 Hz and two at 75 Hz (of which one fried, but that's irrelevant). But the actual values reported back are wrong for some of the screens: one screen reports back 4 Hz for instance, so whether i have the builtin vsync enabled, or use my own, i can't use the returned value since that would force löve to redraw 4 times a second...
Also, nothing's ever an "easy" thing; that's what people said about artificial intelligence in 4 separate places in the U.K. before the winter hit.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Callback on window position change
Yep, that means you need to code it yourself! :v
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests