Skip to content

Commit

Permalink
portal: implement window capture
Browse files Browse the repository at this point in the history
  • Loading branch information
mahkoh committed Apr 19, 2024
1 parent f060091 commit 4e10415
Show file tree
Hide file tree
Showing 27 changed files with 839 additions and 135 deletions.
1 change: 1 addition & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

- Screencasts now support window capture.
- Add support for wp-alpha-modifier.
- Add support for per-device keymaps.
- Add support for virtual-keyboard-unstable-v1.
Expand Down
12 changes: 8 additions & 4 deletions src/client/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use {
},
jay_output::JayOutput,
jay_screencast::JayScreencast,
jay_toplevel::JayToplevel,
jay_workspace::JayWorkspace,
wl_buffer::WlBuffer,
wl_display::WlDisplay,
Expand All @@ -29,10 +30,10 @@ use {
copyhashmap::{CopyHashMap, Locked},
},
wire::{
JayOutputId, JayScreencastId, JayWorkspaceId, WlBufferId, WlDataSourceId, WlOutputId,
WlPointerId, WlRegionId, WlRegistryId, WlSeatId, WlSurfaceId,
WpLinuxDrmSyncobjTimelineV1Id, XdgPositionerId, XdgSurfaceId, XdgToplevelId,
XdgWmBaseId, ZwlrDataControlSourceV1Id, ZwpPrimarySelectionSourceV1Id,
JayOutputId, JayScreencastId, JayToplevelId, JayWorkspaceId, WlBufferId,
WlDataSourceId, WlOutputId, WlPointerId, WlRegionId, WlRegistryId, WlSeatId,
WlSurfaceId, WpLinuxDrmSyncobjTimelineV1Id, XdgPositionerId, XdgSurfaceId,
XdgToplevelId, XdgWmBaseId, ZwlrDataControlSourceV1Id, ZwpPrimarySelectionSourceV1Id,
},
},
std::{cell::RefCell, mem, rc::Rc},
Expand Down Expand Up @@ -60,6 +61,7 @@ pub struct Objects {
pub screencasts: CopyHashMap<JayScreencastId, Rc<JayScreencast>>,
pub timelines: CopyHashMap<WpLinuxDrmSyncobjTimelineV1Id, Rc<WpLinuxDrmSyncobjTimelineV1>>,
pub zwlr_data_sources: CopyHashMap<ZwlrDataControlSourceV1Id, Rc<ZwlrDataControlSourceV1>>,
pub jay_toplevels: CopyHashMap<JayToplevelId, Rc<JayToplevel>>,
ids: RefCell<Vec<usize>>,
}

Expand Down Expand Up @@ -89,6 +91,7 @@ impl Objects {
screencasts: Default::default(),
timelines: Default::default(),
zwlr_data_sources: Default::default(),
jay_toplevels: Default::default(),
ids: RefCell::new(vec![]),
}
}
Expand Down Expand Up @@ -122,6 +125,7 @@ impl Objects {
self.screencasts.clear();
self.timelines.clear();
self.zwlr_data_sources.clear();
self.jay_toplevels.clear();
}

pub fn id<T>(&self, client_data: &Client) -> Result<T, ClientError>
Expand Down
5 changes: 5 additions & 0 deletions src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use {
forker,
globals::Globals,
ifs::{
jay_screencast::{perform_screencast_realloc, perform_toplevel_screencasts},
wl_output::{OutputId, PersistentOutputState, WlOutputGlobal},
wl_surface::{zwp_input_popup_surface_v2::input_popup_positioning, NoneSurfaceExt},
},
Expand Down Expand Up @@ -173,6 +174,8 @@ fn start_compositor2(
pending_float_layout: Default::default(),
pending_float_titles: Default::default(),
pending_input_popup_positioning: Default::default(),
pending_toplevel_screencasts: Default::default(),
pending_toplevel_screencast_reallocs: Default::default(),
dbus: Dbus::new(&engine, &ring, &run_toplevel),
fdcloser: FdCloser::new(),
logger: logger.clone(),
Expand Down Expand Up @@ -329,6 +332,8 @@ fn start_global_event_handlers(
eng.spawn2(Phase::PostLayout, float_titles(state.clone())),
eng.spawn2(Phase::PostLayout, idle(state.clone(), backend.clone())),
eng.spawn2(Phase::PostLayout, input_popup_positioning(state.clone())),
eng.spawn2(Phase::Present, perform_toplevel_screencasts(state.clone())),
eng.spawn2(Phase::PostLayout, perform_screencast_realloc(state.clone())),
]
}

Expand Down
2 changes: 2 additions & 0 deletions src/ifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub mod jay_render_ctx;
pub mod jay_screencast;
pub mod jay_screenshot;
pub mod jay_seat_events;
pub mod jay_select_toplevel;
pub mod jay_toplevel;
pub mod jay_workspace;
pub mod jay_workspace_watcher;
pub mod org_kde_kwin_server_decoration;
Expand Down
38 changes: 32 additions & 6 deletions src/ifs/jay_compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ use {
client::{Client, ClientError},
globals::{Global, GlobalName},
ifs::{
jay_idle::JayIdle, jay_input::JayInput, jay_log_file::JayLogFile,
jay_output::JayOutput, jay_pointer::JayPointer, jay_randr::JayRandr,
jay_render_ctx::JayRenderCtx, jay_screencast::JayScreencast,
jay_screenshot::JayScreenshot, jay_seat_events::JaySeatEvents,
jay_idle::JayIdle,
jay_input::JayInput,
jay_log_file::JayLogFile,
jay_output::JayOutput,
jay_pointer::JayPointer,
jay_randr::JayRandr,
jay_render_ctx::JayRenderCtx,
jay_screencast::JayScreencast,
jay_screenshot::JayScreenshot,
jay_seat_events::JaySeatEvents,
jay_select_toplevel::{JaySelectToplevel, JayToplevelSelector},
jay_workspace_watcher::JayWorkspaceWatcher,
},
leaks::Tracker,
Expand All @@ -18,7 +25,7 @@ use {
},
bstr::ByteSlice,
log::Level,
std::{ops::Deref, rc::Rc},
std::{cell::Cell, ops::Deref, rc::Rc},
thiserror::Error,
};

Expand Down Expand Up @@ -77,13 +84,14 @@ pub struct Cap;

impl Cap {
pub const NONE: u16 = 0;
pub const WINDOW_CAPTURE: u16 = 1;
}

impl JayCompositor {
fn send_capabilities(&self) {
self.client.event(Capabilities {
self_id: self.id,
cap: &[Cap::NONE],
cap: &[Cap::NONE, Cap::WINDOW_CAPTURE],
});
}

Expand Down Expand Up @@ -336,6 +344,24 @@ impl JayCompositorRequestHandler for JayCompositor {
self.client.add_client_obj(&sc)?;
Ok(())
}

fn select_toplevel(&self, req: SelectToplevel, _slf: &Rc<Self>) -> Result<(), Self::Error> {
let seat = self.client.lookup(req.seat)?;
let obj = Rc::new(JaySelectToplevel {
id: req.id,
client: self.client.clone(),
tracker: Default::default(),
destroyed: Cell::new(false),
});
track!(self.client, obj);
self.client.add_client_obj(&obj)?;
let selector = JayToplevelSelector {
tl: Default::default(),
jst: obj.clone(),
};
seat.global.select_toplevel(selector);
Ok(())
}
}

object_base! {
Expand Down
Loading

0 comments on commit 4e10415

Please sign in to comment.