mirror of
https://github.com/davatorium/rofi.git
synced 2025-02-24 15:56:25 -05:00
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:
parent
d76571bcaa
commit
e44183b406
6 changed files with 627 additions and 504 deletions
|
@ -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
|
||||
|
|
|
@ -105,7 +105,6 @@ typedef struct _Settings
|
|||
char * menu_hlbg;
|
||||
char * menu_bc;
|
||||
// Behavior
|
||||
unsigned int zeltak_mode;
|
||||
char * terminal_emulator;
|
||||
|
||||
// Key bindings
|
||||
|
|
|
@ -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__
|
||||
|
|
1110
source/rofi.c
1110
source/rofi.c
File diff suppressed because it is too large
Load diff
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue