Advertisement
Guest User

src/MyWindow.cpp

a guest
Feb 13th, 2011
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #include "../include/MyWindow.h"
  2. #include <string>
  3. #include <iostream>
  4. #include <X11/Xlib.h>
  5.  
  6. int MyWindow::default_width = 400;
  7. int MyWindow::default_height = 400;
  8. std::string MyWindow::default_caption = "Hello World!";
  9.  
  10. MyWindow::MyWindow()
  11. { //ctor
  12. Display* display = XOpenDisplay(NULL);
  13. Visual* visual = XDefaultVisual(display, 0);
  14. int depth = XDefaultDepth(display, 0);
  15. XSetWindowAttributes attributes;
  16. Window window = XCreateWindow(display, XRootWindow(display, 0), 0, 0, MyWindow::default_width, MyWindow::default_height, 16, depth, InputOutput, visual, CWBackPixel, &attributes);
  17. XStoreName(display, window, MyWindow::default_caption.c_str());
  18. XSelectInput(display, window, ExposureMask | KeyPressMask | KeyReleaseMask);
  19. }
  20.  
  21. MyWindow::~MyWindow()
  22. { //dtor
  23. }
  24.  
  25. void MyWindow::loop()
  26. {
  27. XEvent event;
  28. while (true) {
  29. XNextEvent(display, &event);
  30. switch(event.type) {
  31. case Expose: {
  32. std::cout << "draw" << std::endl;
  33. break;
  34. }
  35. case KeyPress: {
  36. std::cout << "Key Pressed: " << event.xkey.keycode << std::endl;
  37. break;
  38. }
  39. case KeyRelease: {
  40. std::cout << "Key Released: " << event.xkey.keycode << std::endl;
  41. break;
  42. }
  43. default: {break;}
  44. }
  45. }
  46. }
  47.  
  48. void MyWindow::show() {
  49. XMapWindow(display, window);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement