Skip to content

Commit

Permalink
ILXQtTaskbarAbstractBackend: add dummy implementation
Browse files Browse the repository at this point in the history
This will be used to avoid crashing panel in case no backend could be
created.
A warning message will be printed in this case.
  • Loading branch information
gfgit committed Feb 22, 2024
1 parent b3d93fb commit 65ea434
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 2 deletions.
2 changes: 2 additions & 0 deletions panel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(PRIV_HEADERS
backends/ilxqttaskbarabstractbackend.h
backends/lxqttaskbartypes.h

backends/lxqttaskbardummybackend.h
backends/xcb/lxqttaskbarbackend_x11.h
)

Expand Down Expand Up @@ -59,6 +60,7 @@ set(SOURCES

backends/ilxqttaskbarabstractbackend.cpp

backends/lxqttaskbardummybackend.cpp
backends/xcb/lxqttaskbarbackend_x11.cpp
)

Expand Down
156 changes: 156 additions & 0 deletions panel/backends/lxqttaskbardummybackend.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#include "lxqttaskbardummybackend.h"

#include <QIcon>

LXQtTaskBarDummyBackend::LXQtTaskBarDummyBackend(QObject *parent)
: ILXQtTaskbarAbstractBackend(parent)
{

}


/************************************************
* Windows function
************************************************/
bool LXQtTaskBarDummyBackend::supportsAction(WId, LXQtTaskBarBackendAction) const
{
return false;
}

bool LXQtTaskBarDummyBackend::reloadWindows()
{
return false;
}

QVector<WId> LXQtTaskBarDummyBackend::getCurrentWindows() const
{
return {};
}

QString LXQtTaskBarDummyBackend::getWindowTitle(WId) const
{
return QString();
}

bool LXQtTaskBarDummyBackend::applicationDemandsAttention(WId) const
{
return false;
}

QIcon LXQtTaskBarDummyBackend::getApplicationIcon(WId, int) const
{
return QIcon();
}

QString LXQtTaskBarDummyBackend::getWindowClass(WId) const
{
return QString();
}

LXQtTaskBarWindowLayer LXQtTaskBarDummyBackend::getWindowLayer(WId) const
{
return LXQtTaskBarWindowLayer::Normal;
}

bool LXQtTaskBarDummyBackend::setWindowLayer(WId, LXQtTaskBarWindowLayer)
{
return false;
}

LXQtTaskBarWindowState LXQtTaskBarDummyBackend::getWindowState(WId) const
{
return LXQtTaskBarWindowState::Normal;
}

bool LXQtTaskBarDummyBackend::setWindowState(WId, LXQtTaskBarWindowState, bool)
{
return false;
}

bool LXQtTaskBarDummyBackend::isWindowActive(WId) const
{
return false;
}

bool LXQtTaskBarDummyBackend::raiseWindow(WId, bool)
{
return false;
}

bool LXQtTaskBarDummyBackend::closeWindow(WId)
{
return false;
}

WId LXQtTaskBarDummyBackend::getActiveWindow() const
{
return 0;
}


/************************************************
* Workspaces
************************************************/
int LXQtTaskBarDummyBackend::getWorkspacesCount() const
{
return 1; // Fake 1 workspace
}

QString LXQtTaskBarDummyBackend::getWorkspaceName(int) const
{
return QString();
}

int LXQtTaskBarDummyBackend::getCurrentWorkspace() const
{
return 0;
}

bool LXQtTaskBarDummyBackend::setCurrentWorkspace(int)
{
return false;
}

int LXQtTaskBarDummyBackend::getWindowWorkspace(WId) const
{
return 0;
}

bool LXQtTaskBarDummyBackend::setWindowOnWorkspace(WId, int)
{
return false;
}

void LXQtTaskBarDummyBackend::moveApplicationToPrevNextMonitor(WId, bool, bool)
{
//No-op
}

bool LXQtTaskBarDummyBackend::isWindowOnScreen(QScreen *, WId) const
{
return false;
}

/************************************************
* X11 Specific
************************************************/
void LXQtTaskBarDummyBackend::moveApplication(WId)
{
//No-op
}

void LXQtTaskBarDummyBackend::resizeApplication(WId)
{
//No-op
}

void LXQtTaskBarDummyBackend::refreshIconGeometry(WId, QRect const &)
{
//No-op
}

bool LXQtTaskBarDummyBackend::isAreaOverlapped(const QRect &) const
{
return false;
}

82 changes: 82 additions & 0 deletions panel/backends/lxqttaskbardummybackend.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#ifndef LXQTTASKBARDUMMYBACKEND_H
#define LXQTTASKBARDUMMYBACKEND_H

#include "ilxqttaskbarabstractbackend.h"

class LXQtTaskBarDummyBackend : public ILXQtTaskbarAbstractBackend
{
Q_OBJECT

public:
explicit LXQtTaskBarDummyBackend(QObject *parent = nullptr);

// Backend
bool supportsAction(WId windowId, LXQtTaskBarBackendAction action) const override;

// Windows
bool reloadWindows() override;

QVector<WId> getCurrentWindows() const override;

QString getWindowTitle(WId windowId) const override;

bool applicationDemandsAttention(WId windowId) const override;

QIcon getApplicationIcon(WId windowId, int fallbackDevicePixels) const override;

QString getWindowClass(WId windowId) const override;

LXQtTaskBarWindowLayer getWindowLayer(WId windowId) const override;
bool setWindowLayer(WId windowId, LXQtTaskBarWindowLayer layer) override;

LXQtTaskBarWindowState getWindowState(WId windowId) const override;
bool setWindowState(WId windowId, LXQtTaskBarWindowState state, bool set = true) override;

bool isWindowActive(WId windowId) const override;
bool raiseWindow(WId windowId, bool onCurrentWorkSpace) override;

bool closeWindow(WId windowId) override;

WId getActiveWindow() const override;

// Workspaces
int getWorkspacesCount() const override;
QString getWorkspaceName(int idx) const override;

int getCurrentWorkspace() const override;
bool setCurrentWorkspace(int idx) override;

int getWindowWorkspace(WId windowId) const override;
bool setWindowOnWorkspace(WId windowId, int idx) override;

void moveApplicationToPrevNextMonitor(WId windowId, bool next, bool raiseOnCurrentDesktop) override;

bool isWindowOnScreen(QScreen *screen, WId windowId) const override;

// X11 Specific
void moveApplication(WId windowId) override;
void resizeApplication(WId windowId) override;

void refreshIconGeometry(WId windowId, const QRect &geom) override;

// Panel internal
bool isAreaOverlapped(const QRect& area) const override;

signals:
void reloaded();

// Windows
void windowAdded(WId windowId);
void windowRemoved(WId windowId);
void windowPropertyChanged(WId windowId, int prop);

// Workspaces
void workspacesCountChanged();
void workspaceNameChanged(int idx);
void currentWorkspaceChanged(int idx);

// TODO: needed?
void activeWindowChanged(WId windowId);
};

#endif // LXQTTASKBARDUMMYBACKEND_H
10 changes: 8 additions & 2 deletions panel/lxqtpanelapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "lxqtpanelapplication_p.h"
#include <LXQt/Settings>

#include "backends/lxqttaskbardummybackend.h"
#include "backends/xcb/lxqttaskbarbackend_x11.h"

#include <chrono>
Expand All @@ -47,8 +48,13 @@ ILXQtTaskbarAbstractBackend *createWMBackend()
if(qGuiApp->nativeInterface<QNativeInterface::QX11Application>())
return new LXQtTaskbarX11Backend;

Q_ASSERT_X(false, "createWMBackend()", "Only X11 supported!");
return nullptr;
qWarning() << "\n"
<< "ERROR: Could not create a backend for window managment operations.\n"
<< "Only X11 supported!\n"
<< "Falling back to dummy backend. Some functions will not be available.\n"
<< "\n";

return new LXQtTaskBarDummyBackend;
}

LXQtPanelApplicationPrivate::LXQtPanelApplicationPrivate(LXQtPanelApplication *q)
Expand Down

0 comments on commit 65ea434

Please sign in to comment.