Selection color from accent color
Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
91
src/App.cpp
91
src/App.cpp
@@ -3,10 +3,10 @@
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
#include <poll.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
@@ -66,8 +66,8 @@ struct SurroundingSlice {
|
||||
int anchor { 0 };
|
||||
};
|
||||
|
||||
auto clamp_surrounding_text(
|
||||
std::string const &text, int cursor, int anchor) -> SurroundingSlice
|
||||
auto clamp_surrounding_text(std::string const &text, int cursor, int anchor)
|
||||
-> SurroundingSlice
|
||||
{
|
||||
int const size = static_cast<int>(text.size());
|
||||
cursor = std::clamp(cursor, 0, size);
|
||||
@@ -78,19 +78,17 @@ auto clamp_surrounding_text(
|
||||
}
|
||||
|
||||
int window_start = std::max(0,
|
||||
std::min(cursor, anchor)
|
||||
- static_cast<int>(MAX_SURROUNDING_BYTES / 2));
|
||||
std::min(cursor, anchor) - static_cast<int>(MAX_SURROUNDING_BYTES / 2));
|
||||
int window_end = window_start + static_cast<int>(MAX_SURROUNDING_BYTES);
|
||||
int const max_pos = std::max(cursor, anchor);
|
||||
if (window_end < max_pos) {
|
||||
window_end = max_pos;
|
||||
window_start = std::max(0,
|
||||
window_end - static_cast<int>(MAX_SURROUNDING_BYTES));
|
||||
window_start
|
||||
= std::max(0, window_end - static_cast<int>(MAX_SURROUNDING_BYTES));
|
||||
}
|
||||
if (window_end > size)
|
||||
window_end = size;
|
||||
if (window_end - window_start
|
||||
> static_cast<int>(MAX_SURROUNDING_BYTES)) {
|
||||
if (window_end - window_start > static_cast<int>(MAX_SURROUNDING_BYTES)) {
|
||||
window_start = window_end - static_cast<int>(MAX_SURROUNDING_BYTES);
|
||||
}
|
||||
|
||||
@@ -357,8 +355,8 @@ auto App::init_wayland() -> void
|
||||
|
||||
static zwp_text_input_v3_listener text_input_listener {};
|
||||
{
|
||||
auto ti_enter = [](void *data, zwp_text_input_v3 *, wl_surface *surface)
|
||||
-> void {
|
||||
auto ti_enter
|
||||
= [](void *data, zwp_text_input_v3 *, wl_surface *surface) -> void {
|
||||
auto *app = static_cast<App *>(data);
|
||||
bool const focused_surface
|
||||
= surface && surface == app->m_wayland.surface;
|
||||
@@ -375,7 +373,8 @@ auto App::init_wayland() -> void
|
||||
}
|
||||
};
|
||||
|
||||
auto ti_leave = [](void *data, zwp_text_input_v3 *, wl_surface *) -> void {
|
||||
auto ti_leave
|
||||
= [](void *data, zwp_text_input_v3 *, wl_surface *) -> void {
|
||||
auto *app = static_cast<App *>(data);
|
||||
app->m_ime.seat_focus = false;
|
||||
app->m_ime.enabled = false;
|
||||
@@ -386,8 +385,9 @@ auto App::init_wayland() -> void
|
||||
app->m_gui->ime_clear_preedit();
|
||||
};
|
||||
|
||||
auto ti_preedit = [](void *data, zwp_text_input_v3 *, char const *text,
|
||||
int32_t cursor_begin, int32_t cursor_end) -> void {
|
||||
auto ti_preedit
|
||||
= [](void *data, zwp_text_input_v3 *, char const *text,
|
||||
int32_t cursor_begin, int32_t cursor_end) -> void {
|
||||
auto *app = static_cast<App *>(data);
|
||||
auto &pending = app->m_ime.pending;
|
||||
pending.has_preedit = true;
|
||||
@@ -396,8 +396,8 @@ auto App::init_wayland() -> void
|
||||
pending.cursor_end = cursor_end;
|
||||
};
|
||||
|
||||
auto ti_commit = [](void *data, zwp_text_input_v3 *, char const *text)
|
||||
-> void {
|
||||
auto ti_commit
|
||||
= [](void *data, zwp_text_input_v3 *, char const *text) -> void {
|
||||
auto *app = static_cast<App *>(data);
|
||||
auto &pending = app->m_ime.pending;
|
||||
pending.has_commit = true;
|
||||
@@ -405,7 +405,7 @@ auto App::init_wayland() -> void
|
||||
};
|
||||
|
||||
auto ti_delete = [](void *data, zwp_text_input_v3 *, uint32_t before,
|
||||
uint32_t after) -> void {
|
||||
uint32_t after) -> void {
|
||||
auto *app = static_cast<App *>(data);
|
||||
auto &pending = app->m_ime.pending;
|
||||
pending.has_delete = true;
|
||||
@@ -413,15 +413,16 @@ auto App::init_wayland() -> void
|
||||
pending.after = after;
|
||||
};
|
||||
|
||||
auto ti_done = [](void *data, zwp_text_input_v3 *, uint32_t serial) -> void {
|
||||
auto ti_done
|
||||
= [](void *data, zwp_text_input_v3 *, uint32_t serial) -> void {
|
||||
auto *app = static_cast<App *>(data);
|
||||
app->m_ime.pending_done = true;
|
||||
app->m_ime.pending_serial = serial;
|
||||
app->m_ime.surrounding_dirty = true;
|
||||
};
|
||||
|
||||
text_input_listener = { ti_enter, ti_leave, ti_preedit, ti_commit,
|
||||
ti_delete, ti_done };
|
||||
text_input_listener
|
||||
= { ti_enter, ti_leave, ti_preedit, ti_commit, ti_delete, ti_done };
|
||||
}
|
||||
|
||||
static auto ensure_text_input = +[](App *app) -> void {
|
||||
@@ -481,8 +482,8 @@ auto App::init_wayland() -> void
|
||||
app->m_wayland.kde_blur_mgr
|
||||
= static_cast<org_kde_kwin_blur_manager *>(wl_registry_bind(
|
||||
registry, name, &org_kde_kwin_blur_manager_interface, 1));
|
||||
} else if (std::strcmp(interface,
|
||||
zwp_text_input_manager_v3_interface.name)
|
||||
} else if (std::strcmp(
|
||||
interface, zwp_text_input_manager_v3_interface.name)
|
||||
== 0) {
|
||||
app->m_wayland.text_input_mgr
|
||||
= static_cast<zwp_text_input_manager_v3 *>(wl_registry_bind(
|
||||
@@ -588,15 +589,27 @@ void App::on_settings_changed(XdpSettings * /*self*/, char const *ns,
|
||||
char const *key, GVariant * /*value*/, gpointer data)
|
||||
{
|
||||
auto *app = static_cast<App *>(data);
|
||||
if (g_strcmp0(ns, "org.freedesktop.appearance") == 0
|
||||
&& g_strcmp0(key, "color-scheme") == 0) {
|
||||
guint v = xdp_settings_read_uint(app->m_xdp.settings,
|
||||
"org.freedesktop.appearance", "color-scheme", NULL, NULL);
|
||||
if (g_strcmp0(ns, "org.freedesktop.appearance") == 0) {
|
||||
if (g_strcmp0(key, "color-scheme") == 0) {
|
||||
guint v = xdp_settings_read_uint(app->m_xdp.settings,
|
||||
"org.freedesktop.appearance", "color-scheme", NULL, NULL);
|
||||
|
||||
if (v == 1)
|
||||
app->m_active_theme = Theme::Dark;
|
||||
else
|
||||
app->m_active_theme = Theme::Light;
|
||||
if (v == 1)
|
||||
app->m_active_theme = Theme::Dark;
|
||||
else
|
||||
app->m_active_theme = Theme::Light;
|
||||
} else if (g_strcmp0(key, "accent-color") == 0) {
|
||||
auto val = xdp_settings_read_value(app->m_xdp.settings,
|
||||
"org.freedesktop.appearance", "accent-color", NULL, NULL);
|
||||
if (val) {
|
||||
gdouble r, g, b;
|
||||
g_variant_get(val, "(ddd)", &r, &g, &b);
|
||||
app->m_accent_color.r = static_cast<u8>(r * 255);
|
||||
app->m_accent_color.g = static_cast<u8>(g * 255);
|
||||
app->m_accent_color.b = static_cast<u8>(b * 255);
|
||||
g_variant_unref(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -612,6 +625,17 @@ auto App::init_theme_portal() -> void
|
||||
else
|
||||
m_active_theme = Theme::Light;
|
||||
|
||||
auto val = xdp_settings_read_value(m_xdp.settings,
|
||||
"org.freedesktop.appearance", "accent-color", NULL, NULL);
|
||||
if (val) {
|
||||
gdouble r, g, b;
|
||||
g_variant_get(val, "(ddd)", &r, &g, &b);
|
||||
m_accent_color.r = static_cast<u8>(r * 255);
|
||||
m_accent_color.g = static_cast<u8>(g * 255);
|
||||
m_accent_color.b = static_cast<u8>(b * 255);
|
||||
g_variant_unref(val);
|
||||
}
|
||||
|
||||
g_signal_connect(
|
||||
m_xdp.settings, "changed", G_CALLBACK(on_settings_changed), this);
|
||||
}
|
||||
@@ -828,8 +852,7 @@ auto App::process_pending_text_input() -> void
|
||||
}
|
||||
|
||||
if (m_ime.pending.has_commit) {
|
||||
m_gui->ime_commit_text(
|
||||
*m_ime.bound_text, m_ime.pending.commit_text);
|
||||
m_gui->ime_commit_text(*m_ime.bound_text, m_ime.pending.commit_text);
|
||||
}
|
||||
|
||||
if (m_ime.pending.has_preedit) {
|
||||
@@ -880,8 +903,8 @@ auto App::update_text_input_state(
|
||||
}
|
||||
|
||||
if (auto info = m_gui->text_input_surrounding(id, text)) {
|
||||
auto slice = clamp_surrounding_text(
|
||||
info->text, info->cursor, info->anchor);
|
||||
auto slice
|
||||
= clamp_surrounding_text(info->text, info->cursor, info->anchor);
|
||||
if (m_ime.surrounding_dirty || slice.text != m_ime.last_surrounding
|
||||
|| slice.cursor != m_ime.last_cursor
|
||||
|| slice.anchor != m_ime.last_anchor) {
|
||||
|
||||
Reference in New Issue
Block a user