File indexing completed on 2024-05-19 05:35:17

0001 #ifndef oxygendetectwidget_h
0002 #define oxygendetectwidget_h
0003 
0004 //////////////////////////////////////////////////////////////////////////////
0005 // oxygendetectwidget.h
0006 // Note: this class is a stripped down version of
0007 // /kdebase/workspace/kwin/kcmkwin/kwinrules/detectwidget.h
0008 // SPDX-FileCopyrightText: 2004 Lubos Lunak <l.lunak@kde.org>
0009 
0010 // -------------------
0011 //
0012 // SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0013 //
0014 // SPDX-License-Identifier: MIT
0015 //////////////////////////////////////////////////////////////////////////////
0016 
0017 #include "oxygensettings.h"
0018 #include "ui_oxygendetectwidget.h"
0019 
0020 #include <QByteArray>
0021 #include <QCheckBox>
0022 #include <QDialog>
0023 #include <QEvent>
0024 #include <QLabel>
0025 
0026 #include <KWindowInfo>
0027 #include <kwindowsystem.h>
0028 
0029 namespace Oxygen
0030 {
0031 class DetectDialog : public QDialog
0032 {
0033     Q_OBJECT
0034 
0035 public:
0036     //* constructor
0037     explicit DetectDialog(QWidget *);
0038 
0039     //* read window properties or select one from mouse grab
0040     void detect(WId window);
0041 
0042     //* selected class
0043     QByteArray selectedClass() const;
0044 
0045     //* window information
0046     const KWindowInfo &windowInfo() const
0047     {
0048         return *(m_info.data());
0049     }
0050 
0051     //* exception type
0052     InternalSettings::EnumExceptionType exceptionType() const
0053     {
0054         if (m_ui.windowClassCheckBox->isChecked())
0055             return InternalSettings::ExceptionWindowClassName;
0056         else if (m_ui.windowTitleCheckBox->isChecked())
0057             return InternalSettings::ExceptionWindowTitle;
0058         else
0059             return InternalSettings::ExceptionWindowClassName;
0060     }
0061 
0062 Q_SIGNALS:
0063 
0064     void detectionDone(bool);
0065 
0066 protected:
0067     bool eventFilter(QObject *o, QEvent *e) override;
0068 
0069 private:
0070     //* select window from grab
0071     void selectWindow();
0072 
0073     //* read window properties
0074     void readWindow(WId window);
0075 
0076     //* find window under cursor
0077     WId findWindow();
0078 
0079     //* execute
0080     void executeDialog(void);
0081 
0082     //* ui
0083     Ui::OxygenDetectWidget m_ui;
0084 
0085     //* invisible dialog used to grab mouse
0086     QDialog *m_grabber = nullptr;
0087 
0088     //* current window information
0089     QScopedPointer<KWindowInfo> m_info;
0090 
0091     //* wm state atom
0092     quint32 m_wmStateAtom = 0;
0093 };
0094 
0095 } // namespace
0096 
0097 #endif