Kronos/src/XWindow.cpp
2020-07-13 00:37:45 +02:00

64 lines
1.5 KiB
C++

#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <string>
#include "XDisplayConnection.hpp"
#include "XWindowInitException.hpp"
#include "XWindow.hpp"
Kronos::XWindow::XWindow(Kronos::XDisplayConnection& conn, Window window)
: m_conn(conn), m_window(window) {
Atom propName = XInternAtom(m_conn.getDisplay(), "WM_NAME", False);
Atom type;
int form;
unsigned long remain, len;
unsigned char* prop = nullptr;
if(XGetWindowProperty(m_conn.getDisplay(), m_window, propName, 0, 1024, False, AnyPropertyType, &type, &form, &len, &remain, &prop) == Success) {
m_name = (const char*) prop;
XFree(prop);
}
XWindowAttributes attr;
if(!XGetWindowAttributes(m_conn.getDisplay(), m_window, &attr)) {
throw Kronos::Exception::XWindowInitException();
}
m_width = attr.width;
m_height = attr.height;
XSelectInput(m_conn.getDisplay(), m_window, StructureNotifyMask);
XSync(m_conn.getDisplay(), 0);
}
Kronos::XWindow::~XWindow() {
XSelectInput(m_conn.getDisplay(), m_window, 0);
}
void Kronos::XWindow::processEvents() {
/*
* IT DOES'T WORK !!
*/
while(XEventsQueued(m_conn.getDisplay(), QueuedAfterReading) > 0) {
XEvent event;
XNextEvent(m_conn.getDisplay(), &event);
if(event.type == ConfigureNotify) {
XConfigureEvent conf = event.xconfigure;
m_width = conf.width;
m_height = conf.height;
}
}
}
std::string Kronos::XWindow::getName() const {
return m_name;
}
int Kronos::XWindow::getWidth() const {
return m_width;
}
int Kronos::XWindow::getHeight() const {
return m_height;
}