1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Pull config option access from out of separator widget.

This commit is contained in:
Dave Davenport 2016-11-01 08:04:39 +01:00
parent dde77ecd7c
commit 4c5df96fcd
9 changed files with 99 additions and 47 deletions

View file

@ -27,6 +27,13 @@ typedef enum
S_VERTICAL = 1
} separator_type;
typedef enum
{
S_LINE_NONE,
S_LINE_SOLID,
S_LINE_DASH
} separator_line_style;
/**
* @param type The type of separator.
* @param sw The thickness of the separator.
@ -37,5 +44,20 @@ typedef enum
*/
separator *separator_create ( separator_type type, short sw );
/**
* @param sp The separator widget handle.
* @param style_str String representation of the style.
*
* Sets the line style based on the string style_str
*/
void separator_set_line_style_from_string ( separator *sp, const char *style_str );
/**
* @param sp The separator widget handle.
* @param style The new style.
*
* Sets the line style.
*/
void separator_set_line_style ( separator *sp, separator_line_style style );
/*@}*/
#endif // ROFI_SEPARATOR_H

View file

@ -46,16 +46,16 @@ typedef struct
*/
typedef enum
{
TB_AUTOHEIGHT = 1 << 0,
TB_AUTOWIDTH = 1 << 1,
TB_LEFT = 1 << 16,
TB_RIGHT = 1 << 17,
TB_CENTER = 1 << 18,
TB_EDITABLE = 1 << 19,
TB_MARKUP = 1 << 20,
TB_WRAP = 1 << 21,
TB_PASSWORD = 1 << 22,
TB_INDICATOR = 1 << 23,
TB_AUTOHEIGHT = 1 << 0,
TB_AUTOWIDTH = 1 << 1,
TB_LEFT = 1 << 16,
TB_RIGHT = 1 << 17,
TB_CENTER = 1 << 18,
TB_EDITABLE = 1 << 19,
TB_MARKUP = 1 << 20,
TB_WRAP = 1 << 21,
TB_PASSWORD = 1 << 22,
TB_INDICATOR = 1 << 23,
} TextboxFlags;
/**
* Flags indicating current state of the textbox.

View file

@ -278,9 +278,9 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
return;
}
size_t nl = ( ( pd->cmd_list_length ) + 1 );
pd->entry_list = g_realloc ( pd->entry_list, nl * sizeof ( *( pd->entry_list ) ) );
pd->entry_list[pd->cmd_list_length].root = g_strdup ( root );
pd->entry_list[pd->cmd_list_length].path = g_strdup ( path );
pd->entry_list = g_realloc ( pd->entry_list, nl * sizeof ( *( pd->entry_list ) ) );
pd->entry_list[pd->cmd_list_length].root = g_strdup ( root );
pd->entry_list[pd->cmd_list_length].path = g_strdup ( path );
gchar *n = g_key_file_get_locale_string ( kf, "Desktop Entry", "Name", NULL, NULL );
pd->entry_list[pd->cmd_list_length].name = n;
gchar *gn = g_key_file_get_locale_string ( kf, "Desktop Entry", "GenericName", NULL, NULL );

View file

@ -260,9 +260,9 @@ static char ** get_apps ( unsigned int *length )
return NULL;
}
const char *const sep = ":";
char *strtok_savepointer = NULL;
for ( const char *dirname = strtok_r ( path, sep, &strtok_savepointer); dirname != NULL; dirname = strtok_r ( NULL, sep, &strtok_savepointer ) ) {
const char *const sep = ":";
char *strtok_savepointer = NULL;
for ( const char *dirname = strtok_r ( path, sep, &strtok_savepointer ); dirname != NULL; dirname = strtok_r ( NULL, sep, &strtok_savepointer ) ) {
DIR *dir = opendir ( dirname );
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Checking path %s for executable.", dirname );

View file

@ -198,7 +198,7 @@ static char **read_hosts_file ( char ** retv, unsigned int *length )
// Reading one line per time.
while ( getline ( &buffer, &buffer_length, fd ) > 0 ) {
// Evaluate one line.
unsigned int index = 0, ti = 0;
unsigned int index = 0, ti = 0;
char *token = buffer;
// Tokenize it.
@ -289,16 +289,16 @@ static char ** get_ssh ( unsigned int *length )
fd = fopen ( path, "r" );
if ( fd != NULL ) {
char *buffer = NULL;
size_t buffer_length = 0;
char *strtok_pointer = NULL;
char *buffer = NULL;
size_t buffer_length = 0;
char *strtok_pointer = NULL;
while ( getline ( &buffer, &buffer_length, fd ) > 0 ) {
// Each line is either empty, a comment line starting with a '#'
// character or of the form "keyword [=] arguments", where there may
// be multiple (possibly quoted) arguments separated by whitespace.
// The keyword is separated from its arguments by whitespace OR by
// optional whitespace and a '=' character.
char *token = strtok_r ( buffer, SSH_TOKEN_DELIM, &strtok_pointer);
char *token = strtok_r ( buffer, SSH_TOKEN_DELIM, &strtok_pointer );
// Skip empty lines and comment lines. Also skip lines where the
// keyword is not "Host".

View file

@ -194,7 +194,7 @@ static GRegex * create_regex ( const char *input, int case_sensitive )
{
#define R( s ) g_regex_new ( s, G_REGEX_OPTIMIZE | ( ( case_sensitive ) ? 0 : G_REGEX_CASELESS ), 0, NULL )
GRegex * retv = NULL;
gchar *r;
gchar *r;
switch ( config.matching_method )
{
case MM_GLOB:
@ -234,7 +234,7 @@ GRegex **tokenize ( const char *input, int case_sensitive )
}
char *saveptr = NULL, *token;
GRegex **retv = NULL;
GRegex **retv = NULL;
if ( !config.tokenize ) {
retv = g_malloc0 ( sizeof ( GRegex* ) * 2 );
retv[0] = (GRegex *) create_regex ( input, case_sensitive );

View file

@ -352,7 +352,7 @@ static int add_mode ( const char * token )
}
else
#endif // WINDOW_MODE
// SSh dialog
// SSh dialog
if ( strcasecmp ( token, "ssh" ) == 0 ) {
modi[num_modi] = &ssh_mode;
num_modi++;

View file

@ -1380,6 +1380,7 @@ RofiViewState *rofi_view_create ( Mode *sw,
state->input_bar = box_create ( BOX_HORIZONTAL, 0, 0, state->width - state->border, line_height );
//box_set_padding ( state->input_bar, config.line_margin );
state->input_bar_separator = separator_create ( S_HORIZONTAL, 2 );
separator_set_line_style_from_string ( state->input_bar_separator, config.separator_style );
if ( ( config.location == WL_EAST_SOUTH || config.location == WL_SOUTH || config.location == WL_SOUTH_WEST ) ) {
box_add ( state->main_box, WIDGET ( state->input_bar_separator ), FALSE, TRUE );
@ -1412,7 +1413,9 @@ RofiViewState *rofi_view_create ( Mode *sw,
textbox *message_tb = textbox_create ( TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, 0, 0,
state->width - ( 2 * ( state->border ) ), -1, NORMAL, message );
box_add ( state->main_box, WIDGET ( message_tb ), FALSE, FALSE );
box_add ( state->main_box, WIDGET ( separator_create ( S_HORIZONTAL, 2 ) ), FALSE, FALSE );
separator *sep = separator_create ( S_HORIZONTAL, 2 );
box_add ( state->main_box, WIDGET ( sep ), FALSE, FALSE );
separator_set_line_style_from_string ( sep, config.separator_style );
}
state->overlay = textbox_create ( TB_AUTOWIDTH, 0, 0, 20, line_height, URGENT, "blaat" );
@ -1437,7 +1440,9 @@ RofiViewState *rofi_view_create ( Mode *sw,
if ( config.sidebar_mode ) {
state->sidebar_bar = box_create ( BOX_HORIZONTAL, 0, 0, state->width - 2 * state->border, line_height );
box_set_padding ( state->sidebar_bar, config.line_margin );
box_add ( state->main_box, WIDGET ( separator_create ( S_HORIZONTAL, 2 ) ), FALSE, TRUE );
separator *sep = separator_create ( S_HORIZONTAL, 2 );
box_add ( state->main_box, WIDGET ( sep ), FALSE, TRUE );
separator_set_line_style_from_string ( sep, config.separator_style );
box_add ( state->main_box, WIDGET ( state->sidebar_bar ), FALSE, TRUE );
state->num_modi = rofi_get_num_enabled_modi ();
state->modi = g_malloc0 ( state->num_modi * sizeof ( textbox * ) );

View file

@ -37,8 +37,9 @@
*/
struct _separator
{
widget widget;
separator_type type;
widget widget;
separator_type type;
separator_line_style line_style;
};
/** Configuration value for separator style indicating no line */
@ -78,27 +79,51 @@ static void separator_free ( widget *wid )
g_free ( sb );
}
void separator_set_line_style ( separator *sp, separator_line_style style )
{
if ( sp ) {
sp->line_style = style;
widget_need_redraw ( WIDGET ( sp ) );
}
}
void separator_set_line_style_from_string ( separator *sp, const char *style_str )
{
if ( !sp ) {
return;
}
separator_line_style style = S_LINE_SOLID;
if ( g_strcmp0 ( style_str, _separator_style_none ) == 0 ) {
style = S_LINE_NONE;
}
else if ( g_strcmp0 ( style_str, _separator_style_dash ) == 0 ) {
style = S_LINE_DASH;
}
separator_set_line_style ( sp, style );
}
static void separator_draw ( widget *wid, cairo_t *draw )
{
separator *sep = (separator *) wid;
if ( strcmp ( config.separator_style, _separator_style_none ) ) {
color_separator ( draw );
if ( strcmp ( config.separator_style, _separator_style_dash ) == 0 ) {
const double dashes[1] = { 4 };
cairo_set_dash ( draw, dashes, 1, 0.0 );
}
if ( sep->type == S_HORIZONTAL ) {
cairo_set_line_width ( draw, wid->h );
double half = wid->h / 2.0;
cairo_move_to ( draw, wid->x, wid->y + half );
cairo_line_to ( draw, wid->x + wid->w, wid->y + half );
}
else {
cairo_set_line_width ( draw, wid->w );
double half = wid->w / 2.0;
cairo_move_to ( draw, wid->x + half, wid->y );
cairo_line_to ( draw, wid->x + half, wid->y + wid->h );
}
cairo_stroke ( draw );
if ( sep->line_style == S_LINE_NONE ) {
// Nothing to draw.
return;
}
color_separator ( draw );
if ( sep->line_style == S_LINE_DASH ) {
const double dashes[1] = { 4 };
cairo_set_dash ( draw, dashes, 1, 0.0 );
}
if ( sep->type == S_HORIZONTAL ) {
cairo_set_line_width ( draw, wid->h );
double half = wid->h / 2.0;
cairo_move_to ( draw, wid->x, wid->y + half );
cairo_line_to ( draw, wid->x + wid->w, wid->y + half );
}
else {
cairo_set_line_width ( draw, wid->w );
double half = wid->w / 2.0;
cairo_move_to ( draw, wid->x + half, wid->y );
cairo_line_to ( draw, wid->x + half, wid->y + wid->h );
}
cairo_stroke ( draw );
}