Skip to content

Commit

Permalink
Screen fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorlinton committed Nov 3, 2013
1 parent c4dff31 commit f0086ca
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 174 deletions.
339 changes: 167 additions & 172 deletions src/api/app/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,168 +67,168 @@ namespace api {
namespace {

#if defined(OS_WIN)
struct MonitorDevice {
std::wstring cardName;
std::wstring deviceName;
std::wstring cardType;
std::wstring deviceType;
int x;
int y;
int x_work;
int y_work;
int width;
int height;
int width_work;
int height_work;
bool isPrimary;
bool isDisabled;
bool isSLM;
int colorDepth;
float scaleFactor;
bool isMirror;
bool isRemovable;
struct MonitorDevice {
std::wstring cardName;
std::wstring deviceName;
std::wstring cardType;
std::wstring deviceType;
int x;
int y;
int x_work;
int y_work;
int width;
int height;
int width_work;
int height_work;
bool isPrimary;
bool isDisabled;
bool isSLM;
int colorDepth;
float scaleFactor;
bool isMirror;
bool isRemovable;
};

RECT getViewingMonitorsBounds(std::vector<MonitorDevice> displays) {
RECT result;
result.left = LONG_MAX;
result.top = LONG_MAX;
result.bottom = LONG_MIN;
result.right = LONG_MIN;

MonitorDevice disp;

for (unsigned i=0;i<displays.size();++i)
{
disp = displays[i];
if (! disp.isSLM && ! disp.isDisabled)
{
result.left = std::min((int)result.left, disp.x);
result.top = std::min((int)result.top, disp.y);
result.right = std::max((int)result.right, disp.x + disp.width);
result.bottom = std::max((int)result.bottom, disp.y + disp.height);
}
}

return result;
}

POINT getNextDisplayPosition(std::vector<MonitorDevice> displays) {
POINT result;
result.x = LONG_MIN;
result.y = LONG_MIN;

MonitorDevice disp;

for (unsigned i=0;i<displays.size();++i)
{
disp = displays[i];
if (! disp.isDisabled)
{
if ((disp.x + disp.width) > result.x)
result.x = disp.x + disp.width;
result.y = disp.y;
}
}
return result;
}

void updateMonitorRect(MonitorDevice * display) {
DEVMODE dm;
ZeroMemory(&dm, sizeof(dm));
dm.dmSize = sizeof(dm);
std::wstring cardName = display->cardName.c_str();

if (EnumDisplaySettingsEx(cardName.c_str(), ENUM_CURRENT_SETTINGS, &dm, 0) == FALSE)
EnumDisplaySettingsEx(cardName.c_str(), ENUM_REGISTRY_SETTINGS, &dm, 0);
display->x = dm.dmPosition.x;
display->y = dm.dmPosition.y;
display->width = dm.dmPelsWidth;
display->height = dm.dmPelsHeight;
}

void updateMonitorRects(std::vector<MonitorDevice> * displays) {
for(unsigned int i=0;i<displays->size();++i)
updateMonitorRect(&(displays->at(i)));
}

std::vector<MonitorDevice> getMonitorInfo()
{
std::vector<MonitorDevice> displays;
DISPLAY_DEVICE dd;
dd.cb = sizeof(dd);
DWORD dev = 0; // device index

while (EnumDisplayDevices(0, dev, &dd, 0))
{
MonitorDevice thisDev;
DISPLAY_DEVICE ddMon;
DEVMODE dm;
DWORD devMon = 0;
HMONITOR hm = 0;
MONITORINFO mi;

// get information about the monitor attached to this display adapter. dualhead cards
// and laptop video cards can have multiple monitors attached
ZeroMemory(&ddMon, sizeof(ddMon));
ddMon.cb = sizeof(ddMon);

// please note that this enumeration may not return the correct monitor if multiple monitors
// are attached. this is because not all display drivers return the ACTIVE flag for the monitor
// that is actually active
while(EnumDisplayDevices(dd.DeviceName, devMon, &ddMon, 0)) {
if(ddMon.StateFlags & DISPLAY_DEVICE_ACTIVE) break;
devMon++;
}

if(!*ddMon.DeviceString) {
EnumDisplayDevices(dd.DeviceName, 0, &ddMon, 0);
if (!*ddMon.DeviceString) lstrcpy(ddMon.DeviceString, (L"Default Monitor"));
}

// get information about the display's position and the current display mode
ZeroMemory(&dm, sizeof(dm));
dm.dmSize = sizeof(dm);
if(EnumDisplaySettingsEx(dd.DeviceName, ENUM_CURRENT_SETTINGS, &dm, 0) == FALSE)
EnumDisplaySettingsEx(dd.DeviceName, ENUM_REGISTRY_SETTINGS, &dm, 0);

// get the monitor handle and workspace
ZeroMemory(&mi, sizeof(mi));
mi.cbSize = sizeof(mi);

if(dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) {
// display is enabled. only enabled displays have a monitor handle
POINT pt = { dm.dmPosition.x, dm.dmPosition.y };
hm = MonitorFromPoint(pt, MONITOR_DEFAULTTONULL);
if (hm) {
GetMonitorInfo(hm, &mi);
}

thisDev.deviceType = std::wstring(ddMon.DeviceString);
thisDev.cardType = std::wstring(dd.DeviceString);
thisDev.deviceName = std::wstring(ddMon.DeviceName);
thisDev.cardName = std::wstring(dd.DeviceName);
thisDev.x = dm.dmPosition.x;
thisDev.y = dm.dmPosition.y;
thisDev.width = dm.dmPelsWidth;
thisDev.height = dm.dmPelsHeight;
thisDev.x_work = mi.rcWork.left;
thisDev.y_work = mi.rcWork.top;
thisDev.width_work = mi.rcWork.right - mi.rcWork.left;
thisDev.height_work = mi.rcWork.bottom - mi.rcWork.top;
thisDev.isPrimary = (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) != 0;
thisDev.isDisabled = !(dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP);
thisDev.isRemovable = (dd.StateFlags & DISPLAY_DEVICE_REMOVABLE);
thisDev.isSLM = false;
thisDev.isMirror = (dd.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER);
thisDev.colorDepth = dm.dmBitsPerPel;

if(!(thisDev.deviceType.length()==0)) displays.push_back(thisDev);
}
dev++;
}

return displays;

RECT getViewingMonitorsBounds(std::vector<MonitorDevice> displays) {
RECT result;
result.left = LONG_MAX;
result.top = LONG_MAX;
result.bottom = LONG_MIN;
result.right = LONG_MIN;

MonitorDevice disp;

for (unsigned i=0;i<displays.size();++i)
{
disp = displays[i];
if (! disp.isSLM && ! disp.isDisabled)
{
result.left = std::min((int)result.left, disp.x);
result.top = std::min((int)result.top, disp.y);
result.right = std::max((int)result.right, disp.x + disp.width);
result.bottom = std::max((int)result.bottom, disp.y + disp.height);
}
}

return result;
}

POINT getNextDisplayPosition(std::vector<MonitorDevice> displays) {
POINT result;
result.x = LONG_MIN;
result.y = LONG_MIN;

MonitorDevice disp;

for (unsigned i=0;i<displays.size();++i)
{
disp = displays[i];
if (! disp.isDisabled)
{
if ((disp.x + disp.width) > result.x)
result.x = disp.x + disp.width;
result.y = disp.y;
}
}
return result;
}

void updateMonitorRect(MonitorDevice * display) {
DEVMODE dm;
ZeroMemory(&dm, sizeof(dm));
dm.dmSize = sizeof(dm);
std::wstring cardName = display->cardName.c_str();

if (EnumDisplaySettingsEx(cardName.c_str(), ENUM_CURRENT_SETTINGS, &dm, 0) == FALSE)
EnumDisplaySettingsEx(cardName.c_str(), ENUM_REGISTRY_SETTINGS, &dm, 0);
display->x = dm.dmPosition.x;
display->y = dm.dmPosition.y;
display->width = dm.dmPelsWidth;
display->height = dm.dmPelsHeight;
}

void updateMonitorRects(std::vector<MonitorDevice> * displays) {
for(unsigned int i=0;i<displays->size();++i)
updateMonitorRect(&(displays->at(i)));
}

std::vector<MonitorDevice> getMonitorInfo()
{
std::vector<MonitorDevice> displays;
DISPLAY_DEVICE dd;
dd.cb = sizeof(dd);
DWORD dev = 0; // device index

while (EnumDisplayDevices(0, dev, &dd, 0))
{
MonitorDevice thisDev;
DISPLAY_DEVICE ddMon;
DEVMODE dm;
DWORD devMon = 0;
HMONITOR hm = 0;
MONITORINFO mi;

// get information about the monitor attached to this display adapter. dualhead cards
// and laptop video cards can have multiple monitors attached
ZeroMemory(&ddMon, sizeof(ddMon));
ddMon.cb = sizeof(ddMon);

// please note that this enumeration may not return the correct monitor if multiple monitors
// are attached. this is because not all display drivers return the ACTIVE flag for the monitor
// that is actually active
while(EnumDisplayDevices(dd.DeviceName, devMon, &ddMon, 0)) {
if(ddMon.StateFlags & DISPLAY_DEVICE_ACTIVE) break;
devMon++;
}

if(!*ddMon.DeviceString) {
EnumDisplayDevices(dd.DeviceName, 0, &ddMon, 0);
if (!*ddMon.DeviceString) lstrcpy(ddMon.DeviceString, (L"Default Monitor"));
}

// get information about the display's position and the current display mode
ZeroMemory(&dm, sizeof(dm));
dm.dmSize = sizeof(dm);
if(EnumDisplaySettingsEx(dd.DeviceName, ENUM_CURRENT_SETTINGS, &dm, 0) == FALSE)
EnumDisplaySettingsEx(dd.DeviceName, ENUM_REGISTRY_SETTINGS, &dm, 0);

// get the monitor handle and workspace
ZeroMemory(&mi, sizeof(mi));
mi.cbSize = sizeof(mi);

if(dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) {
// display is enabled. only enabled displays have a monitor handle
POINT pt = { dm.dmPosition.x, dm.dmPosition.y };
hm = MonitorFromPoint(pt, MONITOR_DEFAULTTONULL);
if (hm) {
GetMonitorInfo(hm, &mi);
}

thisDev.deviceType = std::wstring(ddMon.DeviceString);
thisDev.cardType = std::wstring(dd.DeviceString);
thisDev.deviceName = std::wstring(ddMon.DeviceName);
thisDev.cardName = std::wstring(dd.DeviceName);
thisDev.x = dm.dmPosition.x;
thisDev.y = dm.dmPosition.y;
thisDev.width = dm.dmPelsWidth;
thisDev.height = dm.dmPelsHeight;
thisDev.x_work = mi.rcWork.left;
thisDev.y_work = mi.rcWork.top;
thisDev.width_work = mi.rcWork.right - mi.rcWork.left;
thisDev.height_work = mi.rcWork.bottom - mi.rcWork.top;
thisDev.isPrimary = (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) != 0;
thisDev.isDisabled = !(dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP);
thisDev.isRemovable = (dd.StateFlags & DISPLAY_DEVICE_REMOVABLE);
thisDev.isSLM = false;
thisDev.isMirror = (dd.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER);
thisDev.colorDepth = dm.dmBitsPerPel;

if(!(thisDev.deviceType.length()==0)) displays.push_back(thisDev);
}
dev++;
}

return displays;
}
#endif

Expand Down Expand Up @@ -377,21 +377,17 @@ void App::Call(Shell* shell,
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(online_display);
int depth = 0;
CFStringRef encoding = CGDisplayModeCopyPixelEncoding(mode);
if (CFStringCompare(encoding, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
depth = 32;
} else if (CFStringCompare( encoding, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
depth = 16;
} else if(CFStringCompare( encoding, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
depth = 8;
}
if (CFStringCompare(encoding, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) depth = 32;
else if (CFStringCompare( encoding, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) depth = 16;
else if(CFStringCompare( encoding, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) depth = 8;

if(display_count==1) ret << "{"; else ret << ",{";

ret << "\"bounds\":{\"x\":" << bounds.origin.x << ", \"y\":" << bounds.origin.y << ", \"width\":" << bounds.size.width << ", \"height\":" << bounds.size.height << "}";
if(CGDisplayIsMain(online_display))
ret << "\"workarea\":{\"x\":" << bounds.origin.x << ", \"y\":" << (bounds.origin.y+22) << ", \"width\":" << bounds.size.width << ", \"height\":" << (bounds.size.height-22) << "}";
ret << ",\"workarea\":{\"x\":" << bounds.origin.x << ", \"y\":" << (bounds.origin.y+22) << ", \"width\":" << bounds.size.width << ", \"height\":" << (bounds.size.height-22) << "}";
else
ret << "\"workarea\":{\"x\":" << bounds.origin.x << ", \"y\":" << bounds.origin.y << ", \"width\":" << bounds.size.width << ", \"height\":" << bounds.size.height << "}";
ret << ",\"workarea\":{\"x\":" << bounds.origin.x << ", \"y\":" << bounds.origin.y << ", \"width\":" << bounds.size.width << ", \"height\":" << bounds.size.height << "}";
ret << ",\"colorDepth\":" << depth;
ret << ",\"scaleFactor\":" << HIGetScaleFactor();
ret << ",\"isPrimary\":" << (CGDisplayIsMain(online_display) ? "true" : "false");
Expand All @@ -402,12 +398,11 @@ void App::Call(Shell* shell,
ret << "}";
CFRelease(encoding);
CGDisplayModeRelease(mode);

}
result->AppendString("["+ret.str()+"]");
#endif
return;
}else if (method == "GetArgv") {
} else if (method == "GetArgv") {
nw::Package* package = shell->GetPackage();
CommandLine* command_line = CommandLine::ForCurrentProcess();
CommandLine::StringVector args = command_line->GetArgs();
Expand Down
3 changes: 2 additions & 1 deletion src/api/ti_bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace api {
IDR_TI_API_WINDOW_JS,
IDR_TI_API_TRAY_JS,
IDR_TI_API_FILEDIALOG_JS,
IDR_TI_API_NOTIFY_JS
IDR_TI_API_NOTIFY_JS,
IDR_TI_API_DEVICES_JS
};

const int TiBindings::file_count = sizeof(TiBindings::files)/sizeof(int);
Expand Down
3 changes: 2 additions & 1 deletion src/resources/nw_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
<include name="IDR_TI_API_WINDOW_JS" file="../../../../tint/src/TIWindow.js" type="BINDATA" />
<include name="IDR_TI_API_TRAY_JS" file="../../../../tint/src/Tray.js" type="BINDATA" />
<include name="IDR_TI_API_FILEDIALOG_JS" file="../../../../tint/src/FileDialog.js" type="BINDATA" />
<include name="IDR_TI_API_NOTIFY_JS" file="../../../../tint/src/Notify.js" type="BINDATA" />
<include name="IDR_TI_API_NOTIFY_JS" file="../../../../tint/src/Notify.js" type="BINDATA" />
<include name="IDR_TI_API_DEVICES_JS" file="../../../../tint/src/Devices.js" type="BINDATA" />
<if expr="pp_ifdef('enable_printing')">
<include name="IDR_PRINT_PREVIEW_PAGE" file="pages/print_preview_page.html" flattenhtml="true" allowexternalscript="false" type="BINDATA" />
</if>
Expand Down

0 comments on commit f0086ca

Please sign in to comment.