Skip to content

Commit

Permalink
Updated Clip Library version to 1.9. This is to fix a paste issue whe…
Browse files Browse the repository at this point in the history
…re sometimes the left-most 4 columns of a clipboard image would appear on the right when pasting.
  • Loading branch information
bluescan committed Jun 4, 2024
1 parent 158bec3 commit 31678de
Show file tree
Hide file tree
Showing 21 changed files with 1,417 additions and 742 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ add_executable(

Contrib/clip/clip.cpp
$<$<PLATFORM_ID:Windows>:Contrib/clip/clip_win.cpp>
$<$<PLATFORM_ID:Windows>:Contrib/clip/clip_win_bmp.cpp>
$<$<PLATFORM_ID:Windows>:Contrib/clip/clip_win_wic.cpp>
$<$<PLATFORM_ID:Linux>:Contrib/clip/clip_x11.cpp>
Contrib/clip/image.cpp
)
Expand All @@ -148,6 +150,7 @@ target_compile_definitions(
PRIVATE
ARCHITECTURE_X64
GLFW_INCLUDE_NONE
CLIP_ENABLE_IMAGE
$<$<CONFIG:Debug>:CONFIG_DEBUG>
$<$<CONFIG:Release>:CONFIG_RELEASE>
$<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_DEPRECATE>
Expand Down
2 changes: 1 addition & 1 deletion Contrib/clip/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015-2022 David Capello
Copyright (c) 2015-2024 David Capello

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
14 changes: 13 additions & 1 deletion Contrib/clip/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Clip Library
*Copyright (c) 2015-2022 David Capello*
*Copyright (c) 2015-2024 David Capello*

[![build](https://github.com/dacap/clip/workflows/build/badge.svg)](https://github.com/dacap/clip/actions?query=workflow%3Abuild)
[![MIT Licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.txt)
Expand Down Expand Up @@ -59,6 +59,18 @@ int main() {
- To be able to copy/paste on Linux you need `libx11-dev`/`libX11-devel` package.
- To copy/paste images you will need `libpng-dev`/`libpng-devel` package.

## Compilation Flags

* `CLIP_ENABLE_IMAGE`: Enables the support to
[copy](examples/put_image.cpp)/[paste](examples/show_image.cpp) images.
* `CLIP_ENABLE_LIST_FORMATS` (only for Windows): Enables the
`clip::lock::list_formats()` API function and the
[list_clip_formats](examples/list_clip_formats.cpp) example.
* `CLIP_EXAMPLES`: Compile [examples](examples/).
* `CLIP_TESTS`: Compile [tests](tests/).
* `CLIP_X11_WITH_PNG` (only for Linux/X11): Enables support to
copy/paste images using the `libpng` library on Linux.

## Who is using this library?

[Check the wiki](https://github.com/dacap/clip/wiki#who-is-using-clip)
Expand Down
20 changes: 19 additions & 1 deletion Contrib/clip/clip.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Clip Library
// Copyright (c) 2015-2018 David Capello
// Copyright (c) 2015-2024 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand Down Expand Up @@ -56,6 +56,8 @@ size_t lock::get_data_length(format f) const {
return p->get_data_length(f);
}

#if CLIP_ENABLE_IMAGE

bool lock::set_image(const image& img) {
return p->set_image(img);
}
Expand All @@ -68,9 +70,21 @@ bool lock::get_image_spec(image_spec& spec) const {
return p->get_image_spec(spec);
}

#endif // CLIP_ENABLE_IMAGE

#if CLIP_ENABLE_LIST_FORMATS

std::vector<format_info> lock::list_formats() const {
return p->list_formats();
}

#endif // CLIP_ENABLE_LIST_FORMATS

format empty_format() { return 0; }
format text_format() { return 1; }
#if CLIP_ENABLE_IMAGE
format image_format() { return 2; }
#endif

bool has(format f) {
lock l;
Expand Down Expand Up @@ -120,6 +134,8 @@ bool get_text(std::string& value) {
}
}

#if CLIP_ENABLE_IMAGE

bool set_image(const image& img) {
lock l;
if (l.locked()) {
Expand Down Expand Up @@ -154,6 +170,8 @@ bool get_image_spec(image_spec& spec) {
return l.get_image_spec(spec);
}

#endif // CLIP_ENABLE_IMAGE

void set_error_handler(error_handler handler) {
g_error_handler = handler;
}
Expand Down
34 changes: 33 additions & 1 deletion Contrib/clip/clip.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Clip Library
// Copyright (c) 2015-2022 David Capello
// Copyright (c) 2015-2024 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand All @@ -11,6 +11,8 @@
#include <cassert>
#include <memory>
#include <string>
#include <vector>
#define CLIP_LIBRARY_VERSION "1.9"

namespace clip {

Expand All @@ -21,8 +23,22 @@ namespace clip {
// Clipboard format identifier.
typedef size_t format;

#if CLIP_ENABLE_IMAGE
class image;
struct image_spec;
#endif // CLIP_ENABLE_IMAGE

#if CLIP_ENABLE_LIST_FORMATS
struct format_info {
format id = 0;
std::string name;
format_info(const format id,
const std::string& name)
: id(id),
name(name) {
}
};
#endif // CLIP_ENABLE_LIST_FORMATS

class lock {
public:
Expand Down Expand Up @@ -51,10 +67,18 @@ namespace clip {
bool get_data(format f, char* buf, size_t len) const;
size_t get_data_length(format f) const;

#if CLIP_ENABLE_IMAGE
// For images
bool set_image(const image& image);
bool get_image(image& image) const;
bool get_image_spec(image_spec& spec) const;
#endif // CLIP_ENABLE_IMAGE

#if CLIP_ENABLE_LIST_FORMATS
// Returns the list of available formats (by name) in the
// clipboard.
std::vector<format_info> list_formats() const;
#endif // CLIP_ENABLE_LIST_FORMATS

private:
class impl;
Expand All @@ -69,8 +93,10 @@ namespace clip {
// When the clipboard has UTF8 text.
format text_format();

#if CLIP_ENABLE_IMAGE
// When the clipboard has an image.
format image_format();
#endif

// Returns true if the clipboard has content of the given type.
bool has(format f);
Expand All @@ -84,7 +110,9 @@ namespace clip {

enum class ErrorCode {
CannotLock,
#if CLIP_ENABLE_IMAGE
ImageNotSupported,
#endif
};

typedef void (*error_handler)(ErrorCode code);
Expand All @@ -105,6 +133,8 @@ namespace clip {
// Image
// ======================================================================

#if CLIP_ENABLE_IMAGE

struct image_spec {
unsigned long width = 0;
unsigned long height = 0;
Expand Down Expand Up @@ -165,6 +195,8 @@ namespace clip {
bool get_image(image& img);
bool get_image_spec(image_spec& spec);

#endif // CLIP_ENABLE_IMAGE

// ======================================================================
// Platform-specific
// ======================================================================
Expand Down
8 changes: 7 additions & 1 deletion Contrib/clip/clip_common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Clip Library
// Copyright (C) 2020 David Capello
// Copyright (C) 2020-2024 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand All @@ -8,9 +8,13 @@
#define CLIP_COMMON_H_INCLUDED
#pragma once

#include "clip.h"

namespace clip {
namespace details {

#if CLIP_ENABLE_IMAGE

inline void divide_rgb_by_alpha(image& img,
bool hasAlphaGreaterThanZero = false) {
const image_spec& spec = img.spec();
Expand Down Expand Up @@ -70,6 +74,8 @@ inline void divide_rgb_by_alpha(image& img,
}
}

#endif // CLIP_ENABLE_IMAGE

} // namespace details
} // namespace clip

Expand Down
9 changes: 8 additions & 1 deletion Contrib/clip/clip_lock_impl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Clip Library
// Copyright (c) 2015-2018 David Capello
// Copyright (c) 2015-2024 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand All @@ -20,9 +20,16 @@ class lock::impl {
bool set_data(format f, const char* buf, size_t len);
bool get_data(format f, char* buf, size_t len) const;
size_t get_data_length(format f) const;

#if CLIP_ENABLE_IMAGE
bool set_image(const image& image);
bool get_image(image& image) const;
bool get_image_spec(image_spec& spec) const;
#endif // CLIP_ENABLE_IMAGE

#if CLIP_ENABLE_LIST_FORMATS
std::vector<format_info> list_formats() const;
#endif // CLIP_ENABLE_LIST_FORMATS

private:
bool m_locked;
Expand Down
35 changes: 35 additions & 0 deletions Contrib/clip/clip_osx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Clip Library
// Copyright (c) 2024 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.

#ifndef CLIP_OSX_H_INCLUDED
#define CLIP_OSX_H_INCLUDED
#pragma once

#ifdef __OBJC__

#include <Cocoa/Cocoa.h>

namespace clip {

class image;
struct image_spec;

namespace osx {

#if CLIP_ENABLE_IMAGE

bool get_image_from_clipboard(NSPasteboard* pasteboard,
image* output_img,
image_spec* output_spec);

#endif // CLIP_ENABLE_IMAGE

} // namespace osx
} // namespace clip

#endif

#endif
Loading

0 comments on commit 31678de

Please sign in to comment.