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

Prepare a command to use PRIMARY in wayland #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 24 additions & 2 deletions clipboard_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,30 @@ var (
pasteCmdArgs []string
copyCmdArgs []string

pastePrimaryCmdArgs []string
copyPrimaryCmdArgs []string

xselPasteArgs = []string{xsel, "--output", "--clipboard"}
xselCopyArgs = []string{xsel, "--input", "--clipboard"}

xselPrimaryPasteArgs = []string{xsel, "--output", "--primary"}
xselPrimaryCopyArgs = []string{xsel, "--input", "--primary"}

xclipPasteArgs = []string{xclip, "-out", "-selection", "clipboard"}
xclipCopyArgs = []string{xclip, "-in", "-selection", "clipboard"}

xclipPrimaryPasteArgs = []string{xclip, "-out", "-selection", "primary"}
xclipPrimaryCopyArgs = []string{xclip, "-in", "-selection", "primary"}

powershellExePasteArgs = []string{powershellExe, "Get-Clipboard"}
clipExeCopyArgs = []string{clipExe}

wlpasteArgs = []string{wlpaste, "--no-newline"}
wlcopyArgs = []string{wlcopy}

wlPrimarypasteArgs = []string{wlpaste, "--no-newline", "--primary"}
wlPrimarycopyArgs = []string{wlcopy, "--primary"}

termuxPasteArgs = []string{termuxClipboardGet}
termuxCopyArgs = []string{termuxClipboardSet}

Expand All @@ -52,6 +64,8 @@ func init() {
if os.Getenv("WAYLAND_DISPLAY") != "" {
pasteCmdArgs = wlpasteArgs
copyCmdArgs = wlcopyArgs
pastePrimaryCmdArgs = wlPrimarypasteArgs
copyPrimaryCmdArgs = wlPrimarycopyArgs

if _, err := exec.LookPath(wlcopy); err == nil {
if _, err := exec.LookPath(wlpaste); err == nil {
Expand All @@ -62,20 +76,26 @@ func init() {

pasteCmdArgs = xclipPasteArgs
copyCmdArgs = xclipCopyArgs
pastePrimaryCmdArgs = xclipPrimaryPasteArgs
copyPrimaryCmdArgs = xclipPrimaryCopyArgs

if _, err := exec.LookPath(xclip); err == nil {
return
}

pasteCmdArgs = xselPasteArgs
copyCmdArgs = xselCopyArgs
pastePrimaryCmdArgs = xselPrimaryPasteArgs
copyPrimaryCmdArgs = xselPrimaryCopyArgs

if _, err := exec.LookPath(xsel); err == nil {
return
}

pasteCmdArgs = termuxPasteArgs
copyCmdArgs = termuxCopyArgs
pastePrimaryCmdArgs = termuxPasteArgs
copyPrimaryCmdArgs = termuxCopyArgs

if _, err := exec.LookPath(termuxClipboardSet); err == nil {
if _, err := exec.LookPath(termuxClipboardGet); err == nil {
Expand All @@ -85,6 +105,8 @@ func init() {

pasteCmdArgs = powershellExePasteArgs
copyCmdArgs = clipExeCopyArgs
pastePrimaryCmdArgs = powershellExePasteArgs
copyPrimaryCmdArgs = clipExeCopyArgs
trimDos = true

if _, err := exec.LookPath(clipExe); err == nil {
Expand All @@ -98,14 +120,14 @@ func init() {

func getPasteCommand() *exec.Cmd {
if Primary {
pasteCmdArgs = pasteCmdArgs[:1]
return exec.Command(pastePrimaryCmdArgs[0], pastePrimaryCmdArgs[1:]...)
}
return exec.Command(pasteCmdArgs[0], pasteCmdArgs[1:]...)
}

func getCopyCommand() *exec.Cmd {
if Primary {
copyCmdArgs = copyCmdArgs[:1]
return exec.Command(copyPrimaryCmdArgs[0], copyPrimaryCmdArgs[1:]...)
}
return exec.Command(copyCmdArgs[0], copyCmdArgs[1:]...)
}
Expand Down