From dc163f625ef006c8550791122bda28fb3eb67e3d Mon Sep 17 00:00:00 2001 From: marha Date: Thu, 17 Jan 2013 08:32:19 +0100 Subject: xlaunch: Use dialog for prompting for password input instead of console --- xorg-server/hw/xwin/xlaunch/main.cc | 131 ++++++++++++++-------- xorg-server/hw/xwin/xlaunch/resources/dialog.rc | 15 +++ xorg-server/hw/xwin/xlaunch/resources/resources.h | 4 + 3 files changed, 103 insertions(+), 47 deletions(-) (limited to 'xorg-server/hw/xwin/xlaunch') diff --git a/xorg-server/hw/xwin/xlaunch/main.cc b/xorg-server/hw/xwin/xlaunch/main.cc index 9211fb503..8e13b4436 100644 --- a/xorg-server/hw/xwin/xlaunch/main.cc +++ b/xorg-server/hw/xwin/xlaunch/main.cc @@ -54,56 +54,104 @@ static bool ContainPrintableChars(const char *Buf, unsigned Nbr) return false; } -static bool CheckOutput(HANDLE hChildStdoutRd, int hStdOut, HANDLE hConsoleOutput, HWND hConsoleWnd) +/* + * Process messages for the prompt dialog. + */ + +static INT_PTR CALLBACK DisplayPromptDlgProc (HWND hwndDialog, UINT message, WPARAM wParam, LPARAM lParam) { - DWORD NbrAvail=0; - PeekNamedPipe(hChildStdoutRd, NULL, NULL, NULL, &NbrAvail, NULL); - if (NbrAvail) + static LPARAM Param; + static UINT PasswordChar; + switch (message) { - char Buf[128]; - size_t Nbr = _read(hStdOut, Buf, sizeof(Buf)); - DWORD NbrWritten; - WriteConsole(hConsoleOutput, Buf, Nbr, &NbrWritten, NULL); - if (hConsoleWnd && ContainPrintableChars(Buf,NbrWritten)) + case WM_INITDIALOG: { - // Only show console again when there are new characters printed - ShowWindow(hConsoleWnd, SW_SHOW ); // make it visible again - return true; + HWND hwndDesk=GetForegroundWindow(); + RECT rc, rcDlg, rcDesk; + + PasswordChar=SendDlgItemMessage(hwndDialog, IDC_INPUT, EM_GETPASSWORDCHAR, 0, 0); + + GetWindowRect (hwndDesk, &rcDesk); + GetWindowRect (hwndDialog, &rcDlg); + CopyRect (&rc, &rcDesk); + + OffsetRect (&rcDlg, -rcDlg.left, -rcDlg.top); + OffsetRect (&rc, -rc.left, -rc.top); + OffsetRect (&rc, -rcDlg.right, -rcDlg.bottom); + + SetWindowPos (hwndDialog, + HWND_TOPMOST, + rcDesk.left + (rc.right / 2), + rcDesk.top + (rc.bottom / 2), + 0, 0, + SWP_NOSIZE | SWP_FRAMECHANGED); + + Param=lParam; + SendDlgItemMessage(hwndDialog, IDC_PROMPT_DESC, WM_SETTEXT, 0, lParam); + return TRUE; } + break; + + case WM_COMMAND: + switch (LOWORD (wParam)) + { + case IDOK: + SendDlgItemMessage(hwndDialog, IDC_INPUT, WM_GETTEXT, 128, Param); + EndDialog(hwndDialog, Param); + return TRUE; + case IDCANCEL: + EndDialog(hwndDialog, NULL); + return TRUE; + case IDC_PASSWORD: + { + HWND hDlg=GetDlgItem(hwndDialog, IDC_INPUT); + if (HIWORD(wParam)==BN_CLICKED) + { + if (BST_CHECKED==SendDlgItemMessage(hwndDialog, IDC_PASSWORD, BM_GETCHECK, 0, 0)) + SendMessage(hDlg, EM_SETPASSWORDCHAR, 0, 0); + else + SendMessage(hDlg, EM_SETPASSWORDCHAR, (WPARAM)PasswordChar, 0); + } + InvalidateRect(hDlg, NULL, TRUE); + } + return TRUE; + } + break; + + case WM_CLOSE: + EndDialog (hwndDialog, NULL); + return TRUE; } - return false; -} -#define NRINPUTS 50 + return FALSE; +} -static int CheckInput(HANDLE hConsoleInput, char *Buf, HWND hConsoleWnd) +static bool CheckOutput(HANDLE hChildStdoutRd, int hStdOut, int hStdIn) { - INPUT_RECORD Input[NRINPUTS]; DWORD NbrAvail=0; - GetNumberOfConsoleInputEvents(hConsoleInput, &NbrAvail); - int w=0; + PeekNamedPipe(hChildStdoutRd, NULL, NULL, NULL, &NbrAvail, NULL); if (NbrAvail) { - DWORD NbrRead=0; - ReadConsoleInput(hConsoleInput, Input, NRINPUTS, &NbrRead); - for (int i=0; i