深度截图

前面提到深度的截图工具会自动给截图增加一个蓝色的边框,看上去很怪异,所以自己打了个补丁。

不是很清楚为何官方的版本默认是无法进行构建的,因为 dtkwm 这个包默认只提供了 pkg-config 支持,缺少对 CMake 的支持(不应该是 Ubuntu 上的 dtkwm 版本太老的原因,因为看了官方最新的源代码也并没有提供 CMake 支持),所以同时给构建代码也打了个补丁。

deepin-screenshot 的源代码可以从 github 进行克隆:

https://github.com/linuxdeepin/deepin-screenshot.git

补丁如下:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 08cafaf..802e6de 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,6 +13,8 @@ set(CMAKE_CXX_FLAGS "-g -Wall -g -fPIE -pie")
 set(CMAKE_EXE_LINKER_FLAGS "-fPIE -pie")
 set(BIN_NAME deepin-screenshot)
 
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/")
+
 # Sources files
 set(SRCS
 # main
diff --git a/cmake/modules/FindDtkWm.cmake b/cmake/modules/FindDtkWm.cmake
new file mode 100644
index 0000000..fe7dcc3
--- /dev/null
+++ b/cmake/modules/FindDtkWm.cmake
@@ -0,0 +1,5 @@
+# What is the proper way to use `pkg-config` from `cmake`?
+# https://stackoverflow.com/questions/29191855/what-is-the-proper-way-to-use-pkg-config-from-cmake
+
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(DtkWm REQUIRED dtkwm)
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 3d63ab7..b35c14b 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -720,7 +720,7 @@ void MainWindow::paintEvent(QPaintEvent *event)
         painter.setOpacity(0.5);
         painter.drawRect(backgroundRect);
     } else if (m_recordWidth > 0 && m_recordHeight > 0 && !m_drawNothing) {
-        QRect frameRect = QRect(m_recordX + 1, m_recordY + 1, m_recordWidth - 2, m_recordHeight - 2);
+        QRect frameRect = QRect(m_recordX - 1, m_recordY - 1, m_recordWidth + 2, m_recordHeight + 2);
         // Draw frame.
         if (m_mouseStatus != ShotMouseStatus::Wait) {
             painter.setRenderHint(QPainter::Antialiasing, false);

最后修改于 2019-04-18