From a5c646c86fb6ac89e2f0e5ac67decb5b42bedc68 Mon Sep 17 00:00:00 2001 From: Javier De la Garza Sanchez Date: Fri, 16 Aug 2019 10:23:11 -0700 Subject: [PATCH 1/3] Added theming support --- .../PublicTerminalCore/HwndTerminal.cpp | 20 ++++++ .../PublicTerminalCore/HwndTerminal.hpp | 62 +++++++++++-------- .../WpfTerminalControl/NativeMethods.cs | 3 + .../WpfTerminalControl/TerminalContainer.cs | 8 +++ .../TerminalControl.xaml.cs | 25 ++++---- .../WpfTerminalControl/TerminalSettings.cs | 34 ---------- .../WpfTerminalControl/TerminalTheme.cs | 28 +++++++++ .../WpfTerminalControl.csproj | 2 +- 8 files changed, 110 insertions(+), 72 deletions(-) delete mode 100644 src/cascadia/WpfTerminalControl/TerminalSettings.cs create mode 100644 src/cascadia/WpfTerminalControl/TerminalTheme.cs diff --git a/src/cascadia/PublicTerminalCore/HwndTerminal.cpp b/src/cascadia/PublicTerminalCore/HwndTerminal.cpp index b815457d4fb..1d670504aa9 100644 --- a/src/cascadia/PublicTerminalCore/HwndTerminal.cpp +++ b/src/cascadia/PublicTerminalCore/HwndTerminal.cpp @@ -353,3 +353,23 @@ void _stdcall DestroyTerminal(void* terminal) auto publicTerminal = reinterpret_cast(terminal); delete publicTerminal; } + +// Updates the terminal font type, size, color, as well as the background/foreground colors to a specified theme. +void _stdcall SetTheme(void* terminal, LPTerminalTheme theme, LPCWSTR fontFamily, short fontSize, int newDpi) +{ + auto publicTerminal = (HwndTerminal*)terminal; + + auto lock = publicTerminal->_terminal->LockForWriting(); + + publicTerminal->_terminal->SetDefaultForeground(theme->DefaultForeground); + publicTerminal->_terminal->SetDefaultBackground(theme->DefaultBackground); + + // Set the font colors + for (size_t tableIndex = 0; tableIndex < 16; tableIndex++) + { + publicTerminal->_terminal->SetColorTableEntry(tableIndex, theme->ColorTable[tableIndex]); + } + + publicTerminal->_desiredFont = { fontFamily, 0, 10, { 0, fontSize }, CP_UTF8 }; + publicTerminal->_UpdateFont(newDpi); +} diff --git a/src/cascadia/PublicTerminalCore/HwndTerminal.hpp b/src/cascadia/PublicTerminalCore/HwndTerminal.hpp index 6fd7d49bc81..31cfbe1f54e 100644 --- a/src/cascadia/PublicTerminalCore/HwndTerminal.hpp +++ b/src/cascadia/PublicTerminalCore/HwndTerminal.hpp @@ -4,34 +4,43 @@ #include "../../renderer/dx/DxRenderer.hpp" #include "../../cascadia/TerminalCore/Terminal.hpp" -extern "C" { - __declspec(dllexport) HRESULT _stdcall CreateTerminal(HWND parentHwnd, _Out_ void** hwnd, _Out_ void** terminal); - __declspec(dllexport) void _stdcall SendTerminalOutput(void* terminal, LPCWSTR data); - __declspec(dllexport) void _stdcall RegisterScrollCallback(void* terminal, void __stdcall callback(int, int, int)); - __declspec(dllexport) HRESULT _stdcall TriggerResize(void* terminal, double width, double height, _Out_ int* charColumns, _Out_ int* charRows); - __declspec(dllexport) void _stdcall DpiChanged(void* terminal, int newDpi); - __declspec(dllexport) void _stdcall UserScroll(void* terminal, int viewTop); - __declspec(dllexport) HRESULT _stdcall StartSelection(void* terminal, COORD cursorPosition, bool altPressed); - __declspec(dllexport) HRESULT _stdcall MoveSelection(void* terminal, COORD cursorPosition); - __declspec(dllexport) void _stdcall ClearSelection(void* terminal); - __declspec(dllexport) const wchar_t* _stdcall GetSelection(void* terminal); - __declspec(dllexport) bool _stdcall IsSelectionActive(void* terminal); - __declspec(dllexport) void _stdcall DestroyTerminal(void* terminal); - __declspec(dllexport) void _stdcall RegisterWriteCallback(void* terminal, void __stdcall callback(wchar_t*)); - __declspec(dllexport) void _stdcall SendKeyEvent(void* terminal, WPARAM wParam); - __declspec(dllexport) void _stdcall SendCharEvent(void* terminal, char16_t ch); +enum class CursorStyle : int32_t +{ + Vintage = 0, + Bar = 1, + Underscore = 2, + FilledBox = 3, + EmptyBox = 4, +}; + +typedef struct _TerminalTheme +{ + COLORREF DefaultBackground; + COLORREF DefaultForeground; + CursorStyle CursorStyle; + COLORREF ColorTable[16]; +} TerminalTheme, *LPTerminalTheme; - enum CursorStyle - { +extern "C" +{ + __declspec(dllexport) HRESULT _stdcall CreateTerminal(HWND parentHwnd, _Out_ void** hwnd, _Out_ void** terminal); + __declspec(dllexport) void _stdcall SendTerminalOutput(void* terminal, LPCWSTR data); + __declspec(dllexport) void _stdcall RegisterScrollCallback(void* terminal, void __stdcall callback(int, int, int)); + __declspec(dllexport) HRESULT _stdcall TriggerResize(void* terminal, double width, double height, _Out_ int* charColumns, _Out_ int* charRows); + __declspec(dllexport) void _stdcall DpiChanged(void* terminal, int newDpi); + __declspec(dllexport) void _stdcall UserScroll(void* terminal, int viewTop); + __declspec(dllexport) HRESULT _stdcall StartSelection(void* terminal, COORD cursorPosition, bool altPressed); + __declspec(dllexport) HRESULT _stdcall MoveSelection(void* terminal, COORD cursorPosition); + __declspec(dllexport) void _stdcall ClearSelection(void* terminal); + __declspec(dllexport) const wchar_t* _stdcall GetSelection(void* terminal); + __declspec(dllexport) bool _stdcall IsSelectionActive(void* terminal); + __declspec(dllexport) void _stdcall DestroyTerminal(void* terminal); + __declspec(dllexport) void _stdcall SetTheme(void* terminal, LPTerminalTheme theme, LPCWSTR fontFamily, short fontSize, int newDpi); + __declspec(dllexport) void _stdcall RegisterWriteCallback(void* terminal, void __stdcall callback(wchar_t*)); + __declspec(dllexport) void _stdcall SendKeyEvent(void* terminal, WPARAM wParam); + __declspec(dllexport) void _stdcall SendCharEvent(void* terminal, char16_t ch); - }; - struct TerminalSettings - { - COLORREF DefaultBackground; - COLORREF DefaultForeground; - CursorStyle CursorShape; - }; - } +}; struct HwndTerminal { public: @@ -62,5 +71,6 @@ struct HwndTerminal { friend bool _stdcall IsSelectionActive(void* terminal); friend void _stdcall SendKeyEvent(void* terminal, WPARAM wParam); friend void _stdcall SendCharEvent(void* terminal, char16_t ch); + friend void _stdcall SetTheme(void* terminal, LPTerminalTheme theme, LPCWSTR fontFamily, short fontSize, int newDpi); void _UpdateFont(int newDpi); }; diff --git a/src/cascadia/WpfTerminalControl/NativeMethods.cs b/src/cascadia/WpfTerminalControl/NativeMethods.cs index aa37ade692b..0da7f03dd6d 100644 --- a/src/cascadia/WpfTerminalControl/NativeMethods.cs +++ b/src/cascadia/WpfTerminalControl/NativeMethods.cs @@ -56,6 +56,9 @@ internal static class NativeMethods [DllImport("PublicTerminalCore.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)] public static extern void SendCharEvent(IntPtr terminal, char ch); + [DllImport("PublicTerminalCore.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)] + public static extern void SetTheme(IntPtr terminal, [MarshalAs(UnmanagedType.LPStruct)] TerminalTheme theme, string fontFamily, short fontSize, int newDpi); + [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr SetFocus(IntPtr hWnd); diff --git a/src/cascadia/WpfTerminalControl/TerminalContainer.cs b/src/cascadia/WpfTerminalControl/TerminalContainer.cs index 9d47757a7e3..ff2c7083ceb 100644 --- a/src/cascadia/WpfTerminalControl/TerminalContainer.cs +++ b/src/cascadia/WpfTerminalControl/TerminalContainer.cs @@ -174,6 +174,14 @@ private get } } + /// + /// Sets the theme for the terminal. This includes font family, size, color, as well as background and foreground colors. + /// + public void SetTheme(TerminalTheme theme, string fontFamily, short fontSize, int newDpi) + { + NativeMethods.SetTheme(this.terminal, theme, fontFamily, fontSize, newDpi); + } + private void Connection_TerminalDisconnected(object sender, EventArgs e) { // TODO diff --git a/src/cascadia/WpfTerminalControl/TerminalControl.xaml.cs b/src/cascadia/WpfTerminalControl/TerminalControl.xaml.cs index d8474e072b1..33534718e1e 100644 --- a/src/cascadia/WpfTerminalControl/TerminalControl.xaml.cs +++ b/src/cascadia/WpfTerminalControl/TerminalControl.xaml.cs @@ -1,17 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; +using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; namespace Microsoft.Terminal.Wpf { @@ -61,6 +51,19 @@ public ITerminalConnection Connection } } + /// + /// Sets the theme for the terminal. This includes font family, size, color, as well as background and foreground colors. + /// + public void SetTheme(TerminalTheme theme, string fontFamily, short fontSize) + { + PresentationSource source = PresentationSource.FromVisual(this); + + int dpiX; + dpiX = (int)(96.0 * source.CompositionTarget.TransformToDevice.M11); + + this.termContainer.SetTheme(theme, fontFamily, fontSize, dpiX); + } + private void TermControl_TerminalScrolled(object sender, (int viewTop, int viewHeight, int bufferSize) e) { Dispatcher.InvokeAsync(() => diff --git a/src/cascadia/WpfTerminalControl/TerminalSettings.cs b/src/cascadia/WpfTerminalControl/TerminalSettings.cs deleted file mode 100644 index d1bec04292f..00000000000 --- a/src/cascadia/WpfTerminalControl/TerminalSettings.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Documents; -using System.Windows.Media; - -namespace Microsoft.Terminal.Wpf -{ - public class TerminalSettings - { - public Color DefaultForeground { get; set; } - - public Color DefaultBackground { get; set; } - - public CursorStyle CursorShape { get; set; } - - public uint CursorHeight { get; set; } - - public Color CursorColor { get; set; } - - public List ColorTable { get; set; } - } - - public enum CursorStyle - { - Vintage = 0, - Bar = 1, - Underscore = 2, - FilledBox = 3, - EmptyBox = 4, - } -} diff --git a/src/cascadia/WpfTerminalControl/TerminalTheme.cs b/src/cascadia/WpfTerminalControl/TerminalTheme.cs new file mode 100644 index 00000000000..5f72abb3238 --- /dev/null +++ b/src/cascadia/WpfTerminalControl/TerminalTheme.cs @@ -0,0 +1,28 @@ +using System; +using System.Runtime.InteropServices; + +namespace Microsoft.Terminal.Wpf +{ + /// + /// Structure for color handling in the terminal. + /// + /// Pack = 1 removes the padding added by some compilers/processors for optimization purposes. + [StructLayout(LayoutKind.Sequential)] + public class TerminalTheme + { + public uint DefaultBackground; + public uint DefaultForeground; + public CursorStyle CursorStyle; + [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U8, SizeConst = 16)] + public uint[] ColorTable; + } + + public enum CursorStyle + { + Vintage = 0, + Bar = 1, + Underscore = 2, + FilledBox = 3, + EmptyBox = 4, + } +} diff --git a/src/cascadia/WpfTerminalControl/WpfTerminalControl.csproj b/src/cascadia/WpfTerminalControl/WpfTerminalControl.csproj index 96671b34d02..736494029dd 100644 --- a/src/cascadia/WpfTerminalControl/WpfTerminalControl.csproj +++ b/src/cascadia/WpfTerminalControl/WpfTerminalControl.csproj @@ -69,7 +69,7 @@ - + TerminalControl.xaml From a6d44ae408c27e21281b60a6073e7a9ffd0268f3 Mon Sep 17 00:00:00 2001 From: Javier De la Garza Sanchez Date: Fri, 16 Aug 2019 14:28:21 -0700 Subject: [PATCH 2/3] Fixed locking issues and other nits --- .../PublicTerminalCore/HwndTerminal.cpp | 19 ++++++++++--------- .../TerminalControl.xaml.cs | 5 +++++ .../WpfTerminalControl/TerminalTheme.cs | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/cascadia/PublicTerminalCore/HwndTerminal.cpp b/src/cascadia/PublicTerminalCore/HwndTerminal.cpp index 1d670504aa9..5f9bca43c57 100644 --- a/src/cascadia/PublicTerminalCore/HwndTerminal.cpp +++ b/src/cascadia/PublicTerminalCore/HwndTerminal.cpp @@ -357,17 +357,18 @@ void _stdcall DestroyTerminal(void* terminal) // Updates the terminal font type, size, color, as well as the background/foreground colors to a specified theme. void _stdcall SetTheme(void* terminal, LPTerminalTheme theme, LPCWSTR fontFamily, short fontSize, int newDpi) { - auto publicTerminal = (HwndTerminal*)terminal; - - auto lock = publicTerminal->_terminal->LockForWriting(); + auto publicTerminal = reinterpret_cast(terminal); + { + auto lock = publicTerminal->_terminal->LockForWriting(); - publicTerminal->_terminal->SetDefaultForeground(theme->DefaultForeground); - publicTerminal->_terminal->SetDefaultBackground(theme->DefaultBackground); + publicTerminal->_terminal->SetDefaultForeground(theme->DefaultForeground); + publicTerminal->_terminal->SetDefaultBackground(theme->DefaultBackground); - // Set the font colors - for (size_t tableIndex = 0; tableIndex < 16; tableIndex++) - { - publicTerminal->_terminal->SetColorTableEntry(tableIndex, theme->ColorTable[tableIndex]); + // Set the font colors + for (size_t tableIndex = 0; tableIndex < 16; tableIndex++) + { + publicTerminal->_terminal->SetColorTableEntry(tableIndex, theme->ColorTable[tableIndex]); + } } publicTerminal->_desiredFont = { fontFamily, 0, 10, { 0, fontSize }, CP_UTF8 }; diff --git a/src/cascadia/WpfTerminalControl/TerminalControl.xaml.cs b/src/cascadia/WpfTerminalControl/TerminalControl.xaml.cs index 33534718e1e..4aa216a27b4 100644 --- a/src/cascadia/WpfTerminalControl/TerminalControl.xaml.cs +++ b/src/cascadia/WpfTerminalControl/TerminalControl.xaml.cs @@ -58,6 +58,11 @@ public void SetTheme(TerminalTheme theme, string fontFamily, short fontSize) { PresentationSource source = PresentationSource.FromVisual(this); + if (source == null) + { + return; + } + int dpiX; dpiX = (int)(96.0 * source.CompositionTarget.TransformToDevice.M11); diff --git a/src/cascadia/WpfTerminalControl/TerminalTheme.cs b/src/cascadia/WpfTerminalControl/TerminalTheme.cs index 5f72abb3238..47d1e6b438b 100644 --- a/src/cascadia/WpfTerminalControl/TerminalTheme.cs +++ b/src/cascadia/WpfTerminalControl/TerminalTheme.cs @@ -13,7 +13,7 @@ public class TerminalTheme public uint DefaultBackground; public uint DefaultForeground; public CursorStyle CursorStyle; - [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U8, SizeConst = 16)] + [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U4, SizeConst = 16)] public uint[] ColorTable; } From 3d4ada9b2dd4e35dab9574313a63e27ec8c29caa Mon Sep 17 00:00:00 2001 From: Javier De la Garza Sanchez Date: Fri, 16 Aug 2019 14:46:48 -0700 Subject: [PATCH 3/3] Fixed PR comments and switched to struct instead of class pointer for theme --- OpenConsole.sln | 21 +++++++++++++++++++ .../PublicTerminalCore/HwndTerminal.cpp | 10 +++++---- .../PublicTerminalCore/HwndTerminal.hpp | 15 ++++--------- .../WpfTerminalControl/NativeMethods.cs | 2 +- .../WpfTerminalControl/TerminalTheme.cs | 19 ++++++++++------- 5 files changed, 43 insertions(+), 24 deletions(-) diff --git a/OpenConsole.sln b/OpenConsole.sln index 1b6c882ddf1..0ebee4316ef 100644 --- a/OpenConsole.sln +++ b/OpenConsole.sln @@ -508,6 +508,7 @@ Global {531C23E7-4B76-4C08-8AAD-04164CB628C9}.AuditMode|ARM64.ActiveCfg = Release|ARM64 {531C23E7-4B76-4C08-8AAD-04164CB628C9}.AuditMode|x64.ActiveCfg = Release|x64 {531C23E7-4B76-4C08-8AAD-04164CB628C9}.AuditMode|x86.ActiveCfg = Release|Win32 + {531C23E7-4B76-4C08-8AAD-04164CB628C9}.Debug|Any CPU.ActiveCfg = Debug|Win32 {531C23E7-4B76-4C08-8AAD-04164CB628C9}.Debug|ARM64.ActiveCfg = Debug|ARM64 {531C23E7-4B76-4C08-8AAD-04164CB628C9}.Debug|ARM64.Build.0 = Debug|ARM64 {531C23E7-4B76-4C08-8AAD-04164CB628C9}.Debug|x64.ActiveCfg = Debug|x64 @@ -525,6 +526,7 @@ Global {531C23E7-4B76-4C08-8BBD-04164CB628C9}.AuditMode|ARM64.ActiveCfg = Release|ARM64 {531C23E7-4B76-4C08-8BBD-04164CB628C9}.AuditMode|x64.ActiveCfg = Release|x64 {531C23E7-4B76-4C08-8BBD-04164CB628C9}.AuditMode|x86.ActiveCfg = Release|Win32 + {531C23E7-4B76-4C08-8BBD-04164CB628C9}.Debug|Any CPU.ActiveCfg = Debug|Win32 {531C23E7-4B76-4C08-8BBD-04164CB628C9}.Debug|ARM64.ActiveCfg = Debug|ARM64 {531C23E7-4B76-4C08-8BBD-04164CB628C9}.Debug|ARM64.Build.0 = Debug|ARM64 {531C23E7-4B76-4C08-8BBD-04164CB628C9}.Debug|x64.ActiveCfg = Debug|x64 @@ -542,6 +544,7 @@ Global {8CDB8850-7484-4EC7-B45B-181F85B2EE54}.AuditMode|ARM64.ActiveCfg = Release|ARM64 {8CDB8850-7484-4EC7-B45B-181F85B2EE54}.AuditMode|x64.ActiveCfg = Release|x64 {8CDB8850-7484-4EC7-B45B-181F85B2EE54}.AuditMode|x86.ActiveCfg = Release|Win32 + {8CDB8850-7484-4EC7-B45B-181F85B2EE54}.Debug|Any CPU.ActiveCfg = Debug|Win32 {8CDB8850-7484-4EC7-B45B-181F85B2EE54}.Debug|ARM64.ActiveCfg = Debug|ARM64 {8CDB8850-7484-4EC7-B45B-181F85B2EE54}.Debug|ARM64.Build.0 = Debug|ARM64 {8CDB8850-7484-4EC7-B45B-181F85B2EE54}.Debug|x64.ActiveCfg = Debug|x64 @@ -557,6 +560,7 @@ Global {12144E07-FE63-4D33-9231-748B8D8C3792}.AuditMode|ARM64.ActiveCfg = Release|ARM64 {12144E07-FE63-4D33-9231-748B8D8C3792}.AuditMode|x64.ActiveCfg = Release|x64 {12144E07-FE63-4D33-9231-748B8D8C3792}.AuditMode|x86.ActiveCfg = Release|Win32 + {12144E07-FE63-4D33-9231-748B8D8C3792}.Debug|Any CPU.ActiveCfg = Debug|Win32 {12144E07-FE63-4D33-9231-748B8D8C3792}.Debug|ARM64.ActiveCfg = Debug|ARM64 {12144E07-FE63-4D33-9231-748B8D8C3792}.Debug|ARM64.Build.0 = Debug|ARM64 {12144E07-FE63-4D33-9231-748B8D8C3792}.Debug|x64.ActiveCfg = Debug|x64 @@ -574,6 +578,7 @@ Global {6AF01638-84CF-4B65-9870-484DFFCAC772}.AuditMode|ARM64.ActiveCfg = Release|ARM64 {6AF01638-84CF-4B65-9870-484DFFCAC772}.AuditMode|x64.ActiveCfg = Release|x64 {6AF01638-84CF-4B65-9870-484DFFCAC772}.AuditMode|x86.ActiveCfg = Release|Win32 + {6AF01638-84CF-4B65-9870-484DFFCAC772}.Debug|Any CPU.ActiveCfg = Debug|Win32 {6AF01638-84CF-4B65-9870-484DFFCAC772}.Debug|ARM64.ActiveCfg = Debug|ARM64 {6AF01638-84CF-4B65-9870-484DFFCAC772}.Debug|ARM64.Build.0 = Debug|ARM64 {6AF01638-84CF-4B65-9870-484DFFCAC772}.Debug|x64.ActiveCfg = Debug|x64 @@ -591,6 +596,7 @@ Global {96927B31-D6E8-4ABD-B03E-A5088A30BEBE}.AuditMode|ARM64.ActiveCfg = Release|ARM64 {96927B31-D6E8-4ABD-B03E-A5088A30BEBE}.AuditMode|x64.ActiveCfg = Release|x64 {96927B31-D6E8-4ABD-B03E-A5088A30BEBE}.AuditMode|x86.ActiveCfg = Release|Win32 + {96927B31-D6E8-4ABD-B03E-A5088A30BEBE}.Debug|Any CPU.ActiveCfg = Debug|Win32 {96927B31-D6E8-4ABD-B03E-A5088A30BEBE}.Debug|ARM64.ActiveCfg = Debug|ARM64 {96927B31-D6E8-4ABD-B03E-A5088A30BEBE}.Debug|ARM64.Build.0 = Debug|ARM64 {96927B31-D6E8-4ABD-B03E-A5088A30BEBE}.Debug|x64.ActiveCfg = Debug|x64 @@ -608,6 +614,7 @@ Global {F210A4AE-E02A-4BFC-80BB-F50A672FE763}.AuditMode|ARM64.ActiveCfg = Release|ARM64 {F210A4AE-E02A-4BFC-80BB-F50A672FE763}.AuditMode|x64.ActiveCfg = Release|x64 {F210A4AE-E02A-4BFC-80BB-F50A672FE763}.AuditMode|x86.ActiveCfg = Release|Win32 + {F210A4AE-E02A-4BFC-80BB-F50A672FE763}.Debug|Any CPU.ActiveCfg = Debug|Win32 {F210A4AE-E02A-4BFC-80BB-F50A672FE763}.Debug|ARM64.ActiveCfg = Debug|ARM64 {F210A4AE-E02A-4BFC-80BB-F50A672FE763}.Debug|ARM64.Build.0 = Debug|ARM64 {F210A4AE-E02A-4BFC-80BB-F50A672FE763}.Debug|x64.ActiveCfg = Debug|x64 @@ -668,6 +675,7 @@ Global {C17E1BF3-9D34-4779-9458-A8EF98CC5662}.AuditMode|ARM64.ActiveCfg = Debug|Win32 {C17E1BF3-9D34-4779-9458-A8EF98CC5662}.AuditMode|x64.ActiveCfg = Release|x64 {C17E1BF3-9D34-4779-9458-A8EF98CC5662}.AuditMode|x86.ActiveCfg = Release|Win32 + {C17E1BF3-9D34-4779-9458-A8EF98CC5662}.Debug|Any CPU.ActiveCfg = Debug|Win32 {C17E1BF3-9D34-4779-9458-A8EF98CC5662}.Debug|ARM64.ActiveCfg = Debug|Win32 {C17E1BF3-9D34-4779-9458-A8EF98CC5662}.Debug|x64.ActiveCfg = Debug|x64 {C17E1BF3-9D34-4779-9458-A8EF98CC5662}.Debug|x64.Build.0 = Debug|x64 @@ -684,6 +692,7 @@ Global {099193A0-1E43-4BBC-BA7F-7B351E1342DF}.AuditMode|ARM64.ActiveCfg = Debug|Win32 {099193A0-1E43-4BBC-BA7F-7B351E1342DF}.AuditMode|x64.ActiveCfg = Release|x64 {099193A0-1E43-4BBC-BA7F-7B351E1342DF}.AuditMode|x86.ActiveCfg = Release|Win32 + {099193A0-1E43-4BBC-BA7F-7B351E1342DF}.Debug|Any CPU.ActiveCfg = Debug|Win32 {099193A0-1E43-4BBC-BA7F-7B351E1342DF}.Debug|ARM64.ActiveCfg = Debug|Win32 {099193A0-1E43-4BBC-BA7F-7B351E1342DF}.Debug|x64.ActiveCfg = Debug|x64 {099193A0-1E43-4BBC-BA7F-7B351E1342DF}.Debug|x64.Build.0 = Debug|x64 @@ -699,6 +708,7 @@ Global {FC802440-AD6A-4919-8F2C-7701F2B38D79}.AuditMode|ARM64.ActiveCfg = Release|ARM64 {FC802440-AD6A-4919-8F2C-7701F2B38D79}.AuditMode|x64.ActiveCfg = Release|x64 {FC802440-AD6A-4919-8F2C-7701F2B38D79}.AuditMode|x86.ActiveCfg = Release|Win32 + {FC802440-AD6A-4919-8F2C-7701F2B38D79}.Debug|Any CPU.ActiveCfg = Debug|Win32 {FC802440-AD6A-4919-8F2C-7701F2B38D79}.Debug|ARM64.ActiveCfg = Debug|ARM64 {FC802440-AD6A-4919-8F2C-7701F2B38D79}.Debug|ARM64.Build.0 = Debug|ARM64 {FC802440-AD6A-4919-8F2C-7701F2B38D79}.Debug|x64.ActiveCfg = Debug|x64 @@ -716,6 +726,7 @@ Global {919544AC-D39B-463F-8414-3C3C67CF727C}.AuditMode|ARM64.ActiveCfg = Release|ARM64 {919544AC-D39B-463F-8414-3C3C67CF727C}.AuditMode|x64.ActiveCfg = Release|x64 {919544AC-D39B-463F-8414-3C3C67CF727C}.AuditMode|x86.ActiveCfg = Release|Win32 + {919544AC-D39B-463F-8414-3C3C67CF727C}.Debug|Any CPU.ActiveCfg = Debug|Win32 {919544AC-D39B-463F-8414-3C3C67CF727C}.Debug|ARM64.ActiveCfg = Debug|ARM64 {919544AC-D39B-463F-8414-3C3C67CF727C}.Debug|ARM64.Build.0 = Debug|ARM64 {919544AC-D39B-463F-8414-3C3C67CF727C}.Debug|x64.ActiveCfg = Debug|x64 @@ -733,6 +744,7 @@ Global {ED82003F-FC5D-4E94-8B36-F480018ED064}.AuditMode|ARM64.ActiveCfg = Release|ARM64 {ED82003F-FC5D-4E94-8B36-F480018ED064}.AuditMode|x64.ActiveCfg = Release|x64 {ED82003F-FC5D-4E94-8B36-F480018ED064}.AuditMode|x86.ActiveCfg = Release|Win32 + {ED82003F-FC5D-4E94-8B36-F480018ED064}.Debug|Any CPU.ActiveCfg = Debug|Win32 {ED82003F-FC5D-4E94-8B36-F480018ED064}.Debug|ARM64.ActiveCfg = Debug|ARM64 {ED82003F-FC5D-4E94-8B36-F480018ED064}.Debug|ARM64.Build.0 = Debug|ARM64 {ED82003F-FC5D-4E94-8B36-F480018ED064}.Debug|x64.ActiveCfg = Debug|x64 @@ -771,6 +783,7 @@ Global {ED82003F-FC5D-4E94-8B47-F480018ED064}.AuditMode|ARM64.ActiveCfg = Release|ARM64 {ED82003F-FC5D-4E94-8B47-F480018ED064}.AuditMode|x64.ActiveCfg = Release|x64 {ED82003F-FC5D-4E94-8B47-F480018ED064}.AuditMode|x86.ActiveCfg = Release|Win32 + {ED82003F-FC5D-4E94-8B47-F480018ED064}.Debug|Any CPU.ActiveCfg = Debug|Win32 {ED82003F-FC5D-4E94-8B47-F480018ED064}.Debug|ARM64.ActiveCfg = Debug|ARM64 {ED82003F-FC5D-4E94-8B47-F480018ED064}.Debug|ARM64.Build.0 = Debug|ARM64 {ED82003F-FC5D-4E94-8B47-F480018ED064}.Debug|x64.ActiveCfg = Debug|x64 @@ -809,6 +822,7 @@ Global {D3B92829-26CB-411A-BDA2-7F5DA3D25DD4}.AuditMode|ARM64.ActiveCfg = Release|ARM64 {D3B92829-26CB-411A-BDA2-7F5DA3D25DD4}.AuditMode|x64.ActiveCfg = Release|x64 {D3B92829-26CB-411A-BDA2-7F5DA3D25DD4}.AuditMode|x86.ActiveCfg = Release|Win32 + {D3B92829-26CB-411A-BDA2-7F5DA3D25DD4}.Debug|Any CPU.ActiveCfg = Debug|Win32 {D3B92829-26CB-411A-BDA2-7F5DA3D25DD4}.Debug|ARM64.ActiveCfg = Debug|ARM64 {D3B92829-26CB-411A-BDA2-7F5DA3D25DD4}.Debug|ARM64.Build.0 = Debug|ARM64 {D3B92829-26CB-411A-BDA2-7F5DA3D25DD4}.Debug|x64.ActiveCfg = Debug|x64 @@ -826,6 +840,7 @@ Global {C7A6A5D9-60BE-4AEB-A5F6-AFE352F86CBB}.AuditMode|ARM64.ActiveCfg = Release|ARM64 {C7A6A5D9-60BE-4AEB-A5F6-AFE352F86CBB}.AuditMode|x64.ActiveCfg = Release|x64 {C7A6A5D9-60BE-4AEB-A5F6-AFE352F86CBB}.AuditMode|x86.ActiveCfg = Release|Win32 + {C7A6A5D9-60BE-4AEB-A5F6-AFE352F86CBB}.Debug|Any CPU.ActiveCfg = Debug|Win32 {C7A6A5D9-60BE-4AEB-A5F6-AFE352F86CBB}.Debug|ARM64.ActiveCfg = Debug|ARM64 {C7A6A5D9-60BE-4AEB-A5F6-AFE352F86CBB}.Debug|ARM64.Build.0 = Debug|ARM64 {C7A6A5D9-60BE-4AEB-A5F6-AFE352F86CBB}.Debug|x64.ActiveCfg = Debug|x64 @@ -864,6 +879,7 @@ Global {814DBDDE-894E-4327-A6E1-740504850098}.AuditMode|ARM64.ActiveCfg = Release|ARM64 {814DBDDE-894E-4327-A6E1-740504850098}.AuditMode|x64.ActiveCfg = Release|x64 {814DBDDE-894E-4327-A6E1-740504850098}.AuditMode|x86.ActiveCfg = Release|Win32 + {814DBDDE-894E-4327-A6E1-740504850098}.Debug|Any CPU.ActiveCfg = Debug|Win32 {814DBDDE-894E-4327-A6E1-740504850098}.Debug|ARM64.ActiveCfg = Debug|ARM64 {814DBDDE-894E-4327-A6E1-740504850098}.Debug|ARM64.Build.0 = Debug|ARM64 {814DBDDE-894E-4327-A6E1-740504850098}.Debug|x64.ActiveCfg = Debug|x64 @@ -881,6 +897,7 @@ Global {814CBEEE-894E-4327-A6E1-740504850098}.AuditMode|ARM64.ActiveCfg = Release|ARM64 {814CBEEE-894E-4327-A6E1-740504850098}.AuditMode|x64.ActiveCfg = Release|x64 {814CBEEE-894E-4327-A6E1-740504850098}.AuditMode|x86.ActiveCfg = Release|Win32 + {814CBEEE-894E-4327-A6E1-740504850098}.Debug|Any CPU.ActiveCfg = Debug|Win32 {814CBEEE-894E-4327-A6E1-740504850098}.Debug|ARM64.ActiveCfg = Debug|ARM64 {814CBEEE-894E-4327-A6E1-740504850098}.Debug|ARM64.Build.0 = Debug|ARM64 {814CBEEE-894E-4327-A6E1-740504850098}.Debug|x64.ActiveCfg = Debug|x64 @@ -919,6 +936,7 @@ Global {990F2657-8580-4828-943F-5DD657D11843}.AuditMode|ARM64.ActiveCfg = Release|ARM64 {990F2657-8580-4828-943F-5DD657D11843}.AuditMode|x64.ActiveCfg = Release|x64 {990F2657-8580-4828-943F-5DD657D11843}.AuditMode|x86.ActiveCfg = Release|Win32 + {990F2657-8580-4828-943F-5DD657D11843}.Debug|Any CPU.ActiveCfg = Debug|Win32 {990F2657-8580-4828-943F-5DD657D11843}.Debug|ARM64.ActiveCfg = Debug|ARM64 {990F2657-8580-4828-943F-5DD657D11843}.Debug|ARM64.Build.0 = Debug|ARM64 {990F2657-8580-4828-943F-5DD657D11843}.Debug|x64.ActiveCfg = Debug|x64 @@ -1141,6 +1159,7 @@ Global {2C2BEEF4-9333-4D05-B12A-1905CBF112F9}.AuditMode|ARM64.ActiveCfg = AuditMode|ARM64 {2C2BEEF4-9333-4D05-B12A-1905CBF112F9}.AuditMode|x64.ActiveCfg = AuditMode|x64 {2C2BEEF4-9333-4D05-B12A-1905CBF112F9}.AuditMode|x86.ActiveCfg = AuditMode|Win32 + {2C2BEEF4-9333-4D05-B12A-1905CBF112F9}.Debug|Any CPU.ActiveCfg = Debug|Win32 {2C2BEEF4-9333-4D05-B12A-1905CBF112F9}.Debug|ARM64.ActiveCfg = Debug|ARM64 {2C2BEEF4-9333-4D05-B12A-1905CBF112F9}.Debug|ARM64.Build.0 = Debug|ARM64 {2C2BEEF4-9333-4D05-B12A-1905CBF112F9}.Debug|x64.ActiveCfg = Debug|x64 @@ -1179,6 +1198,7 @@ Global {34DE34D3-1CD6-4EE3-8BD9-A26B5B27EC73}.AuditMode|ARM64.ActiveCfg = AuditMode|ARM64 {34DE34D3-1CD6-4EE3-8BD9-A26B5B27EC73}.AuditMode|x64.ActiveCfg = AuditMode|x64 {34DE34D3-1CD6-4EE3-8BD9-A26B5B27EC73}.AuditMode|x86.ActiveCfg = AuditMode|Win32 + {34DE34D3-1CD6-4EE3-8BD9-A26B5B27EC73}.Debug|Any CPU.ActiveCfg = Debug|Win32 {34DE34D3-1CD6-4EE3-8BD9-A26B5B27EC73}.Debug|ARM64.ActiveCfg = Debug|ARM64 {34DE34D3-1CD6-4EE3-8BD9-A26B5B27EC73}.Debug|ARM64.Build.0 = Debug|ARM64 {34DE34D3-1CD6-4EE3-8BD9-A26B5B27EC73}.Debug|x64.ActiveCfg = Debug|x64 @@ -1239,6 +1259,7 @@ Global {CA5CAD1A-9333-4D05-B12A-1905CBF112F9}.AuditMode|ARM64.ActiveCfg = AuditMode|ARM64 {CA5CAD1A-9333-4D05-B12A-1905CBF112F9}.AuditMode|x64.ActiveCfg = AuditMode|x64 {CA5CAD1A-9333-4D05-B12A-1905CBF112F9}.AuditMode|x86.ActiveCfg = AuditMode|Win32 + {CA5CAD1A-9333-4D05-B12A-1905CBF112F9}.Debug|Any CPU.ActiveCfg = Debug|Win32 {CA5CAD1A-9333-4D05-B12A-1905CBF112F9}.Debug|ARM64.ActiveCfg = Debug|ARM64 {CA5CAD1A-9333-4D05-B12A-1905CBF112F9}.Debug|ARM64.Build.0 = Debug|ARM64 {CA5CAD1A-9333-4D05-B12A-1905CBF112F9}.Debug|x64.ActiveCfg = Debug|x64 diff --git a/src/cascadia/PublicTerminalCore/HwndTerminal.cpp b/src/cascadia/PublicTerminalCore/HwndTerminal.cpp index 5f9bca43c57..f28d8b09f08 100644 --- a/src/cascadia/PublicTerminalCore/HwndTerminal.cpp +++ b/src/cascadia/PublicTerminalCore/HwndTerminal.cpp @@ -355,22 +355,24 @@ void _stdcall DestroyTerminal(void* terminal) } // Updates the terminal font type, size, color, as well as the background/foreground colors to a specified theme. -void _stdcall SetTheme(void* terminal, LPTerminalTheme theme, LPCWSTR fontFamily, short fontSize, int newDpi) +void _stdcall SetTheme(void* terminal, TerminalTheme theme, LPCWSTR fontFamily, short fontSize, int newDpi) { auto publicTerminal = reinterpret_cast(terminal); { auto lock = publicTerminal->_terminal->LockForWriting(); - publicTerminal->_terminal->SetDefaultForeground(theme->DefaultForeground); - publicTerminal->_terminal->SetDefaultBackground(theme->DefaultBackground); + publicTerminal->_terminal->SetDefaultForeground(theme.DefaultForeground); + publicTerminal->_terminal->SetDefaultBackground(theme.DefaultBackground); // Set the font colors for (size_t tableIndex = 0; tableIndex < 16; tableIndex++) { - publicTerminal->_terminal->SetColorTableEntry(tableIndex, theme->ColorTable[tableIndex]); + publicTerminal->_terminal->SetColorTableEntry(tableIndex, theme.ColorTable[tableIndex]); } } + publicTerminal->_terminal->SetCursorStyle(theme.CursorStyle); + publicTerminal->_desiredFont = { fontFamily, 0, 10, { 0, fontSize }, CP_UTF8 }; publicTerminal->_UpdateFont(newDpi); } diff --git a/src/cascadia/PublicTerminalCore/HwndTerminal.hpp b/src/cascadia/PublicTerminalCore/HwndTerminal.hpp index 31cfbe1f54e..0d7b7dc026e 100644 --- a/src/cascadia/PublicTerminalCore/HwndTerminal.hpp +++ b/src/cascadia/PublicTerminalCore/HwndTerminal.hpp @@ -4,20 +4,13 @@ #include "../../renderer/dx/DxRenderer.hpp" #include "../../cascadia/TerminalCore/Terminal.hpp" -enum class CursorStyle : int32_t -{ - Vintage = 0, - Bar = 1, - Underscore = 2, - FilledBox = 3, - EmptyBox = 4, -}; +using namespace Microsoft::Console::VirtualTerminal; typedef struct _TerminalTheme { COLORREF DefaultBackground; COLORREF DefaultForeground; - CursorStyle CursorStyle; + DispatchTypes::CursorStyle CursorStyle; COLORREF ColorTable[16]; } TerminalTheme, *LPTerminalTheme; @@ -35,7 +28,7 @@ extern "C" __declspec(dllexport) const wchar_t* _stdcall GetSelection(void* terminal); __declspec(dllexport) bool _stdcall IsSelectionActive(void* terminal); __declspec(dllexport) void _stdcall DestroyTerminal(void* terminal); - __declspec(dllexport) void _stdcall SetTheme(void* terminal, LPTerminalTheme theme, LPCWSTR fontFamily, short fontSize, int newDpi); + __declspec(dllexport) void _stdcall SetTheme(void* terminal, TerminalTheme theme, LPCWSTR fontFamily, short fontSize, int newDpi); __declspec(dllexport) void _stdcall RegisterWriteCallback(void* terminal, void __stdcall callback(wchar_t*)); __declspec(dllexport) void _stdcall SendKeyEvent(void* terminal, WPARAM wParam); __declspec(dllexport) void _stdcall SendCharEvent(void* terminal, char16_t ch); @@ -71,6 +64,6 @@ struct HwndTerminal { friend bool _stdcall IsSelectionActive(void* terminal); friend void _stdcall SendKeyEvent(void* terminal, WPARAM wParam); friend void _stdcall SendCharEvent(void* terminal, char16_t ch); - friend void _stdcall SetTheme(void* terminal, LPTerminalTheme theme, LPCWSTR fontFamily, short fontSize, int newDpi); + friend void _stdcall SetTheme(void* terminal, TerminalTheme theme, LPCWSTR fontFamily, short fontSize, int newDpi); void _UpdateFont(int newDpi); }; diff --git a/src/cascadia/WpfTerminalControl/NativeMethods.cs b/src/cascadia/WpfTerminalControl/NativeMethods.cs index 0da7f03dd6d..43f8f1fb12e 100644 --- a/src/cascadia/WpfTerminalControl/NativeMethods.cs +++ b/src/cascadia/WpfTerminalControl/NativeMethods.cs @@ -57,7 +57,7 @@ internal static class NativeMethods public static extern void SendCharEvent(IntPtr terminal, char ch); [DllImport("PublicTerminalCore.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)] - public static extern void SetTheme(IntPtr terminal, [MarshalAs(UnmanagedType.LPStruct)] TerminalTheme theme, string fontFamily, short fontSize, int newDpi); + public static extern void SetTheme(IntPtr terminal, [MarshalAs(UnmanagedType.Struct)] TerminalTheme theme, string fontFamily, short fontSize, int newDpi); [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr SetFocus(IntPtr hWnd); diff --git a/src/cascadia/WpfTerminalControl/TerminalTheme.cs b/src/cascadia/WpfTerminalControl/TerminalTheme.cs index 47d1e6b438b..62fd593bf58 100644 --- a/src/cascadia/WpfTerminalControl/TerminalTheme.cs +++ b/src/cascadia/WpfTerminalControl/TerminalTheme.cs @@ -8,7 +8,7 @@ namespace Microsoft.Terminal.Wpf /// /// Pack = 1 removes the padding added by some compilers/processors for optimization purposes. [StructLayout(LayoutKind.Sequential)] - public class TerminalTheme + public struct TerminalTheme { public uint DefaultBackground; public uint DefaultForeground; @@ -17,12 +17,15 @@ public class TerminalTheme public uint[] ColorTable; } - public enum CursorStyle + + public enum CursorStyle : UInt32 { - Vintage = 0, - Bar = 1, - Underscore = 2, - FilledBox = 3, - EmptyBox = 4, - } + BlinkingBlock = 0, + BlinkingBlockDefault = 1, + SteadyBlock = 2, + BlinkingUnderline = 3, + SteadyUnderline = 4, + BlinkingBar = 5, + SteadyBar = 6 + }; }