Use true/false for hmode and fixed-num-lines

* Also update man page to reflect this.
This commit is contained in:
Qball Cow 2014-05-22 00:38:14 +02:00
parent f29751b573
commit beced5d36e
5 changed files with 56 additions and 28 deletions

View file

@ -68,13 +68,13 @@ Settings config = {
// Location of the window. WL_CENTER, WL_NORTH_WEST, WL_NORTH,WL_NORTH_EAST, etc.
.location = WL_CENTER,
// Mode of window, list (Vertical) or dmenu like (Horizontal)
.hmode = VERTICAL,
.hmode = FALSE,
// Padding of the window.
.padding = 5,
.show_title = 1,
.y_offset = 0,
.x_offset = 0,
.fixed_num_lines = 0
.fixed_num_lines = FALSE
};
/**
@ -106,7 +106,7 @@ void config_sanity_check( void )
exit(1);
}
if ( !( config.hmode == VERTICAL || config.hmode == HORIZONTAL ) )
if ( !( config.hmode == TRUE || config.hmode == FALSE ) )
{
fprintf(stderr, "config.hmode is invalid.\n");
exit(1);
@ -141,8 +141,7 @@ void config_print( void )
printf("# Lines: %3d\n", config.menu_lines);
printf("# Columns: %3d\n", config.menu_columns);
printf("Fixed number of lines: %5s\n", config.fixed_num_lines?"true":"false");
printf("Drawing mode: %10s\n",
config.hmode == VERTICAL?"Vertical":"Horizontal");
printf("Horizontal model: %5s\n", config.hmode == TRUE?"true":"false");
printf("Font: %35s\n", config.menu_font);

View file

@ -7,6 +7,8 @@ rofi \- a simple EWMH window switcher
.IR pct_scr ]
.RB [ \-lines
.IR lines ]
.RB [ \-columns
.IR columns ]
.RB [ \-font
.IR xftfont ]
.RB [ \-fg
@ -31,6 +33,7 @@ rofi \- a simple EWMH window switcher
.RB [ \-loc
.IR position ]
.RB [ \-hmode ]
.RB [ \-fixed\-num\-lines ]
.RB [ \-padding
.IR padding ]
.RB [ \-version ]
@ -160,12 +163,19 @@ rofi -o "75"
.RE
.TP
.B -lines
Maximum number of entries the menu may show before scrolling (default: 25).
Maximum number of lines the menu may show before scrolling (default: 25).
.P
.RS
rofi -lines 25
.RE
.TP
.B -columns
The number of columns the menu may show before scrolling (default: 25).
.P
.RS
rofi -columns 2
.RE
.TP
.B -width
Set the width of the menu as a percentage of the screen width (default: 60).
.P
@ -193,9 +203,16 @@ monitor:
.RE
.TP
.B -hmode
Switch to horizontal mode (ala dmenu). You can specify the number of elements with the
Switch to horizontal mode (ala dmenu). The number of elements is the number of
.IR lines
times the number of
.IR columns
.
.TP
.B -fixed-num-lines
Keep a fixed number of visible lines (See the
.IR -lines
option.
option.)
.TP
.B -padding
Define the inner margin of the window. Default is 5 pixels.

View file

@ -9,6 +9,14 @@
#define OVERLAP( a, b, c, d ) ( ( ( a ) == ( c ) && ( b ) == ( d ) ) || MIN ( ( a ) + ( b ), ( c ) + ( d ) ) - MAX ( ( a ), ( c ) ) > 0 )
#define INTERSECT( x, y, w, h, x1, y1, w1, h1 ) ( OVERLAP ( ( x ), ( w ), ( x1 ), ( w1 ) ) && OVERLAP ( ( y ), ( h ), ( y1 ), ( h1 ) ) )
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
extern const char *cache_dir;
typedef enum
@ -53,11 +61,6 @@ typedef enum _WindowLocation
WL_WEST = 8
} WindowLocation;
typedef enum
{
VERTICAL = 0,
HORIZONTAL = 1
} WindowMode;
/**
* Settings
*/
@ -86,7 +89,7 @@ typedef struct _Settings
char * run_key;
char * ssh_key;
WindowLocation location;
WindowMode hmode;
unsigned int hmode;
unsigned int padding;
int y_offset;
int x_offset;

View file

@ -1009,7 +1009,7 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
max_rows = config.menu_lines;
}
// More hacks.
if ( config.hmode == HORIZONTAL )
if ( config.hmode == TRUE )
{
max_rows = 1;
}
@ -1023,7 +1023,7 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
int element_width = w - ( 2 * ( config.padding ) );
// Divide by the # columns
element_width /= config.menu_columns;
if ( config.hmode == HORIZONTAL )
if ( config.hmode == TRUE )
{
element_width = ( w - ( 2 * ( config.padding ) ) - max_elements * LINE_MARGIN ) / ( max_elements + 1 );
}
@ -1076,7 +1076,7 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
textbox *text = textbox_create ( box, TB_AUTOHEIGHT | TB_EDITABLE,
( config.padding )+prompt_tb->w,
( config.padding ),
((config.hmode == HORIZONTAL)?
((config.hmode == TRUE)?
element_width:(w - (2 * ( config.padding ) ) ))-prompt_tb->w, 1,
config.menu_font, config.menu_fg, config.menu_bg,
( input != NULL ) ? *input : "" );
@ -1092,12 +1092,12 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
for ( i = 0; i < max_elements; i++ )
{
int line = ( i ) % max_rows + ( ( config.hmode == VERTICAL ) ? 1 : 0 );
int col = ( i ) / max_rows + ( ( config.hmode == VERTICAL ) ? 0 : 1 );
int line = ( i ) % max_rows + ( ( config.hmode == FALSE ) ? 1 : 0 );
int col = ( i ) / max_rows + ( ( config.hmode == FALSE ) ? 0 : 1 );
boxes[i] = textbox_create ( box,
0,
( config.padding ) + col * ( element_width + LINE_MARGIN ), // X
line * line_height + config.padding + ( ( config.hmode == HORIZONTAL ) ? 0 : LINE_MARGIN ), // y
line * line_height + config.padding + ( ( config.hmode == TRUE ) ? 0 : LINE_MARGIN ), // y
element_width, // w
line_height, // h
config.menu_font, config.menu_fg, config.menu_bg, "" );
@ -1105,7 +1105,7 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
}
// Arrows
textbox *arrowbox_top = NULL, *arrowbox_bottom = NULL;
if ( config.hmode == VERTICAL )
if ( config.hmode == FALSE )
{
arrowbox_top = textbox_create ( box, TB_AUTOHEIGHT | TB_AUTOWIDTH,
( config.padding ),
@ -1170,7 +1170,7 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
int h = line_height * ( max_rows + 1 ) + ( config.padding ) * 2 + LINE_MARGIN;
if ( config.hmode == HORIZONTAL )
if ( config.hmode == TRUE )
{
h = line_height + ( config.padding ) * 2;
}
@ -1245,7 +1245,7 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
max_elements, arrowbox_top,
arrowbox_bottom );
// Why do we need the specian -1?
if ( config.hmode == VERTICAL && max_elements > 0 )
if ( config.hmode == FALSE && max_elements > 0 )
{
XDrawLine ( display, main_window, gc, ( config.padding ),
line_height + ( config.padding ) + ( LINE_MARGIN - 2 ) / 2,
@ -1932,7 +1932,7 @@ static void parse_cmd_options ( int argc, char ** argv )
if ( find_arg ( argc, argv, "-hmode" ) >= 0 )
{
config.hmode = HORIZONTAL;
config.hmode = TRUE;
}
// Keybindings

View file

@ -38,7 +38,8 @@
typedef enum
{
xrm_String = 0,
xrm_Number = 1
xrm_Number = 1,
xrm_Boolean= 2
} XrmOptionType;
typedef struct
@ -72,9 +73,9 @@ static XrmOption xrmOptions[] = {
{ xrm_Number, "location", { .num = &config.location }, NULL },
{ xrm_Number, "yoffset", { .num = &config.y_offset }, NULL },
{ xrm_Number, "xoffset", { .num = &config.x_offset }, NULL },
{ xrm_Number, "fixed_num_lines", { .num = &config.fixed_num_lines }, NULL },
{ xrm_Boolean,"fixed-num-lines", { .num = &config.fixed_num_lines }, NULL },
{ xrm_Number, "columns", { .num = &config.menu_columns }, NULL },
{ xrm_Number, "hmode", { .num = &config.hmode }, NULL },
{ xrm_Boolean,"hmode", { .num = &config.hmode }, NULL },
/* Key bindings */
{ xrm_String, "key", { .str = &config.window_key }, NULL },
{ xrm_String, "rkey", { .str = &config.run_key }, NULL },
@ -129,6 +130,14 @@ void parse_xresource_options ( Display *display )
{
*xrmOptions[i].num = strtol ( xrmValue.addr, NULL, 10 );
}
else if ( xrmOptions[i].type == xrm_Boolean )
{
if(xrmValue.size > 0 && strncasecmp(xrmValue.addr, "true", xrmValue.size) == 0) {
*xrmOptions[i].num = TRUE;
} else {
*xrmOptions[i].num = FALSE;
}
}
}
free ( class );