1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-07-31 21:59:25 -04:00

Don't recreate every string everytime.

This commit is contained in:
Dave Davenport 2017-02-03 20:49:16 +01:00
parent 2fe22cb7e2
commit 8ef7b4b794
9 changed files with 89 additions and 88 deletions

View file

@ -168,7 +168,7 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned
} }
if ( switcher >= 0 ) { if ( switcher >= 0 ) {
if ( eob[0] == ' ' ) { if ( eob[0] == ' ' ) {
char *n = eob+1; char *n = eob + 1;
return mode_result ( pd->switchers[switcher], mretv, &n, return mode_result ( pd->switchers[switcher], mretv, &n,
selected_line - pd->starts[switcher] ); selected_line - pd->starts[switcher] );
} }
@ -255,7 +255,7 @@ static char * combi_preprocess_input ( Mode *sw, const char *input )
if ( eob[0] == '\0' || eob[1] == '\0' ) { if ( eob[0] == '\0' || eob[1] == '\0' ) {
return NULL; return NULL;
} }
return g_strdup ( eob+1 ); return g_strdup ( eob + 1 );
} }
} }
} }

View file

@ -158,7 +158,7 @@ static void async_read_callback ( GObject *source_object, GAsyncResult *res, gpo
} }
if ( !g_cancellable_is_cancelled ( pd->cancel ) ) { if ( !g_cancellable_is_cancelled ( pd->cancel ) ) {
// Hack, don't use get active. // Hack, don't use get active.
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Clearing overlay"); g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Clearing overlay" );
rofi_view_set_overlay ( rofi_view_get_active (), NULL ); rofi_view_set_overlay ( rofi_view_get_active (), NULL );
g_input_stream_close_async ( G_INPUT_STREAM ( stream ), G_PRIORITY_LOW, pd->cancel, async_close_callback, pd ); g_input_stream_close_async ( G_INPUT_STREAM ( stream ), G_PRIORITY_LOW, pd->cancel, async_close_callback, pd );
} }
@ -171,7 +171,7 @@ static void async_read_cancel ( G_GNUC_UNUSED GCancellable *cancel, G_GNUC_UNUSE
static int get_dmenu_async ( DmenuModePrivateData *pd, int sync_pre_read ) static int get_dmenu_async ( DmenuModePrivateData *pd, int sync_pre_read )
{ {
while(sync_pre_read-- ){ while ( sync_pre_read-- ) {
gsize len = 0; gsize len = 0;
char *data = g_data_input_stream_read_upto ( pd->data_input_stream, &( pd->separator ), 1, &len, NULL, NULL ); char *data = g_data_input_stream_read_upto ( pd->data_input_stream, &( pd->separator ), 1, &len, NULL, NULL );
if ( data == NULL ) { if ( data == NULL ) {
@ -636,7 +636,7 @@ int dmenu_switcher_dialog ( void )
} }
if ( async ) { if ( async ) {
unsigned int pre_read = 25; unsigned int pre_read = 25;
find_arg_uint("-async-pre-read", &pre_read); find_arg_uint ( "-async-pre-read", &pre_read );
async = get_dmenu_async ( pd, pre_read ); async = get_dmenu_async ( pd, pre_read );
} }
else { else {
@ -728,5 +728,5 @@ void print_dmenu_options ( void )
print_help_msg ( "-sep", "[char]", "Element separator.", "'\\n'", is_term ); print_help_msg ( "-sep", "[char]", "Element separator.", "'\\n'", is_term );
print_help_msg ( "-input", "[filename]", "Read input from file instead from standard input.", NULL, is_term ); print_help_msg ( "-input", "[filename]", "Read input from file instead from standard input.", NULL, is_term );
print_help_msg ( "-sync", "", "Force dmenu to first read all input data, then show dialog.", NULL, is_term ); print_help_msg ( "-sync", "", "Force dmenu to first read all input data, then show dialog.", NULL, is_term );
print_help_msg ( "-async-pre-read", "[number]", "Read several entries blocking before switching to async mode", "25", is_term); print_help_msg ( "-async-pre-read", "[number]", "Read several entries blocking before switching to async mode", "25", is_term );
} }

View file

@ -288,7 +288,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
} }
size_t nl = ( ( pd->cmd_list_length ) + 1 ); size_t nl = ( ( pd->cmd_list_length ) + 1 );
if ( nl >= pd->cmd_list_length_actual ) { if ( nl >= pd->cmd_list_length_actual ) {
pd->cmd_list_length_actual+=256; pd->cmd_list_length_actual += 256;
pd->entry_list = g_realloc ( pd->entry_list, pd->cmd_list_length_actual * sizeof ( *( pd->entry_list ) ) ); pd->entry_list = g_realloc ( pd->entry_list, pd->cmd_list_length_actual * sizeof ( *( pd->entry_list ) ) );
} }
pd->entry_list[pd->cmd_list_length].root = g_strdup ( root ); pd->entry_list[pd->cmd_list_length].root = g_strdup ( root );

View file

@ -530,9 +530,9 @@ gboolean helper_validate_font ( PangoFontDescription *pfd, const char *font )
{ {
const char *fam = pango_font_description_get_family ( pfd ); const char *fam = pango_font_description_get_family ( pfd );
int size = pango_font_description_get_size ( pfd ); int size = pango_font_description_get_size ( pfd );
if ( fam == NULL || size == 0 ){ if ( fam == NULL || size == 0 ) {
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Pango failed to parse font: '%s'", font); g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Pango failed to parse font: '%s'", font );
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Got family: <b>%s</b> at size: <b>%d</b>", fam?fam:"{unknown}", size); g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Got family: <b>%s</b> at size: <b>%d</b>", fam ? fam : "{unknown}", size );
return FALSE; return FALSE;
} }
return TRUE; return TRUE;

View file

@ -642,11 +642,11 @@ void __create_window ( MenuFlags menu_flags )
printf ( "xcb_create_window() failed error=0x%x\n", error->error_code ); printf ( "xcb_create_window() failed error=0x%x\n", error->error_code );
exit ( EXIT_FAILURE ); exit ( EXIT_FAILURE );
} }
TICK_N ( "xcb create window"); TICK_N ( "xcb create window" );
CacheState.gc = xcb_generate_id ( xcb->connection ); CacheState.gc = xcb_generate_id ( xcb->connection );
xcb_create_gc ( xcb->connection, CacheState.gc, box, 0, 0 ); xcb_create_gc ( xcb->connection, CacheState.gc, box, 0, 0 );
TICK_N ( "xcb create gc"); TICK_N ( "xcb create gc" );
// Create a drawable. // Create a drawable.
CacheState.edit_pixmap = xcb_generate_id ( xcb->connection ); CacheState.edit_pixmap = xcb_generate_id ( xcb->connection );
xcb_create_pixmap ( xcb->connection, depth->depth, xcb_create_pixmap ( xcb->connection, depth->depth,
@ -655,7 +655,7 @@ void __create_window ( MenuFlags menu_flags )
CacheState.edit_surf = cairo_xcb_surface_create ( xcb->connection, CacheState.edit_pixmap, visual, 200, 100 ); CacheState.edit_surf = cairo_xcb_surface_create ( xcb->connection, CacheState.edit_pixmap, visual, 200, 100 );
CacheState.edit_draw = cairo_create ( CacheState.edit_surf ); CacheState.edit_draw = cairo_create ( CacheState.edit_surf );
TICK_N ( "create cairo surface"); TICK_N ( "create cairo surface" );
// Set up pango context. // Set up pango context.
cairo_font_options_t *fo = cairo_font_options_create (); cairo_font_options_t *fo = cairo_font_options_create ();
// Take font description from xlib surface // Take font description from xlib surface
@ -664,7 +664,7 @@ void __create_window ( MenuFlags menu_flags )
PangoContext *p = pango_cairo_create_context ( CacheState.edit_draw ); PangoContext *p = pango_cairo_create_context ( CacheState.edit_draw );
// Set the font options from the xlib surface // Set the font options from the xlib surface
pango_cairo_context_set_font_options ( p, fo ); pango_cairo_context_set_font_options ( p, fo );
TICK_N ( "pango cairo font setup"); TICK_N ( "pango cairo font setup" );
CacheState.main_window = box; CacheState.main_window = box;
CacheState.flags = menu_flags; CacheState.flags = menu_flags;
@ -694,14 +694,14 @@ void __create_window ( MenuFlags menu_flags )
char *font = rofi_theme_get_string ( WIDGET ( win ), "font", config.menu_font ); char *font = rofi_theme_get_string ( WIDGET ( win ), "font", config.menu_font );
if ( font ) { if ( font ) {
PangoFontDescription *pfd = pango_font_description_from_string ( font ); PangoFontDescription *pfd = pango_font_description_from_string ( font );
if ( helper_validate_font(pfd, font)) { if ( helper_validate_font ( pfd, font ) ) {
pango_context_set_font_description ( p, pfd ); pango_context_set_font_description ( p, pfd );
} }
pango_font_description_free ( pfd ); pango_font_description_free ( pfd );
} }
PangoLanguage *l = pango_language_get_default(); PangoLanguage *l = pango_language_get_default ();
pango_context_set_language ( p, l ); pango_context_set_language ( p, l );
TICK_N ( "configure font"); TICK_N ( "configure font" );
// Tell textbox to use this context. // Tell textbox to use this context.
textbox_set_pango_context ( font, p ); textbox_set_pango_context ( font, p );
@ -709,7 +709,7 @@ void __create_window ( MenuFlags menu_flags )
g_object_unref ( p ); g_object_unref ( p );
cairo_font_options_destroy ( fo ); cairo_font_options_destroy ( fo );
TICK_N ( "textbox setup"); TICK_N ( "textbox setup" );
// // make it an unmanaged window // // make it an unmanaged window
if ( ( ( menu_flags & MENU_NORMAL_WINDOW ) == 0 ) ) { if ( ( ( menu_flags & MENU_NORMAL_WINDOW ) == 0 ) ) {
window_set_atom_prop ( box, xcb->ewmh._NET_WM_STATE, &( xcb->ewmh._NET_WM_STATE_ABOVE ), 1 ); window_set_atom_prop ( box, xcb->ewmh._NET_WM_STATE, &( xcb->ewmh._NET_WM_STATE_ABOVE ), 1 );
@ -721,7 +721,7 @@ void __create_window ( MenuFlags menu_flags )
x11_disable_decoration ( box ); x11_disable_decoration ( box );
} }
TICK_N ( "setup window attributes"); TICK_N ( "setup window attributes" );
CacheState.fullscreen = rofi_theme_get_boolean ( WIDGET ( win ), "fullscreen", config.fullscreen ); CacheState.fullscreen = rofi_theme_get_boolean ( WIDGET ( win ), "fullscreen", config.fullscreen );
if ( CacheState.fullscreen ) { if ( CacheState.fullscreen ) {
xcb_atom_t atoms[] = { xcb_atom_t atoms[] = {
@ -731,15 +731,15 @@ void __create_window ( MenuFlags menu_flags )
window_set_atom_prop ( box, xcb->ewmh._NET_WM_STATE, atoms, sizeof ( atoms ) / sizeof ( xcb_atom_t ) ); window_set_atom_prop ( box, xcb->ewmh._NET_WM_STATE, atoms, sizeof ( atoms ) / sizeof ( xcb_atom_t ) );
} }
TICK_N ( "setup window fullscreen"); TICK_N ( "setup window fullscreen" );
// Set the WM_NAME // Set the WM_NAME
xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, box, xcb->ewmh._NET_WM_NAME, xcb->ewmh.UTF8_STRING, 8, 4, "rofi" ); xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, box, xcb->ewmh._NET_WM_NAME, xcb->ewmh.UTF8_STRING, 8, 4, "rofi" );
xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, box, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, 4, "rofi" ); xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, box, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, 4, "rofi" );
const char wm_class_name[] = "rofi\0Rofi"; const char wm_class_name[] = "rofi\0Rofi";
xcb_icccm_set_wm_class ( xcb->connection, box, sizeof(wm_class_name),wm_class_name); xcb_icccm_set_wm_class ( xcb->connection, box, sizeof ( wm_class_name ), wm_class_name );
TICK_N ( "setup window name and class"); TICK_N ( "setup window name and class" );
char *transparency = rofi_theme_get_string ( WIDGET ( win ), "transparency", NULL ); char *transparency = rofi_theme_get_string ( WIDGET ( win ), "transparency", NULL );
if ( transparency == NULL && config.fake_transparency ) { if ( transparency == NULL && config.fake_transparency ) {
transparency = config.fake_background; transparency = config.fake_background;
@ -750,9 +750,9 @@ void __create_window ( MenuFlags menu_flags )
if ( xcb->sncontext != NULL ) { if ( xcb->sncontext != NULL ) {
sn_launchee_context_setup_window ( xcb->sncontext, CacheState.main_window ); sn_launchee_context_setup_window ( xcb->sncontext, CacheState.main_window );
} }
TICK_N ( "setup startup notification"); TICK_N ( "setup startup notification" );
widget_free ( WIDGET ( win ) ); widget_free ( WIDGET ( win ) );
TICK_N ( "done"); TICK_N ( "done" );
} }
/** /**
@ -1598,7 +1598,7 @@ RofiViewState *rofi_view_create ( Mode *sw,
} }
state->overlay = textbox_create ( "window.overlay", TB_AUTOWIDTH | TB_AUTOHEIGHT, URGENT, "blaat" ); state->overlay = textbox_create ( "window.overlay", TB_AUTOWIDTH | TB_AUTOHEIGHT, URGENT, "blaat" );
state->overlay->widget.parent = WIDGET(state->main_window); state->overlay->widget.parent = WIDGET ( state->main_window );
widget_disable ( WIDGET ( state->overlay ) ); widget_disable ( WIDGET ( state->overlay ) );
state->list_view = listview_create ( "window.mainbox.listview", update_callback, state, config.element_height, end ); state->list_view = listview_create ( "window.mainbox.listview", update_callback, state, config.element_height, end );

View file

@ -237,12 +237,12 @@ static void listview_recompute_elements ( listview *lv )
} }
lv->boxes = g_realloc ( lv->boxes, newne * sizeof ( textbox* ) ); lv->boxes = g_realloc ( lv->boxes, newne * sizeof ( textbox* ) );
if ( newne > 0 ) { if ( newne > 0 ) {
char *name = g_strjoin ( ".", lv->listview_name, "element", NULL );
for ( unsigned int i = lv->cur_elements; i < newne; i++ ) { for ( unsigned int i = lv->cur_elements; i < newne; i++ ) {
TextboxFlags flags = ( lv->multi_select ) ? TB_INDICATOR : 0; TextboxFlags flags = ( lv->multi_select ) ? TB_INDICATOR : 0;
char *name = g_strjoin ( ".", lv->listview_name, "element", NULL );
lv->boxes[i] = textbox_create ( name, flags, NORMAL, "" ); lv->boxes[i] = textbox_create ( name, flags, NORMAL, "" );
g_free ( name );
} }
g_free ( name );
} }
lv->rchanged = TRUE; lv->rchanged = TRUE;
lv->cur_elements = newne; lv->cur_elements = newne;

View file

@ -59,7 +59,8 @@ static PangoContext *p_context = NULL;
static PangoFontMetrics *p_metrics = NULL; static PangoFontMetrics *p_metrics = NULL;
/** Cache to hold font descriptions. This it to avoid having to lookup each time. */ /** Cache to hold font descriptions. This it to avoid having to lookup each time. */
typedef struct TBFontConfig { typedef struct TBFontConfig
{
/** Font description */ /** Font description */
PangoFontDescription *pfd; PangoFontDescription *pfd;
/** Font metrics */ /** Font metrics */
@ -121,17 +122,18 @@ textbox* textbox_create ( const char *name, TextboxFlags flags, TextBoxFontType
tb->metrics = p_metrics; tb->metrics = p_metrics;
char * font = rofi_theme_get_string ( WIDGET ( tb ), "font", NULL ); char * font = rofi_theme_get_string ( WIDGET ( tb ), "font", NULL );
if ( font ){ if ( font ) {
TBFontConfig *tbfc = g_hash_table_lookup ( tbfc_cache, font ); TBFontConfig *tbfc = g_hash_table_lookup ( tbfc_cache, font );
if ( tbfc == NULL ){ if ( tbfc == NULL ) {
tbfc = g_malloc0 ( sizeof (TBFontConfig) ); tbfc = g_malloc0 ( sizeof ( TBFontConfig ) );
tbfc->pfd = pango_font_description_from_string ( font ); tbfc->pfd = pango_font_description_from_string ( font );
if ( helper_validate_font ( tbfc->pfd, font)) { if ( helper_validate_font ( tbfc->pfd, font ) ) {
tbfc->metrics = pango_context_get_metrics ( p_context, tbfc->pfd, NULL ); tbfc->metrics = pango_context_get_metrics ( p_context, tbfc->pfd, NULL );
g_hash_table_insert ( tbfc_cache, font, tbfc); g_hash_table_insert ( tbfc_cache, font, tbfc );
} else { }
else {
pango_font_description_free ( tbfc->pfd ); pango_font_description_free ( tbfc->pfd );
g_free( tbfc); g_free ( tbfc );
tbfc = NULL; tbfc = NULL;
} }
} }
@ -142,7 +144,6 @@ textbox* textbox_create ( const char *name, TextboxFlags flags, TextBoxFontType
} }
} }
if ( ( flags & TB_WRAP ) == TB_WRAP ) { if ( ( flags & TB_WRAP ) == TB_WRAP ) {
pango_layout_set_wrap ( tb->layout, PANGO_WRAP_WORD_CHAR ); pango_layout_set_wrap ( tb->layout, PANGO_WRAP_WORD_CHAR );
} }
@ -696,25 +697,25 @@ gboolean textbox_append_char ( textbox *tb, const char *pad, const int pad_len )
static void tbfc_entry_free ( TBFontConfig *tbfc ) static void tbfc_entry_free ( TBFontConfig *tbfc )
{ {
pango_font_metrics_unref ( tbfc->metrics); pango_font_metrics_unref ( tbfc->metrics );
if ( tbfc->pfd ){ if ( tbfc->pfd ) {
pango_font_description_free ( tbfc->pfd ); pango_font_description_free ( tbfc->pfd );
} }
g_free ( tbfc ); g_free ( tbfc );
} }
void textbox_setup ( void ) void textbox_setup ( void )
{ {
tbfc_cache = g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify)tbfc_entry_free ); tbfc_cache = g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify) tbfc_entry_free );
} }
const char *default_font_name = "default"; const char *default_font_name = "default";
void textbox_set_pango_context ( const char *font, PangoContext *p ) void textbox_set_pango_context ( const char *font, PangoContext *p )
{ {
g_assert ( p_metrics == NULL); g_assert ( p_metrics == NULL );
p_context = g_object_ref ( p ); p_context = g_object_ref ( p );
p_metrics = pango_context_get_metrics ( p_context, NULL, NULL ); p_metrics = pango_context_get_metrics ( p_context, NULL, NULL );
TBFontConfig *tbfc = g_malloc0 ( sizeof (TBFontConfig) ); TBFontConfig *tbfc = g_malloc0 ( sizeof ( TBFontConfig ) );
tbfc->metrics = p_metrics; tbfc->metrics = p_metrics;
g_hash_table_insert ( tbfc_cache,(gpointer *)(font?font:default_font_name), tbfc ); g_hash_table_insert ( tbfc_cache, (gpointer *) ( font ? font : default_font_name ), tbfc );
} }
void textbox_cleanup ( void ) void textbox_cleanup ( void )