summaryrefslogtreecommitdiff
path: root/src/haiku_select.cc
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2022-07-07 02:48:19 +0000
committerPo Lu <luangruo@yahoo.com>2022-07-07 02:48:19 +0000
commitfd016ea99724f7abedfddbb470ab96ece6ddf4ae (patch)
treee874e42b2a69d1c22411e2a78c1fa9d2a4270284 /src/haiku_select.cc
parent8575962d46d1f1d08836bf00cb74ccd344953bcb (diff)
downloademacs-fd016ea99724f7abedfddbb470ab96ece6ddf4ae.tar.gz
Port `x-lost-selection-functions' to Haiku
* src/haiku_io.c (haiku_len): Add `CLIPBOARD_CHANGED_EVENT'. * src/haiku_select.cc (be_update_clipboard_count): Set ownership flags. (be_handle_clipboard_changed_message): (be_start_watching_selection): New functions. * src/haiku_support.cc (class Emacs): Handle B_CLIPBOARD_CHANGED. * src/haiku_support.h (enum haiku_event_type): New event `CLIPBOARD_CHANGED_EVENT'. (struct haiku_clipboard_changed_event): New struct. * src/haikuselect.c (haiku_handle_selection_clear) (haiku_selection_disowned, haiku_start_watching_selections): New functions. (syms_of_haikuselect): New defsym and defvar. * src/haikuselect.h: Update prototypes. * src/haikuterm.c (haiku_read_socket): Handle selection events. (haiku_term_init): Start watching selections. * src/haikuterm.h: Update prototypes. * src/keyboard.c (kbd_buffer_get_event, process_special_events) (mark_kboards): Handle SELECTON_CLEAR_EVENTs correctly on Haiku.
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);
+}