Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ set(libinputactions_SRCS
libinputactions/handlers/TouchscreenTriggerHandler.cpp
libinputactions/handlers/TriggerHandler.cpp
libinputactions/helpers/Math.cpp
libinputactions/helpers/QDBusConnection.cpp
libinputactions/helpers/QString.cpp
libinputactions/helpers/QThread.cpp
libinputactions/helpers/QVariant.cpp
libinputactions/helpers/Session.cpp
libinputactions/input/backends/InputBackend.cpp
libinputactions/input/backends/LibevdevComplementaryInputBackend.cpp
libinputactions/input/backends/LibinputInputBackend.cpp
Expand Down
3 changes: 2 additions & 1 deletion src/libinputactions/dbus/IntegratedDBusInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <libinputactions/InputActionsMain.h>
#include <libinputactions/config/ConfigIssueManager.h>
#include <libinputactions/config/ConfigLoader.h>
#include <libinputactions/helpers/QDBusConnection.h>
#include <libinputactions/input/StrokeRecorder.h>
#include <libinputactions/input/backends/InputBackend.h>
#include <libinputactions/interfaces/OnScreenMessageManager.h>
Expand All @@ -31,7 +32,7 @@ namespace InputActions
{

IntegratedDBusInterface::IntegratedDBusInterface()
: m_bus(QDBusConnection::sessionBus())
: m_bus(QDBusConnectionHelpers::sessionBus())
{
m_bus.registerService(INPUTACTIONS_DBUS_SERVICE);
m_bus.registerObject(INPUTACTIONS_DBUS_PATH, this, QDBusConnection::ExportAllSlots);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,32 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "Session.h"
#include <QFile>
#include "QDBusConnection.h"
#include <sys/types.h>
#include <unistd.h>

namespace InputActions::SessionHelpers
namespace InputActions::QDBusConnectionHelpers
{

QString currentTty()
const QDBusConnection &sessionBus()
{
QFile f("/sys/class/tty/tty0/active");
if (f.open(QIODeviceBase::ReadOnly)) {
return QString::fromUtf8(f.readAll()).trimmed();
static std::optional<QDBusConnection> cached;
if (cached) {
return cached.value();
}
return "unknown";

gid_t rgid{};
gid_t egid{};
gid_t sgid{};
if (!getresgid(&rgid, &egid, &sgid) && (rgid != egid || egid != sgid)) {
if (const auto address = qEnvironmentVariable("DBUS_SESSION_BUS_ADDRESS"); !address.isEmpty()) {
cached = QDBusConnection::connectToBus(address, "sessionBus");
return cached.value();
}
}

cached = QDBusConnection::sessionBus();
return cached.value();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@

#pragma once

#include <QString>
#include <QDBusConnection>

namespace InputActions::SessionHelpers
namespace InputActions::QDBusConnectionHelpers
{

QString currentTty();
/**
* Same as QDBusConnection::sessionBus, but uses QDBusConnection::connectToBus with the address specified in the DBUS_SESSION_BUS_ADDRESS environment variable
* for setgid binaries.
*
* Connection is cached.
*/
const QDBusConnection &sessionBus();

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "DBusNotificationManager.h"
#include <QDBusInterface>
#include <QThreadPool>
#include <libinputactions/helpers/QDBusConnection.h>

namespace InputActions
{
Expand All @@ -31,7 +32,7 @@ void DBusNotificationManager::sendNotification(const QString &title, const QStri
QDBusInterface notificationsInterface("org.freedesktop.Notifications",
"/org/freedesktop/Notifications",
"org.freedesktop.Notifications",
QDBusConnection::sessionBus());
QDBusConnectionHelpers::sessionBus());
if (notificationsInterface.isValid()) {
notificationsInterface.asyncCall("Notify", "InputActions", 0U, "", title, content, QStringList(), QVariantMap(), 5000);
}
Expand Down