2009-08-24 16:17:15 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// x11util.cpp
|
|
|
|
// -------------------
|
2009-09-09 00:55:55 +00:00
|
|
|
//
|
2009-08-25 04:15:13 +00:00
|
|
|
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
2009-08-24 16:17:15 +00:00
|
|
|
//
|
|
|
|
// 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
|
2009-09-09 00:55:55 +00:00
|
|
|
// IN THE SOFTWARE.
|
2009-08-24 16:17:15 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2009-08-22 08:24:06 +00:00
|
|
|
|
|
|
|
#include "x11util.h"
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace Nitrogen
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//________________________________________________________________________
|
|
|
|
X11Util& X11Util::get( void )
|
|
|
|
{
|
|
|
|
static X11Util singleton;
|
|
|
|
return singleton;
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//________________________________________________________________________
|
|
|
|
X11Util::X11Util( void )
|
2009-09-09 00:55:55 +00:00
|
|
|
{
|
2009-08-22 08:24:06 +00:00
|
|
|
_initializeAtomNames();
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//________________________________________________________________________
|
|
|
|
bool X11Util::isSupported( const Atoms& atom )
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
#ifdef Q_WS_X11
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
SupportedAtomMap::const_iterator iter( _supportedAtoms().find( atom ) );
|
|
|
|
if( iter != _supportedAtoms().end() ) return iter->second;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
Display* display( QX11Info::display() );
|
|
|
|
Atom net_supported( findAtom( _NET_SUPPORTED ) );
|
|
|
|
Atom searched( findAtom( atom ) );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
Atom actual;
|
|
|
|
int format;
|
|
|
|
unsigned char *data;
|
|
|
|
unsigned long offset = 0;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
while( 1 )
|
|
|
|
{
|
|
|
|
unsigned long n, left;
|
|
|
|
XGetWindowProperty( display, QX11Info::appRootWindow(),
|
|
|
|
net_supported, offset, 1L,
|
2009-09-09 00:55:55 +00:00
|
|
|
false, XA_ATOM, &actual,
|
|
|
|
&format, &n, &left,
|
2009-08-22 08:24:06 +00:00
|
|
|
(unsigned char **) &data);
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
if( data == None ) break;
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// try cast data to atom
|
|
|
|
Atom found( *(Atom*)data );
|
2009-09-09 00:55:55 +00:00
|
|
|
|
|
|
|
if( found == searched )
|
2009-08-22 08:24:06 +00:00
|
|
|
{
|
|
|
|
supported_atoms_[atom] = true;
|
|
|
|
return true;
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
if( !left ) break;
|
|
|
|
else offset ++;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
supported_atoms_[atom] = false;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
#endif
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
return false;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//________________________________________________________________________
|
2009-09-09 00:55:55 +00:00
|
|
|
bool X11Util::moveResizeWidget(
|
|
|
|
WId id,
|
2009-08-22 08:24:06 +00:00
|
|
|
int screen,
|
2009-09-09 00:55:55 +00:00
|
|
|
QPoint position,
|
|
|
|
X11Util::Direction direction,
|
2009-08-22 08:24:06 +00:00
|
|
|
Qt::MouseButton button )
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
#ifdef Q_WS_X11
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// check
|
|
|
|
if( !isSupported( _NET_WM_MOVERESIZE ) ) return false;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
Display* display( QX11Info::display() );
|
2009-09-09 00:55:55 +00:00
|
|
|
Atom net_wm_moveresize( findAtom( _NET_WM_MOVERESIZE ) );
|
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
XEvent event;
|
|
|
|
event.xclient.type = ClientMessage;
|
|
|
|
event.xclient.message_type = net_wm_moveresize;
|
|
|
|
event.xclient.display = display;
|
|
|
|
event.xclient.window = id;
|
|
|
|
event.xclient.format = 32;
|
|
|
|
event.xclient.data.l[0] = position.x();
|
|
|
|
event.xclient.data.l[1] = position.y();
|
2009-09-09 00:55:55 +00:00
|
|
|
event.xclient.data.l[2] = direction;
|
2009-08-22 08:24:06 +00:00
|
|
|
event.xclient.data.l[3] = button;
|
|
|
|
event.xclient.data.l[4] = 0;
|
|
|
|
XUngrabPointer( display, QX11Info::appTime() );
|
2009-09-09 00:55:55 +00:00
|
|
|
XSendEvent(display,
|
|
|
|
QX11Info::appRootWindow( screen ),
|
2009-08-22 08:24:06 +00:00
|
|
|
false,
|
|
|
|
SubstructureRedirectMask | SubstructureNotifyMask, &event);
|
|
|
|
return true;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//________________________________________________________________________
|
|
|
|
void X11Util::_initializeAtomNames( void )
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
atom_names_[_NET_SUPPORTED] = "_NET_SUPPORTED";
|
|
|
|
atom_names_[_NET_WM_STATE] = "_NET_WM_STATE";
|
|
|
|
atom_names_[_NET_WM_MOVERESIZE] = "_NET_WM_MOVERESIZE";
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
#ifdef Q_WS_X11
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
//________________________________________________________________________
|
|
|
|
Atom X11Util::findAtom( const Atoms& atom )
|
|
|
|
{
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// find atom in map
|
|
|
|
AtomMap::iterator iter( _atoms().find( atom ) );
|
|
|
|
if( iter != _atoms().end() ) return iter->second;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
// create atom if not found
|
|
|
|
Display* display( QX11Info::display() );
|
|
|
|
Atom out( XInternAtom(display, qPrintable( atom_names_[atom] ), false ) );
|
|
|
|
atoms_[atom] = out;
|
|
|
|
return out;
|
2009-09-09 00:55:55 +00:00
|
|
|
|
2009-08-22 08:24:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|