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
3 changes: 3 additions & 0 deletions src/capi/screen_capturer_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ typedef struct {

typedef struct {
bool include_cursor;
bool exclude_own_windows;
bool crop_enabled;
native_rectangle_t crop;
} native_screen_capture_options_t;
Expand Down Expand Up @@ -108,6 +109,7 @@ inline nativeapi::CaptureSourceSelectionOptions to_cpp_capture_source_selection_
inline native_screen_capture_options_t to_c_screen_capture_options(const nativeapi::ScreenCaptureOptions& value) {
native_screen_capture_options_t result = {};
result.include_cursor = value.include_cursor;
result.exclude_own_windows = value.exclude_own_windows;
result.crop_enabled = value.crop_enabled;
result.crop = to_c_rectangle(value.crop);
return result;
Expand All @@ -116,6 +118,7 @@ inline native_screen_capture_options_t to_c_screen_capture_options(const nativea
inline nativeapi::ScreenCaptureOptions to_cpp_screen_capture_options(const native_screen_capture_options_t& value) {
nativeapi::ScreenCaptureOptions result = {};
result.include_cursor = value.include_cursor;
result.exclude_own_windows = value.exclude_own_windows;
result.crop_enabled = value.crop_enabled;
result.crop = to_cpp_rectangle(value.crop);
return result;
Expand Down
32 changes: 32 additions & 0 deletions src/capi/window_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,38 @@ bool native_window_is_always_on_top(native_window_t window) {
}
}

bool native_window_set_level(native_window_t window, native_window_level_t level) {
auto self = nativeapi::HandleTable::GetInstance().Resolve<nativeapi::Window>(window);
if (!self) {
return false;
}
try {
return self->SetLevel(to_cpp_window_level(level));
} catch (const std::exception& e) {
NATIVEAPI_LOG_ERROR("CApi", "native_window_set_level: unexpected exception: " << e.what());
return false;
} catch (...) {
NATIVEAPI_LOG_ERROR("CApi", "native_window_set_level: unexpected exception");
return false;
}
}

native_window_level_t native_window_get_level(native_window_t window) {
auto self = nativeapi::HandleTable::GetInstance().Resolve<nativeapi::Window>(window);
if (!self) {
return (native_window_level_t)NATIVE_WINDOW_LEVEL_NORMAL;
}
try {
return to_c_window_level(self->GetLevel());
} catch (const std::exception& e) {
NATIVEAPI_LOG_ERROR("CApi", "native_window_get_level: unexpected exception: " << e.what());
return (native_window_level_t)NATIVE_WINDOW_LEVEL_NORMAL;
} catch (...) {
NATIVEAPI_LOG_ERROR("CApi", "native_window_get_level: unexpected exception");
return (native_window_level_t)NATIVE_WINDOW_LEVEL_NORMAL;
}
}

void native_window_set_always_on_bottom(native_window_t window, bool is_always_on_bottom) {
auto self = nativeapi::HandleTable::GetInstance().Resolve<nativeapi::Window>(window);
if (!self) {
Expand Down
45 changes: 45 additions & 0 deletions src/capi/window_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ typedef enum {
NATIVE_WINDOW_CORNER_PREFERENCE_ROUND_SMALL = 3,
} native_window_corner_preference_t;

typedef enum {
NATIVE_WINDOW_LEVEL_NORMAL = 0,
NATIVE_WINDOW_LEVEL_FLOATING = 1,
NATIVE_WINDOW_LEVEL_STATUS = 2,
NATIVE_WINDOW_LEVEL_SCREEN_SAVER = 3,
} native_window_level_t;

typedef enum {
NATIVE_WINDOW_PROPERTY_TITLE = 0,
NATIVE_WINDOW_PROPERTY_RESIZABLE = 1,
Expand Down Expand Up @@ -363,6 +370,12 @@ void native_window_set_always_on_top(native_window_t window, bool is_always_on_t
FFI_PLUGIN_EXPORT
bool native_window_is_always_on_top(native_window_t window);

FFI_PLUGIN_EXPORT
bool native_window_set_level(native_window_t window, native_window_level_t level);

FFI_PLUGIN_EXPORT
native_window_level_t native_window_get_level(native_window_t window);

FFI_PLUGIN_EXPORT
void native_window_set_always_on_bottom(native_window_t window, bool is_always_on_bottom);

Expand Down Expand Up @@ -636,6 +649,8 @@ inline native_window_dock_side_t to_c_window_dock_side(nativeapi::WindowDockSide
inline nativeapi::WindowDockSide to_cpp_window_dock_side(native_window_dock_side_t value);
inline native_window_corner_preference_t to_c_window_corner_preference(nativeapi::WindowCornerPreference value);
inline nativeapi::WindowCornerPreference to_cpp_window_corner_preference(native_window_corner_preference_t value);
inline native_window_level_t to_c_window_level(nativeapi::WindowLevel value);
inline nativeapi::WindowLevel to_cpp_window_level(native_window_level_t value);
inline native_window_property_t to_c_window_property(nativeapi::WindowProperty value);
inline nativeapi::WindowProperty to_cpp_window_property(native_window_property_t value);
inline native_window_occlusion_state_t to_c_window_occlusion_state(nativeapi::WindowOcclusionState value);
Expand Down Expand Up @@ -723,6 +738,36 @@ inline nativeapi::WindowCornerPreference to_cpp_window_corner_preference(native_
}
}

inline native_window_level_t to_c_window_level(nativeapi::WindowLevel value) {
switch (value) {
case nativeapi::WindowLevel::Normal:
return NATIVE_WINDOW_LEVEL_NORMAL;
case nativeapi::WindowLevel::Floating:
return NATIVE_WINDOW_LEVEL_FLOATING;
case nativeapi::WindowLevel::Status:
return NATIVE_WINDOW_LEVEL_STATUS;
case nativeapi::WindowLevel::ScreenSaver:
return NATIVE_WINDOW_LEVEL_SCREEN_SAVER;
default:
return NATIVE_WINDOW_LEVEL_NORMAL;
}
}

inline nativeapi::WindowLevel to_cpp_window_level(native_window_level_t value) {
switch (value) {
case NATIVE_WINDOW_LEVEL_NORMAL:
return nativeapi::WindowLevel::Normal;
case NATIVE_WINDOW_LEVEL_FLOATING:
return nativeapi::WindowLevel::Floating;
case NATIVE_WINDOW_LEVEL_STATUS:
return nativeapi::WindowLevel::Status;
case NATIVE_WINDOW_LEVEL_SCREEN_SAVER:
return nativeapi::WindowLevel::ScreenSaver;
default:
return static_cast<nativeapi::WindowLevel>(value);
}
}

inline native_window_property_t to_c_window_property(nativeapi::WindowProperty value) {
switch (value) {
case nativeapi::WindowProperty::Title:
Expand Down
8 changes: 8 additions & 0 deletions src/platform/android/window_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ bool Window::IsAlwaysOnTop() const {
return false;
}

bool Window::SetLevel(WindowLevel /*level*/) {
return false;
}

WindowLevel Window::GetLevel() const {
return WindowLevel::Normal;
}

void Window::SetAlwaysOnBottom(bool is_always_on_bottom) {
}

Expand Down
8 changes: 8 additions & 0 deletions src/platform/ios/window_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@
return false;
}

bool Window::SetLevel(WindowLevel /*level*/) {
return false;
}

WindowLevel Window::GetLevel() const {
return WindowLevel::Normal;
}

void Window::SetAlwaysOnBottom(bool is_always_on_bottom) {
// Not applicable to iOS
}
Expand Down
32 changes: 32 additions & 0 deletions src/platform/linux/window_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,22 @@ bool Window::IsAlwaysOnTop() const {
return pimpl_->always_on_top_;
}

bool Window::SetLevel(WindowLevel level) {
if (!pimpl_->widget_) return false;
SetAlwaysOnTop(level != WindowLevel::Normal);
g_object_set_data(G_OBJECT(pimpl_->widget_), "NativeAPIGtk4WindowLevel",
GINT_TO_POINTER(static_cast<int>(level)));
return true;
}

WindowLevel Window::GetLevel() const {
if (!pimpl_->widget_ || !IsAlwaysOnTop()) return WindowLevel::Normal;
int stored = GPOINTER_TO_INT(
g_object_get_data(G_OBJECT(pimpl_->widget_), "NativeAPIGtk4WindowLevel"));
auto level = static_cast<WindowLevel>(stored);
return level == WindowLevel::Normal ? WindowLevel::Floating : level;
}

void Window::SetAlwaysOnBottom(bool is_always_on_bottom) {
pimpl_->always_on_bottom_ = is_always_on_bottom;
if (is_always_on_bottom) {
Expand Down Expand Up @@ -3028,6 +3044,22 @@ bool Window::IsAlwaysOnTop() const {
return state & GDK_WINDOW_STATE_ABOVE;
}

bool Window::SetLevel(WindowLevel level) {
if (!pimpl_->gtk_window_) return false;
SetAlwaysOnTop(level != WindowLevel::Normal);
g_object_set_data(G_OBJECT(pimpl_->gtk_window_), "NativeAPIWindowLevel",
GINT_TO_POINTER(static_cast<int>(level)));
return true;
}

WindowLevel Window::GetLevel() const {
if (!pimpl_->gtk_window_ || !IsAlwaysOnTop()) return WindowLevel::Normal;
int stored = GPOINTER_TO_INT(
g_object_get_data(G_OBJECT(pimpl_->gtk_window_), "NativeAPIWindowLevel"));
auto level = static_cast<WindowLevel>(stored);
return level == WindowLevel::Normal ? WindowLevel::Floating : level;
}

void Window::SetAlwaysOnBottom(bool is_always_on_bottom) {
detail::WindowPropertyScope property_scope(*this);
// GDK clears _NET_WM_STATE_ABOVE when setting BELOW and vice versa, so the two
Expand Down
21 changes: 18 additions & 3 deletions src/platform/macos/screen_capture_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <cstring>
#include <mutex>
#include <thread>
#include <unistd.h>
#include <utility>

#include "../../display.h"
Expand Down Expand Up @@ -296,9 +297,23 @@ CaptureSourceType Type() const override {
}];
if (!completion->Wait(cancel, error)) return nullptr;
if (kind == CaptureSourceType::Display) {
for (SCDisplay* item in completion->content.get().displays)
if (item.displayID == identity) filter = Obj<SCContentFilter*>(Autorelease(
[[SCContentFilter alloc] initWithDisplay:item excludingWindows:@[]]));
NSMutableArray<SCRunningApplication*>* excluded_apps = [NSMutableArray array];
if (options.exclude_own_windows) {
const pid_t self_pid = getpid();
for (SCRunningApplication* app in completion->content.get().applications) {
if (app.processID == self_pid) [excluded_apps addObject:app];
}
}
for (SCDisplay* item in completion->content.get().displays) {
if (item.displayID == identity) {
filter = Obj<SCContentFilter*>(Autorelease(
excluded_apps.count > 0
? [[SCContentFilter alloc] initWithDisplay:item
excludingApplications:excluded_apps
exceptingWindows:@[]]
: [[SCContentFilter alloc] initWithDisplay:item excludingWindows:@[]]));
}
}
} else {
for (SCWindow* item in completion->content.get().windows)
if (item.windowID == identity) filter = Obj<SCContentFilter*>(Autorelease(
Expand Down
Loading
Loading