2007-11-27 19:40:25 +00:00
/********************************************************************
2007-04-29 17:35:43 +00:00
KWin - the KDE window manager
This file is part of the KDE project .
Copyright ( C ) 1999 , 2000 Matthias Ettrich < ettrich @ kde . org >
Copyright ( C ) 2003 Lubos Lunak < l . lunak @ kde . org >
2007-11-27 19:40:25 +00:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-04-29 17:35:43 +00:00
/*
This file is for ( very ) small utility functions / classes .
*/
# include "utils.h"
2013-01-07 07:07:27 +00:00
# include <kxerrorhandler.h>
# include <X11/Xatom.h>
2013-03-07 11:55:39 +00:00
# include <KDE/KLocalizedString>
2007-04-29 17:35:43 +00:00
# ifndef KCMRULES
2010-11-10 22:28:15 +00:00
# include <QLabel>
# include <QVBoxLayout>
2007-04-29 17:35:43 +00:00
# include <assert.h>
# include <kdebug.h>
2008-09-21 18:03:59 +00:00
# include <kglobalaccel.h>
2007-04-29 17:35:43 +00:00
# include <kshortcut.h>
# include <kkeyserver.h>
2010-11-10 22:28:15 +00:00
# include <KPushButton>
2007-04-29 17:35:43 +00:00
# include <X11/Xlib.h>
# include <X11/extensions/shape.h>
# include <QX11Info>
2008-09-21 18:03:59 +00:00
# include <QtGui/QKeySequence>
2007-04-29 17:35:43 +00:00
# include <stdio.h>
# include "atoms.h"
2013-02-19 10:25:46 +00:00
# include "cursor.h"
2007-04-29 17:35:43 +00:00
# include "notifications.h"
# include "workspace.h"
# endif
namespace KWin
{
# ifndef KCMRULES
2009-02-17 15:50:00 +00:00
//************************************
// StrutRect
//************************************
2011-01-30 14:34:42 +00:00
StrutRect : : StrutRect ( QRect rect , StrutArea area )
: QRect ( rect )
, m_area ( area )
{
}
2009-02-17 15:50:00 +00:00
2011-01-30 14:34:42 +00:00
StrutRect : : StrutRect ( const StrutRect & other )
: QRect ( other )
, m_area ( other . area ( ) )
{
}
2009-02-17 15:50:00 +00:00
//************************************
// Motif
//************************************
2011-01-30 14:34:42 +00:00
void Motif : : readFlags ( WId w , bool & got_noborder , bool & noborder ,
bool & resize , bool & move , bool & minimize , bool & maximize , bool & close )
{
2007-04-29 17:35:43 +00:00
Atom type ;
int format ;
unsigned long length , after ;
unsigned char * data ;
MwmHints * hints = 0 ;
2011-01-30 14:34:42 +00:00
if ( XGetWindowProperty ( display ( ) , w , atoms - > motif_wm_hints , 0 , 5 ,
false , atoms - > motif_wm_hints , & type , & format ,
& length , & after , & data ) = = Success ) {
if ( data )
2007-04-29 17:35:43 +00:00
hints = ( MwmHints * ) data ;
2011-01-30 14:34:42 +00:00
}
2009-10-03 14:32:24 +00:00
got_noborder = false ;
2007-04-29 17:35:43 +00:00
noborder = false ;
resize = true ;
move = true ;
minimize = true ;
maximize = true ;
close = true ;
2011-01-30 14:34:42 +00:00
if ( hints ) {
// To quote from Metacity 'We support those MWM hints deemed non-stupid'
if ( hints - > flags & MWM_HINTS_FUNCTIONS ) {
2007-04-29 17:35:43 +00:00
// if MWM_FUNC_ALL is set, other flags say what to turn _off_
2011-01-30 14:34:42 +00:00
bool set_value = ( ( hints - > functions & MWM_FUNC_ALL ) = = 0 ) ;
2007-04-29 17:35:43 +00:00
resize = move = minimize = maximize = close = ! set_value ;
2011-01-30 14:34:42 +00:00
if ( hints - > functions & MWM_FUNC_RESIZE )
2007-04-29 17:35:43 +00:00
resize = set_value ;
2011-01-30 14:34:42 +00:00
if ( hints - > functions & MWM_FUNC_MOVE )
2007-04-29 17:35:43 +00:00
move = set_value ;
2011-01-30 14:34:42 +00:00
if ( hints - > functions & MWM_FUNC_MINIMIZE )
2007-04-29 17:35:43 +00:00
minimize = set_value ;
2011-01-30 14:34:42 +00:00
if ( hints - > functions & MWM_FUNC_MAXIMIZE )
2007-04-29 17:35:43 +00:00
maximize = set_value ;
2011-01-30 14:34:42 +00:00
if ( hints - > functions & MWM_FUNC_CLOSE )
2007-04-29 17:35:43 +00:00
close = set_value ;
2011-01-30 14:34:42 +00:00
}
if ( hints - > flags & MWM_HINTS_DECORATIONS ) {
2009-10-03 14:32:24 +00:00
got_noborder = true ;
noborder = ! hints - > decorations ;
2007-04-29 17:35:43 +00:00
}
2011-01-30 14:34:42 +00:00
XFree ( data ) ;
2007-04-29 17:35:43 +00:00
}
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
//************************************
// KWinSelectionOwner
//************************************
2011-01-30 14:34:42 +00:00
KWinSelectionOwner : : KWinSelectionOwner ( int screen_P )
: KSelectionOwner ( make_selection_atom ( screen_P ) , screen_P )
{
}
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
Atom KWinSelectionOwner : : make_selection_atom ( int screen_P )
{
if ( screen_P < 0 )
screen_P = DefaultScreen ( display ( ) ) ;
2007-04-29 17:35:43 +00:00
char tmp [ 30 ] ;
2011-01-30 14:34:42 +00:00
sprintf ( tmp , " WM_S%d " , screen_P ) ;
return XInternAtom ( display ( ) , tmp , False ) ;
}
2007-04-29 17:35:43 +00:00
void KWinSelectionOwner : : getAtoms ( )
2011-01-30 14:34:42 +00:00
{
2007-04-29 17:35:43 +00:00
KSelectionOwner : : getAtoms ( ) ;
2011-01-30 14:34:42 +00:00
if ( xa_version = = None ) {
2007-04-29 17:35:43 +00:00
Atom atoms [ 1 ] ;
const char * const names [ ] =
2011-01-30 14:34:42 +00:00
{ " VERSION " } ;
XInternAtoms ( display ( ) , const_cast < char * * > ( names ) , 1 , False , atoms ) ;
2007-04-29 17:35:43 +00:00
xa_version = atoms [ 0 ] ;
}
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
void KWinSelectionOwner : : replyTargets ( Atom property_P , Window requestor_P )
{
KSelectionOwner : : replyTargets ( property_P , requestor_P ) ;
2007-04-29 17:35:43 +00:00
Atom atoms [ 1 ] = { xa_version } ;
// PropModeAppend !
2011-01-30 14:34:42 +00:00
XChangeProperty ( display ( ) , requestor_P , property_P , XA_ATOM , 32 , PropModeAppend ,
reinterpret_cast < unsigned char * > ( atoms ) , 1 ) ;
}
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
bool KWinSelectionOwner : : genericReply ( Atom target_P , Atom property_P , Window requestor_P )
{
if ( target_P = = xa_version ) {
2007-04-29 17:35:43 +00:00
long version [ ] = { 2 , 0 } ;
2011-01-30 14:34:42 +00:00
XChangeProperty ( display ( ) , requestor_P , property_P , XA_INTEGER , 32 ,
PropModeReplace , reinterpret_cast < unsigned char * > ( & version ) , 2 ) ;
} else
return KSelectionOwner : : genericReply ( target_P , property_P , requestor_P ) ;
return true ;
}
2007-04-29 17:35:43 +00:00
Atom KWinSelectionOwner : : xa_version = None ;
2013-01-07 07:07:27 +00:00
# endif
2007-04-29 17:35:43 +00:00
QByteArray getStringProperty ( WId w , Atom prop , char separator )
2011-01-30 14:34:42 +00:00
{
2007-04-29 17:35:43 +00:00
Atom type ;
int format , status ;
unsigned long nitems = 0 ;
unsigned long extra = 0 ;
unsigned char * data = 0 ;
QByteArray result = " " ;
KXErrorHandler handler ; // ignore errors
2011-01-30 14:34:42 +00:00
status = XGetWindowProperty ( display ( ) , w , prop , 0 , 10000 ,
false , XA_STRING , & type , & format ,
& nitems , & extra , & data ) ;
if ( status = = Success ) {
if ( data & & separator ) {
for ( int i = 0 ; i < ( int ) nitems ; i + + )
if ( ! data [ i ] & & i + 1 < ( int ) nitems )
2007-04-29 17:35:43 +00:00
data [ i ] = separator ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
if ( data )
result = ( const char * ) data ;
XFree ( data ) ;
}
2011-01-30 14:34:42 +00:00
return result ;
}
2007-04-29 17:35:43 +00:00
2013-01-07 07:07:27 +00:00
# ifndef KCMRULES
2007-04-29 17:35:43 +00:00
static Time next_x_time ;
2011-01-30 14:34:42 +00:00
static Bool update_x_time_predicate ( Display * , XEvent * event , XPointer )
2007-04-29 17:35:43 +00:00
{
2011-01-30 14:34:42 +00:00
if ( next_x_time ! = CurrentTime )
2007-04-29 17:35:43 +00:00
return False ;
// from qapplication_x11.cpp
2011-01-30 14:34:42 +00:00
switch ( event - > type ) {
2007-04-29 17:35:43 +00:00
case ButtonPress :
2011-01-30 14:34:42 +00:00
// fallthrough intended
2007-04-29 17:35:43 +00:00
case ButtonRelease :
2011-01-30 14:34:42 +00:00
next_x_time = event - > xbutton . time ;
break ;
2007-04-29 17:35:43 +00:00
case MotionNotify :
2011-01-30 14:34:42 +00:00
next_x_time = event - > xmotion . time ;
break ;
2007-04-29 17:35:43 +00:00
case KeyPress :
2011-01-30 14:34:42 +00:00
// fallthrough intended
2007-04-29 17:35:43 +00:00
case KeyRelease :
2011-01-30 14:34:42 +00:00
next_x_time = event - > xkey . time ;
break ;
2007-04-29 17:35:43 +00:00
case PropertyNotify :
2011-01-30 14:34:42 +00:00
next_x_time = event - > xproperty . time ;
break ;
2007-04-29 17:35:43 +00:00
case EnterNotify :
case LeaveNotify :
2011-01-30 14:34:42 +00:00
next_x_time = event - > xcrossing . time ;
break ;
2007-04-29 17:35:43 +00:00
case SelectionClear :
2011-01-30 14:34:42 +00:00
next_x_time = event - > xselectionclear . time ;
break ;
2007-04-29 17:35:43 +00:00
default :
2011-01-30 14:34:42 +00:00
break ;
2007-04-29 17:35:43 +00:00
}
return False ;
}
/*
Updates xTime ( ) . This used to simply fetch current timestamp from the server ,
but that can cause xTime ( ) to be newer than timestamp of events that are
still in our events queue , thus e . g . making XSetInputFocus ( ) caused by such
event to be ignored . Therefore events queue is searched for first
event with timestamp , and extra PropertyNotify is generated in order to make
sure such event is found .
*/
void updateXTime ( )
2011-01-30 14:34:42 +00:00
{
2007-04-29 17:35:43 +00:00
static QWidget * w = 0 ;
2011-01-30 14:34:42 +00:00
if ( ! w )
2007-04-29 17:35:43 +00:00
w = new QWidget ;
long data = 1 ;
XChangeProperty ( display ( ) , w - > winId ( ) , atoms - > kwin_running , atoms - > kwin_running , 32 ,
2011-01-30 14:34:42 +00:00
PropModeAppend , ( unsigned char * ) & data , 1 ) ;
2007-04-29 17:35:43 +00:00
next_x_time = CurrentTime ;
XEvent dummy ;
2011-01-30 14:34:42 +00:00
XCheckIfEvent ( display ( ) , & dummy , update_x_time_predicate , NULL ) ;
if ( next_x_time = = CurrentTime ) {
XSync ( display ( ) , False ) ;
XCheckIfEvent ( display ( ) , & dummy , update_x_time_predicate , NULL ) ;
2007-04-29 17:35:43 +00:00
}
2011-01-30 14:34:42 +00:00
assert ( next_x_time ! = CurrentTime ) ;
QX11Info : : setAppTime ( next_x_time ) ;
XEvent ev ; // remove the PropertyNotify event from the events queue
XWindowEvent ( display ( ) , w - > winId ( ) , PropertyChangeMask , & ev ) ;
}
2007-04-29 17:35:43 +00:00
static int server_grab_count = 0 ;
void grabXServer ( )
2011-01-30 14:34:42 +00:00
{
if ( + + server_grab_count = = 1 )
XGrabServer ( display ( ) ) ;
}
2007-04-29 17:35:43 +00:00
void ungrabXServer ( )
2011-01-30 14:34:42 +00:00
{
assert ( server_grab_count > 0 ) ;
if ( - - server_grab_count = = 0 ) {
XUngrabServer ( display ( ) ) ;
XFlush ( display ( ) ) ;
2007-04-29 17:35:43 +00:00
Notify : : sendPendingEvents ( ) ;
}
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
bool grabbedXServer ( )
2011-01-30 14:34:42 +00:00
{
2007-04-29 17:35:43 +00:00
return server_grab_count > 0 ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
static bool keyboard_grabbed = false ;
2011-01-30 14:34:42 +00:00
bool grabXKeyboard ( Window w )
{
if ( QWidget : : keyboardGrabber ( ) ! = NULL )
2007-04-29 17:35:43 +00:00
return false ;
2011-01-30 14:34:42 +00:00
if ( keyboard_grabbed )
2007-04-29 17:35:43 +00:00
return false ;
2011-01-30 14:34:42 +00:00
if ( qApp - > activePopupWidget ( ) ! = NULL )
2007-04-29 17:35:43 +00:00
return false ;
2011-01-30 14:34:42 +00:00
if ( w = = None )
2007-04-29 17:35:43 +00:00
w = rootWindow ( ) ;
2011-01-30 14:34:42 +00:00
if ( XGrabKeyboard ( display ( ) , w , False ,
GrabModeAsync , GrabModeAsync , xTime ( ) ) ! = GrabSuccess )
2007-04-29 17:35:43 +00:00
return false ;
keyboard_grabbed = true ;
return true ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
void ungrabXKeyboard ( )
2011-01-30 14:34:42 +00:00
{
if ( ! keyboard_grabbed ) {
// grabXKeyboard() may fail sometimes, so don't fail, but at least warn anyway
2008-11-17 15:04:52 +00:00
kDebug ( 1212 ) < < " ungrabXKeyboard() called but keyboard not grabbed! " ;
2007-04-29 17:35:43 +00:00
}
2011-01-30 14:34:42 +00:00
keyboard_grabbed = false ;
XUngrabKeyboard ( display ( ) , CurrentTime ) ;
}
2007-04-29 17:35:43 +00:00
QPoint cursorPos ( )
2011-01-30 14:34:42 +00:00
{
2013-02-19 10:25:46 +00:00
return Cursor : : self ( ) - > pos ( ) ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
// converting between X11 mouse/keyboard state mask and Qt button/keyboard states
2011-01-30 14:34:42 +00:00
int qtToX11Button ( Qt : : MouseButton button )
{
if ( button = = Qt : : LeftButton )
2007-04-29 17:35:43 +00:00
return Button1 ;
2011-01-30 14:34:42 +00:00
else if ( button = = Qt : : MidButton )
2007-04-29 17:35:43 +00:00
return Button2 ;
2011-01-30 14:34:42 +00:00
else if ( button = = Qt : : RightButton )
2007-04-29 17:35:43 +00:00
return Button3 ;
return AnyButton ; // 0
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
Qt : : MouseButton x11ToQtMouseButton ( int button )
{
if ( button = = Button1 )
2007-04-29 17:35:43 +00:00
return Qt : : LeftButton ;
2011-01-30 14:34:42 +00:00
if ( button = = Button2 )
2007-04-29 17:35:43 +00:00
return Qt : : MidButton ;
2011-01-30 14:34:42 +00:00
if ( button = = Button3 )
2007-04-29 17:35:43 +00:00
return Qt : : RightButton ;
2011-01-30 14:34:42 +00:00
if ( button = = Button4 )
2009-02-06 09:45:34 +00:00
return Qt : : XButton1 ;
2011-01-30 14:34:42 +00:00
if ( button = = Button5 )
2009-02-06 09:45:34 +00:00
return Qt : : XButton2 ;
2007-04-29 17:35:43 +00:00
return Qt : : NoButton ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
int qtToX11State ( Qt : : MouseButtons buttons , Qt : : KeyboardModifiers modifiers )
{
2007-04-29 17:35:43 +00:00
int ret = 0 ;
2011-01-30 14:34:42 +00:00
if ( buttons & Qt : : LeftButton )
2007-04-29 17:35:43 +00:00
ret | = Button1Mask ;
2011-01-30 14:34:42 +00:00
if ( buttons & Qt : : MidButton )
2007-04-29 17:35:43 +00:00
ret | = Button2Mask ;
2011-01-30 14:34:42 +00:00
if ( buttons & Qt : : RightButton )
2007-04-29 17:35:43 +00:00
ret | = Button3Mask ;
2011-01-30 14:34:42 +00:00
if ( modifiers & Qt : : ShiftModifier )
2007-04-29 17:35:43 +00:00
ret | = ShiftMask ;
2011-01-30 14:34:42 +00:00
if ( modifiers & Qt : : ControlModifier )
2007-04-29 17:35:43 +00:00
ret | = ControlMask ;
2011-01-30 14:34:42 +00:00
if ( modifiers & Qt : : AltModifier )
2007-04-29 17:35:43 +00:00
ret | = KKeyServer : : modXAlt ( ) ;
2011-01-30 14:34:42 +00:00
if ( modifiers & Qt : : MetaModifier )
2007-04-29 17:35:43 +00:00
ret | = KKeyServer : : modXMeta ( ) ;
return ret ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
Qt : : MouseButtons x11ToQtMouseButtons ( int state )
{
2007-04-29 17:35:43 +00:00
Qt : : MouseButtons ret = 0 ;
2011-01-30 14:34:42 +00:00
if ( state & Button1Mask )
2007-04-29 17:35:43 +00:00
ret | = Qt : : LeftButton ;
2011-01-30 14:34:42 +00:00
if ( state & Button2Mask )
2007-04-29 17:35:43 +00:00
ret | = Qt : : MidButton ;
2011-01-30 14:34:42 +00:00
if ( state & Button3Mask )
2007-04-29 17:35:43 +00:00
ret | = Qt : : RightButton ;
2011-01-30 14:34:42 +00:00
if ( state & Button4Mask )
2009-02-06 09:45:34 +00:00
ret | = Qt : : XButton1 ;
2011-01-30 14:34:42 +00:00
if ( state & Button5Mask )
2009-02-06 09:45:34 +00:00
ret | = Qt : : XButton2 ;
2007-04-29 17:35:43 +00:00
return ret ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
2011-01-30 14:34:42 +00:00
Qt : : KeyboardModifiers x11ToQtKeyboardModifiers ( int state )
{
2007-04-29 17:35:43 +00:00
Qt : : KeyboardModifiers ret = 0 ;
2011-01-30 14:34:42 +00:00
if ( state & ShiftMask )
2007-04-29 17:35:43 +00:00
ret | = Qt : : ShiftModifier ;
2011-01-30 14:34:42 +00:00
if ( state & ControlMask )
2007-04-29 17:35:43 +00:00
ret | = Qt : : ControlModifier ;
2011-01-30 14:34:42 +00:00
if ( state & KKeyServer : : modXAlt ( ) )
2007-04-29 17:35:43 +00:00
ret | = Qt : : AltModifier ;
2011-01-30 14:34:42 +00:00
if ( state & KKeyServer : : modXMeta ( ) )
2007-04-29 17:35:43 +00:00
ret | = Qt : : MetaModifier ;
return ret ;
2011-01-30 14:34:42 +00:00
}
2007-04-29 17:35:43 +00:00
# endif
# ifndef KCMRULES
2011-01-30 14:34:42 +00:00
ShortcutDialog : : ShortcutDialog ( const QKeySequence & cut )
2010-11-10 22:28:15 +00:00
: _shortcut ( cut )
2011-01-30 14:34:42 +00:00
{
QWidget * vBoxContainer = new QWidget ( this ) ;
vBoxContainer - > setLayout ( new QVBoxLayout ( vBoxContainer ) ) ;
vBoxContainer - > layout ( ) - > addWidget ( widget = new KKeySequenceWidget ( vBoxContainer ) ) ;
vBoxContainer - > layout ( ) - > addWidget ( warning = new QLabel ( vBoxContainer ) ) ;
2010-11-10 22:28:15 +00:00
warning - > hide ( ) ;
2011-01-30 14:34:42 +00:00
widget - > setKeySequence ( cut ) ;
2008-09-21 18:03:59 +00:00
// To not check for conflicting shortcuts. The widget would use a message
// box which brings down kwin.
widget - > setCheckForConflictsAgainst ( KKeySequenceWidget : : None ) ;
2008-11-10 00:03:17 +00:00
// It's a global shortcut so don't allow multikey shortcuts
widget - > setMultiKeyShortcutsAllowed ( false ) ;
2008-09-21 18:03:59 +00:00
// Listen to changed shortcuts
connect (
2011-08-17 21:51:55 +00:00
widget , SIGNAL ( keySequenceChanged ( QKeySequence ) ) ,
SLOT ( keySequenceChanged ( QKeySequence ) ) ) ;
2008-09-21 18:03:59 +00:00
2011-01-30 14:34:42 +00:00
setMainWidget ( vBoxContainer ) ;
2010-11-10 22:28:15 +00:00
widget - > setFocus ( ) ;
2008-09-21 18:03:59 +00:00
2007-04-29 17:35:43 +00:00
// make it a popup, so that it has the grab
XSetWindowAttributes attrs ;
attrs . override_redirect = True ;
2011-01-30 14:34:42 +00:00
XChangeWindowAttributes ( display ( ) , winId ( ) , CWOverrideRedirect , & attrs ) ;
setWindowFlags ( Qt : : Popup ) ;
}
2007-04-29 17:35:43 +00:00
void ShortcutDialog : : accept ( )
2011-01-30 14:34:42 +00:00
{
2007-11-01 19:24:35 +00:00
QKeySequence seq = shortcut ( ) ;
2011-01-30 14:34:42 +00:00
if ( ! seq . isEmpty ( ) ) {
if ( seq [ 0 ] = = Qt : : Key_Escape ) {
2007-04-29 17:35:43 +00:00
reject ( ) ;
return ;
2011-01-30 14:34:42 +00:00
}
if ( seq [ 0 ] = = Qt : : Key_Space
| | ( seq [ 0 ] & Qt : : KeyboardModifierMask ) = = 0 ) {
// clear
2007-11-01 19:24:35 +00:00
widget - > clearKeySequence ( ) ;
KDialog : : accept ( ) ;
2007-04-29 17:35:43 +00:00
return ;
}
2007-11-01 19:24:35 +00:00
}
2011-01-30 14:34:42 +00:00
KDialog : : accept ( ) ;
}
2007-11-01 19:24:35 +00:00
2011-01-30 14:34:42 +00:00
void ShortcutDialog : : done ( int r )
{
KDialog : : done ( r ) ;
emit dialogDone ( r = = Accepted ) ;
}
2007-11-01 19:24:35 +00:00
2008-09-21 18:03:59 +00:00
void ShortcutDialog : : keySequenceChanged ( const QKeySequence & seq )
2011-01-30 14:34:42 +00:00
{
2010-11-10 22:28:15 +00:00
activateWindow ( ) ; // where is the kbd focus lost? cause of popup state?
if ( _shortcut = = seq )
return ; // don't try to update the same
2012-03-18 16:29:14 +00:00
if ( seq . isEmpty ( ) ) { // clear
_shortcut = seq ;
return ;
}
2008-09-21 18:03:59 +00:00
// Check if the key sequence is used currently
2010-11-10 22:28:15 +00:00
QString sc = seq . toString ( ) ;
// NOTICE - seq.toString() & the entries in "conflicting" randomly get invalidated after the next call (if no sc has been set & conflicting isn't empty?!)
2008-11-10 00:03:17 +00:00
QList < KGlobalShortcutInfo > conflicting = KGlobalAccel : : getGlobalShortcutsByKey ( seq ) ;
2011-01-30 14:34:42 +00:00
if ( ! conflicting . isEmpty ( ) ) {
2010-11-10 22:28:15 +00:00
const KGlobalShortcutInfo & conflict = conflicting . at ( 0 ) ;
warning - > setText ( i18nc ( " '%1' is a keyboard shortcut like 'ctrl+w' " ,
2011-01-30 14:34:42 +00:00
" <b>%1</b> is already in use " , sc ) ) ;
2010-11-10 22:28:15 +00:00
warning - > setToolTip ( i18nc ( " keyboard shortcut '%1' is used by action '%2' in application '%3' " ,
2011-01-30 14:34:42 +00:00
" <b>%1</b> is used by %2 in %3 " , sc , conflict . friendlyName ( ) , conflict . componentFriendlyName ( ) ) ) ;
2010-11-10 22:28:15 +00:00
warning - > show ( ) ;
2008-09-21 18:03:59 +00:00
widget - > setKeySequence ( shortcut ( ) ) ;
2011-01-30 14:34:42 +00:00
} else if ( seq ! = _shortcut ) {
2010-11-10 22:28:15 +00:00
warning - > hide ( ) ;
2011-01-30 14:34:42 +00:00
if ( KPushButton * ok = button ( KDialog : : Ok ) )
2010-11-10 22:28:15 +00:00
ok - > setFocus ( ) ;
2008-09-21 18:03:59 +00:00
}
2011-01-30 14:34:42 +00:00
_shortcut = seq ;
}
2007-11-01 19:24:35 +00:00
QKeySequence ShortcutDialog : : shortcut ( ) const
2011-01-30 14:34:42 +00:00
{
2008-09-21 18:03:59 +00:00
return _shortcut ;
2011-01-30 14:34:42 +00:00
}
2007-11-01 19:24:35 +00:00
2007-04-29 17:35:43 +00:00
# endif //KCMRULES
} // namespace
# ifndef KCMRULES
# include "utils.moc"
# endif