aboutsummaryrefslogtreecommitdiffstats
path: root/src/nsmenu.m
diff options
context:
space:
mode:
authorJan Djärv2012-08-15 20:58:19 +0200
committerJan Djärv2012-08-15 20:58:19 +0200
commitddee65158cd55a0c045a1ebc26f8ff73768cdc64 (patch)
tree3ec8cde41573810900d76832751badde8c57f41e /src/nsmenu.m
parentac4845a68bf3ee0a0b4b88c292207d9738b981bd (diff)
downloademacs-ddee65158cd55a0c045a1ebc26f8ff73768cdc64.tar.gz
emacs-ddee65158cd55a0c045a1ebc26f8ff73768cdc64.zip
Improve event loop on NS so that no polling is used.
* nsmenu.m (popupSession): Remove. (pop_down_menu): Remove endModalSession. (timeout_handler:): New method. (runDialogAt:): Get next timeout. Start a NSTimer with that timeout. Call runModalForWindow. Check timer_fired when it returns. If not set, cancel timer and break out of loop. Otherwise loop again, with a new timeout. * nsterm.h (EmacsApp): fd_handler takes id argument. (EmacsDialogPanel): Add timer_fired and timeout_handler. * nsterm.m: Include fcntl.h if present. (fd_entry, t_readfds, inNsSelect): Remove. (select_writefds, select_valid, select_timeout, selfds) (select_mutex, apploopnr): Add. (EV_TRAILER): Call kbd_buffer_store_event_hold only if q_event_ptr. Otherwise call kbd_buffer_store_event. (ns_send_appdefined): Remove release of fd_entry. (ns_read_socket): Always send appdefined. Remove inNsSelect check. Increment and decrement apploopnr. (ns_select): If no file descriptors, just do a NSTimer. Otherwise copy read/write masks and start select thread (fd_handler). Start main loop and wait for application defined event. Inform select thread to stop selecting after main loop is exited. (ns_term_init): Create selfds pipe and set non-blocking. Initialize select_mutex. Start the select thread (fd_handler). (fd_handler:): Loop forever, wait for info from the main thread to either start or stop selecting. When select returns, send and appdefined event. (sendScrollEventAtLoc:fromEvent:): Check if q_event_ptr is set. If not call kbd_buffer_store_event.
Diffstat (limited to 'src/nsmenu.m')
-rw-r--r--src/nsmenu.m43
1 files changed, 30 insertions, 13 deletions
diff --git a/src/nsmenu.m b/src/nsmenu.m
index 210f4530d7a..657b9306942 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -73,7 +73,6 @@ EmacsMenu *mainMenu, *svcsMenu, *dockMenu;
73 73
74/* Nonzero means a menu is currently active. */ 74/* Nonzero means a menu is currently active. */
75static int popup_activated_flag; 75static int popup_activated_flag;
76static NSModalSession popupSession;
77 76
78/* Nonzero means we are tracking and updating menus. */ 77/* Nonzero means we are tracking and updating menus. */
79static int trackingMenu; 78static int trackingMenu;
@@ -1365,8 +1364,6 @@ pop_down_menu (Lisp_Object arg)
1365 { 1364 {
1366 EmacsDialogPanel *panel = unwind_data->dialog; 1365 EmacsDialogPanel *panel = unwind_data->dialog;
1367 popup_activated_flag = 0; 1366 popup_activated_flag = 0;
1368 [NSApp endModalSession: popupSession];
1369
1370 [panel close]; 1367 [panel close];
1371 [unwind_data->pool release]; 1368 [unwind_data->pool release];
1372 [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow]; 1369 [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow];
@@ -1756,20 +1753,40 @@ void process_dialog (id window, Lisp_Object list)
1756} 1753}
1757 1754
1758 1755
1756
1757- (void)timeout_handler: (NSTimer *)timedEntry
1758{
1759 timer_fired = 1;
1760 [NSApp abortModal];
1761}
1762
1759- (Lisp_Object)runDialogAt: (NSPoint)p 1763- (Lisp_Object)runDialogAt: (NSPoint)p
1760{ 1764{
1761 NSInteger ret; 1765 NSInteger ret = 0;
1762 1766
1763 /* initiate a session that will be ended by pop_down_menu */ 1767 while (popup_activated_flag)
1764 popupSession = [NSApp beginModalSessionForWindow: self];
1765 while (popup_activated_flag
1766 && (ret = [NSApp runModalSession: popupSession])
1767 == NSRunContinuesResponse)
1768 { 1768 {
1769 /* Run this for timers.el, indep of atimers; might not return. 1769 NSTimer *tmo = nil;
1770 TODO: use return value to avoid calling every iteration. */ 1770 EMACS_TIME next_time = timer_check ();
1771 timer_check (); 1771
1772 [NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.1]]; 1772 if (EMACS_TIME_VALID_P (next_time))
1773 {
1774 double time = EMACS_TIME_TO_DOUBLE (next_time);
1775 tmo = [NSTimer timerWithTimeInterval: time
1776 target: self
1777 selector: @selector (timeout_handler:)
1778 userInfo: 0
1779 repeats: NO];
1780 [[NSRunLoop currentRunLoop] addTimer: tmo
1781 forMode: NSModalPanelRunLoopMode];
1782 }
1783 timer_fired = 0;
1784 ret = [NSApp runModalForWindow: self];
1785 if (! timer_fired)
1786 {
1787 if (tmo != nil) [tmo invalidate]; /* Cancels timer */
1788 break;
1789 }
1773 } 1790 }
1774 1791
1775 { /* FIXME: BIG UGLY HACK!!! */ 1792 { /* FIXME: BIG UGLY HACK!!! */