Compare commits

..

2 Commits

Author SHA1 Message Date
Mario Hewardt
8d9de117b9 Adds a video trim dialog to ZoomIt (#45334)
## Summary of the Pull Request
Adds a video trim dialog to ZoomIt

## PR Checklist
Closes 45333

## Validation Steps Performed
Manual validation

---------

Co-authored-by: Mark Russinovich <markruss@ntdev.microsoft.com>
Co-authored-by: foxmsft <foxmsft@hotmail.com>
2026-02-03 13:05:31 -08:00
Jiří Polášek
42a7213644 CmdPal: Supress warning CsWinRT1028 for DeleteObjectSafeHandle (#45324)
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request

This PR adds a local suppression for warning CsWinRT1028: Class should
be marked partial for source generated class `DeleteObjectSafeHandle`.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Related to: #42574
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
2026-02-03 12:12:38 -06:00
41 changed files with 9727 additions and 1578 deletions

View File

@@ -0,0 +1,63 @@
acq
APPLYTOSUBMENUS
AUDCLNT
bitmaps
BUFFERFLAGS
centiseconds
Ctl
CTLCOLOR
CTLCOLORBTN
CTLCOLORDLG
CTLCOLOREDIT
CTLCOLORLISTBOX
CTrim
DFCS
dlg
dlu
DONTCARE
DRAWITEM
DRAWITEMSTRUCT
DWLP
EDITCONTROL
ENABLEHOOK
FDE
GETCHANNELRECT
GETCHECK
GETTHUMBRECT
GIFs
HTBOTTOMRIGHT
HTHEME
KSDATAFORMAT
LEFTNOWORDWRAP
letterbox
lld
logfont
lround
MENUINFO
mic
MMRESULT
OWNERDRAW
PBGRA
pfdc
playhead
pwfx
quantums
REFKNOWNFOLDERID
reposted
SCROLLSIZEGRIP
SETDEFID
SETRECT
SHAREMODE
SHAREVIOLATION
STREAMFLAGS
submix
tci
TEXTMETRIC
tme
TRACKMOUSEEVENT
Unadvise
WASAPI
WAVEFORMATEX
WAVEFORMATEXTENSIBLE
wil
WMU

View File

@@ -1,77 +0,0 @@
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Build Commands
| Task | Command |
|------|---------|
| First build / NuGet restore | `tools\build\build-essentials.cmd` |
| Build current folder | `tools\build\build.cmd` |
| Build with options | `tools\build\build.ps1 -Platform x64 -Configuration Release` |
**Build discipline:**
- `cd` to the project folder (`.csproj`/`.vcxproj`) before building
- Exit code 0 = success; non-zero = failure
- On failure, check `build.<config>.<platform>.errors.log`
- Run `build-essentials.cmd` first if NuGet packages are missing
## Running Tests
- Build test project first, wait for exit code 0
- Run via VS Test Explorer (`Ctrl+E, T`) or `vstest.console.exe`
- **Avoid `dotnet test`** - use VS Test Explorer or vstest.console.exe
- Test projects are named `<Product>*UnitTests` or `<Product>*UITests`
- UI tests require WinAppDriver v1.2.1 and Developer Mode enabled
## Architecture
PowerToys is a collection of Windows productivity utilities with a modular architecture.
| Component | Location | Purpose |
|-----------|----------|---------|
| Runner | `src/runner/` | Main executable - module loader, tray icon, hotkey management |
| Settings UI | `src/settings-ui/` | WinUI/WPF configuration app |
| Modules | `src/modules/` | Individual utilities (30+ modules) |
| Common Libraries | `src/common/` | Shared code: logging, IPC, settings, utilities |
**Module types:**
1. Simple modules - entirely in module interface DLL (e.g., Mouse Pointer Crosshairs)
2. External application launchers - start separate executables (e.g., Color Picker)
3. Context handler modules - File Explorer shell extensions (e.g., Power Rename)
4. Registry-based modules - preview/thumbnail handlers (e.g., Power Preview)
**IPC:** Runner ↔ Settings UI communicate via Windows Named Pipes using JSON messages.
## Critical Guidelines
**IPC contracts:** When modifying JSON message format between Runner and Settings UI:
- Update both `src/runner/` and `src/settings-ui/` in the same PR
- Add migration logic for settings schema changes
- Test both directions of communication
**Common libraries (`src/common/`):** Changes have wide impact:
- Avoid breaking public headers/APIs; update all callers if changed
- No logging in hot paths (hooks, timers, tight loops)
- New dependencies require PM approval and must be added to `NOTICE.md`
**Style enforcement:**
- C++: `src/.clang-format` (run `src/codeAnalysis/format_sources.ps1`)
- C#: `src/.editorconfig` with StyleCop.Analyzers
- XAML: XamlStyler (run `.\.pipelines\applyXamlStyling.ps1 -Main`)
**General:**
- Atomic PRs: one logical change, no drive-by refactors
- Preserve GPO and elevation behaviors
- Initialize git submodules: `git submodule update --init --recursive`
## Validation Checklist
- [ ] Build clean with exit code 0
- [ ] Tests updated and passing locally
- [ ] No unintended ABI breaks or schema changes
- [ ] IPC contracts consistent between runner and settings-ui
- [ ] New dependencies added to `NOTICE.md`
# Important
Always response with Chinese.

View File

@@ -1,9 +1,24 @@
#include "pch.h"
#include "AudioSampleGenerator.h"
#include "CaptureFrameWait.h"
#include "LoopbackCapture.h"
#include <wrl/client.h>
extern TCHAR g_MicrophoneDeviceId[];
namespace
{
// Declare the IMemoryBufferByteAccess interface for accessing raw buffer data
MIDL_INTERFACE("5b0d3235-4dba-4d44-8657-1f1d0f83e9a3")
IMemoryBufferByteAccess : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE GetBuffer(
BYTE** value,
UINT32* capacity) = 0;
};
}
namespace winrt
{
using namespace Windows::Foundation;
@@ -19,17 +34,23 @@ namespace winrt
using namespace Windows::Devices::Enumeration;
}
AudioSampleGenerator::AudioSampleGenerator()
AudioSampleGenerator::AudioSampleGenerator(bool captureMicrophone, bool captureSystemAudio)
: m_captureMicrophone(captureMicrophone)
, m_captureSystemAudio(captureSystemAudio)
{
OutputDebugStringA(("AudioSampleGenerator created, captureMicrophone=" +
std::string(captureMicrophone ? "true" : "false") +
", captureSystemAudio=" + std::string(captureSystemAudio ? "true" : "false") + "\n").c_str());
m_audioEvent.create(wil::EventOptions::ManualReset);
m_endEvent.create(wil::EventOptions::ManualReset);
m_startEvent.create(wil::EventOptions::ManualReset);
m_asyncInitialized.create(wil::EventOptions::ManualReset);
}
AudioSampleGenerator::~AudioSampleGenerator()
{
Stop();
if (m_started.load())
if (m_audioGraph)
{
m_audioGraph.Close();
}
@@ -40,6 +61,10 @@ winrt::IAsyncAction AudioSampleGenerator::InitializeAsync()
auto expected = false;
if (m_initialized.compare_exchange_strong(expected, true))
{
// Reset state in case this instance is reused.
m_endEvent.ResetEvent();
m_startEvent.ResetEvent();
// Initialize the audio graph
auto audioGraphSettings = winrt::AudioGraphSettings(winrt::AudioRenderCategory::Media);
auto audioGraphResult = co_await winrt::AudioGraph::CreateAsync(audioGraphSettings);
@@ -49,28 +74,88 @@ winrt::IAsyncAction AudioSampleGenerator::InitializeAsync()
}
m_audioGraph = audioGraphResult.Graph();
// Initialize the selected microphone
auto defaultMicrophoneId = winrt::MediaDevice::GetDefaultAudioCaptureId(winrt::AudioDeviceRole::Default);
auto microphoneId = (g_MicrophoneDeviceId[0] == 0) ? defaultMicrophoneId : winrt::to_hstring(g_MicrophoneDeviceId);
auto microphone = co_await winrt::DeviceInformation::CreateFromIdAsync(microphoneId);
// Get AudioGraph encoding properties for resampling
auto graphProps = m_audioGraph.EncodingProperties();
m_graphSampleRate = graphProps.SampleRate();
m_graphChannels = graphProps.ChannelCount();
// Initialize audio input and output nodes
auto inputNodeResult = co_await m_audioGraph.CreateDeviceInputNodeAsync(winrt::MediaCategory::Media, m_audioGraph.EncodingProperties(), microphone);
if (inputNodeResult.Status() != winrt::AudioDeviceNodeCreationStatus::Success && microphoneId != defaultMicrophoneId)
{
// If the selected microphone failed, try again with the default
microphone = co_await winrt::DeviceInformation::CreateFromIdAsync(defaultMicrophoneId);
inputNodeResult = co_await m_audioGraph.CreateDeviceInputNodeAsync(winrt::MediaCategory::Media, m_audioGraph.EncodingProperties(), microphone);
}
if (inputNodeResult.Status() != winrt::AudioDeviceNodeCreationStatus::Success)
{
throw winrt::hresult_error(E_FAIL, L"Failed to initialize input audio node!");
}
m_audioInputNode = inputNodeResult.DeviceInputNode();
OutputDebugStringA(("AudioGraph initialized: " + std::to_string(m_graphSampleRate) +
" Hz, " + std::to_string(m_graphChannels) + " ch\n").c_str());
// Create submix node to mix microphone and loopback audio
m_submixNode = m_audioGraph.CreateSubmixNode();
m_audioOutputNode = m_audioGraph.CreateFrameOutputNode();
m_submixNode.AddOutgoingConnection(m_audioOutputNode);
// Initialize WASAPI loopback capture for system audio (if enabled)
if (m_captureSystemAudio)
{
m_loopbackCapture = std::make_unique<LoopbackCapture>();
}
if (m_loopbackCapture && SUCCEEDED(m_loopbackCapture->Initialize()))
{
auto loopbackFormat = m_loopbackCapture->GetFormat();
if (loopbackFormat)
{
m_loopbackChannels = loopbackFormat->nChannels;
m_loopbackSampleRate = loopbackFormat->nSamplesPerSec;
m_resampleRatio = static_cast<double>(m_loopbackSampleRate) / static_cast<double>(m_graphSampleRate);
OutputDebugStringA(("Loopback initialized: " + std::to_string(m_loopbackSampleRate) +
" Hz, " + std::to_string(m_loopbackChannels) + " ch, resample ratio=" +
std::to_string(m_resampleRatio) + "\n").c_str());
}
}
else if (m_captureSystemAudio)
{
OutputDebugStringA("WARNING: Failed to initialize loopback capture\n");
m_loopbackCapture.reset();
}
// Always initialize a microphone input node to keep the AudioGraph running at real-time pace.
// When mic capture is disabled, we mute it so only loopback audio is captured.
{
auto defaultMicrophoneId = winrt::MediaDevice::GetDefaultAudioCaptureId(winrt::AudioDeviceRole::Default);
auto microphoneId = (m_captureMicrophone && g_MicrophoneDeviceId[0] != 0)
? winrt::to_hstring(g_MicrophoneDeviceId)
: defaultMicrophoneId;
if (!microphoneId.empty())
{
auto microphone = co_await winrt::DeviceInformation::CreateFromIdAsync(microphoneId);
// Initialize audio input node
auto inputNodeResult = co_await m_audioGraph.CreateDeviceInputNodeAsync(winrt::MediaCategory::Media, m_audioGraph.EncodingProperties(), microphone);
if (inputNodeResult.Status() != winrt::AudioDeviceNodeCreationStatus::Success && microphoneId != defaultMicrophoneId)
{
// If the selected microphone failed, try again with the default
microphone = co_await winrt::DeviceInformation::CreateFromIdAsync(defaultMicrophoneId);
inputNodeResult = co_await m_audioGraph.CreateDeviceInputNodeAsync(winrt::MediaCategory::Media, m_audioGraph.EncodingProperties(), microphone);
}
if (inputNodeResult.Status() == winrt::AudioDeviceNodeCreationStatus::Success)
{
m_audioInputNode = inputNodeResult.DeviceInputNode();
m_audioInputNode.AddOutgoingConnection(m_submixNode);
// If mic capture is disabled, mute the input so only loopback is captured
if (!m_captureMicrophone)
{
m_audioInputNode.OutgoingGain(0.0);
OutputDebugStringA("Mic input created but muted (loopback-only mode)\n");
}
else
{
OutputDebugStringA("Mic input created and active\n");
}
}
}
}
// Loopback capture is only required when system audio capture is enabled
if (m_captureSystemAudio && !m_loopbackCapture)
{
throw winrt::hresult_error(E_FAIL, L"Failed to initialize loopback audio capture!");
}
// Hookup audio nodes
m_audioInputNode.AddOutgoingConnection(m_audioOutputNode);
m_audioGraph.QuantumStarted({ this, &AudioSampleGenerator::OnAudioQuantumStarted });
m_asyncInitialized.SetEvent();
@@ -86,7 +171,37 @@ winrt::AudioEncodingProperties AudioSampleGenerator::GetEncodingProperties()
std::optional<winrt::MediaStreamSample> AudioSampleGenerator::TryGetNextSample()
{
CheckInitialized();
CheckStarted();
// The MediaStreamSource can request audio samples before we've started the audio graph.
// Instead of throwing (which crashes the app), wait until either Start() is called
// or Stop() signals end-of-stream.
if (!m_started.load())
{
std::vector<HANDLE> events = { m_endEvent.get(), m_startEvent.get() };
auto waitResult = WaitForMultipleObjectsEx(static_cast<DWORD>(events.size()), events.data(), false, INFINITE, false);
auto eventIndex = -1;
switch (waitResult)
{
case WAIT_OBJECT_0:
case WAIT_OBJECT_0 + 1:
eventIndex = waitResult - WAIT_OBJECT_0;
break;
}
WINRT_VERIFY(eventIndex >= 0);
if (events[eventIndex] == m_endEvent.get())
{
// End event signaled, but check if there are any remaining samples in the queue
auto lock = m_lock.lock_exclusive();
if (!m_samples.empty())
{
std::optional result(m_samples.front());
m_samples.pop_front();
return result;
}
return std::nullopt;
}
}
{
auto lock = m_lock.lock_exclusive();
@@ -118,11 +233,25 @@ std::optional<winrt::MediaStreamSample> AudioSampleGenerator::TryGetNextSample()
auto signaledEvent = events[eventIndex];
if (signaledEvent == m_endEvent.get())
{
// End was signaled, but check for any remaining samples before returning nullopt
auto lock = m_lock.lock_exclusive();
if (!m_samples.empty())
{
std::optional result(m_samples.front());
m_samples.pop_front();
return result;
}
return std::nullopt;
}
else
{
auto lock = m_lock.lock_exclusive();
if (m_samples.empty())
{
// Spurious wake or race - no samples available
// If end is signaled, return nullopt
return m_endEvent.is_signaled() ? std::nullopt : std::optional<winrt::MediaStreamSample>{};
}
std::optional result(m_samples.front());
m_samples.pop_front();
return result;
@@ -135,23 +264,349 @@ void AudioSampleGenerator::Start()
auto expected = false;
if (m_started.compare_exchange_strong(expected, true))
{
m_endEvent.ResetEvent();
m_startEvent.SetEvent();
// Start loopback capture if available
if (m_loopbackCapture)
{
// Clear any stale samples
{
auto lock = m_loopbackBufferLock.lock_exclusive();
m_loopbackBuffer.clear();
}
m_resampleInputBuffer.clear();
m_resampleInputPos = 0.0;
m_loopbackCapture->Start();
}
m_audioGraph.Start();
}
}
void AudioSampleGenerator::Stop()
{
CheckInitialized();
if (m_started.load())
// Stop may be called during teardown even if initialization hasn't completed.
// It must never throw.
if (!m_initialized.load())
{
m_asyncInitialized.wait();
m_audioGraph.Stop();
m_endEvent.SetEvent();
return;
}
m_asyncInitialized.wait();
// Stop loopback capture first
if (m_loopbackCapture)
{
m_loopbackCapture->Stop();
}
// Flush any remaining samples from the loopback capture before stopping the audio graph
FlushRemainingAudio();
// Stop the audio graph - no more quantum callbacks will run
m_audioGraph.Stop();
// Mark as stopped
m_started.store(false);
// Combine all remaining queued samples into one final sample so it can be
// returned immediately without waiting for additional TryGetNextSample calls
CombineQueuedSamples();
// NOW signal end event - this allows TryGetNextSample to return remaining
// queued samples and then return nullopt
m_endEvent.SetEvent();
m_audioEvent.SetEvent(); // Also wake any waiting TryGetNextSample
// DO NOT clear m_loopbackBuffer or m_samples here - allow MediaTranscoder to
// consume remaining queued audio samples to avoid audio cutoff at end of recording.
// TryGetNextSample() will return nullopt once m_samples is empty and
// m_endEvent is signaled. Buffers will be cleaned up on destruction.
}
void AudioSampleGenerator::AppendResampledLoopbackSamples(std::vector<float> const& rawLoopbackSamples, bool flushRemaining)
{
if (rawLoopbackSamples.empty())
{
return;
}
m_resampleInputBuffer.insert(m_resampleInputBuffer.end(), rawLoopbackSamples.begin(), rawLoopbackSamples.end());
if (m_loopbackChannels == 0 || m_graphChannels == 0 || m_resampleRatio <= 0.0)
{
return;
}
std::vector<float> resampledSamples;
while (true)
{
const uint32_t inputFrames = static_cast<uint32_t>(m_resampleInputBuffer.size() / m_loopbackChannels);
if (inputFrames == 0)
{
break;
}
if (!flushRemaining)
{
if (inputFrames < 2 || (m_resampleInputPos + 1.0) >= inputFrames)
{
break;
}
}
else
{
if (m_resampleInputPos >= inputFrames)
{
break;
}
}
uint32_t inputFrame = static_cast<uint32_t>(m_resampleInputPos);
double frac = m_resampleInputPos - inputFrame;
uint32_t nextFrame = (inputFrame + 1 < inputFrames) ? (inputFrame + 1) : inputFrame;
for (uint32_t outCh = 0; outCh < m_graphChannels; outCh++)
{
float sample = 0.0f;
if (m_loopbackChannels == m_graphChannels)
{
uint32_t idx1 = inputFrame * m_loopbackChannels + outCh;
uint32_t idx2 = nextFrame * m_loopbackChannels + outCh;
float s1 = m_resampleInputBuffer[idx1];
float s2 = m_resampleInputBuffer[idx2];
sample = static_cast<float>(s1 * (1.0 - frac) + s2 * frac);
}
else if (m_loopbackChannels > m_graphChannels)
{
float sum = 0.0f;
for (uint32_t inCh = 0; inCh < m_loopbackChannels; inCh++)
{
uint32_t idx1 = inputFrame * m_loopbackChannels + inCh;
uint32_t idx2 = nextFrame * m_loopbackChannels + inCh;
float s1 = m_resampleInputBuffer[idx1];
float s2 = m_resampleInputBuffer[idx2];
sum += static_cast<float>(s1 * (1.0 - frac) + s2 * frac);
}
sample = sum / m_loopbackChannels;
}
else
{
uint32_t idx1 = inputFrame * m_loopbackChannels;
uint32_t idx2 = nextFrame * m_loopbackChannels;
float s1 = m_resampleInputBuffer[idx1];
float s2 = m_resampleInputBuffer[idx2];
sample = static_cast<float>(s1 * (1.0 - frac) + s2 * frac);
}
resampledSamples.push_back(sample);
}
m_resampleInputPos += m_resampleRatio;
}
uint32_t consumedFrames = static_cast<uint32_t>(m_resampleInputPos);
if (consumedFrames > 0)
{
size_t samplesToErase = static_cast<size_t>(consumedFrames) * m_loopbackChannels;
if (samplesToErase >= m_resampleInputBuffer.size())
{
m_resampleInputBuffer.clear();
m_resampleInputPos = 0.0;
}
else
{
m_resampleInputBuffer.erase(m_resampleInputBuffer.begin(), m_resampleInputBuffer.begin() + samplesToErase);
m_resampleInputPos -= consumedFrames;
}
}
if (flushRemaining)
{
m_resampleInputBuffer.clear();
m_resampleInputPos = 0.0;
}
if (!resampledSamples.empty())
{
auto loopbackLock = m_loopbackBufferLock.lock_exclusive();
const size_t maxBufferSize = static_cast<size_t>(m_graphSampleRate) * m_graphChannels;
if (m_loopbackBuffer.size() + resampledSamples.size() > maxBufferSize)
{
size_t overflow = (m_loopbackBuffer.size() + resampledSamples.size()) - maxBufferSize;
if (overflow >= m_loopbackBuffer.size())
{
m_loopbackBuffer.clear();
}
else
{
m_loopbackBuffer.erase(m_loopbackBuffer.begin(), m_loopbackBuffer.begin() + overflow);
}
}
m_loopbackBuffer.insert(m_loopbackBuffer.end(), resampledSamples.begin(), resampledSamples.end());
}
}
void AudioSampleGenerator::FlushRemainingAudio()
{
// Called during stop to drain any remaining samples from loopback capture
// and convert them to MediaStreamSamples before the audio graph stops.
if (!m_loopbackCapture)
{
return;
}
auto lock = m_lock.lock_exclusive();
// Drain all remaining samples from the loopback capture client
std::vector<float> rawLoopbackSamples;
{
std::vector<float> tempSamples;
while (m_loopbackCapture->TryGetSamples(tempSamples))
{
rawLoopbackSamples.insert(rawLoopbackSamples.end(), tempSamples.begin(), tempSamples.end());
}
}
// Resample and channel-convert the loopback audio to match AudioGraph format
if (!rawLoopbackSamples.empty())
{
AppendResampledLoopbackSamples(rawLoopbackSamples, true);
}
// Now convert everything in m_loopbackBuffer to MediaStreamSamples
auto loopbackLock = m_loopbackBufferLock.lock_exclusive();
if (!m_loopbackBuffer.empty())
{
uint32_t outputSampleCount = static_cast<uint32_t>(m_loopbackBuffer.size());
std::vector<uint8_t> outputData(outputSampleCount * sizeof(float), 0);
float* outputFloats = reinterpret_cast<float*>(outputData.data());
for (uint32_t i = 0; i < outputSampleCount; i++)
{
float sample = m_loopbackBuffer[i];
if (sample > 1.0f) sample = 1.0f;
else if (sample < -1.0f) sample = -1.0f;
outputFloats[i] = sample;
}
m_loopbackBuffer.clear();
// Create buffer and sample
winrt::Buffer sampleBuffer(outputSampleCount * sizeof(float));
memcpy(sampleBuffer.data(), outputData.data(), outputData.size());
sampleBuffer.Length(static_cast<uint32_t>(outputData.size()));
if (sampleBuffer.Length() > 0)
{
const uint32_t sampleCount = sampleBuffer.Length() / sizeof(float);
const uint32_t frames = (m_graphChannels > 0) ? (sampleCount / m_graphChannels) : 0;
const int64_t durationTicks = (m_graphSampleRate > 0) ? (static_cast<int64_t>(frames) * 10000000LL / m_graphSampleRate) : 0;
const winrt::TimeSpan duration{ durationTicks };
winrt::TimeSpan timestamp{ 0 };
if (m_hasLastSampleTimestamp)
{
timestamp = winrt::TimeSpan{ m_lastSampleTimestamp.count() + m_lastSampleDuration.count() };
}
auto sample = winrt::MediaStreamSample::CreateFromBuffer(sampleBuffer, timestamp);
m_samples.push_back(sample);
m_audioEvent.SetEvent();
m_lastSampleTimestamp = timestamp;
m_lastSampleDuration = duration;
m_hasLastSampleTimestamp = true;
}
}
}
void AudioSampleGenerator::CombineQueuedSamples()
{
// Combine all queued samples into a single sample so it can be returned
// immediately in the next TryGetNextSample call. This is critical because
// once video ends, the MediaTranscoder may only request one more audio sample.
auto lock = m_lock.lock_exclusive();
if (m_samples.size() <= 1)
{
return;
}
// Calculate total size and collect all sample data
size_t totalBytes = 0;
std::vector<std::pair<winrt::Windows::Storage::Streams::IBuffer, winrt::Windows::Foundation::TimeSpan>> buffers;
winrt::Windows::Foundation::TimeSpan firstTimestamp{ 0 };
bool hasFirstTimestamp = false;
for (auto& sample : m_samples)
{
auto buffer = sample.Buffer();
if (buffer)
{
totalBytes += buffer.Length();
if (!hasFirstTimestamp)
{
firstTimestamp = sample.Timestamp();
hasFirstTimestamp = true;
}
buffers.push_back({ buffer, sample.Timestamp() });
}
}
if (totalBytes == 0)
{
return;
}
// Create combined buffer
winrt::Buffer combinedBuffer(static_cast<uint32_t>(totalBytes));
uint8_t* dest = combinedBuffer.data();
uint32_t offset = 0;
for (auto& [buffer, ts] : buffers)
{
uint32_t len = buffer.Length();
memcpy(dest + offset, buffer.data(), len);
offset += len;
}
combinedBuffer.Length(static_cast<uint32_t>(totalBytes));
// Create combined sample with first timestamp
auto combinedSample = winrt::Windows::Media::Core::MediaStreamSample::CreateFromBuffer(combinedBuffer, firstTimestamp);
// Clear queue and add combined sample
m_samples.clear();
m_samples.push_back(combinedSample);
// Update timestamp tracking
const uint32_t sampleCount = static_cast<uint32_t>(totalBytes) / sizeof(float);
const uint32_t frames = (m_graphChannels > 0) ? (sampleCount / m_graphChannels) : 0;
const int64_t durationTicks = (m_graphSampleRate > 0) ? (static_cast<int64_t>(frames) * 10000000LL / m_graphSampleRate) : 0;
m_lastSampleTimestamp = firstTimestamp;
m_lastSampleDuration = winrt::Windows::Foundation::TimeSpan{ durationTicks };
m_hasLastSampleTimestamp = true;
}
void AudioSampleGenerator::OnAudioQuantumStarted(winrt::AudioGraph const& sender, winrt::IInspectable const& args)
{
// Don't process if we're not actively recording
if (!m_started.load())
{
return;
}
{
auto lock = m_lock.lock_exclusive();
@@ -159,10 +614,101 @@ void AudioSampleGenerator::OnAudioQuantumStarted(winrt::AudioGraph const& sender
std::optional<winrt::TimeSpan> timestamp = frame.RelativeTime();
auto audioBuffer = frame.LockBuffer(winrt::AudioBufferAccessMode::Read);
// Get mic audio as a buffer (may be empty if no microphone)
auto sampleBuffer = winrt::Buffer::CreateCopyFromMemoryBuffer(audioBuffer);
sampleBuffer.Length(audioBuffer.Length());
auto sample = winrt::MediaStreamSample::CreateFromBuffer(sampleBuffer, timestamp.value());
m_samples.push_back(sample);
// Calculate expected samples per quantum (~10ms at graph sample rate)
// AudioGraph uses 10ms quantums by default
uint32_t expectedSamplesPerQuantum = (m_graphSampleRate / 100) * m_graphChannels;
uint32_t numMicSamples = audioBuffer.Length() / sizeof(float);
// Drain loopback samples regardless of whether we have mic audio
if (m_loopbackCapture)
{
std::vector<float> rawLoopbackSamples;
{
std::vector<float> tempSamples;
while (m_loopbackCapture->TryGetSamples(tempSamples))
{
rawLoopbackSamples.insert(rawLoopbackSamples.end(), tempSamples.begin(), tempSamples.end());
}
}
// Resample and channel-convert the loopback audio to match AudioGraph format
if (!rawLoopbackSamples.empty())
{
AppendResampledLoopbackSamples(rawLoopbackSamples);
}
}
// Determine the actual number of samples we'll output
// Use mic sample count if mic is enabled
uint32_t outputSampleCount = m_captureMicrophone ? numMicSamples : expectedSamplesPerQuantum;
// If microphone is disabled, create a buffer with only loopback audio
if (!m_captureMicrophone && outputSampleCount > 0)
{
// Create a buffer filled with loopback audio or silence
std::vector<uint8_t> outputData(outputSampleCount * sizeof(float), 0);
float* outputFloats = reinterpret_cast<float*>(outputData.data());
{
auto loopbackLock = m_loopbackBufferLock.lock_exclusive();
uint32_t samplesToUse = min(outputSampleCount, static_cast<uint32_t>(m_loopbackBuffer.size()));
for (uint32_t i = 0; i < samplesToUse; i++)
{
float sample = m_loopbackBuffer[i];
if (sample > 1.0f) sample = 1.0f;
else if (sample < -1.0f) sample = -1.0f;
outputFloats[i] = sample;
}
if (samplesToUse > 0)
{
m_loopbackBuffer.erase(m_loopbackBuffer.begin(), m_loopbackBuffer.begin() + samplesToUse);
}
}
// Create a new buffer with our loopback data
sampleBuffer = winrt::Buffer(outputSampleCount * sizeof(float));
memcpy(sampleBuffer.data(), outputData.data(), outputData.size());
sampleBuffer.Length(static_cast<uint32_t>(outputData.size()));
}
else if (m_captureMicrophone && numMicSamples > 0)
{
// Mix loopback into mic samples
auto loopbackLock = m_loopbackBufferLock.lock_exclusive();
float* bufferData = reinterpret_cast<float*>(sampleBuffer.data());
uint32_t samplesToMix = min(numMicSamples, static_cast<uint32_t>(m_loopbackBuffer.size()));
for (uint32_t i = 0; i < samplesToMix; i++)
{
float mixed = bufferData[i] + m_loopbackBuffer[i];
if (mixed > 1.0f) mixed = 1.0f;
else if (mixed < -1.0f) mixed = -1.0f;
bufferData[i] = mixed;
}
if (samplesToMix > 0)
{
m_loopbackBuffer.erase(m_loopbackBuffer.begin(), m_loopbackBuffer.begin() + samplesToMix);
}
}
if (sampleBuffer.Length() > 0)
{
auto sample = winrt::MediaStreamSample::CreateFromBuffer(sampleBuffer, timestamp.value());
m_samples.push_back(sample);
const uint32_t sampleCount = sampleBuffer.Length() / sizeof(float);
const uint32_t frames = (m_graphChannels > 0) ? (sampleCount / m_graphChannels) : 0;
const int64_t durationTicks = (m_graphSampleRate > 0) ? (static_cast<int64_t>(frames) * 10000000LL / m_graphSampleRate) : 0;
m_lastSampleTimestamp = timestamp.value();
m_lastSampleDuration = winrt::TimeSpan{ durationTicks };
m_hasLastSampleTimestamp = true;
}
}
m_audioEvent.SetEvent();
}

View File

@@ -1,9 +1,11 @@
#pragma once
#include "LoopbackCapture.h"
class AudioSampleGenerator
{
public:
AudioSampleGenerator();
AudioSampleGenerator(bool captureMicrophone = true, bool captureSystemAudio = true);
~AudioSampleGenerator();
winrt::Windows::Foundation::IAsyncAction InitializeAsync();
@@ -18,6 +20,10 @@ private:
winrt::Windows::Media::Audio::AudioGraph const& sender,
winrt::Windows::Foundation::IInspectable const& args);
void FlushRemainingAudio();
void CombineQueuedSamples();
void AppendResampledLoopbackSamples(std::vector<float> const& rawLoopbackSamples, bool flushRemaining = false);
void CheckInitialized()
{
if (!m_initialized.load())
@@ -37,12 +43,31 @@ private:
private:
winrt::Windows::Media::Audio::AudioGraph m_audioGraph{ nullptr };
winrt::Windows::Media::Audio::AudioDeviceInputNode m_audioInputNode{ nullptr };
winrt::Windows::Media::Audio::AudioSubmixNode m_submixNode{ nullptr };
winrt::Windows::Media::Audio::AudioFrameOutputNode m_audioOutputNode{ nullptr };
std::unique_ptr<LoopbackCapture> m_loopbackCapture;
std::vector<float> m_loopbackBuffer; // Accumulated loopback samples (resampled to match AudioGraph)
wil::srwlock m_loopbackBufferLock;
uint32_t m_loopbackChannels = 2;
uint32_t m_loopbackSampleRate = 48000;
uint32_t m_graphSampleRate = 48000;
uint32_t m_graphChannels = 2;
double m_resampleRatio = 1.0; // loopbackSampleRate / graphSampleRate
winrt::Windows::Foundation::TimeSpan m_lastSampleTimestamp{};
winrt::Windows::Foundation::TimeSpan m_lastSampleDuration{};
bool m_hasLastSampleTimestamp = false;
std::vector<float> m_resampleInputBuffer; // raw loopback samples buffered for resampling
double m_resampleInputPos = 0.0; // fractional input frame position for resampling
wil::srwlock m_lock;
wil::unique_event m_audioEvent;
wil::unique_event m_endEvent;
wil::unique_event m_startEvent;
wil::unique_event m_asyncInitialized;
std::deque<winrt::Windows::Media::Core::MediaStreamSample> m_samples;
std::atomic<bool> m_initialized = false;
std::atomic<bool> m_started = false;
bool m_captureMicrophone = true;
bool m_captureSystemAudio = true;
};

View File

@@ -846,7 +846,6 @@ LRESULT CALLBACK DemoTypeHookProc( int nCode, WPARAM wParam, LPARAM lParam )
if( g_UserDriven )
{
// Set baseline indentation to a blocking flag
// Otherwise indentation seeking will trigger user-driven injection events
g_BaselineIndentation = INDENT_SEEK_FLAG;
// Initialize the injection handler

View File

@@ -242,6 +242,13 @@ std::shared_ptr<GifRecordingSession> GifRecordingSession::Create(
//----------------------------------------------------------------------------
HRESULT GifRecordingSession::EncodeFrame(ID3D11Texture2D* frameTexture)
{
std::lock_guard<std::mutex> lock(m_encoderMutex);
if (m_encoderReleased)
{
OutputDebugStringW(L"EncodeFrame called after encoder released.\n");
return E_FAIL;
}
try
{
// Create a staging texture for CPU access
@@ -367,6 +374,7 @@ HRESULT GifRecordingSession::EncodeFrame(ID3D11Texture2D* frameTexture)
// Increment and log frame count
m_frameCount++;
m_hasAnyFrame.store(true);
OutputDebugStringW((L"GIF Frame #" + std::to_wstring(m_frameCount) + L" fully encoded and committed\n").c_str());
return S_OK;
@@ -405,6 +413,12 @@ winrt::IAsyncAction GifRecordingSession::StartAsync()
{
captureAttempts++;
auto frame = m_frameWait->TryGetNextFrame();
if (!frame && !m_isRecording)
{
// Recording was stopped while waiting for frame
OutputDebugStringW(L"[GIF] Recording stopped during frame wait\n");
break;
}
winrt::com_ptr<ID3D11Texture2D> croppedTexture;
@@ -472,8 +486,17 @@ winrt::IAsyncAction GifRecordingSession::StartAsync()
// Wait for the next frame interval
co_await winrt::resume_after(std::chrono::milliseconds(1000 / m_frameRate));
// Check again after resuming from sleep
if (!m_isRecording || m_closed)
{
OutputDebugStringW(L"[GIF] Loop exiting after resume_after\n");
break;
}
}
OutputDebugStringW(L"[GIF] Capture loop exited\n");
// Commit the GIF encoder
if (m_gifEncoder)
{
@@ -511,6 +534,10 @@ winrt::IAsyncAction GifRecordingSession::StartAsync()
CloseInternal();
}
}
// Ensure encoder resources are released in case caller forgets to Close explicitly.
ReleaseEncoderResources();
OutputDebugStringW(L"[GIF] StartAsync completing, about to co_return\n");
co_return;
}
@@ -521,18 +548,18 @@ winrt::IAsyncAction GifRecordingSession::StartAsync()
//----------------------------------------------------------------------------
void GifRecordingSession::Close()
{
OutputDebugStringW(L"[GIF] Close() called\n");
auto expected = false;
if (m_closed.compare_exchange_strong(expected, true))
{
expected = true;
if (!m_isRecording.compare_exchange_strong(expected, false))
{
CloseInternal();
}
else
{
m_frameWait->StopCapture();
}
OutputDebugStringW(L"[GIF] Setting m_closed = true\n");
// Signal the capture loop to stop
m_isRecording = false;
OutputDebugStringW(L"[GIF] Setting m_isRecording = false\n");
// Stop the frame wait to unblock any pending frame acquisition
m_frameWait->StopCapture();
OutputDebugStringW(L"[GIF] StopCapture called\n");
}
}
@@ -543,6 +570,42 @@ void GifRecordingSession::Close()
//----------------------------------------------------------------------------
void GifRecordingSession::CloseInternal()
{
ReleaseEncoderResources();
m_frameWait->StopCapture();
m_itemClosed.revoke();
}
//----------------------------------------------------------------------------
//
// GifRecordingSession::ReleaseEncoderResources
// Ensures encoder/stream COM objects release the temp file handle so trim can reopen it.
//
//----------------------------------------------------------------------------
void GifRecordingSession::ReleaseEncoderResources()
{
std::lock_guard<std::mutex> lock(m_encoderMutex);
if (m_encoderReleased)
{
return;
}
// Commit only if we still own the encoder and it has not been committed; swallow failures.
if (m_gifEncoder)
{
try
{
m_gifEncoder->Commit();
}
catch (...)
{
}
}
m_encoderMetadataWriter = nullptr;
m_gifEncoder = nullptr;
m_wicStream = nullptr;
m_wicFactory = nullptr;
m_stream = nullptr;
m_encoderReleased = true;
}

View File

@@ -11,6 +11,7 @@
#include "CaptureFrameWait.h"
#include <d3d11_4.h>
#include <vector>
#include <mutex>
class GifRecordingSession : public std::enable_shared_from_this<GifRecordingSession>
{
@@ -27,6 +28,8 @@ public:
void EnableCursorCapture(bool enable = true) { m_frameWait->EnableCursorCapture(enable); }
void Close();
bool HasCapturedFrames() const { return m_hasAnyFrame.load(); }
private:
GifRecordingSession(
winrt::Direct3D11::IDirect3DDevice const& device,
@@ -35,6 +38,7 @@ private:
uint32_t frameRate,
winrt::Streams::IRandomAccessStream const& stream);
void CloseInternal();
void ReleaseEncoderResources();
HRESULT EncodeFrame(ID3D11Texture2D* texture);
private:
@@ -58,6 +62,9 @@ private:
std::atomic<bool> m_isRecording = false;
std::atomic<bool> m_closed = false;
std::atomic<bool> m_encoderReleased = false;
std::atomic<bool> m_hasAnyFrame = false;
std::mutex m_encoderMutex;
uint32_t m_frameWidth=0;
uint32_t m_frameHeight=0;

View File

@@ -0,0 +1,337 @@
#include "pch.h"
#include "LoopbackCapture.h"
#include <functiondiscoverykeys_devpkey.h>
#pragma comment(lib, "ole32.lib")
LoopbackCapture::LoopbackCapture()
{
m_stopEvent.create(wil::EventOptions::ManualReset);
m_samplesReadyEvent.create(wil::EventOptions::ManualReset);
}
LoopbackCapture::~LoopbackCapture()
{
Stop();
if (m_pwfx)
{
CoTaskMemFree(m_pwfx);
m_pwfx = nullptr;
}
}
HRESULT LoopbackCapture::Initialize()
{
if (m_initialized.load())
{
return S_OK;
}
HRESULT hr = CoCreateInstance(
__uuidof(MMDeviceEnumerator),
nullptr,
CLSCTX_ALL,
__uuidof(IMMDeviceEnumerator),
m_deviceEnumerator.put_void());
if (FAILED(hr))
{
return hr;
}
// Get the default audio render device (speakers/headphones)
hr = m_deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, m_device.put());
if (FAILED(hr))
{
return hr;
}
hr = m_device->Activate(__uuidof(IAudioClient), CLSCTX_ALL, nullptr, m_audioClient.put_void());
if (FAILED(hr))
{
return hr;
}
// Get the mix format
hr = m_audioClient->GetMixFormat(&m_pwfx);
if (FAILED(hr))
{
return hr;
}
// Initialize audio client in loopback mode
// AUDCLNT_STREAMFLAGS_LOOPBACK enables capturing what's being played on the device
hr = m_audioClient->Initialize(
AUDCLNT_SHAREMODE_SHARED,
AUDCLNT_STREAMFLAGS_LOOPBACK,
1000000, // 100ms buffer to reduce capture latency
0,
m_pwfx,
nullptr);
if (FAILED(hr))
{
return hr;
}
hr = m_audioClient->GetService(__uuidof(IAudioCaptureClient), m_captureClient.put_void());
if (FAILED(hr))
{
return hr;
}
m_initialized.store(true);
return S_OK;
}
HRESULT LoopbackCapture::Start()
{
if (!m_initialized.load())
{
return E_NOT_VALID_STATE;
}
if (m_started.load())
{
return S_OK;
}
m_stopEvent.ResetEvent();
HRESULT hr = m_audioClient->Start();
if (FAILED(hr))
{
return hr;
}
m_started.store(true);
// Start capture thread
m_captureThread = std::thread(&LoopbackCapture::CaptureThread, this);
return S_OK;
}
void LoopbackCapture::Stop()
{
if (!m_started.load())
{
return;
}
m_stopEvent.SetEvent();
if (m_captureThread.joinable())
{
m_captureThread.join();
}
DrainCaptureClient();
if (m_audioClient)
{
m_audioClient->Stop();
}
m_started.store(false);
}
void LoopbackCapture::DrainCaptureClient()
{
if (!m_captureClient)
{
return;
}
while (true)
{
UINT32 packetLength = 0;
HRESULT hr = m_captureClient->GetNextPacketSize(&packetLength);
if (FAILED(hr) || packetLength == 0)
{
break;
}
BYTE* pData = nullptr;
UINT32 numFramesAvailable = 0;
DWORD flags = 0;
hr = m_captureClient->GetBuffer(&pData, &numFramesAvailable, &flags, nullptr, nullptr);
if (FAILED(hr))
{
break;
}
if (numFramesAvailable > 0)
{
std::vector<float> samples;
if (m_pwfx->wFormatTag == WAVE_FORMAT_IEEE_FLOAT ||
(m_pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
reinterpret_cast<WAVEFORMATEXTENSIBLE*>(m_pwfx)->SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))
{
if (flags & AUDCLNT_BUFFERFLAGS_SILENT)
{
samples.resize(static_cast<size_t>(numFramesAvailable) * m_pwfx->nChannels, 0.0f);
}
else
{
float* floatData = reinterpret_cast<float*>(pData);
samples.assign(floatData, floatData + (static_cast<size_t>(numFramesAvailable) * m_pwfx->nChannels));
}
}
else if (m_pwfx->wFormatTag == WAVE_FORMAT_PCM ||
(m_pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
reinterpret_cast<WAVEFORMATEXTENSIBLE*>(m_pwfx)->SubFormat == KSDATAFORMAT_SUBTYPE_PCM))
{
if (flags & AUDCLNT_BUFFERFLAGS_SILENT)
{
samples.resize(static_cast<size_t>(numFramesAvailable) * m_pwfx->nChannels, 0.0f);
}
else if (m_pwfx->wBitsPerSample == 16)
{
int16_t* pcmData = reinterpret_cast<int16_t*>(pData);
samples.resize(static_cast<size_t>(numFramesAvailable) * m_pwfx->nChannels);
for (size_t i = 0; i < samples.size(); i++)
{
samples[i] = static_cast<float>(pcmData[i]) / 32768.0f;
}
}
else if (m_pwfx->wBitsPerSample == 32)
{
int32_t* pcmData = reinterpret_cast<int32_t*>(pData);
samples.resize(static_cast<size_t>(numFramesAvailable) * m_pwfx->nChannels);
for (size_t i = 0; i < samples.size(); i++)
{
samples[i] = static_cast<float>(pcmData[i]) / 2147483648.0f;
}
}
}
if (!samples.empty())
{
auto lock = m_lock.lock_exclusive();
m_sampleQueue.push_back(std::move(samples));
m_samplesReadyEvent.SetEvent();
}
}
hr = m_captureClient->ReleaseBuffer(numFramesAvailable);
if (FAILED(hr))
{
break;
}
}
}
void LoopbackCapture::CaptureThread()
{
while (WaitForSingleObject(m_stopEvent.get(), 10) == WAIT_TIMEOUT)
{
UINT32 packetLength = 0;
HRESULT hr = m_captureClient->GetNextPacketSize(&packetLength);
if (FAILED(hr))
{
break;
}
while (packetLength != 0)
{
BYTE* pData = nullptr;
UINT32 numFramesAvailable = 0;
DWORD flags = 0;
hr = m_captureClient->GetBuffer(&pData, &numFramesAvailable, &flags, nullptr, nullptr);
if (FAILED(hr))
{
break;
}
if (numFramesAvailable > 0)
{
std::vector<float> samples;
// Convert to float samples
if (m_pwfx->wFormatTag == WAVE_FORMAT_IEEE_FLOAT ||
(m_pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
reinterpret_cast<WAVEFORMATEXTENSIBLE*>(m_pwfx)->SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))
{
// Already float format
if (flags & AUDCLNT_BUFFERFLAGS_SILENT)
{
// Insert silence
samples.resize(static_cast<size_t>(numFramesAvailable) * m_pwfx->nChannels, 0.0f);
}
else
{
float* floatData = reinterpret_cast<float*>(pData);
samples.assign(floatData, floatData + (static_cast<size_t>(numFramesAvailable) * m_pwfx->nChannels));
}
}
else if (m_pwfx->wFormatTag == WAVE_FORMAT_PCM ||
(m_pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
reinterpret_cast<WAVEFORMATEXTENSIBLE*>(m_pwfx)->SubFormat == KSDATAFORMAT_SUBTYPE_PCM))
{
// Convert PCM to float
if (flags & AUDCLNT_BUFFERFLAGS_SILENT)
{
samples.resize(static_cast<size_t>(numFramesAvailable) * m_pwfx->nChannels, 0.0f);
}
else if (m_pwfx->wBitsPerSample == 16)
{
int16_t* pcmData = reinterpret_cast<int16_t*>(pData);
samples.resize(static_cast<size_t>(numFramesAvailable) * m_pwfx->nChannels);
for (size_t i = 0; i < samples.size(); i++)
{
samples[i] = static_cast<float>(pcmData[i]) / 32768.0f;
}
}
else if (m_pwfx->wBitsPerSample == 32)
{
int32_t* pcmData = reinterpret_cast<int32_t*>(pData);
samples.resize(static_cast<size_t>(numFramesAvailable) * m_pwfx->nChannels);
for (size_t i = 0; i < samples.size(); i++)
{
samples[i] = static_cast<float>(pcmData[i]) / 2147483648.0f;
}
}
}
if (!samples.empty())
{
auto lock = m_lock.lock_exclusive();
m_sampleQueue.push_back(std::move(samples));
m_samplesReadyEvent.SetEvent();
}
}
hr = m_captureClient->ReleaseBuffer(numFramesAvailable);
if (FAILED(hr))
{
break;
}
hr = m_captureClient->GetNextPacketSize(&packetLength);
if (FAILED(hr))
{
break;
}
}
}
}
bool LoopbackCapture::TryGetSamples(std::vector<float>& samples)
{
auto lock = m_lock.lock_exclusive();
if (m_sampleQueue.empty())
{
return false;
}
samples = std::move(m_sampleQueue.front());
m_sampleQueue.pop_front();
if (m_sampleQueue.empty())
{
m_samplesReadyEvent.ResetEvent();
}
return true;
}

View File

@@ -0,0 +1,46 @@
#pragma once
#include <mmdeviceapi.h>
#include <audioclient.h>
#include <atomic>
#include <vector>
#include <deque>
#include <wil/resource.h>
class LoopbackCapture
{
public:
LoopbackCapture();
~LoopbackCapture();
HRESULT Initialize();
HRESULT Start();
void Stop();
// Returns audio samples in the format: PCM float, stereo, 48kHz
bool TryGetSamples(std::vector<float>& samples);
WAVEFORMATEX* GetFormat() const { return m_pwfx; }
uint32_t GetSampleRate() const { return m_pwfx ? m_pwfx->nSamplesPerSec : 48000; }
uint32_t GetChannels() const { return m_pwfx ? m_pwfx->nChannels : 2; }
private:
void CaptureThread();
void DrainCaptureClient();
winrt::com_ptr<IMMDeviceEnumerator> m_deviceEnumerator;
winrt::com_ptr<IMMDevice> m_device;
winrt::com_ptr<IAudioClient> m_audioClient;
winrt::com_ptr<IAudioCaptureClient> m_captureClient;
WAVEFORMATEX* m_pwfx{ nullptr };
wil::unique_event m_stopEvent;
wil::unique_event m_samplesReadyEvent;
std::thread m_captureThread;
wil::srwlock m_lock;
std::deque<std::vector<float>> m_sampleQueue;
std::atomic<bool> m_initialized{ false };
std::atomic<bool> m_started{ false };
};

View File

@@ -8,6 +8,579 @@
//==============================================================================
#include "pch.h"
#include "Utility.h"
#include <string>
#pragma comment(lib, "uxtheme.lib")
//----------------------------------------------------------------------------
// Dark Mode - Static/Global State
//----------------------------------------------------------------------------
static bool g_darkModeInitialized = false;
static bool g_darkModeEnabled = false;
static HBRUSH g_darkBackgroundBrush = nullptr;
static HBRUSH g_darkControlBrush = nullptr;
static HBRUSH g_darkSurfaceBrush = nullptr;
// Theme override from registry (defined in ZoomItSettings.h)
extern DWORD g_ThemeOverride;
// Preferred App Mode values for Windows 10/11 dark mode
enum class PreferredAppMode
{
Default,
AllowDark,
ForceDark,
ForceLight,
Max
};
// Undocumented ordinals from uxtheme.dll for dark mode support
using fnSetPreferredAppMode = PreferredAppMode(WINAPI*)(PreferredAppMode appMode);
using fnAllowDarkModeForWindow = bool(WINAPI*)(HWND hWnd, bool allow);
using fnShouldAppsUseDarkMode = bool(WINAPI*)();
using fnRefreshImmersiveColorPolicyState = void(WINAPI*)();
using fnFlushMenuThemes = void(WINAPI*)();
static fnSetPreferredAppMode pSetPreferredAppMode = nullptr;
static fnAllowDarkModeForWindow pAllowDarkModeForWindow = nullptr;
static fnShouldAppsUseDarkMode pShouldAppsUseDarkMode = nullptr;
static fnRefreshImmersiveColorPolicyState pRefreshImmersiveColorPolicyState = nullptr;
static fnFlushMenuThemes pFlushMenuThemes = nullptr;
//----------------------------------------------------------------------------
//
// InitializeDarkModeSupport
//
// Initialize dark mode function pointers from uxtheme.dll
//
//----------------------------------------------------------------------------
static void InitializeDarkModeSupport()
{
if (g_darkModeInitialized)
return;
g_darkModeInitialized = true;
HMODULE hUxTheme = GetModuleHandleW(L"uxtheme.dll");
if (hUxTheme)
{
// These are undocumented ordinal exports
// Ordinal 135: SetPreferredAppMode (Windows 10 1903+)
pSetPreferredAppMode = reinterpret_cast<fnSetPreferredAppMode>(
GetProcAddress(hUxTheme, MAKEINTRESOURCEA(135)));
// Ordinal 133: AllowDarkModeForWindow
pAllowDarkModeForWindow = reinterpret_cast<fnAllowDarkModeForWindow>(
GetProcAddress(hUxTheme, MAKEINTRESOURCEA(133)));
// Ordinal 132: ShouldAppsUseDarkMode
pShouldAppsUseDarkMode = reinterpret_cast<fnShouldAppsUseDarkMode>(
GetProcAddress(hUxTheme, MAKEINTRESOURCEA(132)));
// Ordinal 104: RefreshImmersiveColorPolicyState
pRefreshImmersiveColorPolicyState = reinterpret_cast<fnRefreshImmersiveColorPolicyState>(
GetProcAddress(hUxTheme, MAKEINTRESOURCEA(104)));
// Ordinal 136: FlushMenuThemes
pFlushMenuThemes = reinterpret_cast<fnFlushMenuThemes>(
GetProcAddress(hUxTheme, MAKEINTRESOURCEA(136)));
// Set preferred app mode based on our theme override or system setting
// Note: We check g_ThemeOverride directly here because IsDarkModeEnabled
// calls InitializeDarkModeSupport, which would cause recursion
if (pSetPreferredAppMode)
{
bool useDarkMode = false;
if (g_ThemeOverride == 0)
{
useDarkMode = false; // Force light
}
else if (g_ThemeOverride == 1)
{
useDarkMode = true; // Force dark
}
else if (pShouldAppsUseDarkMode)
{
useDarkMode = pShouldAppsUseDarkMode(); // Use system setting
}
if (useDarkMode)
{
pSetPreferredAppMode(PreferredAppMode::ForceDark);
}
else
{
pSetPreferredAppMode(PreferredAppMode::ForceLight);
}
}
// Flush menu themes to apply dark mode to context menus
if (pFlushMenuThemes)
{
pFlushMenuThemes();
}
}
// Update cached dark mode state
g_darkModeEnabled = false;
if (g_ThemeOverride == 0)
{
g_darkModeEnabled = false;
}
else if (g_ThemeOverride == 1)
{
g_darkModeEnabled = true;
}
else if (pShouldAppsUseDarkMode)
{
g_darkModeEnabled = pShouldAppsUseDarkMode();
}
}
//----------------------------------------------------------------------------
//
// IsDarkModeEnabled
//
//----------------------------------------------------------------------------
bool IsDarkModeEnabled()
{
// Check for theme override from registry (0=light, 1=dark, 2+=system)
if (g_ThemeOverride == 0)
{
return false; // Force light mode
}
else if (g_ThemeOverride == 1)
{
return true; // Force dark mode
}
InitializeDarkModeSupport();
// Check the undocumented API first
if (pShouldAppsUseDarkMode)
{
return pShouldAppsUseDarkMode();
}
// Fallback: Check registry for system theme preference
HKEY hKey;
if (RegOpenKeyExW(HKEY_CURRENT_USER,
L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
0, KEY_READ, &hKey) == ERROR_SUCCESS)
{
DWORD value = 1;
DWORD size = sizeof(value);
RegQueryValueExW(hKey, L"AppsUseLightTheme", nullptr, nullptr,
reinterpret_cast<LPBYTE>(&value), &size);
RegCloseKey(hKey);
return value == 0; // 0 = dark mode, 1 = light mode
}
return false;
}
//----------------------------------------------------------------------------
//
// RefreshDarkModeState
//
//----------------------------------------------------------------------------
void RefreshDarkModeState()
{
InitializeDarkModeSupport();
if (pRefreshImmersiveColorPolicyState)
{
pRefreshImmersiveColorPolicyState();
}
// Update preferred app mode based on our IsDarkModeEnabled (respects override)
bool useDark = IsDarkModeEnabled();
if (pSetPreferredAppMode)
{
if (useDark)
{
pSetPreferredAppMode(PreferredAppMode::ForceDark);
}
else
{
pSetPreferredAppMode(PreferredAppMode::ForceLight);
}
}
// Flush menu themes to apply dark mode to context menus
if (pFlushMenuThemes)
{
pFlushMenuThemes();
}
g_darkModeEnabled = useDark;
}
//----------------------------------------------------------------------------
//
// SetDarkModeForWindow
//
//----------------------------------------------------------------------------
void SetDarkModeForWindow(HWND hWnd, bool enable)
{
InitializeDarkModeSupport();
if (pAllowDarkModeForWindow)
{
pAllowDarkModeForWindow(hWnd, enable);
}
// Use DWMWA_USE_IMMERSIVE_DARK_MODE attribute (Windows 10 build 17763+)
// Attribute 20 is DWMWA_USE_IMMERSIVE_DARK_MODE
BOOL useDarkMode = enable ? TRUE : FALSE;
HMODULE hDwmapi = GetModuleHandleW(L"dwmapi.dll");
if (hDwmapi)
{
using fnDwmSetWindowAttribute = HRESULT(WINAPI*)(HWND, DWORD, LPCVOID, DWORD);
auto pDwmSetWindowAttribute = reinterpret_cast<fnDwmSetWindowAttribute>(
GetProcAddress(hDwmapi, "DwmSetWindowAttribute"));
if (pDwmSetWindowAttribute)
{
// Try attribute 20 first (Windows 11 / newer Windows 10)
HRESULT hr = pDwmSetWindowAttribute(hWnd, 20, &useDarkMode, sizeof(useDarkMode));
if (FAILED(hr))
{
// Fall back to attribute 19 (older Windows 10)
pDwmSetWindowAttribute(hWnd, 19, &useDarkMode, sizeof(useDarkMode));
}
}
}
}
//----------------------------------------------------------------------------
//
// GetDarkModeBrush / GetDarkModeControlBrush / GetDarkModeSurfaceBrush
//
//----------------------------------------------------------------------------
HBRUSH GetDarkModeBrush()
{
if (!g_darkBackgroundBrush)
{
g_darkBackgroundBrush = CreateSolidBrush(DarkMode::BackgroundColor);
}
return g_darkBackgroundBrush;
}
HBRUSH GetDarkModeControlBrush()
{
if (!g_darkControlBrush)
{
g_darkControlBrush = CreateSolidBrush(DarkMode::ControlColor);
}
return g_darkControlBrush;
}
HBRUSH GetDarkModeSurfaceBrush()
{
if (!g_darkSurfaceBrush)
{
g_darkSurfaceBrush = CreateSolidBrush(DarkMode::SurfaceColor);
}
return g_darkSurfaceBrush;
}
//----------------------------------------------------------------------------
//
// ApplyDarkModeToDialog
//
//----------------------------------------------------------------------------
void ApplyDarkModeToDialog(HWND hDlg)
{
if (IsDarkModeEnabled())
{
SetDarkModeForWindow(hDlg, true);
// Set dark theme for the dialog
SetWindowTheme(hDlg, L"DarkMode_Explorer", nullptr);
// Apply dark theme to common controls (buttons, edit boxes, etc.)
EnumChildWindows(hDlg, [](HWND hChild, LPARAM) -> BOOL {
wchar_t className[64] = { 0 };
GetClassNameW(hChild, className, _countof(className));
// Apply appropriate theme based on control type
if (_wcsicmp(className, L"Button") == 0)
{
// Check if this is a checkbox or radio button
LONG style = GetWindowLong(hChild, GWL_STYLE);
LONG buttonType = style & BS_TYPEMASK;
if (buttonType == BS_CHECKBOX || buttonType == BS_AUTOCHECKBOX ||
buttonType == BS_3STATE || buttonType == BS_AUTO3STATE ||
buttonType == BS_RADIOBUTTON || buttonType == BS_AUTORADIOBUTTON)
{
// Subclass checkbox/radio for dark mode painting - but keep DarkMode_Explorer theme
// for proper hit testing (empty theme can break mouse interaction)
SetWindowTheme(hChild, L"DarkMode_Explorer", nullptr);
SetWindowSubclass(hChild, CheckboxSubclassProc, 2, 0);
}
else if (buttonType == BS_GROUPBOX)
{
// Subclass group box for dark mode painting
SetWindowTheme(hChild, L"", L"");
SetWindowSubclass(hChild, GroupBoxSubclassProc, 4, 0);
}
else
{
SetWindowTheme(hChild, L"DarkMode_Explorer", nullptr);
}
}
else if (_wcsicmp(className, L"Edit") == 0)
{
// Use empty theme and subclass for dark mode border drawing
SetWindowTheme(hChild, L"", L"");
SetWindowSubclass(hChild, EditControlSubclassProc, 3, 0);
}
else if (_wcsicmp(className, L"ComboBox") == 0)
{
SetWindowTheme(hChild, L"DarkMode_CFD", nullptr);
}
else if (_wcsicmp(className, L"SysListView32") == 0 ||
_wcsicmp(className, L"SysTreeView32") == 0)
{
SetWindowTheme(hChild, L"DarkMode_Explorer", nullptr);
}
else if (_wcsicmp(className, L"msctls_trackbar32") == 0)
{
// Subclass trackbar controls for dark mode painting
SetWindowTheme(hChild, L"", L"");
SetWindowSubclass(hChild, SliderSubclassProc, 1, 0);
}
else if (_wcsicmp(className, L"SysTabControl32") == 0)
{
// Use empty theme for tab control to allow dark background
SetWindowTheme(hChild, L"", L"");
}
else if (_wcsicmp(className, L"msctls_updown32") == 0)
{
SetWindowTheme(hChild, L"DarkMode_Explorer", nullptr);
}
else if (_wcsicmp(className, L"msctls_hotkey32") == 0)
{
// Subclass hotkey controls for dark mode painting
SetWindowTheme(hChild, L"", L"");
SetWindowSubclass(hChild, HotkeyControlSubclassProc, 1, 0);
}
else if (_wcsicmp(className, L"Static") == 0)
{
// Check if this is a text label (not an owner-draw or image control)
LONG style = GetWindowLong(hChild, GWL_STYLE);
LONG staticType = style & SS_TYPEMASK;
// Options header uses a dedicated static subclass (to support large title font).
// Avoid applying the generic static subclass on top of it.
const int controlId = GetDlgCtrlID( hChild );
if( controlId == IDC_VERSION || controlId == IDC_COPYRIGHT )
{
SetWindowTheme( hChild, L"", L"" );
return TRUE;
}
if (staticType == SS_LEFT || staticType == SS_CENTER || staticType == SS_RIGHT ||
staticType == SS_LEFTNOWORDWRAP || staticType == SS_SIMPLE)
{
// Subclass text labels for proper dark mode painting
SetWindowTheme(hChild, L"", L"");
SetWindowSubclass(hChild, StaticTextSubclassProc, 5, 0);
}
else
{
// Other static controls (icons, bitmaps, frames) - just remove theme
SetWindowTheme(hChild, L"", L"");
}
}
else
{
SetWindowTheme(hChild, L"DarkMode_Explorer", nullptr);
}
return TRUE;
}, 0);
}
else
{
// Light mode - remove dark mode
SetDarkModeForWindow(hDlg, false);
SetWindowTheme(hDlg, nullptr, nullptr);
EnumChildWindows(hDlg, [](HWND hChild, LPARAM) -> BOOL {
// Remove subclass from controls
wchar_t className[64] = { 0 };
GetClassNameW(hChild, className, _countof(className));
if (_wcsicmp(className, L"msctls_hotkey32") == 0)
{
RemoveWindowSubclass(hChild, HotkeyControlSubclassProc, 1);
}
else if (_wcsicmp(className, L"msctls_trackbar32") == 0)
{
RemoveWindowSubclass(hChild, SliderSubclassProc, 1);
}
else if (_wcsicmp(className, L"Button") == 0)
{
LONG style = GetWindowLong(hChild, GWL_STYLE);
LONG buttonType = style & BS_TYPEMASK;
if (buttonType == BS_CHECKBOX || buttonType == BS_AUTOCHECKBOX ||
buttonType == BS_3STATE || buttonType == BS_AUTO3STATE ||
buttonType == BS_RADIOBUTTON || buttonType == BS_AUTORADIOBUTTON)
{
RemoveWindowSubclass(hChild, CheckboxSubclassProc, 2);
}
else if (buttonType == BS_GROUPBOX)
{
RemoveWindowSubclass(hChild, GroupBoxSubclassProc, 4);
}
}
else if (_wcsicmp(className, L"Edit") == 0)
{
RemoveWindowSubclass(hChild, EditControlSubclassProc, 3);
}
else if (_wcsicmp(className, L"Static") == 0)
{
RemoveWindowSubclass(hChild, StaticTextSubclassProc, 5);
}
SetWindowTheme(hChild, nullptr, nullptr);
return TRUE;
}, 0);
}
}
//----------------------------------------------------------------------------
//
// HandleDarkModeCtlColor
//
//----------------------------------------------------------------------------
HBRUSH HandleDarkModeCtlColor(HDC hdc, HWND hCtrl, UINT message)
{
if (!IsDarkModeEnabled())
{
return nullptr;
}
switch (message)
{
case WM_CTLCOLORDLG:
SetBkColor(hdc, DarkMode::BackgroundColor);
SetTextColor(hdc, DarkMode::TextColor);
return GetDarkModeBrush();
case WM_CTLCOLORSTATIC:
SetBkMode(hdc, TRANSPARENT);
// Use dimmed color for disabled static controls
if (!IsWindowEnabled(hCtrl))
{
SetTextColor(hdc, RGB(100, 100, 100));
}
else
{
SetTextColor(hdc, DarkMode::TextColor);
}
return GetDarkModeBrush();
case WM_CTLCOLORBTN:
SetBkColor(hdc, DarkMode::ControlColor);
SetTextColor(hdc, DarkMode::TextColor);
return GetDarkModeControlBrush();
case WM_CTLCOLOREDIT:
SetBkColor(hdc, DarkMode::SurfaceColor);
SetTextColor(hdc, DarkMode::TextColor);
return GetDarkModeSurfaceBrush();
case WM_CTLCOLORLISTBOX:
SetBkColor(hdc, DarkMode::SurfaceColor);
SetTextColor(hdc, DarkMode::TextColor);
return GetDarkModeSurfaceBrush();
}
return nullptr;
}
//----------------------------------------------------------------------------
//
// ApplyDarkModeToMenu
//
// Uses undocumented uxtheme functions to enable dark mode for menus
//
//----------------------------------------------------------------------------
void ApplyDarkModeToMenu(HMENU hMenu)
{
if (!hMenu)
{
return;
}
if (!IsDarkModeEnabled())
{
// Light mode - clear any dark background
MENUINFO mi = { sizeof(mi) };
mi.fMask = MIM_BACKGROUND | MIM_APPLYTOSUBMENUS;
mi.hbrBack = nullptr;
SetMenuInfo(hMenu, &mi);
return;
}
// For popup menus, we need to use MENUINFO to set the background
MENUINFO mi = { sizeof(mi) };
mi.fMask = MIM_BACKGROUND | MIM_APPLYTOSUBMENUS;
mi.hbrBack = GetDarkModeSurfaceBrush();
SetMenuInfo(hMenu, &mi);
}
//----------------------------------------------------------------------------
//
// RefreshWindowTheme
//
// Forces a window and all its children to redraw with current theme
//
//----------------------------------------------------------------------------
void RefreshWindowTheme(HWND hWnd)
{
if (!hWnd)
{
return;
}
// Reapply theme to this window
ApplyDarkModeToDialog(hWnd);
// Force redraw
RedrawWindow(hWnd, nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN | RDW_FRAME);
}
//----------------------------------------------------------------------------
//
// CleanupDarkModeResources
//
//----------------------------------------------------------------------------
void CleanupDarkModeResources()
{
if (g_darkBackgroundBrush)
{
DeleteObject(g_darkBackgroundBrush);
g_darkBackgroundBrush = nullptr;
}
if (g_darkControlBrush)
{
DeleteObject(g_darkControlBrush);
g_darkControlBrush = nullptr;
}
if (g_darkSurfaceBrush)
{
DeleteObject(g_darkSurfaceBrush);
g_darkSurfaceBrush = nullptr;
}
}
//----------------------------------------------------------------------------
//
// InitializeDarkMode
//
// Public wrapper to initialize dark mode support early in app startup
//
//----------------------------------------------------------------------------
void InitializeDarkMode()
{
InitializeDarkModeSupport();
}
//----------------------------------------------------------------------------
//
@@ -151,3 +724,177 @@ POINT ScalePointInRects( POINT point, const RECT& source, const RECT& target )
return { targetCenter.x + MulDiv( point.x - sourceCenter.x, targetSize.cx, sourceSize.cx ),
targetCenter.y + MulDiv( point.y - sourceCenter.y, targetSize.cy, sourceSize.cy ) };
}
//----------------------------------------------------------------------------
//
// ScaleDialogForDpi
//
// Scales a dialog and all its child controls for the specified DPI.
// oldDpi defaults to DPI_BASELINE (96) for initial scaling.
//
//----------------------------------------------------------------------------
void ScaleDialogForDpi( HWND hDlg, UINT newDpi, UINT oldDpi )
{
if( newDpi == oldDpi || newDpi == 0 || oldDpi == 0 )
{
return;
}
// With PerMonitorV2, Windows automatically scales dialogs (layout and fonts) when created.
// We only need to scale when moving between monitors with different DPIs.
// When oldDpi == DPI_BASELINE, this is initial creation and Windows already handled scaling.
if( oldDpi == DPI_BASELINE )
{
return;
}
// Scale the dialog window itself
RECT dialogRect;
GetWindowRect( hDlg, &dialogRect );
int dialogWidth = MulDiv( dialogRect.right - dialogRect.left, newDpi, oldDpi );
int dialogHeight = MulDiv( dialogRect.bottom - dialogRect.top, newDpi, oldDpi );
SetWindowPos( hDlg, nullptr, 0, 0, dialogWidth, dialogHeight, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
// Enumerate and scale all child controls
HWND hChild = GetWindow( hDlg, GW_CHILD );
while( hChild != nullptr )
{
RECT childRect;
GetWindowRect( hChild, &childRect );
MapWindowPoints( nullptr, hDlg, reinterpret_cast<LPPOINT>(&childRect), 2 );
int x = MulDiv( childRect.left, newDpi, oldDpi );
int y = MulDiv( childRect.top, newDpi, oldDpi );
int width = MulDiv( childRect.right - childRect.left, newDpi, oldDpi );
int height = MulDiv( childRect.bottom - childRect.top, newDpi, oldDpi );
SetWindowPos( hChild, nullptr, x, y, width, height, SWP_NOZORDER | SWP_NOACTIVATE );
// Scale the font for the control
HFONT hFont = reinterpret_cast<HFONT>(SendMessage( hChild, WM_GETFONT, 0, 0 ));
if( hFont != nullptr )
{
LOGFONT lf{};
if( GetObject( hFont, sizeof(lf), &lf ) )
{
lf.lfHeight = MulDiv( lf.lfHeight, newDpi, oldDpi );
HFONT hNewFont = CreateFontIndirect( &lf );
if( hNewFont )
{
SendMessage( hChild, WM_SETFONT, reinterpret_cast<WPARAM>(hNewFont), TRUE );
// Note: The old font might be shared, so we don't delete it here
// The system will clean up fonts when the dialog is destroyed
}
}
}
hChild = GetWindow( hChild, GW_HWNDNEXT );
}
// Also scale the dialog's own font
HFONT hDialogFont = reinterpret_cast<HFONT>(SendMessage( hDlg, WM_GETFONT, 0, 0 ));
if( hDialogFont != nullptr )
{
LOGFONT lf{};
if( GetObject( hDialogFont, sizeof(lf), &lf ) )
{
lf.lfHeight = MulDiv( lf.lfHeight, newDpi, oldDpi );
HFONT hNewFont = CreateFontIndirect( &lf );
if( hNewFont )
{
SendMessage( hDlg, WM_SETFONT, reinterpret_cast<WPARAM>(hNewFont), TRUE );
}
}
}
}
//----------------------------------------------------------------------------
//
// ScaleChildControlsForDpi
//
// Scales a window's direct child controls (and their fonts) for the specified DPI.
// Unlike ScaleDialogForDpi, this does not resize the parent window itself.
//
// This is useful for child dialogs used as tab pages: the tab page window is
// already scaled when the parent options dialog is scaled, but the controls
// inside the page are not (because they are grandchildren of the options dialog).
//
//----------------------------------------------------------------------------
void ScaleChildControlsForDpi( HWND hParent, UINT newDpi, UINT oldDpi )
{
if( newDpi == oldDpi || newDpi == 0 || oldDpi == 0 )
{
return;
}
// With PerMonitorV2, Windows automatically scales dialogs (layout and fonts) when created.
// We only need to scale when moving between monitors with different DPIs.
// When oldDpi == DPI_BASELINE, this is initial creation and Windows already handled scaling.
if( oldDpi == DPI_BASELINE )
{
return;
}
HWND hChild = GetWindow( hParent, GW_CHILD );
while( hChild != nullptr )
{
RECT childRect;
GetWindowRect( hChild, &childRect );
MapWindowPoints( nullptr, hParent, reinterpret_cast<LPPOINT>(&childRect), 2 );
int x = MulDiv( childRect.left, newDpi, oldDpi );
int y = MulDiv( childRect.top, newDpi, oldDpi );
int width = MulDiv( childRect.right - childRect.left, newDpi, oldDpi );
int height = MulDiv( childRect.bottom - childRect.top, newDpi, oldDpi );
SetWindowPos( hChild, nullptr, x, y, width, height, SWP_NOZORDER | SWP_NOACTIVATE );
// Scale the font for the control
HFONT hFont = reinterpret_cast<HFONT>(SendMessage( hChild, WM_GETFONT, 0, 0 ));
if( hFont != nullptr )
{
LOGFONT lf{};
if( GetObject( hFont, sizeof(lf), &lf ) )
{
lf.lfHeight = MulDiv( lf.lfHeight, newDpi, oldDpi );
HFONT hNewFont = CreateFontIndirect( &lf );
if( hNewFont )
{
SendMessage( hChild, WM_SETFONT, reinterpret_cast<WPARAM>(hNewFont), TRUE );
}
}
}
hChild = GetWindow( hChild, GW_HWNDNEXT );
}
}
//----------------------------------------------------------------------------
//
// HandleDialogDpiChange
//
// Handles WM_DPICHANGED message for dialogs. Call this from the dialog's
// WndProc when WM_DPICHANGED is received.
//
//----------------------------------------------------------------------------
void HandleDialogDpiChange( HWND hDlg, WPARAM wParam, LPARAM lParam, UINT& currentDpi )
{
UINT newDpi = HIWORD( wParam );
if( newDpi != currentDpi && newDpi != 0 )
{
const RECT* pSuggestedRect = reinterpret_cast<const RECT*>(lParam);
// Scale the dialog controls from the current DPI to the new DPI
ScaleDialogForDpi( hDlg, newDpi, currentDpi );
// Move and resize the dialog to the suggested rectangle
SetWindowPos( hDlg, nullptr,
pSuggestedRect->left,
pSuggestedRect->top,
pSuggestedRect->right - pSuggestedRect->left,
pSuggestedRect->bottom - pSuggestedRect->top,
SWP_NOZORDER | SWP_NOACTIVATE );
currentDpi = newDpi;
}
}

View File

@@ -9,6 +9,10 @@
#pragma once
#include "pch.h"
#include <uxtheme.h>
// DPI baseline for scaling calculations (dialog units are designed at 96 DPI)
constexpr UINT DPI_BASELINE = USER_DEFAULT_SCREEN_DPI;
RECT ForceRectInBounds( RECT rect, const RECT& bounds );
UINT GetDpiForWindowHelper( HWND window );
@@ -16,3 +20,86 @@ RECT GetMonitorRectFromCursor();
RECT RectFromPointsMinSize( POINT a, POINT b, LONG minSize );
int ScaleForDpi( int value, UINT dpi );
POINT ScalePointInRects( POINT point, const RECT& source, const RECT& target );
// Dialog DPI scaling functions
void ScaleDialogForDpi( HWND hDlg, UINT newDpi, UINT oldDpi = DPI_BASELINE );
void ScaleChildControlsForDpi( HWND hParent, UINT newDpi, UINT oldDpi = DPI_BASELINE );
void HandleDialogDpiChange( HWND hDlg, WPARAM wParam, LPARAM lParam, UINT& currentDpi );
//----------------------------------------------------------------------------
// Dark Mode Support
//----------------------------------------------------------------------------
// Dark mode colors
namespace DarkMode
{
// Background colors
constexpr COLORREF BackgroundColor = RGB(32, 32, 32);
constexpr COLORREF SurfaceColor = RGB(45, 45, 48);
constexpr COLORREF ControlColor = RGB(51, 51, 55);
// Text colors
constexpr COLORREF TextColor = RGB(200, 200, 200);
constexpr COLORREF DisabledTextColor = RGB(120, 120, 120);
constexpr COLORREF LinkColor = RGB(86, 156, 214);
// Border/accent colors
constexpr COLORREF BorderColor = RGB(67, 67, 70);
constexpr COLORREF AccentColor = RGB(0, 120, 215);
constexpr COLORREF HoverColor = RGB(62, 62, 66);
// Light mode colors for contrast
constexpr COLORREF LightBackgroundColor = RGB(255, 255, 255);
constexpr COLORREF LightTextColor = RGB(0, 0, 0);
}
// Check if system dark mode is enabled
bool IsDarkModeEnabled();
// Refresh dark mode state (call when WM_SETTINGCHANGE received)
void RefreshDarkModeState();
// Enable dark mode title bar for a window
void SetDarkModeForWindow(HWND hWnd, bool enable);
// Apply dark mode to a dialog and enable dark title bar
void ApplyDarkModeToDialog(HWND hDlg);
// Get the appropriate background brush for dark/light mode
HBRUSH GetDarkModeBrush();
HBRUSH GetDarkModeControlBrush();
HBRUSH GetDarkModeSurfaceBrush();
// Handle WM_CTLCOLOR* messages for dark mode
// Returns the brush to use, or nullptr if default handling should be used
HBRUSH HandleDarkModeCtlColor(HDC hdc, HWND hCtrl, UINT message);
// Apply dark mode theme to a popup menu
void ApplyDarkModeToMenu(HMENU hMenu);
// Force redraw of a window and all its children for theme change
void RefreshWindowTheme(HWND hWnd);
// Cleanup dark mode resources (call at app exit)
void CleanupDarkModeResources();
// Initialize dark mode support early in app startup (call before creating windows)
void InitializeDarkMode();
// Subclass procedure for hotkey controls - needs to be accessible from Utility.cpp
LRESULT CALLBACK HotkeyControlSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
// Subclass procedure for checkbox controls - needs to be accessible from Utility.cpp
LRESULT CALLBACK CheckboxSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
// Subclass procedure for edit controls - needs to be accessible from Utility.cpp
LRESULT CALLBACK EditControlSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
// Subclass procedure for group box controls - needs to be accessible from Utility.cpp
LRESULT CALLBACK GroupBoxSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
// Subclass procedure for slider/trackbar controls - needs to be accessible from Utility.cpp
LRESULT CALLBACK SliderSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
// Subclass procedure for static text controls - needs to be accessible from Utility.cpp
LRESULT CALLBACK StaticTextSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);

File diff suppressed because it is too large Load Diff

View File

@@ -11,6 +11,12 @@
#include "CaptureFrameWait.h"
#include "AudioSampleGenerator.h"
#include <d3d11_4.h>
#include <ppltasks.h>
#include <atomic>
#include <algorithm>
#include <chrono>
#include <mutex>
#include <vector>
class VideoRecordingSession : public std::enable_shared_from_this<VideoRecordingSession>
{
@@ -21,6 +27,7 @@ public:
RECT const& cropRect,
uint32_t frameRate,
bool captureAudio,
bool captureSystemAudio,
winrt::Streams::IRandomAccessStream const& stream);
~VideoRecordingSession();
@@ -28,6 +35,151 @@ public:
void EnableCursorCapture(bool enable = true) { m_frameWait->EnableCursorCapture(enable); }
void Close();
bool HasCapturedVideoFrames() const { return m_hasVideoSample.load(); }
// Trim and save functionality
static std::wstring ShowSaveDialogWithTrim(
HWND hWnd,
const std::wstring& suggestedFileName,
const std::wstring& originalVideoPath,
std::wstring& trimmedVideoPath);
struct TrimDialogData
{
struct GifFrame
{
HBITMAP hBitmap{ nullptr };
winrt::Windows::Foundation::TimeSpan start{ 0 };
winrt::Windows::Foundation::TimeSpan duration{ 0 };
UINT width{ 0 };
UINT height{ 0 };
};
std::wstring videoPath;
winrt::Windows::Foundation::TimeSpan videoDuration{ 0 };
winrt::Windows::Foundation::TimeSpan trimStart{ 0 };
winrt::Windows::Foundation::TimeSpan trimEnd{ 0 };
winrt::Windows::Foundation::TimeSpan originalTrimStart{ 0 }; // Initial value to detect if trim needed
winrt::Windows::Foundation::TimeSpan originalTrimEnd{ 0 }; // Initial value to detect if trim needed
winrt::Windows::Foundation::TimeSpan currentPosition{ 0 };
// Playback loop anchor. This is set when the user explicitly positions the playhead
// (e.g., dragging or using the jog buttons). Pausing/resuming should not change it.
winrt::Windows::Foundation::TimeSpan playbackStartPosition{ 0 };
bool playbackStartPositionValid{ false };
// Cached preview frame at playback start position for instant restore when playback stops.
HBITMAP hCachedStartFrame{ nullptr };
winrt::Windows::Foundation::TimeSpan cachedStartFramePosition{ -1 };
// When starting playback at a non-zero position, MediaPlayer may briefly report Position==0
// before the initial seek is applied. Use this to suppress a one-frame UI jump to 0.
std::atomic<bool> pendingInitialSeek{ false };
std::atomic<int64_t> pendingInitialSeekTicks{ 0 };
winrt::Windows::Media::Editing::MediaComposition composition{ nullptr };
winrt::Windows::Media::Playback::MediaPlayer mediaPlayer{ nullptr };
winrt::Windows::Storage::StorageFile playbackFile{ nullptr };
HBITMAP hPreviewBitmap{ nullptr };
HWND hDialog{ nullptr };
std::atomic<bool> loadingPreview{ false };
std::atomic<int64_t> latestPreviewRequest{ 0 };
std::atomic<int64_t> lastRenderedPreview{ -1 };
std::atomic<bool> isPlaying{ false };
// Monotonic serial used to cancel in-flight StartPlaybackAsync work when the user
// immediately pauses after starting playback.
std::atomic<uint64_t> playbackCommandSerial{ 0 };
std::atomic<bool> frameCopyInProgress{ false };
std::atomic<bool> smoothActive{ false };
std::atomic<int64_t> smoothBaseTicks{ 0 };
std::atomic<int64_t> smoothLastSyncMicroseconds{ 0 };
std::atomic<bool> smoothHasNonZeroSample{ false };
std::mutex previewBitmapMutex;
winrt::event_token frameAvailableToken{};
winrt::event_token positionChangedToken{};
winrt::event_token stateChangedToken{};
winrt::com_ptr<ID3D11Device> previewD3DDevice;
winrt::com_ptr<ID3D11DeviceContext> previewD3DContext;
winrt::com_ptr<ID3D11Texture2D> previewFrameTexture;
winrt::com_ptr<ID3D11Texture2D> previewFrameStaging;
bool hoverPlay{ false };
bool hoverRewind{ false };
bool hoverForward{ false };
bool hoverSkipStart{ false };
bool hoverSkipEnd{ false };
bool hoverVolumeIcon{ false };
double volume{ 0.70 }; // Volume level 0.0 to 1.0, initialized from g_TrimDialogVolume in dialog init
double previousVolume{ 0.70 }; // Volume before muting, for unmute restoration
winrt::Windows::Foundation::TimeSpan previewOverride{ 0 };
winrt::Windows::Foundation::TimeSpan positionBeforeOverride{ 0 };
bool previewOverrideActive{ false };
bool restorePreviewOnRelease{ false };
bool playheadPushed{ false };
int dialogX{ 0 };
int dialogY{ 0 };
bool isGif{ false };
bool previewBitmapOwned{ true };
std::vector<GifFrame> gifFrames;
bool gifFramesLoaded{ false };
size_t gifLastFrameIndex{ 0 };
std::chrono::steady_clock::time_point gifFrameStartTime{}; // When the current GIF frame started displaying
// Font for time labels
HFONT hTimeLabelFont{ nullptr };
// Mouse tracking for timeline
enum DragMode { None, TrimStart, Position, TrimEnd };
DragMode dragMode{ None };
bool isDragging{ false };
int lastPlayheadX{ -1 }; // Track last playhead pixel position for efficient invalidation
MMRESULT mmTimerId{ 0 }; // Multimedia timer for smooth MP4 playback
// Helper to convert time to pixel position
int TimeToPixel(winrt::Windows::Foundation::TimeSpan time, int timelineWidth) const
{
if (timelineWidth <= 0 || videoDuration.count() <= 0)
{
return 0;
}
double ratio = static_cast<double>(time.count()) / static_cast<double>(videoDuration.count());
ratio = std::clamp(ratio, 0.0, 1.0);
return static_cast<int>(ratio * timelineWidth);
}
// Helper to convert pixel to time
winrt::Windows::Foundation::TimeSpan PixelToTime(int pixel, int timelineWidth) const
{
if (timelineWidth <= 0 || videoDuration.count() <= 0)
{
return winrt::Windows::Foundation::TimeSpan{ 0 };
}
int clampedPixel = std::clamp(pixel, 0, timelineWidth);
double ratio = static_cast<double>(clampedPixel) / static_cast<double>(timelineWidth);
return winrt::Windows::Foundation::TimeSpan{ static_cast<int64_t>(ratio * videoDuration.count()) };
}
};
static INT_PTR ShowTrimDialog(
HWND hParent,
const std::wstring& videoPath,
winrt::Windows::Foundation::TimeSpan& trimStart,
winrt::Windows::Foundation::TimeSpan& trimEnd);
private:
static INT_PTR CALLBACK TrimDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
static winrt::Windows::Foundation::IAsyncOperation<winrt::hstring> TrimVideoAsync(
const std::wstring& sourceVideoPath,
winrt::Windows::Foundation::TimeSpan trimTimeStart,
winrt::Windows::Foundation::TimeSpan trimTimeEnd);
static winrt::Windows::Foundation::IAsyncOperation<winrt::hstring> TrimGifAsync(
const std::wstring& sourceGifPath,
winrt::Windows::Foundation::TimeSpan trimTimeStart,
winrt::Windows::Foundation::TimeSpan trimTimeEnd);
static INT_PTR ShowTrimDialogInternal(
HWND hParent,
const std::wstring& videoPath,
winrt::Windows::Foundation::TimeSpan& trimStart,
winrt::Windows::Foundation::TimeSpan& trimEnd);
private:
VideoRecordingSession(
winrt::Direct3D11::IDirect3DDevice const& device,
@@ -35,6 +187,7 @@ private:
RECT const cropRect,
uint32_t frameRate,
bool captureAudio,
bool captureSystemAudio,
winrt::Streams::IRandomAccessStream const& stream);
void CloseInternal();
@@ -68,4 +221,7 @@ private:
std::atomic<bool> m_isRecording = false;
std::atomic<bool> m_closed = false;
// Set once the MediaStreamSource successfully returns at least one video sample.
std::atomic<bool> m_hasVideoSample = false;
};

View File

@@ -32,18 +32,18 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
// TEXTINCLUDE
//
1 TEXTINCLUDE
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
3 TEXTINCLUDE
BEGIN
"#include ""binres.rc""\0"
END
@@ -113,26 +113,26 @@ END
// Dialog
//
OPTIONS DIALOGEX 0, 0, 279, 325
OPTIONS DIALOGEX 0, 0, 299, 325
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_CONTROLPARENT
CAPTION "ZoomIt - Sysinternals: www.sysinternals.com"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
DEFPUSHBUTTON "OK",IDOK,166,306,50,14
PUSHBUTTON "Cancel",IDCANCEL,223,306,50,14
LTEXT "ZoomIt v9.21",IDC_VERSION,42,7,73,10
LTEXT "Copyright © 2006-2025 Mark Russinovich",IDC_COPYRIGHT,42,17,231,8
DEFPUSHBUTTON "OK",IDOK,186,306,50,14
PUSHBUTTON "Cancel",IDCANCEL,243,306,50,14
LTEXT "ZoomIt v10.0",IDC_VERSION,42,7,73,10
LTEXT "Copyright \251 2006-2026 Mark Russinovich",IDC_COPYRIGHT,42,17,251,8
CONTROL "<a HREF=""https://www.sysinternals.com"">Sysinternals - www.sysinternals.com</a>",IDC_LINK,
"SysLink",WS_TABSTOP,42,26,150,9
ICON "APPICON",IDC_STATIC,12,9,20,20
CONTROL "Show tray icon",IDC_SHOW_TRAY_ICON,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,295,105,10
CONTROL "",IDC_TAB,"SysTabControl32",TCS_MULTILINE | WS_TABSTOP,8,46,265,245
CONTROL "",IDC_TAB,"SysTabControl32",TCS_MULTILINE | WS_TABSTOP,8,46,285,247
CONTROL "Run ZoomIt when Windows starts",IDC_AUTOSTART,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,309,122,10
END
ADVANCED_BREAK DIALOGEX 0, 0, 209, 219
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
ADVANCED_BREAK DIALOGEX 0, 0, 209, 225
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Advanced Break Options"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
@@ -158,23 +158,22 @@ BEGIN
EDITTEXT IDC_BACKGROUND_FILE,62,164,125,12,ES_AUTOHSCROLL | ES_READONLY
PUSHBUTTON "&...",IDC_BACKGROUND_BROWSE,188,164,13,11
CONTROL "Scale to screen:",IDC_CHECK_BACKGROUND_STRETCH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,58,180,67,10,WS_EX_RIGHT
DEFPUSHBUTTON "OK",IDOK,97,201,50,14
PUSHBUTTON "Cancel",IDCANCEL,150,201,50,14
DEFPUSHBUTTON "OK",IDOK,97,199,50,14
PUSHBUTTON "Cancel",IDCANCEL,150,199,50,14
LTEXT "Alarm Sound File:",IDC_STATIC_SOUND_FILE,61,26,56,8
LTEXT "Timer Opacity:",IDC_STATIC,8,59,48,8
LTEXT "Timer Position:",IDC_STATIC,8,77,48,8
CONTROL "",IDC_STATIC,"Static",SS_BLACKFRAME | SS_SUNKEN,7,196,193,1,WS_EX_CLIENTEDGE
END
ZOOM DIALOGEX 0, 0, 260, 170
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_CLIPSIBLINGS | WS_SYSMENU
STYLE DS_SETFONT | DS_CONTROL | WS_CHILD | WS_CLIPSIBLINGS | WS_SYSMENU
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "",IDC_HOTKEY,"msctls_hotkey32",WS_BORDER | WS_TABSTOP,59,57,80,12
LTEXT "After toggling ZoomIt you can zoom in with the mouse wheel or up and down arrow keys. Exit zoom mode with Escape or by pressing the right mouse button.",IDC_STATIC,7,6,246,26
LTEXT "After toggling ZoomIt you can zoom in with the mouse wheel or up and down arrow keys. Exit zoom mode with Escape or by pressing the right mouse button.",IDC_STATIC,7,6,230,26
LTEXT "Zoom Toggle:",IDC_STATIC,7,59,51,8
CONTROL "",IDC_ZOOM_SLIDER,"msctls_trackbar32",TBS_AUTOTICKS | TBS_BOTH | TBS_NOTICKS | WS_TABSTOP,53,118,150,15,WS_EX_TRANSPARENT
LTEXT "Specify the initial level of magnification when zooming in:",IDC_STATIC,7,105,215,10
LTEXT "Specify the initial level of magnification when zooming in:",IDC_STATIC,7,105,230,10
LTEXT "1.25",IDC_STATIC,52,136,16,8
LTEXT "1.5",IDC_STATIC,82,136,12,8
LTEXT "1.75",IDC_STATIC,108,136,16,8
@@ -183,52 +182,52 @@ BEGIN
LTEXT "4.0",IDC_STATIC,190,136,12,8
CONTROL "Animate zoom in and zoom out:",IDC_ANIMATE_ZOOM,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,7,74,116,10
CONTROL "Smooth zoomed image:",IDC_SMOOTH_IMAGE,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,7,88,116,10
LTEXT "Copy a zoomed screen with Ctrl+C or save it by typing Ctrl+S. Crop the copy or save region by entering Ctrl+Shift instead of Ctrl.",IDC_STATIC,7,148,246,17
LTEXT "Copy a zoomed screen with Ctrl+C or save it by typing Ctrl+S. Crop the copy or save region by entering Ctrl+Shift instead of Ctrl.",IDC_STATIC,6,34,246,18
LTEXT "Copy a zoomed screen with Ctrl+C or save it by typing Ctrl+S. Crop the copy or save region by entering Ctrl+Shift instead of Ctrl.",IDC_STATIC,7,148,230,17
LTEXT "Copy a zoomed screen with Ctrl+C or save it by typing Ctrl+S. Crop the copy or save region by entering Ctrl+Shift instead of Ctrl.",IDC_STATIC,6,34,230,18
END
DRAW DIALOGEX 0, 0, 260, 228
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_SYSMENU
STYLE DS_SETFONT | DS_CONTROL | WS_CHILD | WS_SYSMENU
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LTEXT "Once zoomed, toggle drawing mode by pressing the left mouse button. Undo with Ctrl+Z and all drawing by pressing E. Center the cursor with the space bar. Exit drawing mode by pressing the right mouse button.",IDC_STATIC,7,7,246,24
LTEXT "Once zoomed, toggle drawing mode by pressing the left mouse button. Undo with Ctrl+Z and all drawing by pressing E. Center the cursor with the space bar. Exit drawing mode by pressing the right mouse button.",IDC_STATIC,7,7,230,24
LTEXT "Pen Control ",IDC_PEN_CONTROL,7,38,40,8
LTEXT "Change the pen width by pressing left Ctrl and using the mouse wheel or the up and down arrow keys.",IDC_STATIC,19,48,233,16
LTEXT "Change the pen width by pressing left Ctrl and using the mouse wheel or the up and down arrow keys.",IDC_STATIC,19,48,218,16
LTEXT "Colors",IDC_COLORS,7,70,21,8
LTEXT "Change the pen color by pressing R (red), G (green), B (blue),\nO (orange), Y (yellow) or P (pink).",IDC_STATIC,19,80,233,16
LTEXT "Change the pen color by pressing R (red), G (green), B (blue),\nO (orange), Y (yellow) or P (pink).",IDC_STATIC,19,80,218,16
LTEXT "Highlight and Blur",IDC_HIGHLIGHT_AND_BLUR,7,102,58,8
LTEXT "Hold Shift while pressing a color key for a translucent highlighter color. Press X for blur or Shift+X for a stronger blur.",IDC_STATIC,19,113,233,16
LTEXT "Hold Shift while pressing a color key for a translucent highlighter color. Press X for blur or Shift+X for a stronger blur.",IDC_STATIC,19,113,218,16
LTEXT "Shapes",IDC_SHAPES,7,134,23,8
LTEXT "Draw a line by holding down the Shift key, a rectangle with the Ctrl key, an ellipse with the Tab key and an arrow with Shift+Ctrl.",IDC_STATIC,19,144,233,16
LTEXT "Draw a line by holding down the Shift key, a rectangle with the Ctrl key, an ellipse with the Tab key and an arrow with Shift+Ctrl.",IDC_STATIC,19,144,218,16
LTEXT "Screen",IDC_SCREEN,7,166,22,8
LTEXT "Clear the screen for a sketch pad by pressing W (white) or K (black). Copy a zoomed screen with Ctrl+C or save it by typing Ctrl+S. Crop the copy or save region by entering Ctrl+Shift instead of Ctrl.",IDC_STATIC,19,176,233,24
LTEXT "Clear the screen for a sketch pad by pressing W (white) or K (black). Copy a zoomed screen with Ctrl+C or save it by typing Ctrl+S. Crop the copy or save region by entering Ctrl+Shift instead of Ctrl.",IDC_STATIC,19,176,218,24
CONTROL "",IDC_DRAW_HOTKEY,"msctls_hotkey32",WS_BORDER | WS_TABSTOP,73,207,80,12
LTEXT "Draw w/out Zoom:",IDC_STATIC,7,210,63,11
END
TYPE DIALOGEX 0, 0, 260, 104
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_SYSMENU
STYLE DS_SETFONT | DS_CONTROL | WS_CHILD | WS_SYSMENU
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LTEXT "Once in drawing mode, type 't' to enter typing mode or shift+'t' to enter typing mode with right-aligned input. Exit typing mode by pressing escape or the left mouse button. Use the mouse wheel or up and down arrow keys to change the font size.",IDC_STATIC,7,7,246,32
LTEXT "The text color is the current drawing color.",IDC_STATIC,7,47,211,9
LTEXT "Once in drawing mode, type 't' to enter typing mode or shift+'t' to enter typing mode with right-aligned input. Exit typing mode by pressing escape or the left mouse button. Use the mouse wheel or up and down arrow keys to change the font size.",IDC_STATIC,7,7,230,32
LTEXT "The text color is the current drawing color.",IDC_STATIC,7,47,230,9
PUSHBUTTON "&Font",IDC_FONT,112,69,41,14
GROUPBOX "Text Font",IDC_TEXT_FONT,8,61,99,28
GROUPBOX "Sample",IDC_TEXT_FONT,8,61,99,28
END
BREAK DIALOGEX 0, 0, 260, 123
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_SYSMENU
STYLE DS_SETFONT | DS_CONTROL | WS_CHILD | WS_SYSMENU
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "",IDC_BREAK_HOTKEY,"msctls_hotkey32",WS_BORDER | WS_TABSTOP,52,67,80,12
EDITTEXT IDC_TIMER,31,86,31,13,ES_RIGHT | ES_AUTOHSCROLL | ES_NUMBER
CONTROL "",IDC_SPIN_TIMER,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | UDS_NOTHOUSANDS,45,86,11,12
LTEXT "minutes",IDC_STATIC,67,88,25,8
PUSHBUTTON "&Advanced",IDC_ADVANCED_BREAK,212,102,41,14
LTEXT "Enter timer mode by using the ZoomIt tray icon's Break menu item. Increase and decrease time with the arrow keys. If you Alt-Tab away from the timer window, reactivate it by left-clicking on the ZoomIt tray icon. Exit timer mode with Escape. ",IDC_STATIC,7,7,246,33
EDITTEXT IDC_TIMER,52,86,31,13,ES_RIGHT | ES_AUTOHSCROLL | ES_NUMBER
CONTROL "",IDC_SPIN_TIMER,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | UDS_NOTHOUSANDS,66,86,11,12
LTEXT "minutes",IDC_STATIC,88,88,25,8
PUSHBUTTON "&Advanced",IDC_ADVANCED_BREAK,192,102,41,14
LTEXT "Enter timer mode by using the ZoomIt tray icon's Break menu item. Increase and decrease time with the arrow keys. If you Alt-Tab away from the timer window, reactivate it by left-clicking on the ZoomIt tray icon. Exit timer mode with Escape. ",IDC_STATIC,7,7,230,33
LTEXT "Start Timer:",IDC_STATIC,7,70,39,8
LTEXT "Timer:",IDC_STATIC,7,88,20,8
LTEXT "Change the break timer color using the same keys that the drawing color. The break timer font is the same as text font.",IDC_STATIC,7,45,219,20
LTEXT "Change the break timer color using the same keys that the drawing color. The break timer font is the same as text font.",IDC_STATIC,7,45,230,20
CONTROL "Show Time Elapsed After Expiration:",IDC_CHECK_SHOW_EXPIRED,
"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,8,104,132,10
END
@@ -251,69 +250,90 @@ BEGIN
END
LIVEZOOM DIALOGEX 0, 0, 260, 134
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_SYSMENU
STYLE DS_SETFONT | DS_CONTROL | WS_CHILD | WS_SYSMENU
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "",IDC_LIVE_HOTKEY,"msctls_hotkey32",WS_BORDER | WS_TABSTOP,69,108,80,12
LTEXT "LiveZoom mode is supported on Windows 7 and higher where window updates show while zoomed. ",IDC_STATIC,7,7,246,18
LTEXT "LiveZoom mode is supported on Windows 7 and higher where window updates show while zoomed. ",IDC_STATIC,7,7,230,18
LTEXT "LiveZoom Toggle:",IDC_STATIC,7,110,62,8
LTEXT "To enter and exit LiveZoom, enter the hotkey specified below.",IDC_STATIC,7,94,218,13
LTEXT "Note that in LiveZoom you must use Ctrl+Up and Ctrl+Down to control the zoom level. To enter drawing mode, use the standard zoom-without-draw hotkey and then escape to go back to LiveZoom.",IDC_STATIC,7,30,246,27
LTEXT "Use LiveDraw to draw and annotate the live desktop. To activate LiveDraw, enter the hotkey with the Shift key in the opposite mode. You can remove LiveDraw annotations by activating LiveDraw and enter the escape key",IDC_STATIC,7,62,246,32
LTEXT "To enter and exit LiveZoom, enter the hotkey specified below.",IDC_STATIC,7,94,230,13
LTEXT "Note that in LiveZoom you must use Ctrl+Up and Ctrl+Down to control the zoom level. To enter drawing mode, use the standard zoom-without-draw hotkey and then escape to go back to LiveZoom.",IDC_STATIC,7,30,230,27
LTEXT "Use LiveDraw to draw and annotate the live desktop. To activate LiveDraw, enter the hotkey with the Shift key in the opposite mode. You can remove LiveDraw annotations by activating LiveDraw and enter the escape key",IDC_STATIC,7,62,230,32
END
RECORD DIALOGEX 0, 0, 260, 169
RECORD DIALOGEX 0, 0, 260, 181
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_SYSMENU
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "",IDC_RECORD_HOTKEY,"msctls_hotkey32",WS_BORDER | WS_TABSTOP,61,96,80,12
LTEXT "Record Toggle:",IDC_STATIC,7,98,54,8
LTEXT "Record video of the unzoomed live screen or a static zoomed session by entering the recording hot key and finish the recording by entering it again. ",IDC_STATIC,7,7,246,28
LTEXT "Note: Recording is only available on Windows 10 (version 1903) and higher.",IDC_STATIC,7,77,246,19
LTEXT "Record video of the unzoomed live screen or a static zoomed session by entering the recording hot key and finish the recording by entering it again. ",IDC_STATIC,7,7,248,28
LTEXT "Note: Recording is only available on Windows 10 (version 1903) and higher.",IDC_STATIC,7,77,249,19
LTEXT "Scaling:",IDC_STATIC,30,115,26,8
COMBOBOX IDC_RECORD_SCALING,61,114,26,30,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_OEMCONVERT | CBS_SORT | WS_VSCROLL | WS_TABSTOP
LTEXT "Format:",IDC_STATIC,30,132,26,8
COMBOBOX IDC_RECORD_FORMAT,61,131,60,30,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_OEMCONVERT | WS_VSCROLL | WS_TABSTOP
LTEXT "Frame Rate:",IDC_STATIC,119,115,44,8,NOT WS_VISIBLE
COMBOBOX IDC_RECORD_FRAME_RATE,166,114,42,30,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_OEMCONVERT | CBS_SORT | NOT WS_VISIBLE | WS_VSCROLL | WS_TABSTOP
LTEXT "To crop the portion of the screen that will be recorded, enter the hotkey with the Shift key in the opposite mode. ",IDC_STATIC,7,32,246,19
LTEXT "To record a specific window, enter the hotkey with the Alt key in the opposite mode.",IDC_STATIC,7,55,246,19
CONTROL "&Capture audio input:",IDC_CAPTURE_AUDIO,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,7,149,83,10
COMBOBOX IDC_MICROPHONE,81,164,172,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Microphone:",IDC_STATIC,32,166,47,8
LTEXT "To crop the portion of the screen that will be recorded, enter the hotkey with the Shift key in the opposite mode. ",IDC_STATIC,7,35,245,19
LTEXT "To record a specific window, enter the hotkey with the Alt key in the opposite mode.",IDC_STATIC,7,55,251,19
CONTROL "Capture &system audio",IDC_CAPTURE_SYSTEM_AUDIO,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,7,149,83,10
CONTROL "&Capture audio input:",IDC_CAPTURE_AUDIO,"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,7,161,83,10
COMBOBOX IDC_MICROPHONE,81,176,152,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Microphone:",IDC_MICROPHONE_LABEL,32,178,47,8
END
SNIP DIALOGEX 0, 0, 260, 68
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_CLIPSIBLINGS | WS_SYSMENU
STYLE DS_SETFONT | DS_CONTROL | WS_CHILD | WS_CLIPSIBLINGS | WS_SYSMENU
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "",IDC_SNIP_HOTKEY,"msctls_hotkey32",WS_BORDER | WS_TABSTOP,55,32,80,12
LTEXT "Snip Toggle:",IDC_STATIC,7,33,45,8
LTEXT "Copy a region of the screen to the clipboard or enter the hotkey with the Shift key in the opposite mode to save it to a file. ",IDC_STATIC,7,7,246,19
LTEXT "Copy a region of the screen to the clipboard or enter the hotkey with the Shift key in the opposite mode to save it to a file. ",IDC_STATIC,7,7,230,19
END
DEMOTYPE DIALOGEX 0, 0, 259, 249
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_CLIPSIBLINGS | WS_SYSMENU
DEMOTYPE DIALOGEX 0, 0, 260, 249
STYLE DS_SETFONT | DS_CONTROL | WS_CHILD | WS_CLIPSIBLINGS | WS_SYSMENU
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "",IDC_DEMOTYPE_HOTKEY,"msctls_hotkey32",WS_BORDER | WS_TABSTOP,74,154,80,12
LTEXT "DemoType toggle:",IDC_STATIC,7,157,63,8
PUSHBUTTON "&...",IDC_DEMOTYPE_BROWSE,231,137,16,13
PUSHBUTTON "&...",IDC_DEMOTYPE_BROWSE,211,137,16,13
CONTROL "",IDC_DEMOTYPE_SPEED_SLIDER,"msctls_trackbar32",TBS_AUTOTICKS | TBS_BOTH | TBS_NOTICKS | WS_TABSTOP,52,202,150,11,WS_EX_TRANSPARENT
CONTROL "Drive input with typing:",IDC_DEMOTYPE_USER_DRIVEN,
"Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,7,173,88,10
LTEXT "DemoType typing speed:",IDC_STATIC,7,189,215,10
LTEXT "DemoType typing speed:",IDC_STATIC,7,189,230,10
LTEXT "Slow",IDC_DEMOTYPE_STATIC1,51,213,18,8
LTEXT "Fast",IDC_DEMOTYPE_STATIC2,186,213,17,8
EDITTEXT IDC_DEMOTYPE_FILE,44,137,187,12,ES_AUTOHSCROLL | ES_READONLY
EDITTEXT IDC_DEMOTYPE_FILE,44,137,167,12,ES_AUTOHSCROLL | ES_READONLY
LTEXT "Input file:",IDC_STATIC,7,139,32,8
LTEXT "When you reach the end of the file, ZoomIt will reload the file and start at the beginning. Enter the hotkey with the Shift key in the opposite mode to step back to the last [end].",IDC_STATIC,7,108,248,24
LTEXT "DemoType has ZoomIt type text specified in the input file when you enter the DemoType toggle. Simply separate snippets with the [end] keyword, or you can insert text from the clipboard if it is prefixed with the [start].",IDC_STATIC,7,7,248,24
LTEXT " - Insert pauses with the [pause:n] keyword where 'n' is seconds. ",IDC_STATIC,19,34,212,11
LTEXT "You can have ZoomIt send text automatically, or select the option to drive input with typing. ZoomIt will block keyboard input while sending output.",IDC_STATIC,7,68,248,16
LTEXT "When driving input, hit the space bar to unblock keyboard input at the end of a snippet. In auto mode, control will be returned upon completion.",IDC_STATIC,7,88,248,16
LTEXT "- Send text via the clipboard with [paste] and [/paste]. ",IDC_STATIC,23,45,178,8
LTEXT "- Send keystrokes with [enter], [up], [down], [left], and [right].",IDC_STATIC,23,56,211,8
LTEXT "When you reach the end of the file, ZoomIt will reload the file and start at the beginning. Enter the hotkey with the Shift key in the opposite mode to step back to the last [end].",IDC_STATIC,7,108,230,24
LTEXT "DemoType has ZoomIt type text specified in the input file when you enter the DemoType toggle. Simply separate snippets with the [end] keyword, or you can insert text from the clipboard if it is prefixed with the [start].",IDC_STATIC,7,7,230,24
LTEXT " - Insert pauses with the [pause:n] keyword where 'n' is seconds. ",IDC_STATIC,19,34,218,11
LTEXT "You can have ZoomIt send text automatically, or select the option to drive input with typing. ZoomIt will block keyboard input while sending output.",IDC_STATIC,7,68,230,16
LTEXT "When driving input, hit the space bar to unblock keyboard input at the end of a snippet. In auto mode, control will be returned upon completion.",IDC_STATIC,7,88,230,16
LTEXT "- Send text via the clipboard with [paste] and [/paste]. ",IDC_STATIC,23,45,210,8
LTEXT "- Send keystrokes with [enter], [up], [down], [left], and [right].",IDC_STATIC,23,56,210,8
END
IDD_VIDEO_TRIM DIALOGEX 0, 0, 521, 380
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "ZoomIt Video Trim"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LTEXT "",IDC_TRIM_DURATION_LABEL,12,267,160,8
CONTROL "",IDC_TRIM_PREVIEW,"Static",SS_OWNERDRAW | SS_NOTIFY,12,12,498,244
CTEXT "00:00.000",IDC_TRIM_POSITION_LABEL,155,267,200,8
CONTROL "",IDC_TRIM_TIMELINE,"Static",SS_OWNERDRAW | SS_NOTIFY,11,277,498,47,WS_EX_TRANSPARENT
CONTROL "",IDC_TRIM_SKIP_START,"Button",BS_OWNERDRAW | WS_TABSTOP,183,327,30,26
CONTROL "",IDC_TRIM_REWIND,"Button",BS_OWNERDRAW | WS_TABSTOP,215,327,30,26
CONTROL "",IDC_TRIM_PLAY_PAUSE,"Button",BS_OWNERDRAW | WS_TABSTOP,247,325,44,32
CONTROL "",IDC_TRIM_FORWARD,"Button",BS_OWNERDRAW | WS_TABSTOP,293,327,30,26
CONTROL "",IDC_TRIM_SKIP_END,"Button",BS_OWNERDRAW | WS_TABSTOP,325,327,30,26
CONTROL "",IDC_TRIM_VOLUME_ICON,"Static",SS_OWNERDRAW | SS_NOTIFY,365,334,14,12
CONTROL "",IDC_TRIM_VOLUME,"msctls_trackbar32",TBS_NOTICKS | WS_TABSTOP,380,333,70,14
DEFPUSHBUTTON "OK",IDOK,404,358,50,14
PUSHBUTTON "Cancel",IDCANCEL,458,358,50,14
END
@@ -327,7 +347,7 @@ GUIDELINES DESIGNINFO
BEGIN
"OPTIONS", DIALOG
BEGIN
RIGHTMARGIN, 273
RIGHTMARGIN, 293
BOTTOMMARGIN, 320
END
@@ -340,7 +360,6 @@ BEGIN
"ZOOM", DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 253
TOPMARGIN, 7
BOTTOMMARGIN, 151
END
@@ -348,7 +367,6 @@ BEGIN
"DRAW", DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 253
TOPMARGIN, 7
BOTTOMMARGIN, 221
END
@@ -356,7 +374,6 @@ BEGIN
"TYPE", DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 253
TOPMARGIN, 7
BOTTOMMARGIN, 97
END
@@ -364,7 +381,6 @@ BEGIN
"BREAK", DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 253
TOPMARGIN, 7
BOTTOMMARGIN, 116
END
@@ -378,7 +394,6 @@ BEGIN
"LIVEZOOM", DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 253
TOPMARGIN, 7
BOTTOMMARGIN, 127
END
@@ -386,7 +401,6 @@ BEGIN
"RECORD", DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 253
TOPMARGIN, 7
BOTTOMMARGIN, 164
END
@@ -394,7 +408,6 @@ BEGIN
"SNIP", DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 253
TOPMARGIN, 7
BOTTOMMARGIN, 61
END
@@ -402,10 +415,13 @@ BEGIN
"DEMOTYPE", DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 255
TOPMARGIN, 7
BOTTOMMARGIN, 205
END
IDD_VIDEO_TRIM, DIALOG
BEGIN
END
END
#endif // APSTUDIO_INVOKED
@@ -474,6 +490,11 @@ BEGIN
0
END
IDD_VIDEO_TRIM AFX_DIALOG_LAYOUT
BEGIN
0
END
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////

View File

@@ -216,6 +216,14 @@
<MultiProcessorCompilation Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</MultiProcessorCompilation>
<MultiProcessorCompilation Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</MultiProcessorCompilation>
</ClCompile>
<ClCompile Include="LoopbackCapture.cpp">
<MultiProcessorCompilation Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</MultiProcessorCompilation>
<MultiProcessorCompilation Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</MultiProcessorCompilation>
<MultiProcessorCompilation Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">false</MultiProcessorCompilation>
<MultiProcessorCompilation Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">false</MultiProcessorCompilation>
<MultiProcessorCompilation Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</MultiProcessorCompilation>
<MultiProcessorCompilation Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</MultiProcessorCompilation>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\common\sysinternals\dll.c">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
@@ -293,6 +301,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="AudioSampleGenerator.h" />
<ClInclude Include="LoopbackCapture.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\common\sysinternals\Eula\Eula.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\ZoomItModuleInterface\Trace.h" />
<ClInclude Include="GifRecordingSession.h" />

View File

@@ -33,6 +33,9 @@
<ClCompile Include="AudioSampleGenerator.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="LoopbackCapture.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DemoType.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -80,6 +83,9 @@
<ClInclude Include="AudioSampleGenerator.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="LoopbackCapture.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DemoType.h">
<Filter>Header Files</Filter>
</ClInclude>

View File

@@ -49,8 +49,15 @@ DWORD g_RecordScaling = 100;
DWORD g_RecordScalingGIF = 50;
DWORD g_RecordScalingMP4 = 100;
RecordingFormat g_RecordingFormat = RecordingFormat::MP4;
BOOLEAN g_CaptureSystemAudio = TRUE;
BOOLEAN g_CaptureAudio = FALSE;
TCHAR g_MicrophoneDeviceId[MAX_PATH] = {0};
TCHAR g_RecordingSaveLocationBuffer[MAX_PATH] = {0};
TCHAR g_ScreenshotSaveLocationBuffer[MAX_PATH] = {0};
DWORD g_ThemeOverride = 2; // 0=light, 1=dark, 2=system default
DWORD g_TrimDialogWidth = 0; // 0 means use default; stored in screen pixels
DWORD g_TrimDialogHeight = 0; // 0 means use default; stored in screen pixels
DWORD g_TrimDialogVolume = 70; // 0-100 volume level for trim dialog preview
REG_SETTING RegSettings[] = {
{ L"ToggleKey", SETTING_TYPE_DWORD, 0, &g_ToggleKey, static_cast<DOUBLE>(g_ToggleKey) },
@@ -91,6 +98,13 @@ REG_SETTING RegSettings[] = {
{ L"RecordScalingGIF", SETTING_TYPE_DWORD, 0, &g_RecordScalingGIF, static_cast<DOUBLE>(g_RecordScalingGIF) },
{ L"RecordScalingMP4", SETTING_TYPE_DWORD, 0, &g_RecordScalingMP4, static_cast<DOUBLE>(g_RecordScalingMP4) },
{ L"CaptureAudio", SETTING_TYPE_BOOLEAN, 0, &g_CaptureAudio, static_cast<DOUBLE>(g_CaptureAudio) },
{ L"CaptureSystemAudio", SETTING_TYPE_BOOLEAN, 0, &g_CaptureSystemAudio, static_cast<DOUBLE>(g_CaptureSystemAudio) },
{ L"MicrophoneDeviceId", SETTING_TYPE_STRING, sizeof(g_MicrophoneDeviceId), g_MicrophoneDeviceId, static_cast<DOUBLE>(0) },
{ L"RecordingSaveLocation", SETTING_TYPE_STRING, sizeof(g_RecordingSaveLocationBuffer), g_RecordingSaveLocationBuffer, static_cast<DOUBLE>(0) },
{ L"ScreenshotSaveLocation", SETTING_TYPE_STRING, sizeof(g_ScreenshotSaveLocationBuffer), g_ScreenshotSaveLocationBuffer, static_cast<DOUBLE>(0) },
{ L"Theme", SETTING_TYPE_DWORD, 0, &g_ThemeOverride, static_cast<DOUBLE>(g_ThemeOverride) },
{ L"TrimDialogWidth", SETTING_TYPE_DWORD, 0, &g_TrimDialogWidth, static_cast<DOUBLE>(0) },
{ L"TrimDialogHeight", SETTING_TYPE_DWORD, 0, &g_TrimDialogHeight, static_cast<DOUBLE>(0) },
{ L"TrimDialogVolume", SETTING_TYPE_DWORD, 0, &g_TrimDialogVolume, static_cast<DOUBLE>(g_TrimDialogVolume) },
{ NULL, SETTING_TYPE_DWORD, 0, NULL, static_cast<DOUBLE>(0) }
};

File diff suppressed because it is too large Load Diff

View File

@@ -7,8 +7,10 @@
#include <shlobj.h>
#include <tchar.h>
#include <wincodec.h>
#include <shcore.h>
#include <magnification.h>
#include <Uxtheme.h>
#include <vssym32.h>
#include <math.h>
#include <shellapi.h>
#include <shlwapi.h>
@@ -41,12 +43,15 @@
#include <winrt/Windows.Graphics.DirectX.Direct3d11.h>
#include <winrt/Windows.Media.h>
#include <winrt/Windows.Media.Core.h>
#include <winrt/Windows.Media.Editing.h>
#include <winrt/Windows.Media.Playback.h>
#include <winrt/Windows.Media.Transcoding.h>
#include <winrt/Windows.Media.MediaProperties.h>
#include <winrt/Windows.Media.Devices.h>
#include <winrt/Windows.Storage.h>
#include <winrt/Windows.Storage.Streams.h>
#include <winrt/Windows.Storage.Pickers.h>
#include <winrt/Windows.Storage.FileProperties.h>
#include <winrt/Windows.Devices.Enumeration.h>
#include <filesystem>
@@ -69,6 +74,9 @@
#include <d3d11_4.h>
#include <dxgi1_6.h>
#include <d2d1_3.h>
#include <mfapi.h>
#include <mfidl.h>
#include <mfreadwrite.h>
// STL

View File

@@ -12,6 +12,7 @@
// Non-localizable
//////////////////////////////
#define IDC_AUDIO 117
#define IDD_VIDEO_TRIM 119
#define IDC_LINK 1000
#define IDC_ALT 1001
#define IDC_CTRL 1002
@@ -94,9 +95,22 @@
#define IDC_DEMOTYPE_STATIC2 1074
#define IDC_COPYRIGHT 1075
#define IDC_RECORD_FORMAT 1076
#define IDC_TRIM_POSITION_LABEL 1087
#define IDC_TRIM_PREVIEW 1088
#define IDC_TRIM_TIMELINE 1089
#define IDC_TRIM_PLAY_PAUSE 1090
#define IDC_TRIM_REWIND 1091
#define IDC_TRIM_FORWARD 1092
#define IDC_TRIM_DURATION_LABEL 1094
#define IDC_TRIM_SKIP_START 1095
#define IDC_TRIM_SKIP_END 1096
#define IDC_TRIM_VOLUME 1097
#define IDC_TRIM_VOLUME_ICON 1098
#define IDC_PEN_WIDTH 1105
#define IDC_TIMER 1106
#define IDC_SMOOTH_IMAGE 1107
#define IDC_CAPTURE_SYSTEM_AUDIO 1108
#define IDC_MICROPHONE_LABEL 1109
#define IDC_SAVE 40002
#define IDC_COPY 40004
#define IDC_RECORD 40006
@@ -109,9 +123,9 @@
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 118
#define _APS_NEXT_RESOURCE_VALUE 120
#define _APS_NEXT_COMMAND_VALUE 40013
#define _APS_NEXT_CONTROL_VALUE 1078
#define _APS_NEXT_CONTROL_VALUE 1099
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@@ -7,3 +7,4 @@ using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Interoperability", "CsWinRT1028: Class should be marked partial", Justification = "CsWin32 generated code; not used across WinRT boundary", Scope = "type", Target = "~T:Windows.Win32.DestroyMenuSafeHandle")]
[assembly: SuppressMessage("Interoperability", "CsWinRT1028: Class should be marked partial", Justification = "CsWin32 generated code; not used across WinRT boundary", Scope = "type", Target = "~T:Windows.Win32.FreeLibrarySafeHandle")]
[assembly: SuppressMessage("Interoperability", "CsWinRT1028: Class should be marked partial", Justification = "CsWin32 generated code; not used across WinRT boundary", Scope = "type", Target = "~T:Windows.Win32.UnhookWindowsHookExSafeHandle")]
[assembly: SuppressMessage("Interoperability", "CsWinRT1028: Class should be marked partial", Justification = "CsWin32 generated code; not used across WinRT boundary", Scope = "type", Target = "~T:Windows.Win32.DeleteObjectSafeHandle")]

View File

@@ -1,33 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Text.Json.Serialization;
namespace PowerDisplay.Common.Models
{
/// <summary>
/// Represents a custom name mapping for a VCP code value.
/// Used to override the default VCP value names with user-defined names.
/// </summary>
public class CustomVcpValueMapping
{
/// <summary>
/// Gets or sets the VCP code (e.g., 0x14 for color temperature, 0x60 for input source).
/// </summary>
[JsonPropertyName("vcpCode")]
public byte VcpCode { get; set; }
/// <summary>
/// Gets or sets the VCP value to map (e.g., 0x11 for HDMI-1).
/// </summary>
[JsonPropertyName("value")]
public int Value { get; set; }
/// <summary>
/// Gets or sets the custom name to display instead of the default name.
/// </summary>
[JsonPropertyName("customName")]
public string CustomName { get; set; } = string.Empty;
}
}

View File

@@ -3,8 +3,6 @@
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Linq;
using PowerDisplay.Common.Models;
namespace PowerDisplay.Common.Utils
{
@@ -426,49 +424,5 @@ namespace PowerDisplay.Common.Utils
return $"0x{value:X2}";
}
/// <summary>
/// Get human-readable name for a VCP value with custom mapping support.
/// Custom mappings take priority over built-in mappings.
/// </summary>
/// <param name="vcpCode">VCP code (e.g., 0x14)</param>
/// <param name="value">Value to translate</param>
/// <param name="customMappings">Optional custom mappings that take priority</param>
/// <returns>Name string like "sRGB" or null if unknown</returns>
public static string? GetValueName(byte vcpCode, int value, IEnumerable<CustomVcpValueMapping>? customMappings)
{
// 1. Priority: Check custom mappings first
if (customMappings != null)
{
var custom = customMappings.FirstOrDefault(m =>
m.VcpCode == vcpCode && m.Value == value);
if (custom != null && !string.IsNullOrEmpty(custom.CustomName))
{
return custom.CustomName;
}
}
// 2. Fallback to built-in mappings
return GetValueName(vcpCode, value);
}
/// <summary>
/// Get formatted display name for a VCP value with custom mapping support.
/// Custom mappings take priority over built-in mappings.
/// </summary>
/// <param name="vcpCode">VCP code (e.g., 0x14)</param>
/// <param name="value">Value to translate</param>
/// <param name="customMappings">Optional custom mappings that take priority</param>
/// <returns>Formatted string like "sRGB (0x01)" or "0x01" if unknown</returns>
public static string GetFormattedValueName(byte vcpCode, int value, IEnumerable<CustomVcpValueMapping>? customMappings)
{
var name = GetValueName(vcpCode, value, customMappings);
if (name != null)
{
return $"{name} (0x{value:X2})";
}
return $"0x{value:X2}";
}
}
}

View File

@@ -125,27 +125,14 @@ namespace PowerDisplay
/// <summary>
/// Called when an existing instance is activated by another process.
/// This happens when Quick Access or other launchers start the process while one is already running.
/// We toggle the window to show it - this allows Quick Access launch to work properly.
/// This happens when EnsureProcessRunning() launches a new process while one is already running.
/// We intentionally don't show the window here - window visibility should only be controlled via:
/// - Toggle event (hotkey, tray icon click, Settings UI Launch button)
/// - Standalone mode startup (handled in OnLaunched)
/// </summary>
private static void OnActivated(object? sender, AppActivationArguments args)
{
Logger.LogInfo("OnActivated: Redirect activation received - toggling window");
// Toggle the main window on redirect activation
if (_app?.MainWindow is MainWindow mainWindow)
{
// Dispatch to UI thread since OnActivated may be called from a different thread
mainWindow.DispatcherQueue.TryEnqueue(() =>
{
Logger.LogTrace("OnActivated: Toggling window from redirect activation");
mainWindow.ToggleWindow();
});
}
else
{
Logger.LogWarning("OnActivated: MainWindow not available for toggle");
}
Logger.LogInfo("OnActivated: Redirect activation received - window visibility unchanged");
}
}
}

View File

@@ -304,8 +304,7 @@ public partial class MainViewModel
}
/// <summary>
/// Apply feature visibility settings to a monitor ViewModel.
/// Only shows features that are both enabled by user AND supported by hardware.
/// Apply feature visibility settings to a monitor ViewModel
/// </summary>
private void ApplyFeatureVisibility(MonitorViewModel monitorVm, PowerDisplaySettings settings)
{
@@ -314,13 +313,12 @@ public partial class MainViewModel
if (monitorSettings != null)
{
// Only show features that are both enabled by user AND supported by hardware
monitorVm.ShowContrast = monitorSettings.EnableContrast && monitorVm.SupportsContrast;
monitorVm.ShowVolume = monitorSettings.EnableVolume && monitorVm.SupportsVolume;
monitorVm.ShowInputSource = monitorSettings.EnableInputSource && monitorVm.SupportsInputSource;
monitorVm.ShowContrast = monitorSettings.EnableContrast;
monitorVm.ShowVolume = monitorSettings.EnableVolume;
monitorVm.ShowInputSource = monitorSettings.EnableInputSource;
monitorVm.ShowRotation = monitorSettings.EnableRotation;
monitorVm.ShowColorTemperature = monitorSettings.EnableColorTemperature && monitorVm.SupportsColorTemperature;
monitorVm.ShowPowerState = monitorSettings.EnablePowerState && monitorVm.SupportsPowerState;
monitorVm.ShowColorTemperature = monitorSettings.EnableColorTemperature;
monitorVm.ShowPowerState = monitorSettings.EnablePowerState;
}
}

View File

@@ -163,23 +163,6 @@ public partial class MainViewModel : INotifyPropertyChanged, IDisposable
}
}
// Custom VCP mappings - loaded from settings
private List<Common.Models.CustomVcpValueMapping> _customVcpMappings = new();
/// <summary>
/// Gets or sets the custom VCP value name mappings.
/// These mappings override the default VCP value names for color temperature and input source.
/// </summary>
public List<Common.Models.CustomVcpValueMapping> CustomVcpMappings
{
get => _customVcpMappings;
set
{
_customVcpMappings = value ?? new List<Common.Models.CustomVcpValueMapping>();
OnPropertyChanged();
}
}
public bool IsScanning
{
get => _isScanning;
@@ -406,23 +389,6 @@ public partial class MainViewModel : INotifyPropertyChanged, IDisposable
var settings = _settingsUtils.GetSettingsOrDefault<PowerDisplaySettings>(PowerDisplaySettings.ModuleName);
ShowProfileSwitcher = settings.Properties.ShowProfileSwitcher;
ShowIdentifyMonitorsButton = settings.Properties.ShowIdentifyMonitorsButton;
// Load custom VCP mappings (convert from Settings.UI.Library type to PowerDisplay.Common.Models type)
var uiMappings = settings.Properties.CustomVcpMappings;
if (uiMappings != null && uiMappings.Count > 0)
{
CustomVcpMappings = uiMappings.Select(m => new Common.Models.CustomVcpValueMapping
{
VcpCode = m.VcpCode,
Value = m.Value,
CustomName = m.CustomName,
}).ToList();
Logger.LogInfo($"[Settings] Loaded {CustomVcpMappings.Count} custom VCP mappings");
}
else
{
CustomVcpMappings = new List<Common.Models.CustomVcpValueMapping>();
}
}
catch (Exception ex)
{

View File

@@ -279,16 +279,6 @@ public partial class MonitorViewModel : INotifyPropertyChanged, IDisposable
// Advanced control display logic
public bool HasAdvancedControls => ShowContrast || ShowVolume;
/// <summary>
/// Gets a value indicating whether this monitor supports contrast control via VCP 0x12
/// </summary>
public bool SupportsContrast => _monitor.SupportsContrast;
/// <summary>
/// Gets a value indicating whether this monitor supports volume control via VCP 0x62
/// </summary>
public bool SupportsVolume => _monitor.SupportsVolume;
public bool ShowContrast
{
get => _showContrast;
@@ -466,10 +456,8 @@ public partial class MonitorViewModel : INotifyPropertyChanged, IDisposable
/// <summary>
/// Gets human-readable color temperature preset name (e.g., "6500K", "sRGB")
/// Uses custom mappings if available, otherwise falls back to built-in names.
/// </summary>
public string ColorTemperaturePresetName =>
Common.Utils.VcpNames.GetFormattedValueName(0x14, _monitor.CurrentColorTemperature, _mainViewModel?.CustomVcpMappings);
public string ColorTemperaturePresetName => _monitor.ColorTemperaturePresetName;
/// <summary>
/// Gets a value indicating whether this monitor supports color temperature via VCP 0x14
@@ -549,7 +537,7 @@ public partial class MonitorViewModel : INotifyPropertyChanged, IDisposable
_availableColorPresets = presetValues.Select(value => new ColorTemperatureItem
{
VcpValue = value,
DisplayName = Common.Utils.VcpNames.GetFormattedValueName(0x14, value, _mainViewModel?.CustomVcpMappings),
DisplayName = Common.Utils.VcpNames.GetFormattedValueName(0x14, value),
IsSelected = value == _monitor.CurrentColorTemperature,
MonitorId = _monitor.Id,
}).ToList();
@@ -569,11 +557,8 @@ public partial class MonitorViewModel : INotifyPropertyChanged, IDisposable
/// <summary>
/// Gets human-readable current input source name (e.g., "HDMI-1", "DisplayPort-1")
/// Uses custom mappings if available, otherwise falls back to built-in names.
/// </summary>
public string CurrentInputSourceName =>
Common.Utils.VcpNames.GetValueName(0x60, _monitor.CurrentInputSource, _mainViewModel?.CustomVcpMappings)
?? $"Source 0x{_monitor.CurrentInputSource:X2}";
public string CurrentInputSourceName => _monitor.InputSourceName;
private List<InputSourceItem>? _availableInputSources;
@@ -608,7 +593,7 @@ public partial class MonitorViewModel : INotifyPropertyChanged, IDisposable
_availableInputSources = supportedSources.Select(value => new InputSourceItem
{
Value = value,
Name = Common.Utils.VcpNames.GetValueName(0x60, value, _mainViewModel?.CustomVcpMappings) ?? $"Source 0x{value:X2}",
Name = Common.Utils.VcpNames.GetValueName(0x60, value) ?? $"Source 0x{value:X2}",
SelectionVisibility = value == _monitor.CurrentInputSource ? Visibility.Visible : Visibility.Collapsed,
MonitorId = _monitor.Id,
}).ToList();

View File

@@ -52,11 +52,8 @@ void PowerDisplayProcessManager::send_message(const std::wstring& message_type,
{
submit_task([this, message_type, message_arg] {
// Ensure process is running before sending message
// If process is not running, enable and start it - this allows Quick Access launch
// to work even when the module was not previously enabled
if (!is_process_running())
if (!is_process_running() && m_enabled)
{
m_enabled = true;
refresh();
}
send_named_pipe_message(message_type, message_arg);

View File

@@ -9,8 +9,6 @@
#include <common/utils/winapi_error.h>
#include <common/utils/logger_helper.h>
#include <common/utils/resources.h>
#include <thread>
#include <atomic>
#include "resource.h"
@@ -50,11 +48,6 @@ private:
HANDLE m_hRefreshEvent = nullptr;
HANDLE m_hSendSettingsTelemetryEvent = nullptr;
// Toggle event handle and listener thread for Quick Access support
HANDLE m_hToggleEvent = nullptr;
std::thread m_toggleEventThread;
std::atomic<bool> m_toggleEventThreadRunning = false;
public:
PowerDisplayModule()
{
@@ -69,25 +62,16 @@ public:
m_hSendSettingsTelemetryEvent = CreateDefaultEvent(CommonSharedConstants::POWER_DISPLAY_SEND_SETTINGS_TELEMETRY_EVENT);
Logger::trace(L"Created SEND_SETTINGS_TELEMETRY_EVENT: handle={}", reinterpret_cast<void*>(m_hSendSettingsTelemetryEvent));
// Create Toggle event for Quick Access support
// This allows Quick Access to launch PowerDisplay even when module is not enabled
m_hToggleEvent = CreateDefaultEvent(CommonSharedConstants::TOGGLE_POWER_DISPLAY_EVENT);
Logger::trace(L"Created TOGGLE_EVENT: handle={}", reinterpret_cast<void*>(m_hToggleEvent));
if (!m_hRefreshEvent || !m_hSendSettingsTelemetryEvent || !m_hToggleEvent)
if (!m_hRefreshEvent || !m_hSendSettingsTelemetryEvent)
{
Logger::error(L"Failed to create one or more event handles: Refresh={}, SettingsTelemetry={}, Toggle={}",
Logger::error(L"Failed to create one or more event handles: Refresh={}, SettingsTelemetry={}",
reinterpret_cast<void*>(m_hRefreshEvent),
reinterpret_cast<void*>(m_hSendSettingsTelemetryEvent),
reinterpret_cast<void*>(m_hToggleEvent));
reinterpret_cast<void*>(m_hSendSettingsTelemetryEvent));
}
else
{
Logger::info(L"All Windows Events created successfully");
}
// Start toggle event listener thread for Quick Access support
StartToggleEventListener();
}
~PowerDisplayModule()
@@ -97,9 +81,6 @@ public:
disable();
}
// Stop toggle event listener thread
StopToggleEventListener();
// Clean up event handles
if (m_hRefreshEvent)
{
@@ -111,67 +92,6 @@ public:
CloseHandle(m_hSendSettingsTelemetryEvent);
m_hSendSettingsTelemetryEvent = nullptr;
}
if (m_hToggleEvent)
{
CloseHandle(m_hToggleEvent);
m_hToggleEvent = nullptr;
}
}
void StartToggleEventListener()
{
if (m_toggleEventThreadRunning || !m_hToggleEvent)
{
return;
}
m_toggleEventThreadRunning = true;
m_toggleEventThread = std::thread([this]() {
Logger::info(L"Toggle event listener thread started");
while (m_toggleEventThreadRunning)
{
DWORD result = WaitForSingleObject(m_hToggleEvent, 100);
if (result == WAIT_OBJECT_0)
{
Logger::trace(L"Toggle event received");
TogglePowerDisplay();
}
}
Logger::info(L"Toggle event listener thread stopped");
});
}
void StopToggleEventListener()
{
m_toggleEventThreadRunning = false;
if (m_toggleEventThread.joinable())
{
m_toggleEventThread.join();
}
}
/// <summary>
/// Toggle PowerDisplay window visibility.
/// If process is running, launches again to trigger redirect activation (OnActivated handles toggle).
/// If process is not running, starts it via Named Pipe and sends toggle message.
/// </summary>
void TogglePowerDisplay()
{
if (m_processManager.is_running())
{
// Process running - launch to trigger single instance redirect, OnActivated will toggle
SHELLEXECUTEINFOW sei{ sizeof(sei) };
sei.fMask = SEE_MASK_FLAG_NO_UI;
sei.lpFile = L"WinUI3Apps\\PowerToys.PowerDisplay.exe";
sei.nShow = SW_SHOWNORMAL;
ShellExecuteExW(&sei);
}
else
{
// Process not running - start and send toggle via Named Pipe
m_processManager.send_message(CommonSharedConstants::POWER_DISPLAY_TOGGLE_MESSAGE);
}
Trace::ActivatePowerDisplay();
}
virtual void destroy() override
@@ -215,7 +135,10 @@ public:
if (action_object.get_name() == L"Launch")
{
Logger::trace(L"Launch action received");
TogglePowerDisplay();
// Send Toggle message via Named Pipe (will start process if needed)
m_processManager.send_message(CommonSharedConstants::POWER_DISPLAY_TOGGLE_MESSAGE);
Trace::ActivatePowerDisplay();
}
else if (action_object.get_name() == L"RefreshMonitors")
{

View File

@@ -119,13 +119,6 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
eventHandle.Set();
}
return true;
case ModuleType.PowerDisplay:
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.TogglePowerDisplayEvent()))
{
eventHandle.Set();
}
return true;
default:
return false;

View File

@@ -1,58 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Text.Json.Serialization;
using PowerDisplay.Common.Utils;
namespace Microsoft.PowerToys.Settings.UI.Library
{
/// <summary>
/// Represents a custom name mapping for a VCP code value.
/// Used in Settings UI to allow users to define custom names for VCP values.
/// </summary>
public class CustomVcpValueMapping
{
/// <summary>
/// Gets or sets the VCP code (e.g., 0x14 for color temperature, 0x60 for input source).
/// </summary>
[JsonPropertyName("vcpCode")]
public byte VcpCode { get; set; }
/// <summary>
/// Gets or sets the VCP value to map (e.g., 0x11 for HDMI-1).
/// </summary>
[JsonPropertyName("value")]
public int Value { get; set; }
/// <summary>
/// Gets or sets the custom name to display instead of the default name.
/// </summary>
[JsonPropertyName("customName")]
public string CustomName { get; set; } = string.Empty;
/// <summary>
/// Gets the display name for the VCP code (for UI display).
/// </summary>
[JsonIgnore]
public string VcpCodeDisplayName => VcpCode switch
{
0x14 => "Color Temperature",
0x60 => "Input Source",
_ => $"VCP 0x{VcpCode:X2}",
};
/// <summary>
/// Gets the display name for the VCP value (using built-in mapping).
/// </summary>
[JsonIgnore]
public string ValueDisplayName => VcpNames.GetFormattedValueName(VcpCode, Value);
/// <summary>
/// Gets a summary string for display in the UI list.
/// Format: "VcpCodeName: OriginalValue → CustomName"
/// </summary>
[JsonIgnore]
public string DisplaySummary => $"{VcpNames.GetValueName(VcpCode, Value) ?? $"0x{Value:X2}"} → {CustomName}";
}
}

View File

@@ -23,7 +23,6 @@ namespace Microsoft.PowerToys.Settings.UI.Library
ShowSystemTrayIcon = true;
ShowProfileSwitcher = true;
ShowIdentifyMonitorsButton = true;
CustomVcpMappings = new List<CustomVcpValueMapping>();
// Note: saved_monitor_settings has been moved to monitor_state.json
// which is managed separately by PowerDisplay app
@@ -62,12 +61,5 @@ namespace Microsoft.PowerToys.Settings.UI.Library
/// </summary>
[JsonPropertyName("show_identify_monitors_button")]
public bool ShowIdentifyMonitorsButton { get; set; }
/// <summary>
/// Gets or sets custom VCP value name mappings shared across all monitors.
/// Allows users to define custom names for color temperature presets and input sources.
/// </summary>
[JsonPropertyName("custom_vcp_mappings")]
public List<CustomVcpValueMapping> CustomVcpMappings { get; set; }
}
}

View File

@@ -89,6 +89,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library
public StringProperty RecordFormat { get; set; }
public BoolProperty CaptureSystemAudio { get; set; }
public BoolProperty CaptureAudio { get; set; }
public StringProperty MicrophoneDeviceId { get; set; }

View File

@@ -1,56 +0,0 @@
<ContentDialog
x:Class="Microsoft.PowerToys.Settings.UI.Views.CustomVcpMappingEditorDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Width="400"
MinWidth="400"
CloseButtonClick="ContentDialog_CloseButtonClick"
DefaultButton="Primary"
IsPrimaryButtonEnabled="{x:Bind CanSave, Mode=OneWay}"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
Style="{StaticResource DefaultContentDialogStyle}"
mc:Ignorable="d">
<StackPanel MinWidth="350" Spacing="16">
<!-- VCP Code Selection -->
<ComboBox
x:Name="VcpCodeComboBox"
x:Uid="PowerDisplay_CustomMappingEditor_VcpCode"
HorizontalAlignment="Stretch"
SelectionChanged="VcpCodeComboBox_SelectionChanged">
<ComboBoxItem x:Uid="PowerDisplay_CustomMappingEditor_ColorTemperature" Tag="20" />
<ComboBoxItem x:Uid="PowerDisplay_CustomMappingEditor_InputSource" Tag="96" />
</ComboBox>
<!-- Value Selection from monitors -->
<StackPanel Spacing="8">
<ComboBox
x:Name="ValueComboBox"
x:Uid="PowerDisplay_CustomMappingEditor_ValueComboBox"
HorizontalAlignment="Stretch"
DisplayMemberPath="DisplayName"
ItemsSource="{x:Bind AvailableValues, Mode=OneWay}"
SelectedValuePath="Value"
SelectionChanged="ValueComboBox_SelectionChanged" />
<!-- Custom Value Input (shown when "Custom value" is selected) -->
<TextBox
x:Name="CustomValueTextBox"
x:Uid="PowerDisplay_CustomMappingEditor_CustomValueInput"
HorizontalAlignment="Stretch"
PlaceholderText="0x11"
TextChanged="CustomValueTextBox_TextChanged"
Visibility="{x:Bind ShowCustomValueInput, Mode=OneWay}" />
</StackPanel>
<!-- Custom Name Input -->
<TextBox
x:Name="CustomNameTextBox"
x:Uid="PowerDisplay_CustomMappingEditor_CustomName"
HorizontalAlignment="Stretch"
MaxLength="50"
TextChanged="CustomNameTextBox_TextChanged" />
</StackPanel>
</ContentDialog>

View File

@@ -1,413 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using PowerDisplay.Common.Utils;
namespace Microsoft.PowerToys.Settings.UI.Views
{
/// <summary>
/// Dialog for creating/editing custom VCP value name mappings
/// </summary>
public sealed partial class CustomVcpMappingEditorDialog : ContentDialog, INotifyPropertyChanged
{
/// <summary>
/// Special value to indicate "Custom value" option in the ComboBox
/// </summary>
private const int CustomValueMarker = -1;
/// <summary>
/// Represents a selectable VCP value item in the Value ComboBox
/// </summary>
public class VcpValueItem
{
public int Value { get; set; }
public string DisplayName { get; set; } = string.Empty;
public bool IsCustomOption => Value == CustomValueMarker;
}
private readonly IEnumerable<MonitorInfo>? _monitors;
private ObservableCollection<VcpValueItem> _availableValues = new();
private byte _selectedVcpCode;
private int _selectedValue;
private string _customName = string.Empty;
private bool _canSave;
private bool _showCustomValueInput;
private int _customValueParsed;
public CustomVcpMappingEditorDialog()
: this(null)
{
}
public CustomVcpMappingEditorDialog(IEnumerable<MonitorInfo>? monitors)
{
_monitors = monitors;
this.InitializeComponent();
// Set localized strings for ContentDialog
var resourceLoader = ResourceLoaderInstance.ResourceLoader;
Title = resourceLoader.GetString("PowerDisplay_CustomMappingEditor_Title");
PrimaryButtonText = resourceLoader.GetString("PowerDisplay_Dialog_Save");
CloseButtonText = resourceLoader.GetString("PowerDisplay_Dialog_Cancel");
// Default to Color Temperature (0x14)
VcpCodeComboBox.SelectedIndex = 0;
}
/// <summary>
/// Gets the result mapping after dialog closes with Primary button
/// </summary>
public CustomVcpValueMapping? ResultMapping { get; private set; }
/// <summary>
/// Gets the available values for the selected VCP code
/// </summary>
public ObservableCollection<VcpValueItem> AvailableValues
{
get => _availableValues;
private set
{
_availableValues = value;
OnPropertyChanged();
}
}
/// <summary>
/// Gets a value indicating whether the dialog can be saved
/// </summary>
public bool CanSave
{
get => _canSave;
private set
{
if (_canSave != value)
{
_canSave = value;
OnPropertyChanged();
}
}
}
/// <summary>
/// Gets a value indicating whether to show the custom value input TextBox
/// </summary>
public Visibility ShowCustomValueInput
{
get => _showCustomValueInput ? Visibility.Visible : Visibility.Collapsed;
private set
{
var newValue = value == Visibility.Visible;
if (_showCustomValueInput != newValue)
{
_showCustomValueInput = newValue;
OnPropertyChanged();
}
}
}
/// <summary>
/// Pre-fill the dialog with existing mapping data for editing
/// </summary>
public void PreFillMapping(CustomVcpValueMapping mapping)
{
if (mapping == null)
{
return;
}
// Select the VCP code
VcpCodeComboBox.SelectedIndex = mapping.VcpCode == 0x14 ? 0 : 1;
// Populate values for the selected VCP code
PopulateValuesForVcpCode(mapping.VcpCode);
// Try to select the value in the ComboBox
bool foundInList = false;
foreach (var item in AvailableValues)
{
if (!item.IsCustomOption && item.Value == mapping.Value)
{
ValueComboBox.SelectedItem = item;
foundInList = true;
break;
}
}
// If value not found in list, select "Custom value" option and fill the TextBox
if (!foundInList)
{
// Select the "Custom value" option (last item)
var customOption = AvailableValues.FirstOrDefault(v => v.IsCustomOption);
if (customOption != null)
{
ValueComboBox.SelectedItem = customOption;
}
CustomValueTextBox.Text = $"0x{mapping.Value:X2}";
_customValueParsed = mapping.Value;
}
// Set the custom name
CustomNameTextBox.Text = mapping.CustomName;
_customName = mapping.CustomName;
UpdateCanSave();
}
private void VcpCodeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (VcpCodeComboBox.SelectedItem is ComboBoxItem selectedItem &&
selectedItem.Tag is string tagValue &&
byte.TryParse(tagValue, out byte vcpCode))
{
_selectedVcpCode = vcpCode;
PopulateValuesForVcpCode(vcpCode);
UpdateCanSave();
}
}
private void PopulateValuesForVcpCode(byte vcpCode)
{
var values = new ObservableCollection<VcpValueItem>();
var seenValues = new HashSet<int>();
// Collect values from all monitors
if (_monitors != null)
{
foreach (var monitor in _monitors)
{
if (monitor.VcpCodesFormatted == null)
{
continue;
}
// Find the VCP code entry
var vcpEntry = monitor.VcpCodesFormatted.FirstOrDefault(v =>
!string.IsNullOrEmpty(v.Code) &&
TryParseHexCode(v.Code, out int code) &&
code == vcpCode);
if (vcpEntry?.ValueList == null)
{
continue;
}
// Add each value from this monitor
foreach (var valueInfo in vcpEntry.ValueList)
{
if (TryParseHexCode(valueInfo.Value, out int vcpValue) && !seenValues.Contains(vcpValue))
{
seenValues.Add(vcpValue);
var displayName = !string.IsNullOrEmpty(valueInfo.Name)
? $"{valueInfo.Name} (0x{vcpValue:X2})"
: VcpNames.GetFormattedValueName(vcpCode, vcpValue);
values.Add(new VcpValueItem
{
Value = vcpValue,
DisplayName = displayName,
});
}
}
}
}
// If no values found from monitors, fall back to built-in values
if (values.Count == 0)
{
Dictionary<int, string> builtInValues = vcpCode switch
{
0x14 => GetColorTemperatureValues(),
0x60 => GetInputSourceValues(),
_ => new Dictionary<int, string>(),
};
foreach (var kvp in builtInValues)
{
values.Add(new VcpValueItem
{
Value = kvp.Key,
DisplayName = $"{kvp.Value} (0x{kvp.Key:X2})",
});
}
}
// Sort by value
var sortedValues = new ObservableCollection<VcpValueItem>(values.OrderBy(v => v.Value));
// Add "Custom value" option at the end
var resourceLoader = ResourceLoaderInstance.ResourceLoader;
sortedValues.Add(new VcpValueItem
{
Value = CustomValueMarker,
DisplayName = resourceLoader.GetString("PowerDisplay_CustomMappingEditor_CustomValueOption"),
});
AvailableValues = sortedValues;
// Select first item if available
if (sortedValues.Count > 0)
{
ValueComboBox.SelectedIndex = 0;
}
}
private static bool TryParseHexCode(string? hex, out int result)
{
result = 0;
if (string.IsNullOrEmpty(hex))
{
return false;
}
var cleanHex = hex.StartsWith("0x", StringComparison.OrdinalIgnoreCase) ? hex[2..] : hex;
return int.TryParse(cleanHex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out result);
}
private static Dictionary<int, string> GetColorTemperatureValues()
{
return new Dictionary<int, string>
{
{ 0x01, "sRGB" },
{ 0x02, "Display Native" },
{ 0x03, "4000K" },
{ 0x04, "5000K" },
{ 0x05, "6500K" },
{ 0x06, "7500K" },
{ 0x07, "8200K" },
{ 0x08, "9300K" },
{ 0x09, "10000K" },
{ 0x0A, "11500K" },
{ 0x0B, "User 1" },
{ 0x0C, "User 2" },
{ 0x0D, "User 3" },
};
}
private static Dictionary<int, string> GetInputSourceValues()
{
return new Dictionary<int, string>
{
{ 0x01, "VGA-1" },
{ 0x02, "VGA-2" },
{ 0x03, "DVI-1" },
{ 0x04, "DVI-2" },
{ 0x05, "Composite Video 1" },
{ 0x06, "Composite Video 2" },
{ 0x07, "S-Video-1" },
{ 0x08, "S-Video-2" },
{ 0x09, "Tuner-1" },
{ 0x0A, "Tuner-2" },
{ 0x0B, "Tuner-3" },
{ 0x0C, "Component Video 1" },
{ 0x0D, "Component Video 2" },
{ 0x0E, "Component Video 3" },
{ 0x0F, "DisplayPort-1" },
{ 0x10, "DisplayPort-2" },
{ 0x11, "HDMI-1" },
{ 0x12, "HDMI-2" },
{ 0x1B, "USB-C" },
};
}
private void ValueComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (ValueComboBox.SelectedItem is VcpValueItem selectedItem)
{
if (selectedItem.IsCustomOption)
{
// Show custom value input
ShowCustomValueInput = Visibility.Visible;
_selectedValue = 0; // Will be set from TextBox
}
else
{
// Hide custom value input and use selected value
ShowCustomValueInput = Visibility.Collapsed;
_selectedValue = selectedItem.Value;
}
UpdateCanSave();
}
}
private void CustomValueTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
var text = CustomValueTextBox.Text?.Trim() ?? string.Empty;
if (TryParseHexCode(text, out int parsed))
{
_customValueParsed = parsed;
}
else
{
_customValueParsed = 0;
}
UpdateCanSave();
}
private void CustomNameTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
_customName = CustomNameTextBox.Text?.Trim() ?? string.Empty;
UpdateCanSave();
}
private void UpdateCanSave()
{
bool hasValidValue;
if (_showCustomValueInput)
{
hasValidValue = _customValueParsed > 0;
}
else
{
hasValidValue = ValueComboBox.SelectedItem is VcpValueItem item && !item.IsCustomOption;
}
CanSave = _selectedVcpCode > 0 &&
hasValidValue &&
!string.IsNullOrWhiteSpace(_customName);
}
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
if (CanSave)
{
int finalValue = _showCustomValueInput ? _customValueParsed : _selectedValue;
ResultMapping = new CustomVcpValueMapping
{
VcpCode = _selectedVcpCode,
Value = finalValue,
CustomName = _customName,
};
}
}
private void ContentDialog_CloseButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
ResultMapping = null;
}
public event PropertyChangedEventHandler? PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@@ -63,46 +63,6 @@
</tkcontrols:SettingsCard>
</controls:SettingsGroup>
<!-- Custom VCP Name Mappings -->
<controls:SettingsGroup x:Uid="PowerDisplay_CustomVcpMappings_GroupSettings" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
<tkcontrols:SettingsExpander
x:Uid="PowerDisplay_CustomVcpMappings"
HeaderIcon="{ui:FontIcon Glyph=&#xE70F;}"
IsExpanded="True"
ItemsSource="{x:Bind ViewModel.CustomVcpMappings, Mode=OneWay}">
<tkcontrols:SettingsExpander.ItemTemplate>
<DataTemplate x:DataType="library:CustomVcpValueMapping">
<tkcontrols:SettingsCard Description="{x:Bind VcpCodeDisplayName}" Header="{x:Bind DisplaySummary}">
<StackPanel Orientation="Horizontal" Spacing="8">
<Button
Click="EditCustomMapping_Click"
Content="{ui:FontIcon Glyph=&#xE70F;,
FontSize=14}"
Style="{StaticResource SubtleButtonStyle}"
Tag="{x:Bind}"
ToolTipService.ToolTip="Edit" />
<Button
Click="DeleteCustomMapping_Click"
Content="{ui:FontIcon Glyph=&#xE74D;,
FontSize=14}"
Style="{StaticResource SubtleButtonStyle}"
Tag="{x:Bind}"
ToolTipService.ToolTip="Delete" />
</StackPanel>
</tkcontrols:SettingsCard>
</DataTemplate>
</tkcontrols:SettingsExpander.ItemTemplate>
<!-- Add mapping button -->
<Button x:Uid="PowerDisplay_AddCustomMappingButton" Click="AddCustomMapping_Click">
<StackPanel Orientation="Horizontal" Spacing="6">
<FontIcon FontSize="14" Glyph="&#xE710;" />
<TextBlock x:Uid="PowerDisplay_AddCustomMapping_Text" />
</StackPanel>
</Button>
</tkcontrols:SettingsExpander>
</controls:SettingsGroup>
<controls:SettingsGroup x:Uid="PowerDisplay_Profiles_GroupSettings" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
<tkcontrols:SettingsExpander
x:Uid="PowerDisplay_QuickProfiles"

View File

@@ -133,65 +133,6 @@ namespace Microsoft.PowerToys.Settings.UI.Views
return ProfileHelper.GenerateUniqueProfileName(existingNames, baseName);
}
// Custom VCP Mapping event handlers
private async void AddCustomMapping_Click(object sender, RoutedEventArgs e)
{
var dialog = new CustomVcpMappingEditorDialog(ViewModel.Monitors);
dialog.XamlRoot = this.XamlRoot;
var result = await dialog.ShowAsync();
if (result == ContentDialogResult.Primary && dialog.ResultMapping != null)
{
ViewModel.AddCustomVcpMapping(dialog.ResultMapping);
}
}
private async void EditCustomMapping_Click(object sender, RoutedEventArgs e)
{
if (sender is not Button button || button.Tag is not Library.CustomVcpValueMapping mapping)
{
return;
}
var dialog = new CustomVcpMappingEditorDialog(ViewModel.Monitors);
dialog.XamlRoot = this.XamlRoot;
dialog.PreFillMapping(mapping);
var result = await dialog.ShowAsync();
if (result == ContentDialogResult.Primary && dialog.ResultMapping != null)
{
ViewModel.UpdateCustomVcpMapping(mapping, dialog.ResultMapping);
}
}
private async void DeleteCustomMapping_Click(object sender, RoutedEventArgs e)
{
if (sender is not Button button || button.Tag is not Library.CustomVcpValueMapping mapping)
{
return;
}
var resourceLoader = ResourceLoaderInstance.ResourceLoader;
var dialog = new ContentDialog
{
XamlRoot = this.XamlRoot,
Title = resourceLoader.GetString("PowerDisplay_CustomMapping_Delete_Title"),
Content = resourceLoader.GetString("PowerDisplay_CustomMapping_Delete_Message"),
PrimaryButtonText = resourceLoader.GetString("Yes"),
CloseButtonText = resourceLoader.GetString("No"),
DefaultButton = ContentDialogButton.Close,
};
var result = await dialog.ShowAsync();
if (result == ContentDialogResult.Primary)
{
ViewModel.DeleteCustomVcpMapping(mapping);
}
}
// Flag to prevent reentrant handling during programmatic checkbox changes
private bool _isRestoringColorTempCheckbox;

View File

@@ -285,6 +285,9 @@
<ComboBoxItem>MP4</ComboBoxItem>
</ComboBox>
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard Name="ZoomItRecordCaptureSystemAudio" ContentAlignment="Left">
<CheckBox x:Uid="ZoomIt_Record_CaptureSystemAudio" IsChecked="{x:Bind ViewModel.RecordCaptureSystemAudio, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard Name="ZoomItRecordCaptureAudio" ContentAlignment="Left">
<CheckBox x:Uid="ZoomIt_Record_CaptureAudio" IsChecked="{x:Bind ViewModel.RecordCaptureAudio, Mode=TwoWay}" />
</tkcontrols:SettingsCard>

View File

@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
@@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
@@ -4834,9 +4834,9 @@ Activate by holding the key for the character you want to add an accent to, then
<value>Zoom in or out to enlarge content and make details clearer.</value>
</data>
<data name="ZoomIt_ZoomFAQ.Text" xml:space="preserve">
<value>Press **the mouse wheel** or **the Up / Down arrow keys** to zoom in or out.
Press **Esc** or **the right mouse button** to exit zoom mode.
Press **Ctrl + C** to capture the zoomed view, or **Ctrl + S** to save it.
<value>Press **the mouse wheel** or **the Up / Down arrow keys** to zoom in or out.
Press **Esc** or **the right mouse button** to exit zoom mode.
Press **Ctrl + C** to capture the zoomed view, or **Ctrl + S** to save it.
Press **Ctrl + Shift** to crop before copying or saving.</value>
</data>
<data name="ZoomIt_Zoom_Shortcut.Header" xml:space="preserve">
@@ -4864,23 +4864,23 @@ Press **Ctrl + Shift** to crop before copying or saving.</value>
<value>Draw</value>
</data>
<data name="ZoomIt_DrawFAQ.Text" xml:space="preserve">
<value>Press **the left mouse button** to toggle drawing mode when zoomed in, and **the right mouse button** to exit.
<value>Press **the left mouse button** to toggle drawing mode when zoomed in, and **the right mouse button** to exit.
Press **Ctrl + Z** to undo, **E** to clear drawings, and **Space** to center the cursor.
**Pen control**
**Pen control**
Press **Ctrl + the mouse wheel** or **Ctrl + Up / Down** to adjust the pen width.
**Colors**
**Colors**
Press **R** (Red), **G** (Green), **B** (Blue), **O** (Orange), **Y** (Yellow), or **P** (Pink) to switch colors.
**Highlight and blur**
**Highlight and blur**
Press **Shift + a color key** for a translucent highlighter, **X** for blur, or **Shift + X** for a stronger blur.
**Shapes**
**Shapes**
Press **Shift** for a line, **Ctrl** for a rectangle, **Tab** for an ellipse, or **Shift + Ctrl** for an arrow.
**Screen**
Press **W** or **K** for a white or black sketch pad.
**Screen**
Press **W** or **K** for a white or black sketch pad.
Press **Ctrl + C** to copy or **Ctrl + S** to save, and **Ctrl + Shift** to crop.
</value>
</data>
@@ -4907,16 +4907,16 @@ Press **Ctrl + C** to copy or **Ctrl + S** to save, and **Ctrl + Shift** to crop
<value>Insert predefined text snippets with a shortcut using a text file.</value>
</data>
<data name="ZoomIt_DemoTypeFAQ" xml:space="preserve">
<value>Text can be pulled from the clipboard when it starts with **[start]**.
Use **[end]** to separate snippets, **[pause:n]** to insert pauses (in seconds), and **[paste]** / **[/paste]** to send clipboard text.
<value>Text can be pulled from the clipboard when it starts with **[start]**.
Use **[end]** to separate snippets, **[pause:n]** to insert pauses (in seconds), and **[paste]** / **[/paste]** to send clipboard text.
Use **[enter]**, **[up]**, **[down]**, **[left]**, and **[right]** to issue keystrokes.
ZoomIt can send text automatically or run in manual mode. Keyboard input is blocked while text is being sent.
In manual mode, press **Space** to unblock keyboard input at the end of a snippet.
In manual mode, press **Space** to unblock keyboard input at the end of a snippet.
In auto mode, control returns automatically after completion.
At the end of the file, ZoomIt reloads the file and restarts from the beginning.
At the end of the file, ZoomIt reloads the file and restarts from the beginning.
Press the hotkey with **Shift** in the opposite mode to step back to the previous **[end]** marker.
Press **{0}** to reset DemoType and start from the beginning.</value>
@@ -4952,12 +4952,12 @@ Press **{0}** to reset DemoType and start from the beginning.</value>
<value>Displays a countdown overlay for timed breaks or presentations.</value>
</data>
<data name="ZoomIt_BreakFAQ.Text" xml:space="preserve">
<value>Enter timer mode from the ZoomIt tray icons Break menu.
<value>Enter timer mode from the ZoomIt tray icons Break menu.
Press **the arrow keys** to adjust the time. If the timer window loses focus through **Alt + Tab**, press **the left mouse button** on the ZoomIt tray icon to reactivate it.
Press **Esc** to exit timer mode.
Change the break timer color using the same keys as the drawing colors.
Change the break timer color using the same keys as the drawing colors.
The break timer font matches the text font.</value>
</data>
<data name="ZoomIt_Break_Shortcut.Header" xml:space="preserve">
@@ -5098,6 +5098,9 @@ The break timer font matches the text font.</value>
<data name="ZoomIt_Record_Format.Header" xml:space="preserve">
<value>Format</value>
</data>
<data name="ZoomIt_Record_CaptureSystemAudio.Content" xml:space="preserve">
<value>Capture system audio</value>
</data>
<data name="ZoomIt_Record_CaptureAudio.Content" xml:space="preserve">
<value>Capture audio input</value>
</data>
@@ -5992,57 +5995,6 @@ The break timer font matches the text font.</value>
<data name="PowerDisplay_ShowIdentifyMonitorsButton.Description" xml:space="preserve">
<value>Show or hide the identify monitors button in the Power Display flyout</value>
</data>
<data name="PowerDisplay_CustomVcpMappings_GroupSettings.Header" xml:space="preserve">
<value>Custom VCP Name Mappings</value>
</data>
<data name="PowerDisplay_CustomVcpMappings.Header" xml:space="preserve">
<value>Custom name mappings</value>
</data>
<data name="PowerDisplay_CustomVcpMappings.Description" xml:space="preserve">
<value>Define custom display names for color temperature presets and input sources</value>
</data>
<data name="PowerDisplay_AddCustomMappingButton.ToolTipService.ToolTip" xml:space="preserve">
<value>Add custom mapping</value>
</data>
<data name="PowerDisplay_AddCustomMapping_Text.Text" xml:space="preserve">
<value>Add mapping</value>
</data>
<data name="PowerDisplay_CustomMappingEditor_Title" xml:space="preserve">
<value>Custom VCP Name Mapping</value>
</data>
<data name="PowerDisplay_CustomMappingEditor_VcpCode.Header" xml:space="preserve">
<value>VCP Code</value>
</data>
<data name="PowerDisplay_CustomMappingEditor_ColorTemperature.Content" xml:space="preserve">
<value>Color Temperature (0x14)</value>
</data>
<data name="PowerDisplay_CustomMappingEditor_InputSource.Content" xml:space="preserve">
<value>Input Source (0x60)</value>
</data>
<data name="PowerDisplay_CustomMappingEditor_CustomName.Header" xml:space="preserve">
<value>Custom Name</value>
</data>
<data name="PowerDisplay_CustomMappingEditor_CustomName.PlaceholderText" xml:space="preserve">
<value>Enter custom name</value>
</data>
<data name="PowerDisplay_CustomMappingEditor_ValueComboBox.Header" xml:space="preserve">
<value>Value</value>
</data>
<data name="PowerDisplay_CustomMappingEditor_CustomValueOption" xml:space="preserve">
<value>Custom value...</value>
</data>
<data name="PowerDisplay_CustomMappingEditor_CustomValueInput.Header" xml:space="preserve">
<value>Enter custom value (hex)</value>
</data>
<data name="PowerDisplay_CustomMappingEditor_CustomValueInput.PlaceholderText" xml:space="preserve">
<value>e.g., 0x11 or 17</value>
</data>
<data name="PowerDisplay_CustomMapping_Delete_Title" xml:space="preserve">
<value>Delete custom mapping?</value>
</data>
<data name="PowerDisplay_CustomMapping_Delete_Message" xml:space="preserve">
<value>This custom name mapping will be permanently removed.</value>
</data>
<data name="Hosts_Backup_GroupSettings.Header" xml:space="preserve">
<value>Backup</value>
</data>
@@ -6218,14 +6170,14 @@ The break timer font matches the text font.</value>
</data>
<data name="ZoomIt_LiveZoom_Shortcut_Draw" xml:space="preserve">
<value>Press **{0}** to activate live drawing and **Esc** to clear annotations or to exit.
Press **Ctrl + Up / Down** to adjust the zoom level.
</value>
</data>
<data name="ZoomIt_TypeFAQ.Text" xml:space="preserve">
<value>Press **T** to switch to typing when drawing mode is active, and **Shift** for right-aligned text.
Press **Esc** or **the left mouse button** to exit typing mode.
Press **the mouse wheel** or **Up / Down** to adjust the font size.
<value>Press **T** to switch to typing when drawing mode is active, and **Shift** for right-aligned text.
Press **Esc** or **the left mouse button** to exit typing mode.
Press **the mouse wheel** or **Up / Down** to adjust the font size.
Text uses the current drawing color.</value>
</data>
<data name="ZoomIt_DrawGroup.Description" xml:space="preserve">

View File

@@ -59,9 +59,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
// Load profiles
LoadProfiles();
// Load custom VCP mappings
LoadCustomVcpMappings();
// Listen for monitor refresh events from PowerDisplay.exe
NativeEventWaiter.WaitForEventLoop(
Constants.RefreshPowerDisplayMonitorsEvent(),
@@ -449,25 +446,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
// Profile-related fields
private ObservableCollection<PowerDisplayProfile> _profiles = new ObservableCollection<PowerDisplayProfile>();
// Custom VCP mapping fields
private ObservableCollection<Library.CustomVcpValueMapping> _customVcpMappings = new ObservableCollection<Library.CustomVcpValueMapping>();
/// <summary>
/// Gets or sets collection of custom VCP value name mappings
/// </summary>
public ObservableCollection<Library.CustomVcpValueMapping> CustomVcpMappings
{
get => _customVcpMappings;
set
{
if (_customVcpMappings != value)
{
_customVcpMappings = value;
OnPropertyChanged();
}
}
}
/// <summary>
/// Gets or sets collection of available profiles (for button display)
/// </summary>
@@ -668,102 +646,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
/// <summary>
/// Load custom VCP mappings from settings
/// </summary>
private void LoadCustomVcpMappings()
{
try
{
var mappings = _settings.Properties.CustomVcpMappings ?? new List<Library.CustomVcpValueMapping>();
CustomVcpMappings = new ObservableCollection<Library.CustomVcpValueMapping>(mappings);
Logger.LogInfo($"Loaded {CustomVcpMappings.Count} custom VCP mappings");
}
catch (Exception ex)
{
Logger.LogError($"Failed to load custom VCP mappings: {ex.Message}");
CustomVcpMappings = new ObservableCollection<Library.CustomVcpValueMapping>();
}
}
/// <summary>
/// Add a new custom VCP mapping
/// </summary>
public void AddCustomVcpMapping(Library.CustomVcpValueMapping mapping)
{
if (mapping == null)
{
return;
}
// Check if a mapping for the same VcpCode+Value already exists
var existing = CustomVcpMappings.FirstOrDefault(m =>
m.VcpCode == mapping.VcpCode && m.Value == mapping.Value);
if (existing != null)
{
// Update the existing mapping's custom name
existing.CustomName = mapping.CustomName;
Logger.LogInfo($"Updated existing custom VCP mapping: VCP=0x{mapping.VcpCode:X2}, Value=0x{mapping.Value:X2}");
}
else
{
// Add new mapping
CustomVcpMappings.Add(mapping);
Logger.LogInfo($"Added custom VCP mapping: VCP=0x{mapping.VcpCode:X2}, Value=0x{mapping.Value:X2} -> {mapping.CustomName}");
}
SaveCustomVcpMappings();
}
/// <summary>
/// Update an existing custom VCP mapping
/// </summary>
public void UpdateCustomVcpMapping(Library.CustomVcpValueMapping oldMapping, Library.CustomVcpValueMapping newMapping)
{
if (oldMapping == null || newMapping == null)
{
return;
}
var index = CustomVcpMappings.IndexOf(oldMapping);
if (index >= 0)
{
CustomVcpMappings[index] = newMapping;
Logger.LogInfo($"Updated custom VCP mapping at index {index}");
SaveCustomVcpMappings();
}
}
/// <summary>
/// Delete a custom VCP mapping
/// </summary>
public void DeleteCustomVcpMapping(Library.CustomVcpValueMapping mapping)
{
if (mapping == null)
{
return;
}
if (CustomVcpMappings.Remove(mapping))
{
Logger.LogInfo($"Deleted custom VCP mapping: VCP=0x{mapping.VcpCode:X2}, Value=0x{mapping.Value:X2}");
SaveCustomVcpMappings();
}
}
/// <summary>
/// Save custom VCP mappings to settings
/// </summary>
private void SaveCustomVcpMappings()
{
_settings.Properties.CustomVcpMappings = CustomVcpMappings.ToList();
NotifySettingsChanged();
// Signal PowerDisplay to reload settings
SignalSettingsUpdated();
}
private void NotifySettingsChanged()
{
// Skip during initialization when SendConfigMSG is not yet set

View File

@@ -850,6 +850,20 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public bool RecordCaptureSystemAudio
{
get => _zoomItSettings.Properties.CaptureSystemAudio.Value;
set
{
if (_zoomItSettings.Properties.CaptureSystemAudio.Value != value)
{
_zoomItSettings.Properties.CaptureSystemAudio.Value = value;
OnPropertyChanged(nameof(RecordCaptureSystemAudio));
NotifySettingsChanged();
}
}
}
public bool RecordCaptureAudio
{
get => _zoomItSettings.Properties.CaptureAudio.Value;