Skip to content

Commit

Permalink
Update sctk
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Oct 26, 2023
1 parent a9bddc5 commit d0f3b08
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 93 deletions.
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bitflags = "1.2"
thiserror = "1"
log = "0.4.17"
twox-hash = { version = "1.5", default-features = false }
sctk = { package = "smithay-client-toolkit", git = "https://github.com/smithay/client-toolkit", rev = "dc8c4a0", optional = true }
sctk = { package = "smithay-client-toolkit", git = "https://github.com/smithay/client-toolkit", rev = "828b1eb", optional = true }

[dependencies.palette]
version = "0.7"
Expand Down
2 changes: 1 addition & 1 deletion examples/sctk_drag/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
sctk = { package = "smithay-client-toolkit", git = "https://github.com/smithay/client-toolkit", rev = "dc8c4a0" }
sctk = { package = "smithay-client-toolkit", git = "https://github.com/smithay/client-toolkit", rev = "828b1eb" }
iced = { path = "../..", default-features = false, features = ["wayland", "debug", "a11y"] }
iced_style = { path = "../../style" }
env_logger = "0.10"
Expand Down
2 changes: 1 addition & 1 deletion examples/sctk_todos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ iced = { path = "../..", default-features=false, features = ["async-std", "wayla
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
once_cell = "1.15"
sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", rev = "dc8c4a0" }
sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", rev = "828b1eb" }
iced_style = { path = "../../style" }

log = "0.4.17"
Expand Down
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ wayland = ["iced_accessibility?/accesskit_unix", "iced_core/wayland", "sctk"]

[dependencies]
thiserror = "1"
sctk = { package = "smithay-client-toolkit", git = "https://github.com/smithay/client-toolkit", rev = "dc8c4a0", optional = true }
sctk = { package = "smithay-client-toolkit", git = "https://github.com/smithay/client-toolkit", rev = "828b1eb", optional = true }

[dependencies.iced_core]
version = "0.10"
Expand Down
2 changes: 1 addition & 1 deletion sctk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ a11y = ["iced_accessibility", "iced_runtime/a11y"]
[dependencies]
tracing = "0.1"
thiserror = "1.0"
sctk = { package = "smithay-client-toolkit", git = "https://github.com/smithay/client-toolkit", rev = "dc8c4a0" }
sctk = { package = "smithay-client-toolkit", git = "https://github.com/smithay/client-toolkit", rev = "828b1eb" }
wayland-protocols = { version = "0.31.0", features = [ "staging"]}
# sctk = { package = "smithay-client-toolkit", path = "../../fork/client-toolkit/" }
raw-window-handle = "0.5"
Expand Down
22 changes: 11 additions & 11 deletions sctk/src/event_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use sctk::{
data_device_manager::DataDeviceManagerState,
output::OutputState,
reexports::{
calloop::{self, EventLoop},
calloop::{self, EventLoop, PostAction},
client::{
globals::registry_queue_init, protocol::wl_surface::WlSurface,
ConnectError, Connection, DispatchError, Proxy,
Expand Down Expand Up @@ -1157,11 +1157,11 @@ where
match self.event_loop.handle().insert_source(read_pipe, move |_, f, state| {
let mut dnd_offer = match state.dnd_offer.take() {
Some(s) => s,
None => return,
None => return PostAction::Continue,
};
let (mime_type, data, token) = match dnd_offer.cur_read.take() {
Some(s) => s,
None => return,
None => return PostAction::Continue,
};
let mut reader = BufReader::new(f.as_ref());
let consumed = match reader.fill_buf() {
Expand All @@ -1185,18 +1185,18 @@ where
Err(e) if matches!(e.kind(), std::io::ErrorKind::Interrupted) => {
dnd_offer.cur_read = Some((mime_type, data, token));
state.dnd_offer = Some(dnd_offer);
return;
return PostAction::Continue;
},
Err(e) => {
error!("Error reading selection data: {}", e);
loop_handle.remove(token);
if !dnd_offer.dropped {
state.dnd_offer = Some(dnd_offer);
}
return;
return PostAction::Remove;
},
};
reader.consume(consumed);
PostAction::Continue
}) {
Ok(token) => {
dnd_offer.cur_read = Some((mime_type.clone(), Vec::new(), token));
Expand All @@ -1215,11 +1215,11 @@ where
match self.event_loop.handle().insert_source(read_pipe, move |_, f, state| {
let selection_offer = match state.selection_offer.as_mut() {
Some(s) => s,
None => return,
None => return PostAction::Continue,
};
let (mime_type, data, token) = match selection_offer.cur_read.take() {
Some(s) => s,
None => return,
None => return PostAction::Continue,
};
let mut reader = BufReader::new(f.as_ref());
let consumed = match reader.fill_buf() {
Expand All @@ -1236,15 +1236,15 @@ where
},
Err(e) if matches!(e.kind(), std::io::ErrorKind::Interrupted) => {
selection_offer.cur_read = Some((mime_type, data, token));
return;
return PostAction::Continue;
},
Err(e) => {
error!("Error reading selection data: {}", e);
loop_handle.remove(token);
return;
return PostAction::Continue;
},
};
reader.consume(consumed);
PostAction::Continue
}) {
Ok(token) => {
selection_offer.cur_read = Some((mime_type.clone(), Vec::new(), token));
Expand Down
174 changes: 97 additions & 77 deletions sctk/src/handlers/data_device/data_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ use crate::sctk_event::{DataSourceEvent, SctkEvent};
use sctk::data_device_manager::WritePipe;
use sctk::{
data_device_manager::data_source::DataSourceHandler,
reexports::client::{
protocol::{
wl_data_device_manager::DndAction, wl_data_source::WlDataSource,
reexports::{
calloop::PostAction,
client::{
protocol::{
wl_data_device_manager::DndAction, wl_data_source::WlDataSource,
},
Connection, QueueHandle,
},
Connection, QueueHandle,
},
};
use std::io::{BufWriter, Write};
Expand Down Expand Up @@ -62,50 +65,62 @@ impl<T> DataSourceHandler for SctkState<T> {
.as_mut()
.filter(|s| s.source.inner() == source)
{
match self.loop_handle.insert_source(pipe, move |_, f, state| {
let loop_handle = &state.loop_handle;
let selection_source = match state.selection_source.as_mut() {
Some(s) => s,
None => return,
};
let (data, mut cur_index, token) =
match selection_source.cur_write.take() {
match self.loop_handle.insert_source(
pipe,
move |_, f, state| -> PostAction {
let selection_source = match state.selection_source.as_mut()
{
Some(s) => s,
None => return,
None => {
return PostAction::Continue;
}
};
let mut writer = BufWriter::new(f.as_ref());
let slice = &data.as_slice()[cur_index
..(cur_index + writer.capacity()).min(data.len())];
match writer.write(slice) {
Ok(num_written) => {
cur_index += num_written;
if cur_index == data.len() {
loop_handle.remove(token);
} else {
let (data, mut cur_index, token) =
match selection_source.cur_write.take() {
Some(s) => s,
None => {
return PostAction::Continue;
}
};
let mut writer = BufWriter::new(f.as_ref());
let slice = &data.as_slice()[cur_index
..(cur_index + writer.capacity()).min(data.len())];
match writer.write(slice) {
Ok(num_written) => {
cur_index += num_written;
let done = cur_index == data.len();
if !done {
selection_source.cur_write =
Some((data, cur_index, token));
}
if let Err(err) = writer.flush() {
error!("Failed to flush pipe: {}", err);
return PostAction::Remove;
}
if done {
PostAction::Remove
} else {
PostAction::Continue
}
}
Err(e)
if matches!(
e.kind(),
std::io::ErrorKind::Interrupted
) =>
{
// try again
selection_source.cur_write =
Some((data, cur_index, token));
PostAction::Continue
}
if let Err(err) = writer.flush() {
loop_handle.remove(token);
error!("Failed to flush pipe: {}", err);
Err(_) => {
error!("Failed to write to pipe");
PostAction::Remove
}
}
Err(e)
if matches!(
e.kind(),
std::io::ErrorKind::Interrupted
) =>
{
// try again
selection_source.cur_write =
Some((data, cur_index, token));
}
Err(_) => {
loop_handle.remove(token);
error!("Failed to write to pipe");
}
};
}) {
},
) {
Ok(s) => {
my_source.cur_write = Some((
my_source
Expand All @@ -130,49 +145,54 @@ impl<T> DataSourceHandler for SctkState<T> {
Some((source, data)) => (source, data),
None => return,
};
match self.loop_handle.insert_source(pipe, move |_, f, state| {
let loop_handle = &state.loop_handle;
let dnd_source = match state.dnd_source.as_mut() {
Some(s) => s,
None => return,
};
let (data, mut cur_index, token) =
match dnd_source.cur_write.take() {
match self.loop_handle.insert_source(
pipe,
move |_, f, state| -> PostAction {
let loop_handle = &state.loop_handle;
let dnd_source = match state.dnd_source.as_mut() {
Some(s) => s,
None => return,
None => return PostAction::Continue,
};
let mut writer = BufWriter::new(f.as_ref());
let slice = &data.as_slice()[cur_index
..(cur_index + writer.capacity()).min(data.len())];
match writer.write(slice) {
Ok(num_written) => {
cur_index += num_written;
if cur_index == data.len() {
loop_handle.remove(token);
} else {
let (data, mut cur_index, token) =
match dnd_source.cur_write.take() {
Some(s) => s,
None => return PostAction::Continue,
};
let mut writer = BufWriter::new(f.as_ref());
let slice = &data.as_slice()[cur_index
..(cur_index + writer.capacity()).min(data.len())];
match writer.write(slice) {
Ok(num_written) => {
cur_index += num_written;
if cur_index == data.len() {
loop_handle.remove(token);
} else {
dnd_source.cur_write =
Some((data, cur_index, token));
}
if let Err(err) = writer.flush() {
loop_handle.remove(token);
error!("Failed to flush pipe: {}", err);
}
}
Err(e)
if matches!(
e.kind(),
std::io::ErrorKind::Interrupted
) =>
{
// try again
dnd_source.cur_write =
Some((data, cur_index, token));
}
if let Err(err) = writer.flush() {
Err(_) => {
loop_handle.remove(token);
error!("Failed to flush pipe: {}", err);
error!("Failed to write to pipe");
}
}
Err(e)
if matches!(
e.kind(),
std::io::ErrorKind::Interrupted
) =>
{
// try again
dnd_source.cur_write = Some((data, cur_index, token));
}
Err(_) => {
loop_handle.remove(token);
error!("Failed to write to pipe");
}
};
}) {
};
PostAction::Continue
},
) {
Ok(s) => {
source.cur_write = Some((
data.from_mime_type(&mime).unwrap_or_default(),
Expand Down

0 comments on commit d0f3b08

Please sign in to comment.