Skip to content

Commit

Permalink
fix bug about no focus
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyuanpeng committed Sep 27, 2019
1 parent 615097f commit 127306f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/fullbackgroundwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ void FullBackgroundWidget::showLockWidget()
onCursorMoved(cursor().pos());
}
lockWidget->setFocus();
XSetInputFocus(QX11Info::display(),this->winId(),RevertToNone,CurrentTime);
}

void FullBackgroundWidget::showScreensaver()
Expand Down
6 changes: 5 additions & 1 deletion src/iconedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <QKeyEvent>
#include <QDebug>
#include <QTimer>

#include <QtX11Extras/QX11Info>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>

Expand Down Expand Up @@ -110,6 +110,10 @@ bool IconEdit::eventFilter(QObject *obj, QEvent *event)
return true;
}
}
if(event->type() == 23)
{
XSetInputFocus(QX11Info::display(),this->winId(),RevertToNone,CurrentTime);
}
}
return false;
}
Expand Down
12 changes: 12 additions & 0 deletions src/screensaverwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include <QVBoxLayout>
#include <QDateTime>
#include <QPainter>
#include <QKeyEvent>
#include <QtX11Extras/QX11Info>
#include <X11/Xlib.h>

ScreenSaverWidget::ScreenSaverWidget(ScreenSaver *screensaver, QWidget *parent)
: QWidget(parent),
Expand All @@ -40,6 +43,7 @@ ScreenSaverWidget::ScreenSaverWidget(ScreenSaver *screensaver, QWidget *parent)
qDebug() << *screensaver;
setMouseTracking(true);
setFocus();
this->installEventFilter(this);

QPalette plt;
plt.setBrush(QPalette::Window, Qt::black);
Expand Down Expand Up @@ -165,7 +169,15 @@ void ScreenSaverWidget::paintEvent(QPaintEvent *event)
return QWidget::paintEvent(event);
}

bool ScreenSaverWidget::eventFilter(QObject *obj, QEvent *event)
{
if(event->type() == 23)
{
XSetInputFocus(QX11Info::display(),this->winId(),RevertToNone,CurrentTime);

}
return false;
}
/* Embed xscreensavers */
void ScreenSaverWidget::embedXScreensaver(const QString &path)
{
Expand Down
2 changes: 1 addition & 1 deletion src/screensaverwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ScreenSaverWidget : public QWidget
protected:
void closeEvent(QCloseEvent *);
void paintEvent(QPaintEvent *event);

bool eventFilter(QObject *obj, QEvent *event);
private:
void embedXScreensaver(const QString &path);
void initUI();
Expand Down

0 comments on commit 127306f

Please sign in to comment.