Process focus events

Should help prevent accidents in other windows.
This commit is contained in:
Přemysl Eric Janouch 2021-06-29 04:54:47 +02:00
parent 0335443b22
commit 7e531e95c5
Signed by: p
GPG Key ID: A0420B94F92B9493
5 changed files with 26 additions and 5 deletions

View File

@ -1,4 +1,4 @@
Copyright (c) 2016 - 2020, Přemysl Eric Janouch <p@janouch.name>
Copyright (c) 2016 - 2021, Přemysl Eric Janouch <p@janouch.name>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

6
NEWS
View File

@ -1,3 +1,9 @@
1.1.0 (20xx-xx-xx)
* Now requesting and processing terminal de/focus events,
using a new "defocused" attribute for selected rows
1.0.0 (2020-11-05)
* Coming with a real manual page instead of a help2man-generated stub

View File

@ -12,6 +12,7 @@ colors = {
selection = "231 202"
multiselect = "231 88"
defocused = "231 250"
directory = "16 231 bold"
incoming = "28"

View File

@ -1,7 +1,7 @@
/*
* nncmpp -- the MPD client you never knew you needed
*
* Copyright (c) 2016 - 2020, Přemysl Eric Janouch <p@janouch.name>
* Copyright (c) 2016 - 2021, Přemysl Eric Janouch <p@janouch.name>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
@ -39,6 +39,8 @@
* Can't use A_REVERSE because bold'd be bright.
* Unfortunately ran out of B&W attributes. */ \
XX( MULTISELECT, multiselect, -1, 6, 0 ) \
/* This ought to be indicative enough. */ \
XX( DEFOCUSED, defocused, -1, -1, A_UNDERLINE ) \
XX( SCROLLBAR, scrollbar, -1, -1, 0 ) \
/* These are for debugging only */ \
XX( WARNING, warning, 3, -1, 0 ) \
@ -682,6 +684,7 @@ static struct app_context
struct poller_timer tk_timer; ///< termo timeout timer
bool locale_is_utf8; ///< The locale is Unicode
bool use_partial_boxes; ///< Use Unicode box drawing chars
bool focused; ///< Whether the terminal has focus
struct attrs attrs[ATTRIBUTE_COUNT];
}
@ -910,6 +913,9 @@ app_init_context (void)
// TODO: make this configurable
g.use_partial_boxes = g.locale_is_utf8;
// Presumably, although not necessarily; unsure if queryable at all
g.focused = true;
app_init_attributes ();
}
@ -1338,11 +1344,13 @@ app_draw_view (void)
bool override_colors = true;
if (item_index == tab->item_selected)
row_attrs = APP_ATTR (SELECTION);
row_attrs = g.focused
? APP_ATTR (SELECTION) : APP_ATTR (DEFOCUSED);
else if (tab->item_mark > -1 &&
((item_index >= tab->item_mark && item_index <= tab->item_selected)
|| (item_index >= tab->item_selected && item_index <= tab->item_mark)))
row_attrs = APP_ATTR (MULTISELECT);
row_attrs = g.focused
? APP_ATTR (MULTISELECT) : APP_ATTR (DEFOCUSED);
else
override_colors = false;
@ -2223,6 +2231,12 @@ app_init_bindings (const char *keymap,
static bool
app_process_termo_event (termo_key_t *event)
{
if (event->type == TERMO_TYPE_FOCUS)
{
g.focused = !!event->code.focused;
app_invalidate ();
}
struct binding dummy = { *event, 0, 0 }, *binding;
if (g.editor.line)
{

2
termo

@ -1 +1 @@
Subproject commit f7912a8ce7bbf7f701b5217bbb3879b13b66cfe7
Subproject commit 94a77a10d87367ef33156cd68b2caf601c3f72d0