VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gxcapture.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file gxcapture.h
19 ///
20 
21 #ifndef GX_CAPTURE__H
22 #define GX_CAPTURE__H
23 
24 #include "gdef.h"
25 #include "gxdef.h"
26 
27 namespace GX
28 {
29  class Window ;
30  class Capture ;
31 }
32 
33 /// \class GX::Capture
34 /// RAII class to capture Xlib mouse events.
35 /// See also GX::Window::capture().
36 ///
38 {
39 public:
40  ~Capture() ;
41  ///< Destructor. Releases mouse capture.
42 
43 private:
44  friend class GX::Window ;
45  Capture( ::Display * , ::Window ) ;
46  ///< Constructor. Starts mouse capture.
47 
48 private:
49  Capture( const Capture & ) ;
50  void operator=( const Capture & ) ;
51 
52 private:
53  bool m_ok ;
54  ::Display * m_display ;
55 } ;
56 
57 inline
58 GX::Capture::Capture( ::Display * display , ::Window window ) :
59  m_ok(false) ,
60  m_display(display)
61 {
62  m_ok = GrabSuccess == ::XGrabPointer( display ,
63  window , // grab_window
64  True , // owner_events
65  ButtonReleaseMask | PointerMotionMask , // event_mask
66  GrabModeAsync , // pointer_mode
67  GrabModeAsync , // keyboard_mode
68  window , // confine_to
69  None , // cursor
70  CurrentTime ) ;
71 }
72 
73 inline
75 {
76  if( m_ok )
77  ::XUngrabPointer( m_display , CurrentTime ) ;
78 }
79 
80 #endif
A window class that is-a GX::Drawable and a GX::EventHandler.
Definition: gxwindow.h:47
An Xlib Display wrapper.
Definition: gxdisplay.h:38
RAII class to capture Xlib mouse events.
Definition: gxcapture.h:37
~Capture()
Destructor. Releases mouse capture.
Definition: gxcapture.h:74