CmOSCursorImpl.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "X11/CmOSCursorImpl.h"
  2. // TODO - Not tested and will not work until I properly test it on a unix system!
  3. namespace CamelotEngine
  4. {
  5. OSCursor()
  6. :mCursorGrabbed(false), mCursorHidden(false)
  7. {
  8. mDisplay = XOpenDisplay(0); // TODO - What if there are multiple displays? Need to check for that
  9. mWindow = XRootWindow(mDisplay, 0);
  10. mCursor = createNULLCursor(mDisplay, mWindow); // Create invisible cursor
  11. }
  12. Int2 OSCursor::getPosition()
  13. {
  14. Window returnedWindow;
  15. int rootX, rootY;
  16. int winX, winY;
  17. unsigned int returnedMask;
  18. XQueryPointer(mDisplay, mWindow, &returnedWindow,
  19. &returnedWindow, &rootX, &rootY, &winX, &winY,
  20. &returnedMask)
  21. return Int2(rootX, rootY);
  22. }
  23. void OSCursor::setPosition(const Int2& pos)
  24. {
  25. XWarpPointer(mDisplay, None, mWindow, 0,0,0,0, pos.x, pos.y);
  26. XFlush(mDisplay);
  27. }
  28. void OSCursor::hide()
  29. {
  30. // Hide cursor
  31. if(!mCursorHidden)
  32. {
  33. XDefineCursor(mDisplay, mWindow, mCursor );
  34. mCursorHidden = true;
  35. }
  36. // Grab cursor to user window
  37. if(!mCursorGrabbed)
  38. {
  39. if( XGrabPointer( mDisplay, mWindow, True,
  40. ButtonPressMask | ButtonReleaseMask |
  41. PointerMotionMask, GrabModeAsync, GrabModeAsync,
  42. mWindow, None, CurrentTime ) ==
  43. GrabSuccess )
  44. {
  45. mCursorGrabbed = true;
  46. }
  47. }
  48. }
  49. void OSCursor::show()
  50. {
  51. // Un-grab cursor (only in windowed mode: in fullscreen mode we still
  52. // want the mouse grabbed in order to confine the cursor to the window
  53. // area)
  54. if(mCursorGrabbed)
  55. {
  56. XUngrabPointer(mDisplay, CurrentTime);
  57. mCursorGrabbed = false;
  58. }
  59. // Show cursor
  60. if(mCursorHidden)
  61. {
  62. XUndefineCursor(mDisplay, mWindow);
  63. mCursorHidden = GL_FALSE;
  64. }
  65. }
  66. }