From 791b333539a7a7d9e1e051337b4cb8f4f6de955a Mon Sep 17 00:00:00 2001 From: koldo Date: Tue, 29 Jul 2014 07:53:29 +0000 Subject: [PATCH] SysInfo: Improved screengrab git-svn-id: svn://ultimatepp.org/upp/trunk@7551 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/SysInfo/SysInfo.cpp | 30 +++++++++++------------------- bazaar/SysInfo/SysInfo.h | 2 ++ bazaar/SysInfo/screengrab.cpp | 11 ++++++++--- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/bazaar/SysInfo/SysInfo.cpp b/bazaar/SysInfo/SysInfo.cpp index 611c80737..16bc38453 100644 --- a/bazaar/SysInfo/SysInfo.cpp +++ b/bazaar/SysInfo/SysInfo.cpp @@ -626,37 +626,28 @@ Array GetAdapterInfo() { Array GetAdapterInfo() { Array res; - char buf[8192] = {0}; - struct ifconf ifc = {0}; - struct ifreq *ifr = NULL; - int sck = 0; - int nInterfaces = 0; - int i = 0; - char ip[INET6_ADDRSTRLEN] = {0}; - struct ifreq *item; - struct sockaddr *addr; - socklen_t salen; - char hostname[NI_MAXHOST]; - - sck = socket(PF_INET, SOCK_DGRAM, 0); + int sck = socket(PF_INET, SOCK_DGRAM, 0); if(sck < 0) return res; + char buf[8192] = {0}; + struct ifconf ifc = {0}; ifc.ifc_len = sizeof(buf); ifc.ifc_buf = buf; if(ioctl(sck, SIOCGIFCONF, &ifc) < 0) return res; - ifr = ifc.ifc_req; - nInterfaces = ifc.ifc_len / sizeof(struct ifreq); - for(i = 0; i < nInterfaces; i++) { + struct ifreq *ifr = ifc.ifc_req; + int nInterfaces = ifc.ifc_len / sizeof(struct ifreq); + for(int i = 0; i < nInterfaces; i++) { String MAC; + char hostname[NI_MAXHOST]; bzero(hostname, NI_MAXHOST); - item = &ifr[i]; - - addr = &(item->ifr_addr); + struct ifreq *item = &ifr[i]; + struct sockaddr *addr = &(item->ifr_addr); + socklen_t salen; switch(addr->sa_family) { case AF_INET: salen = sizeof(struct sockaddr_in); break; case AF_INET6: salen = sizeof(struct sockaddr_in6); break; @@ -671,6 +662,7 @@ Array GetAdapterInfo() { NetAdapter &adapter = res.Add(); adapter.description = hostname; + char ip[INET6_ADDRSTRLEN] = {0}; switch(addr->sa_family) { case AF_INET: inet_ntop(AF_INET, &(((struct sockaddr_in *)addr)->sin_addr), ip, INET6_ADDRSTRLEN); adapter.ip4 = ip; diff --git a/bazaar/SysInfo/SysInfo.h b/bazaar/SysInfo/SysInfo.h index 69e16e2d9..6660ea64c 100644 --- a/bazaar/SysInfo/SysInfo.h +++ b/bazaar/SysInfo/SysInfo.h @@ -57,6 +57,8 @@ void GetWindowsList(Upp::Array &wid, Upp::Array &pid, Upp::Array &fileName, Upp::Array &title); Upp::Array GetWindowsList(); +Rect GetDesktopRect(); + bool Window_GetRect(int64 windowId, long &left, long &top, long &right, long &bottom); bool Window_SetRect(int64 windowId, long left, long top, long right, long bottom); void Window_Bottom(int64 windowId); diff --git a/bazaar/SysInfo/screengrab.cpp b/bazaar/SysInfo/screengrab.cpp index eb6fff8a2..48f868287 100644 --- a/bazaar/SysInfo/screengrab.cpp +++ b/bazaar/SysInfo/screengrab.cpp @@ -519,8 +519,10 @@ Image Window_SaveCapture(int64 windowId, int left, int top, int width, int heigh windowId = RootWindow(dpy, screen); else { windowId = GetToplevelParent(dpy, windowId); - if (windowId < 0) + if (windowId < 0) { + SetX11ErrorHandler(); return Null; + } } XWindowAttributes rc; @@ -539,9 +541,12 @@ Image Window_SaveCapture(int64 windowId, int left, int top, int width, int heigh if (height == -1) height = rc.height; - XImage *image = XGetImage(dpy, windowId, 0, 0, width, height, XAllPlanes(), ZPixmap); - if (image == NULL) + XImage *image = XGetImage(dpy, windowId, left, top, width, height, XAllPlanes(), ZPixmap); + if (image == NULL) { + XCloseDisplay(dpy); + SetX11ErrorHandler(); return Null; + } ImageBuffer ib(width, height);