diff --git a/README.md b/README.md index 0a3927d5..d5b2a826 100644 --- a/README.md +++ b/README.md @@ -37,17 +37,25 @@ This fork adds the following features: ## 🖼️ Screenshots
- +
## 🖥️ Supported platforms diff --git a/docs/images/screenshot_linux.png b/docs/images/screenshot_linux.png deleted file mode 100644 index 729aa8c8..00000000 Binary files a/docs/images/screenshot_linux.png and /dev/null differ diff --git a/docs/images/screenshot_macos.png b/docs/images/screenshot_macos.png deleted file mode 100644 index fb1d5762..00000000 Binary files a/docs/images/screenshot_macos.png and /dev/null differ diff --git a/docs/images/screenshot_windows.png b/docs/images/screenshot_windows.png deleted file mode 100644 index d2feada5..00000000 Binary files a/docs/images/screenshot_windows.png and /dev/null differ diff --git a/docs/images/tray_menu_left_click_linux.png b/docs/images/tray_menu_left_click_linux.png new file mode 100644 index 00000000..387852db Binary files /dev/null and b/docs/images/tray_menu_left_click_linux.png differ diff --git a/docs/images/tray_menu_left_click_macos.png b/docs/images/tray_menu_left_click_macos.png new file mode 100644 index 00000000..f912269a Binary files /dev/null and b/docs/images/tray_menu_left_click_macos.png differ diff --git a/docs/images/tray_menu_left_click_windows.png b/docs/images/tray_menu_left_click_windows.png new file mode 100644 index 00000000..2eea6d0b Binary files /dev/null and b/docs/images/tray_menu_left_click_windows.png differ diff --git a/docs/images/tray_notification_svg_icon_linux.png b/docs/images/tray_notification_svg_icon_linux.png new file mode 100644 index 00000000..e82638bc Binary files /dev/null and b/docs/images/tray_notification_svg_icon_linux.png differ diff --git a/docs/images/tray_notification_svg_icon_windows.png b/docs/images/tray_notification_svg_icon_windows.png new file mode 100644 index 00000000..668f284d Binary files /dev/null and b/docs/images/tray_notification_svg_icon_windows.png differ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 22193683..33c73672 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -25,7 +25,9 @@ elseif(NOT TARGET lizardbyte::test_support) endif() # extra libraries for tests if (APPLE) - set(TEST_LIBS "-framework Cocoa") + set(TEST_LIBS "-framework Cocoa" Qt${TRAY_QT_VERSION}::Gui) +elseif (UNIX) + set(TEST_LIBS Qt${TRAY_QT_VERSION}::Gui) elseif (WIN32) set(TEST_LIBS gdi32 gdiplus) endif() diff --git a/tests/screenshot_utils.cpp b/tests/screenshot_utils.cpp index 5d54730d..6c1e3c09 100644 --- a/tests/screenshot_utils.cpp +++ b/tests/screenshot_utils.cpp @@ -9,6 +9,11 @@ #include #include #include +#if defined(__linux__) || defined(__APPLE__) + // qt includes + #include + #include +#endif #ifdef _WIN32 #ifndef NOMINMAX #define NOMINMAX @@ -21,7 +26,14 @@ // clang-format on #endif +// lib includes +#include + namespace { + bool capture_full_screen() { + return lizardbyte::common::is_github_actions() && lizardbyte::common::get_env("RUNNER_DEBUG") == "1"; + } + #if defined(__linux__) || defined(__APPLE__) std::string quote_shell_path(const std::filesystem::path &path) { const std::string input = path.string(); @@ -38,6 +50,24 @@ namespace { output.push_back('"'); return output; } + + bool crop_to_top_right_quadrant(const std::filesystem::path &file) { + const QString imagePath = QString::fromUtf8(file.u8string().c_str()); + const QImage image(imagePath); + if (image.isNull() || image.width() < 2 || image.height() < 2) { + std::cerr << "Screenshot dimensions invalid" << std::endl; + return false; + } + + const int width = image.width() / 2; + const int height = image.height() / 2; + const QImage quadrant = image.copy(image.width() - width, 0, width, height); + if (!quadrant.save(imagePath, "PNG")) { + std::cerr << "Failed to crop " << file << std::endl; + return false; + } + return true; + } #endif #ifdef _WIN32 @@ -108,7 +138,10 @@ namespace screenshot { #ifdef __APPLE__ static bool capture_macos(const std::filesystem::path &file, const Options &) { std::string cmd = "screencapture -x " + quote_shell_path(file); - return std::system(cmd.c_str()) == 0; + if (std::system(cmd.c_str()) != 0) { + return false; + } + return capture_full_screen() || crop_to_top_right_quadrant(file); } #endif @@ -118,17 +151,20 @@ namespace screenshot { if (std::system("which import > /dev/null 2>&1") == 0) { std::string cmd = "import -window root " + target; if (std::system(cmd.c_str()) == 0) { - return true; + return capture_full_screen() || crop_to_top_right_quadrant(file); } } if (std::system("which spectacle > /dev/null 2>&1") == 0) { std::string cmd = "spectacle -f -b -n -o " + target; if (std::system(cmd.c_str()) == 0) { - return true; + return capture_full_screen() || crop_to_top_right_quadrant(file); } } std::string cmd = "gnome-screenshot -f " + target; - return std::system(cmd.c_str()) == 0; + if (std::system(cmd.c_str()) != 0) { + return false; + } + return capture_full_screen() || crop_to_top_right_quadrant(file); } #endif @@ -162,6 +198,15 @@ namespace screenshot { return false; } + if (!capture_full_screen()) { + const int fullWidth = width; + const int fullHeight = height; + width = fullWidth / 2; + height = fullHeight / 2; + left += fullWidth - width; + top += fullHeight - height; + } + HDC hdcScreen = GetDC(nullptr); if (hdcScreen == nullptr) { std::cerr << "GetDC(nullptr) failed" << std::endl; diff --git a/tests/unit/test_tray.cpp b/tests/unit/test_tray.cpp index 8a9fd513..dc2dbb62 100644 --- a/tests/unit/test_tray.cpp +++ b/tests/unit/test_tray.cpp @@ -142,6 +142,12 @@ class TrayTest: public BaseTest { }); tray_show_menu(); + if (positionMouse) { + const int restoreMouseResult = tray_restore_mouse_position(); + if (positionMouseResult == 0) { + EXPECT_EQ(restoreMouseResult, 0); + } + } while (tray_loop(0) == 0) { if (exitRequested.load(std::memory_order_acquire)) { tray_exit(); @@ -149,12 +155,6 @@ class TrayTest: public BaseTest { std::this_thread::sleep_for(std::chrono::milliseconds(10)); } capture_thread.join(); - if (positionMouse) { - const int restoreMouseResult = tray_restore_mouse_position(); - if (positionMouseResult == 0) { - EXPECT_EQ(restoreMouseResult, 0); - } - } } static void hello_cb(struct tray_menu *) { @@ -469,6 +469,23 @@ TEST_F(TrayTest, TestTooltipUpdate) { tray_update(&testTray); } +TEST_F(TrayTest, TestTooltipDisplayOnHover) { + testTray.icon = TRAY_ICON_SVG; + + int initResult = tray_init(&testTray); + trayRunning = (initResult == 0); + ASSERT_EQ(initResult, 0); + WaitForTrayReady(); + + ASSERT_EQ(tray_position_mouse_over_icon(), 0); + for (int i = 0; i < 20; ++i) { + tray_loop(0); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + } + EXPECT_TRUE(captureScreenshot("tray_tooltip_hover")); + EXPECT_EQ(tray_restore_mouse_position(), 0); +} + TEST_F(TrayTest, TestMenuItemContext) { static int contextValue = 42; static bool contextCallbackInvoked = false;