mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
feat(input): submit text fields via configured validate keybinds
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "app/poll_source.h"
|
||||
#include "compositors/compositor_detect.h"
|
||||
#include "compositors/output_backend.h"
|
||||
#include "config/config_types.h"
|
||||
#include "core/build_info.h"
|
||||
#include "core/deferred_call.h"
|
||||
#include "core/log.h"
|
||||
@@ -353,6 +354,9 @@ void Application::initServices() {
|
||||
m_wayland.setClipboardService(&m_clipboardService);
|
||||
m_wayland.setVirtualKeyboardService(&m_virtualKeyboardService);
|
||||
Input::setClipboardService(&m_clipboardService);
|
||||
Input::setValidateKeyMatcher([this](std::uint32_t sym, std::uint32_t modifiers) {
|
||||
return m_configService.matchesKeybind(KeybindAction::Validate, sym, modifiers);
|
||||
});
|
||||
|
||||
m_wayland.setOutputChangeCallback([this]() {
|
||||
if (m_brightnessService != nullptr) {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <array>
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -26,6 +27,7 @@ namespace {
|
||||
|
||||
ClipboardService* g_clipboard = nullptr;
|
||||
Input::PasswordMaskStyle g_passwordMaskStyle = Input::PasswordMaskStyle::CircleFilled;
|
||||
std::function<bool(std::uint32_t, std::uint32_t)> g_validateKeyMatcher;
|
||||
|
||||
std::optional<std::string> readClipboardText() {
|
||||
if (g_clipboard == nullptr) {
|
||||
@@ -332,6 +334,10 @@ void Input::setOnKeyEvent(std::function<bool(std::uint32_t, std::uint32_t)> call
|
||||
|
||||
void Input::setClipboardService(ClipboardService* clipboard) noexcept { g_clipboard = clipboard; }
|
||||
|
||||
void Input::setValidateKeyMatcher(std::function<bool(std::uint32_t, std::uint32_t)> matcher) noexcept {
|
||||
g_validateKeyMatcher = std::move(matcher);
|
||||
}
|
||||
|
||||
void Input::setPasswordMaskStyle(PasswordMaskStyle style) noexcept { g_passwordMaskStyle = style; }
|
||||
|
||||
void Input::selectAll() {
|
||||
@@ -488,10 +494,15 @@ void Input::handleKey(std::uint32_t sym, std::uint32_t utf32, std::uint32_t modi
|
||||
return;
|
||||
}
|
||||
|
||||
const bool validateMatch = g_validateKeyMatcher && g_validateKeyMatcher(sym, modifiers);
|
||||
|
||||
// Ignore keys that produce no text and aren't action keys we handle below
|
||||
if (utf32 == 0 && !preedit && sym != XKB_KEY_BackSpace && sym != XKB_KEY_Delete && sym != XKB_KEY_Left &&
|
||||
sym != XKB_KEY_Right && sym != XKB_KEY_Home && sym != XKB_KEY_End && sym != XKB_KEY_Return) {
|
||||
return;
|
||||
if (utf32 == 0 && !preedit) {
|
||||
const bool navigationOrEdit = sym == XKB_KEY_BackSpace || sym == XKB_KEY_Delete || sym == XKB_KEY_Left ||
|
||||
sym == XKB_KEY_Right || sym == XKB_KEY_Home || sym == XKB_KEY_End;
|
||||
if (!navigationOrEdit && !validateMatch) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool changed = false;
|
||||
@@ -585,7 +596,7 @@ void Input::handleKey(std::uint32_t sym, std::uint32_t utf32, std::uint32_t modi
|
||||
if (!shift) {
|
||||
m_selectionAnchor = m_cursorPos;
|
||||
}
|
||||
} else if (sym == XKB_KEY_Return) {
|
||||
} else if (validateMatch) {
|
||||
if (m_onSubmit) {
|
||||
m_onSubmit(m_value);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
@@ -45,6 +46,8 @@ public:
|
||||
|
||||
// Set once at application startup; all Input instances use this for Ctrl+C/X/V.
|
||||
static void setClipboardService(ClipboardService* clipboard) noexcept;
|
||||
/// Submit invokes onSubmit only when this matcher returns true (Application wires ConfigService validate keybinds).
|
||||
static void setValidateKeyMatcher(std::function<bool(std::uint32_t sym, std::uint32_t modifiers)> matcher) noexcept;
|
||||
static void setPasswordMaskStyle(PasswordMaskStyle style) noexcept;
|
||||
void clearSelection();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user