summaryrefslogtreecommitdiff
path: root/src/haiku_select.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/haiku_select.cc')
-rw-r--r--src/haiku_select.cc54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/haiku_select.cc b/src/haiku_select.cc
index 80c5d294820..edb821e3132 100644
--- a/src/haiku_select.cc
+++ b/src/haiku_select.cc
@@ -18,6 +18,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
+#include <Application.h>
#include <Clipboard.h>
#include <Message.h>
#include <Path.h>
@@ -47,6 +48,16 @@ static int64 count_primary = -1;
/* The number of times the secondary selection has changed. */
static int64 count_secondary = -1;
+/* Whether or not we currently think Emacs owns the primary
+ selection. */
+static bool owned_primary;
+
+/* Likewise for the secondary selection. */
+static bool owned_secondary;
+
+/* And the clipboard. */
+static bool owned_clipboard;
+
static BClipboard *
get_clipboard_object (enum haiku_clipboard clipboard)
{
@@ -150,14 +161,17 @@ be_update_clipboard_count (enum haiku_clipboard id)
{
case CLIPBOARD_CLIPBOARD:
count_clipboard = system_clipboard->SystemCount ();
+ owned_clipboard = true;
break;
case CLIPBOARD_PRIMARY:
count_primary = primary->SystemCount ();
+ owned_primary = true;
break;
case CLIPBOARD_SECONDARY:
count_secondary = secondary->SystemCount ();
+ owned_secondary = true;
break;
}
}
@@ -433,3 +447,43 @@ be_unlock_clipboard (enum haiku_clipboard clipboard, bool discard)
board->Unlock ();
}
+
+void
+be_handle_clipboard_changed_message (void)
+{
+ if (count_clipboard != -1
+ && (system_clipboard->SystemCount ()
+ > count_clipboard + 1)
+ && owned_clipboard)
+ {
+ owned_clipboard = false;
+ haiku_selection_disowned (CLIPBOARD_CLIPBOARD);
+ }
+
+ if (count_primary != -1
+ && (primary->SystemCount ()
+ > count_primary + 1)
+ && owned_primary)
+ {
+ owned_primary = false;
+ haiku_selection_disowned (CLIPBOARD_PRIMARY);
+ }
+
+ if (count_secondary != -1
+ && (secondary->SystemCount ()
+ > count_secondary + 1)
+ && owned_secondary)
+ {
+ owned_secondary = false;
+ haiku_selection_disowned (CLIPBOARD_SECONDARY);
+ }
+}
+
+void
+be_start_watching_selection (enum haiku_clipboard id)
+{
+ BClipboard *clipboard;
+
+ clipboard = get_clipboard_object (id);
+ clipboard->StartWatching (be_app);
+}