Skip to content

Commit

Permalink
Merge pull request #201 from pop-os/smithay-update
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix authored Oct 20, 2023
2 parents cff4340 + 5268e06 commit 0f29b02
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 55 deletions.
35 changes: 13 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ once_cell = "1.18.0"
i18n-embed = { version = "0.14", features = ["fluent-system", "desktop-requester"] }
i18n-embed-fl = "0.7"
rust-embed = "8.0"
libc = "0.2.149"

[dependencies.id_tree]
git = "https://github.com/Drakulix/id-tree.git"
Expand Down Expand Up @@ -87,7 +88,7 @@ debug = true
lto = "fat"

[patch."https://github.com/Smithay/smithay.git"]
smithay = { git = "https://github.com/smithay//smithay", rev = "d60b1b83e" }
smithay = { git = "https://github.com/smithay//smithay", rev = "988c94d7e" }

[patch.crates-io]
calloop = { git = "https://github.com/Smithay/calloop", rev = "71b6e633b1" }
34 changes: 16 additions & 18 deletions src/backend/kms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{

use anyhow::{Context, Result};
use cosmic_protocols::screencopy::v1::server::zcosmic_screencopy_session_v1::FailureReason;
use libc::dev_t;
use smithay::{
backend::{
allocator::{
Expand Down Expand Up @@ -58,7 +59,7 @@ use smithay::{
Device as _,
},
input::{self, Libinput},
nix::{fcntl::OFlag, sys::stat::dev_t},
rustix::fs::OFlags,
wayland_protocols::wp::{
linux_dmabuf::zv1::server::zwp_linux_dmabuf_feedback_v1,
presentation_time::server::wp_presentation_feedback,
Expand All @@ -82,7 +83,6 @@ use std::{
collections::{HashMap, HashSet},
ffi::CStr,
fmt,
os::unix::io::FromRawFd,
path::PathBuf,
time::Duration,
};
Expand Down Expand Up @@ -418,23 +418,21 @@ impl State {
return Ok(());
}

let fd = DrmDeviceFd::new(unsafe {
DeviceFd::from_raw_fd(
self.backend
.kms()
.session
.open(
&path,
OFlag::O_RDWR | OFlag::O_CLOEXEC | OFlag::O_NOCTTY | OFlag::O_NONBLOCK,
let fd = DrmDeviceFd::new(DeviceFd::from(
self.backend
.kms()
.session
.open(
&path,
OFlags::RDWR | OFlags::CLOEXEC | OFlags::NOCTTY | OFlags::NONBLOCK,
)
.with_context(|| {
format!(
"Failed to optain file descriptor for drm device: {}",
path.display()
)
.with_context(|| {
format!(
"Failed to optain file descriptor for drm device: {}",
path.display()
)
})?,
)
});
})?,
));
let (drm, notifier) = DrmDevice::new(fd.clone(), false)
.with_context(|| format!("Failed to initialize drm device for: {}", path.display()))?;
let drm_node = DrmNode::from_dev_id(dev)?;
Expand Down
20 changes: 12 additions & 8 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use smithay::reexports::{
calloop::{generic::Generic, Interest, LoopHandle, Mode, PostAction},
nix::{fcntl, unistd},
rustix,
};

use anyhow::{anyhow, Context, Result};
Expand Down Expand Up @@ -50,20 +50,24 @@ impl From<UnixStream> for StreamWrapper {
}
}

unsafe fn set_cloexec(fd: RawFd) -> rustix::io::Result<()> {
if fd == -1 {
return Err(rustix::io::Errno::BADF);
}
let fd = BorrowedFd::borrow_raw(fd);
let flags = rustix::io::fcntl_getfd(fd)?;
rustix::io::fcntl_setfd(fd, flags | rustix::io::FdFlags::CLOEXEC)
}

pub fn setup_socket(handle: LoopHandle<State>, state: &State) -> Result<()> {
if let Ok(fd_num) = std::env::var("COSMIC_SESSION_SOCK") {
if let Ok(fd) = fd_num.parse::<RawFd>() {
// set CLOEXEC
let flags = fcntl::fcntl(fd, fcntl::FcntlArg::F_GETFD);
let result = flags
.map(|f| fcntl::FdFlag::from_bits(f).unwrap() | fcntl::FdFlag::FD_CLOEXEC)
.and_then(|f| fcntl::fcntl(fd, fcntl::FcntlArg::F_SETFD(f)));
let mut session_socket = match result {
let mut session_socket = match unsafe { set_cloexec(fd) } {
// CLOEXEC worked and we can startup with session IPC
Ok(_) => unsafe { UnixStream::from_raw_fd(fd) },
// CLOEXEC didn't work, something is wrong with the fd, just close it
Err(err) => {
let _ = unistd::close(fd);
unsafe { rustix::io::close(fd) };
return Err(err).with_context(|| "Failed to setup session socket");
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/shell/grabs/moving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ impl MoveGrab {
None
};

handle.unset_grab(state, serial, time);
handle.unset_grab(state, serial, time, true);

{
let cursor_state = self.seat.user_data().get::<CursorState>().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/shell/layout/floating/grabs/resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl PointerGrab<State> for ResizeSurfaceGrab {

// It is impossible to get `min_size` and `max_size` of dead toplevel, so we return early.
if !self.window.alive() {
handle.unset_grab(data, event.serial, event.time);
handle.unset_grab(data, event.serial, event.time, true);
return;
}

Expand Down Expand Up @@ -129,7 +129,7 @@ impl PointerGrab<State> for ResizeSurfaceGrab {
handle.button(data, event);
if handle.current_pressed().is_empty() {
// No more buttons are pressed, release the grab.
handle.unset_grab(data, event.serial, event.time);
handle.unset_grab(data, event.serial, event.time, true);

// If toplevel is dead, we can't resize it, so we return early.
if !self.window.alive() {
Expand Down
6 changes: 3 additions & 3 deletions src/shell/layout/tiling/grabs/resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl PointerGrab<State> for ResizeForkGrab {
let first_elem = iter.next();
let second_elem = iter.next();
if first_elem.is_none() || second_elem.is_none() {
return handle.unset_grab(data, event.serial, event.time);
return handle.unset_grab(data, event.serial, event.time, true);
};

match tree.get_mut(&self.node).unwrap().data_mut() {
Expand Down Expand Up @@ -196,7 +196,7 @@ impl PointerGrab<State> for ResizeForkGrab {
let blocker = TilingLayout::update_positions(&output, tree, gaps);
tiling_layer.pending_blockers.extend(blocker);
} else {
handle.unset_grab(data, event.serial, event.time);
handle.unset_grab(data, event.serial, event.time, true);
}
}
}
Expand All @@ -221,7 +221,7 @@ impl PointerGrab<State> for ResizeForkGrab {
handle.button(data, event);
if handle.current_pressed().is_empty() {
// No more buttons are pressed, release the grab.
handle.unset_grab(data, event.serial, event.time);
handle.unset_grab(data, event.serial, event.time, true);
}
}

Expand Down

0 comments on commit 0f29b02

Please sign in to comment.