Skip to content

Commit

Permalink
Merge pull request #34 from Thaodan/qcdebug
Browse files Browse the repository at this point in the history
Reduce logging output and refactor headers
  • Loading branch information
duvholt authored May 26, 2024
2 parents 041803f + 2103876 commit a30baba
Show file tree
Hide file tree
Showing 17 changed files with 130 additions and 58 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(KF_MAJOR_VERSION "6")

set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_MODULE_PATH})

include(ECMQtDeclareLoggingCategory)
include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings)
Expand Down
5 changes: 5 additions & 0 deletions plasmoid/contents/config/config.qml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/* -*- qml -*-
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/

import QtQuick 2.15
import org.kde.plasma.configuration

Expand Down
3 changes: 3 additions & 0 deletions plasmoid/contents/config/main.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- -*- xml -*-
SPDX-License-Identifier: GPL-3.0-or-later
!-->
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
<kcfgfile name="" />
<group name="General">
Expand Down
5 changes: 5 additions & 0 deletions plasmoid/contents/ui/configGeneral.qml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/* -*- qml -*-
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/

import QtQuick 2.15
import QtQuick.Controls
import QtQuick.Layouts
Expand Down
5 changes: 5 additions & 0 deletions plasmoid/contents/ui/configScreens.qml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/* -*- qml -*-
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/

import QtQuick 2.15
import QtQuick.Controls as QQC2
import QtQuick.Dialogs
Expand Down
5 changes: 5 additions & 0 deletions plasmoid/contents/ui/main.qml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/* -*- qml -*-
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/

import QtQuick 2.15
import QtQuick.Layouts
import QtQuick.Controls
Expand Down
5 changes: 5 additions & 0 deletions plasmoid/contents/ui/screens.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/* -*- qml -*-
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/

function saveConfig() {
console.log("Saving config")
cfg_screenNameList = [];
Expand Down
9 changes: 7 additions & 2 deletions plasmoid/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
{
"Email": "[email protected]",
"Name": "Christian duvholt"
},
{
"Email": "[email protected]",
"Name": "Björn Bidar"
}

],
"Description": "i3 Pager",
"Id": "org.kde.I3Pager",
"License": "GPL",
"License": "GPL-3.0-or-later",
"Name": "i3Pager",
"ServiceTypes": [
"Plasma/Applet"
],
"Version": "1.0",
"Website": "plasma.kde.org"
"Website": "https://github.com/duvholt/i3-pager"
},
"X-Plasma-API": "declarativeappletscript",
"X-Plasma-API-Minimum-Version": "6.0",
Expand Down
11 changes: 11 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ set(I3PagerPlugin_SRCS
workspace.cpp
workspace.h)

ecm_qt_declare_logging_category(I3PagerPlugin_SRCS
HEADER i3pager_debug.h
IDENTIFIER I3PAGER
CATEGORY_NAME org.kde.I3Pager
DESCRIPTION "I3Pager Plasmoid"
EXPORT I3Pager
)

add_library(I3PagerPlugin SHARED ${I3PagerPlugin_SRCS})
target_compile_options(I3PagerPlugin PRIVATE -fexceptions)

Expand All @@ -31,3 +39,6 @@ target_link_libraries(I3PagerPlugin
# install plugin
install(TARGETS I3PagerPlugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/private/I3Pager)
install(FILES qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/private/I3Pager)
ecm_qt_install_logging_categories(EXPORT I3PAGER
FILE org.kde.i3pager.categories
DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR})
18 changes: 14 additions & 4 deletions src/i3listener.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
/* -*- c++ -*-
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/

#include "i3listener.h"
#include "i3pager_debug.h"
#include <QDebug>
#include <QLocalSocket>
#include <QSocketNotifier>
#include <i3ipc++/ipc.hpp>

I3ListenerThread::I3ListenerThread(QObject* parent)
: QThread(parent) {
Expand All @@ -19,25 +29,25 @@ void I3ListenerThread::handleI3Events() {

// Workspace events handler
conn.signal_workspace_event.connect([this](const i3ipc::workspace_event_t& ev) {
qDebug() << "workspace_event: " << (char)ev.type;
qCDebug(I3PAGER) << "workspace_event: " << (char)ev.type;
if (ev.current) {
qDebug() << "\tSwitched to #" << ev.current->num << " - \"" << QString::fromStdString(ev.current->name) << '"';
qCDebug(I3PAGER) << "\tSwitched to #" << ev.current->num << " - \"" << QString::fromStdString(ev.current->name) << '"';
Q_EMIT workspacesChanged();
}
});

// Mode events handler
conn.signal_mode_event.connect([this](const i3ipc::mode_t& i3mode) {
const auto mode = QString::fromStdString(i3mode.change);
qDebug() << "mode: " << mode;
qCDebug(I3PAGER) << "mode: " << mode;
Q_EMIT modeChanged(mode);
});

while (!stopping) {
conn.handle_event();
}
} catch (std::exception const& e) {
qWarning() << "Exception in i3listener handle events:" << e.what();
qCWarning(I3PAGER) << "Exception in i3listener handle events:" << e.what();
}
}

Expand Down
15 changes: 6 additions & 9 deletions src/i3listener.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#ifndef I3LISTENER_H
#define I3LISTENER_H
/* -*- c++ -*-
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/

#pragma once

#include <QDebug>
#include <QLocalSocket>
#include <QSocketNotifier>
#include <QThread>
#include <QtCore/QObject>
#include <i3ipc++/ipc.hpp>

class I3ListenerThread : public QThread {
Q_OBJECT
Expand All @@ -24,5 +23,3 @@ class I3ListenerThread : public QThread {
bool stopping = false;
void handleI3Events();
};

#endif //I3LISTENER_H
32 changes: 22 additions & 10 deletions src/i3pager.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
/* -*- c++ -*-
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/

#include "i3pager.h"

#include <i3ipc++/ipc.hpp>
#include "i3pager_debug.h"
#include "i3listener.h"
#include <future>
#include <QDebug>


I3Pager::I3Pager(QObject* parent)
: QObject(parent) {
currentScreenPrivate = QString();
mode = "default";

qDebug() << "Starting i3 listener";
qCDebug(I3PAGER) << "Starting i3 listener";
this->i3ListenerThread = new I3ListenerThread(this);
connect(i3ListenerThread, &I3ListenerThread::modeChanged, this, [=](const QString& mode) {
this->mode = mode;
Expand All @@ -16,14 +28,14 @@ I3Pager::I3Pager(QObject* parent)
});
connect(i3ListenerThread, &I3ListenerThread::finished, i3ListenerThread, &QObject::deleteLater);
i3ListenerThread->start();
qDebug() << "i3 listener started";
qCDebug(I3PAGER) << "i3 listener started";
}

I3Pager::~I3Pager() {
qDebug() << "I3Pager destructor";
qCDebug(I3PAGER) << "I3Pager destructor";
this->i3ListenerThread->stop();
this->i3ListenerThread->wait();
qDebug() << "I3Pager destructor done";
qCDebug(I3PAGER) << "I3Pager destructor done";
}

QList<QString> I3Pager::getScreenNames() {
Expand All @@ -35,11 +47,11 @@ QList<QString> I3Pager::getScreenNames() {
for (auto& screen : screens) {
if (screen->active) {
screenList.append(QString::fromStdString(screen->name));
qDebug() << "Screen name:" << QString::fromStdString(screen->name);
qCDebug(I3PAGER) << "Screen name:" << QString::fromStdString(screen->name);
}
}
} catch (std::exception const& e) {
qWarning() << "Exception while retrieving screen names: " << e.what();
qCWarning(I3PAGER) << "Exception while retrieving screen names: " << e.what();
}

return screenList;
Expand All @@ -50,7 +62,7 @@ QList<Workspace> I3Pager::getWorkspaces(bool filterByCurrentScreen, QString orde
try {
i3ipc::connection conn;
auto i3workspaceList = conn.get_workspaces();
qDebug() << "Loading workspaces:";
qCDebug(I3PAGER) << "Loading workspaces:";

for (auto& i3workspace : i3workspaceList) {
Workspace workspace;
Expand All @@ -66,8 +78,8 @@ QList<Workspace> I3Pager::getWorkspaces(bool filterByCurrentScreen, QString orde
workspace.visible = i3workspace->visible;
workspace.urgent = i3workspace->urgent;

qDebug() << "i3Workspace name:" << QString::fromStdString(i3workspace->name);
qDebug() << "Workspace:"
qCDebug(I3PAGER) << "i3Workspace name:" << QString::fromStdString(i3workspace->name);
qCDebug(I3PAGER) << "Workspace:"
<< "id:" << workspace.id
<< "index:" << workspace.index
<< "name:" << workspace.name
Expand All @@ -79,7 +91,7 @@ QList<Workspace> I3Pager::getWorkspaces(bool filterByCurrentScreen, QString orde
workspaceList.append(workspace);
}
} catch (std::exception const& e) {
qWarning() << "Exception while retrieving workspaces:" << e.what();
qCWarning(I3PAGER) << "Exception while retrieving workspaces:" << e.what();
}

if (filterByCurrentScreen) {
Expand Down
25 changes: 10 additions & 15 deletions src/i3pager.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
#ifndef I3PAGER_PLASMOID_H
#define I3PAGER_PLASMOID_H
/* -*- c++ -*-
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/

#pragma once

#include "i3listener.h"
#include "workspace.h"
#include <QApplication>
#include <QDebug>
#include <QGuiApplication>
#include <QMetaType>
#include <QScreen>
#include <QVariant>
#include <QtConcurrent/QtConcurrent>
#include <QtCore/QObject>
#include <future>
#include <i3ipc++/ipc.hpp>
#include <QObject>

class I3ListenerThread;
class Workspace;

class I3Pager : public QObject {
Q_OBJECT
Expand Down Expand Up @@ -42,5 +39,3 @@ public Q_SLOTS:
QString currentScreenPrivate;
QString mode;
};

#endif //I3PAGER_PLASMOID_H
8 changes: 7 additions & 1 deletion src/plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#include "plugin.h"
/* -*- c++ -*-
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/

#include "plugin.h"
#include "i3pager.h"
#include "workspace.h"
#include <QtQml>

void Plugin::registerTypes(const char *uri) {
Expand Down
11 changes: 5 additions & 6 deletions src/plugin.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#ifndef I3PAGER_PLASMOID_PLUGIN_H
#define I3PAGER_PLASMOID_PLUGIN_H
/* -*- c++ -*-
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/

#include "i3pager.h"
#include "workspace.h"
#pragma once

#include <QQmlExtensionPlugin>

Expand All @@ -14,5 +15,3 @@ class Plugin : public QQmlExtensionPlugin {
public:
void registerTypes(const char* uri) override;
};

#endif //I3PAGER_PLASMOID_PLUGIN_H
17 changes: 12 additions & 5 deletions src/workspace.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
/* -*- c++ -*-
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/

#include "workspace.h"
#include "i3pager_debug.h"
#include <algorithm>
#include <QDebug>

QList<Workspace> Workspace::filterByCurrentScreen(QList<Workspace> inputWorkspaces, QString currentScreen) {
QList<Workspace> outputWorkspaces;
qDebug() << "Filtering by current screen:" << currentScreen;
qCDebug(I3PAGER) << "Filtering by current screen:" << currentScreen;
for (auto workspace : inputWorkspaces) {
if (currentScreen == workspace.output) {
qDebug() << "Added workspace:" << workspace.name << "output:" << workspace.output;
qCDebug(I3PAGER) << "Added workspace:" << workspace.name << "output:" << workspace.output;
outputWorkspaces.append(workspace);
} else {
qDebug() << "Removed workspace:" << workspace.name << "output:" << workspace.output;
qCDebug(I3PAGER) << "Removed workspace:" << workspace.name << "output:" << workspace.output;
}
}
return outputWorkspaces;
Expand All @@ -24,11 +31,11 @@ QList<Workspace> Workspace::orderByName(QList<Workspace> inputWorkspaces) {

QList<Workspace> Workspace::orderByOutput(QList<Workspace> inputWorkspaces, QList<QString> outputList) {
QList<Workspace> outputWorkspaces;
qDebug() << "Ordering workspaces by screens:" << outputList;
qCDebug(I3PAGER) << "Ordering workspaces by screens:" << outputList;
for (auto output : outputList) {
for (auto workspace : inputWorkspaces) {
if (workspace.output == output) {
qDebug() << "Added workspace:" << workspace.name << "output:" << workspace.output;
qCDebug(I3PAGER) << "Added workspace:" << workspace.name << "output:" << workspace.output;
outputWorkspaces.append(workspace);
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/workspace.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#ifndef WORKSPACE_H
#define WORKSPACE_H
/* -*- c++ -*-
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/

#include <QDebug>
#include <QtCore/QObject>
#pragma once

#include <QObject>

class Workspace {
Q_GADGET
Expand All @@ -29,5 +32,3 @@ class Workspace {
};

Q_DECLARE_METATYPE(Workspace)

#endif //WORKSPACE_H

0 comments on commit a30baba

Please sign in to comment.