Fix [#26981] Command window is not opening in 2.57.0
authorNathan Letwory <nathan@letworyinteractive.com>
Mon, 2 May 2011 08:07:24 +0000 (08:07 +0000)
committerNathan Letwory <nathan@letworyinteractive.com>
Mon, 2 May 2011 08:07:24 +0000 (08:07 +0000)
  Reported by Thomas Engel
Fix [#26938] Blender Zoom not working after startup (Windows)
  Reported by Ilija Boshkov

by applying patch [#26881] Fix for console disappearing in debug mode [Windows]
  Submitted by Alexander Kuznetsov (AlexK)

The patch moves console toggling code into GHOST and improves on the toggling behaviour.

The patch changes handling of WM_SYSCOMMAND so that alt-key toggling isn't a problem anymore.

intern/ghost/GHOST_C-api.h
intern/ghost/GHOST_ISystem.h
intern/ghost/intern/GHOST_C-api.cpp
intern/ghost/intern/GHOST_SystemWin32.cpp
intern/ghost/intern/GHOST_SystemWin32.h
source/blender/blenlib/BLI_winstuff.h
source/blender/blenlib/intern/winstuff.c
source/blender/windowmanager/intern/wm_init_exit.c
source/blender/windowmanager/intern/wm_operators.c

index be8dc138797d1f9b8a028ccacc47ccb9e74cc140..75837239c4ac75fb30152750598a066aa98f4024 100644 (file)
@@ -845,6 +845,18 @@ extern GHOST_TUns8* GHOST_getClipboard(int selection);
 extern void GHOST_putClipboard(GHOST_TInt8 *buffer, int selection);
 
 
+
+/**
+ * Toggles console
+ * @action     0 - Hides
+ *                     1 - Shows
+ *                     2 - Toggles
+ *                     3 - Hides if it runs not from  command line
+ *                     * - Does nothing
+ * @return current status (1 -visible, 0 - hidden)
+ */
+extern int GHOST_toggleConsole(int action);
+
 #ifdef __cplusplus
 }
 #endif
index 38c732153d79c201aeb97f770023f3ef52bd23a2..69e10070be57a87c87fbcc8848b0ae296b9eb465 100644 (file)
@@ -355,6 +355,16 @@ public:
         */
        virtual GHOST_TSuccess getButtonState(GHOST_TButtonMask mask, bool& isDown) const = 0;
 
+       /**
+        * Toggles console
+        * @action      0 - Hides
+        *                      1 - Shows
+        *                      2 - Toggles
+        *                      3 - Hides if it runs not from  command line
+        *                      * - Does nothing
+        * @return current status (1 -visible, 0 - hidden)
+        */
+       virtual int toggleConsole(int action) = 0;
        
        /***************************************************************************************
         ** Access to clipboard.
index a1e1bafa82fe05d84bd9b02d0fbdc5380ba54012..7ba8d7db411c3d281a1bb9dce7ea47c8804d1165 100644 (file)
@@ -877,3 +877,9 @@ void GHOST_putClipboard(GHOST_TInt8 *buffer, int selection)
        GHOST_ISystem* system = GHOST_ISystem::getSystem();
        system->putClipboard(buffer, selection);
 }
+
+int GHOST_toggleConsole(int action)
+{
+       GHOST_ISystem* system = GHOST_ISystem::getSystem();
+       return system->toggleConsole(action);
+}
index dc16711b532979355ce7b4d282313b0364e50af1..c901c40271697c49b7a1eb6e2a31c83a84717f27 100644 (file)
@@ -174,6 +174,8 @@ GHOST_SystemWin32::GHOST_SystemWin32()
        GHOST_ASSERT(m_displayManager, "GHOST_SystemWin32::GHOST_SystemWin32(): m_displayManager==0\n");
        m_displayManager->initialize();
 
+       m_consoleStatus = 1;
+
        // Check if current keyboard layout uses AltGr and save keylayout ID for
        // specialized handling if keys like VK_OEM_*. I.e. french keylayout
        // generates VK_OEM_8 for their exclamation key (key left of right shift)
@@ -186,6 +188,7 @@ GHOST_SystemWin32::~GHOST_SystemWin32()
 {
        // Shutdown COM
        OleUninitialize();
+       toggleConsole(1);
 }
 
 
@@ -847,7 +850,14 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                         * a dead key that is pressed while holding down the alt key.
                                         * To prevent the sound, DefWindowProc must be avoided by return
                                         */
-                                       return 0;
+                                       break;
+                               case WM_SYSCOMMAND:
+                                       /* The WM_SYSCHAR message is sent to the window when system commands such as 
+                                        * maximize, minimize  or close the window are triggered. Also it is sent when ALT 
+                                        * button is press for menu. To prevent this we must return preventing DefWindowProc.
+                                        */
+                                       if(wParam==SC_KEYMENU) return 0;
+                                       break;
                                ////////////////////////////////////////////////////////////////////////
                                // Tablet events, processed
                                ////////////////////////////////////////////////////////////////////////
@@ -1047,8 +1057,12 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
                                         * DestroyWindow function sends the WM_NCDESTROY message to the window following the WM_DESTROY
                                         * message. WM_DESTROY is used to free the allocated memory object associated with the window. 
                                         */
+                                       break;
                                case WM_KILLFOCUS:
-                                       /* The WM_KILLFOCUS message is sent to a window immediately before it loses the keyboard focus. */
+                                       /* The WM_KILLFOCUS message is sent to a window immediately before it loses the keyboard focus. 
+                                        * We want to prevent this if a window is still active and it loses focus to nowhere*/
+                                       if(!wParam && hwnd==GetActiveWindow())
+                                               SetFocus(hwnd);
                                case WM_SHOWWINDOW:
                                        /* The WM_SHOWWINDOW message is sent to a window when the window is about to be hidden or shown. */
                                case WM_WINDOWPOSCHANGING:
@@ -1196,3 +1210,32 @@ void GHOST_SystemWin32::putClipboard(GHOST_TInt8 *buffer, bool selection) const
                return;
        }
 }
+
+int GHOST_SystemWin32::toggleConsole(int action)
+{
+       switch(action)
+       {
+               case 3: //hide if no console
+                       {
+                       CONSOLE_SCREEN_BUFFER_INFO csbi = {{0}};
+                       if(!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi) || csbi.dwCursorPosition.X || csbi.dwCursorPosition.Y>1)
+                               break;
+                       }
+               case 0: //hide
+                       ShowWindow(GetConsoleWindow(),SW_HIDE);
+                       m_consoleStatus = 0;
+                       break;
+               case 1: //show
+                       ShowWindow(GetConsoleWindow(),SW_SHOW);
+                       m_consoleStatus = 1;
+                       break;
+               case 2: //toggle
+                       ShowWindow(GetConsoleWindow(),m_consoleStatus?SW_HIDE:SW_SHOW);
+                       m_consoleStatus=!m_consoleStatus;
+                       break;
+
+       };
+
+
+       return m_consoleStatus;
+}
index d79b9a22b698236b20f0d92e416d5b33ef74592a..2dad3a6f44d768e94c90c1e97ac1d74804bd7ffa 100644 (file)
@@ -415,6 +415,17 @@ protected:
         * Initiates WM_INPUT messages from keyboard 
         */
        GHOST_TInt32 initKeyboardRawInput(void);
+
+       /**
+ * Toggles console
+ * @action     0 - Hides
+ *                     1 - Shows
+ *                     2 - Toggles
+ *                     3 - Hides if it runs not from  command line
+ *                     * - Does nothing
+ * @return current status (1 -visible, 0 - hidden)
+ */
+       int toggleConsole(int action);
        
        /** The current state of the modifier keys. */
        GHOST_ModifierKeys m_modifierKeys;
@@ -431,6 +442,9 @@ protected:
        /** stores keyboard layout. */
        HKL m_keylayout;
 
+       /** Console status */
+       int m_consoleStatus;
+
        /** handle for user32.dll*/
        HMODULE user32;
        #ifdef NEED_RAW_PROC
@@ -471,6 +485,5 @@ inline void GHOST_SystemWin32::handleKeyboardChange(void)
                }
        }
 }
-
 #endif // _GHOST_SYSTEM_WIN32_H_
 
index 176e7319bf78fa60f1d8da7a0a0788d6a26188e8..d0eb3c7d67d3d6a4713cf87c146cc9ac80ab4ec4 100644 (file)
@@ -127,7 +127,6 @@ typedef struct _DIR {
        struct dirent direntry;
 } DIR;
 
-int IsConsoleEmpty(void);
 void RegisterBlendExtension(void);
 DIR *opendir (const char *path);
 struct dirent *readdir(DIR *dp);
index 596ab2b04703eb6fe89777f71fbd64e4f91e907b..66080ed2a8516673adbaafab6d8156b64667b00d 100644 (file)
@@ -66,14 +66,6 @@ int BLI_getInstallationDir( char * str ) {
        return 1;
 }
 
-int IsConsoleEmpty(void)
-{
-       CONSOLE_SCREEN_BUFFER_INFO csbi = {{0}};
-       HANDLE hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
-
-       return GetConsoleScreenBufferInfo(hStdOutput, &csbi) && csbi.dwCursorPosition.X == 0 && csbi.dwCursorPosition.Y == 0;
-}
-
 void RegisterBlendExtension_Fail(HKEY root)
 {
        printf("failed\n");
index 58485b1f54410033acea4cbfd6366887bd304ef6..620d3314d431dee0ee3dbddebbd6a33286bc8efa 100644 (file)
@@ -75,6 +75,7 @@
 #include "SYS_System.h"
 #endif
 #include "GHOST_Path-api.h"
+#include "GHOST_C-api.h"
 
 #include "RNA_define.h"
 
 
 #include "BKE_depsgraph.h"
 #include "BKE_sound.h"
-#include "GHOST_C-api.h"
 
 static void wm_init_reports(bContext *C)
 {
@@ -120,17 +120,11 @@ int wm_start_with_console = 0;
 /* only called once, for startup */
 void WM_init(bContext *C, int argc, const char **argv)
 {
-
        if (!G.background) {
                wm_ghost_init(C);       /* note: it assigns C to ghost! */
                wm_init_cursor_data();
-#ifdef WIN32
-               if (IsConsoleEmpty()) /* never hide if the console window pre-existed */
-                       WM_console_toggle(C, wm_start_with_console);
-#endif
        }
        GHOST_CreateSystemPaths();
-
        wm_operatortype_init();
        
        set_free_windowmanager_cb(wm_close_and_free);   /* library.c */
@@ -144,7 +138,6 @@ void WM_init(bContext *C, int argc, const char **argv)
        
        BLF_init(11, U.dpi); /* Please update source/gamengine/GamePlayer/GPG_ghost.cpp if you change this */
        BLF_lang_init();
-       
        /* get the default database, plus a wm */
        WM_read_homefile(C, NULL, G.factory_startup);
 
@@ -167,6 +160,9 @@ void WM_init(bContext *C, int argc, const char **argv)
        (void)argv; /* unused */
 #endif
 
+       if (!G.background && !wm_start_with_console)
+               GHOST_toggleConsole(3);
+
        wm_init_reports(C); /* reports cant be initialized before the wm */
 
        if (!G.background) {
@@ -194,7 +190,6 @@ void WM_init(bContext *C, int argc, const char **argv)
        */
 
        BLI_strncpy(G.lib, G.main->name, FILE_MAX);
-
 }
 
 void WM_init_splash(bContext *C)
@@ -357,9 +352,6 @@ void WM_exit(bContext *C)
 
        sound_exit();
 
-#ifdef WIN32
-       WM_console_toggle(C, 1); /* never leave behind invisible consoles */
-#endif
 
        /* first wrap up running stuff, we assume only the active WM is running */
        /* modal handlers are on window level freed, others too? */
@@ -481,7 +473,6 @@ void WM_exit(bContext *C)
                getchar();
        }
 #endif 
-       
        exit(G.afbreek==1);
 }
 
index 100dd914026de5dcceb95f81e7e6972b46ee14f7..fd39755607f7722cc86edabe13a1bc147b0b04dc 100644 (file)
 #include <stddef.h>
 #include <assert.h>
 
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#include <windows.h>  
-
-#include <io.h>
-#endif
+#include "GHOST_C-api.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -2001,7 +1996,6 @@ static void WM_OT_collada_import(wmOperatorType *ot)
 #endif
 
 
-
 /* *********************** */
 
 static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
@@ -2035,28 +2029,10 @@ static void WM_OT_quit_blender(wmOperatorType *ot)
 }
 
 /* *********************** */
-#if defined(WIN32)
-static int console= 1;
-void WM_console_toggle(bContext *UNUSED(C), short show)
-{
-       if(show) {
-               ShowWindow(GetConsoleWindow(),SW_SHOW);
-               console= 1;
-       }
-       else {
-               ShowWindow(GetConsoleWindow(),SW_HIDE);
-               console= 0;
-       }
-}
 
 static int wm_console_toggle_op(bContext *C, wmOperator *UNUSED(op))
 {
-       if(console) {
-               WM_console_toggle(C, 0);
-       }
-       else {
-               WM_console_toggle(C, 1);
-       }
+       GHOST_toggleConsole(2);
        return OPERATOR_FINISHED;
 }
 
@@ -2069,7 +2045,6 @@ static void WM_OT_console_toggle(wmOperatorType *ot)
        ot->exec= wm_console_toggle_op;
        ot->poll= WM_operator_winactive;
 }
-#endif
 
 /* ************ default paint cursors, draw always around cursor *********** */
 /*