-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[x11] fix: get desktop bounds correctly (aseprite #3118)
Use Xrandr's XRRGetMonitors function to find find the position, bounds, and "main screen" status of all monitors. On X11, there is no supported method to find the workarea of a monitor. This includes the _NET_WORKAREA atom, which breaks multi-monitor setups. This may not be an issue as most window managers aggressively and correctly enforce their, albeit private, workarea for windows. Signed-off-by: Aiden J Erickson <[email protected]>
- Loading branch information
Showing
8 changed files
with
115 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "monitor.h" | ||
#include "os/x11/x11.h" | ||
|
||
#include <X11/extensions/Xrandr.h> | ||
|
||
namespace os { | ||
|
||
MonitorsX11::MonitorsX11() | ||
{ | ||
auto x11display = X11::instance()->display(); | ||
|
||
int numMonitors; | ||
XRRMonitorInfo* monitors = XRRGetMonitors(x11display, XDefaultRootWindow(x11display), false, &numMonitors); | ||
|
||
m_numMonitors = numMonitors; | ||
m_monitors = unique_monitors_ptr(monitors); | ||
} | ||
|
||
int MonitorsX11::numMonitors() const { return m_numMonitors; } | ||
|
||
const XRRMonitorInfo& MonitorsX11::monitor(int monitorNum) const { return m_monitors.get()[monitorNum]; } | ||
|
||
} // namespace os | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef MONITOR_H | ||
#define MONITOR_H | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <X11/extensions/Xrandr.h> | ||
|
||
namespace os { | ||
|
||
struct MonitorCloser { | ||
void operator()(XRRMonitorInfo* monitors) const noexcept { XRRFreeMonitors(monitors); } | ||
}; | ||
|
||
typedef std::unique_ptr<XRRMonitorInfo, MonitorCloser> unique_monitors_ptr; | ||
|
||
class MonitorsX11 { | ||
public: | ||
MonitorsX11(); | ||
int numMonitors() const; | ||
const XRRMonitorInfo& monitor(int monitorNum) const; | ||
|
||
private: | ||
int m_numMonitors; | ||
unique_monitors_ptr m_monitors; | ||
}; | ||
|
||
} // namespace os | ||
|
||
#endif //MONITOR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters