microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
94.75k stars 8.2k forks source link

Enable `globalSummon` / `quakeMode` to work even when there isn't a running Terminal #9996

Open zadjii-msft opened 3 years ago

zadjii-msft commented 3 years ago

This is probably going to need the "headless monarch" work we theorized. Different parts to this:

I've had many more thoughts on the matter in the past, I just need to have somewhere to put them.

dag03tsc commented 3 years ago

Is the monarch a phoenix (when it's killed, who restarts it?)

I'm pretty sure this already came to your mind before, but what about using the service approach? It'd only require the tray icon feature to enable the persistence and provide some control over the service itself.

I guess that'd also allow termination commands like exit, while keeping the globalSummon or quakeMode available, for as long as the service is running.

Could it be useful to have some kind of a master orchestrator service? Something like a service to host and manage all WT instances?

kensykora commented 3 years ago

Been testing out the preview channel and I LOVE quake mode. Since the terminal is so core to my development workflow, it'd be HUGE if this launched on startup so it felt like a core part of the OS.

hensz commented 3 years ago

Is this issue purely about starting (and keep running) Terminal at startup? I was looking for a way to manually start a terminal in Quake mode, just as asked for in issue #10206.

zadjii-msft commented 3 years ago

I was looking for a way to manually start a terminal in Quake mode

That'd be wt -w _quake. See also the docs

hensz commented 3 years ago

This doesn't work since I have both the stable and the preview version installed, and wt runs the stable version. Most likely I could simply uninstall the stable version. Is there any other way to launch the preview?

zadjii-msft commented 3 years ago

Is there any other way to launch the preview?

You could always change wt to open the Preview version. To do that, you can check out the "Manage app execution aliases" page in the settings

hensz commented 3 years ago

Hmm, if I do this and try to run wt, I get an error from the stable version: [Window Title] C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.8.1521.0_x64__8wekyb3d8bbwe\wt.exe

[Content] Windows cannot access the specified device, path, or file. You may not have the appropriate permissions to access the item.

hensz commented 3 years ago

OK, when I remove the stable version running wt successfully launches the preview, and also launching in Quake mode works fine. Thanks a lot! Now I only need to figure out how I can add this command as a shortcut to my start menu 🙈

NinovanderMark commented 3 years ago

If there were an option to start Windows Terminal in Quake mode, but hidden, that would solve it in my book.

Something like this: wt -w _quake --hidden

zadjii-msft commented 2 years ago

Another idea suggested in #13210 - start Terminal minimized to the tray on system startup.

I'm not sure how I feel about that. Initial thoughts is that I'd want to avoid that solution, since it would incur starting the user's shell(s) at startup, and having them running until the user actually invokes the Terminal. (I should be OOF this week so I'm not gonna give this much more thought ATM beyond just de-duping threads)

vadimkantorov commented 2 years ago

This minimized to tray on startup is quite frequent among other apps. If needed, spawning actual shell / profile can be postponed until the first summon (especially for WSLv2 shells that spawn a virtual machine and occupy a lot of RAM), but the rest of the app would already be initialized.

And in quake scenario, having Terminal occupying space in the app bar is wasteful, having one in tray is sufficient.

PathogenDavid commented 2 years ago

Unless there's other useful functionality associated with it, I'd personally rather not have yet another thing cluttering the overflow menu of the notification tray (and definitely not in the taskbar.)

To me this feature should feel like an ambient operating system thing.

JJRcop commented 2 years ago

For the moment launching minimized to tray could be solved with a new command line option "--minimized"

AlexHunterCodes commented 2 years ago

"Launch on machine startup" and "Always display an icon in the notification area" both enabled achieves similar behaviour to what I'm used to with always-available Quake mode terminals on macOS and Linux, but it's not perfect.

I have to accept the always-present tray icon that does nothing and is either visible or not visible when a normal Terminal window is open (depending on how you configure it), and I have to manually close the default Terminal window that opens on startup every time (although I'll try @JJRcop's suggestion to suppress that). Plus, when I open the Quake terminal, it appears as another Terminal window in the taskbar.

Ideally, there would be an option to launch into the background without any window at startup, and an option to have Terminal running in the background but without yet another tray icon. Anyone using Quake mode is a developer or a power user, if Terminal breaks or needs restarting we know how to kill it from Task Manager without a tray icon adding clutter.

Definitely like @PathogenDavid's perspective that if Quake mode is enabled, it should just be available whenever without jumping through a sequence of obscure configuration options and workarounds. I know some Linux desktop environments do that already and it's really nice.

JJRcop commented 2 years ago

(although I'll try @JJRcop's suggestion to suppress that)

Sorry, allow me to clarify that --minimized does not currently exist, and my suggestion is directed towards near-future quick-fix development rather than towards current usage.

I just edited my comment to hopefully make this clear, oops.

My sincerest apologies, sorry for any misunderstanding. 😅

zadjii-msft commented 2 years ago

FWIW, --minimized is tracked in #7374

akovia commented 2 years ago

Probably missing something, but I don't see a reason to have anything start with the OS unless there is some large configuration to load that took an inordinate amount of time. When you hit your launcher Hotkey, it should just launch directly into quake mode as the title suggests. Having a taskbar icon doesn't bother me at all as it tucks away in the overflow and just gives another way to interact with the program to access settings or kill the program for people who are used to working that way. There really doesn't need to be an icon in the app bar though when using quake mode. Having quake mode enabled pretty much insinuates you will be accessing your terminal via hotkey, so an app bar icon should at least be configurable if it's not desired.

Linux has perfected most of these issues over the years. I use XFCE4-terminal and it does almost everything perfectly. After booting is finished I just hit F12 and it launches nearly instantly. It has a tray icon but not an app icon. If I launch any additional instances it opens in a regular window with an app bar icon, but it doesn't affect my quake mode instance. I can also launch programs directly into a new tab of my existing running quake mode instance which is extremely handy for my custom actions in Thunar.

I only use Windows at work but I am truly grateful to have WT with quake mode now. If there is one thing I actually prefer with WT, is the ability to open with a pre defined set of tabs. (though the tabs should really be on the bottom of the window imho, (and visible) )

Lastly, it may be trivial, but I do wish the window would slide down from the top instead of opening across the screen from the bottom.

DHowett commented 2 years ago

When you hit your launcher Hotkey, it should just launch directly into quake mode as the title suggests.

Unfortunately, the problem is that we can't do that without having something launched before you press the hotkey to register for it and intercept it when you press it.

The only other way for us to accomplish it without pre-launching something would be to add a hook in the Windows shell, which wouldn't come out to users for another 1,000 years and then would only be available to people with Intel Core i48 processors.

akovia commented 2 years ago

Unfortunately, the problem is that we can't do that without having something launched before you press the hotkey to register for it and intercept it when you press it.

Thank you for the reply and sorry for my ignorance, but couldn't you use a systemwide hotkey to launch wt with the options you wanted? (ie.. create a shortcut and assign it a "shortcut key"?) If it determines the program is already open, it would function as a visibility toggle, otherwise it would spawn the program itself. It wouldn't be a hotkey that you configure within wt itself, but not sure that would matter if it accomplished the same goal.

I admit my ignorance on the inner workings of Windows, so again I apologize if there is something fundamentally flawed with this approach. It is completely useable as is and I'm glad to have it. Thanks for your hard work!

DHowett commented 2 years ago

HUH. Now that you mention it . . . shortcuts do support that! I wonder if they need to be placed in a specific directory, or need some other special treatment.

That's an excellent idea. Thank you! Is it I who was ignorant!

PathogenDavid commented 2 years ago

I wonder if they need to be placed in a specific directory

I thought they could be anywhere, but it seems they must be on the desktop or a folder on the desktop. (Maybe other places too, but it's definitely not anywhere.)

It's worth noting it doesn't support shortcuts involving the Windows key (at least the UI doesn't let you create them.) Additionally, on my PC at least there's a pretty significant/unacceptable delay between me pressing the shortcut and the application actually launching.

I kinda get the vibe that this feature exists mainly due to legacy momentum. It's been around since at least Windows 95:

Screenshot of a Windows 95 properties window for a shortcut showing the shortcut key option.

It's definitely an interesting feature from a trivia perspective, but I doesn't feel particularly well-suited for this task IMO.

akovia commented 2 years ago

LoL, it's always something with Windows.

From glossing over this answer to the problem, it seems like it's fixable, but may not be worth the trouble for some. There are programs out there like this which may offer a solution, but again I'm not sure it's worth the trouble for most.

Such a shame it's got to be this difficult. Systemwide shortcuts should just work out of the box. :\

AlexHunterCodes commented 2 years ago

I don't think I'd want to rely on Windows Desktop shortcuts since it seems like a janky forgotten feature that could be axed by Explorer for security reasons at any time. I think it was added back when Active Desktop was all the rage. "Let's replace your desktop wallpaper with an IE4 instance, what could possibly go wrong?"

Thinking about the UX from the perspective of an end-user who just wants to use the product without participating in its development: If Terminals' goal is to become a first-class citizen for Windows on par with most Linux DEs, then shell integration should be on the long-term roadmap regardless. If we're already able to replace the default console host with WT, then shell integration and Windows shipping with WT pre-installed should both be inevitable. If that's going to take a long time, then those conversations should be started now so it's at least on the right people's radars.

If that's not feasible, that's not a technical problem, that's a management and product roadmap problem. To be frank, end users don't care that Microsoft's corporate culture insists on pitting its own teams against each other, competing in parallel to solve the same problems.

A means to run WT minimised to the tray on startup (and WT itself listens for the Quake mode shortcut key), or a startup background helper to launch Terminal in Quake mode the first time the shortcut is pressed are both sensible short-term compromises. I don't have a strong preference either way; but I'd like the option to choose when the shell init happens (pre-emptively or deferred) and hide the tray icon.

PowerToys offers a mechanism to rebind system shortcuts, but doesn't have a mechanism to create new ones. However it also offers a modular architecture to run small tools in the background which add supplementary functionality to apps for power users. Maybe the Quake mode trigger helper would be a good candidate for that? It would synergise well with the keyboard remapping toy, and if it was generic it could be used for other tools too. (custom macro boards, game controllers, accessibility utilities, etc.)

Hellzbellz123 commented 2 years ago

fun fact, the desktop shortcut doesn't work properly if you select minimized in shortcut options, it results in the wt instance being spawned off screen and the only way to get it to show up after a restart is restarting WT or toggling full-screen then using win+arrow keys to move it back onto the desktop :/ this is also related too #9053 and others mentioned their, this is a decent work around if you only intend on using quake mode, however if you have windows terminal set too attach to an already opened instance you cant use WT from anywhere but win + ` until you use above workarounds, this was tested just now using windows terminal preview on windows 11

cs-spacecat commented 1 year ago

dirty way to start it minimized: wt -w _quake powershell -nologo -window minimized

NinovanderMark commented 1 year ago

dirty way to start it minimized: wt -w _quake powershell -nologo -window minimized

That's exactly what I was looking for. Thank you so much! I can't quite figure out how to pass a particular Windows Terminal profile though. I tried the following, but it pops up an error about the -window argument being unexpected.

wt -w _quake -p "PowerShell" -window minimized

DHowett commented 1 year ago

Ah, the ages-old issue with -p x. You'll need to specify a command to run using that profile¹; try wt -w _quake -p PowerShell pwsh -nologo -window minimized

¹ why is this the case? Passing a command on the commandline _overrides_ the profile's command, it doesn't add to it (various reasons this is true, one of which is that appending arguments to `cmd` profiles would require `cmd /s /c` and appending to powershell profiles would require `-command`, unless you wanted to pass arguments and *not* a command, at which point it's all for naught really... see docker's `ENTRYPOINT` for all the terribly fun ways this can fall apart 😄)
zeroZshadow commented 1 year ago

Note that this doesn't seem to apply all settings for the given profile. For example, the set Font is not applied.

alexanderVprice commented 1 year ago

For now, I'm using this shortcut:

pwsh -c "Start-Process wt.exe -WindowStyle Hidden"

with Run: Minimized

To run

Start-Process wt.exe -WindowStyle Hidden

in a short-lived, minimized conhost window.

Aside from (1) the conhost/pwsh icon that pops up on the taskbar very briefly on login (blink and you'll miss it), and (2) the fact that global summon / quake mode will stop working if you close all your terminals, this workaround.... well, works around the issue.

Potato22 commented 1 year ago

wt -w _quake powershell -nologo -window minimized

I really wished I could somehow only run this command once since the _quake window always pops up then quickly disappears every time a new window is opened (aka new instance in which the profile has to be re-init)

I put the command in the profile.
cs-spacecat commented 1 year ago

wt -w _quake powershell -nologo -window minimized

I really wished I could somehow only run this command once since the _quake window always pops up then quickly disappears every time a new window is opened (aka new instance in which the profile has to be re-init)

I put the command in the profile.

I don't exactly know what you mean, but yeah, it pops up for a second when launched. The problem is that you could shorten this delay by removing the "-nologo", but then the subshell gets really messed up.

batu1579 commented 1 year ago

I made a few tweaks to @KKirschi 's way, and so far it's working.

  1. Created a shortcut, put the following line in "Target", and select Minimize window to run
    "C:\Program Files\PowerShell\7\pwsh.exe" -Command "wt -w _quake 'C:\Program Files\PowerShell\7\pwsh.exe'  -NoExit  -Command '& {clear}' -window minimized;Start-Sleep -Seconds 1;$app=New-Object -ComObject shell.application;$app.ToggleDesktop();"
  2. Move the shortcut to C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup

I added a 1 second wait after launch quake. If the window doesn't disappear after logging in, try to extend it for a little longer.

Hope that helps orz~

zadjii-msft commented 1 year ago

I know that the "start the Terminal without a visible window" is a big part of this, but #14944 should make this a heck of a lot easier going forward.

NOTE TO SELF

Do the ~startOnUserLogin: headless~ wt --headless thing to close this.

--headless: Forces this launch of the Terminal into headless mode. If there are no other actions specified on the command line, then this will start the Terminal without a visible window. If the Terminal is already running, force the currently running terminal into headless mode. In headless mode, closing all terminal windows does not close this terminal instance, unless you perform the "Quit the Terminal" action.

Started in dev/migrie/oop/3/of-the-silmarils

User1785604260 commented 1 year ago

Will it be possible to enforce that the headless terminal window is the only window capturing the Win+` quakeMode hotkey? I don't like having the quake terminal run as admin, so I'd want to start the headless as non-admin and make sure it's the only thing opening new terminals when Win+` is pressed.

I wrote my own script to act as an Emporer and take over the Win+` hotkey entirely on its own to ensure this wouldn't happen. Sometimes I'd end up opening an admin terminal immediately on login, and if it was the first instance to run it'd grab the Win+` hotkey and then I was locked into having admin quakeMode until I quit that initial terminal.

zadjii-msft commented 1 year ago

After #14944 it'll still be whoever launches first who gets it. We're vaguely tracking the elevated/unelevated wonkiness in #12173 though, so that's probably the thread to follow up in 😊

zadjii-msft commented 1 year ago

Since folks in this thread are probably interested: https://github.com/microsoft/terminal/releases/tag/v1.18.1421.0 added the global setting compatibility.allowHeadless, which should let the Terminal keep running in the background after closing all windows. This'll let the global hotkeys keep working, even if the Terminal isn't open.

    // Add support for running the Terminal without _any_ windows #14944
    // (you probably also want at least `quakeMode` or a `globalSummon`)
    "compatibility.allowHeadless": true,

There's still more work to do, and I'm tracking it as follows:

vadimkantorov commented 1 year ago

@zadjii-msft could Terminal somehow run headless / without UI or with minimal non fully-fledged UWP UI if a *.cmd (or other) script is being launched in an unattended way as part of Windows startup? usecase of slow Terminal UI flickering when Windows runs some startup scripts: https://github.com/microsoft/terminal/issues/15001 - maybe these runtime scripts are being executed as cmd.exe .... which now spins up Terminal. maybe for these cases Terminal could support a headless mode?

zadjii-msft commented 1 year ago

@vadimkantorov I'm gonna move that discussion over to #15001.

vadimkantorov commented 1 year ago

no prob! just wondering if this new headless mode is useful for that usecase. currently every windows startup script spins up its own Terminal instance. maybe at least they could share an instance (and thus speed up all subsequent ui draws)

DrLeh commented 1 year ago

I use the following hotkey in Autohotkey to help enable this:

$#`::
If (ProcessExist("WindowsTerminal.exe"))
    Send #``
else
    Run "wt"
::

I couldn't get this to actually start in quake mode, so in reality what i have to do is press `#``, this opens terminal, then press it again to get quake mode, then again to hide it, then close the original terminal.

This is far from optimal but at least gives me a single hotkey to get terminal open and into quake mode without having to open wt through some other means.

NewtonChutney commented 1 year ago

Since folks in this thread are probably interested: https://github.com/microsoft/terminal/releases/tag/v1.18.1421.0 added the global setting compatibility.allowHeadless, which should let the Terminal keep running in the background after closing all windows. This'll let the global hotkeys keep working, even if the Terminal isn't open.

    // Add support for running the Terminal without _any_ windows #14944
    // (you probably also want at least `quakeMode` or a `globalSummon`)
    "compatibility.allowHeadless": true,

Meanwhile, can the preview release of WT point to a schema with these keys in it? I did try changing the schema, and didn't find this key though.. This seems missing.. 🫠 But the key value pair is detected! 😌

20230703_124156.jpg

Memoraike commented 1 year ago

I use the following hotkey in Autohotkey to help enable this:

$#`::
If (ProcessExist("WindowsTerminal.exe"))
    Send #``
else
    Run "wt"
::

I couldn't get this to actually start in quake mode, so in reality what i have to do is press `#``, this opens terminal, then press it again to get quake mode, then again to hide it, then close the original terminal.

This is far from optimal but at least gives me a single hotkey to get terminal open and into quake mode without having to open wt through some other means.

Try this:

ProcessExist(Name){
    Process,Exist,%Name%
    return Errorlevel
}

#If !ProcessExist("WindowsTerminal.exe")
#`::
Run wt -w _quake
Return

image

H4M5TER commented 1 year ago

dirty way to start it minimized: wt -w _quake powershell -nologo -window minimized

Since it would open a new shell nested in default shell, I put pwsh -nologo -window minimized on a standalone wt profile and use wt -w _quake -p quake to launch.

MolotovCherry commented 10 months ago

As of my current posting date, after reading all the above, this works for me

As a startup task. (By default it won't run the initial user profile; if you don't care about this, feel free to remove the command and even NoExit) wt -w _quake pwsh -nologo -window minimized -NoExit -Command "& { . 'C:\Users\><User>\Documents\PowerShell\Microsoft.PowerShell_profile.ps1' }"

Inside your settings.json (so you can still open quake after terminal/quake windows are closed) "compatibility.allowHeadless": true,

Now it always shows up no matter what (seems that a side effect as of the latest version of this posting date, is actual terminal windows open behind all others)

unennhexium commented 9 months ago

@MolotovCherry

I followed your instructions and got this error:

[error 2147942402 (0x80070002) when launching `"powershell -nologo -window minimized"']

⚠️Error

I also read all above.


Please clarify the exact command for the "target" field of startup shortcut. If I understand correctly, you are creating a shortcut in this directory:

%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup

📝Properties
MolotovCherry commented 9 months ago

@unennhexium I have mine in a task schedule job. (trigger at log in, action start a program) Program C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\wt.exe Args -w _quake powershell -nologo -window minimized -NoExit -Command "& { . 'C:\Users\<user>\Documents\PowerShell\Microsoft.PowerShell_profile.ps1' }" Start in C:\Users\<user>

I'm sure a shortcut way exists, but I have no need to experiment with that since it's already working for me.

In either case, I noticed your command is "powershell -nologo -window minimized", why is that double quoted? Double quotes turn it into one argument. It is looking for a program named "powershell -nologo -window minimized", but no such program exists (the program is powershell). That should be simply, powershell -nologo -window minimized

In either case, I don't know exactly what you're doing, so I can't really debug that for you. The usual rules apply. Make sure wt, powershell is in PATH, etc

(Also, while writing this, I noticed I should use pwsh instead of powershell, since the latter is the built in one in windows, where I have the newest powershell installed, which calls it pwsh instead)

amzon-ex commented 9 months ago

Program C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\wt.exe Args -w _quake powershell -nologo -window minimized -NoExit -Command "& { . 'C:\Users\<user>\Documents\PowerShell\Microsoft.PowerShell_profile.ps1' }" Start in C:\Users\<user>

@MolotovCherry could you please tell me what -NoExit does?

MolotovCherry commented 9 months ago

Program C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\wt.exe Args -w _quake powershell -nologo -window minimized -NoExit -Command "& { . 'C:\Users\<user>\Documents\PowerShell\Microsoft.PowerShell_profile.ps1' }" Start in C:\Users\<user>

@MolotovCherry could you please tell me what -NoExit does?

@amzon-ex According to microsoft docs, it:

Doesn't exit after running startup commands.

So, it just keeps the shell open after running a command.

unennhexium commented 9 months ago

@H4M5TER

Could you describe in detail what you do?

I do the following


🚩This also happens if I simply open a new tab with this profile in an already active terminal window.

unennhexium commented 9 months ago

@MolotovCherry

Ok. I did this using Task Scheduler


Just in case, I'm replacing powershell with pwsh. Both are in my PATH. The wt has also been added to PATH. That is, they can all be launched from the command line.

✅Checking access

I also did not include any additional quotation or other chars. I checked for extra spaces inside and at the ends of the command and its arguments. None of this was found.

This method still doesn't work for me.


The Task Scheduler allows to export tasks in xml format. I did this for my task and am attaching the code from this file. So you can "debug".

✏️wt_task.xml
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2023-11-03T19:04:05.6192719</Date>
    <Author>LAPTOP-PC\User</Author>
    <Description>Launches Windows Terminal in the background to be activated in Quake mode using (⊞ + `) in the future</Description>
    <URI>\Windows Terminal</URI>
  </RegistrationInfo>
  <Triggers>
    <LogonTrigger>
      <Enabled>true</Enabled>
    </LogonTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>S-1-5-21-3286135726-1618621029-3948465185-1014</UserId>
      <LogonType>InteractiveToken</LogonType>
      <RunLevel>LeastPrivilege</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Users\User\AppData\Local\MIcrosoft\WindowsApps\wt.exe</Command>
      <Arguments>-w _quake pwsh -nologo -window minimized</Arguments>
      <WorkingDirectory>C:\Users\User</WorkingDirectory>
    </Exec>
  </Actions>
</Task>