Skip to content

Commit 0acbd6f

Browse files
authored
Dev (#12)
* quick_settings * refactor * stable * f
1 parent f57634a commit 0acbd6f

File tree

12 files changed

+141
-89
lines changed

12 files changed

+141
-89
lines changed

Diff for: .vscode/launch.json

+43-43
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
{
2-
// Use IntelliSense to learn about possible attributes.
3-
// Hover to view descriptions of existing attributes.
4-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5-
"version": "0.2.0",
6-
"configurations": [
7-
{
8-
"type": "lldb",
9-
"request": "launch",
10-
"name": "Debug executable 'cosmic-clipboard-manager'",
11-
"cargo": {
12-
"args": [
13-
"build",
14-
"--bin=cosmic-clipboard-manager",
15-
"--package=cosmic-clipboard-manager"
16-
],
17-
"filter": {
18-
"name": "cosmic-clipboard-manager",
19-
"kind": "bin"
20-
}
21-
},
22-
"args": [],
23-
"cwd": "${workspaceFolder}"
24-
},
25-
{
26-
"type": "lldb",
27-
"request": "launch",
28-
"name": "Debug unit tests in executable 'cosmic-clipboard-manager'",
29-
"cargo": {
30-
"args": [
31-
"test",
32-
"--no-run",
33-
"--bin=cosmic-clipboard-manager",
34-
"--package=cosmic-clipboard-manager"
35-
],
36-
"filter": {
37-
"name": "cosmic-clipboard-manager",
38-
"kind": "bin"
39-
}
40-
},
41-
"args": [],
42-
"cwd": "${workspaceFolder}"
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "lldb",
9+
"request": "launch",
10+
"name": "Debug executable 'cosmic-clipboard-manager'",
11+
"cargo": {
12+
"args": [
13+
"build",
14+
"--bin=cosmic-clipboard-manager",
15+
"--package=cosmic-clipboard-manager"
16+
],
17+
"filter": {
18+
"name": "cosmic-clipboard-manager",
19+
"kind": "bin"
4320
}
44-
]
45-
}
21+
},
22+
"args": [],
23+
"cwd": "${workspaceFolder}"
24+
},
25+
{
26+
"type": "lldb",
27+
"request": "launch",
28+
"name": "Debug unit tests in executable 'cosmic-clipboard-manager'",
29+
"cargo": {
30+
"args": [
31+
"test",
32+
"--no-run",
33+
"--bin=cosmic-clipboard-manager",
34+
"--package=cosmic-clipboard-manager"
35+
],
36+
"filter": {
37+
"name": "cosmic-clipboard-manager",
38+
"kind": "bin"
39+
}
40+
},
41+
"args": [],
42+
"cwd": "${workspaceFolder}"
43+
}
44+
]
45+
}

Diff for: Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ features = [
4040
"tokio",
4141
"wayland",
4242
"desktop",
43-
#"wgpu",
43+
#"multi-window",
4444
#"winit",
45+
#"wgpu",
4546
]
4647

4748
[dependencies.wl-clipboard-rs]

Diff for: DEV.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## DEPS
22

33
#### Fedora
4+
45
```sh
56
sudo dnf install libxkbcommon-devel -y
67
```
@@ -10,29 +11,29 @@ sudo dnf install libxkbcommon-devel -y
1011
```
1112
journalctl --user _EXE=/usr/bin/cosmic-session -r -S -10m | grep cosmic_clipboard_manager > ~/log.txt && code ~/log.txt
1213
```
14+
1315
## INfO
1416

1517
clipboard crates:
18+
1619
- https://crates.io/crates/wl-clipboard-rs
1720
- https://crates.io/crates/arboard
1821

19-
2022
wayland protocol / official impl:
23+
2124
- https://wayland.app/protocols/wlr-data-control-unstable-v1
2225
- https://github.com/bugaevc/wl-clipboard/tree/master/src
2326

24-
2527
other app:
26-
- https://github.com/mohamadzoh/clipop
27-
2828

29+
- https://github.com/mohamadzoh/clipop
2930

3031
discussions:
32+
3133
- https://github.com/pop-os/cosmic-epoch/issues/175
3234
- https://www.reddit.com/r/pop_os/comments/194bugz/comment/khfxyoo/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
3335

34-
35-
3636
links:
37+
3738
- https://github.com/pop-os/cosmic-launcher/blob/master/src/app.rs
38-
- https://github.com/pop-os/cosmic-applets
39+
- https://github.com/pop-os/cosmic-applets

Diff for: README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44

55
The goal is to make a simple yet fast clipboard history, with a focus on UX, rapidity and security.
66

7-
87
Currently support storing the history on disk, search, delete
98

9+
There is a quick settings popup when you right click the icon.
1010

1111
Todo:
12+
1213
- image support
1314
- auto remove old entries
1415
- ...
1516

1617
Maybe take inspiration on this gnome extension: https://github.com/oae/gnome-shell-pano
1718

18-
1919
## Install
2020

2121
```
@@ -25,21 +25,23 @@ just install
2525
```
2626

2727
You curently need to activate a setting of the compositor:
28+
2829
```
2930
sudo nano /etc/cosmic-comp/config.ron
3031
```
32+
3133
And change `data_control_enabled: false` to `true` at the end of the file. Note that you may need to reset the setting at each update you make (at least, i noticied it on Fedora).
3234

3335
Obiously, a better integration is planned, maybe with a portal that ask the user if they want to activate this protocol (which is insecure since its let an app access the clipboard without receiving an event for it (like ctrl-c) or being focused).
3436

3537
Finally, you will need to set up the applet in cosmic-settings.
3638

37-
3839
## Logs
3940

4041
```
4142
journalctl -p 3 -xb --user _EXE=/usr/bin/cosmic-panel | grep com.wiiznokes.CosmicClipboardManager
4243
```
44+
4345
-p 3 means priority error
4446
-x add information
4547
b means since last boot

Diff for: justfile

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ install:
77
sudo install -Dm0644 resources/{{APP_ID}}.desktop /usr/share/app_IDlications/com.wiiznokes.CosmicClipboardManager.desktop
88
sudo install -Dm0644 resources/icons/assignment24.svg /usr/share/{{APP_ID}}/icons/assignment24.svg
99

10+
11+
pull: fmt prettier fix
12+
13+
1014
################### Test
1115

1216
test:

Diff for: resources/icons/settings24.svg

+1
Loading

Diff for: rust-toolchain.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[toolchain]
2-
channel = "nightly"
2+
channel = "stable"

Diff for: src/app.rs

+40-9
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ use cosmic::iced_runtime::command::Action;
1010
use cosmic::iced_runtime::core::window;
1111
use cosmic::iced_style::application;
1212
use cosmic::iced_widget::Column;
13-
use cosmic::widget::{button, icon, text, text_input};
13+
use cosmic::widget::{button, icon, text, text_input, MouseArea};
1414

1515
use cosmic::{Element, Theme};
1616

1717
use crate::config::{Config, CONFIG_VERSION, PRIVATE_MODE};
1818
use crate::db::{self, Data, Db};
1919
use crate::message::AppMessage;
2020
use crate::utils::command_message;
21+
use crate::view::{popup_view, quick_settings_view};
2122
use crate::{clipboard, config, navigation};
2223

2324
use cosmic::cosmic_config;
@@ -31,6 +32,7 @@ pub struct Window {
3132
config_handler: Option<cosmic_config::Config>,
3233
popup: Option<Id>,
3334
state: AppState,
35+
quick_settings_visible: bool,
3436
}
3537

3638
pub struct AppState {
@@ -98,11 +100,12 @@ impl cosmic::Application for Window {
98100
focused: 0,
99101
},
100102
config,
103+
quick_settings_visible: false,
101104
};
102105

103106
#[cfg(debug_assertions)]
104107
let command = Command::single(Action::Future(Box::pin(async {
105-
cosmic::app::Message::App(AppMessage::TogglePopup)
108+
cosmic::app::Message::App(AppMessage::QuickSettings)
106109
})));
107110

108111
#[cfg(not(debug_assertions))]
@@ -148,9 +151,30 @@ impl cosmic::Application for Window {
148151
self.config = config;
149152
}
150153
}
154+
AppMessage::QuickSettings => {
155+
return if let Some(p) = self.popup.take() {
156+
self.quick_settings_visible = false;
157+
destroy_popup(p)
158+
} else {
159+
self.quick_settings_visible = true;
160+
let new_id = Id::unique();
161+
self.popup.replace(new_id);
162+
let mut popup_settings =
163+
self.core
164+
.applet
165+
.get_popup_settings(Id::MAIN, new_id, None, None, None);
166+
popup_settings.positioner.size_limits = Limits::NONE
167+
.max_width(250.0)
168+
.min_width(200.0)
169+
.min_height(200.0)
170+
.max_height(550.0);
171+
get_popup(popup_settings)
172+
};
173+
}
174+
151175
AppMessage::TogglePopup => {
152176
//info!("TogglePopup");
153-
177+
self.quick_settings_visible = false;
154178
return if let Some(p) = self.popup.take() {
155179
destroy_popup(p)
156180
} else {
@@ -232,18 +256,25 @@ impl cosmic::Application for Window {
232256
}
233257

234258
fn view(&self) -> Element<Self::Message> {
235-
self.core
259+
let icon = self
260+
.core
236261
.applet
237262
.icon_button("/usr/share/com.wiiznokes.CosmicClipboardManager/icons/assignment24.svg")
238-
.on_press(AppMessage::TogglePopup)
263+
.on_press(AppMessage::TogglePopup);
264+
265+
MouseArea::new(icon)
266+
.on_right_release(AppMessage::QuickSettings)
239267
.into()
240268
}
241269

242270
fn view_window(&self, _id: Id) -> Element<Self::Message> {
243-
self.core
244-
.applet
245-
.popup_container(self.state.view(&self.config))
246-
.into()
271+
let view = if self.quick_settings_visible {
272+
quick_settings_view(&self.state, &self.config)
273+
} else {
274+
popup_view(&self.state, &self.config)
275+
};
276+
277+
self.core.applet.popup_container(view).into()
247278
}
248279
fn subscription(&self) -> Subscription<Self::Message> {
249280
let mut subscriptions = vec![config::sub(), navigation::sub().map(AppMessage::Navigation)];

Diff for: src/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(split_at_checked)]
21

32
#![allow(dead_code)]
43
#![allow(unused_macros)]

Diff for: src/message.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::{
1212
pub enum AppMessage {
1313
ChangeConfig(Config),
1414
TogglePopup,
15+
QuickSettings,
1516
ClosePopup(Id),
1617
Search(String),
1718
ClipboardEvent(ClipboardMessage),

Diff for: src/utils.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn split_at(str: &str, n: usize) -> &str {
3636
if str.len() > n {
3737
let mut i = n;
3838
loop {
39-
if let Some((left, _)) = str.split_at_checked(i) {
39+
if let Some((left, _)) = split_at_checked(str, i) {
4040
return left;
4141
}
4242
i -= 1;
@@ -46,6 +46,17 @@ fn split_at(str: &str, n: usize) -> &str {
4646
}
4747
}
4848

49+
// https://github.com/rust-lang/rust/issues/119128
50+
pub fn split_at_checked(s: &str, mid: usize) -> Option<(&str, &str)> {
51+
// is_char_boundary checks that the index is in [0, .len()]
52+
if s.is_char_boundary(mid) {
53+
// SAFETY: just checked that `mid` is on a char boundary.
54+
Some(unsafe { (s.get_unchecked(0..mid), s.get_unchecked(mid..s.len())) })
55+
} else {
56+
None
57+
}
58+
}
59+
4960
pub fn horizontal_padding(value: f32) -> Padding {
5061
Padding {
5162
top: 0f32,

0 commit comments

Comments
 (0)