109
info_over_me.cpp
Normal file
109
info_over_me.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
#include "info_over_me.h"
|
||||
|
||||
#include "utils/whereami.h"
|
||||
|
||||
#include <iostream>
|
||||
#ifdef __linux
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
#include "gtk-imports.h"
|
||||
}
|
||||
#include <list>
|
||||
|
||||
std::string InfoOverMe::containingFolder()
|
||||
{
|
||||
int len = wai_getExecutablePath(NULL, 0, NULL);
|
||||
|
||||
char *path = static_cast<char *>(malloc(len + 1));
|
||||
wai_getExecutablePath(path, len, NULL);
|
||||
path[len] = '\0';
|
||||
|
||||
std::string p(path);
|
||||
std::cout << p << std::endl;
|
||||
return p;
|
||||
}
|
||||
|
||||
std::string InfoOverMe::myHostname()
|
||||
{
|
||||
char buf[10240];
|
||||
#ifdef __linux
|
||||
int r = gethostname(buf, 10240);
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
DWORD size = 10240;
|
||||
bool r = GetComputerNameA(buf, &size);
|
||||
buf[size] = '\0';
|
||||
if (!r) { sprintf(buf, "unknown"); }
|
||||
#endif
|
||||
std::string name(buf);
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string InfoOverMe::myOsHostname()
|
||||
{
|
||||
std::string os;
|
||||
#ifdef __linux
|
||||
os = "linux";
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
os = "windows";
|
||||
#else
|
||||
os = "unknown";
|
||||
#endif
|
||||
#endif
|
||||
return os + "_" + myHostname();
|
||||
}
|
||||
|
||||
std::string InfoOverMe::myId()
|
||||
{
|
||||
|
||||
std::list<GdkRectangle> l;
|
||||
GdkDisplay *d = gdk_display_get_default();
|
||||
int n = gdk_display_get_n_monitors(d);
|
||||
int i;
|
||||
for(i = 0; i < n; i++) {
|
||||
GdkMonitor *m = gdk_display_get_monitor(d, i);
|
||||
GdkRectangle r;
|
||||
gdk_monitor_get_geometry(m, &r);
|
||||
l.push_back(r);
|
||||
//std::cout << r.width << ", " << r.height << ", x = " << r.x << ", y = " << r.y << std::endl;
|
||||
}
|
||||
|
||||
auto compare = [](const GdkRectangle &a, const GdkRectangle &b) {
|
||||
if (a.x < b.x) {
|
||||
return true;
|
||||
} else if (a.x > b. x) {
|
||||
return false;
|
||||
} else if (a.y < b.y) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
l.sort(compare);
|
||||
std::list<GdkRectangle>::iterator it;
|
||||
std::string monitor_id;
|
||||
std::string sep = "";
|
||||
for(it = l.begin(); it != l.end(); it++) {
|
||||
char buf[200];
|
||||
const GdkRectangle &r = *it;
|
||||
sprintf(buf, "%d-%d-%d-%d", r.x, r.y, r.width, r.height);
|
||||
std::string geom(buf);
|
||||
monitor_id += sep;
|
||||
monitor_id += geom;
|
||||
sep = "-";
|
||||
}
|
||||
|
||||
monitor_id = myOsHostname() + "/" + monitor_id;
|
||||
|
||||
return monitor_id;
|
||||
}
|
||||
|
||||
InfoOverMe::InfoOverMe() {}
|
||||
Reference in New Issue
Block a user