Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Clipboard support on Linux: A few hiccups.  (Read 87589 times)

0 Members and 6 Guests are viewing this topic.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Clipboard support on Linux: A few hiccups.
« Reply #120 on: December 30, 2014, 09:17:43 am »
Thanks Tank for the explanation. (When it comes down to X11 I'm a complete noob. ;))

@Laurent, agreed. We can still refined our judgment in 3.0 anyway.
SFML / OS X developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Clipboard support on Linux: A few hiccups.
« Reply #121 on: February 08, 2015, 01:15:56 am »
So can we ever agree to an implementation?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Juhani

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Clipboard support on Linux: A few hiccups.
« Reply #122 on: February 09, 2015, 12:51:35 am »
Setters and getters probably have to forward the job to some private sf::Window functions, and the clipboard requests could be handled among other events in processEvent.

Are there more implementation details to decide about?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Clipboard support on Linux: A few hiccups.
« Reply #123 on: February 20, 2015, 09:29:37 pm »
If we can't get this feature moving anytime soon, it most likely won't make it into SFML 2.3. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Clipboard support on Linux: A few hiccups.
« Reply #124 on: August 03, 2015, 01:43:01 pm »
Before this descends into a gaping abyss, let's come up with the final API 8)

The main controversy in this thread revolved around the appearance of a window in the API (which is needed by some, but not all platforms). Towards the end of the discussion, many arguments were in favor of an independent sf::Clipboard class with static functions taking a window parameter:
class Clipboard
{
public:
    static void       copy(sf::Window& window, const sf::String& text);
    static sf::String paste(sf::Window& window);
};

However, this is not ideal from an object-oriented and semantic perspective; it's neither intuitive nor handy to have a window around whenever the clipboard is used.

I have a new idea that would combine both requests (have a window in the API but without clutter). We essentially move away from the global access -- but keep in mind that was illusory, because you had to keep a window around. This API uses an instance-based (non-static method) approach:
class Clipboard
{
public:
    void       copy(const sf::String& text);
    sf::String paste() const;

private:
    sf::Window* m_window;
};

class Window
{
public:
    Clipboard getClipboard(); // const?
};

This has several advantages over both a purely sf::Window-based interface and a singleton-style sf::Clipboard class:
  • The interface is much simpler. The user need not specify the window all the time.
  • We don't have a global class, thus resource lifetimes can be bound to the object, not the program duration (either sf::Clipboard, but probably more meaningful sf::Window).
  • We can use const-correctness: if we want certain modules to only read but not write to the clipboard, we pass them a const-reference.
  • A window is not strictly required: a platform can provide other means of creating sf::Clipboard instances.
What we can still discuss is whether sf::Clipboard has value semantics, and every instance refers to the same clipboard; or whether we make it noncopyable and allow only to pass around pointers and references.

What do you think of this idea? :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: Clipboard support on Linux: A few hiccups.
« Reply #125 on: August 03, 2015, 02:56:17 pm »
I like this approach, it really seems to combine all the ideas into one solution. The only thing I'd change is the function names: "copy" to "set" and "paste" to "get", because you set/get a clipboard, you don't copy/paste it. But other than that, nice.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Clipboard support on Linux: A few hiccups.
« Reply #126 on: August 03, 2015, 02:57:22 pm »
I don't think that your modification makes much difference:
window.setClipboardData(...);
// vs
window.getClipboard().setData(...);

So my comments about the solution that I presented still apply:

Quote
2. it doesn't give the false impression that each window has different clipboard data; instead it focuses on the global nature of this data
3. instead of adding more and more functions to the sf::Window class, this new functionality is kept separated in its own class, which makes maintenance and evolution easier
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Clipboard support on Linux: A few hiccups.
« Reply #127 on: August 03, 2015, 04:40:47 pm »
As mentioned in earlier posts, I'm also fine with a solution that hides the window entirely. And now that you mention it again, it makes sense to have a truly global access point.

The question is then which window the implementation would choose, or if it would always create a hidden one.

About naming: Why not copy/paste? That's exactly what a clipboard does. Like this, it's obvious how the functions correspond to user commands like Ctrl+C, Ctrl+V.
« Last Edit: August 03, 2015, 04:42:25 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: Clipboard support on Linux: A few hiccups.
« Reply #128 on: August 03, 2015, 08:17:43 pm »
A clipboard is the place where copied data gets stored, and where you paste data from. The clipboard itself doesn't do that.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Clipboard support on Linux: A few hiccups.
« Reply #129 on: August 03, 2015, 09:04:22 pm »
Copy/paste is end-user semantics for the application where there also exists cut, which does (for the end-user) something very different to copy but as far as the clipboard is concerned, not very different (unless you actually move the content, in which case you would need to provide another method, move, to transfer pointers or whatever).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Clipboard support on Linux: A few hiccups.
« Reply #130 on: August 04, 2015, 10:43:38 pm »
A clipboard is the place where copied data gets stored, and where you paste data from.
Yes, that would only add a preposition, which I omitted for simplicity:
Clipboard::copyTo()
Clipboard::pasteFrom()

Copy/paste is end-user semantics for the application where there also exists cut, which does (for the end-user) something very different to copy but as far as the clipboard is concerned, not very different (unless you actually move the content, in which case you would need to provide another method, move, to transfer pointers or whatever).
You might be right, "copy/cut/paste" are perhaps higher-level terms used in the UI rather than the OS interface.

I personally thought "copy sth. to the clipboard / paste sth. from it" is easier and more intuitive to understand than "set a value in the clipboard / get a value from it".

Further opinions? Also not only regarding the naming?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Juhani

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Clipboard support on Linux: A few hiccups.
« Reply #131 on: August 16, 2015, 11:50:21 am »
I'd prefer a solution that doesn't incur unnecessary overhead (eg. a superfluous hidden window). Other than that, I'm ok with any interface or implementation. I'm just looking forward to getting clipboard support to SFML.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: Clipboard support on Linux: A few hiccups.
« Reply #132 on: August 16, 2015, 01:44:16 pm »
I still have to reply for the naming. ;)

Quote
Clipboard::copyTo()
Clipboard::pasteFrom()

Compare this to:

Quote
Object::copyTo()
Object::pasteFrom()

In the 2nd case, you would clearly say that the object is copied to somewhere or pasted from somewhere. This is actually the same with Clipboard::*. I guess the sole reason why it's confusing is that it's, like said, not the clipboard that's performing the copy/paste/cut operations, but the user. The clipboard is utilized to fulfill the operations, by setting and getting its contents.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Clipboard support on Linux: A few hiccups.
« Reply #133 on: August 16, 2015, 03:39:36 pm »
I thought about it again after further input. So far, the main argument to use a window in the API is to reflect the underlying OS-specific APIs. Since SFML is an abstraction, those are implementation details, and there exists no reason per se to propagate them to the public API. Easy of implementation is not a good argument, especially not when it comes at the cost of ease of use.

On the other side, there are good arguments to have a hidden window:
  • The clipboard feels global in nature, linking it to a window makes no sense from user perspective
  • Associated with a window, the semantics are confusing: what happens when we set the string at one window and get it from another?
  • The user need not carry around a window object when accessing the clipboard, usage thus gets simpler
  • On some platforms (e.g. Android) there's not even a window behind the scenes, so the implementation would just ignore it anyway
So, I'll suggest we proceed with a hidden window and a truly global sf::Clipboard class. Regarding the naming, I'm okay with "setString/getString".
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Clipboard support on Linux: A few hiccups.
« Reply #134 on: August 16, 2015, 05:02:50 pm »
Good to see someone finally sharing my point of view.

However this would mean global variables / hidden windows / or whatever that we don't want to see again in our internal code.

But until someone tries to implement a global clipboard, we'll never really know. The thing is, we need at least the 3 desktop implementations to be sure :-\
Laurent Gomila - SFML developer