rofi  1.6.0
view.c
Go to the documentation of this file.
1 /*
2  * rofi
3  *
4  * MIT/X11 License
5  * Copyright © 2013-2020 Qball Cow <qball@gmpclient.org>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  */
27 
29 #define G_LOG_DOMAIN "View"
30 
31 #include <config.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <unistd.h>
36 #include <stdint.h>
37 #include <signal.h>
38 #include <errno.h>
39 #include <time.h>
40 #include <locale.h>
41 #include <xkbcommon/xkbcommon-x11.h>
42 #include <xcb/xkb.h>
43 #include <xcb/xcb_ewmh.h>
44 #include <xcb/xcb_icccm.h>
45 
46 #include <cairo.h>
47 #include <cairo-xcb.h>
48 
50 #define SN_API_NOT_YET_FROZEN
51 #include <libsn/sn.h>
52 #include "rofi.h"
53 
54 #include "timings.h"
55 #include "settings.h"
56 
57 #include "mode.h"
58 #include "display.h"
59 #include "xcb-internal.h"
60 #include "helper.h"
61 #include "helper-theme.h"
62 #include "xrmoptions.h"
63 #include "dialogs/dialogs.h"
64 
65 #include "view.h"
66 #include "view-internal.h"
67 
68 #include "theme.h"
69 
70 #include "xcb.h"
71 
78 void rofi_view_update ( RofiViewState *state, gboolean qr );
79 
80 static int rofi_view_calculate_height ( RofiViewState *state );
81 
83 GThreadPool *tpool = NULL;
84 
87 
91 struct
92 {
94  xcb_window_t main_window;
96  cairo_surface_t *fake_bg;
98  xcb_gcontext_t gc;
100  xcb_pixmap_t edit_pixmap;
102  cairo_surface_t *edit_surf;
104  cairo_t *edit_draw;
110  GQueue views;
116  unsigned long long count;
120  gboolean fullscreen;
121 } CacheState = {
122  .main_window = XCB_WINDOW_NONE,
123  .fake_bg = NULL,
124  .edit_surf = NULL,
125  .edit_draw = NULL,
126  .fake_bgrel = FALSE,
127  .flags = MENU_NORMAL,
128  .views = G_QUEUE_INIT,
129  .idle_timeout = 0,
130  .count = 0L,
131  .repaint_source = 0,
132  .fullscreen = FALSE,
133 };
134 
135 void rofi_view_get_current_monitor ( int *width, int *height )
136 {
137  if ( width ) {
138  *width = CacheState.mon.w;
139  }
140  if ( height ) {
141  *height = CacheState.mon.h;
142  }
143 }
144 static char * get_matching_state ( void )
145 {
146  if ( config.case_sensitive ) {
147  if ( config.sort ) {
148  return "±";
149  }
150  else {
151  return "-";
152  }
153  }
154  else{
155  if ( config.sort ) {
156  return "+";
157  }
158  }
159  return " ";
160 }
161 
165 static int lev_sort ( const void *p1, const void *p2, void *arg )
166 {
167  const int *a = p1;
168  const int *b = p2;
169  int *distances = arg;
170 
171  return distances[*a] - distances[*b];
172 }
173 
178 {
179  const char *outp = g_getenv ( "ROFI_PNG_OUTPUT" );
180  if ( CacheState.edit_surf == NULL ) {
181  // Nothing to store.
182  g_warning ( "There is no rofi surface to store" );
183  return;
184  }
185  const char *xdg_pict_dir = g_get_user_special_dir ( G_USER_DIRECTORY_PICTURES );
186  if ( outp == NULL && xdg_pict_dir == NULL ) {
187  g_warning ( "XDG user picture directory or ROFI_PNG_OUTPUT is not set. Cannot store screenshot." );
188  return;
189  }
190  // Get current time.
191  GDateTime *now = g_date_time_new_now_local ();
192  // Format filename.
193  char *timestmp = g_date_time_format ( now, "rofi-%Y-%m-%d-%H%M" );
194  char *filename = g_strdup_printf ( "%s-%05d.png", timestmp, 0 );
195  // Build full path
196  char *fpath = NULL;
197  if ( outp == NULL ) {
198  int index = 0;
199  fpath = g_build_filename ( xdg_pict_dir, filename, NULL );
200  while ( g_file_test ( fpath, G_FILE_TEST_EXISTS ) && index < 99 ) {
201  g_free ( fpath );
202  g_free ( filename );
203  // Try the next index.
204  index++;
205  // Format filename.
206  filename = g_strdup_printf ( "%s-%05d.png", timestmp, index );
207  // Build full path
208  fpath = g_build_filename ( xdg_pict_dir, filename, NULL );
209  }
210  }
211  else {
212  fpath = g_strdup ( outp );
213  }
214  fprintf ( stderr, color_green "Storing screenshot %s\n"color_reset, fpath );
215  cairo_status_t status = cairo_surface_write_to_png ( CacheState.edit_surf, fpath );
216  if ( status != CAIRO_STATUS_SUCCESS ) {
217  g_warning ( "Failed to produce screenshot '%s', got error: '%s'", fpath,
218  cairo_status_to_string ( status ) );
219  }
220  g_free ( fpath );
221  g_free ( filename );
222  g_free ( timestmp );
223  g_date_time_unref ( now );
224 }
225 
229 gboolean do_bench = TRUE;
230 struct
231 {
232  GTimer *time;
233  uint64_t draws;
234  double last_ts;
235  double min;
236 } BenchMark = {
237  .time = NULL,
238  .draws = 0,
239  .last_ts = 0.0,
240  .min = G_MAXDOUBLE
241 };
242 
243 static gboolean bench_update ( void )
244 {
245  if ( !config.benchmark_ui ) {
246  return FALSE;
247  }
248  BenchMark.draws++;
249  if ( BenchMark.time == NULL ) {
250  BenchMark.time = g_timer_new ();
251  }
252 
253  if ( ( BenchMark.draws & 1023 ) == 0 ) {
254  double ts = g_timer_elapsed ( BenchMark.time, NULL );
255  double fps = 1024 / ( ts - BenchMark.last_ts );
256 
257  if ( fps < BenchMark.min ) {
258  BenchMark.min = fps;
259  }
260  printf ( "current: %.2f fps, avg: %.2f fps, min: %.2f fps, %lu draws\r\n", fps, BenchMark.draws / ts, BenchMark.min, BenchMark.draws );
261 
262  BenchMark.last_ts = ts;
263  }
264  return TRUE;
265 }
266 
267 static gboolean rofi_view_repaint ( G_GNUC_UNUSED void * data )
268 {
269  if ( current_active_menu ) {
270  // Repaint the view (if needed).
271  // After a resize the edit_pixmap surface might not contain anything anymore.
272  // If we already re-painted, this does nothing.
274  g_debug ( "expose event" );
275  TICK_N ( "Expose" );
276  xcb_copy_area ( xcb->connection, CacheState.edit_pixmap, CacheState.main_window, CacheState.gc,
278  xcb_flush ( xcb->connection );
279  TICK_N ( "flush" );
280  CacheState.repaint_source = 0;
281  }
282  return ( bench_update () == TRUE ) ? G_SOURCE_CONTINUE : G_SOURCE_REMOVE;
283 }
284 
286 {
287  if ( state->prompt ) {
288  const char *str = mode_get_display_name ( state->sw );
289  textbox_text ( state->prompt, str );
290  }
291 }
292 
305 static const int loc_transtable[9] = {
306  WL_CENTER,
307  WL_NORTH | WL_WEST,
308  WL_NORTH,
309  WL_NORTH | WL_EAST,
310  WL_EAST,
311  WL_SOUTH | WL_EAST,
312  WL_SOUTH,
313  WL_SOUTH | WL_WEST,
314  WL_WEST
315 };
317 {
318  int location = rofi_theme_get_position ( WIDGET ( state->main_window ), "location", loc_transtable[config.location] );
319  int anchor = location;
320  if ( !listview_get_fixed_num_lines ( state->list_view ) ) {
321  anchor = location;
322  if ( location == WL_CENTER ) {
323  anchor = WL_NORTH;
324  }
325  else if ( location == WL_EAST ) {
326  anchor = WL_NORTH_EAST;
327  }
328  else if ( location == WL_WEST ) {
329  anchor = WL_NORTH_WEST;
330  }
331  }
332  anchor = rofi_theme_get_position ( WIDGET ( state->main_window ), "anchor", anchor );
333 
334  if ( CacheState.fullscreen ) {
335  state->x = CacheState.mon.x;
336  state->y = CacheState.mon.y;
337  return;
338  }
339  state->y = CacheState.mon.y + ( CacheState.mon.h ) / 2;
340  state->x = CacheState.mon.x + ( CacheState.mon.w ) / 2;
341  // Determine window location
342  switch ( location )
343  {
344  case WL_NORTH_WEST:
345  state->x = CacheState.mon.x;
346  /* FALLTHRU */
347  case WL_NORTH:
348  state->y = CacheState.mon.y;
349  break;
350  case WL_NORTH_EAST:
351  state->y = CacheState.mon.y;
352  /* FALLTHRU */
353  case WL_EAST:
354  state->x = CacheState.mon.x + CacheState.mon.w;
355  break;
356  case WL_SOUTH_EAST:
357  state->x = CacheState.mon.x + CacheState.mon.w;
358  /* FALLTHRU */
359  case WL_SOUTH:
360  state->y = CacheState.mon.y + CacheState.mon.h;
361  break;
362  case WL_SOUTH_WEST:
363  state->y = CacheState.mon.y + CacheState.mon.h;
364  /* FALLTHRU */
365  case WL_WEST:
366  state->x = CacheState.mon.x;
367  break;
368  case WL_CENTER:
369  ;
370  /* FALLTHRU */
371  default:
372  break;
373  }
374  switch ( anchor )
375  {
376  case WL_SOUTH_WEST:
377  state->y -= state->height;
378  break;
379  case WL_SOUTH:
380  state->x -= state->width / 2;
381  state->y -= state->height;
382  break;
383  case WL_SOUTH_EAST:
384  state->x -= state->width;
385  state->y -= state->height;
386  break;
387  case WL_NORTH_EAST:
388  state->x -= state->width;
389  break;
390  case WL_NORTH_WEST:
391  break;
392  case WL_NORTH:
393  state->x -= state->width / 2;
394  break;
395  case WL_EAST:
396  state->x -= state->width;
397  state->y -= state->height / 2;
398  break;
399  case WL_WEST:
400  state->y -= state->height / 2;
401  break;
402  case WL_CENTER:
403  state->y -= state->height / 2;
404  state->x -= state->width / 2;
405  break;
406  default:
407  break;
408  }
409  // Apply offset.
410  RofiDistance x = rofi_theme_get_distance ( WIDGET ( state->main_window ), "x-offset", config.x_offset );
411  RofiDistance y = rofi_theme_get_distance ( WIDGET ( state->main_window ), "y-offset", config.y_offset );
414 }
415 
417 {
418  uint16_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
419  uint32_t vals[] = { state->x, state->y, state->width, state->height };
420 
421  // Display it.
422  xcb_configure_window ( xcb->connection, CacheState.main_window, mask, vals );
423  cairo_destroy ( CacheState.edit_draw );
424  cairo_surface_destroy ( CacheState.edit_surf );
425 
426  xcb_free_pixmap ( xcb->connection, CacheState.edit_pixmap );
427  CacheState.edit_pixmap = xcb_generate_id ( xcb->connection );
428  xcb_create_pixmap ( xcb->connection, depth->depth,
429  CacheState.edit_pixmap, CacheState.main_window, state->width, state->height );
430 
431  CacheState.edit_surf = cairo_xcb_surface_create ( xcb->connection, CacheState.edit_pixmap, visual, state->width, state->height );
432  CacheState.edit_draw = cairo_create ( CacheState.edit_surf );
433 
434  g_debug ( "Re-size window based internal request: %dx%d.", state->width, state->height );
435  // Should wrap main window in a widget.
436  widget_resize ( WIDGET ( state->main_window ), state->width, state->height );
437 }
438 
440 {
441  if ( state->mesg_box == NULL ) {
442  return;
443  }
444  char *msg = mode_get_message ( state->sw );
445  if ( msg ) {
446  textbox_text ( state->mesg_tb, msg );
447  widget_enable ( WIDGET ( state->mesg_box ) );
448  g_free ( msg );
449  }
450  else {
451  widget_disable ( WIDGET ( state->mesg_box ) );
452  }
453 }
454 
455 static gboolean rofi_view_reload_idle ( G_GNUC_UNUSED gpointer data )
456 {
457  if ( current_active_menu ) {
458  current_active_menu->reload = TRUE;
461  }
462  CacheState.idle_timeout = 0;
463  return G_SOURCE_REMOVE;
464 }
465 
466 void rofi_view_reload ( void )
467 {
468  // @TODO add check if current view is equal to the callee
469  if ( CacheState.idle_timeout == 0 ) {
470  CacheState.idle_timeout = g_timeout_add ( 1000 / 10, rofi_view_reload_idle, NULL );
471  }
472 }
474 {
475  if ( current_active_menu && CacheState.repaint_source == 0 ) {
476  CacheState.count++;
477  g_debug ( "redraw %llu", CacheState.count );
478  CacheState.repaint_source = g_idle_add_full ( G_PRIORITY_HIGH_IDLE, rofi_view_repaint, NULL, NULL );
479  }
480 }
481 
483 {
484  state->quit = FALSE;
485  state->retv = MENU_CANCEL;
486 }
487 
489 {
490  return current_active_menu;
491 }
492 
494 {
495  if ( current_active_menu != NULL && state != NULL ) {
496  g_queue_push_head ( &( CacheState.views ), current_active_menu );
497  // TODO check.
498  current_active_menu = state;
499  g_debug ( "stack view." );
502  return;
503  }
504  else if ( state == NULL && !g_queue_is_empty ( &( CacheState.views ) ) ) {
505  g_debug ( "pop view." );
506  current_active_menu = g_queue_pop_head ( &( CacheState.views ) );
509  return;
510  }
511  g_assert ( ( current_active_menu == NULL && state != NULL ) || ( current_active_menu != NULL && state == NULL ) );
512  current_active_menu = state;
514 }
515 
516 void rofi_view_set_selected_line ( RofiViewState *state, unsigned int selected_line )
517 {
518  state->selected_line = selected_line;
519  // Find the line.
520  unsigned int selected = 0;
521  for ( unsigned int i = 0; ( ( state->selected_line ) ) < UINT32_MAX && !selected && i < state->filtered_lines; i++ ) {
522  if ( state->line_map[i] == ( state->selected_line ) ) {
523  selected = i;
524  break;
525  }
526  }
527  listview_set_selected ( state->list_view, selected );
528  xcb_clear_area ( xcb->connection, CacheState.main_window, 1, 0, 0, 1, 1 );
529  xcb_flush ( xcb->connection );
530 }
531 
533 {
534  if ( state->tokens ) {
535  helper_tokenize_free ( state->tokens );
536  state->tokens = NULL;
537  }
538  // Do this here?
539  // Wait for final release?
540  widget_free ( WIDGET ( state->main_window ) );
541 
542  g_free ( state->line_map );
543  g_free ( state->distance );
544  // Free the switcher boxes.
545  // When state is free'ed we should no longer need these.
546  g_free ( state->modi );
547  state->num_modi = 0;
548  g_free ( state );
549 }
550 
552 {
553  return state->retv;
554 }
555 
556 unsigned int rofi_view_get_selected_line ( const RofiViewState *state )
557 {
558  return state->selected_line;
559 }
560 
561 unsigned int rofi_view_get_next_position ( const RofiViewState *state )
562 {
563  unsigned int next_pos = state->selected_line;
564  unsigned int selected = listview_get_selected ( state->list_view );
565  if ( ( selected + 1 ) < state->num_lines ) {
566  ( next_pos ) = state->line_map[selected + 1];
567  }
568  return next_pos;
569 }
570 
571 unsigned int rofi_view_get_completed ( const RofiViewState *state )
572 {
573  return state->quit;
574 }
575 
576 const char * rofi_view_get_user_input ( const RofiViewState *state )
577 {
578  if ( state->text ) {
579  return state->text->text;
580  }
581  return NULL;
582 }
583 
590 {
591  return g_malloc0 ( sizeof ( RofiViewState ) );
592 }
593 
597 typedef struct _thread_state_view
598 {
601 
603  GCond *cond;
605  GMutex *mutex;
607  unsigned int *acount;
608 
612  unsigned int start;
614  unsigned int stop;
616  unsigned int count;
617 
619  const char *pattern;
621  glong plen;
629 static void rofi_view_call_thread ( gpointer data, gpointer user_data )
630 {
631  thread_state *t = (thread_state *) data;
632  t->callback ( t, user_data );
633 }
634 
635 static void filter_elements ( thread_state *ts, G_GNUC_UNUSED gpointer user_data )
636 {
638  for ( unsigned int i = t->start; i < t->stop; i++ ) {
639  int match = mode_token_match ( t->state->sw, t->state->tokens, i );
640  // If each token was matched, add it to list.
641  if ( match ) {
642  t->state->line_map[t->start + t->count] = i;
643  if ( config.sort ) {
644  // This is inefficient, need to fix it.
645  char * str = mode_get_completion ( t->state->sw, i );
646  glong slen = g_utf8_strlen ( str, -1 );
647  switch ( config.sorting_method_enum )
648  {
649  case SORT_FZF:
650  t->state->distance[i] = rofi_scorer_fuzzy_evaluate ( t->pattern, t->plen, str, slen );
651  break;
652  case SORT_NORMAL:
653  default:
654  t->state->distance[i] = levenshtein ( t->pattern, t->plen, str, slen );
655  break;
656  }
657  g_free ( str );
658  }
659  t->count++;
660  }
661  }
662  if ( t->acount != NULL ) {
663  g_mutex_lock ( t->mutex );
664  ( *( t->acount ) )--;
665  g_cond_signal ( t->cond );
666  g_mutex_unlock ( t->mutex );
667  }
668 }
669 static void rofi_view_setup_fake_transparency ( const char* const fake_background )
670 {
671  if ( CacheState.fake_bg == NULL ) {
672  cairo_surface_t *s = NULL;
677  TICK_N ( "Fake start" );
678  if ( g_strcmp0 ( fake_background, "real" ) == 0 ) {
679  return;
680  }
681  else if ( g_strcmp0 ( fake_background, "screenshot" ) == 0 ) {
683  }
684  else if ( g_strcmp0 ( fake_background, "background" ) == 0 ) {
686  }
687  else {
688  char *fpath = rofi_expand_path ( fake_background );
689  g_debug ( "Opening %s to use as background.", fpath );
690  s = cairo_image_surface_create_from_png ( fpath );
691  CacheState.fake_bgrel = TRUE;
692  g_free ( fpath );
693  }
694  TICK_N ( "Get surface." );
695  if ( s != NULL ) {
696  if ( cairo_surface_status ( s ) != CAIRO_STATUS_SUCCESS ) {
697  g_debug ( "Failed to open surface fake background: %s",
698  cairo_status_to_string ( cairo_surface_status ( s ) ) );
699  cairo_surface_destroy ( s );
700  s = NULL;
701  }
702  else {
703  CacheState.fake_bg = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, CacheState.mon.w, CacheState.mon.h );
704  cairo_t *dr = cairo_create ( CacheState.fake_bg );
705  if ( CacheState.fake_bgrel ) {
706  cairo_set_source_surface ( dr, s, 0, 0 );
707  }
708  else {
709  cairo_set_source_surface ( dr, s, -CacheState.mon.x, -CacheState.mon.y );
710  }
711  cairo_paint ( dr );
712  cairo_destroy ( dr );
713  cairo_surface_destroy ( s );
714  }
715  }
716  TICK_N ( "Fake transparency" );
717  }
718 }
719 void __create_window ( MenuFlags menu_flags )
720 {
721  uint32_t selmask = XCB_CW_BACK_PIXMAP | XCB_CW_BORDER_PIXEL | XCB_CW_BIT_GRAVITY | XCB_CW_BACKING_STORE | XCB_CW_EVENT_MASK | XCB_CW_COLORMAP;
722  uint32_t selval[] = {
723  XCB_BACK_PIXMAP_NONE, 0,
724  XCB_GRAVITY_STATIC,
725  XCB_BACKING_STORE_NOT_USEFUL,
726  XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE |
727  XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_KEYMAP_STATE |
728  XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_FOCUS_CHANGE | XCB_EVENT_MASK_BUTTON_1_MOTION,
729  map
730  };
731 
732  xcb_window_t box_window = xcb_generate_id ( xcb->connection );
733  xcb_void_cookie_t cc = xcb_create_window_checked ( xcb->connection, depth->depth, box_window, xcb_stuff_get_root_window ( ),
734  0, 0, 200, 100, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
735  visual->visual_id, selmask, selval );
736  xcb_generic_error_t *error;
737  error = xcb_request_check ( xcb->connection, cc );
738  if ( error ) {
739  g_error ( "xcb_create_window() failed error=0x%x\n", error->error_code );
740  exit ( EXIT_FAILURE );
741  }
742  TICK_N ( "xcb create window" );
743  CacheState.gc = xcb_generate_id ( xcb->connection );
744  xcb_create_gc ( xcb->connection, CacheState.gc, box_window, 0, 0 );
745 
746  TICK_N ( "xcb create gc" );
747  // Create a drawable.
748  CacheState.edit_pixmap = xcb_generate_id ( xcb->connection );
749  xcb_create_pixmap ( xcb->connection, depth->depth,
750  CacheState.edit_pixmap, CacheState.main_window, 200, 100 );
751 
752  CacheState.edit_surf = cairo_xcb_surface_create ( xcb->connection, CacheState.edit_pixmap, visual, 200, 100 );
753  CacheState.edit_draw = cairo_create ( CacheState.edit_surf );
754 
755  TICK_N ( "create cairo surface" );
756  // Set up pango context.
757  cairo_font_options_t *fo = cairo_font_options_create ();
758  // Take font description from xlib surface
759  cairo_surface_get_font_options ( CacheState.edit_surf, fo );
760  // TODO should we update the drawable each time?
761  PangoContext *p = pango_cairo_create_context ( CacheState.edit_draw );
762  // Set the font options from the xlib surface
763  pango_cairo_context_set_font_options ( p, fo );
764  TICK_N ( "pango cairo font setup" );
765 
766  CacheState.main_window = box_window;
767  CacheState.flags = menu_flags;
768  monitor_active ( &( CacheState.mon ) );
769  // Setup dpi
770  if ( config.dpi > 1 ) {
771  PangoFontMap *font_map = pango_cairo_font_map_get_default ();
772  pango_cairo_font_map_set_resolution ( (PangoCairoFontMap *) font_map, (double) config.dpi );
773  }
774  else if ( config.dpi == 0 || config.dpi == 1 ) {
775  // Auto-detect mode.
776  double dpi = 96;
777  if ( CacheState.mon.mh > 0 && config.dpi == 1 ) {
778  dpi = ( CacheState.mon.h * 25.4 ) / (double) ( CacheState.mon.mh );
779  }
780  else {
781  dpi = ( xcb->screen->height_in_pixels * 25.4 ) / (double) ( xcb->screen->height_in_millimeters );
782  }
783 
784  g_debug ( "Auto-detected DPI: %.2lf", dpi );
785  PangoFontMap *font_map = pango_cairo_font_map_get_default ();
786  pango_cairo_font_map_set_resolution ( (PangoCairoFontMap *) font_map, dpi );
787  config.dpi = dpi;
788  }
789  else {
790  // default pango is 96.
791  PangoFontMap *font_map = pango_cairo_font_map_get_default ();
792  config.dpi = pango_cairo_font_map_get_resolution ( (PangoCairoFontMap *) font_map );
793  }
794  // Setup font.
795  // Dummy widget.
796  box *win = box_create ( NULL, "window", ROFI_ORIENTATION_HORIZONTAL );
797  const char *font = rofi_theme_get_string ( WIDGET ( win ), "font", config.menu_font );
798  if ( font ) {
799  PangoFontDescription *pfd = pango_font_description_from_string ( font );
800  if ( helper_validate_font ( pfd, font ) ) {
801  pango_context_set_font_description ( p, pfd );
802  }
803  pango_font_description_free ( pfd );
804  }
805  PangoLanguage *l = pango_language_get_default ();
806  pango_context_set_language ( p, l );
807  TICK_N ( "configure font" );
808 
809  // Tell textbox to use this context.
810  textbox_set_pango_context ( font, p );
811  // cleanup
812  g_object_unref ( p );
813  cairo_font_options_destroy ( fo );
814 
815  TICK_N ( "textbox setup" );
816  // // make it an unmanaged window
817  if ( ( ( menu_flags & MENU_NORMAL_WINDOW ) == 0 ) ) {
818  window_set_atom_prop ( box_window, xcb->ewmh._NET_WM_STATE, &( xcb->ewmh._NET_WM_STATE_ABOVE ), 1 );
819  uint32_t values[] = { 1 };
820  xcb_change_window_attributes ( xcb->connection, box_window, XCB_CW_OVERRIDE_REDIRECT, values );
821  }
822  else{
823  window_set_atom_prop ( box_window, xcb->ewmh._NET_WM_WINDOW_TYPE, &( xcb->ewmh._NET_WM_WINDOW_TYPE_NORMAL ), 1 );
824  x11_disable_decoration ( box_window );
825  }
826 
827  TICK_N ( "setup window attributes" );
828  CacheState.fullscreen = rofi_theme_get_boolean ( WIDGET ( win ), "fullscreen", config.fullscreen );
829  if ( CacheState.fullscreen ) {
830  xcb_atom_t atoms[] = {
831  xcb->ewmh._NET_WM_STATE_FULLSCREEN,
832  xcb->ewmh._NET_WM_STATE_ABOVE
833  };
834  window_set_atom_prop ( box_window, xcb->ewmh._NET_WM_STATE, atoms, sizeof ( atoms ) / sizeof ( xcb_atom_t ) );
835  }
836 
837  TICK_N ( "setup window fullscreen" );
838  // Set the WM_NAME
839  rofi_view_set_window_title ( "rofi" );
840  const char wm_class_name[] = "rofi\0Rofi";
841  xcb_icccm_set_wm_class ( xcb->connection, box_window, sizeof ( wm_class_name ), wm_class_name );
842 
843  TICK_N ( "setup window name and class" );
844  const char *transparency = rofi_theme_get_string ( WIDGET ( win ), "transparency", NULL );
845  if ( transparency ) {
846  rofi_view_setup_fake_transparency ( transparency );
847  }
850  }
851  if ( xcb->sncontext != NULL ) {
852  sn_launchee_context_setup_window ( xcb->sncontext, CacheState.main_window );
853  }
854  TICK_N ( "setup startup notification" );
855  widget_free ( WIDGET ( win ) );
856  TICK_N ( "done" );
857 
858  // Set the PID.
859  pid_t pid = getpid ();
860  xcb_ewmh_set_wm_pid ( &( xcb->ewmh ), CacheState.main_window, pid );
861 
862  // Get hostname
863  const char *hostname = g_get_host_name ();
864  char *ahost = g_hostname_to_ascii ( hostname );
865  if ( ahost != NULL ) {
866  xcb_icccm_set_wm_client_machine ( xcb->connection,
867  CacheState.main_window,
868  XCB_ATOM_STRING, 8,
869  strlen ( ahost ), ahost );
870  g_free ( ahost );
871  }
872 }
873 
880 {
881  if ( CacheState.fullscreen ) {
882  state->width = CacheState.mon.w;
883  return;
884  }
885  if ( config.menu_width < 0 ) {
886  double fw = textbox_get_estimated_char_width ( );
887  state->width = -( fw * config.menu_width );
888  state->width += widget_padding_get_padding_width ( WIDGET ( state->main_window ) );
889  }
890  else{
891  // Calculate as float to stop silly, big rounding down errors.
892  state->width = config.menu_width < 101 ? ( CacheState.mon.w / 100.0f ) * ( float ) config.menu_width : config.menu_width;
893  }
894  // Use theme configured width, if set.
895  RofiDistance width = rofi_theme_get_distance ( WIDGET ( state->main_window ), "width", state->width );
897 }
898 
908 static void rofi_view_nav_row_tab ( RofiViewState *state )
909 {
910  if ( state->filtered_lines == 1 ) {
911  state->retv = MENU_OK;
912  ( state->selected_line ) = state->line_map[listview_get_selected ( state->list_view )];
913  state->quit = 1;
914  return;
915  }
916 
917  // Double tab!
918  if ( state->filtered_lines == 0 && ROW_TAB == state->prev_action ) {
919  state->retv = MENU_NEXT;
920  ( state->selected_line ) = 0;
921  state->quit = TRUE;
922  }
923  else {
924  listview_nav_down ( state->list_view );
925  }
926  state->prev_action = ROW_TAB;
927 }
933 inline static void rofi_view_nav_row_select ( RofiViewState *state )
934 {
935  if ( state->list_view == NULL ) {
936  return;
937  }
938  unsigned int selected = listview_get_selected ( state->list_view );
939  // If a valid item is selected, return that..
940  if ( selected < state->filtered_lines ) {
941  char *str = mode_get_completion ( state->sw, state->line_map[selected] );
942  textbox_text ( state->text, str );
943  g_free ( str );
944  textbox_keybinding ( state->text, MOVE_END );
945  state->refilter = TRUE;
946  }
947 }
948 
954 inline static void rofi_view_nav_first ( RofiViewState * state )
955 {
956 // state->selected = 0;
957  listview_set_selected ( state->list_view, 0 );
958 }
959 
965 inline static void rofi_view_nav_last ( RofiViewState * state )
966 {
967  // If no lines, do nothing.
968  if ( state->filtered_lines == 0 ) {
969  return;
970  }
971  //state->selected = state->filtered_lines - 1;
972  listview_set_selected ( state->list_view, -1 );
973 }
974 
975 static void update_callback ( textbox *t, icon *ico, unsigned int index, void *udata, TextBoxFontType *type, gboolean full )
976 {
977  RofiViewState *state = (RofiViewState *) udata;
978  if ( full ) {
979  GList *add_list = NULL;
980  int fstate = 0;
981  char *text = mode_get_display_value ( state->sw, state->line_map[index], &fstate, &add_list, TRUE );
982  ( *type ) |= fstate;
983  // TODO needed for markup.
984  textbox_font ( t, *type );
985  // Move into list view.
986  textbox_text ( t, text );
987  PangoAttrList *list = textbox_get_pango_attributes ( t );
988  if ( list != NULL ) {
989  pango_attr_list_ref ( list );
990  }
991  else{
992  list = pango_attr_list_new ();
993  }
994  if ( ico ) {
995  int icon_height = widget_get_desired_height ( WIDGET ( ico ) );
996  cairo_surface_t *icon = mode_get_icon ( state->sw, state->line_map[index], icon_height );
997  icon_set_surface ( ico, icon );
998  }
999 
1000  if ( state->tokens && config.show_match ) {
1001  RofiHighlightColorStyle th = { ROFI_HL_BOLD | ROFI_HL_UNDERLINE, { 0.0, 0.0, 0.0, 0.0 } };
1002  th = rofi_theme_get_highlight ( WIDGET ( t ), "highlight", th );
1004  }
1005  for ( GList *iter = g_list_first ( add_list ); iter != NULL; iter = g_list_next ( iter ) ) {
1006  pango_attr_list_insert ( list, (PangoAttribute *) ( iter->data ) );
1007  }
1008  textbox_set_pango_attributes ( t, list );
1009  pango_attr_list_unref ( list );
1010  g_list_free ( add_list );
1011  g_free ( text );
1012  }
1013  else {
1014  int fstate = 0;
1015  mode_get_display_value ( state->sw, state->line_map[index], &fstate, NULL, FALSE );
1016  ( *type ) |= fstate;
1017  // TODO needed for markup.
1018  textbox_font ( t, *type );
1019  }
1020 }
1021 
1022 void rofi_view_update ( RofiViewState *state, gboolean qr )
1023 {
1024  if ( !widget_need_redraw ( WIDGET ( state->main_window ) ) ) {
1025  return;
1026  }
1027  g_debug ( "Redraw view" );
1028  TICK ();
1029  cairo_t *d = CacheState.edit_draw;
1030  cairo_set_operator ( d, CAIRO_OPERATOR_SOURCE );
1031  if ( CacheState.fake_bg != NULL ) {
1032  if ( CacheState.fake_bgrel ) {
1033  cairo_set_source_surface ( d, CacheState.fake_bg, 0.0, 0.0 );
1034  }
1035  else {
1036  cairo_set_source_surface ( d, CacheState.fake_bg,
1037  -(double) ( state->x - CacheState.mon.x ),
1038  -(double) ( state->y - CacheState.mon.y ) );
1039  }
1040  cairo_paint ( d );
1041  cairo_set_operator ( d, CAIRO_OPERATOR_OVER );
1042  }
1043  else {
1044  // Paint the background transparent.
1045  cairo_set_source_rgba ( d, 0, 0, 0, 0.0 );
1046  cairo_paint ( d );
1047  }
1048  TICK_N ( "Background" );
1049 
1050  // Always paint as overlay over the background.
1051  cairo_set_operator ( d, CAIRO_OPERATOR_OVER );
1052  widget_draw ( WIDGET ( state->main_window ), d );
1053 
1054  TICK_N ( "widgets" );
1055  cairo_surface_flush ( CacheState.edit_surf );
1056  if ( qr ) {
1058  }
1059 }
1060 
1061 static void _rofi_view_reload_row ( RofiViewState *state )
1062 {
1063  g_free ( state->line_map );
1064  g_free ( state->distance );
1065  state->num_lines = mode_get_num_entries ( state->sw );
1066  state->line_map = g_malloc0_n ( state->num_lines, sizeof ( unsigned int ) );
1067  state->distance = g_malloc0_n ( state->num_lines, sizeof ( int ) );
1068  listview_set_max_lines ( state->list_view, state->num_lines );
1069  rofi_view_reload_message_bar ( state );
1070 }
1071 
1072 static void rofi_view_refilter ( RofiViewState *state )
1073 {
1074  TICK_N ( "Filter start" );
1075  if ( state->reload ) {
1076  _rofi_view_reload_row ( state );
1077  state->reload = FALSE;
1078  }
1079  TICK_N ( "Filter reload rows" );
1080  if ( state->tokens ) {
1081  helper_tokenize_free ( state->tokens );
1082  state->tokens = NULL;
1083  }
1084  TICK_N ( "Filter tokenize" );
1085  if ( state->text && strlen ( state->text->text ) > 0 ) {
1086  unsigned int j = 0;
1087  gchar *pattern = mode_preprocess_input ( state->sw, state->text->text );
1088  glong plen = pattern ? g_utf8_strlen ( pattern, -1 ) : 0;
1089  state->tokens = helper_tokenize ( pattern, config.case_sensitive );
1096  unsigned int nt = MAX ( 1, state->num_lines / 500 );
1097  thread_state_view states[nt];
1098  GCond cond;
1099  GMutex mutex;
1100  g_mutex_init ( &mutex );
1101  g_cond_init ( &cond );
1102  unsigned int count = nt;
1103  unsigned int steps = ( state->num_lines + nt ) / nt;
1104  for ( unsigned int i = 0; i < nt; i++ ) {
1105  states[i].state = state;
1106  states[i].start = i * steps;
1107  states[i].stop = MIN ( state->num_lines, ( i + 1 ) * steps );
1108  states[i].count = 0;
1109  states[i].cond = &cond;
1110  states[i].mutex = &mutex;
1111  states[i].acount = &count;
1112  states[i].plen = plen;
1113  states[i].pattern = pattern;
1114  states[i].st.callback = filter_elements;
1115  if ( i > 0 ) {
1116  g_thread_pool_push ( tpool, &states[i], NULL );
1117  }
1118  }
1119  // Run one in this thread.
1120  rofi_view_call_thread ( &states[0], NULL );
1121  // No need to do this with only one thread.
1122  if ( nt > 1 ) {
1123  g_mutex_lock ( &mutex );
1124  while ( count > 0 ) {
1125  g_cond_wait ( &cond, &mutex );
1126  }
1127  g_mutex_unlock ( &mutex );
1128  }
1129  g_cond_clear ( &cond );
1130  g_mutex_clear ( &mutex );
1131  for ( unsigned int i = 0; i < nt; i++ ) {
1132  if ( j != states[i].start ) {
1133  memmove ( &( state->line_map[j] ), &( state->line_map[states[i].start] ), sizeof ( unsigned int ) * ( states[i].count ) );
1134  }
1135  j += states[i].count;
1136  }
1137  if ( config.sort ) {
1138  g_qsort_with_data ( state->line_map, j, sizeof ( int ), lev_sort, state->distance );
1139  }
1140 
1141  // Cleanup + bookkeeping.
1142  state->filtered_lines = j;
1143  g_free ( pattern );
1144  }
1145  else{
1146  for ( unsigned int i = 0; i < state->num_lines; i++ ) {
1147  state->line_map[i] = i;
1148  }
1149  state->filtered_lines = state->num_lines;
1150  }
1151  TICK_N ( "Filter matching done" );
1153 
1154  if ( state->tb_filtered_rows ) {
1155  char *r = g_strdup_printf ( "%u", state->filtered_lines );
1156  textbox_text ( state->tb_filtered_rows, r );
1157  g_free ( r );
1158  }
1159  if ( state->tb_total_rows ) {
1160  char *r = g_strdup_printf ( "%u", state->num_lines );
1161  textbox_text ( state->tb_total_rows, r );
1162  g_free ( r );
1163  }
1164  TICK_N ( "Update filter lines" );
1165 
1166  if ( config.auto_select == TRUE && state->filtered_lines == 1 && state->num_lines > 1 ) {
1167  ( state->selected_line ) = state->line_map[listview_get_selected ( state->list_view )];
1168  state->retv = MENU_OK;
1169  state->quit = TRUE;
1170  }
1171 
1172  // Size the window.
1173  int height = rofi_view_calculate_height ( state );
1174  if ( height != state->height ) {
1175  state->height = height;
1177  rofi_view_window_update_size ( state );
1178  g_debug ( "Resize based on re-filter" );
1179  }
1180  TICK_N ( "Filter resize window based on window " );
1181  state->refilter = FALSE;
1182  TICK_N ( "Filter done" );
1183 }
1189 void process_result ( RofiViewState *state );
1191 {
1192  if ( state && state->finalize != NULL ) {
1193  state->finalize ( state );
1194  }
1195 }
1196 
1198 {
1199  RofiViewState *state = rofi_view_get_active ();
1200  switch ( action )
1201  {
1202  // Handling of paste
1203  case PASTE_PRIMARY:
1204  xcb_convert_selection ( xcb->connection, CacheState.main_window, XCB_ATOM_PRIMARY,
1205  xcb->ewmh.UTF8_STRING, xcb->ewmh.UTF8_STRING, XCB_CURRENT_TIME );
1206  xcb_flush ( xcb->connection );
1207  break;
1208  case PASTE_SECONDARY:
1209  xcb_convert_selection ( xcb->connection, CacheState.main_window, netatoms[CLIPBOARD],
1210  xcb->ewmh.UTF8_STRING, xcb->ewmh.UTF8_STRING, XCB_CURRENT_TIME );
1211  xcb_flush ( xcb->connection );
1212  break;
1213  case SCREENSHOT:
1215  break;
1216  case CHANGE_ELLIPSIZE:
1217  if ( state->list_view ) {
1219  }
1220  break;
1221  case TOGGLE_SORT:
1222  if ( state->case_indicator != NULL ) {
1223  config.sort = !config.sort;
1224  state->refilter = TRUE;
1226  }
1227  break;
1228  case MODE_PREVIOUS:
1229  state->retv = MENU_PREVIOUS;
1230  ( state->selected_line ) = 0;
1231  state->quit = TRUE;
1232  break;
1233  // Menu navigation.
1234  case MODE_NEXT:
1235  state->retv = MENU_NEXT;
1236  ( state->selected_line ) = 0;
1237  state->quit = TRUE;
1238  break;
1239  // Toggle case sensitivity.
1241  if ( state->case_indicator != NULL ) {
1243  ( state->selected_line ) = 0;
1244  state->refilter = TRUE;
1246  }
1247  break;
1248  // Special delete entry command.
1249  case DELETE_ENTRY:
1250  {
1251  unsigned int selected = listview_get_selected ( state->list_view );
1252  if ( selected < state->filtered_lines ) {
1253  ( state->selected_line ) = state->line_map[selected];
1254  state->retv = MENU_ENTRY_DELETE;
1255  state->quit = TRUE;
1256  }
1257  break;
1258  }
1259  case SELECT_ELEMENT_1:
1260  case SELECT_ELEMENT_2:
1261  case SELECT_ELEMENT_3:
1262  case SELECT_ELEMENT_4:
1263  case SELECT_ELEMENT_5:
1264  case SELECT_ELEMENT_6:
1265  case SELECT_ELEMENT_7:
1266  case SELECT_ELEMENT_8:
1267  case SELECT_ELEMENT_9:
1268  case SELECT_ELEMENT_10:
1269  {
1270  unsigned int index = action - SELECT_ELEMENT_1;
1271  if ( index < state->filtered_lines ) {
1272  state->selected_line = state->line_map[index];
1273  state->retv = MENU_OK;
1274  state->quit = TRUE;
1275  }
1276  break;
1277  }
1278  case CUSTOM_1:
1279  case CUSTOM_2:
1280  case CUSTOM_3:
1281  case CUSTOM_4:
1282  case CUSTOM_5:
1283  case CUSTOM_6:
1284  case CUSTOM_7:
1285  case CUSTOM_8:
1286  case CUSTOM_9:
1287  case CUSTOM_10:
1288  case CUSTOM_11:
1289  case CUSTOM_12:
1290  case CUSTOM_13:
1291  case CUSTOM_14:
1292  case CUSTOM_15:
1293  case CUSTOM_16:
1294  case CUSTOM_17:
1295  case CUSTOM_18:
1296  case CUSTOM_19:
1297  {
1298  state->selected_line = UINT32_MAX;
1299  unsigned int selected = listview_get_selected ( state->list_view );
1300  if ( selected < state->filtered_lines ) {
1301  ( state->selected_line ) = state->line_map[selected];
1302  }
1303  state->retv = MENU_QUICK_SWITCH | ( ( action - CUSTOM_1 ) & MENU_LOWER_MASK );
1304  state->quit = TRUE;
1305  break;
1306  }
1307  // If you add a binding here, make sure to add it to rofi_view_keyboard_navigation too
1308  case CANCEL:
1309  state->retv = MENU_CANCEL;
1310  state->quit = TRUE;
1311  break;
1312  case ROW_UP:
1313  listview_nav_up ( state->list_view );
1314  break;
1315  case ROW_TAB:
1316  rofi_view_nav_row_tab ( state );
1317  break;
1318  case ROW_DOWN:
1319  listview_nav_down ( state->list_view );
1320  break;
1321  case ROW_LEFT:
1322  listview_nav_left ( state->list_view );
1323  break;
1324  case ROW_RIGHT:
1325  listview_nav_right ( state->list_view );
1326  break;
1327  case PAGE_PREV:
1328  listview_nav_page_prev ( state->list_view );
1329  break;
1330  case PAGE_NEXT:
1331  listview_nav_page_next ( state->list_view );
1332  break;
1333  case ROW_FIRST:
1334  rofi_view_nav_first ( state );
1335  break;
1336  case ROW_LAST:
1337  rofi_view_nav_last ( state );
1338  break;
1339  case ROW_SELECT:
1340  rofi_view_nav_row_select ( state );
1341  break;
1342  // If you add a binding here, make sure to add it to textbox_keybinding too
1343  case MOVE_CHAR_BACK:
1344  {
1345  if ( textbox_keybinding ( state->text, action ) == 0 ) {
1346  listview_nav_left ( state->list_view );
1347  }
1348  break;
1349  }
1350  case MOVE_CHAR_FORWARD:
1351  {
1352  if ( textbox_keybinding ( state->text, action ) == 0 ) {
1353  listview_nav_right ( state->list_view );
1354  }
1355  break;
1356  }
1357  case CLEAR_LINE:
1358  case MOVE_FRONT:
1359  case MOVE_END:
1360  case REMOVE_TO_EOL:
1361  case REMOVE_TO_SOL:
1362  case REMOVE_WORD_BACK:
1363  case REMOVE_WORD_FORWARD:
1364  case REMOVE_CHAR_FORWARD:
1365  case MOVE_WORD_BACK:
1366  case MOVE_WORD_FORWARD:
1367  case REMOVE_CHAR_BACK:
1368  {
1369  int rc = textbox_keybinding ( state->text, action );
1370  if ( rc == 1 ) {
1371  // Entry changed.
1372  state->refilter = TRUE;
1373  }
1374  else if ( rc == 2 ) {
1375  // Movement.
1376  }
1377  break;
1378  }
1379  case ACCEPT_ALT:
1380  {
1381  unsigned int selected = listview_get_selected ( state->list_view );
1382  state->selected_line = UINT32_MAX;
1383  if ( selected < state->filtered_lines ) {
1384  ( state->selected_line ) = state->line_map[selected];
1385  state->retv = MENU_OK;
1386  }
1387  else {
1388  // Nothing entered and nothing selected.
1389  state->retv = MENU_CUSTOM_INPUT;
1390  }
1391  state->retv |= MENU_CUSTOM_ACTION;
1392  state->quit = TRUE;
1393  break;
1394  }
1395  case ACCEPT_CUSTOM:
1396  {
1397  state->selected_line = UINT32_MAX;
1398  state->retv = MENU_CUSTOM_INPUT;
1399  state->quit = TRUE;
1400  break;
1401  }
1402  case ACCEPT_ENTRY:
1403  {
1404  // If a valid item is selected, return that..
1405  unsigned int selected = listview_get_selected ( state->list_view );
1406  state->selected_line = UINT32_MAX;
1407  if ( selected < state->filtered_lines ) {
1408  ( state->selected_line ) = state->line_map[selected];
1409  state->retv = MENU_OK;
1410  }
1411  else {
1412  // Nothing entered and nothing selected.
1413  state->retv = MENU_CUSTOM_INPUT;
1414  }
1415 
1416  state->quit = TRUE;
1417  break;
1418  }
1419  }
1420 }
1421 
1422 gboolean rofi_view_trigger_action ( RofiViewState *state, BindingsScope scope, guint action )
1423 {
1424  switch ( scope )
1425  {
1426  case SCOPE_GLOBAL:
1428  return TRUE;
1429  case SCOPE_MOUSE_LISTVIEW:
1431  case SCOPE_MOUSE_EDITBOX:
1432  case SCOPE_MOUSE_SCROLLBAR:
1434  {
1435  gint x = state->mouse.x, y = state->mouse.y;
1436  widget *target = widget_find_mouse_target ( WIDGET ( state->main_window ), scope, x, y );
1437  if ( target == NULL ) {
1438  return FALSE;
1439  }
1440  widget_xy_to_relative ( target, &x, &y );
1441  switch ( widget_trigger_action ( target, action, x, y ) )
1442  {
1444  return FALSE;
1446  target = NULL;
1447  /* FALLTHRU */
1449  state->mouse.motion_target = target;
1450  /* FALLTHRU */
1452  return TRUE;
1453  }
1454  break;
1455  }
1456  }
1457  return FALSE;
1458 }
1459 
1460 void rofi_view_handle_text ( RofiViewState *state, char *text )
1461 {
1462  if ( textbox_append_text ( state->text, text, strlen ( text ) ) ) {
1463  state->refilter = TRUE;
1464  }
1465 }
1466 
1467 void rofi_view_handle_mouse_motion ( RofiViewState *state, gint x, gint y )
1468 {
1469  state->mouse.x = x;
1470  state->mouse.y = y;
1471  if ( state->mouse.motion_target != NULL ) {
1472  widget_xy_to_relative ( state->mouse.motion_target, &x, &y );
1473  widget_motion_notify ( state->mouse.motion_target, x, y );
1474  }
1475 }
1476 
1478 {
1479  if ( rofi_view_get_completed ( state ) ) {
1480  // This menu is done.
1481  rofi_view_finalize ( state );
1482  // If there a state. (for example error) reload it.
1483  state = rofi_view_get_active ();
1484 
1485  // cleanup, if no more state to display.
1486  if ( state == NULL ) {
1487  // Quit main-loop.
1489  return;
1490  }
1491  }
1492 
1493  // Update if requested.
1494  if ( state->refilter ) {
1495  rofi_view_refilter ( state );
1496  }
1497  rofi_view_update ( state, TRUE );
1498 }
1499 
1504 void rofi_view_temp_configure_notify ( RofiViewState *state, xcb_configure_notify_event_t *xce )
1505 {
1506  if ( xce->window == CacheState.main_window ) {
1507  if ( state->x != xce->x || state->y != xce->y ) {
1508  state->x = xce->x;
1509  state->y = xce->y;
1510  widget_queue_redraw ( WIDGET ( state->main_window ) );
1511  }
1512  if ( state->width != xce->width || state->height != xce->height ) {
1513  state->width = xce->width;
1514  state->height = xce->height;
1515 
1516  cairo_destroy ( CacheState.edit_draw );
1517  cairo_surface_destroy ( CacheState.edit_surf );
1518 
1519  xcb_free_pixmap ( xcb->connection, CacheState.edit_pixmap );
1520  CacheState.edit_pixmap = xcb_generate_id ( xcb->connection );
1521  xcb_create_pixmap ( xcb->connection, depth->depth, CacheState.edit_pixmap, CacheState.main_window,
1522  state->width, state->height );
1523 
1524  CacheState.edit_surf = cairo_xcb_surface_create ( xcb->connection, CacheState.edit_pixmap, visual, state->width, state->height );
1525  CacheState.edit_draw = cairo_create ( CacheState.edit_surf );
1526  g_debug ( "Re-size window based external request: %d %d", state->width, state->height );
1527  widget_resize ( WIDGET ( state->main_window ), state->width, state->height );
1528  }
1529  }
1530 }
1531 
1535 void rofi_view_temp_click_to_exit ( RofiViewState *state, xcb_window_t target )
1536 {
1537  if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == 0 ) {
1538  if ( target != CacheState.main_window ) {
1539  state->quit = TRUE;
1540  state->retv = MENU_CANCEL;
1541  }
1542  }
1543 }
1544 
1546 {
1547  if ( CacheState.repaint_source == 0 ) {
1548  CacheState.repaint_source = g_idle_add_full ( G_PRIORITY_HIGH_IDLE, rofi_view_repaint, NULL, NULL );
1549  }
1550 }
1551 
1553 {
1554  if ( CacheState.fullscreen == TRUE ) {
1555  return CacheState.mon.h;
1556  }
1557 
1558  RofiDistance h = rofi_theme_get_distance ( WIDGET ( state->main_window ), "height", 0 );
1559  unsigned int height = distance_get_pixel ( h, ROFI_ORIENTATION_VERTICAL );
1560  // If height is set, return it.
1561  if ( height > 0 ) {
1562  return height;
1563  }
1564  // Autosize based on widgets.
1565  widget *main_window = WIDGET ( state->main_window );
1567 }
1568 
1569 static WidgetTriggerActionResult textbox_button_trigger_action ( widget *wid, MouseBindingMouseDefaultAction action, G_GNUC_UNUSED gint x, G_GNUC_UNUSED gint y, G_GNUC_UNUSED void *user_data )
1570 {
1571  RofiViewState *state = ( RofiViewState *) user_data;
1572  switch ( action )
1573  {
1574  case MOUSE_CLICK_DOWN:
1575  {
1576  const char * type = rofi_theme_get_string ( wid, "action", "ok" );
1577  ( state->selected_line ) = state->line_map[listview_get_selected ( state->list_view )];
1578  if ( strcmp ( type, "ok" ) == 0 ) {
1579  state->retv = MENU_OK;
1580  }
1581  else if ( strcmp ( type, "ok|alternate" ) == 0 ) {
1582  state->retv = MENU_CUSTOM_ACTION | MENU_OK;
1583  }
1584  else if ( strcmp ( type, "custom" ) ) {
1585  state->retv = MENU_CUSTOM_INPUT;
1586  }
1587  else if ( strcmp ( type, "custom|alternate" ) == 0 ) {
1589  }
1590  else {
1591  g_warning ( "Invalid action specified." );
1593  }
1594  state->quit = TRUE;
1595  state->skip_absorb = TRUE;
1597  }
1598  case MOUSE_CLICK_UP:
1599  case MOUSE_DCLICK_DOWN:
1600  case MOUSE_DCLICK_UP:
1601  break;
1602  }
1604 }
1605 static WidgetTriggerActionResult textbox_sidebar_modi_trigger_action ( widget *wid, MouseBindingMouseDefaultAction action, G_GNUC_UNUSED gint x, G_GNUC_UNUSED gint y, G_GNUC_UNUSED void *user_data )
1606 {
1607  RofiViewState *state = ( RofiViewState *) user_data;
1608  unsigned int i;
1609  for ( i = 0; i < state->num_modi; i++ ) {
1610  if ( WIDGET ( state->modi[i] ) == wid ) {
1611  break;
1612  }
1613  }
1614  if ( i == state->num_modi ) {
1616  }
1617 
1618  switch ( action )
1619  {
1620  case MOUSE_CLICK_DOWN:
1621  state->retv = MENU_QUICK_SWITCH | ( i & MENU_LOWER_MASK );
1622  state->quit = TRUE;
1623  state->skip_absorb = TRUE;
1625  case MOUSE_CLICK_UP:
1626  case MOUSE_DCLICK_DOWN:
1627  case MOUSE_DCLICK_UP:
1628  break;
1629  }
1631 }
1632 
1633 // @TODO don't like this construction.
1634 static void rofi_view_listview_mouse_activated_cb ( listview *lv, gboolean custom, void *udata )
1635 {
1636  RofiViewState *state = (RofiViewState *) udata;
1637  state->retv = MENU_OK;
1638  if ( custom ) {
1639  state->retv |= MENU_CUSTOM_ACTION;
1640  }
1641  ( state->selected_line ) = state->line_map[listview_get_selected ( lv )];
1642  // Quit
1643  state->quit = TRUE;
1644  state->skip_absorb = TRUE;
1645 }
1646 
1647 static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget, const char *name )
1648 {
1649  char *defaults = NULL;
1650  widget *wid = NULL;
1651 
1655  if ( strcmp ( name, "mainbox" ) == 0 ) {
1656  wid = (widget *) box_create ( parent_widget, name, ROFI_ORIENTATION_VERTICAL );
1657  box_add ( (box *) parent_widget, WIDGET ( wid ), TRUE );
1658  if ( config.sidebar_mode ) {
1659  defaults = "inputbar,message,listview,mode-switcher";
1660  }
1661  else {
1662  defaults = "inputbar,message,listview";
1663  }
1664  }
1668  else if ( strcmp ( name, "inputbar" ) == 0 ) {
1669  wid = (widget *) box_create ( parent_widget, name, ROFI_ORIENTATION_HORIZONTAL );
1670  defaults = "prompt,entry,overlay,case-indicator";
1671  box_add ( (box *) parent_widget, WIDGET ( wid ), FALSE );
1672  }
1676  else if ( strcmp ( name, "prompt" ) == 0 ) {
1677  if ( state->prompt != NULL ) {
1678  g_error ( "Prompt widget can only be added once to the layout." );
1679  return;
1680  }
1681  // Prompt box.
1682  state->prompt = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "", 0, 0 );
1683  rofi_view_update_prompt ( state );
1684  box_add ( (box *) parent_widget, WIDGET ( state->prompt ), FALSE );
1685  defaults = NULL;
1686  }
1687  else if ( strcmp ( name, "num-rows" ) == 0 ) {
1688  state->tb_total_rows = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "", 0, 0 );
1689  box_add ( (box *) parent_widget, WIDGET ( state->tb_total_rows ), FALSE );
1690  defaults = NULL;
1691  }
1692  else if ( strcmp ( name, "num-filtered-rows" ) == 0 ) {
1693  state->tb_filtered_rows = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "", 0, 0 );
1694  box_add ( (box *) parent_widget, WIDGET ( state->tb_filtered_rows ), FALSE );
1695  defaults = NULL;
1696  }
1700  else if ( strcmp ( name, "case-indicator" ) == 0 ) {
1701  if ( state->case_indicator != NULL ) {
1702  g_error ( "Case indicator widget can only be added once to the layout." );
1703  return;
1704  }
1705  state->case_indicator = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "*", 0, 0 );
1706  // Add small separator between case indicator and text box.
1707  box_add ( (box *) parent_widget, WIDGET ( state->case_indicator ), FALSE );
1709  }
1713  else if ( strcmp ( name, "entry" ) == 0 ) {
1714  if ( state->text != NULL ) {
1715  g_error ( "Entry textbox widget can only be added once to the layout." );
1716  return;
1717  }
1718  // Entry box
1719  TextboxFlags tfl = TB_EDITABLE;
1720  tfl |= ( ( state->menu_flags & MENU_PASSWORD ) == MENU_PASSWORD ) ? TB_PASSWORD : 0;
1721  state->text = textbox_create ( parent_widget, WIDGET_TYPE_EDITBOX, name, tfl | TB_AUTOHEIGHT, NORMAL, NULL, 0, 0 );
1722  box_add ( (box *) parent_widget, WIDGET ( state->text ), TRUE );
1723  }
1727  else if ( strcmp ( name, "message" ) == 0 ) {
1728  if ( state->mesg_box != NULL ) {
1729  g_error ( "Message widget can only be added once to the layout." );
1730  return;
1731  }
1732  state->mesg_box = container_create ( parent_widget, name );
1733  state->mesg_tb = textbox_create ( WIDGET ( state->mesg_box ), WIDGET_TYPE_TEXTBOX_TEXT, "textbox", TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, NORMAL, NULL, 0, 0 );
1734  container_add ( state->mesg_box, WIDGET ( state->mesg_tb ) );
1735  rofi_view_reload_message_bar ( state );
1736  box_add ( (box *) parent_widget, WIDGET ( state->mesg_box ), FALSE );
1737  }
1741  else if ( strcmp ( name, "listview" ) == 0 ) {
1742  if ( state->list_view != NULL ) {
1743  g_error ( "Listview widget can only be added once to the layout." );
1744  return;
1745  }
1746  state->list_view = listview_create ( parent_widget, name, update_callback, state, config.element_height, 0 );
1747  box_add ( (box *) parent_widget, WIDGET ( state->list_view ), TRUE );
1748  // Set configuration
1752 
1753  int lines = rofi_theme_get_integer ( WIDGET ( state->list_view ), "lines", config.menu_lines );
1754  listview_set_num_lines ( state->list_view, lines );
1755  listview_set_max_lines ( state->list_view, state->num_lines );
1756  }
1760  else if ( strcmp ( name, "mode-switcher" ) == 0 || strcmp ( name, "sidebar" ) == 0 ) {
1761  if ( state->sidebar_bar != NULL ) {
1762  g_error ( "Mode-switcher can only be added once to the layout." );
1763  return;
1764  }
1765  state->sidebar_bar = box_create ( parent_widget, name, ROFI_ORIENTATION_HORIZONTAL );
1766  box_add ( (box *) parent_widget, WIDGET ( state->sidebar_bar ), FALSE );
1767  state->num_modi = rofi_get_num_enabled_modi ();
1768  state->modi = g_malloc0 ( state->num_modi * sizeof ( textbox * ) );
1769  for ( unsigned int j = 0; j < state->num_modi; j++ ) {
1770  const Mode * mode = rofi_get_mode ( j );
1771  state->modi[j] = textbox_create ( WIDGET ( state->sidebar_bar ), WIDGET_TYPE_MODE_SWITCHER, "button", TB_AUTOHEIGHT, ( mode == state->sw ) ? HIGHLIGHT : NORMAL,
1772  mode_get_display_name ( mode ), 0.5, 0.5 );
1773  box_add ( state->sidebar_bar, WIDGET ( state->modi[j] ), TRUE );
1775  }
1776  }
1777  else if ( g_ascii_strcasecmp ( name, "overlay" ) == 0 ) {
1778  state->overlay = textbox_create ( WIDGET ( parent_widget ), WIDGET_TYPE_TEXTBOX_TEXT, "overlay", TB_AUTOWIDTH | TB_AUTOHEIGHT, URGENT, "blaat", 0.5, 0 );
1779  box_add ( (box *) parent_widget, WIDGET ( state->overlay ), FALSE );
1780  widget_disable ( WIDGET ( state->overlay ) );
1781  }
1782  else if ( g_ascii_strncasecmp ( name, "textbox", 7 ) == 0 ) {
1783  textbox *t = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOHEIGHT | TB_WRAP, NORMAL, "", 0, 0 );
1784  box_add ( (box *) parent_widget, WIDGET ( t ), TRUE );
1785  }
1786  else if ( g_ascii_strncasecmp ( name, "button", 6 ) == 0 ) {
1787  textbox *t = textbox_create ( parent_widget, WIDGET_TYPE_EDITBOX, name, TB_AUTOHEIGHT | TB_WRAP, NORMAL, "", 0, 0 );
1788  box_add ( (box *) parent_widget, WIDGET ( t ), TRUE );
1790  }
1791  else if ( g_ascii_strncasecmp ( name, "icon", 4 ) == 0 ) {
1792  icon *t = icon_create ( parent_widget, name );
1793  box_add ( (box *) parent_widget, WIDGET ( t ), TRUE );
1794  }
1795  else {
1796  wid = (widget *) box_create ( parent_widget, name, ROFI_ORIENTATION_VERTICAL );
1797  box_add ( (box *) parent_widget, WIDGET ( wid ), TRUE );
1798  //g_error("The widget %s does not exists. Invalid layout.", name);
1799  }
1800  if ( wid ) {
1801  GList *list = rofi_theme_get_list ( wid, "children", defaults );
1802  for ( const GList *iter = list; iter != NULL; iter = g_list_next ( iter ) ) {
1803  rofi_view_add_widget ( state, wid, (const char *) iter->data );
1804  }
1805  g_list_free_full ( list, g_free );
1806  }
1807 }
1808 
1810  const char *input,
1811  MenuFlags menu_flags,
1812  void ( *finalize )( RofiViewState * ) )
1813 {
1814  TICK ();
1816  state->menu_flags = menu_flags;
1817  state->sw = sw;
1818  state->selected_line = UINT32_MAX;
1819  state->retv = MENU_CANCEL;
1820  state->distance = NULL;
1821  state->quit = FALSE;
1822  state->skip_absorb = FALSE;
1823  //We want to filter on the first run.
1824  state->refilter = TRUE;
1825  state->finalize = finalize;
1826  state->mouse_seen = FALSE;
1827 
1828  // Request the lines to show.
1829  state->num_lines = mode_get_num_entries ( sw );
1830 
1831  if ( state->sw ) {
1832  char * title = g_strdup_printf ( "rofi - %s", mode_get_display_name ( state->sw ) );
1833  rofi_view_set_window_title ( title );
1834  g_free ( title );
1835  }
1836  else {
1837  rofi_view_set_window_title ( "rofi" );
1838  }
1839  TICK_N ( "Startup notification" );
1840 
1841  // Get active monitor size.
1842  TICK_N ( "Get active monitor" );
1843 
1844  state->main_window = box_create ( NULL, "window", ROFI_ORIENTATION_VERTICAL );
1845  // Get children.
1846  GList *list = rofi_theme_get_list ( WIDGET ( state->main_window ), "children", "mainbox" );
1847  for ( const GList *iter = list; iter != NULL; iter = g_list_next ( iter ) ) {
1848  rofi_view_add_widget ( state, WIDGET ( state->main_window ), (const char *) iter->data );
1849  }
1850  g_list_free_full ( list, g_free );
1851 
1852  if ( state->text && input ) {
1853  textbox_text ( state->text, input );
1854  textbox_cursor_end ( state->text );
1855  }
1856 
1857  // filtered list
1858  state->line_map = g_malloc0_n ( state->num_lines, sizeof ( unsigned int ) );
1859  state->distance = (int *) g_malloc0_n ( state->num_lines, sizeof ( int ) );
1860 
1862  // Need to resize otherwise calculated desired height is wrong.
1863  widget_resize ( WIDGET ( state->main_window ), state->width, 100 );
1864  // Only needed when window is fixed size.
1865  if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == MENU_NORMAL_WINDOW ) {
1867  }
1868 
1869  state->height = rofi_view_calculate_height ( state );
1870  // Move the window to the correct x,y position.
1872  rofi_view_window_update_size ( state );
1873 
1874  state->quit = FALSE;
1875  rofi_view_refilter ( state );
1876  rofi_view_update ( state, TRUE );
1877  xcb_map_window ( xcb->connection, CacheState.main_window );
1878  widget_queue_redraw ( WIDGET ( state->main_window ) );
1879  xcb_flush ( xcb->connection );
1880  if ( xcb->sncontext != NULL ) {
1881  sn_launchee_context_complete ( xcb->sncontext );
1882  }
1883  return state;
1884 }
1885 
1886 int rofi_view_error_dialog ( const char *msg, int markup )
1887 {
1889  state->retv = MENU_CANCEL;
1890  state->menu_flags = MENU_ERROR_DIALOG;
1891  state->finalize = process_result;
1892 
1893  state->main_window = box_create ( NULL, "window", ROFI_ORIENTATION_VERTICAL );
1894  box *box = box_create ( WIDGET ( state->main_window ), "error-message", ROFI_ORIENTATION_VERTICAL );
1895  box_add ( state->main_window, WIDGET ( box ), TRUE );
1896  state->text = textbox_create ( WIDGET ( box ), WIDGET_TYPE_TEXTBOX_TEXT, "textbox", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ),
1897  NORMAL, ( msg != NULL ) ? msg : "", 0, 0 );
1898  box_add ( box, WIDGET ( state->text ), TRUE );
1899 
1900  // Make sure we enable fixed num lines when in normal window mode.
1901  if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == MENU_NORMAL_WINDOW ) {
1903  }
1905  // Need to resize otherwise calculated desired height is wrong.
1906  widget_resize ( WIDGET ( state->main_window ), state->width, 100 );
1907  // resize window vertically to suit
1908  state->height = widget_get_desired_height ( WIDGET ( state->main_window ) );
1909 
1910  // Calculte window position.
1912 
1913  // Move the window to the correct x,y position.
1914  rofi_view_window_update_size ( state );
1915 
1916  // Display it.
1917  xcb_map_window ( xcb->connection, CacheState.main_window );
1918  widget_queue_redraw ( WIDGET ( state->main_window ) );
1919 
1920  if ( xcb->sncontext != NULL ) {
1921  sn_launchee_context_complete ( xcb->sncontext );
1922  }
1923 
1924  // Set it as current window.
1925  rofi_view_set_active ( state );
1926  return TRUE;
1927 }
1928 
1929 void rofi_view_hide ( void )
1930 {
1931  if ( CacheState.main_window != XCB_WINDOW_NONE ) {
1932  xcb_unmap_window ( xcb->connection, CacheState.main_window );
1934  }
1935 }
1936 
1938 {
1939  g_debug ( "Cleanup." );
1940  if ( CacheState.idle_timeout > 0 ) {
1941  g_source_remove ( CacheState.idle_timeout );
1942  CacheState.idle_timeout = 0;
1943  }
1944  if ( CacheState.repaint_source > 0 ) {
1945  g_source_remove ( CacheState.repaint_source );
1946  CacheState.repaint_source = 0;
1947  }
1948  if ( CacheState.fake_bg ) {
1949  cairo_surface_destroy ( CacheState.fake_bg );
1950  CacheState.fake_bg = NULL;
1951  }
1952  if ( CacheState.edit_draw ) {
1953  cairo_destroy ( CacheState.edit_draw );
1954  CacheState.edit_draw = NULL;
1955  }
1956  if ( CacheState.edit_surf ) {
1957  cairo_surface_destroy ( CacheState.edit_surf );
1958  CacheState.edit_surf = NULL;
1959  }
1960  if ( CacheState.main_window != XCB_WINDOW_NONE ) {
1961  g_debug ( "Unmapping and free'ing window" );
1962  xcb_unmap_window ( xcb->connection, CacheState.main_window );
1963  xcb_free_gc ( xcb->connection, CacheState.gc );
1964  xcb_free_pixmap ( xcb->connection, CacheState.edit_pixmap );
1965  xcb_destroy_window ( xcb->connection, CacheState.main_window );
1966  CacheState.main_window = XCB_WINDOW_NONE;
1967  }
1968  if ( map != XCB_COLORMAP_NONE ) {
1969  xcb_free_colormap ( xcb->connection, map );
1970  map = XCB_COLORMAP_NONE;
1971  }
1972  xcb_flush ( xcb->connection );
1973  g_assert ( g_queue_is_empty ( &( CacheState.views ) ) );
1974 }
1976 {
1977  TICK_N ( "Setup Threadpool, start" );
1978  if ( config.threads == 0 ) {
1979  config.threads = 1;
1980  long procs = sysconf ( _SC_NPROCESSORS_CONF );
1981  if ( procs > 0 ) {
1982  config.threads = MIN ( procs, 128l );
1983  }
1984  }
1985  // Create thread pool
1986  GError *error = NULL;
1987  tpool = g_thread_pool_new ( rofi_view_call_thread, NULL, config.threads, FALSE, &error );
1988  if ( error == NULL ) {
1989  // Idle threads should stick around for a max of 60 seconds.
1990  g_thread_pool_set_max_idle_time ( 60000 );
1991  // We are allowed to have
1992  g_thread_pool_set_max_threads ( tpool, config.threads, &error );
1993  }
1994  // If error occurred during setup of pool, tell user and exit.
1995  if ( error != NULL ) {
1996  g_warning ( "Failed to setup thread pool: '%s'", error->message );
1997  g_error_free ( error );
1998  exit ( EXIT_FAILURE );
1999  }
2000  TICK_N ( "Setup Threadpool, done" );
2001 }
2003 {
2004  if ( tpool ) {
2005  g_thread_pool_free ( tpool, TRUE, TRUE );
2006  tpool = NULL;
2007  }
2008 }
2010 {
2011  return state->sw;
2012 }
2013 
2014 void rofi_view_set_overlay ( RofiViewState *state, const char *text )
2015 {
2016  if ( state->overlay == NULL || state->list_view == NULL ) {
2017  return;
2018  }
2019  if ( text == NULL ) {
2020  widget_disable ( WIDGET ( state->overlay ) );
2021  return;
2022  }
2023  widget_enable ( WIDGET ( state->overlay ) );
2024  textbox_text ( state->overlay, text );
2025  // We want to queue a repaint.
2027 }
2028 
2030 {
2031  if ( state->text ) {
2032  textbox_text ( state->text, "" );
2033  rofi_view_set_selected_line ( state, 0 );
2034  }
2035 }
2036 
2038 {
2040 }
2041 
2043 {
2044  state->sw = mode;
2045  // Update prompt;
2046  if ( state->prompt ) {
2047  rofi_view_update_prompt ( state );
2048  }
2049  if ( state->sw ) {
2050  char * title = g_strdup_printf ( "rofi - %s", mode_get_display_name ( state->sw ) );
2051  rofi_view_set_window_title ( title );
2052  g_free ( title );
2053  }
2054  else {
2055  rofi_view_set_window_title ( "rofi" );
2056  }
2057  if ( state->sidebar_bar ) {
2058  for ( unsigned int j = 0; j < state->num_modi; j++ ) {
2059  const Mode * mode = rofi_get_mode ( j );
2060  textbox_font ( state->modi[j], ( mode == state->sw ) ? HIGHLIGHT : NORMAL );
2061  }
2062  }
2063  rofi_view_restart ( state );
2064  state->reload = TRUE;
2065  state->refilter = TRUE;
2066  rofi_view_refilter ( state );
2067  rofi_view_update ( state, TRUE );
2068 }
2069 
2070 xcb_window_t rofi_view_get_window ( void )
2071 {
2072  return CacheState.main_window;
2073 }
2074 
2075 void rofi_view_set_window_title ( const char * title )
2076 {
2077  ssize_t len = strlen ( title );
2078  xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, CacheState.main_window, xcb->ewmh._NET_WM_NAME, xcb->ewmh.UTF8_STRING, 8, len, title );
2079  xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, CacheState.main_window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, len, title );
2080 }
rofi_theme_get_position
int rofi_theme_get_position(const widget *widget, const char *property, int def)
Definition: theme.c:712
views
GQueue views
Definition: view.c:110
SCOPE_GLOBAL
@ SCOPE_GLOBAL
Definition: keyb.h:44
RofiViewState::sw
Mode * sw
Definition: view-internal.h:50
SELECT_ELEMENT_5
@ SELECT_ELEMENT_5
Definition: keyb.h:135
widget_xy_to_relative
void widget_xy_to_relative(widget *widget, gint *x, gint *y)
Definition: widget.c:387
PASTE_SECONDARY
@ PASTE_SECONDARY
Definition: keyb.h:63
current_active_menu
RofiViewState * current_active_menu
Definition: view.c:86
WIDGET
#define WIDGET(a)
Definition: widget.h:115
helper_tokenize_free
void helper_tokenize_free(rofi_int_matcher **tokens)
Definition: helper.c:126
REMOVE_WORD_BACK
@ REMOVE_WORD_BACK
Definition: keyb.h:79
BindingsScope
BindingsScope
Definition: keyb.h:43
SELECT_ELEMENT_9
@ SELECT_ELEMENT_9
Definition: keyb.h:139
listview_toggle_ellipsizing
void listview_toggle_ellipsizing(listview *lv)
Definition: listview.c:978
rofi_view_frame_callback
void rofi_view_frame_callback(void)
Definition: view.c:1545
CANCEL
@ CANCEL
Definition: keyb.h:108
rofi_view_add_widget
static void rofi_view_add_widget(RofiViewState *state, widget *parent_widget, const char *name)
Definition: view.c:1647
textbox_font
void textbox_font(textbox *tb, TextBoxFontType tbft)
Definition: textbox.c:234
MenuFlags
MenuFlags
Definition: view.h:44
rofi_view_repaint
static gboolean rofi_view_repaint(G_GNUC_UNUSED void *data)
Definition: view.c:267
MOVE_CHAR_BACK
@ MOVE_CHAR_BACK
Definition: keyb.h:75
do_bench
gboolean do_bench
Definition: view.c:229
MENU_QUICK_SWITCH
@ MENU_QUICK_SWITCH
Definition: mode.h:79
xcb
xcb_stuff * xcb
Definition: xcb.c:87
ACCEPT_ENTRY
@ ACCEPT_ENTRY
Definition: keyb.h:91
xrmoptions.h
rofi_view_call_thread
static void rofi_view_call_thread(gpointer data, gpointer user_data)
Definition: view.c:629
CUSTOM_17
@ CUSTOM_17
Definition: keyb.h:125
REMOVE_WORD_FORWARD
@ REMOVE_WORD_FORWARD
Definition: keyb.h:81
depth
xcb_depth_t * depth
Definition: xcb.c:92
widget_set_trigger_action_handler
void widget_set_trigger_action_handler(widget *wid, widget_trigger_action_cb cb, void *cb_data)
Definition: widget.c:462
edit_surf
cairo_surface_t * edit_surf
Definition: view.c:102
RofiViewState::height
int height
Definition: view-internal.h:122
dialogs.h
CUSTOM_6
@ CUSTOM_6
Definition: keyb.h:114
rofi_view_workers_initialize
void rofi_view_workers_initialize(void)
Definition: view.c:1975
_thread_state
Definition: rofi-types.h:277
ROW_LAST
@ ROW_LAST
Definition: keyb.h:106
rofi_capture_screenshot
void rofi_capture_screenshot(void)
Definition: view.c:177
ROW_LEFT
@ ROW_LEFT
Definition: keyb.h:98
listview_nav_up
void listview_nav_up(listview *lv)
Definition: listview.c:729
mode_get_completion
char * mode_get_completion(const Mode *mode, unsigned int selected_line)
Definition: mode.c:84
SELECT_ELEMENT_7
@ SELECT_ELEMENT_7
Definition: keyb.h:137
fake_bgrel
int fake_bgrel
Definition: view.c:106
listview_nav_page_prev
void listview_nav_page_prev(listview *lv)
Definition: listview.c:844
_xcb_stuff::screen
xcb_screen_t * screen
Definition: xcb-internal.h:49
settings.h
rofi_view_nav_first
static void rofi_view_nav_first(RofiViewState *state)
Definition: view.c:954
WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END
@ WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_END
Definition: widget.h:86
listview_set_num_elements
void listview_set_num_elements(listview *lv, unsigned int rows)
Definition: listview.c:513
MENU_INDICATOR
@ MENU_INDICATOR
Definition: view.h:54
CUSTOM_9
@ CUSTOM_9
Definition: keyb.h:117
PAGE_NEXT
@ PAGE_NEXT
Definition: keyb.h:104
listview_create
listview * listview_create(widget *parent, const char *name, listview_update_callback cb, void *udata, unsigned int eh, gboolean reverse)
Definition: listview.c:643
rofi_view_nav_row_select
static void rofi_view_nav_row_select(RofiViewState *state)
Definition: view.c:933
mode_token_match
int mode_token_match(const Mode *mode, rofi_int_matcher **tokens, unsigned int selected_line)
Definition: mode.c:105
helper_tokenize
rofi_int_matcher ** helper_tokenize(const char *input, int case_sensitive)
Definition: helper.c:227
RofiViewState::num_modi
unsigned int num_modi
Definition: view-internal.h:101
MOUSE_CLICK_UP
@ MOUSE_CLICK_UP
Definition: keyb.h:170
ROFI_ORIENTATION_VERTICAL
@ ROFI_ORIENTATION_VERTICAL
Definition: rofi-types.h:137
rofi_view_clear_input
void rofi_view_clear_input(RofiViewState *state)
Definition: view.c:2029
KeyBindingAction
KeyBindingAction
Definition: keyb.h:59
Settings::element_height
int element_height
Definition: settings.h:139
REMOVE_TO_EOL
@ REMOVE_TO_EOL
Definition: keyb.h:87
SELECT_ELEMENT_10
@ SELECT_ELEMENT_10
Definition: keyb.h:140
MENU_OK
@ MENU_OK
Definition: mode.h:69
textbox_text
void textbox_text(textbox *tb, const char *text)
Definition: textbox.c:314
rofi_view_get_next_position
unsigned int rofi_view_get_next_position(const RofiViewState *state)
Definition: view.c:561
rofi_view_get_active
RofiViewState * rofi_view_get_active(void)
Definition: view.c:488
x11_disable_decoration
void x11_disable_decoration(xcb_window_t window)
Definition: xcb.c:1432
listview_set_scroll_type
void listview_set_scroll_type(listview *lv, ScrollType type)
Definition: listview.c:913
Settings::menu_width
int menu_width
Definition: settings.h:66
container_create
container * container_create(widget *parent, const char *name)
Definition: container.c:110
textbox_cursor_end
void textbox_cursor_end(textbox *tb)
Definition: textbox.c:584
MODE_PREVIOUS
@ MODE_PREVIOUS
Definition: keyb.h:95
rofi_view_trigger_global_action
static void rofi_view_trigger_global_action(KeyBindingAction action)
Definition: view.c:1197
NORMAL
@ NORMAL
Definition: textbox.h:94
_thread_state_view::st
thread_state st
Definition: view.c:600
rofi_scorer_fuzzy_evaluate
int rofi_scorer_fuzzy_evaluate(const char *pattern, glong plen, const char *str, glong slen)
Definition: helper.c:886
distance_get_pixel
int distance_get_pixel(RofiDistance d, RofiOrientation ori)
Definition: theme.c:996
_thread_state_view::start
unsigned int start
Definition: view.c:612
box_create
box * box_create(widget *parent, const char *name, RofiOrientation type)
Definition: box.c:343
mon
workarea mon
Definition: view.c:112
SCOPE_MOUSE_SCROLLBAR
@ SCOPE_MOUSE_SCROLLBAR
Definition: keyb.h:50
CUSTOM_10
@ CUSTOM_10
Definition: keyb.h:118
rofi_theme_get_distance
RofiDistance rofi_theme_get_distance(const widget *widget, const char *property, int def)
Definition: theme.c:745
TB_PASSWORD
@ TB_PASSWORD
Definition: textbox.h:85
MOUSE_DCLICK_UP
@ MOUSE_DCLICK_UP
Definition: keyb.h:172
rofi_theme_get_boolean
int rofi_theme_get_boolean(const widget *widget, const char *property, int def)
Definition: theme.c:767
mode_get_icon
cairo_surface_t * mode_get_icon(const Mode *mode, unsigned int selected_line, int height)
Definition: mode.c:72
RofiViewState::distance
int * distance
Definition: view-internal.h:73
textbox_append_text
gboolean textbox_append_text(textbox *tb, const char *pad, const int pad_len)
Definition: textbox.c:785
RofiViewState::skip_absorb
int skip_absorb
Definition: view-internal.h:90
mode.h
SELECT_ELEMENT_1
@ SELECT_ELEMENT_1
Definition: keyb.h:131
rofi_view_error_dialog
int rofi_view_error_dialog(const char *msg, int markup)
Definition: view.c:1886
widget_disable
static void widget_disable(widget *widget)
Definition: widget.h:175
rofi_view_maybe_update
void rofi_view_maybe_update(RofiViewState *state)
Definition: view.c:1477
HIGHLIGHT
@ HIGHLIGHT
Definition: textbox.h:107
rofi_get_mode
const Mode * rofi_get_mode(unsigned int index)
Definition: rofi.c:136
TB_AUTOHEIGHT
@ TB_AUTOHEIGHT
Definition: textbox.h:80
WL_EAST
@ WL_EAST
Definition: rofi-types.h:194
rofi_view_handle_text
void rofi_view_handle_text(RofiViewState *state, char *text)
Definition: view.c:1460
MENU_PREVIOUS
@ MENU_PREVIOUS
Definition: mode.h:81
widget_enable
static void widget_enable(widget *widget)
Definition: widget.h:185
TB_AUTOWIDTH
@ TB_AUTOWIDTH
Definition: textbox.h:81
MOUSE_CLICK_DOWN
@ MOUSE_CLICK_DOWN
Definition: keyb.h:169
_icon
Definition: icon.c:41
rofi_view_set_window_title
void rofi_view_set_window_title(const char *title)
Definition: view.c:2075
CUSTOM_11
@ CUSTOM_11
Definition: keyb.h:119
_xcb_stuff::sncontext
SnLauncheeContext * sncontext
Definition: xcb-internal.h:52
rofi_theme_get_integer
int rofi_theme_get_integer(const widget *widget, const char *property, int def)
Definition: theme.c:729
get_matching_state
static char * get_matching_state(void)
Definition: view.c:144
rofi_view_queue_redraw
void rofi_view_queue_redraw(void)
Definition: view.c:473
rofi_view_get_selected_line
unsigned int rofi_view_get_selected_line(const RofiViewState *state)
Definition: view.c:556
widget_find_mouse_target
widget * widget_find_mouse_target(widget *wid, WidgetType type, gint x, gint y)
Definition: widget.c:433
RofiViewState::retv
MenuReturn retv
Definition: view-internal.h:94
box_add
void box_add(box *box, widget *child, gboolean expand)
Definition: box.c:283
ROW_RIGHT
@ ROW_RIGHT
Definition: keyb.h:99
MOVE_WORD_FORWARD
@ MOVE_WORD_FORWARD
Definition: keyb.h:73
bench_update
static gboolean bench_update(void)
Definition: view.c:243
rofi_view_get_mode
Mode * rofi_view_get_mode(RofiViewState *state)
Definition: view.c:2009
CLEAR_LINE
@ CLEAR_LINE
Definition: keyb.h:65
_thread_state_view
Definition: view.c:598
CUSTOM_13
@ CUSTOM_13
Definition: keyb.h:121
rofi_view_get_current_monitor
void rofi_view_get_current_monitor(int *width, int *height)
Definition: view.c:135
MENU_NORMAL
@ MENU_NORMAL
Definition: view.h:46
rofi_view_ellipsize_start
void rofi_view_ellipsize_start(RofiViewState *state)
Definition: view.c:2037
listview_set_mouse_activated_cb
void listview_set_mouse_activated_cb(listview *lv, listview_mouse_activated_cb cb, void *udata)
Definition: listview.c:920
WL_NORTH_EAST
@ WL_NORTH_EAST
Definition: rofi-types.h:202
__create_window
void __create_window(MenuFlags menu_flags)
Definition: view.c:719
Settings::sorting_method_enum
SortingMethod sorting_method_enum
Definition: settings.h:119
helper_validate_font
gboolean helper_validate_font(PangoFontDescription *pfd, const char *font)
Definition: helper.c:534
fake_bg
cairo_surface_t * fake_bg
Definition: view.c:96
RofiViewState::quit
int quit
Definition: view-internal.h:88
rofi_view_free
void rofi_view_free(RofiViewState *state)
Definition: view.c:532
CUSTOM_5
@ CUSTOM_5
Definition: keyb.h:113
SELECT_ELEMENT_6
@ SELECT_ELEMENT_6
Definition: keyb.h:136
MenuReturn
MenuReturn
Definition: mode.h:67
Settings::location
WindowLocation location
Definition: settings.h:103
RofiViewState::tokens
rofi_int_matcher ** tokens
Definition: view-internal.h:140
textbox_get_estimated_char_width
double textbox_get_estimated_char_width(void)
Definition: textbox.c:894
rofi_view_reload_message_bar
static void rofi_view_reload_message_bar(RofiViewState *state)
Definition: view.c:439
SORT_FZF
@ SORT_FZF
Definition: settings.h:52
_workarea
Definition: xcb.h:100
_thread_state_view::mutex
GMutex * mutex
Definition: view.c:605
tpool
GThreadPool * tpool
Definition: view.c:83
icon_set_surface
void icon_set_surface(icon *icon, cairo_surface_t *surf)
Definition: icon.c:125
WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN
@ WIDGET_TRIGGER_ACTION_RESULT_GRAB_MOTION_BEGIN
Definition: widget.h:84
RofiViewState::motion_target
widget * motion_target
Definition: view-internal.h:136
WL_SOUTH_WEST
@ WL_SOUTH_WEST
Definition: rofi-types.h:206
rofi_view_calculate_window_position
static void rofi_view_calculate_window_position(RofiViewState *state)
Definition: view.c:316
timings.h
Settings::fake_transparency
unsigned int fake_transparency
Definition: settings.h:169
MouseBindingMouseDefaultAction
MouseBindingMouseDefaultAction
Definition: keyb.h:168
rofi_view_get_return_value
MenuReturn rofi_view_get_return_value(const RofiViewState *state)
Definition: view.c:551
Settings::show_match
gboolean show_match
Definition: settings.h:182
textbox_button_trigger_action
static WidgetTriggerActionResult textbox_button_trigger_action(widget *wid, MouseBindingMouseDefaultAction action, G_GNUC_UNUSED gint x, G_GNUC_UNUSED gint y, G_GNUC_UNUSED void *user_data)
Definition: view.c:1569
REMOVE_TO_SOL
@ REMOVE_TO_SOL
Definition: keyb.h:89
RofiViewState::mouse
struct RofiViewState::@5 mouse
textbox_keybinding
int textbox_keybinding(textbox *tb, KeyBindingAction action)
Definition: textbox.c:721
Settings::sidebar_mode
unsigned int sidebar_mode
Definition: settings.h:141
theme.h
helper_token_match_get_pango_attr
PangoAttrList * helper_token_match_get_pango_attr(RofiHighlightColorStyle th, rofi_int_matcher **tokens, const char *input, PangoAttrList *retv)
Definition: helper.c:381
_thread_state_view::pattern
const char * pattern
Definition: view.c:619
rofi_quit_main_loop
void rofi_quit_main_loop(void)
Definition: rofi.c:656
ROW_DOWN
@ ROW_DOWN
Definition: keyb.h:101
ROW_TAB
@ ROW_TAB
Definition: keyb.h:102
flags
MenuFlags flags
Definition: view.c:108
rofi_view_set_active
void rofi_view_set_active(RofiViewState *state)
Definition: view.c:493
loc_transtable
static const int loc_transtable[9]
Definition: view.c:305
CHANGE_ELLIPSIZE
@ CHANGE_ELLIPSIZE
Definition: keyb.h:129
listview_nav_right
void listview_nav_right(listview *lv)
Definition: listview.c:768
_thread_state_view::plen
glong plen
Definition: view.c:621
widget_free
void widget_free(widget *wid)
Definition: widget.c:339
_xcb_stuff::ewmh
xcb_ewmh_connection_t ewmh
Definition: xcb-internal.h:48
SELECT_ELEMENT_4
@ SELECT_ELEMENT_4
Definition: keyb.h:134
listview_set_num_lines
void listview_set_num_lines(listview *lv, unsigned int num_lines)
Definition: listview.c:933
CacheState
struct @0 CacheState
RofiDistance
Definition: rofi-types.h:125
RofiViewState::main_window
box * main_window
Definition: view-internal.h:55
rofi_theme_get_list
GList * rofi_theme_get_list(const widget *widget, const char *property, const char *defaults)
Definition: theme.c:888
SCOPE_MOUSE_LISTVIEW_ELEMENT
@ SCOPE_MOUSE_LISTVIEW_ELEMENT
Definition: keyb.h:46
ROFI_HL_UNDERLINE
@ ROFI_HL_UNDERLINE
Definition: rofi-types.h:56
rofi_view_handle_mouse_motion
void rofi_view_handle_mouse_motion(RofiViewState *state, gint x, gint y)
Definition: view.c:1467
mode_get_num_entries
unsigned int mode_get_num_entries(const Mode *mode)
Definition: mode.c:56
CUSTOM_12
@ CUSTOM_12
Definition: keyb.h:120
CUSTOM_1
@ CUSTOM_1
Definition: keyb.h:109
textbox_get_visible_text
const char * textbox_get_visible_text(const textbox *tb)
Definition: textbox.c:291
MOVE_END
@ MOVE_END
Definition: keyb.h:69
SCOPE_MOUSE_MODE_SWITCHER
@ SCOPE_MOUSE_MODE_SWITCHER
Definition: keyb.h:51
DELETE_ENTRY
@ DELETE_ENTRY
Definition: keyb.h:97
monitor_active
int monitor_active(workarea *mon)
Definition: xcb.c:751
listview_set_ellipsize_start
void listview_set_ellipsize_start(listview *lv)
Definition: listview.c:968
CUSTOM_7
@ CUSTOM_7
Definition: keyb.h:115
WL_CENTER
@ WL_CENTER
Definition: rofi-types.h:190
Settings::menu_font
char * menu_font
Definition: settings.h:72
listview_get_selected
unsigned int listview_get_selected(listview *lv)
Definition: listview.c:528
widget_queue_redraw
void widget_queue_redraw(widget *wid)
Definition: widget.c:408
RofiViewState::mesg_tb
textbox * mesg_tb
Definition: view-internal.h:70
RofiViewState::list_view
listview * list_view
Definition: view-internal.h:64
MENU_ENTRY_DELETE
@ MENU_ENTRY_DELETE
Definition: mode.h:77
RofiViewState::prev_action
KeyBindingAction prev_action
Definition: view-internal.h:83
textbox::text
char * text
Definition: textbox.h:55
MOUSE_DCLICK_DOWN
@ MOUSE_DCLICK_DOWN
Definition: keyb.h:171
rofi_view_temp_configure_notify
void rofi_view_temp_configure_notify(RofiViewState *state, xcb_configure_notify_event_t *xce)
Definition: view.c:1504
TICK_N
#define TICK_N(a)
Definition: timings.h:69
icon_create
icon * icon_create(widget *parent, const char *name)
Definition: icon.c:139
CUSTOM_15
@ CUSTOM_15
Definition: keyb.h:123
RofiViewState::num_lines
unsigned int num_lines
Definition: view-internal.h:77
mode_preprocess_input
char * mode_preprocess_input(Mode *mode, const char *input)
Definition: mode.c:157
SCREENSHOT
@ SCREENSHOT
Definition: keyb.h:128
view-internal.h
rofi_view_calculate_height
static int rofi_view_calculate_height(RofiViewState *state)
Definition: view.c:1552
thread_state_view
struct _thread_state_view thread_state_view
visual
xcb_visualtype_t * visual
Definition: xcb.c:93
rofi_view_finalize
void rofi_view_finalize(RofiViewState *state)
Definition: view.c:1190
window_set_atom_prop
void window_set_atom_prop(xcb_window_t w, xcb_atom_t prop, xcb_atom_t *atoms, int count)
Definition: xcb.c:248
update_callback
static void update_callback(textbox *t, icon *ico, unsigned int index, void *udata, TextBoxFontType *type, gboolean full)
Definition: view.c:975
CUSTOM_3
@ CUSTOM_3
Definition: keyb.h:111
WL_WEST
@ WL_WEST
Definition: rofi-types.h:198
RofiViewState::refilter
int refilter
Definition: view-internal.h:53
RofiViewState::y
int y
Definition: view-internal.h:126
Settings::benchmark_ui
gboolean benchmark_ui
Definition: settings.h:205
WL_SOUTH_EAST
@ WL_SOUTH_EAST
Definition: rofi-types.h:204
x11_helper_get_bg_surface
cairo_surface_t * x11_helper_get_bg_surface(void)
Definition: xcb.c:211
rofi_expand_path
char * rofi_expand_path(const char *input)
Definition: helper.c:664
rofi_theme_get_string
const char * rofi_theme_get_string(const widget *widget, const char *property, const char *def)
Definition: theme.c:800
widget_motion_notify
gboolean widget_motion_notify(widget *wid, gint x, gint y)
Definition: widget.c:471
CUSTOM_19
@ CUSTOM_19
Definition: keyb.h:127
rofi_view_restart
void rofi_view_restart(RofiViewState *state)
Definition: view.c:482
rofi_view_update_prompt
static void rofi_view_update_prompt(RofiViewState *state)
Definition: view.c:285
URGENT
@ URGENT
Definition: textbox.h:96
rofi_view_get_window
xcb_window_t rofi_view_get_window(void)
Definition: view.c:2070
time
GTimer * time
Definition: view.c:232
TB_MARKUP
@ TB_MARKUP
Definition: textbox.h:83
PASTE_PRIMARY
@ PASTE_PRIMARY
Definition: keyb.h:61
SCOPE_MOUSE_EDITBOX
@ SCOPE_MOUSE_EDITBOX
Definition: keyb.h:49
rofi_mode
Definition: mode-private.h:152
rofi.h
RofiViewState::selected_line
unsigned int selected_line
Definition: view-internal.h:92
__rofi_view_state_create
static RofiViewState * __rofi_view_state_create(void)
Definition: view.c:589
SELECT_ELEMENT_3
@ SELECT_ELEMENT_3
Definition: keyb.h:133
WL_SOUTH
@ WL_SOUTH
Definition: rofi-types.h:196
CUSTOM_14
@ CUSTOM_14
Definition: keyb.h:122
TextboxFlags
TextboxFlags
Definition: textbox.h:79
rofi_view_temp_click_to_exit
void rofi_view_temp_click_to_exit(RofiViewState *state, xcb_window_t target)
Definition: view.c:1535
idle_timeout
guint idle_timeout
Definition: view.c:114
_listview
Definition: listview.c:71
RofiViewState::modi
textbox ** modi
Definition: view-internal.h:103
RofiViewState::menu_flags
MenuFlags menu_flags
Definition: view-internal.h:111
x11_helper_get_screenshot_surface
cairo_surface_t * x11_helper_get_screenshot_surface(void)
Definition: xcb.c:176
MENU_PASSWORD
@ MENU_PASSWORD
Definition: view.h:48
textbox_sidebar_modi_trigger_action
static WidgetTriggerActionResult textbox_sidebar_modi_trigger_action(widget *wid, MouseBindingMouseDefaultAction action, G_GNUC_UNUSED gint x, G_GNUC_UNUSED gint y, G_GNUC_UNUSED void *user_data)
Definition: view.c:1605
ROW_SELECT
@ ROW_SELECT
Definition: keyb.h:107
levenshtein
unsigned int levenshtein(const char *needle, const glong needlelen, const char *haystack, const glong haystacklen)
Definition: helper.c:697
xcb.h
_box
Definition: box.c:42
RofiViewState::width
int width
Definition: view-internal.h:120
listview_set_multi_select
void listview_set_multi_select(listview *lv, gboolean enable)
Definition: listview.c:927
MOVE_FRONT
@ MOVE_FRONT
Definition: keyb.h:67
rofi_get_num_enabled_modi
unsigned int rofi_get_num_enabled_modi(void)
Definition: rofi.c:131
listview_nav_page_next
void listview_nav_page_next(listview *lv)
Definition: listview.c:856
TOGGLE_CASE_SENSITIVITY
@ TOGGLE_CASE_SENSITIVITY
Definition: keyb.h:96
textbox_get_pango_attributes
PangoAttrList * textbox_get_pango_attributes(textbox *tb)
Definition: textbox.c:298
_thread_state_view::state
RofiViewState * state
Definition: view.c:610
rofi_view_calculate_window_width
static void rofi_view_calculate_window_width(RofiViewState *state)
Definition: view.c:879
WL_NORTH
@ WL_NORTH
Definition: rofi-types.h:192
RofiViewState::tb_total_rows
textbox * tb_total_rows
Definition: view-internal.h:106
_thread_state_view::cond
GCond * cond
Definition: view.c:603
container_add
void container_add(container *container, widget *child)
Definition: container.c:72
MENU_CUSTOM_ACTION
@ MENU_CUSTOM_ACTION
Definition: mode.h:83
edit_pixmap
xcb_pixmap_t edit_pixmap
Definition: view.c:100
RofiViewState::prompt
textbox * prompt
Definition: view-internal.h:57
mode_get_display_name
const char * mode_get_display_name(const Mode *mode)
Definition: mode.c:143
_xcb_stuff::connection
xcb_connection_t * connection
Definition: xcb-internal.h:47
Settings::dpi
int dpi
Definition: settings.h:171
TOGGLE_SORT
@ TOGGLE_SORT
Definition: keyb.h:130
WIDGET_TYPE_EDITBOX
@ WIDGET_TYPE_EDITBOX
Definition: widget.h:65
display.h
WIDGET_TYPE_MODE_SWITCHER
@ WIDGET_TYPE_MODE_SWITCHER
Definition: widget.h:69
MODE_NEXT
@ MODE_NEXT
Definition: keyb.h:94
_thread_state_view::count
unsigned int count
Definition: view.c:616
listview_set_fixed_num_lines
void listview_set_fixed_num_lines(listview *lv)
Definition: listview.c:961
MENU_CUSTOM_INPUT
@ MENU_CUSTOM_INPUT
Definition: mode.h:75
_rofi_view_reload_row
static void _rofi_view_reload_row(RofiViewState *state)
Definition: view.c:1061
MENU_NORMAL_WINDOW
@ MENU_NORMAL_WINDOW
Definition: view.h:50
rofi_view_refilter
static void rofi_view_refilter(RofiViewState *state)
Definition: view.c:1072
RofiViewState::reload
int reload
Definition: view-internal.h:115
lev_sort
static int lev_sort(const void *p1, const void *p2, void *arg)
Definition: view.c:165
CUSTOM_2
@ CUSTOM_2
Definition: keyb.h:110
netatoms
xcb_atom_t netatoms[NUM_NETATOMS]
Definition: xcb.c:99
TB_WRAP
@ TB_WRAP
Definition: textbox.h:84
main_window
xcb_window_t main_window
Definition: view.c:94
rofi_view_update
void rofi_view_update(RofiViewState *state, gboolean qr)
Definition: view.c:1022
filter_elements
static void filter_elements(thread_state *ts, G_GNUC_UNUSED gpointer user_data)
Definition: view.c:635
gc
xcb_gcontext_t gc
Definition: view.c:98
min
double min
Definition: view.c:235
rofi_view_nav_row_tab
static void rofi_view_nav_row_tab(RofiViewState *state)
Definition: view.c:908
widget_trigger_action
WidgetTriggerActionResult widget_trigger_action(widget *wid, guint action, gint x, gint y)
Definition: widget.c:451
ACCEPT_CUSTOM
@ ACCEPT_CUSTOM
Definition: keyb.h:93
Settings::auto_select
unsigned int auto_select
Definition: settings.h:145
MENU_NEXT
@ MENU_NEXT
Definition: mode.h:73
RofiViewState::tb_filtered_rows
textbox * tb_filtered_rows
Definition: view-internal.h:108
BenchMark
struct @1 BenchMark
count
unsigned long long count
Definition: view.c:116
RofiViewState::finalize
void(* finalize)(struct RofiViewState *state)
Definition: view-internal.h:117
display_early_cleanup
void display_early_cleanup(void)
Definition: xcb.c:1397
Settings::x_offset
int x_offset
Definition: settings.h:109
TextBoxFontType
TextBoxFontType
Definition: textbox.h:92
listview_set_max_lines
void listview_set_max_lines(listview *lv, unsigned int max_lines)
Definition: listview.c:947
textbox_set_pango_attributes
void textbox_set_pango_attributes(textbox *tb, PangoAttrList *list)
Definition: textbox.c:305
CUSTOM_8
@ CUSTOM_8
Definition: keyb.h:116
widget_draw
void widget_draw(widget *widget, cairo_t *d)
Definition: widget.c:185
SELECT_ELEMENT_2
@ SELECT_ELEMENT_2
Definition: keyb.h:132
RofiViewState::text
textbox * text
Definition: view-internal.h:59
rofi_view_hide
void rofi_view_hide(void)
Definition: view.c:1929
RofiViewState::line_map
unsigned int * line_map
Definition: view-internal.h:75
view.h
rofi_theme_get_highlight
RofiHighlightColorStyle rofi_theme_get_highlight(widget *widget, const char *property, RofiHighlightColorStyle th)
Definition: theme.c:914
listview_get_fixed_num_lines
gboolean listview_get_fixed_num_lines(listview *lv)
Definition: listview.c:954
map
xcb_colormap_t map
Definition: xcb.c:94
Settings::fullscreen
unsigned int fullscreen
Definition: settings.h:167
listview_nav_left
void listview_nav_left(listview *lv)
Definition: listview.c:754
last_ts
double last_ts
Definition: view.c:234
SORT_NORMAL
@ SORT_NORMAL
Definition: settings.h:51
textbox
Definition: textbox.h:51
MENU_ERROR_DIALOG
@ MENU_ERROR_DIALOG
Definition: view.h:52
WL_NORTH_WEST
@ WL_NORTH_WEST
Definition: rofi-types.h:200
MENU_CANCEL
@ MENU_CANCEL
Definition: mode.h:71
RofiViewState::sidebar_bar
box * sidebar_bar
Definition: view-internal.h:99
Settings::fake_background
char * fake_background
Definition: settings.h:177
xcb_stuff_get_root_window
xcb_window_t xcb_stuff_get_root_window(void)
Definition: xcb.c:1392
helper-theme.h
mode_get_display_value
char * mode_get_display_value(const Mode *mode, unsigned int selected_line, int *state, GList **attribute_list, int get_entry)
Definition: mode.c:63
draws
uint64_t draws
Definition: view.c:233
TICK
#define TICK()
Definition: timings.h:64
RofiViewState::x
int x
Definition: view-internal.h:124
textbox_set_pango_context
void textbox_set_pango_context(const char *font, PangoContext *p)
Definition: textbox.c:824
rofi_view_create
RofiViewState * rofi_view_create(Mode *sw, const char *input, MenuFlags menu_flags, void(*finalize)(RofiViewState *))
Definition: view.c:1809
PAGE_PREV
@ PAGE_PREV
Definition: keyb.h:103
Settings::menu_lines
unsigned int menu_lines
Definition: settings.h:68
Settings::case_sensitive
unsigned int case_sensitive
Definition: settings.h:135
Settings::y_offset
int y_offset
Definition: settings.h:107
rofi_view_nav_last
static void rofi_view_nav_last(RofiViewState *state)
Definition: view.c:965
RofiViewState::mesg_box
container * mesg_box
Definition: view-internal.h:68
CUSTOM_18
@ CUSTOM_18
Definition: keyb.h:126
rofi_view_get_user_input
const char * rofi_view_get_user_input(const RofiViewState *state)
Definition: view.c:576
color_reset
#define color_reset
Definition: rofi.h:90
rofi_view_workers_finalize
void rofi_view_workers_finalize(void)
Definition: view.c:2002
SCOPE_MOUSE_LISTVIEW
@ SCOPE_MOUSE_LISTVIEW
Definition: keyb.h:45
widget_get_desired_height
int widget_get_desired_height(widget *wid)
Definition: widget.c:552
mode_get_message
char * mode_get_message(const Mode *mode)
Definition: mode.c:164
rofi_view_cleanup
void rofi_view_cleanup()
Definition: view.c:1937
SELECT_ELEMENT_8
@ SELECT_ELEMENT_8
Definition: keyb.h:138
RofiViewState::overlay
textbox * overlay
Definition: view-internal.h:66
MOVE_WORD_BACK
@ MOVE_WORD_BACK
Definition: keyb.h:71
CUSTOM_16
@ CUSTOM_16
Definition: keyb.h:124
_thread_state_view::stop
unsigned int stop
Definition: view.c:614
MENU_LOWER_MASK
@ MENU_LOWER_MASK
Definition: mode.h:85
_thread_state_view::acount
unsigned int * acount
Definition: view.c:607
rofi_view_listview_mouse_activated_cb
static void rofi_view_listview_mouse_activated_cb(listview *lv, gboolean custom, void *udata)
Definition: view.c:1634
helper.h
xcb-internal.h
rofi_view_get_completed
unsigned int rofi_view_get_completed(const RofiViewState *state)
Definition: view.c:571
rofi_view_trigger_action
gboolean rofi_view_trigger_action(RofiViewState *state, BindingsScope scope, guint action)
Definition: view.c:1422
_thread_state::callback
void(* callback)(struct _thread_state *t, gpointer data)
Definition: rofi-types.h:278
ROFI_HL_BOLD
@ ROFI_HL_BOLD
Definition: rofi-types.h:54
MOVE_CHAR_FORWARD
@ MOVE_CHAR_FORWARD
Definition: keyb.h:77
REMOVE_CHAR_FORWARD
@ REMOVE_CHAR_FORWARD
Definition: keyb.h:83
process_result
void process_result(RofiViewState *state)
Definition: rofi.c:208
widget_resize
void widget_resize(widget *widget, short w, short h)
Definition: widget.c:123
RofiViewState::case_indicator
textbox * case_indicator
Definition: view-internal.h:61
RofiViewState
Definition: view-internal.h:48
widget_need_redraw
gboolean widget_need_redraw(widget *wid)
Definition: widget.c:422
WIDGET_TRIGGER_ACTION_RESULT_HANDLED
@ WIDGET_TRIGGER_ACTION_RESULT_HANDLED
Definition: widget.h:82
config
Settings config
Settings::scroll_method
unsigned int scroll_method
Definition: settings.h:174
WIDGET_TRIGGER_ACTION_RESULT_IGNORED
@ WIDGET_TRIGGER_ACTION_RESULT_IGNORED
Definition: widget.h:80
RofiViewState::filtered_lines
unsigned int filtered_lines
Definition: view-internal.h:80
RofiHighlightColorStyle
Definition: rofi-types.h:171
ROFI_ORIENTATION_HORIZONTAL
@ ROFI_ORIENTATION_HORIZONTAL
Definition: rofi-types.h:138
listview_set_selected
void listview_set_selected(listview *lv, unsigned int selected)
Definition: listview.c:536
color_green
#define color_green
Definition: rofi.h:96
repaint_source
guint repaint_source
Definition: view.c:118
TB_EDITABLE
@ TB_EDITABLE
Definition: textbox.h:82
Settings::sort
unsigned int sort
Definition: settings.h:117
ROW_UP
@ ROW_UP
Definition: keyb.h:100
fullscreen
gboolean fullscreen
Definition: view.c:120
listview_nav_down
void listview_nav_down(listview *lv)
Definition: listview.c:741
rofi_view_reload_idle
static gboolean rofi_view_reload_idle(G_GNUC_UNUSED gpointer data)
Definition: view.c:455
widget_padding_get_padding_width
int widget_padding_get_padding_width(const widget *wid)
Definition: widget.c:544
rofi_view_setup_fake_transparency
static void rofi_view_setup_fake_transparency(const char *const fake_background)
Definition: view.c:669
rofi_view_set_selected_line
void rofi_view_set_selected_line(RofiViewState *state, unsigned int selected_line)
Definition: view.c:516
_widget
Definition: widget-internal.h:36
WidgetTriggerActionResult
WidgetTriggerActionResult
Definition: widget.h:78
Settings::threads
unsigned int threads
Definition: settings.h:173
ACCEPT_ALT
@ ACCEPT_ALT
Definition: keyb.h:92
ROW_FIRST
@ ROW_FIRST
Definition: keyb.h:105
rofi_view_set_overlay
void rofi_view_set_overlay(RofiViewState *state, const char *text)
Definition: view.c:2014
REMOVE_CHAR_BACK
@ REMOVE_CHAR_BACK
Definition: keyb.h:85
RofiViewState::mouse_seen
int mouse_seen
Definition: view-internal.h:113
WIDGET_TYPE_TEXTBOX_TEXT
@ WIDGET_TYPE_TEXTBOX_TEXT
Definition: widget.h:71
rofi_view_window_update_size
static void rofi_view_window_update_size(RofiViewState *state)
Definition: view.c:416
rofi_view_reload
void rofi_view_reload(void)
Definition: view.c:466
CUSTOM_4
@ CUSTOM_4
Definition: keyb.h:112
rofi_view_switch_mode
void rofi_view_switch_mode(RofiViewState *state, Mode *mode)
Definition: view.c:2042
textbox_create
textbox * textbox_create(widget *parent, WidgetType type, const char *name, TextboxFlags flags, TextBoxFontType tbft, const char *text, double xalign, double yalign)
Definition: textbox.c:164
edit_draw
cairo_t * edit_draw
Definition: view.c:104