-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee30a86
commit 0ff3220
Showing
9 changed files
with
210 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,74 @@ | ||
use iced_core::clipboard::Kind; | ||
use iced_core::Clipboard; | ||
pub struct LayerShellClipboard; | ||
use layershellev::WindowWrapper; | ||
pub struct LayerShellClipboard { | ||
state: State, | ||
} | ||
|
||
enum State { | ||
Connected(window_clipboard::Clipboard), | ||
Unavailable, | ||
} | ||
|
||
impl LayerShellClipboard { | ||
/// Creates a new [`Clipboard`] for the given window. | ||
pub fn connect(window: &WindowWrapper) -> Self { | ||
#[allow(unsafe_code)] | ||
let state = unsafe { window_clipboard::Clipboard::connect(window) } | ||
.ok() | ||
.map(State::Connected) | ||
.unwrap_or(State::Unavailable); | ||
|
||
Self { state } | ||
} | ||
|
||
/// Creates a new [`Clipboard`] that isn't associated with a window. | ||
/// This clipboard will never contain a copied value. | ||
#[allow(unused)] | ||
pub fn unconnected() -> Self { | ||
Self { | ||
state: State::Unavailable, | ||
} | ||
} | ||
|
||
/// Reads the current content of the [`Clipboard`] as text. | ||
pub fn read(&self, kind: Kind) -> Option<String> { | ||
match &self.state { | ||
State::Connected(clipboard) => match kind { | ||
Kind::Standard => clipboard.read().ok(), | ||
Kind::Primary => clipboard.read_primary().and_then(Result::ok), | ||
}, | ||
State::Unavailable => None, | ||
} | ||
} | ||
|
||
/// Writes the given text contents to the [`Clipboard`]. | ||
pub fn write(&mut self, kind: Kind, contents: String) { | ||
match &mut self.state { | ||
State::Connected(clipboard) => { | ||
let result = match kind { | ||
Kind::Standard => clipboard.write(contents), | ||
Kind::Primary => clipboard.write_primary(contents).unwrap_or(Ok(())), | ||
}; | ||
|
||
match result { | ||
Ok(()) => {} | ||
Err(error) => { | ||
log::warn!("error writing to clipboard: {error}"); | ||
} | ||
} | ||
} | ||
State::Unavailable => {} | ||
} | ||
} | ||
} | ||
|
||
// TODO: clipboard | ||
impl Clipboard for LayerShellClipboard { | ||
fn read(&self, _kind: iced_core::clipboard::Kind) -> Option<String> { | ||
None | ||
fn read(&self, kind: Kind) -> Option<String> { | ||
self.read(kind) | ||
} | ||
|
||
fn write(&mut self, kind: Kind, contents: String) { | ||
self.write(kind, contents); | ||
} | ||
fn write(&mut self, _kind: iced_core::clipboard::Kind, _contents: String) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,75 @@ | ||
use iced_core::clipboard::Kind; | ||
use iced_core::Clipboard; | ||
pub struct LayerShellClipboard; | ||
use sessionlockev::WindowWrapper; | ||
|
||
// TODO: clipboard | ||
impl Clipboard for LayerShellClipboard { | ||
fn read(&self, _kind: iced_core::clipboard::Kind) -> Option<String> { | ||
None | ||
pub struct SessionLockClipboard { | ||
state: State, | ||
} | ||
|
||
enum State { | ||
Connected(window_clipboard::Clipboard), | ||
Unavailable, | ||
} | ||
|
||
impl SessionLockClipboard { | ||
/// Creates a new [`Clipboard`] for the given window. | ||
pub fn connect(window: &WindowWrapper) -> Self { | ||
#[allow(unsafe_code)] | ||
let state = unsafe { window_clipboard::Clipboard::connect(window) } | ||
.ok() | ||
.map(State::Connected) | ||
.unwrap_or(State::Unavailable); | ||
|
||
Self { state } | ||
} | ||
|
||
/// Creates a new [`Clipboard`] that isn't associated with a window. | ||
/// This clipboard will never contain a copied value. | ||
#[allow(unused)] | ||
pub fn unconnected() -> Self { | ||
Self { | ||
state: State::Unavailable, | ||
} | ||
} | ||
|
||
/// Reads the current content of the [`Clipboard`] as text. | ||
pub fn read(&self, kind: Kind) -> Option<String> { | ||
match &self.state { | ||
State::Connected(clipboard) => match kind { | ||
Kind::Standard => clipboard.read().ok(), | ||
Kind::Primary => clipboard.read_primary().and_then(Result::ok), | ||
}, | ||
State::Unavailable => None, | ||
} | ||
} | ||
|
||
/// Writes the given text contents to the [`Clipboard`]. | ||
pub fn write(&mut self, kind: Kind, contents: String) { | ||
match &mut self.state { | ||
State::Connected(clipboard) => { | ||
let result = match kind { | ||
Kind::Standard => clipboard.write(contents), | ||
Kind::Primary => clipboard.write_primary(contents).unwrap_or(Ok(())), | ||
}; | ||
|
||
match result { | ||
Ok(()) => {} | ||
Err(error) => { | ||
log::warn!("error writing to clipboard: {error}"); | ||
} | ||
} | ||
} | ||
State::Unavailable => {} | ||
} | ||
} | ||
} | ||
|
||
impl Clipboard for SessionLockClipboard { | ||
fn read(&self, kind: Kind) -> Option<String> { | ||
self.read(kind) | ||
} | ||
|
||
fn write(&mut self, kind: Kind, contents: String) { | ||
self.write(kind, contents); | ||
} | ||
fn write(&mut self, _kind: iced_core::clipboard::Kind, _contents: String) {} | ||
} |
Oops, something went wrong.