Skip to content
Merged
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
15 changes: 13 additions & 2 deletions clipboard_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,14 @@ func read(t Format) (buf []byte, err error) {
return x11Read("UTF8_STRING")
case FmtImage:
return x11Read("image/png")
default:
mime, ok := formatMIME(t)
if !ok {
return nil, errUnsupported
}
// On X11 a MIME type is used directly as the target atom.
return x11Read(mime)
}
return nil, errUnsupported
}

func write(t Format, buf []byte) (<-chan struct{}, error) {
Expand All @@ -55,8 +61,13 @@ func write(t Format, buf []byte) (<-chan struct{}, error) {
return x11Write("UTF8_STRING", buf)
case FmtImage:
return x11Write("image/png", buf)
default:
mime, ok := formatMIME(t)
if !ok {
return nil, errUnsupported
}
return x11Write(mime, buf)
}
return nil, errUnsupported
}

func watch(ctx context.Context, t Format) <-chan []byte {
Expand Down
15 changes: 15 additions & 0 deletions clipboard_custom_bsd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2021 The golang.design Initiative Authors.
// All rights reserved. Use of this source code is governed
// by a MIT license that can be found in the LICENSE file.
//
// Written by Changkun Ou <changkun.de>

//go:build (freebsd || openbsd || netbsd) && !android

package clipboard_test

import "testing"

// The BSDs share the X11 backend with Linux. CI only builds (no X server), so
// this exercises compilation; it runs the round-trip locally on a BSD with X11.
func TestCustomFormatRoundTrip(t *testing.T) { customRoundTrip(t) }
24 changes: 24 additions & 0 deletions clipboard_custom_linux_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2021 The golang.design Initiative Authors.
// All rights reserved. Use of this source code is governed
// by a MIT license that can be found in the LICENSE file.
//
// Written by Changkun Ou <changkun.de>

//go:build linux && !android

package clipboard_test

import (
"os"
"testing"
)

func TestCustomFormatRoundTrip(t *testing.T) {
// This PR wires custom formats into the X11 backend only. Under Wayland
// (e.g. the headless-sway CI job) the data-control backend is used, where
// custom-format support lands in a separate PR; skip there for now.
if os.Getenv("WAYLAND_DISPLAY") != "" {
t.Skip("Wayland custom-format support lands in a separate PR")
}
customRoundTrip(t)
}
15 changes: 13 additions & 2 deletions clipboard_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ func read(t Format) (buf []byte, err error) {
return x11Read("UTF8_STRING")
case FmtImage:
return x11Read("image/png")
default:
mime, ok := formatMIME(t)
if !ok {
return nil, errUnsupported
}
// On X11 a MIME type is used directly as the target atom.
return x11Read(mime)
}
return nil, errUnsupported
}

func write(t Format, buf []byte) (<-chan struct{}, error) {
Expand All @@ -74,8 +80,13 @@ func write(t Format, buf []byte) (<-chan struct{}, error) {
return x11Write("UTF8_STRING", buf)
case FmtImage:
return x11Write("image/png", buf)
default:
mime, ok := formatMIME(t)
if !ok {
return nil, errUnsupported
}
return x11Write(mime, buf)
}
return nil, errUnsupported
}

func watch(ctx context.Context, t Format) <-chan []byte {
Expand Down
Loading