Skip to content

Commit

Permalink
Merge remote-tracking branch 'hmh/master' into pr1
Browse files Browse the repository at this point in the history
  • Loading branch information
lyonbot committed Oct 30, 2024
2 parents 0ddb4f7 + 00a19aa commit f5d4ac4
Show file tree
Hide file tree
Showing 19 changed files with 845 additions and 143 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-macos:
runs-on: macOS-latest
strategy:
matrix:
os: [macos-latest, macos-13] # -latest if for Apple Silicon, -13 is for Intel
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
Expand All @@ -114,13 +117,15 @@ jobs:
# run: MACOSX_DEPLOYMENT_TARGET=10.13 cargo bundle --release
run: cargo bundle --release
- name: Package
run: cd target/release/bundle/osx/ && zip -r macOS.zip Weylus.app
run: |
MACOS_BUILD_NAME=macos-$([ "${{ matrix.os }}" == "macos-latest" ] && echo "arm" || echo "intel")
echo "MACOS_BUILD_NAME=$MACOS_BUILD_NAME" >> $GITHUB_ENV
cd target/release/bundle/osx/ && zip -r ${MACOS_BUILD_NAME}.zip Weylus.app
- name: Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ runner.os }}
path: |
target/release/bundle/osx/macOS.zip
name: ${{ env.MACOS_BUILD_NAME }}
path: target/release/bundle/osx/${{ env.MACOS_BUILD_NAME }}.zip
- name: ArtifactsDebug
if: failure()
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion deps/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -ex

test -d x264 || git clone --depth 1 -b stable https://code.videolan.org/videolan/x264.git x264
test -d ffmpeg || git clone --depth 1 -b n7.0.2 https://git.ffmpeg.org/ffmpeg.git ffmpeg
test -d ffmpeg || git clone --depth 1 -b n7.1 https://git.ffmpeg.org/ffmpeg.git ffmpeg
if [ "$TARGET_OS" == "linux" ]; then
test -d nv-codec-headers || git clone --depth 1 https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
test -d libva || git clone --depth 1 -b 2.22.0 https://github.com/intel/libva
Expand Down
6 changes: 4 additions & 2 deletions lib/linux/xhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ int x11_error_handler(Display* disp, XErrorEvent* err)
return 0;
}

void x11_set_error_handler() {
void x11_set_error_handler()
{
// setting an error handler is required as otherwise xlib may just exit the process, even though
// the error was recoverable.
XSetErrorHandler(x11_error_handler);
Expand Down Expand Up @@ -176,7 +177,8 @@ Window* get_client_list(Display* disp, unsigned long* size, Error* err)
return client_list;
}

int create_capturables(Display* disp, Capturable** capturables, int* num_monitors, int size, Error* err)
int create_capturables(
Display* disp, Capturable** capturables, int* num_monitors, int size, Error* err)
{
if (size <= 0)
return 0;
Expand Down
2 changes: 2 additions & 0 deletions src/capturable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod core_graphics;
#[cfg(target_os = "linux")]
pub mod pipewire;
#[cfg(target_os = "linux")]
#[allow(dead_code)]
pub mod remote_desktop_dbus;
pub mod testsrc;

Expand Down Expand Up @@ -37,6 +38,7 @@ where
/// VirtualScreen: offset_x, offset_y, width, height for a capturable using a virtual screen. (Windows)
pub enum Geometry {
Relative(f64, f64, f64, f64),
#[cfg(target_os = "windows")]
VirtualScreen(i32, i32, u32, u32, i32, i32),
}

Expand Down
36 changes: 20 additions & 16 deletions src/capturable/pipewire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ struct CallBackContext {
streams: Vec<PwStreamInfo>,
fd: Option<OwnedFd>,
restore_token: Option<String>,
is_plasma: bool,
has_remote_desktop: bool,
failure: bool,
}

Expand All @@ -387,10 +387,10 @@ fn on_create_session_response(
.into();

context.lock().unwrap().session = session.clone();
if context.lock().unwrap().is_plasma {
select_sources(portal, context)
} else {
if context.lock().unwrap().has_remote_desktop {
select_devices(portal, context)
} else {
select_sources(portal, context)
}
}

Expand Down Expand Up @@ -461,7 +461,8 @@ fn select_sources(
// 4: Metadata: The cursor is not part of the screen cast stream, but sent as PipeWire stream metadata.
let cursor_mode = if capture_cursor { 2u32 } else { 1u32 };

if context.lock().unwrap().is_plasma && capture_cursor {
let is_plasma = std::env::var("DESKTOP_SESSION").map_or(false, |s| s.contains("plasma"));
if is_plasma && capture_cursor {
// Warn the user if capturing the cursor is tried on kde as this can crash
// kwin_wayland and tear down the plasma desktop, see:
// https://bugs.kde.org/show_bug.cgi?id=435042
Expand Down Expand Up @@ -491,15 +492,15 @@ fn on_select_sources_response(
"handle_token".to_string(),
Variant(Box::new(format!("weylus{t}"))),
);
let path = if context.lock().unwrap().is_plasma {
OrgFreedesktopPortalScreenCast::start(
let path = if context.lock().unwrap().has_remote_desktop {
OrgFreedesktopPortalRemoteDesktop::start(
&portal,
context.lock().unwrap().session.clone(),
"",
args,
)?
} else {
OrgFreedesktopPortalRemoteDesktop::start(
OrgFreedesktopPortalScreenCast::start(
&portal,
context.lock().unwrap().session.clone(),
"",
Expand Down Expand Up @@ -527,10 +528,10 @@ fn on_start_response(
context.restore_token = Some(t.to_string());
}
dbg!(&context.restore_token);
if context.is_plasma {
debug!("Screen Cast Session started");
} else {
if context.has_remote_desktop {
debug!("Remote Desktop Session started");
} else {
debug!("Screen Cast Session started");
}
Ok(())
}
Expand All @@ -541,15 +542,18 @@ fn request_remote_desktop(
let conn = SyncConnection::new_session()?;
let portal = get_portal(&conn);

let is_plasma = std::env::var("DESKTOP_SESSION").map_or(false, |s| s.contains("plasma"));
// Disabled for KDE plasma due to https://bugs.kde.org/show_bug.cgi?id=484996
// List of supported DEs: https://wiki.archlinux.org/title/XDG_Desktop_Portal#List_of_backends_and_interfaces
let has_remote_desktop =
std::env::var("DESKTOP_SESSION").map_or(false, |s| s.contains("gnome"));

let context = CallBackContext {
capture_cursor,
session: Default::default(),
streams: Default::default(),
fd: None,
restore_token: None,
is_plasma,
has_remote_desktop,
failure: false,
};
let context = Arc::new(Mutex::new(context));
Expand All @@ -565,10 +569,10 @@ fn request_remote_desktop(
"handle_token".to_string(),
Variant(Box::new(format!("weylus{t2}"))),
);
let path = if is_plasma {
OrgFreedesktopPortalScreenCast::create_session(&portal, args)?
} else {
let path = if has_remote_desktop {
OrgFreedesktopPortalRemoteDesktop::create_session(&portal, args)?
} else {
OrgFreedesktopPortalScreenCast::create_session(&portal, args)?
};
handle_response(portal, path, context.clone(), on_create_session_response)?;

Expand Down
Loading

0 comments on commit f5d4ac4

Please sign in to comment.