• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
kxerrorhandler.cpp
1 /*
2 
3  Copyright (c) 2003 Lubos Lunak <l.lunak@kde.org>
4 
5  Permission is hereby granted, free of charge, to any person obtaining a
6  copy of this software and associated documentation files (the "Software"),
7  to deal in the Software without restriction, including without limitation
8  the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  and/or sell copies of the Software, and to permit persons to whom the
10  Software is furnished to do so, subject to the following conditions:
11 
12  The above copyright notice and this permission notice shall be included in
13  all copies or substantial portions of the Software.
14 
15  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  DEALINGS IN THE SOFTWARE.
22 
23 */
24 
25 #include <tqwidget.h>
26 #ifdef Q_WS_X11 //FIXME
27 
28 #include "kxerrorhandler.h"
29 #include <assert.h>
30 #include <stdlib.h>
31 #include <netwm_def.h>
32 
33 KXErrorHandler** KXErrorHandler::handlers = NULL;
34 int KXErrorHandler::pos = 0;
35 int KXErrorHandler::size = 0;
36 
37 KXErrorHandler::KXErrorHandler( Display* dpy )
38  : user_handler1( NULL ),
39  user_handler2( NULL ),
40  old_handler( XSetErrorHandler( handler_wrapper )),
41  first_request( XNextRequest( dpy )),
42  display( dpy ),
43  was_error( false )
44  {
45  addHandler();
46  }
47 
48 KXErrorHandler::KXErrorHandler( bool (*handler)( int request, int error_code, unsigned long resource_id ), Display* dpy )
49  : user_handler1( handler ),
50  user_handler2( NULL ),
51  old_handler( XSetErrorHandler( handler_wrapper )),
52  first_request( XNextRequest( dpy )),
53  display( dpy ),
54  was_error( false )
55  {
56  addHandler();
57  }
58 
59 KXErrorHandler::KXErrorHandler( int (*handler)( Display*, XErrorEvent* ), Display* dpy )
60  : user_handler1( NULL ),
61  user_handler2( handler ),
62  old_handler( XSetErrorHandler( handler_wrapper )),
63  first_request( XNextRequest( dpy )),
64  display( dpy ),
65  was_error( false )
66  {
67  addHandler();
68  }
69 
70 KXErrorHandler::~KXErrorHandler()
71  {
72  XSetErrorHandler( old_handler );
73  assert( this == handlers[ pos - 1 ] ); // destroy in reverse order
74  --pos;
75  }
76 
77 void KXErrorHandler::addHandler()
78  {
79  if( size == pos )
80  {
81  size += 16;
82  handlers = static_cast< KXErrorHandler** >( realloc( handlers, size * sizeof( KXErrorHandler* )));
83  }
84  handlers[ pos++ ] = this;
85  }
86 
87 bool KXErrorHandler::error( bool sync ) const
88  {
89  if( sync )
90  XSync( display, False );
91  return was_error;
92  }
93 
94 int KXErrorHandler::handler_wrapper( Display* dpy, XErrorEvent* e )
95  {
96  --pos;
97  int ret = handlers[ pos ]->handle( dpy, e );
98  ++pos;
99  return ret;
100  }
101 
102 int KXErrorHandler::handle( Display* dpy, XErrorEvent* e )
103  {
104  if( dpy == display
105  // e->serial >= first_request , compare like X timestamps to handle wrapping
106  && NET::timestampCompare( e->serial, first_request ) >= 0 )
107  { // it's for us
108  //tqDebug( "Handling: %p", static_cast< void* >( this ));
109  if( user_handler1 != NULL && user_handler1( e->request_code, e->error_code, e->resourceid ))
110  was_error = true;
111  if( user_handler2 != NULL && user_handler2( dpy, e ) != 0 )
112  was_error = true;
113  else // no handler set, simply set that there was an error
114  was_error = true;
115  return 0;
116  }
117  //tqDebug( "Going deeper: %p", static_cast< void* >( this ));
118  return old_handler( dpy, e );
119  }
120 
121 #endif
KXErrorHandler::KXErrorHandler
KXErrorHandler(Display *dpy=tqt_xdisplay())
Creates error handler that will set error flag after encountering any X error.
KXErrorHandler::error
bool error(bool sync) const
This function returns true if the error flag is set (i.e.
KXErrorHandler
This class simplifies handling of X errors.
Definition: kxerrorhandler.h:57
NET::timestampCompare
static int timestampCompare(unsigned long time1, unsigned long time2)
Compares two X timestamps, taking into account wrapping and 64bit architectures.

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.8.8
This website is maintained by Timothy Pearson.