Skip to content

Commit

Permalink
Merge pull request #186 from mahkoh/drm-lease
Browse files Browse the repository at this point in the history
wayland: implement wp-drm-lease-v1
  • Loading branch information
mahkoh authored Apr 26, 2024
2 parents 5b851ef + abbc847 commit fe2663f
Show file tree
Hide file tree
Showing 41 changed files with 1,622 additions and 170 deletions.
2 changes: 2 additions & 0 deletions deploy-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

- Needs jay-compositor release.

# 1.1.0

- Needs jay-config release.
Expand Down
5 changes: 5 additions & 0 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ You can explicitly opt into giving applications access to privileged protocols v

Jay's shortcut system allows you to execute an action when a key is pressed and to execute a different action when the key is released.

## VR

Jay's supports leasing VR headsets to applications.

## Protocol Support

Jay supports the following wayland protocols:
Expand All @@ -139,6 +143,7 @@ Jay supports the following wayland protocols:
| wp_alpha_modifier_v1 | 1 | |
| wp_content_type_manager_v1 | 1 | |
| wp_cursor_shape_manager_v1 | 1 | |
| wp_drm_lease_device_v1 | 1 | |
| wp_fractional_scale_manager_v1 | 1 | |
| wp_linux_drm_syncobj_manager_v1 | 1 | |
| wp_presentation | 1 | |
Expand Down
1 change: 1 addition & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Add support for wp-security-manager-v1.
- Add support for xdg-dialog-v1.
- Add support for ext-transient-seat-v1.
- Add support for wp-drm-lease-v1.

# 1.1.0 (2024-04-22)

Expand Down
4 changes: 2 additions & 2 deletions src/acceptor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use {
crate::{
async_engine::SpawnedFuture,
client::{ClientCaps, CAP_LAYER_SHELL},
client::{ClientCaps, CAPS_DEFAULT},
state::State,
utils::{errorfmt::ErrorFmt, oserror::OsError, xrd::xrd},
},
Expand Down Expand Up @@ -154,7 +154,7 @@ impl Acceptor {
state.eng.spawn(accept(
acc.socket.insecure.clone(),
state.clone(),
CAP_LAYER_SHELL,
CAPS_DEFAULT,
)),
];
state.acceptor.set(Some(acc.clone()));
Expand Down
29 changes: 27 additions & 2 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
gfx_api::{GfxFramebuffer, SyncFile},
ifs::wl_seat::wl_pointer::{CONTINUOUS, FINGER, HORIZONTAL_SCROLL, VERTICAL_SCROLL, WHEEL},
libinput::consts::DeviceCapability,
video::drm::{ConnectorType, DrmError, DrmVersion},
video::drm::{ConnectorType, DrmConnector, DrmError, DrmVersion},
},
jay_config::video::GfxApi,
std::{
Expand All @@ -15,7 +15,7 @@ use {
fmt::{Debug, Display, Formatter},
rc::Rc,
},
uapi::c,
uapi::{c, OwnedFd},
};

linear_ids!(ConnectorIds, ConnectorId);
Expand Down Expand Up @@ -59,6 +59,7 @@ pub struct MonitorInfo {
pub initial_mode: Mode,
pub width_mm: i32,
pub height_mm: i32,
pub non_desktop: bool,
}

#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -90,6 +91,12 @@ pub trait Connector {
None
}
fn set_mode(&self, mode: Mode);
fn set_non_desktop_override(&self, non_desktop: Option<bool>) {
let _ = non_desktop;
}
fn drm_object_id(&self) -> Option<DrmConnector> {
None
}
}

#[derive(Debug)]
Expand All @@ -99,6 +106,8 @@ pub enum ConnectorEvent {
Disconnected,
Removed,
ModeChanged(Mode),
Unavailable,
Available,
}

pub trait HardwareCursor: Debug {
Expand Down Expand Up @@ -282,4 +291,20 @@ pub trait BackendDrmDevice {
fn version(&self) -> Result<DrmVersion, DrmError>;
fn set_direct_scanout_enabled(&self, enabled: bool);
fn is_render_device(&self) -> bool;
fn create_lease(
self: Rc<Self>,
lessee: Rc<dyn BackendDrmLessee>,
connector_ids: &[ConnectorId],
) {
let _ = lessee;
let _ = connector_ids;
}
}

pub trait BackendDrmLease {
fn fd(&self) -> &Rc<OwnedFd>;
}

pub trait BackendDrmLessee {
fn created(&self, lease: Rc<dyn BackendDrmLease>);
}
35 changes: 32 additions & 3 deletions src/backends/metal/monitor.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use {
crate::{
backend::BackendEvent,
backend::{BackendEvent, ConnectorEvent},
backends::metal::{
video::{MetalDrmDeviceData, PendingDrmDevice},
video::{FrontState, MetalDrmDeviceData, PendingDrmDevice},
MetalBackend, MetalDevice, MetalError, MetalInputDevice,
},
dbus::{DbusError, TRUE},
udev::UdevDevice,
utils::{bitflags::BitflagsExt, errorfmt::ErrorFmt, nonblock::set_nonblock},
utils::{
bitflags::BitflagsExt, cell_ext::CellExt, errorfmt::ErrorFmt, nonblock::set_nonblock,
},
video::drm::DrmMaster,
wire_dbus::org::freedesktop::login1::session::{
PauseDevice, ResumeDevice, TakeDeviceReply,
Expand Down Expand Up @@ -89,6 +91,18 @@ impl MetalBackend {

fn handle_drm_device_resume(self: &Rc<Self>, dev: &Rc<MetalDrmDeviceData>, _fd: Rc<OwnedFd>) {
log::info!("Device resumed: {}", dev.dev.devnode.to_bytes().as_bstr());
dev.dev.paused.set(false);
self.break_leases(dev);
for c in dev.connectors.lock().values() {
match c.frontend_state.get() {
FrontState::Removed | FrontState::Disconnected | FrontState::Connected { .. } => {}
FrontState::Unavailable => {
if c.lease.is_none() {
c.send_event(ConnectorEvent::Available);
}
}
}
}
if let Err(e) = self.resume_drm_device(dev) {
log::error!("Could not resume drm device: {}", ErrorFmt(e));
}
Expand Down Expand Up @@ -149,6 +163,21 @@ impl MetalBackend {
}

fn handle_drm_device_paused(self: &Rc<Self>, dev: &Rc<MetalDrmDeviceData>) {
dev.dev.paused.set(true);
for c in dev.connectors.lock().values() {
match c.frontend_state.get() {
FrontState::Removed
| FrontState::Disconnected
| FrontState::Unavailable
| FrontState::Connected { non_desktop: false } => {}
FrontState::Connected { non_desktop: true } => {
c.send_event(ConnectorEvent::Unavailable);
}
}
}
for (lease_id, lease) in dev.dev.leases.lock().drain() {
dev.dev.leases_to_break.set(lease_id, lease);
}
log::info!("Device paused: {}", dev.dev.devnode.to_bytes().as_bstr());
}

Expand Down
Loading

0 comments on commit fe2663f

Please sign in to comment.