rofi  1.5.2
view.c
Go to the documentation of this file.
1 /*
2  * rofi
3  *
4  * MIT/X11 License
5  * Copyright © 2013-2017 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 
226 static gboolean rofi_view_repaint ( G_GNUC_UNUSED void * data )
227 {
228  if ( current_active_menu ) {
229  // Repaint the view (if needed).
230  // After a resize the edit_pixmap surface might not contain anything anymore.
231  // If we already re-painted, this does nothing.
233  g_debug ( "expose event" );
234  TICK_N ( "Expose" );
235  xcb_copy_area ( xcb->connection, CacheState.edit_pixmap, CacheState.main_window, CacheState.gc,
237  xcb_flush ( xcb->connection );
238  TICK_N ( "flush" );
239  CacheState.repaint_source = 0;
240  }
241  return G_SOURCE_REMOVE;
242 }
243 
245 {
246  if ( state->prompt ) {
247  const char *str = mode_get_display_name ( state->sw );
248  textbox_text ( state->prompt, str );
249  }
250 }
251 
264 static const int loc_transtable[9] = {
265  WL_CENTER,
266  WL_NORTH | WL_WEST,
267  WL_NORTH,
268  WL_NORTH | WL_EAST,
269  WL_EAST,
270  WL_SOUTH | WL_EAST,
271  WL_SOUTH,
272  WL_SOUTH | WL_WEST,
273  WL_WEST
274 };
276 {
277  int location = rofi_theme_get_position ( WIDGET ( state->main_window ), "location", loc_transtable[config.location] );
278  int anchor = location;
279  if ( !listview_get_fixed_num_lines ( state->list_view ) ) {
280  anchor = location;
281  if ( location == WL_CENTER ) {
282  anchor = WL_NORTH;
283  }
284  else if ( location == WL_EAST ) {
285  anchor = WL_NORTH_EAST;
286  }
287  else if ( location == WL_WEST ) {
288  anchor = WL_NORTH_WEST;
289  }
290  }
291  anchor = rofi_theme_get_position ( WIDGET ( state->main_window ), "anchor", anchor );
292 
293  if ( CacheState.fullscreen ) {
294  state->x = CacheState.mon.x;
295  state->y = CacheState.mon.y;
296  return;
297  }
298  state->y = CacheState.mon.y + ( CacheState.mon.h ) / 2;
299  state->x = CacheState.mon.x + ( CacheState.mon.w ) / 2;
300  // Determine window location
301  switch ( location )
302  {
303  case WL_NORTH_WEST:
304  state->x = CacheState.mon.x;
305  /* FALLTHRU */
306  case WL_NORTH:
307  state->y = CacheState.mon.y;
308  break;
309  case WL_NORTH_EAST:
310  state->y = CacheState.mon.y;
311  /* FALLTHRU */
312  case WL_EAST:
313  state->x = CacheState.mon.x + CacheState.mon.w;
314  break;
315  case WL_SOUTH_EAST:
316  state->x = CacheState.mon.x + CacheState.mon.w;
317  /* FALLTHRU */
318  case WL_SOUTH:
319  state->y = CacheState.mon.y + CacheState.mon.h;
320  break;
321  case WL_SOUTH_WEST:
322  state->y = CacheState.mon.y + CacheState.mon.h;
323  /* FALLTHRU */
324  case WL_WEST:
325  state->x = CacheState.mon.x;
326  break;
327  case WL_CENTER:
328  ;
329  /* FALLTHRU */
330  default:
331  break;
332  }
333  switch ( anchor )
334  {
335  case WL_SOUTH_WEST:
336  state->y -= state->height;
337  break;
338  case WL_SOUTH:
339  state->x -= state->width / 2;
340  state->y -= state->height;
341  break;
342  case WL_SOUTH_EAST:
343  state->x -= state->width;
344  state->y -= state->height;
345  break;
346  case WL_NORTH_EAST:
347  state->x -= state->width;
348  break;
349  case WL_NORTH_WEST:
350  break;
351  case WL_NORTH:
352  state->x -= state->width / 2;
353  break;
354  case WL_EAST:
355  state->x -= state->width;
356  state->y -= state->height / 2;
357  break;
358  case WL_WEST:
359  state->y -= state->height / 2;
360  break;
361  case WL_CENTER:
362  state->y -= state->height / 2;
363  state->x -= state->width / 2;
364  break;
365  default:
366  break;
367  }
368  // Apply offset.
369  RofiDistance x = rofi_theme_get_distance ( WIDGET ( state->main_window ), "x-offset", config.x_offset );
370  RofiDistance y = rofi_theme_get_distance ( WIDGET ( state->main_window ), "y-offset", config.y_offset );
373 }
374 
376 {
377  uint16_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
378  uint32_t vals[] = { state->x, state->y, state->width, state->height };
379 
380  // Display it.
381  xcb_configure_window ( xcb->connection, CacheState.main_window, mask, vals );
382  cairo_destroy ( CacheState.edit_draw );
383  cairo_surface_destroy ( CacheState.edit_surf );
384 
385  xcb_free_pixmap ( xcb->connection, CacheState.edit_pixmap );
386  CacheState.edit_pixmap = xcb_generate_id ( xcb->connection );
387  xcb_create_pixmap ( xcb->connection, depth->depth,
388  CacheState.edit_pixmap, CacheState.main_window, state->width, state->height );
389 
390  CacheState.edit_surf = cairo_xcb_surface_create ( xcb->connection, CacheState.edit_pixmap, visual, state->width, state->height );
391  CacheState.edit_draw = cairo_create ( CacheState.edit_surf );
392 
393  g_debug ( "Re-size window based internal request: %dx%d.", state->width, state->height );
394  // Should wrap main window in a widget.
395  widget_resize ( WIDGET ( state->main_window ), state->width, state->height );
396 }
397 
399 {
400  if ( state->mesg_box == NULL ) {
401  return;
402  }
403  char *msg = mode_get_message ( state->sw );
404  if ( msg ) {
405  textbox_text ( state->mesg_tb, msg );
406  widget_enable ( WIDGET ( state->mesg_box ) );
407  g_free ( msg );
408  }
409  else {
410  widget_disable ( WIDGET ( state->mesg_box ) );
411  }
412 }
413 
414 static gboolean rofi_view_reload_idle ( G_GNUC_UNUSED gpointer data )
415 {
416  if ( current_active_menu ) {
417  current_active_menu->reload = TRUE;
420  }
421  CacheState.idle_timeout = 0;
422  return G_SOURCE_REMOVE;
423 }
424 
425 void rofi_view_reload ( void )
426 {
427  // @TODO add check if current view is equal to the callee
428  if ( CacheState.idle_timeout == 0 ) {
429  CacheState.idle_timeout = g_timeout_add ( 1000 / 10, rofi_view_reload_idle, NULL );
430  }
431 }
433 {
434  if ( current_active_menu && CacheState.repaint_source == 0 ) {
435  CacheState.count++;
436  g_debug ( "redraw %llu", CacheState.count );
437  CacheState.repaint_source = g_idle_add_full ( G_PRIORITY_HIGH_IDLE, rofi_view_repaint, NULL, NULL );
438  }
439 }
440 
442 {
443  state->quit = FALSE;
444  state->retv = MENU_CANCEL;
445 }
446 
448 {
449  return current_active_menu;
450 }
451 
453 {
454  if ( current_active_menu != NULL && state != NULL ) {
455  g_queue_push_head ( &( CacheState.views ), current_active_menu );
456  // TODO check.
457  current_active_menu = state;
458  g_debug ( "stack view." );
461  return;
462  }
463  else if ( state == NULL && !g_queue_is_empty ( &( CacheState.views ) ) ) {
464  g_debug ( "pop view." );
465  current_active_menu = g_queue_pop_head ( &( CacheState.views ) );
468  return;
469  }
470  g_assert ( ( current_active_menu == NULL && state != NULL ) || ( current_active_menu != NULL && state == NULL ) );
471  current_active_menu = state;
473 }
474 
475 void rofi_view_set_selected_line ( RofiViewState *state, unsigned int selected_line )
476 {
477  state->selected_line = selected_line;
478  // Find the line.
479  unsigned int selected = 0;
480  for ( unsigned int i = 0; ( ( state->selected_line ) ) < UINT32_MAX && !selected && i < state->filtered_lines; i++ ) {
481  if ( state->line_map[i] == ( state->selected_line ) ) {
482  selected = i;
483  break;
484  }
485  }
486  listview_set_selected ( state->list_view, selected );
487  xcb_clear_area ( xcb->connection, CacheState.main_window, 1, 0, 0, 1, 1 );
488  xcb_flush ( xcb->connection );
489 }
490 
492 {
493  if ( state->tokens ) {
494  helper_tokenize_free ( state->tokens );
495  state->tokens = NULL;
496  }
497  // Do this here?
498  // Wait for final release?
499  widget_free ( WIDGET ( state->main_window ) );
500  widget_free ( WIDGET ( state->overlay ) );
501 
502  g_free ( state->line_map );
503  g_free ( state->distance );
504  // Free the switcher boxes.
505  // When state is free'ed we should no longer need these.
506  if ( config.sidebar_mode == TRUE ) {
507  g_free ( state->modi );
508  state->num_modi = 0;
509  }
510  g_free ( state );
511 }
512 
514 {
515  return state->retv;
516 }
517 
518 unsigned int rofi_view_get_selected_line ( const RofiViewState *state )
519 {
520  return state->selected_line;
521 }
522 
523 unsigned int rofi_view_get_next_position ( const RofiViewState *state )
524 {
525  unsigned int next_pos = state->selected_line;
526  unsigned int selected = listview_get_selected ( state->list_view );
527  if ( ( selected + 1 ) < state->num_lines ) {
528  ( next_pos ) = state->line_map[selected + 1];
529  }
530  return next_pos;
531 }
532 
533 unsigned int rofi_view_get_completed ( const RofiViewState *state )
534 {
535  return state->quit;
536 }
537 
538 const char * rofi_view_get_user_input ( const RofiViewState *state )
539 {
540  if ( state->text ) {
541  return state->text->text;
542  }
543  return NULL;
544 }
545 
552 {
553  return g_malloc0 ( sizeof ( RofiViewState ) );
554 }
555 
559 typedef struct _thread_state_view
560 {
563 
565  GCond *cond;
567  GMutex *mutex;
569  unsigned int *acount;
570 
574  unsigned int start;
576  unsigned int stop;
578  unsigned int count;
579 
581  const char *pattern;
583  glong plen;
591 static void rofi_view_call_thread ( gpointer data, gpointer user_data )
592 {
593  thread_state *t = (thread_state *) data;
594  t->callback ( t, user_data );
595 }
596 
597 static void filter_elements ( thread_state *ts, G_GNUC_UNUSED gpointer user_data )
598 {
600  for ( unsigned int i = t->start; i < t->stop; i++ ) {
601  int match = mode_token_match ( t->state->sw, t->state->tokens, i );
602  // If each token was matched, add it to list.
603  if ( match ) {
604  t->state->line_map[t->start + t->count] = i;
605  if ( config.sort ) {
606  // This is inefficient, need to fix it.
607  char * str = mode_get_completion ( t->state->sw, i );
608  glong slen = g_utf8_strlen ( str, -1 );
609  switch ( config.sorting_method_enum )
610  {
611  case SORT_FZF:
612  t->state->distance[i] = rofi_scorer_fuzzy_evaluate ( t->pattern, t->plen, str, slen );
613  break;
614  case SORT_NORMAL:
615  default:
616  t->state->distance[i] = levenshtein ( t->pattern, t->plen, str, slen );
617  break;
618  }
619  g_free ( str );
620  }
621  t->count++;
622  }
623  }
624  if ( t->acount != NULL ) {
625  g_mutex_lock ( t->mutex );
626  ( *( t->acount ) )--;
627  g_cond_signal ( t->cond );
628  g_mutex_unlock ( t->mutex );
629  }
630 }
631 static void rofi_view_setup_fake_transparency ( const char* const fake_background )
632 {
633  if ( CacheState.fake_bg == NULL ) {
634  cairo_surface_t *s = NULL;
639  TICK_N ( "Fake start" );
640  if ( g_strcmp0 ( fake_background, "real" ) == 0 ) {
641  return;
642  }
643  else if ( g_strcmp0 ( fake_background, "screenshot" ) == 0 ) {
645  }
646  else if ( g_strcmp0 ( fake_background, "background" ) == 0 ) {
648  }
649  else {
650  char *fpath = rofi_expand_path ( fake_background );
651  g_debug ( "Opening %s to use as background.", fpath );
652  s = cairo_image_surface_create_from_png ( fpath );
653  CacheState.fake_bgrel = TRUE;
654  g_free ( fpath );
655  }
656  TICK_N ( "Get surface." );
657  if ( s != NULL ) {
658  if ( cairo_surface_status ( s ) != CAIRO_STATUS_SUCCESS ) {
659  g_debug ( "Failed to open surface fake background: %s",
660  cairo_status_to_string ( cairo_surface_status ( s ) ) );
661  cairo_surface_destroy ( s );
662  s = NULL;
663  }
664  else {
665  CacheState.fake_bg = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, CacheState.mon.w, CacheState.mon.h );
666  cairo_t *dr = cairo_create ( CacheState.fake_bg );
667  if ( CacheState.fake_bgrel ) {
668  cairo_set_source_surface ( dr, s, 0, 0 );
669  }
670  else {
671  cairo_set_source_surface ( dr, s, -CacheState.mon.x, -CacheState.mon.y );
672  }
673  cairo_paint ( dr );
674  cairo_destroy ( dr );
675  cairo_surface_destroy ( s );
676  }
677  }
678  TICK_N ( "Fake transparency" );
679  }
680 }
681 void __create_window ( MenuFlags menu_flags )
682 {
683  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;
684  uint32_t selval[] = {
685  XCB_BACK_PIXMAP_NONE, 0,
686  XCB_GRAVITY_STATIC,
687  XCB_BACKING_STORE_NOT_USEFUL,
688  XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE |
689  XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_KEYMAP_STATE |
690  XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_FOCUS_CHANGE | XCB_EVENT_MASK_BUTTON_1_MOTION,
691  map
692  };
693 
694  xcb_window_t box_window = xcb_generate_id ( xcb->connection );
695  xcb_void_cookie_t cc = xcb_create_window_checked ( xcb->connection, depth->depth, box_window, xcb_stuff_get_root_window ( ),
696  0, 0, 200, 100, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
697  visual->visual_id, selmask, selval );
698  xcb_generic_error_t *error;
699  error = xcb_request_check ( xcb->connection, cc );
700  if ( error ) {
701  g_error ( "xcb_create_window() failed error=0x%x\n", error->error_code );
702  exit ( EXIT_FAILURE );
703  }
704  TICK_N ( "xcb create window" );
705  CacheState.gc = xcb_generate_id ( xcb->connection );
706  xcb_create_gc ( xcb->connection, CacheState.gc, box_window, 0, 0 );
707 
708  TICK_N ( "xcb create gc" );
709  // Create a drawable.
710  CacheState.edit_pixmap = xcb_generate_id ( xcb->connection );
711  xcb_create_pixmap ( xcb->connection, depth->depth,
712  CacheState.edit_pixmap, CacheState.main_window, 200, 100 );
713 
714  CacheState.edit_surf = cairo_xcb_surface_create ( xcb->connection, CacheState.edit_pixmap, visual, 200, 100 );
715  CacheState.edit_draw = cairo_create ( CacheState.edit_surf );
716 
717  TICK_N ( "create cairo surface" );
718  // Set up pango context.
719  cairo_font_options_t *fo = cairo_font_options_create ();
720  // Take font description from xlib surface
721  cairo_surface_get_font_options ( CacheState.edit_surf, fo );
722  // TODO should we update the drawable each time?
723  PangoContext *p = pango_cairo_create_context ( CacheState.edit_draw );
724  // Set the font options from the xlib surface
725  pango_cairo_context_set_font_options ( p, fo );
726  TICK_N ( "pango cairo font setup" );
727 
728  CacheState.main_window = box_window;
729  CacheState.flags = menu_flags;
730  monitor_active ( &( CacheState.mon ) );
731  // Setup dpi
732  if ( config.dpi > 1 ) {
733  PangoFontMap *font_map = pango_cairo_font_map_get_default ();
734  pango_cairo_font_map_set_resolution ( (PangoCairoFontMap *) font_map, (double) config.dpi );
735  }
736  else if ( config.dpi == 0 || config.dpi == 1 ) {
737  // Auto-detect mode.
738  double dpi = 96;
739  if ( CacheState.mon.mh > 0 && config.dpi == 1 ) {
740  dpi = ( CacheState.mon.h * 25.4 ) / (double) ( CacheState.mon.mh );
741  }
742  else {
743  dpi = ( xcb->screen->height_in_pixels * 25.4 ) / (double) ( xcb->screen->height_in_millimeters );
744  }
745 
746  g_debug ( "Auto-detected DPI: %.2lf", dpi );
747  PangoFontMap *font_map = pango_cairo_font_map_get_default ();
748  pango_cairo_font_map_set_resolution ( (PangoCairoFontMap *) font_map, dpi );
749  config.dpi = dpi;
750  }
751  // Setup font.
752  // Dummy widget.
753  box *win = box_create ( NULL, "window", ROFI_ORIENTATION_HORIZONTAL );
754  const char *font = rofi_theme_get_string ( WIDGET ( win ), "font", config.menu_font );
755  if ( font ) {
756  PangoFontDescription *pfd = pango_font_description_from_string ( font );
757  if ( helper_validate_font ( pfd, font ) ) {
758  pango_context_set_font_description ( p, pfd );
759  }
760  pango_font_description_free ( pfd );
761  }
762  PangoLanguage *l = pango_language_get_default ();
763  pango_context_set_language ( p, l );
764  TICK_N ( "configure font" );
765 
766  // Tell textbox to use this context.
767  textbox_set_pango_context ( font, p );
768  // cleanup
769  g_object_unref ( p );
770  cairo_font_options_destroy ( fo );
771 
772  TICK_N ( "textbox setup" );
773  // // make it an unmanaged window
774  if ( ( ( menu_flags & MENU_NORMAL_WINDOW ) == 0 ) ) {
775  window_set_atom_prop ( box_window, xcb->ewmh._NET_WM_STATE, &( xcb->ewmh._NET_WM_STATE_ABOVE ), 1 );
776  uint32_t values[] = { 1 };
777  xcb_change_window_attributes ( xcb->connection, box_window, XCB_CW_OVERRIDE_REDIRECT, values );
778  }
779  else{
780  window_set_atom_prop ( box_window, xcb->ewmh._NET_WM_WINDOW_TYPE, &( xcb->ewmh._NET_WM_WINDOW_TYPE_NORMAL ), 1 );
781  x11_disable_decoration ( box_window );
782  }
783 
784  TICK_N ( "setup window attributes" );
785  CacheState.fullscreen = rofi_theme_get_boolean ( WIDGET ( win ), "fullscreen", config.fullscreen );
786  if ( CacheState.fullscreen ) {
787  xcb_atom_t atoms[] = {
788  xcb->ewmh._NET_WM_STATE_FULLSCREEN,
789  xcb->ewmh._NET_WM_STATE_ABOVE
790  };
791  window_set_atom_prop ( box_window, xcb->ewmh._NET_WM_STATE, atoms, sizeof ( atoms ) / sizeof ( xcb_atom_t ) );
792  }
793 
794  TICK_N ( "setup window fullscreen" );
795  // Set the WM_NAME
796  xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, box_window, xcb->ewmh._NET_WM_NAME, xcb->ewmh.UTF8_STRING, 8, 4, "rofi" );
797  xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, box_window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, 4, "rofi" );
798 
799  const char wm_class_name[] = "rofi\0Rofi";
800  xcb_icccm_set_wm_class ( xcb->connection, box_window, sizeof ( wm_class_name ), wm_class_name );
801 
802  TICK_N ( "setup window name and class" );
803  const char *transparency = rofi_theme_get_string ( WIDGET ( win ), "transparency", NULL );
804  if ( transparency ) {
805  rofi_view_setup_fake_transparency ( transparency );
806  }
809  }
810  if ( xcb->sncontext != NULL ) {
811  sn_launchee_context_setup_window ( xcb->sncontext, CacheState.main_window );
812  }
813  TICK_N ( "setup startup notification" );
814  widget_free ( WIDGET ( win ) );
815  TICK_N ( "done" );
816 
817  // Set the PID.
818  pid_t pid = getpid ();
819  xcb_ewmh_set_wm_pid ( &( xcb->ewmh ), CacheState.main_window, pid );
820 
821  // Get hostname
822  const char *hostname = g_get_host_name ();
823  char *ahost = g_hostname_to_ascii ( hostname );
824  if ( ahost != NULL ) {
825  xcb_icccm_set_wm_client_machine ( xcb->connection,
826  CacheState.main_window,
827  XCB_ATOM_STRING, 8,
828  strlen ( ahost ), ahost );
829  g_free ( ahost );
830  }
831 }
832 
839 {
840  if ( CacheState.fullscreen ) {
841  state->width = CacheState.mon.w;
842  return;
843  }
844  if ( config.menu_width < 0 ) {
845  double fw = textbox_get_estimated_char_width ( );
846  state->width = -( fw * config.menu_width );
847  state->width += widget_padding_get_padding_width ( WIDGET ( state->main_window ) );
848  }
849  else{
850  // Calculate as float to stop silly, big rounding down errors.
851  state->width = config.menu_width < 101 ? ( CacheState.mon.w / 100.0f ) * ( float ) config.menu_width : config.menu_width;
852  }
853  // Use theme configured width, if set.
854  RofiDistance width = rofi_theme_get_distance ( WIDGET ( state->main_window ), "width", state->width );
856 }
857 
867 static void rofi_view_nav_row_tab ( RofiViewState *state )
868 {
869  if ( state->filtered_lines == 1 ) {
870  state->retv = MENU_OK;
871  ( state->selected_line ) = state->line_map[listview_get_selected ( state->list_view )];
872  state->quit = 1;
873  return;
874  }
875 
876  // Double tab!
877  if ( state->filtered_lines == 0 && ROW_TAB == state->prev_action ) {
878  state->retv = MENU_NEXT;
879  ( state->selected_line ) = 0;
880  state->quit = TRUE;
881  }
882  else {
883  listview_nav_down ( state->list_view );
884  }
885  state->prev_action = ROW_TAB;
886 }
892 inline static void rofi_view_nav_row_select ( RofiViewState *state )
893 {
894  if ( state->list_view == NULL ) {
895  return;
896  }
897  unsigned int selected = listview_get_selected ( state->list_view );
898  // If a valid item is selected, return that..
899  if ( selected < state->filtered_lines ) {
900  char *str = mode_get_completion ( state->sw, state->line_map[selected] );
901  textbox_text ( state->text, str );
902  g_free ( str );
903  textbox_keybinding ( state->text, MOVE_END );
904  state->refilter = TRUE;
905  }
906 }
907 
913 inline static void rofi_view_nav_first ( RofiViewState * state )
914 {
915 // state->selected = 0;
916  listview_set_selected ( state->list_view, 0 );
917 }
918 
924 inline static void rofi_view_nav_last ( RofiViewState * state )
925 {
926  // If no lines, do nothing.
927  if ( state->filtered_lines == 0 ) {
928  return;
929  }
930  //state->selected = state->filtered_lines - 1;
931  listview_set_selected ( state->list_view, -1 );
932 }
933 
934 static void update_callback ( textbox *t, unsigned int index, void *udata, TextBoxFontType type, gboolean full )
935 {
936  RofiViewState *state = (RofiViewState *) udata;
937  if ( full ) {
938  GList *add_list = NULL;
939  int fstate = 0;
940  char *text = mode_get_display_value ( state->sw, state->line_map[index], &fstate, &add_list, TRUE );
941  type |= fstate;
942  textbox_font ( t, type );
943  // Move into list view.
944  textbox_text ( t, text );
945  PangoAttrList *list = textbox_get_pango_attributes ( t );
946  if ( list != NULL ) {
947  pango_attr_list_ref ( list );
948  }
949  else{
950  list = pango_attr_list_new ();
951  }
952  int icon_height = textbox_get_font_height ( t );
953 
954  cairo_surface_t *icon = mode_get_icon ( state->sw, state->line_map[index], icon_height );
955  textbox_icon ( t, icon );
956 
957  if ( state->tokens && config.show_match ) {
958  RofiHighlightColorStyle th = { ROFI_HL_BOLD | ROFI_HL_UNDERLINE, { 0.0, 0.0, 0.0, 0.0 } };
959  th = rofi_theme_get_highlight ( WIDGET ( t ), "highlight", th );
961  }
962  for ( GList *iter = g_list_first ( add_list ); iter != NULL; iter = g_list_next ( iter ) ) {
963  pango_attr_list_insert ( list, (PangoAttribute *) ( iter->data ) );
964  }
965  textbox_set_pango_attributes ( t, list );
966  pango_attr_list_unref ( list );
967  g_list_free ( add_list );
968  g_free ( text );
969  }
970  else {
971  int fstate = 0;
972  mode_get_display_value ( state->sw, state->line_map[index], &fstate, NULL, FALSE );
973  type |= fstate;
974  textbox_font ( t, type );
975  }
976 }
977 
978 void rofi_view_update ( RofiViewState *state, gboolean qr )
979 {
980  if ( !widget_need_redraw ( WIDGET ( state->main_window ) ) ) {
981  return;
982  }
983  g_debug ( "Redraw view" );
984  TICK ();
985  cairo_t *d = CacheState.edit_draw;
986  cairo_set_operator ( d, CAIRO_OPERATOR_SOURCE );
987  if ( CacheState.fake_bg != NULL ) {
988  if ( CacheState.fake_bgrel ) {
989  cairo_set_source_surface ( d, CacheState.fake_bg, 0.0, 0.0 );
990  }
991  else {
992  cairo_set_source_surface ( d, CacheState.fake_bg,
993  -(double) ( state->x - CacheState.mon.x ),
994  -(double) ( state->y - CacheState.mon.y ) );
995  }
996  cairo_paint ( d );
997  cairo_set_operator ( d, CAIRO_OPERATOR_OVER );
998  }
999  else {
1000  // Paint the background transparent.
1001  cairo_set_source_rgba ( d, 0, 0, 0, 0.0 );
1002  cairo_paint ( d );
1003  }
1004  TICK_N ( "Background" );
1005 
1006  // Always paint as overlay over the background.
1007  cairo_set_operator ( d, CAIRO_OPERATOR_OVER );
1008  widget_draw ( WIDGET ( state->main_window ), d );
1009 
1010  if ( state->overlay ) {
1011  widget_draw ( WIDGET ( state->overlay ), d );
1012  }
1013 
1014  TICK_N ( "widgets" );
1015  cairo_surface_flush ( CacheState.edit_surf );
1016  if ( qr ) {
1018  }
1019 }
1020 
1021 static void _rofi_view_reload_row ( RofiViewState *state )
1022 {
1023  g_free ( state->line_map );
1024  g_free ( state->distance );
1025  state->num_lines = mode_get_num_entries ( state->sw );
1026  state->line_map = g_malloc0_n ( state->num_lines, sizeof ( unsigned int ) );
1027  state->distance = g_malloc0_n ( state->num_lines, sizeof ( int ) );
1028  listview_set_max_lines ( state->list_view, state->num_lines );
1029  rofi_view_reload_message_bar ( state );
1030 }
1031 
1032 static void rofi_view_refilter ( RofiViewState *state )
1033 {
1034  TICK_N ( "Filter start" );
1035  if ( state->reload ) {
1036  _rofi_view_reload_row ( state );
1037  state->reload = FALSE;
1038  }
1039  if ( state->tokens ) {
1040  helper_tokenize_free ( state->tokens );
1041  state->tokens = NULL;
1042  }
1043  if ( state->text && strlen ( state->text->text ) > 0 ) {
1044  unsigned int j = 0;
1045  gchar *pattern = mode_preprocess_input ( state->sw, state->text->text );
1046  glong plen = pattern ? g_utf8_strlen ( pattern, -1 ) : 0;
1047  state->tokens = helper_tokenize ( pattern, config.case_sensitive );
1054  unsigned int nt = MAX ( 1, state->num_lines / 500 );
1055  thread_state_view states[nt];
1056  GCond cond;
1057  GMutex mutex;
1058  g_mutex_init ( &mutex );
1059  g_cond_init ( &cond );
1060  unsigned int count = nt;
1061  unsigned int steps = ( state->num_lines + nt ) / nt;
1062  for ( unsigned int i = 0; i < nt; i++ ) {
1063  states[i].state = state;
1064  states[i].start = i * steps;
1065  states[i].stop = MIN ( state->num_lines, ( i + 1 ) * steps );
1066  states[i].count = 0;
1067  states[i].cond = &cond;
1068  states[i].mutex = &mutex;
1069  states[i].acount = &count;
1070  states[i].plen = plen;
1071  states[i].pattern = pattern;
1072  states[i].st.callback = filter_elements;
1073  if ( i > 0 ) {
1074  g_thread_pool_push ( tpool, &states[i], NULL );
1075  }
1076  }
1077  // Run one in this thread.
1078  rofi_view_call_thread ( &states[0], NULL );
1079  // No need to do this with only one thread.
1080  if ( nt > 1 ) {
1081  g_mutex_lock ( &mutex );
1082  while ( count > 0 ) {
1083  g_cond_wait ( &cond, &mutex );
1084  }
1085  g_mutex_unlock ( &mutex );
1086  }
1087  g_cond_clear ( &cond );
1088  g_mutex_clear ( &mutex );
1089  for ( unsigned int i = 0; i < nt; i++ ) {
1090  if ( j != states[i].start ) {
1091  memmove ( &( state->line_map[j] ), &( state->line_map[states[i].start] ), sizeof ( unsigned int ) * ( states[i].count ) );
1092  }
1093  j += states[i].count;
1094  }
1095  if ( config.sort ) {
1096  g_qsort_with_data ( state->line_map, j, sizeof ( int ), lev_sort, state->distance );
1097  }
1098 
1099  // Cleanup + bookkeeping.
1100  state->filtered_lines = j;
1101  g_free ( pattern );
1102  }
1103  else{
1104  for ( unsigned int i = 0; i < state->num_lines; i++ ) {
1105  state->line_map[i] = i;
1106  }
1107  state->filtered_lines = state->num_lines;
1108  }
1110 
1111  if ( config.auto_select == TRUE && state->filtered_lines == 1 && state->num_lines > 1 ) {
1112  ( state->selected_line ) = state->line_map[listview_get_selected ( state->list_view )];
1113  state->retv = MENU_OK;
1114  state->quit = TRUE;
1115  }
1116  // Size the window.
1117  int height = rofi_view_calculate_height ( state );
1118  if ( height != state->height ) {
1119  state->height = height;
1121  rofi_view_window_update_size ( state );
1122  g_debug ( "Resize based on re-filter" );
1123  }
1124  state->refilter = FALSE;
1125  TICK_N ( "Filter done" );
1126 }
1132 void process_result ( RofiViewState *state );
1134 {
1135  if ( state && state->finalize != NULL ) {
1136  state->finalize ( state );
1137  }
1138 }
1139 
1141 {
1142  RofiViewState *state = rofi_view_get_active ();
1143  switch ( action )
1144  {
1145  // Handling of paste
1146  case PASTE_PRIMARY:
1147  xcb_convert_selection ( xcb->connection, CacheState.main_window, XCB_ATOM_PRIMARY,
1148  xcb->ewmh.UTF8_STRING, xcb->ewmh.UTF8_STRING, XCB_CURRENT_TIME );
1149  xcb_flush ( xcb->connection );
1150  break;
1151  case PASTE_SECONDARY:
1152  xcb_convert_selection ( xcb->connection, CacheState.main_window, netatoms[CLIPBOARD],
1153  xcb->ewmh.UTF8_STRING, xcb->ewmh.UTF8_STRING, XCB_CURRENT_TIME );
1154  xcb_flush ( xcb->connection );
1155  break;
1156  case SCREENSHOT:
1158  break;
1159  case TOGGLE_SORT:
1160  if ( state->case_indicator != NULL ) {
1161  config.sort = !config.sort;
1162  state->refilter = TRUE;
1164  }
1165  break;
1166  case MODE_PREVIOUS:
1167  state->retv = MENU_PREVIOUS;
1168  ( state->selected_line ) = 0;
1169  state->quit = TRUE;
1170  break;
1171  // Menu navigation.
1172  case MODE_NEXT:
1173  state->retv = MENU_NEXT;
1174  ( state->selected_line ) = 0;
1175  state->quit = TRUE;
1176  break;
1177  // Toggle case sensitivity.
1179  if ( state->case_indicator != NULL ) {
1181  ( state->selected_line ) = 0;
1182  state->refilter = TRUE;
1184  }
1185  break;
1186  // Special delete entry command.
1187  case DELETE_ENTRY:
1188  {
1189  unsigned int selected = listview_get_selected ( state->list_view );
1190  if ( selected < state->filtered_lines ) {
1191  ( state->selected_line ) = state->line_map[selected];
1192  state->retv = MENU_ENTRY_DELETE;
1193  state->quit = TRUE;
1194  }
1195  break;
1196  }
1197  case SELECT_ELEMENT_1:
1198  case SELECT_ELEMENT_2:
1199  case SELECT_ELEMENT_3:
1200  case SELECT_ELEMENT_4:
1201  case SELECT_ELEMENT_5:
1202  case SELECT_ELEMENT_6:
1203  case SELECT_ELEMENT_7:
1204  case SELECT_ELEMENT_8:
1205  case SELECT_ELEMENT_9:
1206  case SELECT_ELEMENT_10:
1207  {
1208  unsigned int index = action - SELECT_ELEMENT_1;
1209  if ( index < state->filtered_lines ) {
1210  state->selected_line = state->line_map[index];
1211  state->retv = MENU_OK;
1212  state->quit = TRUE;
1213  }
1214  break;
1215  }
1216  case CUSTOM_1:
1217  case CUSTOM_2:
1218  case CUSTOM_3:
1219  case CUSTOM_4:
1220  case CUSTOM_5:
1221  case CUSTOM_6:
1222  case CUSTOM_7:
1223  case CUSTOM_8:
1224  case CUSTOM_9:
1225  case CUSTOM_10:
1226  case CUSTOM_11:
1227  case CUSTOM_12:
1228  case CUSTOM_13:
1229  case CUSTOM_14:
1230  case CUSTOM_15:
1231  case CUSTOM_16:
1232  case CUSTOM_17:
1233  case CUSTOM_18:
1234  case CUSTOM_19:
1235  {
1236  state->selected_line = UINT32_MAX;
1237  unsigned int selected = listview_get_selected ( state->list_view );
1238  if ( selected < state->filtered_lines ) {
1239  ( state->selected_line ) = state->line_map[selected];
1240  }
1241  state->retv = MENU_QUICK_SWITCH | ( ( action - CUSTOM_1 ) & MENU_LOWER_MASK );
1242  state->quit = TRUE;
1243  break;
1244  }
1245  // If you add a binding here, make sure to add it to rofi_view_keyboard_navigation too
1246  case CANCEL:
1247  state->retv = MENU_CANCEL;
1248  state->quit = TRUE;
1249  break;
1250  case ROW_UP:
1251  listview_nav_up ( state->list_view );
1252  break;
1253  case ROW_TAB:
1254  rofi_view_nav_row_tab ( state );
1255  break;
1256  case ROW_DOWN:
1257  listview_nav_down ( state->list_view );
1258  break;
1259  case ROW_LEFT:
1260  listview_nav_left ( state->list_view );
1261  break;
1262  case ROW_RIGHT:
1263  listview_nav_right ( state->list_view );
1264  break;
1265  case PAGE_PREV:
1266  listview_nav_page_prev ( state->list_view );
1267  break;
1268  case PAGE_NEXT:
1269  listview_nav_page_next ( state->list_view );
1270  break;
1271  case ROW_FIRST:
1272  rofi_view_nav_first ( state );
1273  break;
1274  case ROW_LAST:
1275  rofi_view_nav_last ( state );
1276  break;
1277  case ROW_SELECT:
1278  rofi_view_nav_row_select ( state );
1279  break;
1280  // If you add a binding here, make sure to add it to textbox_keybinding too
1281  case MOVE_CHAR_BACK:
1282  {
1283  if ( textbox_keybinding ( state->text, action ) == 0 ) {
1284  listview_nav_left ( state->list_view );
1285  }
1286  break;
1287  }
1288  case MOVE_CHAR_FORWARD:
1289  {
1290  if ( textbox_keybinding ( state->text, action ) == 0 ) {
1291  listview_nav_right ( state->list_view );
1292  }
1293  break;
1294  }
1295  case CLEAR_LINE:
1296  case MOVE_FRONT:
1297  case MOVE_END:
1298  case REMOVE_TO_EOL:
1299  case REMOVE_TO_SOL:
1300  case REMOVE_WORD_BACK:
1301  case REMOVE_WORD_FORWARD:
1302  case REMOVE_CHAR_FORWARD:
1303  case MOVE_WORD_BACK:
1304  case MOVE_WORD_FORWARD:
1305  case REMOVE_CHAR_BACK:
1306  {
1307  int rc = textbox_keybinding ( state->text, action );
1308  if ( rc == 1 ) {
1309  // Entry changed.
1310  state->refilter = TRUE;
1311  }
1312  else if ( rc == 2 ) {
1313  // Movement.
1314  }
1315  break;
1316  }
1317  case ACCEPT_ALT:
1318  {
1319  unsigned int selected = listview_get_selected ( state->list_view );
1320  state->selected_line = UINT32_MAX;
1321  if ( selected < state->filtered_lines ) {
1322  ( state->selected_line ) = state->line_map[selected];
1323  state->retv = MENU_OK;
1324  }
1325  else {
1326  // Nothing entered and nothing selected.
1327  state->retv = MENU_CUSTOM_INPUT;
1328  }
1329  state->retv |= MENU_CUSTOM_ACTION;
1330  state->quit = TRUE;
1331  break;
1332  }
1333  case ACCEPT_CUSTOM:
1334  {
1335  state->selected_line = UINT32_MAX;
1336  state->retv = MENU_CUSTOM_INPUT;
1337  state->quit = TRUE;
1338  break;
1339  }
1340  case ACCEPT_ENTRY:
1341  {
1342  // If a valid item is selected, return that..
1343  unsigned int selected = listview_get_selected ( state->list_view );
1344  state->selected_line = UINT32_MAX;
1345  if ( selected < state->filtered_lines ) {
1346  ( state->selected_line ) = state->line_map[selected];
1347  state->retv = MENU_OK;
1348  }
1349  else {
1350  // Nothing entered and nothing selected.
1351  state->retv = MENU_CUSTOM_INPUT;
1352  }
1353 
1354  state->quit = TRUE;
1355  break;
1356  }
1357  }
1358 }
1359 
1360 gboolean rofi_view_trigger_action ( RofiViewState *state, BindingsScope scope, guint action )
1361 {
1362  switch ( scope )
1363  {
1364  case SCOPE_GLOBAL:
1366  return TRUE;
1367  case SCOPE_MOUSE_LISTVIEW:
1369  case SCOPE_MOUSE_EDITBOX:
1370  case SCOPE_MOUSE_SCROLLBAR:
1372  {
1373  gint x = state->mouse.x, y = state->mouse.y;
1374  widget *target = widget_find_mouse_target ( WIDGET ( state->main_window ), scope, x, y );
1375  if ( target == NULL ) {
1376  return FALSE;
1377  }
1378  widget_xy_to_relative ( target, &x, &y );
1379  switch ( widget_trigger_action ( target, action, x, y ) )
1380  {
1382  return FALSE;
1384  target = NULL;
1385  /* FALLTHRU */
1387  state->mouse.motion_target = target;
1388  /* FALLTHRU */
1390  return TRUE;
1391  }
1392  break;
1393  }
1394  }
1395  return FALSE;
1396 }
1397 
1398 void rofi_view_handle_text ( RofiViewState *state, char *text )
1399 {
1400  if ( textbox_append_text ( state->text, text, strlen ( text ) ) ) {
1401  state->refilter = TRUE;
1402  }
1403 }
1404 
1405 void rofi_view_handle_mouse_motion ( RofiViewState *state, gint x, gint y )
1406 {
1407  state->mouse.x = x;
1408  state->mouse.y = y;
1409  if ( state->mouse.motion_target != NULL ) {
1410  widget_xy_to_relative ( state->mouse.motion_target, &x, &y );
1411  widget_motion_notify ( state->mouse.motion_target, x, y );
1412  }
1413 }
1414 
1416 {
1417  if ( rofi_view_get_completed ( state ) ) {
1418  // This menu is done.
1419  rofi_view_finalize ( state );
1420  // If there a state. (for example error) reload it.
1421  state = rofi_view_get_active ();
1422 
1423  // cleanup, if no more state to display.
1424  if ( state == NULL ) {
1425  // Quit main-loop.
1427  return;
1428  }
1429  }
1430 
1431  // Update if requested.
1432  if ( state->refilter ) {
1433  rofi_view_refilter ( state );
1434  }
1435  rofi_view_update ( state, TRUE );
1436 }
1437 
1442 void rofi_view_temp_configure_notify ( RofiViewState *state, xcb_configure_notify_event_t *xce )
1443 {
1444  if ( xce->window == CacheState.main_window ) {
1445  if ( state->x != xce->x || state->y != xce->y ) {
1446  state->x = xce->x;
1447  state->y = xce->y;
1448  widget_queue_redraw ( WIDGET ( state->main_window ) );
1449  }
1450  if ( state->width != xce->width || state->height != xce->height ) {
1451  state->width = xce->width;
1452  state->height = xce->height;
1453 
1454  cairo_destroy ( CacheState.edit_draw );
1455  cairo_surface_destroy ( CacheState.edit_surf );
1456 
1457  xcb_free_pixmap ( xcb->connection, CacheState.edit_pixmap );
1458  CacheState.edit_pixmap = xcb_generate_id ( xcb->connection );
1459  xcb_create_pixmap ( xcb->connection, depth->depth, CacheState.edit_pixmap, CacheState.main_window,
1460  state->width, state->height );
1461 
1462  CacheState.edit_surf = cairo_xcb_surface_create ( xcb->connection, CacheState.edit_pixmap, visual, state->width, state->height );
1463  CacheState.edit_draw = cairo_create ( CacheState.edit_surf );
1464  g_debug ( "Re-size window based external request: %d %d", state->width, state->height );
1465  widget_resize ( WIDGET ( state->main_window ), state->width, state->height );
1466  }
1467  }
1468 }
1469 
1473 void rofi_view_temp_click_to_exit ( RofiViewState *state, xcb_window_t target )
1474 {
1475  if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == 0 ) {
1476  if ( target != CacheState.main_window ) {
1477  state->quit = TRUE;
1478  state->retv = MENU_CANCEL;
1479  }
1480  }
1481 }
1482 
1484 {
1485  if ( CacheState.repaint_source == 0 ) {
1486  CacheState.repaint_source = g_idle_add_full ( G_PRIORITY_HIGH_IDLE, rofi_view_repaint, NULL, NULL );
1487  }
1488 }
1489 
1491 {
1492  if ( CacheState.fullscreen == TRUE ) {
1493  return CacheState.mon.h;
1494  }
1495 
1496  RofiDistance h = rofi_theme_get_distance ( WIDGET ( state->main_window ), "height", 0 );
1497  unsigned int height = distance_get_pixel ( h, ROFI_ORIENTATION_VERTICAL );
1498  // If height is set, return it.
1499  if ( height > 0 ) {
1500  return height;
1501  }
1502  // Autosize based on widgets.
1503  widget *main_window = WIDGET ( state->main_window );
1505 }
1506 
1507 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 )
1508 {
1509  RofiViewState *state = ( RofiViewState *) user_data;
1510  unsigned int i;
1511  for ( i = 0; i < state->num_modi; i++ ) {
1512  if ( WIDGET ( state->modi[i] ) == wid ) {
1513  break;
1514  }
1515  }
1516  if ( i == state->num_modi ) {
1518  }
1519 
1520  switch ( action )
1521  {
1522  case MOUSE_CLICK_DOWN:
1523  state->retv = MENU_QUICK_SWITCH | ( i & MENU_LOWER_MASK );
1524  state->quit = TRUE;
1525  state->skip_absorb = TRUE;
1527  case MOUSE_CLICK_UP:
1528  case MOUSE_DCLICK_DOWN:
1529  case MOUSE_DCLICK_UP:
1530  break;
1531  }
1533 }
1534 
1535 // @TODO don't like this construction.
1536 static void rofi_view_listview_mouse_activated_cb ( listview *lv, gboolean custom, void *udata )
1537 {
1538  RofiViewState *state = (RofiViewState *) udata;
1539  state->retv = MENU_OK;
1540  if ( custom ) {
1541  state->retv |= MENU_CUSTOM_ACTION;
1542  }
1543  ( state->selected_line ) = state->line_map[listview_get_selected ( lv )];
1544  // Quit
1545  state->quit = TRUE;
1546  state->skip_absorb = TRUE;
1547 }
1548 
1549 static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget, const char *name )
1550 {
1551  char *defaults = NULL;
1552  widget *wid = NULL;
1553 
1557  if ( strcmp ( name, "mainbox" ) == 0 ) {
1558  wid = (widget *) box_create ( parent_widget, name, ROFI_ORIENTATION_VERTICAL );
1559  box_add ( (box *) parent_widget, WIDGET ( wid ), TRUE );
1560  defaults = "inputbar,message,listview,sidebar";
1561  }
1565  else if ( strcmp ( name, "inputbar" ) == 0 ) {
1566  wid = (widget *) box_create ( parent_widget, name, ROFI_ORIENTATION_HORIZONTAL );
1567  defaults = "prompt,entry,case-indicator";
1568  box_add ( (box *) parent_widget, WIDGET ( wid ), FALSE );
1569  }
1573  else if ( strcmp ( name, "prompt" ) == 0 ) {
1574  if ( state->prompt != NULL ) {
1575  g_error ( "Prompt widget can only be added once to the layout." );
1576  return;
1577  }
1578  // Prompt box.
1579  state->prompt = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "", 0, 0 );
1580  rofi_view_update_prompt ( state );
1581  box_add ( (box *) parent_widget, WIDGET ( state->prompt ), FALSE );
1582  defaults = NULL;
1583  }
1587  else if ( strcmp ( name, "case-indicator" ) == 0 ) {
1588  if ( state->case_indicator != NULL ) {
1589  g_error ( "Case indicator widget can only be added once to the layout." );
1590  return;
1591  }
1592  state->case_indicator = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "*", 0, 0 );
1593  // Add small separator between case indicator and text box.
1594  box_add ( (box *) parent_widget, WIDGET ( state->case_indicator ), FALSE );
1596  }
1600  else if ( strcmp ( name, "entry" ) == 0 ) {
1601  if ( state->text != NULL ) {
1602  g_error ( "Entry textbox widget can only be added once to the layout." );
1603  return;
1604  }
1605  // Entry box
1606  TextboxFlags tfl = TB_EDITABLE;
1607  tfl |= ( ( state->menu_flags & MENU_PASSWORD ) == MENU_PASSWORD ) ? TB_PASSWORD : 0;
1608  state->text = textbox_create ( parent_widget, WIDGET_TYPE_EDITBOX, name, tfl | TB_AUTOHEIGHT, NORMAL, NULL, 0, 0 );
1609  box_add ( (box *) parent_widget, WIDGET ( state->text ), TRUE );
1610  }
1614  else if ( strcmp ( name, "message" ) == 0 ) {
1615  if ( state->mesg_box != NULL ) {
1616  g_error ( "Message widget can only be added once to the layout." );
1617  return;
1618  }
1619  state->mesg_box = container_create ( parent_widget, name );
1620  state->mesg_tb = textbox_create ( WIDGET ( state->mesg_box ), WIDGET_TYPE_TEXTBOX_TEXT, "textbox", TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, NORMAL, NULL, 0, 0 );
1621  container_add ( state->mesg_box, WIDGET ( state->mesg_tb ) );
1622  rofi_view_reload_message_bar ( state );
1623  box_add ( (box *) parent_widget, WIDGET ( state->mesg_box ), FALSE );
1624  }
1628  else if ( strcmp ( name, "listview" ) == 0 ) {
1629  if ( state->list_view != NULL ) {
1630  g_error ( "Listview widget can only be added once to the layout." );
1631  return;
1632  }
1633  state->list_view = listview_create ( parent_widget, name, update_callback, state, config.element_height, 0 );
1634  box_add ( (box *) parent_widget, WIDGET ( state->list_view ), TRUE );
1635  // Set configuration
1639 
1640  int lines = rofi_theme_get_integer ( WIDGET ( state->list_view ), "lines", config.menu_lines );
1641  listview_set_num_lines ( state->list_view, lines );
1642  listview_set_max_lines ( state->list_view, state->num_lines );
1643  }
1647  else if ( strcmp ( name, "sidebar" ) == 0 ) {
1648  if ( state->sidebar_bar != NULL ) {
1649  g_error ( "Sidebar widget can only be added once to the layout." );
1650  return;
1651  }
1652  if ( config.sidebar_mode ) {
1653  state->sidebar_bar = box_create ( parent_widget, name, ROFI_ORIENTATION_HORIZONTAL );
1654  box_add ( (box *) parent_widget, WIDGET ( state->sidebar_bar ), FALSE );
1655  state->num_modi = rofi_get_num_enabled_modi ();
1656  state->modi = g_malloc0 ( state->num_modi * sizeof ( textbox * ) );
1657  for ( unsigned int j = 0; j < state->num_modi; j++ ) {
1658  const Mode * mode = rofi_get_mode ( j );
1659  state->modi[j] = textbox_create ( WIDGET ( state->sidebar_bar ), WIDGET_TYPE_SIDEBAR_MODI, "button", TB_AUTOHEIGHT, ( mode == state->sw ) ? HIGHLIGHT : NORMAL,
1660  mode_get_display_name ( mode ), 0.5, 0.5 );
1661  box_add ( state->sidebar_bar, WIDGET ( state->modi[j] ), TRUE );
1663  }
1664  }
1665  }
1666  else if ( g_ascii_strncasecmp ( name, "textbox", 7 ) == 0 ) {
1667  textbox *t = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOHEIGHT | TB_WRAP, NORMAL, "", 0, 0 );
1668  box_add ( (box *) parent_widget, WIDGET ( t ), TRUE );
1669  }
1670  else if ( g_ascii_strncasecmp ( name, "icon", 4 ) == 0 ) {
1671  icon *t = icon_create ( parent_widget, name );
1672  box_add ( (box *) parent_widget, WIDGET ( t ), TRUE );
1673  }
1674  else {
1675  wid = (widget *) box_create ( parent_widget, name, ROFI_ORIENTATION_VERTICAL );
1676  box_add ( (box *) parent_widget, WIDGET ( wid ), TRUE );
1677  //g_error("The widget %s does not exists. Invalid layout.", name);
1678  }
1679  if ( wid ) {
1680  GList *list = rofi_theme_get_list ( wid, "children", defaults );
1681  for ( const GList *iter = list; iter != NULL; iter = g_list_next ( iter ) ) {
1682  rofi_view_add_widget ( state, wid, (const char *) iter->data );
1683  }
1684  g_list_free_full ( list, g_free );
1685  }
1686 }
1687 
1689  const char *input,
1690  MenuFlags menu_flags,
1691  void ( *finalize )( RofiViewState * ) )
1692 {
1693  TICK ();
1695  state->menu_flags = menu_flags;
1696  state->sw = sw;
1697  state->selected_line = UINT32_MAX;
1698  state->retv = MENU_CANCEL;
1699  state->distance = NULL;
1700  state->quit = FALSE;
1701  state->skip_absorb = FALSE;
1702  //We want to filter on the first run.
1703  state->refilter = TRUE;
1704  state->finalize = finalize;
1705  state->mouse_seen = FALSE;
1706 
1707  // Request the lines to show.
1708  state->num_lines = mode_get_num_entries ( sw );
1709 
1710  TICK_N ( "Startup notification" );
1711 
1712  // Get active monitor size.
1713  TICK_N ( "Get active monitor" );
1714 
1715  state->main_window = box_create ( NULL, "window", ROFI_ORIENTATION_VERTICAL );
1716  // Get children.
1717  GList *list = rofi_theme_get_list ( WIDGET ( state->main_window ), "children", "mainbox" );
1718  for ( const GList *iter = list; iter != NULL; iter = g_list_next ( iter ) ) {
1719  rofi_view_add_widget ( state, WIDGET ( state->main_window ), (const char *) iter->data );
1720  }
1721  g_list_free_full ( list, g_free );
1722 
1723  if ( state->text && input ) {
1724  textbox_text ( state->text, input );
1725  textbox_cursor_end ( state->text );
1726  }
1727 
1728  state->overlay = textbox_create ( WIDGET ( state->main_window ), WIDGET_TYPE_TEXTBOX_TEXT, "overlay", TB_AUTOWIDTH | TB_AUTOHEIGHT, URGENT, "blaat", 0.5, 0 );
1729  widget_disable ( WIDGET ( state->overlay ) );
1730 
1731  // filtered list
1732  state->line_map = g_malloc0_n ( state->num_lines, sizeof ( unsigned int ) );
1733  state->distance = (int *) g_malloc0_n ( state->num_lines, sizeof ( int ) );
1734 
1736  // Need to resize otherwise calculated desired height is wrong.
1737  widget_resize ( WIDGET ( state->main_window ), state->width, 100 );
1738  // Only needed when window is fixed size.
1739  if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == MENU_NORMAL_WINDOW ) {
1741  }
1742 
1743  state->height = rofi_view_calculate_height ( state );
1744  // Move the window to the correct x,y position.
1746  rofi_view_window_update_size ( state );
1747 
1748  state->quit = FALSE;
1749  rofi_view_refilter ( state );
1750  rofi_view_update ( state, TRUE );
1751  xcb_map_window ( xcb->connection, CacheState.main_window );
1752  widget_queue_redraw ( WIDGET ( state->main_window ) );
1753  xcb_flush ( xcb->connection );
1754  if ( xcb->sncontext != NULL ) {
1755  sn_launchee_context_complete ( xcb->sncontext );
1756  }
1757  return state;
1758 }
1759 
1760 int rofi_view_error_dialog ( const char *msg, int markup )
1761 {
1763  state->retv = MENU_CANCEL;
1764  state->menu_flags = MENU_ERROR_DIALOG;
1765  state->finalize = process_result;
1766 
1767  state->main_window = box_create ( NULL, "window", ROFI_ORIENTATION_VERTICAL );
1768  box *box = box_create ( WIDGET ( state->main_window ), "error-message", ROFI_ORIENTATION_VERTICAL );
1769  box_add ( state->main_window, WIDGET ( box ), TRUE );
1770  state->text = textbox_create ( WIDGET ( box ), WIDGET_TYPE_TEXTBOX_TEXT, "textbox", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ),
1771  NORMAL, ( msg != NULL ) ? msg : "", 0, 0 );
1772  box_add ( box, WIDGET ( state->text ), TRUE );
1773 
1774  // Make sure we enable fixed num lines when in normal window mode.
1775  if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == MENU_NORMAL_WINDOW ) {
1777  }
1779  // Need to resize otherwise calculated desired height is wrong.
1780  widget_resize ( WIDGET ( state->main_window ), state->width, 100 );
1781  // resize window vertically to suit
1782  state->height = widget_get_desired_height ( WIDGET ( state->main_window ) );
1783 
1784  // Calculte window position.
1786 
1787  // Move the window to the correct x,y position.
1788  rofi_view_window_update_size ( state );
1789 
1790  // Display it.
1791  xcb_map_window ( xcb->connection, CacheState.main_window );
1792  widget_queue_redraw ( WIDGET ( state->main_window ) );
1793 
1794  if ( xcb->sncontext != NULL ) {
1795  sn_launchee_context_complete ( xcb->sncontext );
1796  }
1797 
1798  // Set it as current window.
1799  rofi_view_set_active ( state );
1800  return TRUE;
1801 }
1802 
1803 void rofi_view_hide ( void )
1804 {
1805  if ( CacheState.main_window != XCB_WINDOW_NONE ) {
1806  xcb_unmap_window ( xcb->connection, CacheState.main_window );
1808  }
1809 }
1810 
1812 {
1813  g_debug ( "Cleanup." );
1814  if ( CacheState.idle_timeout > 0 ) {
1815  g_source_remove ( CacheState.idle_timeout );
1816  CacheState.idle_timeout = 0;
1817  }
1818  if ( CacheState.repaint_source > 0 ) {
1819  g_source_remove ( CacheState.repaint_source );
1820  CacheState.repaint_source = 0;
1821  }
1822  if ( CacheState.fake_bg ) {
1823  cairo_surface_destroy ( CacheState.fake_bg );
1824  CacheState.fake_bg = NULL;
1825  }
1826  if ( CacheState.edit_draw ) {
1827  cairo_destroy ( CacheState.edit_draw );
1828  CacheState.edit_draw = NULL;
1829  }
1830  if ( CacheState.edit_surf ) {
1831  cairo_surface_destroy ( CacheState.edit_surf );
1832  CacheState.edit_surf = NULL;
1833  }
1834  if ( CacheState.main_window != XCB_WINDOW_NONE ) {
1835  g_debug ( "Unmapping and free'ing window" );
1836  xcb_unmap_window ( xcb->connection, CacheState.main_window );
1837  xcb_free_gc ( xcb->connection, CacheState.gc );
1838  xcb_free_pixmap ( xcb->connection, CacheState.edit_pixmap );
1839  xcb_destroy_window ( xcb->connection, CacheState.main_window );
1840  CacheState.main_window = XCB_WINDOW_NONE;
1841  }
1842  if ( map != XCB_COLORMAP_NONE ) {
1843  xcb_free_colormap ( xcb->connection, map );
1844  map = XCB_COLORMAP_NONE;
1845  }
1846  xcb_flush ( xcb->connection );
1847  g_assert ( g_queue_is_empty ( &( CacheState.views ) ) );
1848 }
1850 {
1851  TICK_N ( "Setup Threadpool, start" );
1852  if ( config.threads == 0 ) {
1853  config.threads = 1;
1854  long procs = sysconf ( _SC_NPROCESSORS_CONF );
1855  if ( procs > 0 ) {
1856  config.threads = MIN ( procs, 128l );
1857  }
1858  }
1859  // Create thread pool
1860  GError *error = NULL;
1861  tpool = g_thread_pool_new ( rofi_view_call_thread, NULL, config.threads, FALSE, &error );
1862  if ( error == NULL ) {
1863  // Idle threads should stick around for a max of 60 seconds.
1864  g_thread_pool_set_max_idle_time ( 60000 );
1865  // We are allowed to have
1866  g_thread_pool_set_max_threads ( tpool, config.threads, &error );
1867  }
1868  // If error occurred during setup of pool, tell user and exit.
1869  if ( error != NULL ) {
1870  g_warning ( "Failed to setup thread pool: '%s'", error->message );
1871  g_error_free ( error );
1872  exit ( EXIT_FAILURE );
1873  }
1874  TICK_N ( "Setup Threadpool, done" );
1875 }
1877 {
1878  if ( tpool ) {
1879  g_thread_pool_free ( tpool, TRUE, TRUE );
1880  tpool = NULL;
1881  }
1882 }
1884 {
1885  return state->sw;
1886 }
1887 
1888 void rofi_view_set_overlay ( RofiViewState *state, const char *text )
1889 {
1890  if ( state->overlay == NULL || state->list_view == NULL ) {
1891  return;
1892  }
1893  if ( text == NULL ) {
1894  widget_disable ( WIDGET ( state->overlay ) );
1895  return;
1896  }
1897  widget_enable ( WIDGET ( state->overlay ) );
1898  textbox_text ( state->overlay, text );
1899  int x_offset = widget_get_width ( WIDGET ( state->list_view ) );
1900  // Within padding of window.
1901  x_offset += widget_get_absolute_xpos ( WIDGET ( state->list_view ) );
1902  x_offset -= widget_get_width ( WIDGET ( state->overlay ) );
1903  // Within the border of widget.
1904  int top_offset = widget_get_absolute_ypos ( WIDGET ( state->list_view ) );
1905  widget_move ( WIDGET ( state->overlay ), x_offset, top_offset );
1906  // We want to queue a repaint.
1908 }
1909 
1911 {
1912  if ( state->text ) {
1913  textbox_text ( state->text, "" );
1914  rofi_view_set_selected_line ( state, 0 );
1915  }
1916 }
1917 
1919 {
1920  state->sw = mode;
1921  // Update prompt;
1922  if ( state->prompt ) {
1923  rofi_view_update_prompt ( state );
1924  }
1925  if ( config.sidebar_mode && state->sidebar_bar ) {
1926  for ( unsigned int j = 0; j < state->num_modi; j++ ) {
1927  const Mode * mode = rofi_get_mode ( j );
1928  textbox_font ( state->modi[j], ( mode == state->sw ) ? HIGHLIGHT : NORMAL );
1929  }
1930  }
1931  rofi_view_restart ( state );
1932  state->reload = TRUE;
1933  state->refilter = TRUE;
1934  rofi_view_refilter ( state );
1935  rofi_view_update ( state, TRUE );
1936 }
1937 
1938 xcb_window_t rofi_view_get_window ( void )
1939 {
1940  return CacheState.main_window;
1941 }
void rofi_view_cleanup()
Definition: view.c:1811
xcb_depth_t * depth
Definition: xcb.c:92
unsigned int * line_map
Definition: view-internal.h:75
void listview_set_selected(listview *lv, unsigned int selected)
Definition: listview.c:410
unsigned int levenshtein(const char *needle, const glong needlelen, const char *haystack, const glong haystacklen)
Definition: helper.c:720
static const int loc_transtable[9]
Definition: view.c:264
Definition: box.c:41
guint idle_timeout
Definition: view.c:114
MenuReturn
Definition: mode.h:66
void textbox_cursor_end(textbox *tb)
Definition: textbox.c:597
GList * rofi_theme_get_list(const widget *widget, const char *property, const char *defaults)
Definition: theme.c:693
void rofi_view_get_current_monitor(int *width, int *height)
Definition: view.c:135
textbox ** modi
cairo_surface_t * fake_bg
Definition: view.c:96
MouseBindingMouseDefaultAction
Definition: keyb.h:166
unsigned int auto_select
Definition: settings.h:134
void rofi_quit_main_loop(void)
Definition: rofi.c:631
unsigned int fake_transparency
Definition: settings.h:158
void rofi_view_finalize(RofiViewState *state)
Definition: view.c:1133
gboolean widget_need_redraw(widget *wid)
Definition: widget.c:445
BindingsScope
Definition: keyb.h:42
listview * listview_create(widget *parent, const char *name, listview_update_callback cb, void *udata, unsigned int eh, gboolean reverse)
Definition: listview.c:523
void display_early_cleanup(void)
Definition: xcb.c:1319
int mode_token_match(const Mode *mode, rofi_int_matcher **tokens, unsigned int selected_line)
Definition: mode.c:105
void rofi_view_clear_input(RofiViewState *state)
Definition: view.c:1910
WindowLocation location
Definition: settings.h:100
unsigned int case_sensitive
Definition: settings.h:124
static void rofi_view_nav_last(RofiViewState *state)
Definition: view.c:924
Definition: mode.h:69
void x11_disable_decoration(xcb_window_t window)
Definition: xcb.c:1354
void textbox_text(textbox *tb, const char *text)
Definition: textbox.c:304
static void update_callback(textbox *t, unsigned int index, void *udata, TextBoxFontType type, gboolean full)
Definition: view.c:934
struct _thread_state_view thread_state_view
const char * pattern
Definition: view.c:581
void rofi_view_reload(void)
Definition: view.c:425
unsigned int sidebar_mode
Definition: settings.h:130
PangoAttrList * helper_token_match_get_pango_attr(RofiHighlightColorStyle th, rofi_int_matcher **tokens, const char *input, PangoAttrList *retv)
Definition: helper.c:411
Definition: keyb.h:106
void rofi_view_temp_configure_notify(RofiViewState *state, xcb_configure_notify_event_t *xce)
Definition: view.c:1442
void listview_nav_up(listview *lv)
Definition: listview.c:596
Definition: keyb.h:99
Definition: xcb.h:99
void listview_nav_page_prev(listview *lv)
Definition: listview.c:711
void rofi_view_workers_finalize(void)
Definition: view.c:1876
void textbox_icon(textbox *tb, cairo_surface_t *icon)
Definition: textbox.c:336
void rofi_view_queue_redraw(void)
Definition: view.c:432
unsigned int menu_lines
Definition: settings.h:65
xcb_window_t xcb_stuff_get_root_window(void)
Definition: xcb.c:1314
Mode * rofi_view_get_mode(RofiViewState *state)
Definition: view.c:1883
double textbox_get_estimated_char_width(void)
Definition: textbox.c:907
void listview_set_num_elements(listview *lv, unsigned int rows)
Definition: listview.c:391
KeyBindingAction prev_action
Definition: view-internal.h:83
int widget_padding_get_padding_width(const widget *wid)
Definition: widget.c:559
cairo_surface_t * mode_get_icon(const Mode *mode, unsigned int selected_line, int height)
Definition: mode.c:72
unsigned int start
Definition: view.c:574
Definition: keyb.h:108
static void rofi_view_update_prompt(RofiViewState *state)
Definition: view.c:244
xcb_stuff * xcb
Definition: xcb.c:87
char * mode_preprocess_input(Mode *mode, const char *input)
Definition: mode.c:157
const char * rofi_view_get_user_input(const RofiViewState *state)
Definition: view.c:538
void __create_window(MenuFlags menu_flags)
Definition: view.c:681
const char * rofi_theme_get_string(const widget *widget, const char *property, const char *def)
Definition: theme.c:605
unsigned int sort
Definition: settings.h:112
static void rofi_view_setup_fake_transparency(const char *const fake_background)
Definition: view.c:631
unsigned int scroll_method
Definition: settings.h:163
void listview_set_scroll_type(listview *lv, ScrollType type)
Definition: listview.c:780
int widget_get_width(widget *widget)
Definition: widget.c:388
void widget_free(widget *wid)
Definition: widget.c:365
Definition: keyb.h:102
GMutex * mutex
Definition: view.c:567
Definition: keyb.h:98
thread_state st
Definition: view.c:562
Definition: keyb.h:101
static void rofi_view_nav_first(RofiViewState *state)
Definition: view.c:913
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:1507
void rofi_view_set_selected_line(RofiViewState *state, unsigned int selected_line)
Definition: view.c:475
#define color_green
Definition: rofi.h:96
Definition: keyb.h:117
unsigned int num_lines
Definition: view-internal.h:77
void rofi_view_temp_click_to_exit(RofiViewState *state, xcb_window_t target)
Definition: view.c:1473
void textbox_font(textbox *tb, TextBoxFontType tbft)
Definition: textbox.c:230
textbox * prompt
Definition: view-internal.h:57
Definition: keyb.h:109
char * text
Definition: textbox.h:55
int rofi_theme_get_boolean(const widget *widget, const char *property, int def)
Definition: theme.c:572
RofiViewState * rofi_view_get_active(void)
Definition: view.c:447
static void rofi_view_refilter(RofiViewState *state)
Definition: view.c:1032
void widget_set_trigger_action_handler(widget *wid, widget_trigger_action_cb cb, void *cb_data)
Definition: widget.c:479
RofiDistance rofi_theme_get_distance(const widget *widget, const char *property, int def)
Definition: theme.c:550
void widget_draw(widget *widget, cairo_t *d)
Definition: widget.c:142
unsigned int rofi_get_num_enabled_modi(void)
Definition: rofi.c:128
textbox * textbox_create(widget *parent, WidgetType type, const char *name, TextboxFlags flags, TextBoxFontType tbft, const char *text, double xalign, double yalign)
Definition: textbox.c:166
void widget_disable(widget *widget)
Definition: widget.c:133
cairo_surface_t * x11_helper_get_bg_surface(void)
Definition: xcb.c:141
static void filter_elements(thread_state *ts, G_GNUC_UNUSED gpointer user_data)
Definition: view.c:597
MenuReturn rofi_view_get_return_value(const RofiViewState *state)
Definition: view.c:513
int fake_bgrel
Definition: view.c:106
void listview_nav_right(listview *lv)
Definition: listview.c:635
xcb_ewmh_connection_t ewmh
Definition: xcb-internal.h:48
char * fake_background
Definition: settings.h:166
void rofi_view_workers_initialize(void)
Definition: view.c:1849
void listview_set_mouse_activated_cb(listview *lv, listview_mouse_activated_cb cb, void *udata)
Definition: listview.c:787
void listview_set_num_lines(listview *lv, unsigned int num_lines)
Definition: listview.c:800
int dpi
Definition: settings.h:160
void rofi_view_frame_callback(void)
Definition: view.c:1483
rofi_int_matcher ** helper_tokenize(const char *input, int case_sensitive)
Definition: helper.c:257
xcb_pixmap_t edit_pixmap
Definition: view.c:100
void rofi_view_free(RofiViewState *state)
Definition: view.c:491
Definition: keyb.h:69
int y_offset
Definition: settings.h:104
RofiViewState * current_active_menu
Definition: view.c:86
void rofi_view_handle_mouse_motion(RofiViewState *state, gint x, gint y)
Definition: view.c:1405
textbox * mesg_tb
Definition: view-internal.h:70
void widget_move(widget *widget, short x, short y)
Definition: widget.c:100
static void rofi_view_nav_row_select(RofiViewState *state)
Definition: view.c:892
RofiHighlightColorStyle rofi_theme_get_highlight(widget *widget, const char *property, RofiHighlightColorStyle th)
Definition: theme.c:719
Definition: icon.c:40
TextboxFlags
Definition: textbox.h:79
void widget_xy_to_relative(widget *widget, gint *x, gint *y)
Definition: widget.c:413
void rofi_view_hide(void)
Definition: view.c:1803
xcb_window_t rofi_view_get_window(void)
Definition: view.c:1938
void widget_resize(widget *widget, short w, short h)
Definition: widget.c:84
unsigned long long count
Definition: view.c:116
xcb_window_t main_window
Definition: view.c:94
void rofi_view_update(RofiViewState *state, gboolean qr)
Definition: view.c:978
WidgetTriggerActionResult widget_trigger_action(widget *wid, guint action, gint x, gint y)
Definition: widget.c:471
struct RofiViewState::@4 mouse
unsigned int rofi_view_get_next_position(const RofiViewState *state)
Definition: view.c:523
int menu_width
Definition: settings.h:63
static void rofi_view_listview_mouse_activated_cb(listview *lv, gboolean custom, void *udata)
Definition: view.c:1536
void widget_queue_redraw(widget *wid)
Definition: widget.c:432
int x_offset
Definition: settings.h:106
Definition: keyb.h:111
Definition: keyb.h:113
MenuReturn retv
Definition: view-internal.h:94
Definition: keyb.h:115
unsigned int listview_get_selected(listview *lv)
Definition: listview.c:402
unsigned int * acount
Definition: view.c:569
int textbox_keybinding(textbox *tb, KeyBindingAction action)
Definition: textbox.c:734
icon * icon_create(widget *parent, const char *name)
Definition: icon.c:130
void rofi_view_handle_text(RofiViewState *state, char *text)
Definition: view.c:1398
const char * textbox_get_visible_text(const textbox *tb)
Definition: textbox.c:281
unsigned int rofi_view_get_completed(const RofiViewState *state)
Definition: view.c:533
void rofi_view_set_active(RofiViewState *state)
Definition: view.c:452
guint repaint_source
Definition: view.c:118
container * mesg_box
Definition: view-internal.h:68
int rofi_view_error_dialog(const char *msg, int markup)
Definition: view.c:1760
textbox * text
Definition: view-internal.h:59
#define TICK()
Definition: timings.h:89
box * box_create(widget *parent, const char *name, RofiOrientation type)
Definition: box.c:336
gboolean rofi_view_trigger_action(RofiViewState *state, BindingsScope scope, guint action)
Definition: view.c:1360
static void rofi_view_nav_row_tab(RofiViewState *state)
Definition: view.c:867
TextBoxFontType
Definition: textbox.h:93
static char * get_matching_state(void)
Definition: view.c:144
static void rofi_view_window_update_size(RofiViewState *state)
Definition: view.c:375
char * menu_font
Definition: settings.h:69
cairo_t * edit_draw
Definition: view.c:104
Definition: textbox.h:96
GQueue views
Definition: view.c:110
void listview_set_multi_select(listview *lv, gboolean enable)
Definition: listview.c:794
GThreadPool * tpool
Definition: view.c:83
static void rofi_view_calculate_window_position(RofiViewState *state)
Definition: view.c:275
Definition: textbox.h:98
char * rofi_expand_path(const char *input)
Definition: helper.c:687
gboolean show_match
Definition: settings.h:171
xcb_connection_t * connection
Definition: xcb-internal.h:47
KeyBindingAction
Definition: keyb.h:58
xcb_colormap_t map
Definition: xcb.c:94
void process_result(RofiViewState *state)
Definition: rofi.c:198
void listview_set_fixed_num_lines(listview *lv)
Definition: listview.c:828
SortingMethod sorting_method_enum
Definition: settings.h:114
Definition: keyb.h:94
MenuFlags flags
Definition: view.c:108
void rofi_view_switch_mode(RofiViewState *state, Mode *mode)
Definition: view.c:1918
unsigned int mode_get_num_entries(const Mode *mode)
Definition: mode.c:56
void(* finalize)(struct RofiViewState *state)
int distance_get_pixel(RofiDistance d, RofiOrientation ori)
Definition: theme.c:736
static int rofi_view_calculate_height(RofiViewState *state)
Definition: view.c:1490
char * mode_get_display_value(const Mode *mode, unsigned int selected_line, int *state, GList **attribute_list, int get_entry)
Definition: mode.c:63
textbox * case_indicator
Definition: view-internal.h:61
int monitor_active(workarea *mon)
Definition: xcb.c:681
gboolean fullscreen
Definition: view.c:120
xcb_visualtype_t * visual
Definition: xcb.c:93
unsigned int filtered_lines
Definition: view-internal.h:80
int element_height
Definition: settings.h:128
void window_set_atom_prop(xcb_window_t w, xcb_atom_t prop, xcb_atom_t *atoms, int count)
Definition: xcb.c:178
WidgetTriggerActionResult
Definition: widget.h:77
void listview_nav_page_next(listview *lv)
Definition: listview.c:723
GCond * cond
Definition: view.c:565
void widget_enable(widget *widget)
Definition: widget.c:124
PangoAttrList * textbox_get_pango_attributes(textbox *tb)
Definition: textbox.c:288
static void rofi_view_add_widget(RofiViewState *state, widget *parent_widget, const char *name)
Definition: view.c:1549
void rofi_view_restart(RofiViewState *state)
Definition: view.c:441
static void rofi_view_reload_message_bar(RofiViewState *state)
Definition: view.c:398
xcb_screen_t * screen
Definition: xcb-internal.h:49
#define WIDGET(a)
Definition: widget.h:115
void helper_tokenize_free(rofi_int_matcher **tokens)
Definition: helper.c:156
void(* callback)(struct _thread_state *t, gpointer data)
Definition: rofi-types.h:244
void rofi_view_maybe_update(RofiViewState *state)
Definition: view.c:1415
listview * list_view
Definition: view-internal.h:64
int rofi_theme_get_position(const widget *widget, const char *property, int def)
Definition: theme.c:517
textbox * overlay
Definition: view-internal.h:66
Definition: mode.h:73
static gboolean rofi_view_reload_idle(G_GNUC_UNUSED gpointer data)
Definition: view.c:414
SnLauncheeContext * sncontext
Definition: xcb-internal.h:52
const Mode * rofi_get_mode(unsigned int index)
Definition: rofi.c:133
void listview_set_max_lines(listview *lv, unsigned int max_lines)
Definition: listview.c:814
char * mode_get_message(const Mode *mode)
Definition: mode.c:164
const char * mode_get_display_name(const Mode *mode)
Definition: mode.c:143
rofi_int_matcher ** tokens
unsigned int rofi_view_get_selected_line(const RofiViewState *state)
Definition: view.c:518
Settings config
unsigned int num_modi
static void rofi_view_calculate_window_width(RofiViewState *state)
Definition: view.c:838
void rofi_view_set_overlay(RofiViewState *state, const char *text)
Definition: view.c:1888
int widget_get_absolute_xpos(widget *wid)
Definition: widget.c:588
gboolean widget_motion_notify(widget *wid, gint x, gint y)
Definition: widget.c:488
int widget_get_absolute_ypos(widget *wid)
Definition: widget.c:599
int widget_get_desired_height(widget *wid)
Definition: widget.c:567
unsigned int threads
Definition: settings.h:162
widget * widget_find_mouse_target(widget *wid, WidgetType type, gint x, gint y)
Definition: widget.c:453
int textbox_get_font_height(const textbox *tb)
Definition: textbox.c:880
gboolean listview_get_fixed_num_lines(listview *lv)
Definition: listview.c:821
void listview_nav_left(listview *lv)
Definition: listview.c:621
#define TICK_N(a)
Definition: timings.h:94
Definition: keyb.h:110
unsigned int count
Definition: view.c:578
static gboolean rofi_view_repaint(G_GNUC_UNUSED void *data)
Definition: view.c:226
xcb_gcontext_t gc
Definition: view.c:98
static void rofi_view_call_thread(gpointer data, gpointer user_data)
Definition: view.c:591
void container_add(container *container, widget *child)
Definition: container.c:72
unsigned int selected_line
Definition: view-internal.h:92
#define color_reset
Definition: rofi.h:90
static RofiViewState * __rofi_view_state_create(void)
Definition: view.c:551
void listview_nav_down(listview *lv)
Definition: listview.c:608
cairo_surface_t * edit_surf
Definition: view.c:102
void textbox_set_pango_attributes(textbox *tb, PangoAttrList *list)
Definition: textbox.c:295
Definition: keyb.h:100
int rofi_theme_get_integer(const widget *widget, const char *property, int def)
Definition: theme.c:534
Definition: keyb.h:114
unsigned int fullscreen
Definition: settings.h:156
void rofi_capture_screenshot(void)
Definition: view.c:177
Definition: keyb.h:112
static void rofi_view_trigger_global_action(KeyBindingAction action)
Definition: view.c:1140
Definition: keyb.h:116
void box_add(box *box, widget *child, gboolean expand)
Definition: box.c:284
MenuFlags menu_flags
RofiViewState * rofi_view_create(Mode *sw, const char *input, MenuFlags menu_flags, void(*finalize)(RofiViewState *))
Definition: view.c:1688
MenuFlags
Definition: view.h:43
char * mode_get_completion(const Mode *mode, unsigned int selected_line)
Definition: mode.c:84
RofiViewState * state
Definition: view.c:572
unsigned int stop
Definition: view.c:576
workarea mon
Definition: view.c:112
xcb_atom_t netatoms[NUM_NETATOMS]
Definition: xcb.c:99
static void _rofi_view_reload_row(RofiViewState *state)
Definition: view.c:1021
widget * motion_target
static int lev_sort(const void *p1, const void *p2, void *arg)
Definition: view.c:165
gboolean textbox_append_text(textbox *tb, const char *pad, const int pad_len)
Definition: textbox.c:798
int rofi_scorer_fuzzy_evaluate(const char *pattern, glong plen, const char *str, glong slen)
Definition: helper.c:909
container * container_create(widget *parent, const char *name)
Definition: container.c:104
cairo_surface_t * x11_helper_get_screenshot_surface(void)
Definition: xcb.c:106
gboolean helper_validate_font(PangoFontDescription *pfd, const char *font)
Definition: helper.c:557
void textbox_set_pango_context(const char *font, PangoContext *p)
Definition: textbox.c:837
struct @0 CacheState