edit: window manager and add keyhook
This commit is contained in:
parent
46deb59efd
commit
18c4896be4
4 changed files with 66 additions and 22 deletions
1
TODO
Normal file
1
TODO
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
TODO: error handling in WindowManager.cpp
|
||||||
|
|
@ -12,14 +12,21 @@ public:
|
||||||
|
|
||||||
void loop();
|
void loop();
|
||||||
private:
|
private:
|
||||||
Display *_display;
|
int WindowX;
|
||||||
int _screen;
|
int WindowY;
|
||||||
Window root;
|
int WindowWidth;
|
||||||
Window win;
|
int WindowHeight;
|
||||||
XEvent event;
|
int BorderWidth;
|
||||||
int _width;
|
int WindowDepth;
|
||||||
int _height;
|
int WindowClass;
|
||||||
|
Visual *WindowVisual;
|
||||||
|
int AttributeValueMask;
|
||||||
|
XSetWindowAttributes WindowAttributes;
|
||||||
|
Window MainWindow;
|
||||||
|
Display *MainDisplay;
|
||||||
|
Window RootWindow;
|
||||||
|
Atom wmDelete;
|
||||||
|
bool isWindowOpen;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //NOISE_GENERATOR_WINDOWMANAGER_HPP
|
#endif //NOISE_GENERATOR_WINDOWMANAGER_HPP
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
WindowManager window(WIDTH, HEIGHT);
|
WindowManager window(WIDTH, HEIGHT);
|
||||||
|
|
||||||
window.loop();
|
window.loop();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,60 @@
|
||||||
#include "windowManager/WindowManager.hpp"
|
#include "windowManager/WindowManager.hpp"
|
||||||
|
#include <string.h>
|
||||||
|
#include <X11/Xutil.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
WindowManager::WindowManager(int width, int height) : _width(width), _height(height) {
|
WindowManager::WindowManager(int width, int height) :
|
||||||
_display = XOpenDisplay(NULL);
|
WindowX(0), WindowY(0),
|
||||||
if (NULL == _display) errx(2, "unable to open display");
|
WindowWidth(width), WindowHeight(height),
|
||||||
_screen = DefaultScreen(_display);
|
BorderWidth(0),
|
||||||
root = RootWindow(_display, _screen);
|
WindowDepth(CopyFromParent),
|
||||||
win = XCreateSimpleWindow(_display, root, 0, 0, _width, _height, 10,
|
WindowClass(CopyFromParent),
|
||||||
0, 0x0f0f0f);
|
WindowVisual(CopyFromParent),
|
||||||
|
AttributeValueMask(CWBackPixel | CWEventMask)
|
||||||
|
{
|
||||||
|
MainDisplay = XOpenDisplay(0);
|
||||||
|
RootWindow = XDefaultRootWindow(MainDisplay);
|
||||||
|
bzero(&WindowAttributes, sizeof(XSetWindowAttributes));
|
||||||
|
WindowAttributes.background_pixel = 0xffafe9af;
|
||||||
|
WindowAttributes.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask | ExposureMask;
|
||||||
|
|
||||||
XMapWindow(_display, win);
|
MainWindow = XCreateWindow(MainDisplay, RootWindow,
|
||||||
XFlush(_display);
|
WindowX, WindowY, WindowWidth, WindowHeight,
|
||||||
|
BorderWidth, WindowDepth, WindowClass, WindowVisual,
|
||||||
|
AttributeValueMask, &WindowAttributes);
|
||||||
|
XMapWindow(MainDisplay, MainWindow);
|
||||||
|
wmDelete = XInternAtom(MainDisplay, "WM_DELETE_WINDOW", false);
|
||||||
|
XSetWMProtocols(MainDisplay, MainWindow, &wmDelete, 1);
|
||||||
|
|
||||||
|
isWindowOpen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowManager::~WindowManager() {
|
WindowManager::~WindowManager() {
|
||||||
XUnmapWindow(_display, win);
|
XUnmapWindow(this->MainDisplay, this->MainWindow);
|
||||||
XDestroyWindow(_display, win);
|
XDestroyWindow(this->MainDisplay, this->MainWindow);
|
||||||
XCloseDisplay(_display);
|
XCloseDisplay(this->MainDisplay);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::loop() {
|
void WindowManager::loop() {
|
||||||
while (XNextEvent(_display, &event) != 0);
|
while (isWindowOpen) {
|
||||||
|
XEvent GeneralEvent = {};
|
||||||
|
XNextEvent(this->MainDisplay, &GeneralEvent);
|
||||||
|
|
||||||
|
switch(GeneralEvent.type) {
|
||||||
|
case KeyPress:
|
||||||
|
case KeyRelease:
|
||||||
|
{
|
||||||
|
XKeyPressedEvent *event = (XKeyPressedEvent *)&GeneralEvent;
|
||||||
|
if (event->keycode == XKeysymToKeycode(this->MainDisplay, XK_Escape)) {
|
||||||
|
this->isWindowOpen = false;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case ClientMessage: {
|
||||||
|
if (static_cast<Atom>(GeneralEvent.xclient.data.l[0]) == this->wmDelete) {
|
||||||
|
this->isWindowOpen = false;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue