aboutsummaryrefslogtreecommitdiffstats
path: root/src/haiku_select.cc
diff options
context:
space:
mode:
authorPo Lu2022-07-07 02:48:19 +0000
committerPo Lu2022-07-07 02:48:19 +0000
commitfd016ea99724f7abedfddbb470ab96ece6ddf4ae (patch)
treee874e42b2a69d1c22411e2a78c1fa9d2a4270284 /src/haiku_select.cc
parent8575962d46d1f1d08836bf00cb74ccd344953bcb (diff)
downloademacs-fd016ea99724f7abedfddbb470ab96ece6ddf4ae.tar.gz
emacs-fd016ea99724f7abedfddbb470ab96ece6ddf4ae.zip
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/>. */
18 18
19#include <config.h> 19#include <config.h>
20 20
21#include <Application.h>
21#include <Clipboard.h> 22#include <Clipboard.h>
22#include <Message.h> 23#include <Message.h>
23#include <Path.h> 24#include <Path.h>
@@ -47,6 +48,16 @@ static int64 count_primary = -1;
47/* The number of times the secondary selection has changed. */ 48/* The number of times the secondary selection has changed. */
48static int64 count_secondary = -1; 49static int64 count_secondary = -1;
49 50
51/* Whether or not we currently think Emacs owns the primary
52 selection. */
53static bool owned_primary;
54
55/* Likewise for the secondary selection. */
56static bool owned_secondary;
57
58/* And the clipboard. */
59static bool owned_clipboard;
60
50static BClipboard * 61static BClipboard *
51get_clipboard_object (enum haiku_clipboard clipboard) 62get_clipboard_object (enum haiku_clipboard clipboard)
52{ 63{
@@ -150,14 +161,17 @@ be_update_clipboard_count (enum haiku_clipboard id)
150 { 161 {
151 case CLIPBOARD_CLIPBOARD: 162 case CLIPBOARD_CLIPBOARD:
152 count_clipboard = system_clipboard->SystemCount (); 163 count_clipboard = system_clipboard->SystemCount ();
164 owned_clipboard = true;
153 break; 165 break;
154 166
155 case CLIPBOARD_PRIMARY: 167 case CLIPBOARD_PRIMARY:
156 count_primary = primary->SystemCount (); 168 count_primary = primary->SystemCount ();
169 owned_primary = true;
157 break; 170 break;
158 171
159 case CLIPBOARD_SECONDARY: 172 case CLIPBOARD_SECONDARY:
160 count_secondary = secondary->SystemCount (); 173 count_secondary = secondary->SystemCount ();
174 owned_secondary = true;
161 break; 175 break;
162 } 176 }
163} 177}
@@ -433,3 +447,43 @@ be_unlock_clipboard (enum haiku_clipboard clipboard, bool discard)
433 447
434 board->Unlock (); 448 board->Unlock ();
435} 449}
450
451void
452be_handle_clipboard_changed_message (void)
453{
454 if (count_clipboard != -1
455 && (system_clipboard->SystemCount ()
456 > count_clipboard + 1)
457 && owned_clipboard)
458 {
459 owned_clipboard = false;
460 haiku_selection_disowned (CLIPBOARD_CLIPBOARD);
461 }
462
463 if (count_primary != -1
464 && (primary->SystemCount ()
465 > count_primary + 1)
466 && owned_primary)
467 {
468 owned_primary = false;
469 haiku_selection_disowned (CLIPBOARD_PRIMARY);
470 }
471
472 if (count_secondary != -1
473 && (secondary->SystemCount ()
474 > count_secondary + 1)
475 && owned_secondary)
476 {
477 owned_secondary = false;
478 haiku_selection_disowned (CLIPBOARD_SECONDARY);
479 }
480}
481
482void
483be_start_watching_selection (enum haiku_clipboard id)
484{
485 BClipboard *clipboard;
486
487 clipboard = get_clipboard_object (id);
488 clipboard->StartWatching (be_app);
489}