Keybinds on Wayland

This commit is contained in:
Victor Tran 2021-06-17 08:09:24 +10:00
parent 23f8e09eb3
commit f351c63c1e
No known key found for this signature in database
GPG key ID: 1F0729FE016CDC3E
9 changed files with 199 additions and 5 deletions

View file

@ -72,8 +72,8 @@ Gateway::Gateway() :
}
});
DesktopWm::setSystemWindow(this, DesktopWm::SystemWindowTypeMenu);
this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
DesktopWm::setSystemWindow(this, DesktopWm::SystemWindowTypeMenu);
this->setFixedWidth(0);
connect(GestureDaemon::instance(), &GestureDaemon::gestureBegin, this, [ = ](GestureInteractionPtr interaction) {

View file

@ -4,5 +4,5 @@ Type=Application
Exec=/usr/bin/wayfire --config /usr/share/thedesk/startdesk/wayfire-thedesk-config.conf
TryExec=/usr/bin/wayfire
DesktopNames=theDesk
Name=theDesk (Wayland)
Name=theDesk on Wayland
Comment=theDesk Desktop Environment

View file

@ -38,9 +38,6 @@
# See Output options for a complete reference.
# https://github.com/WayfireWM/wayfire/wiki/Configuration#output
[output:HDMI-A-1]
mode = 3840x2160@30000
# Core options ─────────────────────────────────────────────────────────────────
[core]
@ -70,6 +67,7 @@ plugins = \
wobbly \
wrot \
zoom \
thedesk-keygrab \
thedesk-startdesk
# Note: [blur] is not enabled by default, because it can be resource-intensive.

View file

@ -0,0 +1,19 @@
CONFIG += qt
TEMPLATE = lib
DEFINES += KEYGRABPLUGIN_LIBRARY
TARGET = thedesk-keygrab
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
keygrabplugin.cpp
HEADERS += \
keygrabplugin.h
WAYLAND_PROTOCOL_EXTENSIONS += /usr/share/libtdesktopenvironment/wayland-protocols/tdesktopenvironment-keygrab-v1.xml
include(../plugins.pri)

View file

@ -0,0 +1,31 @@
/****************************************
*
* INSERT-PROJECT-NAME-HERE - INSERT-GENERIC-NAME-HERE
* Copyright (C) 2021 Victor Tran
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* *************************************/
#ifndef KEYGRABPLUGIN_GLOBAL_H
#define KEYGRABPLUGIN_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(KEYGRABPLUGIN_LIBRARY)
# define KEYGRABPLUGIN_EXPORT Q_DECL_EXPORT
#else
# define KEYGRABPLUGIN_EXPORT Q_DECL_IMPORT
#endif
#endif // KEYGRABPLUGIN_GLOBAL_H

View file

@ -0,0 +1,85 @@
/****************************************
*
* INSERT-PROJECT-NAME-HERE - INSERT-GENERIC-NAME-HERE
* Copyright (C) 2021 Victor Tran
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* *************************************/
#include "keygrabplugin.h"
#include <wayfire/core.hpp>
#include <wayfire/output.hpp>
#include <wlr/types/wlr_xdg_foreign_registry.h>
#include "wayland-tdesktopenvironment-keygrab-v1-server-protocol.h"
#include <iostream>
struct KeygrabPluginPrivate {
wl_resource* tdeKeygrabManager;
};
KeygrabPlugin::KeygrabPlugin() {
d = new KeygrabPluginPrivate();
}
KeygrabPlugin::~KeygrabPlugin() {
delete d;
}
void KeygrabPlugin::grabKey(wl_client* client, uint32_t mod, uint32_t key) {
std::cout << "Grabbing key " << key << " mod " << mod << "\n";
output->add_key(wf::create_option(wf::keybinding_t(mod, key)), new wf::key_callback([ = ](const wf::keybinding_t& keybind) {
std::cout << "Pressed " << key << " mod " << mod << "\n";
tdesktopenvironment_keygrab_manager_v1_send_activated(d->tdeKeygrabManager, mod, key, 0);
return true;
}));
}
void KeygrabPlugin::ungrabKey(wl_client* client, uint32_t mod, uint32_t key) {
}
void KeygrabPlugin::init() {
output->add_key(wf::create_option(wf::keybinding_t(0, 36)), new wf::key_callback([ = ](const wf::keybinding_t& key) {
std::cout << "Pressed J\n";
return true;
}));
// wf::get_core().
wl_global_create(wf::get_core().display, &tdesktopenvironment_keygrab_manager_v1_interface, 1, this, [](wl_client * client, void* data, uint32_t version, uint32_t id) {
KeygrabPlugin* plugin = reinterpret_cast<KeygrabPlugin*>(data);
plugin->d->tdeKeygrabManager = wl_resource_create(client, &tdesktopenvironment_keygrab_manager_v1_interface, 1, id);
struct tdesktopenvironment_keygrab_manager_v1_interface* interface = new struct tdesktopenvironment_keygrab_manager_v1_interface();
interface->grab_key = [](struct wl_client * client, struct wl_resource * resource, uint32_t mod, uint32_t key) {
reinterpret_cast<KeygrabPlugin*>(resource->data)->grabKey(client, mod, key);
};
interface->ungrab_key = [](struct wl_client * client, struct wl_resource * resource, uint32_t mod, uint32_t key) {
reinterpret_cast<KeygrabPlugin*>(resource->data)->ungrabKey(client, mod, key);
};
interface->destroy = [](struct wl_client * client, struct wl_resource * resource) {
};
wl_resource_set_implementation(plugin->d->tdeKeygrabManager, interface, plugin, nullptr);
});
}
void KeygrabPlugin::fini() {
}
bool KeygrabPlugin::is_unloadable() {
return false;
}

View file

@ -0,0 +1,47 @@
/****************************************
*
* INSERT-PROJECT-NAME-HERE - INSERT-GENERIC-NAME-HERE
* Copyright (C) 2021 Victor Tran
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* *************************************/
#ifndef KEYGRABPLUGIN_H
#define KEYGRABPLUGIN_H
#include <wayfire/plugin.hpp>
struct wl_client;
struct KeygrabPluginPrivate;
class KeygrabPlugin : public wf::plugin_interface_t {
public:
KeygrabPlugin();
~KeygrabPlugin();
void grabKey(wl_client* client, uint32_t mod, uint32_t key);
void ungrabKey(wl_client* client, uint32_t mod, uint32_t key);
// plugin_interface_t interface
public:
void init();
void fini();
bool is_unloadable();
private:
KeygrabPluginPrivate* d;
};
DECLARE_WAYFIRE_PLUGIN(KeygrabPlugin)
#endif // KEYGRABPLUGIN_H

View file

@ -9,5 +9,18 @@ CONFIG += c++17 plugin
CONFIG += link_pkgconfig
PKGCONFIG += wayfire wlroots
wayland_scanner_headers.output = wayland-${QMAKE_FILE_BASE}-server-protocol.h
wayland_scanner_headers.commands = wayland-scanner server-header ${QMAKE_FILE_NAME} ${QMAKE_FILE_OUT}
wayland_scanner_headers.input = WAYLAND_PROTOCOL_EXTENSIONS
wayland_scanner_headers.CONFIG += target_predeps no_link
wayland_scanner_sources.output = wayland-${QMAKE_FILE_BASE}-server-protocol.c
wayland_scanner_sources.commands = wayland-scanner private-code ${QMAKE_FILE_NAME} ${QMAKE_FILE_OUT}
wayland_scanner_sources.input = WAYLAND_PROTOCOL_EXTENSIONS
wayland_scanner_sources.variable_out = SOURCES
wayland_scanner_headers.CONFIG += target_predeps no_link
QMAKE_EXTRA_COMPILERS += wayland_scanner_headers wayland_scanner_sources
target.path = $$THELIBS_INSTALL_LIB/wayfire/
INSTALLS = target

View file

@ -1,4 +1,5 @@
TEMPLATE = subdirs
SUBDIRS += \
keygrab-plugin \
startdesk-plugin