1
1
/* **************************************************************************
2
- * Copyright (c) 2015 Pier Luigi Fiorini <[email protected] >
2
+ * Copyright (c) 2015-2016 Pier Luigi Fiorini <[email protected] >
3
3
* Copyright (c) 2013 Abdurrahman AVCI <[email protected] >
4
4
*
5
5
* This program is free software; you can redistribute it and/or modify
36
36
#include < QQmlContext>
37
37
#include < QQmlEngine>
38
38
#include < QDebug>
39
+ #include < QTimer>
39
40
#include < QTranslator>
40
41
41
42
#include < iostream>
@@ -135,6 +136,11 @@ namespace SDDM {
135
136
136
137
// handle screens
137
138
connect (this , &GreeterApp::screenAdded, this , &GreeterApp::addViewForScreen);
139
+ #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
140
+ connect (this , &GreeterApp::primaryScreenChanged, this , [this ](QScreen *) {
141
+ activatePrimary ();
142
+ });
143
+ #endif
138
144
}
139
145
140
146
void GreeterApp::addViewForScreen (QScreen *screen) {
@@ -144,6 +150,7 @@ namespace SDDM {
144
150
view->setResizeMode (QQuickView::SizeRootObjectToView);
145
151
// view->setGeometry(QRect(QPoint(0, 0), screen->geometry().size()));
146
152
view->setGeometry (screen->geometry ());
153
+ m_views.append (view);
147
154
148
155
// remove the view when the screen is removed, but we
149
156
// need to be careful here since Qt will move the view to
@@ -201,11 +208,33 @@ namespace SDDM {
201
208
// show
202
209
qDebug () << " Adding view for" << screen->name () << screen->geometry ();
203
210
view->show ();
211
+
212
+ // activate windows for the primary screen to give focus to text fields
213
+ if (QGuiApplication::primaryScreen () == screen)
214
+ view->requestActivate ();
204
215
}
205
216
206
217
void GreeterApp::removeViewForScreen (QQuickView *view) {
218
+ // screen is gone, remove the window
207
219
m_views.removeOne (view);
208
220
view->deleteLater ();
221
+
222
+ #if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
223
+ // starting from Qt 5.6 we are notified when the primary screen is changed
224
+ // and we request activation for the view when we get the signal, with
225
+ // older version we iterate the views and request activation
226
+ activatePrimary ();
227
+ #endif
228
+ }
229
+
230
+ void GreeterApp::activatePrimary () {
231
+ // activate and give focus to the window assigned to the primary screen
232
+ Q_FOREACH (QQuickView *view, m_views) {
233
+ if (view->screen () == QGuiApplication::primaryScreen ()) {
234
+ view->requestActivate ();
235
+ break ;
236
+ }
237
+ }
209
238
}
210
239
}
211
240
0 commit comments