[Bf-blender-cvs] [f021d467526] master: Cleanup: GHOST_ISystem::toggleConsole API

Shrey Aggarwal noreply at git.blender.org
Wed Feb 9 01:40:55 CET 2022


Commit: f021d467526af3f3fc839c0ca48acc61dd781d56
Author: Shrey Aggarwal
Date:   Tue Feb 8 17:40:48 2022 -0700
Branches: master
https://developer.blender.org/rBf021d467526af3f3fc839c0ca48acc61dd781d56

Cleanup: GHOST_ISystem::toggleConsole API

GHOST_ISystem::toggleConsole had a somewhat misleading name
it could be fed 4 different values, so it was not as much a
toggle as a set console window state.

This change renames `toggleConsole` to a more appropriately
named `setConsoleWindowState` and replaces the integer it had
to an enum so it's easy to tell what is being asked of it at
the call site.

Reviewed By: LazyDodo
Differential Revision: https://developer.blender.org/D14020

===================================================================

M	intern/ghost/GHOST_C-api.h
M	intern/ghost/GHOST_ISystem.h
M	intern/ghost/GHOST_Types.h
M	intern/ghost/intern/GHOST_C-api.cpp
M	intern/ghost/intern/GHOST_SystemCocoa.h
M	intern/ghost/intern/GHOST_SystemNULL.h
M	intern/ghost/intern/GHOST_SystemSDL.h
M	intern/ghost/intern/GHOST_SystemWayland.cpp
M	intern/ghost/intern/GHOST_SystemWayland.h
M	intern/ghost/intern/GHOST_SystemWin32.cpp
M	intern/ghost/intern/GHOST_SystemWin32.h
M	intern/ghost/intern/GHOST_SystemX11.h
M	source/blender/windowmanager/intern/wm_init_exit.c
M	source/blender/windowmanager/intern/wm_operators.c

===================================================================

diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 98094cc0669..38adf81f877 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -889,16 +889,11 @@ extern char *GHOST_getClipboard(bool selection);
 extern void GHOST_putClipboard(const char *buffer, bool selection);
 
 /**
- * Toggles console
- * \param action:
- * - 0: Hides
- * - 1: Shows
- * - 2: Toggles
- * - 3: Hides if it runs not from  command line
- * - *: Does nothing
+ * Set the Console State
+ * \param action: console state
  * \return current status (1 -visible, 0 - hidden)
  */
-extern int GHOST_toggleConsole(int action);
+extern int setConsoleWindowState(GHOST_TConsoleWindowState action);
 
 /**
  * Use native pixel size (MacBook pro 'retina'), if supported.
diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h
index 05c6c9d907f..3edc7605d41 100644
--- a/intern/ghost/GHOST_ISystem.h
+++ b/intern/ghost/GHOST_ISystem.h
@@ -411,16 +411,11 @@ class GHOST_ISystem {
 #endif
 
   /**
-   * Toggles console
-   * \param action:
-   * - 0: Hides.
-   * - 1: Shows
-   * - 2: Toggles
-   * - 3: Hides if it runs not from  command line
-   * - *: Does nothing
+   * Set the Console State
+   * \param action: console state
    * \return current status (1 -visible, 0 - hidden)
    */
-  virtual int toggleConsole(int action) = 0;
+  virtual int setConsoleWindowState(GHOST_TConsoleWindowState action) = 0;
 
   /***************************************************************************************
    * Access to clipboard.
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index 7fe9300ec3f..4e190d09234 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -140,6 +140,13 @@ typedef enum {
   // GHOST_kWindowStateUnModified,
 } GHOST_TWindowState;
 
+typedef enum {
+  GHOST_kConsoleWindowStateHide = 0,
+  GHOST_kConsoleWindowStateShow,
+  GHOST_kConsoleWindowStateToggle,
+  GHOST_kConsoleWindowStateHideForNonConsoleLaunch
+} GHOST_TConsoleWindowState;
+
 typedef enum { GHOST_kWindowOrderTop = 0, GHOST_kWindowOrderBottom } GHOST_TWindowOrder;
 
 typedef enum {
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index a21c3a90c06..a2d1c143316 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -809,10 +809,10 @@ void GHOST_putClipboard(const char *buffer, bool selection)
   system->putClipboard(buffer, selection);
 }
 
-int GHOST_toggleConsole(int action)
+int setConsoleWindowState(GHOST_TConsoleWindowState action)
 {
   GHOST_ISystem *system = GHOST_ISystem::getSystem();
-  return system->toggleConsole(action);
+  return system->setConsoleWindowState(action);
 }
 
 int GHOST_UseNativePixels(void)
diff --git a/intern/ghost/intern/GHOST_SystemCocoa.h b/intern/ghost/intern/GHOST_SystemCocoa.h
index 5950da6813d..02216f9d1f8 100644
--- a/intern/ghost/intern/GHOST_SystemCocoa.h
+++ b/intern/ghost/intern/GHOST_SystemCocoa.h
@@ -244,7 +244,7 @@ class GHOST_SystemCocoa : public GHOST_System {
   /**
    * \see GHOST_ISystem
    */
-  int toggleConsole(int action)
+  int setConsoleWindowState(GHOST_TConsoleWindowState action)
   {
     return 0;
   }
diff --git a/intern/ghost/intern/GHOST_SystemNULL.h b/intern/ghost/intern/GHOST_SystemNULL.h
index 5dbc42b53a2..53cd97e8e57 100644
--- a/intern/ghost/intern/GHOST_SystemNULL.h
+++ b/intern/ghost/intern/GHOST_SystemNULL.h
@@ -40,7 +40,7 @@ class GHOST_SystemNULL : public GHOST_System {
   {
     return false;
   }
-  int toggleConsole(int action)
+  int setConsoleWindowState(GHOST_TConsoleWindowState action)
   {
     return 0;
   }
diff --git a/intern/ghost/intern/GHOST_SystemSDL.h b/intern/ghost/intern/GHOST_SystemSDL.h
index 051bb6777b1..8706dd0daa7 100644
--- a/intern/ghost/intern/GHOST_SystemSDL.h
+++ b/intern/ghost/intern/GHOST_SystemSDL.h
@@ -47,7 +47,7 @@ class GHOST_SystemSDL : public GHOST_System {
 
   bool processEvents(bool waitForEvent);
 
-  int toggleConsole(int action)
+  int setConsoleWindowState(GHOST_TConsoleWindowState action)
   {
     return 0;
   }
diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp
index 38700845405..27b37d0d326 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.cpp
+++ b/intern/ghost/intern/GHOST_SystemWayland.cpp
@@ -1473,7 +1473,7 @@ bool GHOST_SystemWayland::processEvents(bool waitForEvent)
   return fired || (getEventManager()->getNumEvents() > 0);
 }
 
-int GHOST_SystemWayland::toggleConsole(int /*action*/)
+int GHOST_SystemWayland::setConsoleWindowState(GHOST_TConsoleWindowState /*action*/)
 {
   return 0;
 }
diff --git a/intern/ghost/intern/GHOST_SystemWayland.h b/intern/ghost/intern/GHOST_SystemWayland.h
index 9f02afb9d5a..b11c243aca8 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.h
+++ b/intern/ghost/intern/GHOST_SystemWayland.h
@@ -53,7 +53,7 @@ class GHOST_SystemWayland : public GHOST_System {
 
   bool processEvents(bool waitForEvent) override;
 
-  int toggleConsole(int action) override;
+  int setConsoleWindowState(GHOST_TConsoleWindowState action) override;
 
   GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys &keys) const override;
 
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index 923453d6c6f..2f5395fc8d0 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -170,7 +170,7 @@ GHOST_SystemWin32::~GHOST_SystemWin32()
   OleUninitialize();
 
   if (isStartedFromCommandPrompt()) {
-    toggleConsole(1);
+    setConsoleWindowState(GHOST_kConsoleWindowStateShow);
   }
 }
 
@@ -2221,31 +2221,30 @@ static bool isStartedFromCommandPrompt()
   return false;
 }
 
-int GHOST_SystemWin32::toggleConsole(int action)
+int GHOST_SystemWin32::setConsoleWindowState(GHOST_TConsoleWindowState action)
 {
   HWND wnd = GetConsoleWindow();
 
   switch (action) {
-    case 3:  // startup: hide if not started from command prompt
-    {
+    case GHOST_kConsoleWindowStateHideForNonConsoleLaunch: {
       if (!isStartedFromCommandPrompt()) {
         ShowWindow(wnd, SW_HIDE);
         m_consoleStatus = 0;
       }
       break;
     }
-    case 0:  // hide
+    case GHOST_kConsoleWindowStateHide:
       ShowWindow(wnd, SW_HIDE);
       m_consoleStatus = 0;
       break;
-    case 1:  // show
+    case GHOST_kConsoleWindowStateShow:
       ShowWindow(wnd, SW_SHOW);
       if (!isStartedFromCommandPrompt()) {
         DeleteMenu(GetSystemMenu(wnd, FALSE), SC_CLOSE, MF_BYCOMMAND);
       }
       m_consoleStatus = 1;
       break;
-    case 2:  // toggle
+    case GHOST_kConsoleWindowStateToggle:
       ShowWindow(wnd, m_consoleStatus ? SW_HIDE : SW_SHOW);
       m_consoleStatus = !m_consoleStatus;
       if (m_consoleStatus && !isStartedFromCommandPrompt()) {
diff --git a/intern/ghost/intern/GHOST_SystemWin32.h b/intern/ghost/intern/GHOST_SystemWin32.h
index 4794982dc65..4f0fd6e6801 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.h
+++ b/intern/ghost/intern/GHOST_SystemWin32.h
@@ -436,16 +436,11 @@ class GHOST_SystemWin32 : public GHOST_System {
   static LRESULT WINAPI s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
 
   /**
-   * Toggles console
-   * \param action:
-   * - 0 - Hides
-   * - 1 - Shows
-   * - 2 - Toggles
-   * - 3 - Hides if it runs not from  command line
-   * - * - Does nothing
+   * Set the Console State
+   * \param action: console state
    * \return current status (1 -visible, 0 - hidden)
    */
-  int toggleConsole(int action);
+  int setConsoleWindowState(GHOST_TConsoleWindowState action);
 
   /** The current state of the modifier keys. */
   GHOST_ModifierKeys m_modifierKeys;
diff --git a/intern/ghost/intern/GHOST_SystemX11.h b/intern/ghost/intern/GHOST_SystemX11.h
index d4803f88fbb..76011d3522b 100644
--- a/intern/ghost/intern/GHOST_SystemX11.h
+++ b/intern/ghost/intern/GHOST_SystemX11.h
@@ -269,7 +269,7 @@ class GHOST_SystemX11 : public GHOST_System {
   /**
    * \see GHOST_ISystem
    */
-  int toggleConsole(int /*action*/)
+  int setConsoleWindowState(GHOST_TConsoleWindowState /*action*/)
   {
     return 0;
   }
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index 1d26c58bcf9..cff4287a2d0 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -356,10 +356,10 @@ void WM_init(bContext *C, int argc, const char **argv)
 
   if (!G.background) {
     if (wm_start_with_console) {
-      GHOST_toggleConsole(1);
+      setConsoleWindowState(GHOST_kConsoleWindowStateShow);
     }
     else {
-      GHOST_toggleConsole(3);
+      setConsoleWindowState(GHOST_kConsoleWindowStateHideForNonConsoleLaunch);
     }
   }
 
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 6c9b0af5186..2c82d8f5b6b 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -2046,7 +2046,7 @@ static void WM_OT_quit_blender(wmOperatorType *ot)
 
 static int wm_console_toggle_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
 {
-  GHOST_toggleConsole(2);
+  setConsoleWindowState(GHOST_kConsoleWindowStateToggle);
   return OPERATOR_FINISHED;
 }



More information about the Bf-blender-cvs mailing list