Created
August 4, 2010 05:14
-
-
Save mkroman/507682 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #include <stdio.h> | |
| #include <unistd.h> | |
| #include "oculus.hpp" | |
| Oculus::Oculus() { | |
| if ((disp = XOpenDisplay(":0")) == NULL) | |
| printf("Could not connect to X server\n"); | |
| Window active = this->getActiveWindow(); | |
| printf("%s - %dx%d\n", this->getWindowName(&active), this->getWindowWidth(&active), this->getWindowHeight(&active)); | |
| } | |
| Window Oculus::getActiveWindow() { | |
| unsigned long n_items, bytes_after_ret; | |
| Atom atom_type_prop; | |
| int actual_format; | |
| Window *props; | |
| XGetWindowProperty(disp, DefaultRootWindow(disp), | |
| XInternAtom(disp, "_NET_ACTIVE_WINDOW", true), | |
| 0, 1, false, AnyPropertyType, | |
| &atom_type_prop, &actual_format, | |
| &n_items, &bytes_after_ret, (unsigned char**)&props); | |
| return props[0]; | |
| } | |
| char* Oculus::getWindowName(Window* window) { | |
| char *windowName; | |
| XFetchName(disp, *window, &windowName); | |
| return windowName; | |
| } | |
| int Oculus::getWindowWidth(Window* window) { | |
| return getWindowAttributes(window).width; | |
| } | |
| int Oculus::getWindowHeight(Window* window) { | |
| return getWindowAttributes(window).height; | |
| } | |
| XWindowAttributes Oculus::getWindowAttributes(Window* window) { | |
| XWindowAttributes attributes; | |
| XGetWindowAttributes(disp, *window, &attributes); | |
| return attributes; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment