Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Monarch/Peasant & Make UI single-threaded #18215

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Nov 19, 2024

As before, a minor refactor:

  • I started off by removing the Monarch/Peasant with the goal of moving
    it into and deduplicating its functionality with WindowEmperor.
  • Since I needed a replacement for the Monarch (= ensures that there's
    a single instance), I wrote single-instance code with a NT mutex
    and by yeeting data across processes with WM_COPYDATA.
  • This resulted in severe threading issues, because it now started up
    way faster. The more I tried to solve them the deeper I had to dig,
    because you can't just put a mutex around CascadiaSettings.
    I then tried to seeif WinUI can run multiple windows on a single
    thread and, as it turns out, it can.
    So, I removed the multi- from the window threading.
  • At this point I had dig about 1 mile deep and brought no ladder.
    So, to finish it up, I had to clean up the entire eventing system
    around WindowEmperor, cleaned up all the coroutines,
    and cleaned up all the callbacks.

Closes #16733
Closes #17799
Closes #18176
Closes #18191
TODO: Find other issues

Validation Steps Performed

  • It does not crash ✅
  • New/close tab ✅
  • New/close window ✅
  • Move tabs between windows ✅
  • Split tab into new window ✅
  • Persist windows on exit / restore startup ✅

@lhecker lhecker changed the title Remove Monarch/Peasant, Single-threaded UI, and Windowing cleanup Remove Monarch/Peasant & Make UI single-threaded Nov 19, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added Issue-Bug It either shouldn't be doing this or needs an investigation. Area-Quality Stability, Performance, Etc. Product-Terminal The new Windows Terminal. Severity-Crash Crashes are real bad news. labels Nov 19, 2024
@@ -170,7 +170,6 @@ namespace winrt::TerminalApp::implementation

const auto canDragDrop = CanDragDrop();

_tabRow.PointerMoved({ get_weak(), &TerminalPage::_RestorePointerCursorHandler });
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved into TerminalControl as a different workaround is needed for this functionality.

{
auto weakThis{ get_weak() };
co_await wil::resume_foreground(Dispatcher());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No multi-threading = No problem. (Suppress whitespace in the diff.)

<CurrentXamlPackage Include="@(AppxPackageRegistration)"
Condition="'%(AppxPackageRegistration.Architecture)'=='$(Platform)' AND
$([System.String]::new('%(AppxPackageRegistration.Filename)').StartsWith('Microsoft.UI.Xaml'))" />
<CurrentXamlPackage Include="@(AppxPackageRegistration)" Condition="'%(AppxPackageRegistration.Architecture)'=='$(Platform)' AND&#xD;&#xA; $([System.String]::new('%(AppxPackageRegistration.Filename)').StartsWith('Microsoft.UI.Xaml'))" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VS mangled this :(

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

86/154! It's easy to review deletions ;)

@DHowett
Copy link
Member

DHowett commented Nov 19, 2024

  • different branding versions of terminal do not interact
  • unpackaged terminal doesn't interact with:
    • any other unpackaged terminal
    • any other packaged terminal

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

139/154

auto isCurrentlyDark = Theme::IsSystemInDarkTheme();
if (isCurrentlyDark != _currentSystemThemeIsDark)
{
_currentSystemThemeIsDark = isCurrentlyDark;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 DH - Guessing this moved to the Message Window; confirm

@microsoft-github-policy-service microsoft-github-policy-service bot added the Area-Windowing Window frame, quake mode, tearout label Nov 19, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Priority-3 A description (P3) label Nov 20, 2024
{
runtimeclass CommandlineArgs
{
CommandlineArgs();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, these constructors are only necessary if they will be created from outside the DLL.

If not, you can remove the ctor from the IDL, and the FACTORY from the header.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's instantiated in the WindowEmperor. Honestly, we could just move WindowEmperor into TerminalApp and call it from main(). That may make things simpler, especially now that it's way smaller.

WindowRequestedArgs(String window, String content, Windows.Foundation.IReference<Windows.Foundation.Rect> bounds);

UInt64 Id;
String WindowName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw you had to make a change to make WindowName writable. Is it possible to restrict that to the internal interface, so that it is not writable in the winmd and idl?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's being written the WindowEmperor which is external. I was hoping to improve this design at a later time.

// On the foreground thread:
co_await wil::resume_foreground(_rootGrid.Dispatcher());
_summonWindowRoutineBody(args);
_summonWindowRoutineBody(std::move(args));
}

// Method Description:
// - As above.
// BODGY: ARM64 BUILD FAILED WITH fatal error C1001: Internal compiler error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that we got a new compiler, is this still valid

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not even a coroutine any longer, so we can probably dispense with the separation entirely...

Comment on lines -86 to -87
ScopedResourceLoader loader{ L"TerminalApp/ContextMenu" };
const auto appNameLoc = loader.GetLocalizedString(L"AppName");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 DH - Loading up somebody else's resources - probably moved to Emperor

HWND GetMainWindow() const noexcept;
AppHost* GetWindowById(uint64_t id) const noexcept;
AppHost* GetWindowByName(std::wstring_view name) const noexcept;
void CreateNewWindow(winrt::TerminalApp::WindowRequestedArgs args);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why not const&?

bool _registerHotKey(const int index, const winrt::Microsoft::Terminal::Control::KeyChord& hotkey) noexcept;
void _unregisterHotKey(const int index) noexcept;
safe_void_coroutine _setupGlobalHotkeys();
enum class TriBool : uint8_t
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HAHAHAHAHAHAHAHAHAHAH

hahahahahaha

hahah

std::optional<bool>?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::optional<bool> is two bools in a trench coat, so... meh.

...but yeah I could do that.

const auto absoluteWindowOrigin = CoreWindow::GetForCurrentThread().Bounds();
// Get the offset (margin + tabs, etc..) of the control within the window
const auto controlOrigin = TransformToVisual(nullptr).TransformPoint({});
const auto inverseScale = 1.0f / static_cast<float>(XamlRoot().RasterizationScale());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these don't seem related to regicide

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CoreWindow::GetForCurrentThread().Bounds() won't work anymore, so this had to be rewritten. I also chose to use the technically correct way to get the rasterization scale (we do it incorrectly everywhere, according to the docs).

This comment has been minimized.

Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

Unrecognized words (2)

IInput
inputpaneinterop

Previously acknowledged words that are now absent barbaz DISPATCHNOTIFY Ralph stb 🫥
To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the [email protected]:microsoft/terminal.git repository
on the dev/lhecker/dethronement branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.22/apply.pl' |
perl - 'https://github.com/microsoft/terminal/actions/runs/12038853251/attempts/1'
Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary

This includes both expected items (2229) from .github/actions/spelling/expect/alphabet.txt
.github/actions/spelling/expect/expect.txt
.github/actions/spelling/expect/web.txt and unrecognized words (2)

Dictionary Entries Covers Uniquely
cspell:cpp/src/lang-jargon.txt 11 1 1
cspell:swift/src/swift.txt 53 1 1
cspell:gaming-terms/dict/gaming-terms.txt 59 1 1
cspell:monkeyc/src/monkeyc_keywords.txt 123 1 1
cspell:cryptocurrencies/cryptocurrencies.txt 125 1 1

Consider adding them (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

      with:
        extra_dictionaries:
          cspell:cpp/src/lang-jargon.txt
          cspell:swift/src/swift.txt
          cspell:gaming-terms/dict/gaming-terms.txt
          cspell:monkeyc/src/monkeyc_keywords.txt
          cspell:cryptocurrencies/cryptocurrencies.txt

To stop checking additional dictionaries, add (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

check_extra_dictionaries: ''
Errors (1)

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors Count
❌ ignored-expect-variant 6

See ❌ Event descriptions for more information.

✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Quality Stability, Performance, Etc. Area-Windowing Window frame, quake mode, tearout Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-3 A description (P3) Product-Terminal The new Windows Terminal. Severity-Crash Crashes are real bad news.
Projects
None yet
2 participants