File indexing completed on 2024-05-05 05:56:59

0001 /*
0002   SPDX-FileCopyrightText: 2008-2014 Eike Hein <hein@kde.org>
0003   SPDX-FileCopyrightText: 2009 Juan Carlos Torres <carlosdgtorres@gmail.com>
0004 
0005   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 */
0007 
0008 #ifndef MAINWINDOW_H
0009 #define MAINWINDOW_H
0010 
0011 #include <config-yakuake.h>
0012 
0013 #include <KMainWindow>
0014 
0015 #include <QTimer>
0016 
0017 class FirstRunDialog;
0018 class SessionStack;
0019 class Skin;
0020 class TabBar;
0021 class Terminal;
0022 class TitleBar;
0023 
0024 class KHelpMenu;
0025 class KActionCollection;
0026 class KStatusNotifierItem;
0027 
0028 #if HAVE_KWAYLAND
0029 namespace KWayland
0030 {
0031 namespace Client
0032 {
0033 class PlasmaShell;
0034 class PlasmaShellSurface;
0035 }
0036 }
0037 #endif
0038 
0039 class MainWindow : public KMainWindow
0040 {
0041     Q_OBJECT
0042     Q_CLASSINFO("D-Bus Interface", "org.kde.yakuake")
0043 
0044     friend class TitleBar;
0045 
0046 public:
0047     explicit MainWindow(QWidget *parent = nullptr);
0048     ~MainWindow();
0049 
0050     KActionCollection *actionCollection()
0051     {
0052         return m_actionCollection;
0053     }
0054     SessionStack *sessionStack()
0055     {
0056         return m_sessionStack;
0057     }
0058 
0059     Skin *skin()
0060     {
0061         return m_skin;
0062     }
0063     QMenu *menu()
0064     {
0065         return m_menu;
0066     }
0067 
0068     bool useTranslucency()
0069     {
0070         return m_useTranslucency;
0071     }
0072 
0073     void setContextDependentActionsQuiet(bool quiet);
0074 
0075 public Q_SLOTS:
0076     Q_SCRIPTABLE void toggleWindowState();
0077 
0078     void handleContextDependentAction(QAction *action = nullptr, int sessionId = -1);
0079     void handleContextDependentToggleAction(bool checked, QAction *action = nullptr, int sessionId = -1);
0080     void handleToggleTerminalKeyboardInput(bool checked);
0081     void handleToggleTerminalMonitorActivity(bool checked);
0082     void handleToggleTerminalMonitorSilence(bool checked);
0083     void handleTerminalActivity(Terminal *terminal);
0084     void handleTerminalSilence(Terminal *terminal);
0085     void handleLastTabClosed();
0086 
0087 Q_SIGNALS:
0088     void windowOpened();
0089     void windowClosed();
0090 
0091 protected:
0092     void paintEvent(QPaintEvent *) override;
0093     void moveEvent(QMoveEvent *) override;
0094     void changeEvent(QEvent *event) override;
0095     void closeEvent(QCloseEvent *event) override;
0096     bool focusNextPrevChild(bool) override;
0097 
0098     virtual bool queryClose() override;
0099 
0100 private Q_SLOTS:
0101     void applySettings();
0102     void applySkin();
0103     void applyWindowProperties();
0104 
0105     void applyWindowGeometry();
0106     void setWindowGeometry(int width, int height, int position);
0107 
0108     void updateScreenMenu();
0109     void setScreen(QAction *action);
0110 
0111     void setWindowWidth(int width);
0112     void setWindowHeight(int height);
0113     void setWindowWidth(QAction *action);
0114     void setWindowHeight(QAction *action);
0115 
0116     void increaseWindowWidth();
0117     void decreaseWindowWidth();
0118     void increaseWindowHeight();
0119     void decreaseWindowHeight();
0120 
0121     void wmActiveWindowChanged();
0122 
0123     void xshapeOpenWindow();
0124     void xshapeRetractWindow();
0125 
0126     void activate();
0127 
0128     void toggleMousePoll(bool poll);
0129     void pollMouse();
0130 
0131     void setKeepOpen(bool keepOpen);
0132 
0133     void setFullScreen(bool state);
0134 
0135     void handleSwitchToAction();
0136 
0137     void handleToggleTitlebar();
0138 
0139     void whatsThis();
0140 
0141     void configureKeys();
0142     void configureNotifications();
0143     void configureApp();
0144     void updateTrayTooltip();
0145 
0146     void showFirstRunDialog();
0147     void firstRunDialogFinished();
0148     void firstRunDialogOk();
0149 
0150 private:
0151     void setupActions();
0152 
0153     void setupMenu();
0154 
0155     void updateWindowSizeMenus();
0156     void updateWindowHeightMenu();
0157     void updateWindowWidthMenu();
0158 
0159 #if HAVE_X11
0160     void kwinAssistToggleWindowState(bool visible);
0161     void kwinAssistPropCleanup();
0162     bool m_kwinAssistPropSet;
0163 #endif
0164 
0165     void xshapeToggleWindowState(bool visible);
0166 
0167     void sharedPreOpenWindow();
0168     void sharedAfterOpenWindow();
0169     void sharedPreHideWindow();
0170     void sharedAfterHideWindow();
0171 
0172     void updateMask();
0173 
0174     int getScreen();
0175     QRect getScreenGeometry();
0176     QRect getDesktopGeometry();
0177 
0178     // get a better value from plasmashell through dbus in wayland case
0179     QRect m_availableScreenRect;
0180     void _toggleWindowState();
0181 
0182     void slideWindow();
0183 
0184     void updateUseTranslucency();
0185     bool m_useTranslucency;
0186     bool m_isFullscreen;
0187 
0188     KActionCollection *m_actionCollection;
0189     QList<QAction *> m_contextDependentActions;
0190 
0191     Skin *m_skin;
0192     TitleBar *m_titleBar;
0193     TabBar *m_tabBar;
0194     SessionStack *m_sessionStack;
0195 
0196     QMenu *m_menu;
0197     KHelpMenu *m_helpMenu;
0198     QMenu *m_screenMenu;
0199     QMenu *m_windowWidthMenu;
0200     QMenu *m_windowHeightMenu;
0201 
0202     FirstRunDialog *m_firstRunDialog;
0203     KStatusNotifierItem *m_notifierItem;
0204 
0205     QTimer m_animationTimer;
0206     QTimer m_mousePoller;
0207     int m_animationFrame;
0208     int m_animationStepSize;
0209 
0210     bool m_toggleLock;
0211 
0212     bool m_isX11;
0213     bool m_isWayland;
0214 
0215 #if HAVE_KWAYLAND
0216     void initWayland();
0217     void initWaylandSurface();
0218     KWayland::Client::PlasmaShell *m_plasmaShell;
0219     KWayland::Client::PlasmaShellSurface *m_plasmaShellSurface;
0220 #endif
0221 };
0222 
0223 #endif