diff --git a/src/overlay.cpp b/src/overlay.cpp index a53bc14..f1467b9 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -1,82 +1,88 @@ /* * Copyright (C) 2018 Intevation GmbH * * This file is part of GpgOL. * * GpgOL is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * GpgOL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, see . */ #include "config.h" #include "overlay.h" #include "common.h" #include "cpphelp.h" #include #include -Overlay::Overlay (HWND wid, const std::string &text) +Overlay::Overlay (HWND wid, const std::string &text): m_wid (wid) { + // Disable the window early to avoid it beeing closed. + EnableWindow (m_wid, FALSE); std::vector args; // Collect the arguments char *gpg4win_dir = get_gpg4win_dir (); if (!gpg4win_dir) { TRACEPOINT; + EnableWindow (m_wid, TRUE); return; } const auto overlayer = std::string (gpg4win_dir) + "\\bin\\overlayer.exe"; xfree (gpg4win_dir); args.push_back (overlayer); args.push_back (std::string ("--hwnd")); args.push_back (std::to_string ((int) wid)); args.push_back (std::string ("--overlayText")); args.push_back (text); char **cargs = vector_to_cArray (args); m_overlayCtx = GpgME::Context::createForEngine (GpgME::SpawnEngine); if (!m_overlayCtx) { // can't happen release_cArray (cargs); TRACEPOINT; + EnableWindow (m_wid, TRUE); return; } GpgME::Data mystderr(GpgME::Data::null); GpgME::Data mystdout(GpgME::Data::null); GpgME::Error err = m_overlayCtx->spawnAsync (cargs[0], const_cast (cargs), m_overlayStdin, mystdout, mystderr, (GpgME::Context::SpawnFlags) ( GpgME::Context::SpawnAllowSetFg | GpgME::Context::SpawnShowWindow)); release_cArray (cargs); - TRACEPOINT; log_debug ("%s:%s: Created overlay window over %p", SRCNAME, __func__, wid); } Overlay::~Overlay() { log_debug ("%s:%s: Stopping overlay.", SRCNAME, __func__); + m_overlayCtx->wait (); m_overlayStdin.write ("quit\n", 5); + m_overlayStdin.write (nullptr, 0); + EnableWindow (m_wid, TRUE); } diff --git a/src/overlay.h b/src/overlay.h index 9f8ed62..3e9c634 100644 --- a/src/overlay.h +++ b/src/overlay.h @@ -1,46 +1,47 @@ #ifndef OVERLAY_H #define OVERLAY_H /* @file overlay.h * @brief Overlay something through WinAPI. * * Copyright (C) 2018 Intevation GmbH * * This file is part of GpgOL. * * GpgOL is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * GpgOL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, see . */ #include #include #include namespace GpgME { class Context; } // namespace GpgME class Overlay { public: /* Create an overlay over a foreign window */ Overlay(HWND handle, const std::string &text); ~Overlay(); private: std::unique_ptr m_overlayCtx; GpgME::Data m_overlayStdin; + HWND m_wid; }; #endif // OVERLAY_H