[client,sdl] position active input

When querying for credentials position the selected input field to the
first element not already containing a value.
This commit is contained in:
akallabeth
2025-12-07 08:50:23 +01:00
parent 0f5c53d3e5
commit 266bf0e153
3 changed files with 31 additions and 12 deletions

View File

@@ -585,7 +585,23 @@ BOOL sdl_auth_dialog_show(const SDL_UserAuthArg* args)
flags = { 0, 0, SdlInputWidgetPair::SDL_INPUT_MASK };
}
}
SdlInputWidgetPairList ilist(args->title, prompt, initial, flags);
ssize_t selected = -1;
switch (args->result)
{
case AUTH_SMARTCARD_PIN:
case AUTH_RDSTLS:
break;
default:
if (args->user)
{
selected++;
if (args->domain)
selected++;
}
break;
}
SdlInputWidgetPairList ilist(args->title, prompt, initial, flags, selected);
rc = ilist.run(result);
}
@@ -606,6 +622,7 @@ BOOL sdl_auth_dialog_show(const SDL_UserAuthArg* args)
pwd = _strdup(result[2].c_str());
}
}
return sdl_push_user_event(SDL_EVENT_USER_AUTH_RESULT, user, domain, pwd, rc);
}

View File

@@ -30,7 +30,7 @@ static const Uint32 vpadding = 5;
SdlInputWidgetPairList::SdlInputWidgetPairList(const std::string& title,
const std::vector<std::string>& labels,
const std::vector<std::string>& initial,
const std::vector<Uint32>& flags)
const std::vector<Uint32>& flags, ssize_t selected)
{
assert(labels.size() == initial.size());
assert(labels.size() == flags.size());
@@ -59,6 +59,7 @@ SdlInputWidgetPairList::SdlInputWidgetPairList(const std::string& title,
static_cast<Sint32>(input_height), static_cast<Sint32>(widget_width),
static_cast<Sint32>(widget_heigth));
_buttons.set_highlight(0);
_CurrentActiveTextInput = selected;
}
}
@@ -145,7 +146,7 @@ int SdlInputWidgetPairList::run(std::vector<std::string>& result)
{
int res = -1;
ssize_t LastActiveTextInput = -1;
ssize_t CurrentActiveTextInput = next(-1);
_CurrentActiveTextInput = next(_CurrentActiveTextInput);
if (!_window || !_renderer)
return -2;
@@ -174,7 +175,7 @@ int SdlInputWidgetPairList::run(std::vector<std::string>& result)
{
case SDLK_BACKSPACE:
{
auto cur = get(CurrentActiveTextInput);
auto cur = get(_CurrentActiveTextInput);
if (cur)
{
if ((event.key.mod & SDL_KMOD_CTRL) != 0)
@@ -191,7 +192,7 @@ int SdlInputWidgetPairList::run(std::vector<std::string>& result)
}
break;
case SDLK_TAB:
CurrentActiveTextInput = next(CurrentActiveTextInput);
_CurrentActiveTextInput = next(_CurrentActiveTextInput);
break;
case SDLK_RETURN:
case SDLK_RETURN2:
@@ -206,7 +207,7 @@ int SdlInputWidgetPairList::run(std::vector<std::string>& result)
case SDLK_V:
if ((event.key.mod & SDL_KMOD_CTRL) != 0)
{
auto cur = get(CurrentActiveTextInput);
auto cur = get(_CurrentActiveTextInput);
if (cur)
{
auto text = SDL_GetClipboardText();
@@ -221,7 +222,7 @@ int SdlInputWidgetPairList::run(std::vector<std::string>& result)
break;
case SDL_EVENT_TEXT_INPUT:
{
auto cur = get(CurrentActiveTextInput);
auto cur = get(_CurrentActiveTextInput);
if (cur)
{
if (!cur->append_str(event.text.text))
@@ -251,7 +252,7 @@ int SdlInputWidgetPairList::run(std::vector<std::string>& result)
{
auto val = get_index(event.button);
if (valid(val))
CurrentActiveTextInput = val;
_CurrentActiveTextInput = val;
auto button = _buttons.get_selected(event.button);
if (button)
@@ -273,9 +274,9 @@ int SdlInputWidgetPairList::run(std::vector<std::string>& result)
}
} while (SDL_PollEvent(&event));
if (LastActiveTextInput != CurrentActiveTextInput)
if (LastActiveTextInput != _CurrentActiveTextInput)
{
LastActiveTextInput = CurrentActiveTextInput;
LastActiveTextInput = _CurrentActiveTextInput;
}
for (auto& cur : _list)
@@ -283,7 +284,7 @@ int SdlInputWidgetPairList::run(std::vector<std::string>& result)
if (!cur->set_highlight(false))
throw;
}
auto cur = get(CurrentActiveTextInput);
auto cur = get(_CurrentActiveTextInput);
if (cur)
{
if (!cur->set_highlight(true))

View File

@@ -32,7 +32,7 @@ class SdlInputWidgetPairList : public SdlWidgetList
public:
SdlInputWidgetPairList(const std::string& title, const std::vector<std::string>& labels,
const std::vector<std::string>& initial,
const std::vector<Uint32>& flags);
const std::vector<Uint32>& flags, ssize_t selected = -1);
SdlInputWidgetPairList(const SdlInputWidgetPairList& other) = delete;
SdlInputWidgetPairList(SdlInputWidgetPairList&& other) = delete;
@@ -59,4 +59,5 @@ class SdlInputWidgetPairList : public SdlWidgetList
std::shared_ptr<SdlInputWidgetPair> get(ssize_t index);
std::vector<std::shared_ptr<SdlInputWidgetPair>> _list;
ssize_t _CurrentActiveTextInput = -1;
};