Skip to content

Commit 7e6da4d

Browse files
committed
feat(clipboard): add clipboard widget
1 parent f24bd17 commit 7e6da4d

4 files changed

Lines changed: 783 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ https://github.com/user-attachments/assets/aab8d8e8-248f-46a1-919c-9b0601236ac1
9494
- **[Cava](https://github.com/amnweb/yasb/wiki/(Widget)-Cava)**: Displays audio visualizer using Cava.
9595
- **[Copilot](https://github.com/amnweb/yasb/wiki/(Widget)-Copilot)**: GitHub Copilot usage with a detailed menu showing statistics
9696
- **[CPU](https://github.com/amnweb/yasb/wiki/(Widget)-CPU)**: Shows the current CPU usage.
97+
- **[Clipboard](https://github.com/amnweb/yasb/wiki/(Widget)-Clipboard)**: A native lightweight clipboard manager for YASB.
9798
- **[Clock](https://github.com/amnweb/yasb/wiki/(Widget)-Clock)**: Displays the current time and date.
9899
- **[Custom](https://github.com/amnweb/yasb/wiki/(Widget)-Custom)**: Create a custom widget.
99100
- **[Github](https://github.com/amnweb/yasb/wiki/(Widget)-Github)**: Shows notifications from GitHub.

docs/widgets/(Widget)-Clipboard.md

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Clipboard Widget for YASB
2+
3+
A lightweight clipboard manager for YASB that integrates directly with the native Windows Clipboard History (Win + V). This widget provides real-time access to your system's clip buffer without the need for heavy local storage or complex background monitoring.
4+
5+
## Features
6+
- **Native Windows Sync**: Syncs in real-time with your official Windows Clipboard History.
7+
- **Search**: Built-in real-time search bar to filter through your text-based history.
8+
- **History**: View your Clipboard history and delete a single history item or your entire history.
9+
- **Image Support**: Full support for re-copying images directly from the history list.
10+
- **Long text preview**: Hover over a copied long piece of text to display text preview (configurable).
11+
- **Image list info**: Show image dimensions, size, and date in the history list (configurable).
12+
- **Feedback**: Visual feedback when content is copied.
13+
- **Customizable tooltips**: Enable/disable tooltips and adjust delay.
14+
15+
## Options
16+
17+
| Option | Type | Default | Description |
18+
| :--- | :--- | :--- | :--- |
19+
| `type` | `string` | `yasb.clipboard.ClipboardWidget` | The widget class identifier. |
20+
| `label` | `string` | `<span>\udb80\udd4d</span>` | Primary label format. |
21+
| `label_alt` | `string` | `CLIPBOARD` | Alternative label format (swapped on right-click). |
22+
| `max_history` | `integer` | `50` | Maximum number of history items to fetch from Windows. |
23+
| `class_name` | `string` | `""` | Additional CSS class for the widget container. |
24+
| `copied_feedback` | `string` | `\uf00c` | Feedback message when copying. |
25+
| `menu` | `dict` | (See Schema) | Configuration for the popup menu. |
26+
| `icons` | `dict` | (See Schema) | Custom icons for clipboard actions. |
27+
| `animation` | `dict` | (See Schema) | Animation configuration for label toggling. |
28+
| `label_shadow` | `dict` | (See Schema) | Shadow configuration for the label. |
29+
| `container_shadow` | `dict` | (See Schema) | Shadow configuration for the widget container. |
30+
31+
## Icons Configuration Defaults
32+
33+
| Key | Default | Description |
34+
| :--- | :--- | :--- |
35+
| `clear_icon` | `\uf1f8` | Clear all history icon. |
36+
| `delete_icon` | `\uf1f8` | Delete item icon. |
37+
38+
## Menu Configuration Defaults
39+
40+
| Key | Default | Description |
41+
| :--- | :--- | :--- |
42+
| `blur` | `true` | Enable blur effect on popup. |
43+
| `round_corners` | `true` | Enable rounded corners on popup. |
44+
| `round_corners_type` | `"normal"` | Corner radius style (`"normal"` or `"small"`). |
45+
| `border_color` | `"System"` | Border color for the popup. |
46+
| `alignment` | `"right"` | Horizontal alignment relative to widget (`"left"`, `"right"`, `"center"`). |
47+
| `direction` | `"down"` | Vertical direction for popup (`"up"` or `"down"`). |
48+
| `offset_top` | `6` | Top offset in pixels. |
49+
| `offset_left` | `0` | Left offset in pixels. |
50+
| `max_item_length` | `50` | Max characters to display for text items (10-200). |
51+
| `tooltip_enabled` | `true` | Enable custom tooltips for history items. |
52+
| `tooltip_delay` | `400` | Delay in milliseconds before showing tooltip (0-2000). |
53+
| `show_image_thumbnail` | `true` | Show image thumbnail in history list. If false, shows `image_replacement_text` instead. |
54+
| `image_replacement_text` | `"[Image]"` | Text to display for image items in history list when `show_image_thumbnail` is false. |
55+
| `show_image_list_info` | `true` | Show image dimensions, date, and size below the image in the history list. |
56+
57+
## Callbacks
58+
59+
| Function | Description |
60+
| :--- | :--- |
61+
| `toggle_menu` | Opens/closes the clipboard history popup (Scheduled asynchronously). |
62+
| `toggle_label` | Switches display between `label` and `label_alt` on the bar. |
63+
64+
---
65+
66+
67+
## Configuration Example
68+
69+
```yaml
70+
71+
clipboard:
72+
type: "yasb.clipboard.ClipboardWidget"
73+
options:
74+
label: "<span>\uf0ea</span>"
75+
label_alt: "<span>CLIPBOARD</span>"
76+
icons:
77+
delete_icon: "\uf1f8"
78+
clear_icon: "\uf1f8"
79+
copied_feedback: "\uf00c"
80+
menu:
81+
blur: true
82+
round_corners: true
83+
alignment: "right"
84+
direction: "down"
85+
tooltip_enabled: true
86+
tooltip_delay: 400
87+
show_image_thumbnail: true
88+
image_replacement_text: "[IMAGE]"
89+
show_image_list_info: true
90+
callbacks:
91+
on_left: "toggle_menu"
92+
on_right: "toggle_label"
93+
```
94+
95+
## Styling
96+
97+
### Example CSS
98+
99+
```css
100+
/* Widget on the bar */
101+
.clipboard-widget {
102+
font-family: "JetBrainsMono Nerd Font", "Segoe UI Variable";
103+
}
104+
105+
.clipboard-widget .label {
106+
}
107+
108+
/* Main Popup Container */
109+
.clipboard-menu {
110+
background-color: #1e1e2e;
111+
border: 1px solid #11111b;
112+
border-radius: 10px;
113+
padding: 8px;
114+
}
115+
116+
/* Search Bar */
117+
.clipboard-menu .search-input {
118+
background-color: rgba(255, 255, 255, 0.05);
119+
border: 1px solid rgba(255, 255, 255, 0.1);
120+
border-radius: 6px;
121+
padding: 6px 10px;
122+
margin-bottom: 6px;
123+
color: #cdd6f4;
124+
font-size: 13px;
125+
}
126+
127+
.clipboard-menu .search-input:focus {
128+
border: 1px solid #89b4fa;
129+
}
130+
131+
/* Global Clear Button */
132+
.clipboard-menu .clear-button {
133+
background-color: #cb3b42;
134+
border-radius: 6px;
135+
padding: 5px;
136+
margin-bottom: 8px;
137+
font-weight: bold;
138+
font-size: 11px;
139+
}
140+
141+
.clipboard-menu .clear-button:hover {
142+
background-color: #cc6a6f;
143+
}
144+
145+
/* Clipboard Items */
146+
.clipboard-menu .clipboard-item {
147+
background-color: rgba(255, 255, 255, 0.03);
148+
border-radius: 10%;
149+
margin-bottom: 4px;
150+
font-size: 12px;
151+
}
152+
153+
.clipboard-menu .clipboard-item:hover {
154+
background-color: rgba(255, 255, 255, 0.08);
155+
border: 1px solid #11111b;
156+
}
157+
158+
/* Image Item */
159+
.clipboard-menu .image-item {
160+
/* Styles for image items in the list */
161+
}
162+
163+
/* Image List Info (shown below image in list) */
164+
.clipboard-menu .image-list-info {
165+
font-size: 10px;
166+
color: #ffffff;
167+
padding-left: 4px;
168+
}
169+
170+
/* Scroll Area */
171+
.clipboard-menu .scroll-area {
172+
background: transparent;
173+
}
174+
175+
/* Delete Button */
176+
.clipboard-menu .delete-button {
177+
background: #cb3b42;
178+
}
179+
.clipboard-menu .delete-button:hover {
180+
background-color: #cc6a6f;
181+
}
182+
```
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from typing import Literal
2+
3+
from pydantic import Field
4+
5+
from core.validation.widgets.base_model import (
6+
AnimationConfig,
7+
CallbacksConfig,
8+
CustomBaseModel,
9+
KeybindingConfig,
10+
ShadowConfig,
11+
)
12+
13+
14+
class ClipboardMenuConfig(CustomBaseModel):
15+
"""Configuration for the clipboard popup menu."""
16+
17+
blur: bool = True
18+
round_corners: bool = True
19+
round_corners_type: Literal["normal", "small"] = "normal"
20+
border_color: str = "System"
21+
alignment: Literal["left", "right", "center"] = "right"
22+
direction: Literal["up", "down"] = "down"
23+
offset_top: int = 6
24+
offset_left: int = 0
25+
max_item_length: int = Field(default=50, ge=10, le=200)
26+
tooltip_enabled: bool = True
27+
tooltip_delay: int = Field(default=400, ge=0, le=2000)
28+
show_image_thumbnail: bool = True
29+
image_replacement_text: str = "[Image]"
30+
show_image_list_info: bool = True
31+
32+
33+
class ClipboardIconsConfig(CustomBaseModel):
34+
"""Configuration for clipboard widget icons."""
35+
36+
clear_icon: str = "\uf1f8"
37+
delete_icon: str = "\uf1f8"
38+
39+
40+
class ClipboardCallbacksConfig(CallbacksConfig):
41+
"""Callbacks configuration with clipboard-specific defaults."""
42+
43+
on_left: str = "toggle_menu"
44+
on_right: str = "toggle_label"
45+
46+
47+
class ClipboardConfig(CustomBaseModel):
48+
"""Main configuration model for the Clipboard widget."""
49+
50+
label: str = "<span>\udb80\udd4d</span>"
51+
label_alt: str = "CLIPBOARD"
52+
class_name: str = ""
53+
copied_feedback: str = "\uf00c"
54+
max_history: int = Field(default=50, ge=10, le=500)
55+
menu: ClipboardMenuConfig = ClipboardMenuConfig()
56+
icons: ClipboardIconsConfig = ClipboardIconsConfig()
57+
animation: AnimationConfig = AnimationConfig()
58+
label_shadow: ShadowConfig = ShadowConfig()
59+
container_shadow: ShadowConfig = ShadowConfig()
60+
keybindings: list[KeybindingConfig] = []
61+
callbacks: ClipboardCallbacksConfig = ClipboardCallbacksConfig()

0 commit comments

Comments
 (0)