diff options
author | Po Lu <luangruo@yahoo.com> | 2022-07-09 04:50:06 +0000 |
---|---|---|
committer | Po Lu <luangruo@yahoo.com> | 2022-07-09 04:50:35 +0000 |
commit | edabfe4ff66090b3b2c433962df4cfe1a68259fd (patch) | |
tree | 89d27a45082768a61bdcbcb49bfb25a7f4637b98 /src/haiku_select.cc | |
parent | f400c60237f04781b60423492c583beea6c77e8e (diff) | |
download | emacs-edabfe4ff66090b3b2c433962df4cfe1a68259fd.tar.gz |
Fix race conditions handling selection clear events on Haiku
* src/haiku_select.cc (be_handle_clipboard_changed_message):
Include current clipboard count.
(be_selection_outdated_p): New function.
* src/haikuselect.c (haiku_handle_selection_clear): Ignore
outdated events.
(haiku_selection_disowned): New argument `count'. Include it in
the timestamp field of the selection clear event.
* src/haikuselect.h: Update prototypes.
* src/systime.h: Define `Time' to an appropriate value on Haiku.
Diffstat (limited to 'src/haiku_select.cc')
-rw-r--r-- | src/haiku_select.cc | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/src/haiku_select.cc b/src/haiku_select.cc index edb821e3132..e1f2a815241 100644 --- a/src/haiku_select.cc +++ b/src/haiku_select.cc @@ -451,31 +451,37 @@ be_unlock_clipboard (enum haiku_clipboard clipboard, bool discard) void be_handle_clipboard_changed_message (void) { + int64 n_clipboard, n_primary, n_secondary; + + n_clipboard = system_clipboard->SystemCount (); + n_primary = primary->SystemCount (); + n_secondary = secondary->SystemCount (); + if (count_clipboard != -1 - && (system_clipboard->SystemCount () - > count_clipboard + 1) + && (n_clipboard > count_clipboard + 1) && owned_clipboard) { owned_clipboard = false; - haiku_selection_disowned (CLIPBOARD_CLIPBOARD); + haiku_selection_disowned (CLIPBOARD_CLIPBOARD, + n_clipboard); } if (count_primary != -1 - && (primary->SystemCount () - > count_primary + 1) + && (n_primary > count_primary + 1) && owned_primary) { owned_primary = false; - haiku_selection_disowned (CLIPBOARD_PRIMARY); + haiku_selection_disowned (CLIPBOARD_PRIMARY, + n_primary); } if (count_secondary != -1 - && (secondary->SystemCount () - > count_secondary + 1) + && (n_secondary > count_secondary + 1) && owned_secondary) { owned_secondary = false; - haiku_selection_disowned (CLIPBOARD_SECONDARY); + haiku_selection_disowned (CLIPBOARD_SECONDARY, + n_secondary); } } @@ -487,3 +493,18 @@ be_start_watching_selection (enum haiku_clipboard id) clipboard = get_clipboard_object (id); clipboard->StartWatching (be_app); } + +bool +be_selection_outdated_p (enum haiku_clipboard id, int64 count) +{ + if (id == CLIPBOARD_CLIPBOARD && count_clipboard > count) + return true; + + if (id == CLIPBOARD_PRIMARY && count_primary > count) + return true; + + if (id == CLIPBOARD_SECONDARY && count_secondary > count) + return true; + + return false; +} |