Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 66 additions & 43 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,88 @@
name: Release Build
name: CI

on:
push:
tags:
- 'v*'
branches: [main]
tags: ['v*']
pull_request:
branches: [main]

permissions:
contents: write

jobs:
build:
# The detection algorithm has no Windows dependency, so its regression suite
# runs on Linux in a couple of seconds.
detector-tests:
name: Shake detector tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure
run: cmake -S . -B build -DSTFC_BUILD_TESTS=ON
- name: Build tests
run: cmake --build build --target shake_detector_tests
- name: Run tests
run: ctest --test-dir build --output-on-failure

windows:
name: Windows (${{ matrix.arch }})
runs-on: windows-latest
strategy:
matrix:
arch: [x64, x86]

arch: [x64, Win32]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Set up Visual Studio shell
uses: egor-tensin/vs-shell@v2
with:
arch: ${{ matrix.arch }}
- name: Configure
run: cmake -S . -B build -A ${{ matrix.arch }}

- name: Create Build Directory
run: cmake -E make_directory ${{github.workspace}}/build
- name: Build
run: cmake --build build --config Release

- name: Configure CMake
working-directory: ${{github.workspace}}/build
run: cmake .. -A ${{ matrix.arch=='x64' && 'x64' || 'Win32' }}
- name: Run tests (MSVC)
run: ctest --test-dir build -C Release --output-on-failure

- name: Build
working-directory: ${{github.workspace}}/build
run: cmake --build . --config Release
- name: Check the manifest really is embedded
shell: pwsh
run: |
$exe = "build/Release/ShakeToFindCursor.exe"
Get-Item $exe | Select-Object Name, Length
$bytes = [System.IO.File]::ReadAllBytes((Resolve-Path $exe))
$text = [System.Text.Encoding]::ASCII.GetString($bytes)
if (-not $text.Contains('PerMonitorV2')) {
throw "the embedded manifest does not declare PerMonitorV2"
}

- name: Package
run: |
mkdir publish
cp build/Release/ShakeToFindCursor.exe "publish/ShakeToFindCursor-${{ matrix.arch }}.exe" || true
- name: Package
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path publish | Out-Null
$arch = "${{ matrix.arch }}".ToLower()
Copy-Item build/Release/ShakeToFindCursor.exe "publish/ShakeToFindCursor-$arch.exe"
Get-ChildItem publish

- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: ShakeToFindCursor-${{ matrix.arch }}
path: publish/*
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ShakeToFindCursor-${{ matrix.arch }}
path: publish/*

release:
needs: build
name: GitHub release
needs: [windows, detector-tests]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: windows-latest
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true

- name: Create Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: artifacts/*.exe
draft: false
prerelease: false
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Create release
uses: softprops/action-gh-release@v2
with:
files: artifacts/*.exe
draft: false
prerelease: false
generate_release_notes: true
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@
.vscode/*

# Build files
build/*
build/*
# Generated resources
*.res
166 changes: 126 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,40 +1,126 @@
cmake_minimum_required(VERSION 3.15)

project(ShakeToFindCursor
VERSION 1.3.0
LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)

if(NOT WIN32)
message(FATAL_ERROR "This project only supports Windows platform")
endif()

add_definitions(-DUNICODE -D_UNICODE)

add_executable(${PROJECT_NAME}
WIN32
main.cpp
res.rc
)

if(MSVC)
target_compile_options(${PROJECT_NAME}
PRIVATE
/W4
/WX
/MP
/EHsc
/utf-8
)
set_target_properties(${PROJECT_NAME} PROPERTIES
LINK_FLAGS "/MANIFEST /MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\" "
)
else()
target_compile_options(${PROJECT_NAME}
PRIVATE
-Wall
-Wextra
-Wpedantic
)
endif()
cmake_minimum_required(VERSION 3.15)

project(ShakeToFindCursor
VERSION 1.4.0
LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# The app ships as one bare .exe, so the CRT is linked in rather than referenced
# (otherwise a fresh Windows box without the Visual C++ redistributable gets
# "VCRUNTIME140.dll was not found" on first double-click).
if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY
"MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()

option(STFC_BUILD_TESTS "Build the detector unit tests (run with ctest)" ON)
option(STFC_STRICT_WARNINGS "Treat warnings as errors when building" ON)
option(STFC_REQUIRE_ADMIN
"Embed a requireAdministrator manifest instead of asInvoker")

enable_testing()

# ---------------------------------------------------------------------------
# Shake detector tests. Header-only, no Windows dependency, so they build and
# run on any platform - which is how the detection algorithm gets regression
# coverage without a Windows machine.
# ---------------------------------------------------------------------------
if(STFC_BUILD_TESTS)
add_executable(shake_detector_tests tests/shake_detector_test.cpp)
target_include_directories(shake_detector_tests PRIVATE src)
if(MSVC)
target_compile_options(shake_detector_tests PRIVATE /W3 /EHsc /utf-8)
else()
target_compile_options(shake_detector_tests PRIVATE -Wall -Wextra)
endif()
add_test(NAME shake_detector_tests COMMAND shake_detector_tests)
endif()

if(NOT WIN32)
message(STATUS "ShakeToFindCursor: not on Windows - only the detector "
"tests were configured.")
return()
endif()

add_definitions(-DUNICODE -D_UNICODE)

set(STFC_SOURCES
main.cpp
src/app_settings.cpp
src/auto_start.cpp
src/find_overlay.cpp
src/pointer_zoomer.cpp
src/win_util.cpp)

# ---------------------------------------------------------------------------
# Resources. res.rc is generated with absolute paths for the icon and the
# manifest: rc.exe and windres disagree about how a relative resource file name
# is resolved, and the manifest is what carries the DPI awareness plus the
# asInvoker / requireAdministrator choice, so it must be embedded exactly once.
# ---------------------------------------------------------------------------
if(STFC_REQUIRE_ADMIN)
set(STFC_MANIFEST_FILE
"${CMAKE_CURRENT_SOURCE_DIR}/app.requireAdministrator.manifest")
else()
set(STFC_MANIFEST_FILE "${CMAKE_CURRENT_SOURCE_DIR}/app.manifest")
endif()
# rc.exe runs quoted resource strings through its own escape processing, so a
# backslash path such as D:\a\ShakeToFindCursor\app_icon.ico can come out
# mangled (\a) or rejected outright. Forward slashes are accepted by both
# rc.exe and windres, which is also what CMake itself writes into the .rc files
# it generates for the Visual Studio generators.
string(REPLACE "\\" "/" STFC_MANIFEST_FILE "${STFC_MANIFEST_FILE}")
string(REPLACE "\\" "/" STFC_ICON_FILE
"${CMAKE_CURRENT_SOURCE_DIR}/app_icon.ico")
set(STFC_MANIFEST_LINE
"1 24 \"${STFC_MANIFEST_FILE}\"")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/res.rc.in"
"${CMAKE_CURRENT_BINARY_DIR}/res.rc" @ONLY)

add_executable(${PROJECT_NAME}
WIN32
${STFC_SOURCES}
"${CMAKE_CURRENT_BINARY_DIR}/res.rc")

target_include_directories(${PROJECT_NAME} PRIVATE src)

# The five DLLs the app really imports. MSVC additionally picks ole32 up from
# the #pragma comment in src/auto_start.cpp, which is harmless. Notably absent
# is taskschd: the Task Scheduler API is used through COM interfaces obtained
# from CoCreateInstance, so no import library is required (and a toolchain
# without one, like the many MinGW builds, still links).
target_link_libraries(${PROJECT_NAME} PRIVATE
user32 gdi32 shell32 ole32 oleaut32 advapi32)

if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE
/W4
/MP
/EHsc
/utf-8)
if(STFC_STRICT_WARNINGS)
target_compile_options(${PROJECT_NAME} PRIVATE /WX)
endif()
# The manifest is embedded by the resource compiler; keep the linker from
# generating (and then merging) a second one.
target_link_options(${PROJECT_NAME} PRIVATE "/MANIFEST:NO")
else()
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall
-Wextra
-municode)
if(STFC_STRICT_WARNINGS)
target_compile_options(${PROJECT_NAME} PRIVATE -Werror)
endif()
# -municode picks the startup object that calls wWinMain instead of
# WinMain; the -static flags keep libgcc/libstdc++/libwinpthread out of the
# result so the MinGW build is a single file as well.
target_link_options(${PROJECT_NAME} PRIVATE
-municode -static -static-libgcc -static-libstdc++)
endif()

message(STATUS "ShakeToFindCursor ${PROJECT_VERSION}: manifest "
"${STFC_MANIFEST_FILE}")
54 changes: 54 additions & 0 deletions app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.4.0.0"
type="win32"
name="ShakeToFindCursor"
processorArchitecture="*" />

<!--
asInvoker, not requireAdministrator.

The highlight overlay needs no privileges at all, so the app is useful to
everyone; enlarging the *pointer* itself goes through SetSystemCursor,
which does require admin. The tray menu offers a one-click elevated restart
and registers a scheduled task for it, instead of demanding a UAC prompt on
every start (and instead of failing outright when the user says no).
Build with -DSTFC_REQUIRE_ADMIN=ON to force elevation from the manifest.
-->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 and 11 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
</application>
</compatibility>

<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<!--
Declaring awareness in the manifest (instead of SetProcessDPIAware at
run time) is what stops the DWM from stretching the whole desktop, which
is exactly the artifact you would see on a scaled pointer: a blurry
cursor next to a sharp screen. PerMonitorV2 matters on mixed-DPI
multi-monitor setups; "system" is the fallback for pre-1703 builds.
-->
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, system</dpiAwareness>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
</assembly>
31 changes: 31 additions & 0 deletions app.requireAdministrator.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Same as app.manifest, but forcing elevation. Selected by -DSTFC_REQUIRE_ADMIN=ON. -->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.4.0.0"
type="win32"
name="ShakeToFindCursor"
processorArchitecture="*" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
</application>
</compatibility>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, system</dpiAwareness>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
</assembly>
Binary file added binaries/ShakeToFindCursor-amd64.exe
Binary file not shown.
Binary file added binaries/ShakeToFindCursor-x86.exe
Binary file not shown.
Loading
Loading