Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix screen flicker on Wayland #203

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/cb/src/clipboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ std::string formatBytes(const auto& bytes) {
}

void verifyClipboardName();
void setupGUIClipboardDaemon();
void syncWithRemoteClipboard(bool force = false);
void syncWithGUIClipboard(bool force = false);
void fixMissingItems();
Expand Down
67 changes: 0 additions & 67 deletions src/cb/src/externalclipboards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,70 +304,3 @@ void updateExternalClipboards(bool force) {
if (!envVarIsTrue("CLIPBOARD_NOREMOTE")) writeToRemoteClipboard(thisContent);
}
}

void setupGUIClipboardDaemon() {
if (envVarIsTrue("CLIPBOARD_NOGUI")) return;

#if defined(__linux__) || defined(__APPLE__) || defined(__unix__)
auto pid = fork();
if (pid > 0) return;
if (pid < 0) {
perror("fork");
exit(EXIT_FAILURE);
}
if (setsid() < 0) {
perror("setsid");
exit(EXIT_FAILURE);
}
if (chdir("/") < 0) {
perror("chdir");
exit(EXIT_FAILURE);
}

#if defined(__linux__)
// check if there is already a cb daemon by checking /proc for a process which has an exe symlink entry that points to a binary called "cb" and which does not have stdin or stdout file descriptors
// that point to a tty

for (const auto& entry : fs::directory_iterator("/proc")) {
try {
if (!fs::is_directory(entry)) continue;
auto exe = entry.path() / "exe";
if (!fs::exists(exe)) continue;
auto exeTarget = fs::read_symlink(exe);
if (exeTarget.filename() != "cb") continue;
auto fd = entry.path() / "fd";

auto pointsToFilesystemObject = [](const fs::path& path) {
auto target = fs::read_symlink(path);
if (fs::is_directory(target) || fs::is_regular_file(target)) return true;
return false;
};

if (fs::exists(fd / "0") && !pointsToFilesystemObject(fd / "0")) continue;
if (fs::exists(fd / "1") && !pointsToFilesystemObject(fd / "1")) continue;
if (fs::exists(fd / "2") && !pointsToFilesystemObject(fd / "2")) continue;

// found a cb daemon
_exit(EXIT_SUCCESS);
} catch (...) {}
}
#endif

close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);

#elif defined(_WIN32) | defined(_WIN64)

#endif

while (fs::exists(path)) {
path.getLock();
syncWithGUIClipboard(true);
path.releaseLock();
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
path = Clipboard(std::string(constants.default_clipboard_name));
}

exit(EXIT_SUCCESS);
}
6 changes: 0 additions & 6 deletions src/cb/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,8 @@ int main(int argc, char* argv[]) {

verifyAction();

#if defined(__linux__)
setupGUIClipboardDaemon();
syncWithRemoteClipboard();
if (action != Action::Info) path.getLock();
#else
if (action != Action::Info) path.getLock();
syncWithExternalClipboards();
#endif

fixMissingItems();

Expand Down
Loading