Skip to content

Commit b7dd2d4

Browse files
committed
add-clipboard-widget
1 parent f24bd17 commit b7dd2d4

4 files changed

Lines changed: 821 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: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
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+
### Available CSS Classes
98+
99+
| Class | Description |
100+
| :--- | :--- |
101+
| `.clipboard-widget` | Main widget container on the bar |
102+
| `.widget-container` | Inner container for widget content |
103+
| `.label` | Primary label/icon on the bar |
104+
| `.label.alt` | Alternate label on bar (has both `.label` and `.alt` classes) |
105+
| `.clipboard-menu` | Main popup container |
106+
| `.search-input` | Search bar input field |
107+
| `.clear-button` | Clear all history button |
108+
| `.scroll-area` | Scroll area container |
109+
| `.clipboard-scroll-content` | Content container inside scroll area |
110+
| `.clipboard-item` | Individual clipboard item container |
111+
| `.clipboard-item-content` | Content area (button + optional info) |
112+
| `.clipboard-item-btn` | Clickable button for each item |
113+
| `.clipboard-item-info` | Image info container (dimensions, size, date) |
114+
| `.image-list-info` | Labels for image metadata |
115+
| `.delete-button` | Delete item button |
116+
| `.status-message` | Empty/error message label |
117+
| `.status-message.error` | Error message (e.g., clipboard disabled) |
118+
| `.status-message.empty` | Empty search result message |
119+
120+
### Example CSS
121+
122+
```css
123+
/* Widget on the bar */
124+
.clipboard-widget {
125+
font-family: "JetBrainsMono Nerd Font", "Segoe UI Variable";
126+
}
127+
128+
/* Widget Label (icon/text on bar) */
129+
.clipboard-widget .label {
130+
color: #ffffff;
131+
}
132+
133+
/* Main Popup Container */
134+
.clipboard-menu {
135+
background-color: #1e1e2e;
136+
border: 1px solid #11111b;
137+
border-radius: 10px;
138+
padding: 10px;
139+
min-width: 320px;
140+
}
141+
142+
/* Search Bar */
143+
.clipboard-menu .search-input {
144+
background-color: rgba(255, 255, 255, 0.05);
145+
border: 1px solid rgba(255, 255, 255, 0.1);
146+
border-radius: 6px;
147+
padding: 6px 10px;
148+
margin-bottom: 6px;
149+
color: #cdd6f4;
150+
font-size: 13px;
151+
}
152+
153+
.clipboard-menu .search-input:focus {
154+
border: 1px solid #89b4fa;
155+
}
156+
157+
/* Global Clear Button */
158+
.clipboard-menu .clear-button {
159+
background-color: #cb3b42;
160+
border-radius: 6px;
161+
padding: 5px;
162+
margin-bottom: 8px;
163+
font-weight: bold;
164+
font-size: 11px;
165+
}
166+
167+
.clipboard-menu .clear-button:hover {
168+
background-color: #cc6a6f;
169+
}
170+
171+
/* Scroll Area */
172+
.clipboard-menu .scroll-area {
173+
background: transparent;
174+
}
175+
176+
/* Scroll Content Container */
177+
.clipboard-menu .clipboard-scroll-content {
178+
background: transparent;
179+
}
180+
181+
/* Clipboard Item Container */
182+
.clipboard-menu .clipboard-item {
183+
background-color: rgba(255, 255, 255, 0.03);
184+
border: 1px solid transparent;
185+
border-radius: 6px;
186+
margin-bottom: 4px;
187+
padding: 4px 8px;
188+
font-size: 12px;
189+
}
190+
191+
.clipboard-menu .clipboard-item:hover {
192+
background-color: rgba(255, 255, 255, 0.08);
193+
border: 1px solid #11111b;
194+
}
195+
196+
/* Content Area (button + optional info) */
197+
.clipboard-menu .clipboard-item-content {
198+
background: transparent;
199+
}
200+
201+
/* Item Button */
202+
.clipboard-menu .clipboard-item-btn {
203+
background: transparent;
204+
border: none;
205+
text-align: left;
206+
padding: 4px;
207+
}
208+
209+
/* Image Info Container */
210+
.clipboard-menu .clipboard-item-info {
211+
background: transparent;
212+
}
213+
214+
/* Image List Info (dimensions, size, date) */
215+
.clipboard-menu .image-list-info {
216+
font-size: 10px;
217+
color: #ffffff;
218+
padding-left: 4px;
219+
}
220+
221+
/* Delete Button */
222+
.clipboard-menu .delete-button {
223+
background: #cb3b42;
224+
border: none;
225+
border-radius: 6px;
226+
padding: 4px;
227+
}
228+
229+
.clipboard-menu .delete-button:hover {
230+
background-color: #cc6a6f;
231+
}
232+
233+
/* Status Messages */
234+
.clipboard-menu .status-message {
235+
text-align: center;
236+
color: gray;
237+
}
238+
239+
.clipboard-menu .status-message.error {
240+
color: #e74c3c;
241+
}
242+
```
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)