You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12-fltk-1.3.2-xhandlers.patch 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. diff -up fltk-1.3.2/FL/Fl.H.xhandlers fltk-1.3.2/FL/Fl.H
  2. --- fltk-1.3.2/FL/Fl.H.xhandlers 2014-07-22 15:23:18.087334467 +0200
  3. +++ fltk-1.3.2/FL/Fl.H 2014-07-22 15:23:18.094334589 +0200
  4. @@ -96,6 +96,9 @@ typedef void (*Fl_FD_Handler)(FL_SOCKET
  5. /** Signature of add_handler functions passed as parameters */
  6. typedef int (*Fl_Event_Handler)(int event);
  7. +/** Signature of add_system_handler functions passed as parameters */
  8. +typedef int (*Fl_System_Handler)(void *event, void *data);
  9. +
  10. /** Signature of set_abort functions passed as parameters */
  11. typedef void (*Fl_Abort_Handler)(const char *format,...);
  12. @@ -712,6 +715,8 @@ public:
  13. static void focus(Fl_Widget*);
  14. static void add_handler(Fl_Event_Handler h);
  15. static void remove_handler(Fl_Event_Handler h);
  16. + static void add_system_handler(Fl_System_Handler h, void *data);
  17. + static void remove_system_handler(Fl_System_Handler h);
  18. static void event_dispatch(Fl_Event_Dispatch d);
  19. static Fl_Event_Dispatch event_dispatch();
  20. /** @} */
  21. diff -up fltk-1.3.2/src/Fl_cocoa.mm.xhandlers fltk-1.3.2/src/Fl_cocoa.mm
  22. --- fltk-1.3.2/src/Fl_cocoa.mm.xhandlers 2014-07-22 15:23:18.089334502 +0200
  23. +++ fltk-1.3.2/src/Fl_cocoa.mm 2014-07-22 15:23:18.095334607 +0200
  24. @@ -1269,6 +1269,8 @@ void fl_open_callback(void (*cb)(const c
  25. }
  26. @end
  27. +extern int fl_send_system_handlers(void *e);
  28. +
  29. static void clipboard_check(void);
  30. @implementation FLApplication
  31. @@ -1276,6 +1278,10 @@ static void clipboard_check(void);
  32. {
  33. // update clipboard status
  34. clipboard_check();
  35. +
  36. + if (fl_send_system_handlers(theEvent))
  37. + return;
  38. +
  39. NSEventType type = [theEvent type];
  40. if (type == NSLeftMouseDown) {
  41. fl_lock_function();
  42. diff -up fltk-1.3.2/src/Fl.cxx.xhandlers fltk-1.3.2/src/Fl.cxx
  43. --- fltk-1.3.2/src/Fl.cxx.xhandlers 2014-07-22 15:23:18.085334432 +0200
  44. +++ fltk-1.3.2/src/Fl.cxx 2014-07-22 15:23:18.095334607 +0200
  45. @@ -891,6 +891,83 @@ static int send_handlers(int e) {
  46. return 0;
  47. }
  48. +
  49. +////////////////////////////////////////////////////////////////
  50. +// System event handlers:
  51. +
  52. +
  53. +struct system_handler_link {
  54. + Fl_System_Handler handle;
  55. + void *data;
  56. + system_handler_link *next;
  57. +};
  58. +
  59. +
  60. +static system_handler_link *sys_handlers = 0;
  61. +
  62. +
  63. +/**
  64. + \brief Install a function to intercept system events.
  65. +
  66. + FLTK calls each of these functions as soon as a new system event is
  67. + received. The processing will stop at the first function to return
  68. + non-zero. If all functions return zero then the event is passed on
  69. + for normal handling by FLTK.
  70. +
  71. + Each function will be called with a pointer to the system event as
  72. + the first argument and \p data as the second argument. The system
  73. + event pointer will always be void *, but will point to different
  74. + objects depending on the platform:
  75. + - X11: XEvent
  76. + - Windows: MSG
  77. + - OS X: NSEvent
  78. +
  79. + \param ha The event handler function to register
  80. + \param data User data to include on each call
  81. +
  82. + \see Fl::remove_system_handler(Fl_System_Handler)
  83. +*/
  84. +void Fl::add_system_handler(Fl_System_Handler ha, void *data) {
  85. + system_handler_link *l = new system_handler_link;
  86. + l->handle = ha;
  87. + l->data = data;
  88. + l->next = sys_handlers;
  89. + sys_handlers = l;
  90. +}
  91. +
  92. +
  93. +/**
  94. + Removes a previously added system event handler.
  95. +
  96. + \param ha The event handler function to remove
  97. +
  98. + \see Fl::add_system_handler(Fl_System_Handler)
  99. +*/
  100. +void Fl::remove_system_handler(Fl_System_Handler ha) {
  101. + system_handler_link *l, *p;
  102. +
  103. + // Search for the handler in the list...
  104. + for (l = sys_handlers, p = 0; l && l->handle != ha; p = l, l = l->next);
  105. +
  106. + if (l) {
  107. + // Found it, so remove it from the list...
  108. + if (p) p->next = l->next;
  109. + else sys_handlers = l->next;
  110. +
  111. + // And free the record...
  112. + delete l;
  113. + }
  114. +}
  115. +
  116. +int fl_send_system_handlers(void *e) {
  117. + for (const system_handler_link *hl = sys_handlers; hl; hl = hl->next) {
  118. + if (hl->handle(e, hl->data))
  119. + return 1;
  120. + }
  121. + return 0;
  122. +}
  123. +
  124. +
  125. ////////////////////////////////////////////////////////////////
  126. Fl_Widget* fl_oldfocus; // kludge for Fl_Group...
  127. diff -up fltk-1.3.2/src/Fl_win32.cxx.xhandlers fltk-1.3.2/src/Fl_win32.cxx
  128. --- fltk-1.3.2/src/Fl_win32.cxx.xhandlers 2014-07-22 15:23:18.092334554 +0200
  129. +++ fltk-1.3.2/src/Fl_win32.cxx 2014-07-22 15:24:44.682843610 +0200
  130. @@ -336,6 +336,8 @@ void* Fl::thread_message() {
  131. return r;
  132. }
  133. +extern int fl_send_system_handlers(void *e);
  134. +
  135. IActiveIMMApp *fl_aimm = NULL;
  136. MSG fl_msg;
  137. @@ -401,23 +403,21 @@ int fl_wait(double time_to_wait) {
  138. // Execute the message we got, and all other pending messages:
  139. // have_message = PeekMessage(&fl_msg, NULL, 0, 0, PM_REMOVE);
  140. - have_message = PeekMessageW(&fl_msg, NULL, 0, 0, PM_REMOVE);
  141. - if (have_message > 0) {
  142. - while (have_message != 0 && have_message != -1) {
  143. - if (fl_msg.message == fl_wake_msg) {
  144. - // Used for awaking wait() from another thread
  145. - thread_message_ = (void*)fl_msg.wParam;
  146. - Fl_Awake_Handler func;
  147. - void *data;
  148. - while (Fl::get_awake_handler_(func, data)==0) {
  149. - func(data);
  150. - }
  151. - }
  152. -
  153. - TranslateMessage(&fl_msg);
  154. - DispatchMessageW(&fl_msg);
  155. - have_message = PeekMessageW(&fl_msg, NULL, 0, 0, PM_REMOVE);
  156. + while ((have_message = PeekMessageW(&fl_msg, NULL, 0, 0, PM_REMOVE)) > 0) {
  157. + if (fl_send_system_handlers(&fl_msg))
  158. + continue;
  159. +
  160. + if (fl_msg.message == fl_wake_msg) {
  161. + // Used for awaking wait() from another thread
  162. + thread_message_ = (void*)fl_msg.wParam;
  163. + Fl_Awake_Handler func;
  164. + void *data;
  165. + while (Fl::get_awake_handler_(func, data)==0)
  166. + func(data);
  167. }
  168. +
  169. + TranslateMessage(&fl_msg);
  170. + DispatchMessageW(&fl_msg);
  171. }
  172. Fl::flush();
  173. diff -up fltk-1.3.2/src/Fl_x.cxx.xhandlers fltk-1.3.2/src/Fl_x.cxx
  174. --- fltk-1.3.2/src/Fl_x.cxx.xhandlers 2014-07-22 15:23:18.093334572 +0200
  175. +++ fltk-1.3.2/src/Fl_x.cxx 2014-07-22 15:23:18.096334624 +0200
  176. @@ -188,6 +188,8 @@ void Fl::remove_fd(int n) {
  177. remove_fd(n, -1);
  178. }
  179. +extern int fl_send_system_handlers(void *e);
  180. +
  181. #if CONSOLIDATE_MOTION
  182. static Fl_Window* send_motion;
  183. extern Fl_Window* fl_xmousewin;
  184. @@ -198,6 +200,8 @@ static void do_queued_events() {
  185. while (XEventsQueued(fl_display,QueuedAfterReading)) {
  186. XEvent xevent;
  187. XNextEvent(fl_display, &xevent);
  188. + if (fl_send_system_handlers(&xevent))
  189. + continue;
  190. fl_handle(xevent);
  191. }
  192. // we send FL_LEAVE only if the mouse did not enter some other window: