Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "../include/MyWindow.h"
- #include <string>
- #include <iostream>
- #include <X11/Xlib.h>
- int MyWindow::default_width = 400;
- int MyWindow::default_height = 400;
- std::string MyWindow::default_caption = "Hello World!";
- MyWindow::MyWindow()
- { //ctor
- Display* display = XOpenDisplay(NULL);
- Visual* visual = XDefaultVisual(display, 0);
- int depth = XDefaultDepth(display, 0);
- XSetWindowAttributes attributes;
- Window window = XCreateWindow(display, XRootWindow(display, 0), 0, 0, MyWindow::default_width, MyWindow::default_height, 16, depth, InputOutput, visual, CWBackPixel, &attributes);
- XStoreName(display, window, MyWindow::default_caption.c_str());
- XSelectInput(display, window, ExposureMask | KeyPressMask | KeyReleaseMask);
- }
- MyWindow::~MyWindow()
- { //dtor
- }
- void MyWindow::loop()
- {
- XEvent event;
- while (true) {
- XNextEvent(display, &event);
- switch(event.type) {
- case Expose: {
- std::cout << "draw" << std::endl;
- break;
- }
- case KeyPress: {
- std::cout << "Key Pressed: " << event.xkey.keycode << std::endl;
- break;
- }
- case KeyRelease: {
- std::cout << "Key Released: " << event.xkey.keycode << std::endl;
- break;
- }
- default: {break;}
- }
- }
- }
- void MyWindow::show() {
- XMapWindow(display, window);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement