mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Don't recreate every string everytime.
This commit is contained in:
parent
2fe22cb7e2
commit
8ef7b4b794
9 changed files with 89 additions and 88 deletions
|
@ -168,7 +168,7 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned
|
|||
}
|
||||
if ( switcher >= 0 ) {
|
||||
if ( eob[0] == ' ' ) {
|
||||
char *n = eob+1;
|
||||
char *n = eob + 1;
|
||||
return mode_result ( pd->switchers[switcher], mretv, &n,
|
||||
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' ) {
|
||||
return NULL;
|
||||
}
|
||||
return g_strdup ( eob+1 );
|
||||
return g_strdup ( eob + 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ static void async_read_callback ( GObject *source_object, GAsyncResult *res, gpo
|
|||
}
|
||||
if ( !g_cancellable_is_cancelled ( pd->cancel ) ) {
|
||||
// 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 );
|
||||
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 )
|
||||
{
|
||||
while(sync_pre_read-- ){
|
||||
while ( sync_pre_read-- ) {
|
||||
gsize len = 0;
|
||||
char *data = g_data_input_stream_read_upto ( pd->data_input_stream, &( pd->separator ), 1, &len, NULL, NULL );
|
||||
if ( data == NULL ) {
|
||||
|
@ -636,7 +636,7 @@ int dmenu_switcher_dialog ( void )
|
|||
}
|
||||
if ( async ) {
|
||||
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 );
|
||||
}
|
||||
else {
|
||||
|
@ -728,5 +728,5 @@ void print_dmenu_options ( void )
|
|||
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 ( "-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 );
|
||||
}
|
||||
|
|
|
@ -288,7 +288,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
|
|||
}
|
||||
size_t nl = ( ( pd->cmd_list_length ) + 1 );
|
||||
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[pd->cmd_list_length].root = g_strdup ( root );
|
||||
|
|
|
@ -530,9 +530,9 @@ gboolean helper_validate_font ( PangoFontDescription *pfd, const char *font )
|
|||
{
|
||||
const char *fam = pango_font_description_get_family ( pfd );
|
||||
int size = pango_font_description_get_size ( pfd );
|
||||
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, "Got family: <b>%s</b> at size: <b>%d</b>", fam?fam:"{unknown}", size);
|
||||
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, "Got family: <b>%s</b> at size: <b>%d</b>", fam ? fam : "{unknown}", size );
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
|
|
|
@ -642,11 +642,11 @@ void __create_window ( MenuFlags menu_flags )
|
|||
printf ( "xcb_create_window() failed error=0x%x\n", error->error_code );
|
||||
exit ( EXIT_FAILURE );
|
||||
}
|
||||
TICK_N ( "xcb create window");
|
||||
TICK_N ( "xcb create window" );
|
||||
CacheState.gc = xcb_generate_id ( xcb->connection );
|
||||
xcb_create_gc ( xcb->connection, CacheState.gc, box, 0, 0 );
|
||||
|
||||
TICK_N ( "xcb create gc");
|
||||
TICK_N ( "xcb create gc" );
|
||||
// Create a drawable.
|
||||
CacheState.edit_pixmap = xcb_generate_id ( xcb->connection );
|
||||
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_draw = cairo_create ( CacheState.edit_surf );
|
||||
|
||||
TICK_N ( "create cairo surface");
|
||||
TICK_N ( "create cairo surface" );
|
||||
// Set up pango context.
|
||||
cairo_font_options_t *fo = cairo_font_options_create ();
|
||||
// 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 );
|
||||
// Set the font options from the xlib surface
|
||||
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.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 );
|
||||
if ( 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_font_description_free ( pfd );
|
||||
}
|
||||
PangoLanguage *l = pango_language_get_default();
|
||||
PangoLanguage *l = pango_language_get_default ();
|
||||
pango_context_set_language ( p, l );
|
||||
TICK_N ( "configure font");
|
||||
TICK_N ( "configure font" );
|
||||
|
||||
// Tell textbox to use this context.
|
||||
textbox_set_pango_context ( font, p );
|
||||
|
@ -709,7 +709,7 @@ void __create_window ( MenuFlags menu_flags )
|
|||
g_object_unref ( p );
|
||||
cairo_font_options_destroy ( fo );
|
||||
|
||||
TICK_N ( "textbox setup");
|
||||
TICK_N ( "textbox setup" );
|
||||
// // make it an unmanaged window
|
||||
if ( ( ( menu_flags & MENU_NORMAL_WINDOW ) == 0 ) ) {
|
||||
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 );
|
||||
}
|
||||
|
||||
TICK_N ( "setup window attributes");
|
||||
TICK_N ( "setup window attributes" );
|
||||
CacheState.fullscreen = rofi_theme_get_boolean ( WIDGET ( win ), "fullscreen", config.fullscreen );
|
||||
if ( CacheState.fullscreen ) {
|
||||
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 ) );
|
||||
}
|
||||
|
||||
TICK_N ( "setup window fullscreen");
|
||||
TICK_N ( "setup window fullscreen" );
|
||||
// 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_ATOM_WM_NAME, XCB_ATOM_STRING, 8, 4, "rofi" );
|
||||
|
||||
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 );
|
||||
if ( transparency == NULL && config.fake_transparency ) {
|
||||
transparency = config.fake_background;
|
||||
|
@ -750,9 +750,9 @@ void __create_window ( MenuFlags menu_flags )
|
|||
if ( xcb->sncontext != NULL ) {
|
||||
sn_launchee_context_setup_window ( xcb->sncontext, CacheState.main_window );
|
||||
}
|
||||
TICK_N ( "setup startup notification");
|
||||
TICK_N ( "setup startup notification" );
|
||||
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->widget.parent = WIDGET(state->main_window);
|
||||
state->overlay->widget.parent = WIDGET ( state->main_window );
|
||||
widget_disable ( WIDGET ( state->overlay ) );
|
||||
|
||||
state->list_view = listview_create ( "window.mainbox.listview", update_callback, state, config.element_height, end );
|
||||
|
|
|
@ -237,12 +237,12 @@ static void listview_recompute_elements ( listview *lv )
|
|||
}
|
||||
lv->boxes = g_realloc ( lv->boxes, newne * sizeof ( textbox* ) );
|
||||
if ( newne > 0 ) {
|
||||
char *name = g_strjoin ( ".", lv->listview_name, "element", NULL );
|
||||
for ( unsigned int i = lv->cur_elements; i < newne; i++ ) {
|
||||
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, "" );
|
||||
g_free ( name );
|
||||
}
|
||||
g_free ( name );
|
||||
}
|
||||
lv->rchanged = TRUE;
|
||||
lv->cur_elements = newne;
|
||||
|
|
|
@ -59,7 +59,8 @@ static PangoContext *p_context = NULL;
|
|||
static PangoFontMetrics *p_metrics = NULL;
|
||||
|
||||
/** Cache to hold font descriptions. This it to avoid having to lookup each time. */
|
||||
typedef struct TBFontConfig {
|
||||
typedef struct TBFontConfig
|
||||
{
|
||||
/** Font description */
|
||||
PangoFontDescription *pfd;
|
||||
/** Font metrics */
|
||||
|
@ -121,17 +122,18 @@ textbox* textbox_create ( const char *name, TextboxFlags flags, TextBoxFontType
|
|||
|
||||
tb->metrics = p_metrics;
|
||||
char * font = rofi_theme_get_string ( WIDGET ( tb ), "font", NULL );
|
||||
if ( font ){
|
||||
if ( font ) {
|
||||
TBFontConfig *tbfc = g_hash_table_lookup ( tbfc_cache, font );
|
||||
if ( tbfc == NULL ){
|
||||
tbfc = g_malloc0 ( sizeof (TBFontConfig) );
|
||||
if ( tbfc == NULL ) {
|
||||
tbfc = g_malloc0 ( sizeof ( TBFontConfig ) );
|
||||
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 );
|
||||
g_hash_table_insert ( tbfc_cache, font, tbfc);
|
||||
} else {
|
||||
g_hash_table_insert ( tbfc_cache, font, tbfc );
|
||||
}
|
||||
else {
|
||||
pango_font_description_free ( tbfc->pfd );
|
||||
g_free( tbfc);
|
||||
g_free ( tbfc );
|
||||
tbfc = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +144,6 @@ textbox* textbox_create ( const char *name, TextboxFlags flags, TextBoxFontType
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if ( ( flags & TB_WRAP ) == TB_WRAP ) {
|
||||
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 )
|
||||
{
|
||||
pango_font_metrics_unref ( tbfc->metrics);
|
||||
if ( tbfc->pfd ){
|
||||
pango_font_metrics_unref ( tbfc->metrics );
|
||||
if ( tbfc->pfd ) {
|
||||
pango_font_description_free ( tbfc->pfd );
|
||||
}
|
||||
g_free ( tbfc );
|
||||
}
|
||||
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";
|
||||
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_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;
|
||||
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 )
|
||||
|
|
Loading…
Reference in a new issue