]> git.lyx.org Git - features.git/commitdiff
Raise the window in single-instance mode
authorEnrico Forestieri <forenr@lyx.org>
Tue, 21 Apr 2020 19:55:20 +0000 (21:55 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:56 +0000 (15:48 +0200)
Other than issuing a warning on the console, now the LyX window is
raised when in single-instance mode and no files to load are specified.
In this way, the user is aware that something happened after double
clicking the program icon. To support this functionality the new lfun
window-raise has been introduced.

src/FuncCode.h
src/LyXAction.cpp
src/Server.cpp
src/frontends/qt/GuiView.cpp

index 84deea34dfe7b04bb2a1012531bce968ff127053..585d1e15809de8aec6e9193c5195e24a66ced47f 100644 (file)
@@ -489,6 +489,7 @@ enum FuncCode
        // 380
        LFUN_MASTER_BUFFER_FORALL,      // spitz 20191231
        LFUN_IF_RELATIVES,              // spitz 20200102
+       LFUN_WINDOW_RAISE,              // forenr, 20202104
        LFUN_LASTACTION                 // end of the table
 };
 
index 9f4d3a558916039f191ecfa6be0e92a23950dd45..c9f76258f897d89a3bed41b03816febf6bc1fb95 100644 (file)
@@ -4220,6 +4220,18 @@ void LyXAction::init()
  */
                { LFUN_WINDOW_NEW, "window-new", NoBuffer, Buffer },
 
+/*!
+ * \var lyx::FuncCode lyx::LFUN_WINDOW_RAISE
+ * \li Action: Raises the LyX window.
+ * \li Notion: Brings the LyX window to the front. Such behavior is allowed
+               on Windows only when no other application has focus.
+               This action is used when LyX is in single instance mode.
+ * \li Syntax: window-raise
+ * \li Origin: forenr, 21 Apr 2020
+ * \endvar
+ */
+               { LFUN_WINDOW_RAISE, "window-raise", ReadOnly | NoBuffer, Hidden },
+
 /*!
  * \var lyx::FuncCode lyx::LFUN_WORD_BACKWARD
  * \li Action: Moves the cursor to the logically previous beginning of a word.
index 5fb089d758300cc69b3980081fb912afe7e75d4d..dfc932c67466f0ec1c5a8a3c2f3062be6680d326 100644 (file)
@@ -1002,14 +1002,25 @@ struct Sleep : QThread
 
 bool LyXComm::loadFilesInOtherInstance()
 {
+       int pipefd;
+       FileName const pipe(inPipeName());
+
        if (theFilesToLoad().empty()) {
                LYXERR0("LyX is already running in another instance\n"
                        "and 'use single instance' is active.");
+               // Wait a while for the other instance to reset the connection
+               Sleep::millisec(200);
+               pipefd = ::open(pipe.toFilesystemEncoding().c_str(), O_WRONLY);
+               if (pipefd >= 0) {
+                       string const cmd = "LYXCMD:pipe:window-raise\n";
+                       if (::write(pipefd, cmd.c_str(), cmd.length()) < 0)
+                               LYXERR0("Cannot communicate with running instance!");
+                       ::close(pipefd);
+               }
                return true;
        }
-       int pipefd;
+
        int loaded_files = 0;
-       FileName const pipe(inPipeName());
        vector<string>::iterator it = theFilesToLoad().begin();
        while (it != theFilesToLoad().end()) {
                FileName fname = fileSearch(string(), os::internal_path(*it),
index 78e0817cdd37ef67f060c1f140d4a7f176e346d3..382496e3e501dd14b33c7b166326596d1f672f30 100644 (file)
@@ -2312,6 +2312,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 
        case LFUN_SERVER_GOTO_FILE_ROW:
        case LFUN_LYX_ACTIVATE:
+       case LFUN_WINDOW_RAISE:
                break;
        case LFUN_FORWARD_SEARCH:
                enable = !(lyxrc.forward_search_dvi.empty() && lyxrc.forward_search_pdf.empty());
@@ -4502,6 +4503,12 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        activateWindow();
                        break;
 
+               case LFUN_WINDOW_RAISE:
+                       raise();
+                       activateWindow();
+                       showNormal();
+                       break;
+
                case LFUN_FORWARD_SEARCH: {
                        // it seems safe to assume we have a document buffer, since
                        // getStatus wants one.