Skip to content
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

Open
lesterfan opened this issue May 23, 2020 · 6 comments
Open

Could the screenWidth and screenHeight fields be exposed? #85

lesterfan opened this issue May 23, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@lesterfan
Copy link

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 and screenHeight fields exposed from the screen API.

@spyoungtech
Copy link
Owner

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?

@spyoungtech spyoungtech added the enhancement New feature or request label May 28, 2020
@idbrii
Copy link

idbrii commented May 29, 2020

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.)

@lesterfan
Copy link
Author

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.

@spyoungtech
Copy link
Owner

spyoungtech commented May 30, 2020

Thanks for the feedback on this and use cases. I think my next step will be to implement SysGet. Might get around to that this weekend or the next.

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

@idbrii
Copy link

idbrii commented Jun 5, 2020

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!

Repository owner deleted a comment Feb 26, 2024
@KyleTheScientist
Copy link

KyleTheScientist commented Mar 15, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants