-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could the screenWidth
and screenHeight
fields be exposed?
#85
Comments
I'd be happy to look into adding this functionality. @lesterfan could you help me by pointing to the AHK docs for this or an example AHK script? Would adding SysGet functionality work for your case? |
A_ScreenWidth/Height gives you the dimensions of the primary monitor, but to get other monitors or the entire desktop (spanning monitors), you need to use SysGet. SysGet covers more use cases, so it'd be preferable to me! In my AutoHotkey scripts, I use SysGet to find the active monitor, position windows at edges of monitors, and change layout based on the number of monitors and which is primary. (So I use Monitor MonitorCount MonitorPrimary and MonitorWorkArea.) |
SysGet functionality would be perfect! Additionally, getting a handle to the active monitor like in @idbrii's case seems to be a really common use case which is not easy to implement. Having an API call specifically for that would be amazing, but I'm not sure if that's within the scope of this library. |
Thanks for the feedback on this and use cases. I think my next step will be to implement I'll also invest some thought into what kind of utility will be provided around working with (multiple) monitors. I imagine having at least one high level function that would return some data structure or object with info of all monitors. Maybe a mockup of what I'm thinking: >>> ahk.monitors
[{'number': 1, 'primary': True, 'working_area': [0, 0, 3840, 2060], 'area': [0, 0, 3840, 2160]},
{'number': 2, 'primary': False, ...},
...
] >>> ahk.primary_monitor
{'number': 1, 'working_area': [0, 0, 3840, 2060], 'area': [0, 0, 3840, 2160]} Or maybe a full on class for representing a monitor >>> mon = ahk.primary_monitor
>>> mon
<ahk.Monitor number=1>
>>> mon.area
[0, 0, 3840, 2160]
>>> mon.working_area
[0, 0, 3840, 2060]
>>> mon.number
1 |
That sounds awesome! My working solution is a simple class and some hard-coded coordinates The x,y of a monitor may be negative, so having width/height is useful (or maybe mon.area is x,y,w,h and not x1,y1,x2,y2?). Having a class might be simpler than storing a bunch of derived data. Also, exposing attributes that produce values easily applied to the existing API would help. Being able to do something like this would be great: mon = ahk.get_monitor_by_layout(0) # the left-most monitor
win = ahk.find_window_by_class("Vim")
x,y = mon.topleft
w,h = mon.dimensions
win.move(x,y, w/2,h)
win = ahk.find_window_by_exe("chrome.exe")
x,y = mon.topright
win.move(x - w/2,y, w/2,h) The physical layout (determined by monitor pixel locations within the whole desktop) is more useful than monitor numbers. When I have three monitors, often my centre is 1 because it's the primary. Right now, my rightmost monitor is 1 but it's disabled and Windows won't let me remove it. Regardless, getting access to those SysGet values is a great first step. Looking forward to it! |
In the meantime, win32api has functionality for this: from win32api import GetMonitorInfo, EnumDisplayMonitors
class Monitor:
pass
def get_monitors():
monitors = []
for m in EnumDisplayMonitors():
info = GetMonitorInfo(m[0])
monitor = Monitor()
monitor.name = info['Device'],
monitor.x = info['Work'][0], # Work describes the area of the monitor not occluded by the taskbar
monitor.y = info['Work'][1],
monitor.width = info['Work'][2],
monitor.height = info['Work'][3],
monitor.is_primary = info['Flags'] == 1
monitors.append(monitor)
return monitors or more simply: from win32api import EnumDisplayMonitors
def get_monitors():
return [m[0] for m in EnumDisplayMonitors()] # this is the full size of the screen as a tuple, including the taskbar |
For whatever it's worth, I finally had a personal use case for this and decided to make an attempt at enabling this functionality via the ahk-wmutil extension package. It seems to work well for my use case, but I haven't done extensive testing, since I only have my personal monitor setup to test against. But I use 3 monitors all with different resolutions and DPI settings and it seems to do the right thing. In any case, I've decided that I'm going to try to keep the focus of the In the near future, I hope to provide a dedicated space in the documentation for examples, so keep an eye out for that if that sounds like something you might wish to contribute. |
My use case involves resizing a window to a fraction of the current screen's dimensions. To this end, It would be nice to have the
screenWidth
andscreenHeight
fields exposed from thescreen
API.The text was updated successfully, but these errors were encountered: