Skip to content
Merged
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
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,25 @@ This fork adds the following features:
## 🖼️ Screenshots

<div class="tabbed">
<ul>
<li><b class="tab-title">Linux</b><br>
![linux](docs/images/screenshot_linux.png)
</li>
<li><b class="tab-title">macOS</b><br>
![macOS](docs/images/screenshot_macos.png)
</li>
<li><b class="tab-title">Windows</b><br>
![windows](docs/images/screenshot_windows.png)
</li>
</ul>
<ul>
<li><b class="tab-title">Linux</b><br>

![Linux tray menu](docs/images/tray_menu_left_click_linux.png)
![Linux notification](docs/images/tray_notification_svg_icon_linux.png)

</li>
<li><b class="tab-title">macOS</b><br>

![macOS tray menu](docs/images/tray_menu_left_click_macos.png)

</li>
<li><b class="tab-title">Windows</b><br>

![Windows tray menu](docs/images/tray_menu_left_click_windows.png)
![Windows notification](docs/images/tray_notification_svg_icon_windows.png)

</li>
</ul>
</div>

## 🖥️ Supported platforms
Expand Down
Binary file removed docs/images/screenshot_linux.png
Binary file not shown.
Binary file removed docs/images/screenshot_macos.png
Binary file not shown.
Binary file removed docs/images/screenshot_windows.png
Binary file not shown.
Binary file added docs/images/tray_menu_left_click_linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/tray_menu_left_click_macos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/tray_menu_left_click_windows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/tray_notification_svg_icon_linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
53 changes: 49 additions & 4 deletions tests/screenshot_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#include <string>
#include <thread>
#include <vector>
#if defined(__linux__) || defined(__APPLE__)
// qt includes
#include <QImage>
#include <QString>
#endif
#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
Expand All @@ -21,7 +26,14 @@
// clang-format on
#endif

// lib includes
#include <lizardbyte/common/env.h>

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();
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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;
Expand Down
29 changes: 23 additions & 6 deletions tests/unit/test_tray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,19 @@ 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();
}
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 *) {
Expand Down Expand Up @@ -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;
Expand Down
Loading