Refactor the to-long menu() function.

* Split out larger sub-parts into separate functions.
    * Create a state structure.
    * Remove zeltak mode.
This commit is contained in:
Dave Davenport 2014-08-26 20:25:00 +02:00
parent d76571bcaa
commit e44183b406
6 changed files with 627 additions and 504 deletions

View File

@ -56,8 +56,6 @@ Settings config = {
.menu_hlbg = "#005577",
// Border color.
.menu_bc = "black",
// Directly select when only 1 choice is left
.zeltak_mode = 0,
// Terminal to use. (for ssh and open in terminal)
.terminal_emulator = "x-terminal-emulator",
// Key binding

View File

@ -105,7 +105,6 @@ typedef struct _Settings
char * menu_hlbg;
char * menu_bc;
// Behavior
unsigned int zeltak_mode;
char * terminal_emulator;
// Key bindings

View File

@ -91,5 +91,5 @@ int textbox_get_width ( textbox *tb );
int textbox_get_font_height ( textbox *tb );
int textbox_get_font_width ( textbox *tb );
double textbox_get_estimated_char_width ( textbox *tb );
double textbox_get_estimated_char_width ( );
#endif //__TEXTBOX_H__

File diff suppressed because it is too large Load Diff

View File

@ -47,7 +47,7 @@
#define RUN_CACHE_FILE "rofi-2.runcache"
static inline int execsh ( const char *cmd, int run_in_term )
static inline void execsh ( const char *cmd, int run_in_term )
{
char **args = g_malloc_n ( 6, sizeof ( char* ) );
int i = 0;

View File

@ -475,11 +475,21 @@ int textbox_get_font_width ( textbox *tb )
return width;
}
double textbox_get_estimated_char_width ( textbox *tb )
double textbox_get_estimated_char_width ( )
{
PangoContext *context = pango_layout_get_context ( tb->layout );
// Create a temp layout with right font.
PangoLayout *layout = pango_layout_new ( p_context );
// Set font.
PangoFontDescription *pfd = pango_font_description_from_string ( config.menu_font );
pango_layout_set_font_description ( layout, pfd );
pango_font_description_free ( pfd );
// Get width
PangoContext *context = pango_layout_get_context ( layout );
PangoFontMetrics *metric = pango_context_get_metrics ( context, NULL, NULL );
int width = pango_font_metrics_get_approximate_char_width ( metric );
pango_font_metrics_unref ( metric );
g_object_unref ( layout );
return ( width ) / (double) PANGO_SCALE;
}