Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Z-Dante committed Nov 15, 2021
2 parents 00953cb + a69f902 commit b762b0e
Show file tree
Hide file tree
Showing 16 changed files with 896 additions and 805 deletions.
63 changes: 63 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# 贡献指南

**首先,感谢你将宝贵的时间花费在本项目上!**

Magpie 是一个个人项目,最早启发于 Integer Scaler 和 Lossless Scaling,但现在它比前辈们强大的多。开发者的能力和精力有限,因此欢迎任何形式的贡献!Magpie 遵循 [All Contributors](https://github.com/all-contributors/all-contributors) 规范,无论你以何种形式做出贡献,诸如编写代码、撰写文档、用户测试等,只要你的贡献足够,开发者都会把你加入贡献者清单。

如果你是新手,强烈推荐你读一下[这篇文章](https://opensourceway.community/open-source-guide/how-to-contribute/)

下面是一些你可能想做的贡献:

### 我有一个问题 🙏

[FAQ](https://github.com/Blinue/Magpie/wiki/FAQ) 汇总了常见的问题,你也可以搜索 [Issue](https://github.com/Blinue/Magpie/issues)[Discussion](https://github.com/Blinue/Magpie/discussions) 看是否已经有人提出过。如果依然没有得到解答,请在 Discussion 中询问。

### 我遇到了一个错误 🐞

Magpie 没有广泛的测试过,因此错误不可避免。希望你能向开发者反馈这个错误,这样可以帮助所有和你遇到同样问题的人。

首先请在 Issue 和 Discussion 中搜索你遇到的错误,避免和现有 Issue 重复。汇报错误时请发布一个 [Issue(bug report)](https://github.com/Blinue/Magpie/issues/new?assignees=&labels=bug&template=01_bug.yaml),下面是一些有利于开发者快速定位问题的最佳实践:

1. 选择一个清晰简洁的标题,可以在标题前加上[bug]标签。如 “[bug] Windows 11窗口圆角导致游戏窗口超分后左下/右下角模糊” 是一个好标题,而 “应用程序错误” 则意义不明。
2. 上传日志文件对定位问题特别有帮助,它们位于 logs 文件夹下。
3. 请详细的描述复现步骤,最好提供一些截图。
4. 还有一些信息可能对开发者有帮助,比如特殊的显示器配置,显卡型号等。

### 我有一个功能建议 🚀

你可能有一些关于 Magpie 的奇思妙想,请和开发者分享它们!开发者通常只是通过自己的使用经验添加新功能,但你的点子可能会使 Magpie 与众不同。

首先请在 Issue 中搜索你的功能建议,确保不和已有的重复,尤其要查看路线图(它们会在 Issue 页面置顶)里是否有这个功能。然后提交一个 [Issue(feature request)](https://github.com/Blinue/Magpie/issues/new?assignees=&labels=enhancement&template=03_request.yaml),详细地描述你的建议,比如是否有其他软件实现了类似的功能。

### 我想贡献代码 💻

贡献代码是帮助 Magpie 项目最直接的方式,你可以修复 bug,增加新功能或修正格式错误。不要因为修改太小就羞于贡献,你的每一行修改都很重要。

和所有开源项目一样,你需要提交 pull request 来向 Magpie 贡献代码。开发者可能会要求你做一些更改,如果你无法及时响应,你的 pull request 可能会被关闭。为了激励贡献,大多数 pull request 都会被接受。

**注意:一旦你向 Magpie 贡献代码,便表示你同意将该代码的版权转让给 Magpie 当前的版权所有者。Magpie 可能在没有征得你的同意的情况下更换许可证。** 这是为了使开发者做出重大决定时无需征得每一个贡献者的同意,开发者承诺 Magpie 项目更换许可证的唯一情形是迁移到更新版本的 GPL 协议。如果你想保留版权,只能放弃贡献,将更改保留在自己的 Fork 中。

贡献代码时你需要遵守一些准则:

1. 和现有的代码风格保持一致,包括花括号不换行,tab 缩进,变量、类、源文件等的命名方式,所有源码文件格式均为 UTF-8 without BOM,大部分情况下采用行注释,git 消息风格等等。
2. 如果你要进行比较大的更改请先提交 pull request 和开发者交流,确保和项目当前的方向一致。
3. 你的分支必须可以通过编译检查。
4. 请尽量应用 VS 检查代码时提出的建议。
5. 含有“私货”的代码不会被接受。

### 我想贡献翻译 🌍

贡献新的翻译和修正现有翻译都是非常欢迎的。向 Magpie 贡献翻译非常简单,所有用户界面文本均存储在 resx 中,创建新的Resources.xx-xx.resx 文件并翻译所有字符串即可。

贡献翻译的方式和[贡献代码](#我想贡献代码-)的方式相同,但翻译的 pull request 基本都会被接受。强烈推荐你定期维护自己的翻译,因为 Magpie 的用户界面经常会进行较大的更改。

### 我想贡献文档 📖

因为开发者的懒惰,Magpie 的文档长期处于缺失/过时的状态。尽管 Magpie 的 wiki 是人人可编辑的,但强烈推荐你在编辑前提交一个[Issue(docs)](https://github.com/Blinue/Magpie/issues/new?assignees=&labels=documentation&template=05_document.yaml),以避免加入错误/过时的信息。更改 README、贡献指南等文档需要参考[贡献代码](#我想贡献代码-)

### 我想资助 Magpie 💰

开发者每周都会花费大量的时间开发新功能,这些工作都是无偿的。目前 Magpie 没有资助的渠道,对它进行 Star、Fork 或者宣传就是最好的资助!



34 changes: 26 additions & 8 deletions Magpie/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Copyright (c) 2021 - present, Liu Xu
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.


using Gma.System.MouseKeyHook;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -414,9 +430,9 @@ public partial class MainWindow : Window {
}
}

private void CheckOSTheme() {
bool isLightTheme = false;
private bool? isLightTheme = null;

private void CheckOSTheme() {
// 检查注册表获取系统主题,迁移到新版本的 .NET 后将使用 WinRT
IntPtr hKey = IntPtr.Zero;
if (NativeMethods.RegOpenKeyEx(
Expand All @@ -436,16 +452,18 @@ ref hKey
data,
ref dataSize
) == 0) {
isLightTheme = data.Any(b => { return b != 0; });
bool newVal = data.Any(b => { return b != 0; });
if (!isLightTheme.HasValue || newVal != isLightTheme.Value) {
isLightTheme = newVal;
Uri logoUri = new Uri($"pack://application:,,,/Magpie;component/Resources/Logo_{(newVal ? "Black" : "White")}.ico");

notifyIcon.Icon = new System.Drawing.Icon(App.GetResourceStream(logoUri).Stream);
System.Windows.Application.Current.Resources["Logo"] = new BitmapImage(logoUri);
}
}

NativeMethods.RegCloseKey(hKey);
}

Uri logoUri = new Uri($"pack://application:,,,/Magpie;component/Resources/Logo_{(isLightTheme ? "Black" : "White")}.ico");

notifyIcon.Icon = new System.Drawing.Icon(App.GetResourceStream(logoUri).Stream);
System.Windows.Application.Current.Resources["Logo"] = new BitmapImage(logoUri);
}
}
}
2 changes: 1 addition & 1 deletion Magpie/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Magpie")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyCopyright("Copyright © 2021 Liu Xu")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
Binary file modified Magpie/Resources/Logo_White.ico
Binary file not shown.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Magpie 可以将任意窗口放大至全屏,支持多种高级缩放算法,

[自定义缩放配置](https://github.com/Blinue/Magpie/wiki/自定义缩放配置)

[贡献指南](https://github.com/Blinue/Magpie/blob/master/CONTRIBUTING.md)

## 使用方法

![窗口截图](img/窗口截图.png)
Expand Down
51 changes: 26 additions & 25 deletions Runtime/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,27 @@ bool App::Run(
_cursorInterpolationMode = cursorInterpolationMode;
_flags = flags;

SPDLOG_LOGGER_INFO(logger, fmt::format("运行时参数:\n\thwndSrc:{}\n\tcaptureMode:{}\n\tadjustCursorSpeed:{}\n\tshowFPS:{}\n\tdisableRoundCorner:{}\n\tframeRate:{}\n\tdisableLowLatency:{}\n\tbreakpointMode:{}", (void*)hwndSrc, captureMode, IsAdjustCursorSpeed(), IsShowFPS(), IsDisableRoundCorner(), frameRate, IsDisableLowLatency(), IsBreakpointMode()));
SPDLOG_LOGGER_INFO(logger, fmt::format("运行时参数:\n\thwndSrc:{}\n\tcaptureMode:{}\n\tadjustCursorSpeed:{}\n\tshowFPS:{}\n\tdisableRoundCorner:{}\n\tframeRate:{}\n\tdisableLowLatency:{}\n\tbreakpointMode:{}\n\tdisableWindowResizing:{}\n\tdisableDirectFlip:{}", (void*)hwndSrc, captureMode, IsAdjustCursorSpeed(), IsShowFPS(), IsDisableRoundCorner(), frameRate, IsDisableLowLatency(), IsBreakpointMode(), IsDisableWindowResizing(), IsDisableDirectFlip()));

// 每次进入全屏都要重置
_nextTimerId = 1;

SetErrorMsg(ErrorMessages::GENERIC);

// 禁用窗口大小调整
bool windowResizingDisabled = false;
if (IsDisableWindowResizing()) {
LONG_PTR style = GetWindowLongPtr(hwndSrc, GWL_STYLE);
if (style & WS_THICKFRAME) {
if (SetWindowLongPtr(hwndSrc, GWL_STYLE, style ^ WS_THICKFRAME)) {
SPDLOG_LOGGER_INFO(logger, "已禁用窗口大小调整");
windowResizingDisabled = true;
} else {
SPDLOG_LOGGER_ERROR(logger, "禁用窗口大小调整失败");
}
}
}

_srcClientRect = Utils::GetClientScreenRect(_hwndSrc);
if (_srcClientRect.right == 0 || _srcClientRect.bottom == 0) {
SPDLOG_LOGGER_CRITICAL(logger, "Failed to get source window");
Expand Down Expand Up @@ -160,22 +174,20 @@ bool App::Run(
}
}

// 禁用窗口大小调整
bool windowResizingDisabled = false;
if (IsDisableWindowResizing()) {
LONG_PTR style = GetWindowLongPtr(hwndSrc, GWL_STYLE);
if (style & WS_THICKFRAME) {
if (SetWindowLongPtr(hwndSrc, GWL_STYLE, style ^ WS_THICKFRAME)) {
SPDLOG_LOGGER_INFO(logger, "已禁用窗口大小调整");
windowResizingDisabled = true;
} else {
SPDLOG_LOGGER_ERROR(logger, "禁用窗口大小调整失败");
}
_Run();

// 还原窗口圆角
if (roundCornerDisabled) {
INT attr = DWMWCP_DEFAULT;
HRESULT hr = DwmSetWindowAttribute(hwndSrc, DWMWA_WINDOW_CORNER_PREFERENCE, &attr, sizeof(attr));
if (FAILED(hr)) {
SPDLOG_LOGGER_INFO(logger, "Failed to disable rounded window corners");
} else {
SPDLOG_LOGGER_INFO(logger, "Rounded window corners has been disabled");
}
}

_Run();

// 还原窗口大小调整
if (windowResizingDisabled) {
LONG_PTR style = GetWindowLongPtr(hwndSrc, GWL_STYLE);
if (!(style & WS_THICKFRAME)) {
Expand All @@ -186,17 +198,6 @@ bool App::Run(
}
}
}

if (roundCornerDisabled) {
INT attr = DWMWCP_DEFAULT;
HRESULT hr = DwmSetWindowAttribute(hwndSrc, DWMWA_WINDOW_CORNER_PREFERENCE, &attr, sizeof(attr));
if (FAILED(hr)) {
SPDLOG_LOGGER_INFO(logger, "Failed to disable rounded window corners");
} else {
SPDLOG_LOGGER_INFO(logger, "Rounded window corners has been undisabled");
}
}

return true;
}

Expand Down
14 changes: 13 additions & 1 deletion Runtime/DllMain.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// DllMain.cpp : Runtime.dll 的入口点。
// Copyright (c) 2021 - present, Liu Xu
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.


#include "pch.h"
Expand Down
1 change: 0 additions & 1 deletion Runtime/DwmSharedSurfaceFrameSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ bool DwmSharedSurfaceFrameSource::Update() {

_d3dDC->CopySubresourceRegion(_output.Get(), 0, 0, 0, 0, sharedTexture.Get(), 0, &_frameInWnd);

SPDLOG_LOGGER_INFO(logger, "DwmSharedSurfaceFrameSource 初始化完成");
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions Runtime/EffectCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ bool EffectCache::Load(const wchar_t* fileName, std::string_view hash, EffectDes
// 检查版本
UINT version;
ia& version;
if (version != EffectCompiler::VERSION) {
SPDLOG_LOGGER_INFO(logger, "版本不匹配");
if (version != _VERSION) {
SPDLOG_LOGGER_INFO(logger, "缓存版本不匹配");
return false;
}

Expand Down
4 changes: 4 additions & 0 deletions Runtime/EffectCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ class EffectCache {

// 缓存文件后缀名:Compiled MagpieFX
static constexpr const wchar_t* _SUFFIX = L"cmfx";

// 缓存版本
// 当缓存文件结构有更改时将更新它,使得所有旧缓存失效
static constexpr const UINT _VERSION = 1;
};
Loading

0 comments on commit b762b0e

Please sign in to comment.