////////////////////////////////////////////////////////////////////////////// // x11util.cpp // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "x11util.h" namespace Oxygen { //________________________________________________________________________ X11Util& X11Util::get( void ) { static X11Util singleton; return singleton; } //________________________________________________________________________ X11Util::X11Util( void ) { initializeAtomNames(); } //________________________________________________________________________ bool X11Util::isSupported( const Atoms& atom ) { SupportedAtomMap::const_iterator iter( supportedAtoms().find( atom ) ); if( iter != supportedAtoms().end() ) return iter->second; Display* display( QX11Info::display() ); Atom net_supported( findAtom( _NET_SUPPORTED ) ); Atom searched( findAtom( atom ) ); Atom type; int format; unsigned char *data; unsigned long count; unsigned long unused; // get window property if( XGetWindowProperty( display, QX11Info::appRootWindow(), net_supported, 0l, 2048l, false, XA_ATOM, &type, &format, &count, &unused, (unsigned char **) &data) != Success ) { return false; } if( type != XA_ATOM || format != 32 || count <= 0 || data == None ) { return false; } long *states = (long *) data; bool found = false; static bool first( true ); for( unsigned long i = 0; isecond; // create atom if not found Display* display( QX11Info::display() ); Atom out( XInternAtom(display, qPrintable( atomNames_[atom] ), false ) ); atoms_[atom] = out; return out; } }