@@ -44,7 +44,9 @@ struct ui_ctx {
4444};
4545
4646enum sleep_result {
47- SHOULD_CANCEL , SHOULD_SWITCH , SHOULD_SYNC ,
47+ SHOULD_CANCEL ,
48+ SHOULD_SWITCH ,
49+ SHOULD_SYNC ,
4850};
4951
5052static void * rotate_panes (void * );
@@ -160,7 +162,8 @@ void ui_sync(struct ui_ctx *ctx)
160162 fprintf (stderr , "failed to write to sync_fd_tx: %s" , STR_ERR );
161163}
162164
163- static enum sleep_result cancellable_sleep (int cancellation_fd , int sync_fd , int * sleep_time )
165+ static enum sleep_result cancellable_sleep (
166+ int cancellation_fd , int sync_fd , int * sleep_time )
164167{
165168 // If sleep_time is too low during a barrage of requests, poll(2) might
166169 // just not exhuast its timeout, and delta will be zero we'll never
@@ -182,27 +185,30 @@ static enum sleep_result cancellable_sleep(int cancellation_fd, int sync_fd, int
182185 clock_gettime (CLOCK_MONOTONIC_RAW , & a );
183186
184187 int r = poll (fds , sizeof (fds ) / sizeof (* fds ), * sleep_time );
185- if (r == -1 ) FATAL_ERR ("cancellable_sleep: poll(2) failed: %s" , STR_ERR );
188+ if (r == -1 )
189+ FATAL_ERR ("cancellable_sleep: poll(2) failed: %s" , STR_ERR );
186190
187191 if (fds [0 ].revents &= POLLIN ) {
188192 // Cancellation fd.
189193 if (read (fds [0 ].fd , buf , 1 ) != 1 )
190- fprintf (stderr , "cancellable_sleep: failed to read from cancellation fd.\n" );
194+ fprintf (stderr ,
195+ "cancellable_sleep: failed to read from cancellation fd.\n" );
191196
192197 * sleep_time = PANE_DELAY ;
193198 return SHOULD_CANCEL ;
194199 } else if (fds [1 ].revents &= POLLIN ) {
195200 // Sync fd.
196201 if (read (fds [1 ].fd , buf , 1 ) != 1 )
197- fprintf (stderr , "cancellable_sleep: failed to read from sync fd.\n" );
202+ fprintf (stderr ,
203+ "cancellable_sleep: failed to read from sync fd.\n" );
198204
199205 clock_gettime (CLOCK_MONOTONIC_RAW , & b );
200206
201207 uint64_t prior = (a .tv_sec * 1000 ) + (a .tv_nsec / 1000 / 1000 );
202208 uint64_t post = (b .tv_sec * 1000 ) + (b .tv_nsec / 1000 / 1000 );
203- int delta = (int ) post - prior ;
209+ int delta = (int )post - prior ;
204210
205- if (delta < 20 )
211+ if (delta < 20 )
206212 delta += 20 ;
207213
208214 if (delta >= * sleep_time ) {
@@ -234,7 +240,8 @@ static void *rotate_panes(void *arg)
234240 FATAL_ERR ("ui: couldn't take lock: %s" , strerror (r ));
235241
236242 i += switching ;
237- if (i >= ctx -> panes .count ) i = 0 ;
243+ if (i >= ctx -> panes .count )
244+ i = 0 ;
238245
239246 struct pane * p = & ctx -> panes .panes [i ];
240247
@@ -245,7 +252,8 @@ static void *rotate_panes(void *arg)
245252 if (r != 0 )
246253 FATAL_ERR ("ui: couldn't return lock: %s" , strerror (r ));
247254
248- enum sleep_result r = cancellable_sleep (ctx -> cancellation_fd , ctx -> sync_fd_rx , & sleep_time );
255+ enum sleep_result r = cancellable_sleep (
256+ ctx -> cancellation_fd , ctx -> sync_fd_rx , & sleep_time );
249257 switch (r ) {
250258 case SHOULD_SWITCH :
251259 switching = true;
@@ -314,6 +322,18 @@ enum ui_failure ui_pane_create(
314322 return UI_OK ;
315323}
316324
325+ size_t ui_pane_count (struct ui_ctx * ctx )
326+ {
327+ int r = pthread_mutex_lock (& ctx -> panes .lock );
328+ if (r != 0 )
329+ FATAL_ERR (
330+ "ui_pane_count: failed to take lock: %s" , strerror (r ));
331+
332+ size_t ret = ctx -> panes .count ;
333+ pthread_mutex_unlock (& ctx -> panes .lock );
334+ return ret ;
335+ }
336+
317337enum ui_failure ui_pane_remove (struct ui_ctx * ctx , char * name )
318338{
319339 int r ;
0 commit comments