3 Dialog class that handles input focus in absence of a wm
5 Copyright (C) 1997, 1998 Steffen Hansen <hansen@kde.org>
6 Copyright (C) 2000-2003 Oswald Buddenhagen <ossi@kde.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include "kdmconfig.h"
27 #include "kdm_greet.h"
30 #include <KPushButton>
32 #include <QApplication>
33 #include <QDesktopWidget>
35 #include <QGridLayout>
37 #include <QMouseEvent>
44 FDialog::FDialog( QWidget
*parent
, bool framed
)
45 : inherited( parent
/*, framed ? 0 : WStyle_NoBorder*/ )
49 winFrame
= new QFrame( this );
50 winFrame
->setFrameStyle( QFrame::WinPanel
| QFrame::Raised
);
51 winFrame
->setLineWidth( 2 );
57 FDialog::resizeEvent( QResizeEvent
*e
)
59 inherited::resizeEvent( e
);
61 winFrame
->resize( size() );
65 FDialog::fitInto( const QRect
&scr
, QRect
&grt
)
68 if ((di
= scr
.right() - grt
.right()) < 0)
69 grt
.translate( di
, 0 );
70 if ((di
= scr
.left() - grt
.left()) > 0)
71 grt
.translate( di
, 0 );
72 if ((di
= scr
.bottom() - grt
.bottom()) < 0)
73 grt
.translate( 0, di
);
74 if ((di
= scr
.top() - grt
.top()) > 0)
75 grt
.translate( 0, di
);
79 FDialog::adjustGeometry()
81 QDesktopWidget
*dsk
= qApp
->desktop();
83 QRect scr
= dsk
->screenGeometry( _greeterScreen
);
85 setFixedSize( scr
.size() );
87 setMaximumSize( scr
.size() * .9 );
88 setMinimumSize( 0, 0 );
97 unsigned x
= 50, y
= 50;
98 sscanf( _greeterPos
, "%u,%u", &x
, &y
);
99 grt
.moveCenter( QPoint( scr
.x() + scr
.width() * x
/ 100,
100 scr
.y() + scr
.height() * y
/ 100 ) );
105 if (dsk
->screenNumber( QCursor::pos() ) != _greeterScreen
)
106 QCursor::setPos( grt
.center() );
110 fakeFocusIn( WId window
)
112 // We have keyboard grab, so this application will
113 // get keyboard events even without having focus.
114 // Fake FocusIn to make Qt realize it has the active
115 // window, so that it will correctly show cursor in the dialog.
117 memset( &ev
, 0, sizeof(ev
) );
118 ev
.xfocus
.display
= QX11Info::display();
119 ev
.xfocus
.type
= FocusIn
;
120 ev
.xfocus
.window
= window
;
121 ev
.xfocus
.mode
= NotifyNormal
;
122 ev
.xfocus
.detail
= NotifyAncestor
;
123 XSendEvent( QX11Info::display(), window
, False
, NoEventMask
, &ev
);
129 static QWidget
*current
;
133 secureInputs( QX11Info::display() );
135 qApp
->processEvents();
136 fakeFocusIn( winId() );
137 QWidget
*previous
= current
;
142 fakeFocusIn( current
->winId() );
144 unsecureInputs( QX11Info::display() );
148 KFMsgBox::KFMsgBox( QWidget
*parent
, QMessageBox::Icon type
, const QString
&text
)
149 : inherited( parent
)
151 QLabel
*label1
= new QLabel( this );
152 label1
->setPixmap( QMessageBox::standardIcon( type
) );
153 QLabel
*label2
= new QLabel( text
, this );
154 KPushButton
*button
= new KPushButton( KStandardGuiItem::ok(), this );
155 button
->setDefault( true );
156 button
->setSizePolicy( QSizePolicy( QSizePolicy::Preferred
, QSizePolicy::Preferred
) );
157 connect( button
, SIGNAL(clicked()), SLOT(accept()) );
159 QGridLayout
*grid
= new QGridLayout( this );
160 grid
->addWidget( label1
, 0, 0, Qt::AlignCenter
);
161 grid
->addWidget( label2
, 0, 1, Qt::AlignCenter
);
162 grid
->addWidget( button
, 1, 0, 1, 2, Qt::AlignCenter
);
166 KFMsgBox::box( QWidget
*parent
, QMessageBox::Icon type
, const QString
&text
)
168 KFMsgBox
dlg( parent
, type
, text
.trimmed() );