Skip to content

Commit

Permalink
Extend clipboard public to allow mark new content as password
Browse files Browse the repository at this point in the history
  • Loading branch information
wengxt committed Apr 7, 2024
1 parent 2497d0f commit cca82ee
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
20 changes: 18 additions & 2 deletions src/modules/clipboard/clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,27 @@ void Clipboard::updateUI(InputContext *inputContext) {
}

void Clipboard::setPrimary(const std::string &name, const std::string &str) {
setPrimaryEntry(name, ClipboardEntry{.text = str});
setPrimaryV2(name, str, false);
}

void Clipboard::setClipboard(const std::string &name, const std::string &str) {
setClipboardEntry(name, ClipboardEntry{.text = str});
setClipboardV2(name, str, false);
}

void Clipboard::setPrimaryV2(const std::string &name, const std::string &str,
bool password) {
setPrimaryEntry(name,
ClipboardEntry{.text = str,
.passwordTimestamp =
(password ? now(CLOCK_MONOTONIC) : 0)});
}

void Clipboard::setClipboardV2(const std::string &name, const std::string &str,
bool password) {
setClipboardEntry(
name, ClipboardEntry{.text = str,
.passwordTimestamp =
(password ? now(CLOCK_MONOTONIC) : 0)});
}

void Clipboard::setPrimaryEntry(const std::string &name, ClipboardEntry entry) {
Expand Down
12 changes: 9 additions & 3 deletions src/modules/clipboard/clipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ class Clipboard final : public AddonInstance {

void setPrimary(const std::string &name, const std::string &str);
void setClipboard(const std::string &name, const std::string &str);
void setPrimaryEntry(const std::string &name, ClipboardEntry entry);
void setClipboardEntry(const std::string &name,
const ClipboardEntry &entry);
void setPrimaryV2(const std::string &name, const std::string &str,
bool password);
void setClipboardV2(const std::string &name, const std::string &str,
bool password);
const auto &config() const { return config_; }

#ifdef ENABLE_X11
Expand All @@ -120,11 +121,16 @@ class Clipboard final : public AddonInstance {
FCITX_ADDON_EXPORT_FUNCTION(Clipboard, clipboard);
FCITX_ADDON_EXPORT_FUNCTION(Clipboard, setPrimary);
FCITX_ADDON_EXPORT_FUNCTION(Clipboard, setClipboard);
FCITX_ADDON_EXPORT_FUNCTION(Clipboard, setPrimaryV2);
FCITX_ADDON_EXPORT_FUNCTION(Clipboard, setClipboardV2);
#ifdef WAYLAND_FOUND
FCITX_ADDON_DEPENDENCY_LOADER(wayland, instance_->addonManager());
#endif

void refreshPasswordTimer();
void setPrimaryEntry(const std::string &name, ClipboardEntry entry);
void setClipboardEntry(const std::string &name,
const ClipboardEntry &entry);

Instance *instance_;
std::vector<std::unique_ptr<fcitx::HandlerTableEntry<fcitx::EventHandler>>>
Expand Down
6 changes: 6 additions & 0 deletions src/modules/clipboard/clipboard_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,11 @@ FCITX_ADDON_DECLARE_FUNCTION(Clipboard, setPrimary,
FCITX_ADDON_DECLARE_FUNCTION(Clipboard, setClipboard,
void(const std::string &name,
const std::string &str));
FCITX_ADDON_DECLARE_FUNCTION(Clipboard, setPrimaryV2,
void(const std::string &name,
const std::string &str, bool password));
FCITX_ADDON_DECLARE_FUNCTION(Clipboard, setClipboardV2,
void(const std::string &name,
const std::string &str, bool password));

#endif // _FCITX_MODULES_CLIPBOARD_CLIPBOARD_PUBLIC_H_
8 changes: 2 additions & 6 deletions src/modules/clipboard/waylandclipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,11 @@ EventLoop *WaylandClipboard::eventLoop() {
}

void WaylandClipboard::setClipboard(const std::string &str, bool password) {
parent_->setClipboardEntry(
name_, {.text = str,
.passwordTimestamp = (password ? now(CLOCK_MONOTONIC) : 0)});
parent_->setClipboardV2(name_, str, password);
}

void WaylandClipboard::setPrimary(const std::string &str, bool password) {
parent_->setPrimaryEntry(
name_, {.text = str,
.passwordTimestamp = (password ? now(CLOCK_MONOTONIC) : 0)});
parent_->setPrimaryV2(name_, str, password);
}

} // namespace fcitx
10 changes: 3 additions & 7 deletions src/modules/clipboard/xcbclipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,11 @@ void XcbClipboard::primaryChanged() { primary_.request(); }
void XcbClipboard::clipboardChanged() { clipboard_.request(); }

void XcbClipboard::setClipboard(const std::string &str, bool password) {
parent_->setClipboardEntry(
name_, {.text = str,
.passwordTimestamp = (password ? now(CLOCK_MONOTONIC) : 0)});
parent_->setClipboardV2(name_, str, password);
}

void XcbClipboard::setPrimary(const std::string &str, bool password) {
parent_->setPrimaryEntry(
name_, {.text = str,
.passwordTimestamp = (password ? now(CLOCK_MONOTONIC) : 0)});
parent_->setPrimaryV2(name_, str, password);
}

} // namespace fcitx
} // namespace fcitx

0 comments on commit cca82ee

Please sign in to comment.