Run indenter.

This commit is contained in:
Dave Davenport 2020-08-28 16:41:59 +02:00
parent 5bec191d2e
commit 30735791b4
21 changed files with 349 additions and 331 deletions

View file

@ -118,9 +118,9 @@ Settings config = {
.matching_method = MM_NORMAL,
/** Desktop entries to match in drun */
.drun_match_fields = "name,generic,exec,categories,keywords",
.drun_match_fields = "name,generic,exec,categories,keywords",
/** Only show entries in this category */
.drun_categories = NULL,
.drun_categories = NULL,
/** Desktop entry show actions */
.drun_show_actions = FALSE,
/** Desktop format display */
@ -162,8 +162,8 @@ Settings config = {
.matching_negate_char = '-',
.cache_dir = NULL,
.window_thumbnail = FALSE,
.cache_dir = NULL,
.window_thumbnail = FALSE,
/** drun cache */
.drun_use_desktop_cache = FALSE,

View file

@ -104,22 +104,21 @@ typedef enum
ROFI_DISTANCE_MODIFIER_GROUP,
} RofiDistanceModifier;
typedef struct RofiDistanceUnit
typedef struct RofiDistanceUnit
{
/** Distance */
double distance;
double distance;
/** Unit type of the distance */
RofiPixelUnit type;
RofiPixelUnit type;
/** Type */
RofiDistanceModifier modtype;
RofiDistanceModifier modtype;
/** Modifier */
struct RofiDistanceUnit *left;
/** Modifier */
struct RofiDistanceUnit *right;
} RofiDistanceUnit;
typedef struct
@ -127,7 +126,7 @@ typedef struct
/** Base */
RofiDistanceUnit base;
/** Style of the line (optional)*/
RofiLineStyle style;
RofiLineStyle style;
} RofiDistance;
/**

View file

@ -249,7 +249,6 @@ double rofi_theme_get_double ( const widget *widget, const char *property, doub
*/
void rofi_theme_get_color ( const widget *widget, const char *property, cairo_t *d );
/**
* @param widget The widget to query
* @param property The property to query.

View file

@ -307,7 +307,6 @@ void rofi_capture_screenshot ( void );
*/
void rofi_view_set_window_title ( const char * title );
/**
* set ellipsize mode to start.
*/

View file

@ -81,7 +81,7 @@ struct _widget
int ( *get_desired_height )( struct _widget * );
int ( *get_desired_width )( struct _widget * );
void ( *set_state ) ( struct _widget *, const char *);
void ( *set_state ) ( struct _widget *, const char * );
/** widget find_mouse_target callback */
widget_find_mouse_target_cb find_mouse_target;

View file

@ -172,7 +172,8 @@ void widget_set_enabled ( widget *widget, gboolean enabled );
* Disable the widget.
*/
static inline
void widget_disable ( widget *widget ) {
void widget_disable ( widget *widget )
{
widget_set_enabled ( widget, FALSE );
}
/**
@ -181,7 +182,8 @@ void widget_disable ( widget *widget ) {
* Enable the widget.
*/
static inline
void widget_enable ( widget *widget ) {
void widget_enable ( widget *widget )
{
widget_set_enabled ( widget, TRUE );
}

View file

@ -155,11 +155,11 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned
CombiModePrivateData *pd = mode_get_private_data ( sw );
if ( input[0][0] == '!' ) {
int switcher = -1;
int switcher = -1;
// Implement strchrnul behaviour.
char *eob = g_utf8_strchr ( input[0], -1,' ' );
char *eob = g_utf8_strchr ( input[0], -1, ' ' );
if ( eob == NULL ) {
eob = &(input[0][strlen(input[0])]);
eob = &( input[0][strlen ( input[0] )] );
}
ssize_t bang_len = g_utf8_pointer_to_offset ( input[0], eob ) - 1;
if ( bang_len > 0 ) {
@ -282,10 +282,10 @@ static char * combi_preprocess_input ( Mode *sw, const char *input )
}
if ( input != NULL && input[0] == '!' ) {
// Implement strchrnul behaviour.
const char *eob = g_utf8_strchr ( input, -1, ' ' );
const char *eob = g_utf8_strchr ( input, -1, ' ' );
if ( eob == NULL ) {
// Set it to end.
eob = &(input[strlen(input)]);
eob = &( input[strlen ( input )] );
}
ssize_t bang_len = g_utf8_pointer_to_offset ( input, eob ) - 1;
if ( bang_len > 0 ) {

View file

@ -122,7 +122,7 @@ static void read_add ( DmenuModePrivateData * pd, char *data, gsize len )
pd->cmd_list[pd->cmd_list_length].icon_fetch_uid = 0;
pd->cmd_list[pd->cmd_list_length].icon_name = NULL;
pd->cmd_list[pd->cmd_list_length].meta = NULL;
pd->cmd_list[pd->cmd_list_length].info = NULL;
pd->cmd_list[pd->cmd_list_length].info = NULL;
char *end = strchr ( data, '\0' );
if ( end != NULL ) {
data_len = end - data;
@ -736,7 +736,6 @@ int dmenu_switcher_dialog ( void )
find_arg_str ( "-p", &( dmenu_mode.display_name ) );
RofiViewState *state = rofi_view_create ( &dmenu_mode, input, menu_flags, dmenu_finalize );
if ( find_arg ( "-keep-right" ) >= 0 ) {
rofi_view_ellipsize_start ( state );
}

View file

@ -92,27 +92,27 @@ typedef struct
/* Icon size is used to indicate what size is requested by the gui.
* secondary it indicates if the request for a lookup has been issued (0 not issued )
*/
int icon_size;
int icon_size;
/* Surface holding the icon. */
cairo_surface_t *icon;
cairo_surface_t *icon;
/* Executable - for Application entries only */
char *exec;
char *exec;
/* Name of the Entry */
char *name;
char *name;
/* Generic Name */
char *generic_name;
char *generic_name;
/* Categories */
char **categories;
char **categories;
/* Keywords */
char **keywords;
char **keywords;
/* Comments */
char *comment;
char *comment;
GKeyFile *key_file;
GKeyFile *key_file;
gint sort_index;
gint sort_index;
uint32_t icon_fetch_uid;
uint32_t icon_fetch_uid;
DRunDesktopEntryType type;
} DRunModeEntry;
@ -193,7 +193,7 @@ static gboolean drun_helper_eval_cb ( const GMatchInfo *info, GString *res, gpoi
case 'm':
break;
case '%':
g_string_append(res, "%");
g_string_append ( res, "%" );
break;
case 'k':
if ( e->e->path ) {
@ -241,12 +241,12 @@ static void launch_link_entry ( DRunModeEntry *e )
if ( url == NULL || strlen ( url ) == 0 ) {
g_warning ( "[%s] [%s] No URL found.", e->app_id, e->path );
g_free ( url );
return ;
return;
}
gsize command_len = strlen( config.drun_url_launcher ) + strlen( url ) + 2; // space + terminator = 2
gchar *command = g_newa ( gchar, command_len );
g_snprintf( command, command_len, "%s %s", config.drun_url_launcher, url );
gsize command_len = strlen ( config.drun_url_launcher ) + strlen ( url ) + 2; // space + terminator = 2
gchar *command = g_newa ( gchar, command_len );
g_snprintf ( command, command_len, "%s %s", config.drun_url_launcher, url );
g_free ( url );
g_debug ( "Link launch command: |%s|", command );
@ -349,7 +349,7 @@ static gboolean rofi_strv_contains ( const char * const *categories, const char
static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const char *path, const gchar *basename, const char *action )
{
DRunDesktopEntryType desktop_entry_type = DRUN_DESKTOP_ENTRY_TYPE_UNDETERMINED;
int parse_action = ( config.drun_show_actions && action != DRUN_GROUP_NAME );
int parse_action = ( config.drun_show_actions && action != DRUN_GROUP_NAME );
// Create ID on stack.
// We know strlen (path ) > strlen(root)+1
const ssize_t id_len = strlen ( path ) - strlen ( root );
@ -393,9 +393,11 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
}
if ( !g_strcmp0 ( key, "Application" ) ) {
desktop_entry_type = DRUN_DESKTOP_ENTRY_TYPE_APPLICATION;
} else if ( !g_strcmp0 ( key, "Link" ) ) {
}
else if ( !g_strcmp0 ( key, "Link" ) ) {
desktop_entry_type = DRUN_DESKTOP_ENTRY_TYPE_LINK;
} else {
}
else {
g_debug ( "[%s] [%s] Skipping desktop file: Not of type Application or Link (%s)", id, path, key );
g_free ( key );
g_key_file_free ( kf );
@ -499,7 +501,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
char **categories = NULL;
if ( pd->show_categories ) {
categories = g_key_file_get_locale_string_list ( kf, DRUN_GROUP_NAME, "Categories", NULL, NULL, NULL );
if ( !rofi_strv_contains ( (const char * const *) categories, (const char *const *) pd->show_categories ) ) {
if ( !rofi_strv_contains ( (const char * const *) categories, (const char * const *) pd->show_categories ) ) {
g_strfreev ( categories );
g_key_file_free ( kf );
return;
@ -563,7 +565,8 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
pd->entry_list[pd->cmd_list_length].type = desktop_entry_type;
if ( desktop_entry_type == DRUN_DESKTOP_ENTRY_TYPE_APPLICATION ) {
pd->entry_list[pd->cmd_list_length].exec = g_key_file_get_string ( kf, action, "Exec", NULL );
} else {
}
else {
pd->entry_list[pd->cmd_list_length].exec = NULL;
}
@ -1019,15 +1022,16 @@ static ModeMode drun_mode_result ( Mode *sw, int mretv, char **input, unsigned i
retv = ( mretv & MENU_LOWER_MASK );
}
else if ( ( mretv & MENU_OK ) ) {
switch ( rmpd->entry_list[selected_line].type ) {
case DRUN_DESKTOP_ENTRY_TYPE_APPLICATION:
exec_cmd_entry ( &( rmpd->entry_list[selected_line] ) );
break;
case DRUN_DESKTOP_ENTRY_TYPE_LINK:
launch_link_entry ( &( rmpd->entry_list[selected_line] ) );
break;
default:
g_assert_not_reached ();
switch ( rmpd->entry_list[selected_line].type )
{
case DRUN_DESKTOP_ENTRY_TYPE_APPLICATION:
exec_cmd_entry ( &( rmpd->entry_list[selected_line] ) );
break;
case DRUN_DESKTOP_ENTRY_TYPE_LINK:
launch_link_entry ( &( rmpd->entry_list[selected_line] ) );
break;
default:
g_assert_not_reached ();
}
}
else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) {

View file

@ -68,7 +68,7 @@ typedef struct
char *message;
char *prompt;
gboolean do_markup;
char delim;
char delim;
/** no custom */
gboolean no_custom;
} ScriptModePrivateData;
@ -80,10 +80,9 @@ void dmenuscript_parse_entry_extras ( G_GNUC_UNUSED Mode *sw, DmenuScriptEntry *
{
gchar **extras = g_strsplit ( buffer, "\x1f", -1 );
gchar **extra;
for ( extra = extras ; *extra != NULL && *(extra + 1) != NULL ; extra += 2 )
{
gchar *key = *extra;
gchar *value = *(extra + 1);
for ( extra = extras; *extra != NULL && *( extra + 1 ) != NULL; extra += 2 ) {
gchar *key = *extra;
gchar *value = *( extra + 1 );
if ( strcasecmp ( key, "icon" ) == 0 ) {
entry->icon_name = value;
}
@ -95,14 +94,14 @@ void dmenuscript_parse_entry_extras ( G_GNUC_UNUSED Mode *sw, DmenuScriptEntry *
}
else if ( strcasecmp ( key, "nonselectable" ) == 0 ) {
entry->nonselectable = strcasecmp ( value, "true" ) == 0;
g_free(value);
g_free ( value );
}
else {
g_free(value);
g_free ( value );
}
g_free(key);
g_free ( key );
}
g_free(extras);
g_free ( extras );
}
/**
@ -117,7 +116,7 @@ static void parse_header_entry ( Mode *sw, char *line, ssize_t length )
length_key++;
}
if ( (length_key+1) < length ) {
if ( ( length_key + 1 ) < length ) {
line[length_key] = '\0';
char *value = line + length_key + 1;
if ( strcasecmp ( line, "message" ) == 0 ) {
@ -140,39 +139,38 @@ static void parse_header_entry ( Mode *sw, char *line, ssize_t length )
}
else if ( strcasecmp ( line, "delim" ) == 0 ) {
pd->delim = helper_parse_char ( value );
} else if ( strcasecmp ( line, "no-custom" ) == 0 ) {
pd->no_custom = ( strcasecmp ( value, "true") == 0 );
}
else if ( strcasecmp ( line, "no-custom" ) == 0 ) {
pd->no_custom = ( strcasecmp ( value, "true" ) == 0 );
}
}
}
static DmenuScriptEntry *execute_executor ( Mode *sw, char *arg, unsigned int *length, int value, DmenuScriptEntry *entry )
{
ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data;
int fd = -1;
GError *error = NULL;
DmenuScriptEntry *retv = NULL;
char **argv = NULL;
int argc = 0;
ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data;
int fd = -1;
GError *error = NULL;
DmenuScriptEntry *retv = NULL;
char **argv = NULL;
int argc = 0;
*length = 0;
// Environment
char ** env = g_get_environ ();
char *str_value = g_strdup_printf("%d", value);
env = g_environ_setenv ( env, "ROFI_RETV", str_value, TRUE);
char *str_value = g_strdup_printf ( "%d", value );
env = g_environ_setenv ( env, "ROFI_RETV", str_value, TRUE );
g_free ( str_value );
str_value = g_strdup_printf("%d", (int) getpid());
env = g_environ_setenv ( env, "ROFI_OUTSIDE", str_value, TRUE);
str_value = g_strdup_printf ( "%d", (int) getpid () );
env = g_environ_setenv ( env, "ROFI_OUTSIDE", str_value, TRUE );
g_free ( str_value );
if ( entry && entry->info ) {
env = g_environ_setenv ( env, "ROFI_INFO", entry->info, TRUE);
env = g_environ_setenv ( env, "ROFI_INFO", entry->info, TRUE );
}
if ( g_shell_parse_argv ( sw->ed, &argc, &argv, &error ) ) {
argv = g_realloc ( argv, ( argc + 2 ) * sizeof ( char* ) );
argv[argc] = g_strdup ( arg );
@ -181,7 +179,7 @@ static DmenuScriptEntry *execute_executor ( Mode *sw, char *arg, unsigned int *l
}
g_strfreev ( env );
if ( error != NULL ) {
char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", (char*)sw->ed, error->message );
char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", (char *) sw->ed, error->message );
rofi_view_error_dialog ( msg, FALSE );
g_free ( msg );
// print error.
@ -249,7 +247,7 @@ static int script_mode_init ( Mode *sw )
{
if ( sw->private_data == NULL ) {
ScriptModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
pd->delim = '\n';
pd->delim = '\n';
sw->private_data = (void *) pd;
pd->cmd_list = execute_executor ( sw, NULL, &( pd->cmd_list_length ), 0, NULL );
}
@ -290,11 +288,13 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned
//retv = 1+( mretv & MENU_LOWER_MASK );
script_mode_reset_highlight ( sw );
if ( selected_line != UINT32_MAX ) {
new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length,10+( mretv & MENU_LOWER_MASK ), &(rmpd->cmd_list[selected_line]) );
} else {
new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length, 10 + ( mretv & MENU_LOWER_MASK ), &( rmpd->cmd_list[selected_line] ) );
}
else {
if ( rmpd->no_custom == FALSE ) {
new_list = execute_executor ( sw, *input, &new_length,10+( mretv & MENU_LOWER_MASK ), NULL );
} else {
new_list = execute_executor ( sw, *input, &new_length, 10 + ( mretv & MENU_LOWER_MASK ), NULL );
}
else {
return RELOAD_DIALOG;
}
}
@ -304,13 +304,14 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned
return RELOAD_DIALOG;
}
script_mode_reset_highlight ( sw );
new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length, 1, &(rmpd->cmd_list[selected_line]) );
new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length, 1, &( rmpd->cmd_list[selected_line] ) );
}
else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) {
if ( rmpd->no_custom == FALSE ) {
script_mode_reset_highlight ( sw );
new_list = execute_executor ( sw, *input, &new_length, 2 , NULL );
} else {
new_list = execute_executor ( sw, *input, &new_length, 2, NULL );
}
else {
return RELOAD_DIALOG;
}
}

View file

@ -519,7 +519,7 @@ static SshEntry * get_ssh ( SSHModePrivateData *pd, unsigned int *length )
g_free ( path );
for ( GList *iter = g_list_first ( pd->user_known_hosts ); iter; iter = g_list_next ( iter ) ) {
char *path = rofi_expand_path ( (const char *) iter->data );
retv = read_known_hosts_file ( (const char*) path, retv, length );
retv = read_known_hosts_file ( (const char *) path, retv, length );
g_free ( path );
}
}

View file

@ -464,7 +464,7 @@ static const char * _window_name_list_entry ( const char *str, uint32_t length,
}
offset++;
}
if ( offset >= length ){
if ( offset >= length ) {
return invalid_desktop_name;
}
return &str[offset];

View file

@ -133,64 +133,66 @@ void rofi_icon_fetcher_destroy ( void )
g_free ( rofi_icon_fetcher_data );
}
static cairo_surface_t* cairo_image_surface_create_from_jpeg_private ( struct jpeg_decompress_struct* cinfo )
{
cairo_surface_t* surface = 0;
unsigned char * data = 0;
unsigned char * rgb = 0;
jpeg_read_header ( cinfo, TRUE );
jpeg_start_decompress ( cinfo );
static cairo_surface_t* cairo_image_surface_create_from_jpeg_private(struct jpeg_decompress_struct* cinfo) {
cairo_surface_t* surface = 0;
unsigned char* data = 0;
unsigned char* rgb = 0;
surface = cairo_image_surface_create ( CAIRO_FORMAT_RGB24, cinfo->image_width, cinfo->image_height );
data = cairo_image_surface_get_data ( surface );
rgb = (unsigned char *) ( malloc ( cinfo->output_width * cinfo->output_components ) );
jpeg_read_header(cinfo, TRUE);
jpeg_start_decompress(cinfo);
while ( cinfo->output_scanline < cinfo->output_height ) {
unsigned int i;
int scanline = cinfo->output_scanline * cairo_image_surface_get_stride ( surface );
surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, cinfo->image_width, cinfo->image_height);
data = cairo_image_surface_get_data(surface);
rgb = (unsigned char*)(malloc(cinfo->output_width * cinfo->output_components));
jpeg_read_scanlines ( cinfo, &rgb, 1 );
while(cinfo->output_scanline < cinfo->output_height) {
unsigned int i;
int scanline = cinfo->output_scanline * cairo_image_surface_get_stride(surface);
for ( i = 0; i < cinfo->output_width; i++ ) {
int offset = scanline + ( i * 4 );
jpeg_read_scanlines(cinfo, &rgb, 1);
data[offset + 3] = 255;
data[offset + 2] = rgb[( i * 3 )];
data[offset + 1] = rgb[( i * 3 ) + 1];
data[offset ] = rgb[( i * 3 ) + 2];
}
}
for(i = 0; i < cinfo->output_width; i++) {
int offset = scanline + (i * 4);
free ( rgb );
data[offset + 3] = 255;
data[offset + 2] = rgb[(i * 3)];
data[offset + 1] = rgb[(i * 3) + 1];
data[offset ] = rgb[(i * 3) + 2];
}
}
jpeg_finish_decompress ( cinfo );
jpeg_destroy_decompress ( cinfo );
free(rgb);
cairo_surface_mark_dirty ( surface );
jpeg_finish_decompress(cinfo);
jpeg_destroy_decompress(cinfo);
cairo_surface_mark_dirty(surface);
return surface;
return surface;
}
static cairo_surface_t* cairo_image_surface_create_from_jpeg(const char* file) {
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
cairo_surface_t* surface;
FILE* infile;
static cairo_surface_t* cairo_image_surface_create_from_jpeg ( const char* file )
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
cairo_surface_t * surface;
FILE * infile;
if((infile = fopen(file, "rb")) == NULL) return NULL;
if ( ( infile = fopen ( file, "rb" ) ) == NULL ) {
return NULL;
}
cinfo.err = jpeg_std_error(&jerr);
cinfo.err = jpeg_std_error ( &jerr );
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, infile);
jpeg_create_decompress ( &cinfo );
jpeg_stdio_src ( &cinfo, infile );
surface = cairo_image_surface_create_from_jpeg_private(&cinfo);
surface = cairo_image_surface_create_from_jpeg_private ( &cinfo );
fclose(infile);
fclose ( infile );
return surface;
return surface;
}
static void rofi_icon_fetcher_worker ( thread_state *sdata, G_GNUC_UNUSED gpointer user_data )
@ -235,29 +237,26 @@ static void rofi_icon_fetcher_worker ( thread_state *sdata, G_GNUC_UNUSED gpoint
}
if ( icon_surf ) {
if ( cairo_surface_status ( icon_surf ) == CAIRO_STATUS_SUCCESS ) {
float sw = sentry->size/(float)cairo_image_surface_get_width( icon_surf );
float sh = sentry->size/(float)cairo_image_surface_get_height( icon_surf );
float sw = sentry->size / (float) cairo_image_surface_get_width ( icon_surf );
float sh = sentry->size / (float) cairo_image_surface_get_height ( icon_surf );
float scale = ( sw > sh)? sh:sw;
if ( scale < 0.5 )
{
cairo_surface_t * surface = cairo_image_surface_create(
cairo_image_surface_get_format( icon_surf ),
cairo_image_surface_get_width( icon_surf )*scale,
cairo_image_surface_get_height( icon_surf )*scale);
float scale = ( sw > sh ) ? sh : sw;
if ( scale < 0.5 ) {
cairo_surface_t * surface = cairo_image_surface_create (
cairo_image_surface_get_format ( icon_surf ),
cairo_image_surface_get_width ( icon_surf ) * scale,
cairo_image_surface_get_height ( icon_surf ) * scale );
cairo_t *d = cairo_create ( surface );
cairo_scale ( d, scale, scale );
cairo_set_source_surface ( d, icon_surf, 0.0,0.0);
cairo_pattern_set_filter (cairo_get_source (d), CAIRO_FILTER_FAST);
cairo_set_source_surface ( d, icon_surf, 0.0, 0.0 );
cairo_pattern_set_filter ( cairo_get_source ( d ), CAIRO_FILTER_FAST );
cairo_paint ( d );
cairo_destroy ( d );
cairo_surface_destroy ( icon_surf );
icon_surf = surface;
}
}
// check if surface is valid.
if ( cairo_surface_status ( icon_surf ) != CAIRO_STATUS_SUCCESS ) {

View file

@ -193,10 +193,10 @@ static void run_switcher ( ModeMode mode )
RofiViewState * state = rofi_view_create ( modi[mode], config.filter, 0, process_result );
// User can pre-select a row.
if ( find_arg ( "-selected-row" ) >= 0 ){
unsigned int sr = 0;
find_arg_uint ( "-selected-row", &(sr) );
rofi_view_set_selected_line ( state, sr );
if ( find_arg ( "-selected-row" ) >= 0 ) {
unsigned int sr = 0;
find_arg_uint ( "-selected-row", &( sr ) );
rofi_view_set_selected_line ( state, sr );
}
if ( state ) {
rofi_view_set_active ( state );
@ -512,7 +512,7 @@ static void rofi_collect_modi_dir ( const char *base_dir )
if ( !g_str_has_suffix ( dn, G_MODULE_SUFFIX ) ) {
continue;
}
char *fn = g_build_filename ( base_dir, dn, NULL );
char *fn = g_build_filename ( base_dir, dn, NULL );
g_debug ( "Trying to open: %s plugin", fn );
GModule *mod = g_module_open ( fn, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL );
if ( mod ) {
@ -565,7 +565,7 @@ static void rofi_collect_modi ( void )
g_debug ( "Parse plugin path: %s", config.plugin_path );
rofi_collect_modi_dir ( config.plugin_path );
/* ROFI_PLUGIN_PATH */
const char *path = g_getenv("ROFI_PLUGIN_PATH");
const char *path = g_getenv ( "ROFI_PLUGIN_PATH" );
if ( path != NULL ) {
gchar ** paths = g_strsplit ( path, ":", -1 );
for ( unsigned int i = 0; paths[i]; i++ ) {
@ -789,12 +789,12 @@ int main ( int argc, char *argv[] )
}
{
const char *ro_pid = g_getenv("ROFI_OUTSIDE");
const char *ro_pid = g_getenv ( "ROFI_OUTSIDE" );
if ( ro_pid != NULL ) {
int ro_pidi = g_ascii_strtoll ( ro_pid, NULL, 0 );
if ( kill ( ro_pidi, 0 ) == 0 ) {
printf ( "Do not launch rofi from inside rofi.\r\n" );
return EXIT_FAILURE;
printf ( "Do not launch rofi from inside rofi.\r\n" );
return EXIT_FAILURE;
}
}
}
@ -880,40 +880,41 @@ int main ( int argc, char *argv[] )
if ( find_arg ( "-no-config" ) < 0 ) {
// Load distro default settings
gboolean found_system = FALSE;
const char * const * dirs = g_get_system_config_dirs();
if ( dirs )
{
for ( unsigned int i =0; !found_system && dirs[i]; i++ ) {
gboolean found_system = FALSE;
const char * const * dirs = g_get_system_config_dirs ();
if ( dirs ) {
for ( unsigned int i = 0; !found_system && dirs[i]; i++ ) {
/** New format. */
gchar *etc = g_build_filename ( dirs[i], "rofi.rasi", NULL );
g_debug ( "Look for default config file: %s", etc );
if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) {
g_debug ( "Parsing: %s", etc );
rofi_theme_parse_file ( etc );
found_system = TRUE;
} else {
found_system = TRUE;
}
else {
/** Old format. */
gchar *xetc = g_build_filename ( dirs[i], "rofi.conf", NULL );
g_debug ( "Look for default config file: %s", xetc );
if ( g_file_test ( xetc, G_FILE_TEST_IS_REGULAR ) ) {
config_parse_xresource_options_file ( xetc );
old_config_format = TRUE;
found_system = TRUE;
found_system = TRUE;
}
g_free ( xetc );
}
g_free ( etc );
}
}
if ( ! found_system ) {
if ( !found_system ) {
/** New format. */
gchar *etc = g_build_filename ( SYSCONFDIR, "rofi.rasi", NULL );
g_debug ( "Look for default config file: %s", etc );
if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) {
g_debug ( "Look for default config file: %s", etc );
rofi_theme_parse_file ( etc );
} else {
}
else {
/** Old format. */
gchar *xetc = g_build_filename ( SYSCONFDIR, "rofi.conf", NULL );
g_debug ( "Look for default config file: %s", xetc );

View file

@ -84,25 +84,23 @@ Property *rofi_theme_property_create ( PropertyType type )
static RofiDistanceUnit *rofi_theme_property_copy_distance_unit ( RofiDistanceUnit *unit )
{
RofiDistanceUnit *retv = g_slice_new0( RofiDistanceUnit );
*retv = *unit;
RofiDistanceUnit *retv = g_slice_new0 ( RofiDistanceUnit );
*retv = *unit;
if ( unit->left ) {
retv->left = rofi_theme_property_copy_distance_unit ( unit->left );
retv->left = rofi_theme_property_copy_distance_unit ( unit->left );
}
if ( unit->right ) {
retv->right = rofi_theme_property_copy_distance_unit ( unit->right );
retv->right = rofi_theme_property_copy_distance_unit ( unit->right );
}
return retv;
}
RofiDistance rofi_theme_property_copy_distance ( RofiDistance const distance )
{
RofiDistance retv = distance;
if ( distance.base.left )
{
if ( distance.base.left ) {
retv.base.left = rofi_theme_property_copy_distance_unit ( distance.base.left );
}
if ( distance.base.right )
{
if ( distance.base.right ) {
retv.base.right = rofi_theme_property_copy_distance_unit ( distance.base.right );
}
return retv;
@ -129,14 +127,14 @@ Property* rofi_theme_property_copy ( Property *p )
}
break;
case P_PADDING:
{
retv->value = p->value;
retv->value.padding.top = rofi_theme_property_copy_distance ( p->value.padding.top);
retv->value.padding.left = rofi_theme_property_copy_distance ( p->value.padding.left);
retv->value.padding.bottom = rofi_theme_property_copy_distance ( p->value.padding.bottom);
retv->value.padding.right = rofi_theme_property_copy_distance ( p->value.padding.right);
break;
}
{
retv->value = p->value;
retv->value.padding.top = rofi_theme_property_copy_distance ( p->value.padding.top );
retv->value.padding.left = rofi_theme_property_copy_distance ( p->value.padding.left );
retv->value.padding.bottom = rofi_theme_property_copy_distance ( p->value.padding.bottom );
retv->value.padding.right = rofi_theme_property_copy_distance ( p->value.padding.right );
break;
}
default:
retv->value = p->value;
}
@ -153,7 +151,7 @@ static void rofi_theme_distance_unit_property_free ( RofiDistanceUnit *unit )
rofi_theme_distance_unit_property_free ( unit->right );
unit->right = NULL;
}
g_slice_free ( RofiDistanceUnit, unit);
g_slice_free ( RofiDistanceUnit, unit );
}
static void rofi_theme_distance_property_free ( RofiDistance *distance )
{
@ -182,11 +180,11 @@ void rofi_theme_property_free ( Property *p )
rofi_theme_property_free ( p->value.link.def_value );
}
}
if ( p->type == P_PADDING) {
rofi_theme_distance_property_free( &(p->value.padding.top));
rofi_theme_distance_property_free( &(p->value.padding.right));
rofi_theme_distance_property_free( &(p->value.padding.bottom));
rofi_theme_distance_property_free( &(p->value.padding.left));
if ( p->type == P_PADDING ) {
rofi_theme_distance_property_free ( &( p->value.padding.top ) );
rofi_theme_distance_property_free ( &( p->value.padding.right ) );
rofi_theme_distance_property_free ( &( p->value.padding.bottom ) );
rofi_theme_distance_property_free ( &( p->value.padding.left ) );
}
g_slice_free ( Property, p );
}
@ -216,7 +214,7 @@ static void rofi_theme_insert_listview_backwards_fix ( void )
rofi_theme_widget_add_properties ( tt, table );
RofiDistance dsize = (RofiDistance){ .base = {1.2, ROFI_PU_CH, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID };
RofiDistance dsize = (RofiDistance){ .base = { 1.2, ROFI_PU_CH, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID };
Property *pts = rofi_theme_property_create ( P_PADDING );
pts->value.padding.top = pts->value.padding.right = pts->value.padding.bottom = pts->value.padding.left = dsize;
pts->name = g_strdup ( "size" );
@ -229,7 +227,7 @@ static void rofi_theme_insert_listview_backwards_fix ( void )
table = g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify) rofi_theme_property_free );
Property *psp = rofi_theme_property_create ( P_PADDING );
psp->name = g_strdup ( "spacing" );
RofiDistance d = (RofiDistance){ .base = {5, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID };
RofiDistance d = (RofiDistance){ .base = { 5, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID };
psp->value.padding = (RofiPadding){ d, d, d, d };
g_hash_table_replace ( table, psp->name, psp );
rofi_theme_widget_add_properties ( t, table );
@ -277,27 +275,33 @@ inline static void printf_double ( double d )
static void rofi_theme_print_distance_unit ( RofiDistanceUnit *unit )
{
if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP )
fputs("( " , stdout);
if ( unit->left )
if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) {
fputs ( "( ", stdout );
}
if ( unit->left ) {
rofi_theme_print_distance_unit ( unit->left );
}
if ( unit->modtype == ROFI_DISTANCE_MODIFIER_ADD ) {
fputs ( " + ", stdout );
} else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_SUBTRACT ) {
}
else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_SUBTRACT ) {
fputs ( " - ", stdout );
} else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_DIVIDE ) {
}
else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_DIVIDE ) {
fputs ( " / ", stdout );
} else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MULTIPLY) {
}
else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MULTIPLY ) {
fputs ( " * ", stdout );
} else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MODULO) {
}
else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MODULO ) {
fputs ( " % ", stdout );
}
if ( unit->right )
}
if ( unit->right ) {
rofi_theme_print_distance_unit ( unit->right );
if ( unit->modtype == ROFI_DISTANCE_MODIFIER_NONE )
{
}
if ( unit->modtype == ROFI_DISTANCE_MODIFIER_NONE ) {
if ( unit->type == ROFI_PU_PX ) {
printf ( "%upx ", (unsigned int) unit->distance );
}
@ -318,18 +322,19 @@ static void rofi_theme_print_distance_unit ( RofiDistanceUnit *unit )
fputs ( "em ", stdout );
}
}
if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP )
fputs(" )" , stdout);
if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) {
fputs ( " )", stdout );
}
}
static void rofi_theme_print_distance ( RofiDistance d )
{
if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ){
fputs( "calc( ", stdout );
if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ) {
fputs ( "calc( ", stdout );
}
rofi_theme_print_distance_unit ( &(d.base) );
if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ){
fputs( ")", stdout );
rofi_theme_print_distance_unit ( &( d.base ) );
if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ) {
fputs ( ")", stdout );
}
if ( d.style == ROFI_HL_DASH ) {
printf ( "dash " );
@ -746,17 +751,17 @@ RofiDistance rofi_theme_get_distance ( const widget *widget, const char *propert
if ( widget->parent ) {
return rofi_theme_get_distance ( widget->parent, property, def );
}
return (RofiDistance){ .base = {def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID };
return (RofiDistance){ .base = { def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID };
}
if ( p->type == P_INTEGER ) {
return (RofiDistance){ .base = { p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID };
return (RofiDistance){ .base = { p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID };
}
else {
return p->value.padding.left;
}
}
g_debug ( "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property );
return (RofiDistance){ .base = {def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID };
return (RofiDistance){ .base = { def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID };
}
int rofi_theme_get_boolean ( const widget *widget, const char *property, int def )
@ -872,7 +877,7 @@ RofiPadding rofi_theme_get_padding ( const widget *widget, const char *property,
pad = p->value.padding;
}
else {
RofiDistance d = (RofiDistance){ .base = {p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID };
RofiDistance d = (RofiDistance){ .base = { p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID };
return (RofiPadding){ d, d, d, d };
}
}
@ -927,7 +932,6 @@ static int get_pixels ( RofiDistanceUnit *unit, RofiOrientation ori )
{
int val = unit->distance;
if ( unit->type == ROFI_PU_EM ) {
val = unit->distance * textbox_get_estimated_char_height ();
}
@ -952,48 +956,46 @@ static int get_pixels ( RofiDistanceUnit *unit, RofiOrientation ori )
return val;
}
static int distance_unit_get_pixel ( RofiDistanceUnit *unit, RofiOrientation ori )
{
switch ( unit->modtype)
switch ( unit->modtype )
{
case ROFI_DISTANCE_MODIFIER_GROUP:
return distance_unit_get_pixel ( unit->left, ori );
break;
case ROFI_DISTANCE_MODIFIER_ADD:
return distance_unit_get_pixel ( unit->left, ori)+ distance_unit_get_pixel ( unit->right, ori);
case ROFI_DISTANCE_MODIFIER_SUBTRACT:
return distance_unit_get_pixel ( unit->left, ori)- distance_unit_get_pixel ( unit->right, ori);
case ROFI_DISTANCE_MODIFIER_MULTIPLY:
return distance_unit_get_pixel ( unit->left, ori)* distance_unit_get_pixel ( unit->right, ori);
case ROFI_DISTANCE_MODIFIER_DIVIDE:
{
int a = distance_unit_get_pixel ( unit->left, ori);
int b = distance_unit_get_pixel ( unit->right, ori);
if ( b != 0 ) {
return a/b;
}
return a;
}
case ROFI_DISTANCE_MODIFIER_MODULO:
{
int a = distance_unit_get_pixel ( unit->left, ori);
int b = distance_unit_get_pixel ( unit->right, ori);
if ( b != 0 ) {
return a%b;
}
return 0;
}
default:
break;
case ROFI_DISTANCE_MODIFIER_GROUP:
return distance_unit_get_pixel ( unit->left, ori );
break;
case ROFI_DISTANCE_MODIFIER_ADD:
return distance_unit_get_pixel ( unit->left, ori ) + distance_unit_get_pixel ( unit->right, ori );
case ROFI_DISTANCE_MODIFIER_SUBTRACT:
return distance_unit_get_pixel ( unit->left, ori ) - distance_unit_get_pixel ( unit->right, ori );
case ROFI_DISTANCE_MODIFIER_MULTIPLY:
return distance_unit_get_pixel ( unit->left, ori ) * distance_unit_get_pixel ( unit->right, ori );
case ROFI_DISTANCE_MODIFIER_DIVIDE:
{
int a = distance_unit_get_pixel ( unit->left, ori );
int b = distance_unit_get_pixel ( unit->right, ori );
if ( b != 0 ) {
return a / b;
}
return a;
}
case ROFI_DISTANCE_MODIFIER_MODULO:
{
int a = distance_unit_get_pixel ( unit->left, ori );
int b = distance_unit_get_pixel ( unit->right, ori );
if ( b != 0 ) {
return a % b;
}
return 0;
}
default:
break;
}
return get_pixels ( unit, ori );
}
int distance_get_pixel ( RofiDistance d, RofiOrientation ori )
{
return distance_unit_get_pixel ( &(d.base), ori);
return distance_unit_get_pixel ( &( d.base ), ori );
}
void distance_get_linestyle ( RofiDistance d, cairo_t *draw )
@ -1016,13 +1018,13 @@ gboolean rofi_theme_is_empty ( void )
return TRUE;
}
if ( rofi_theme->num_widgets == 3 ) {
// HACK: check for default added elements.
for ( unsigned int i = 0; i < rofi_theme->num_widgets;i++) {
if ( strncmp ( rofi_theme->widgets[i]->name, "element", 7) != 0 ){
return FALSE;
// HACK: check for default added elements.
for ( unsigned int i = 0; i < rofi_theme->num_widgets; i++ ) {
if ( strncmp ( rofi_theme->widgets[i]->name, "element", 7 ) != 0 ) {
return FALSE;
}
}
}
return TRUE;
return TRUE;
}
return FALSE;
@ -1319,7 +1321,6 @@ ThemeMediaType rofi_theme_parse_media_type ( const char *type )
return THEME_MEDIA_TYPE_INVALID;
}
gboolean rofi_theme_has_property ( const widget *widget, const char *property )
{
ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE );

View file

@ -223,21 +223,21 @@ void rofi_capture_screenshot ( void )
g_date_time_unref ( now );
}
/**
* Code used for benchmarking drawing the gui, this will keep updating the UI as fast as possible.
*/
gboolean do_bench = TRUE;
struct {
GTimer *time;
struct
{
GTimer *time;
uint64_t draws;
double last_ts;
double min;
double last_ts;
double min;
} BenchMark = {
.time = NULL,
.draws = 0,
.time = NULL,
.draws = 0,
.last_ts = 0.0,
.min = G_MAXDOUBLE
.min = G_MAXDOUBLE
};
static gboolean bench_update ( void )
@ -247,17 +247,17 @@ static gboolean bench_update ( void )
}
BenchMark.draws++;
if ( BenchMark.time == NULL ) {
BenchMark.time = g_timer_new();
BenchMark.time = g_timer_new ();
}
if ( (BenchMark.draws & 1023) == 0 ){
double ts = g_timer_elapsed(BenchMark.time, NULL);
double fps = 1024/(ts-BenchMark.last_ts);
if ( ( BenchMark.draws & 1023 ) == 0 ) {
double ts = g_timer_elapsed ( BenchMark.time, NULL );
double fps = 1024 / ( ts - BenchMark.last_ts );
if ( fps < BenchMark.min ) {
BenchMark.min = fps;
}
printf("current: %.2f fps, avg: %.2f fps, min: %.2f fps, %lu draws\r\n", fps, BenchMark.draws/ts, BenchMark.min, BenchMark.draws);
printf ( "current: %.2f fps, avg: %.2f fps, min: %.2f fps, %lu draws\r\n", fps, BenchMark.draws / ts, BenchMark.min, BenchMark.draws );
BenchMark.last_ts = ts;
}
@ -279,7 +279,7 @@ static gboolean rofi_view_repaint ( G_GNUC_UNUSED void * data )
TICK_N ( "flush" );
CacheState.repaint_source = 0;
}
return (bench_update () == TRUE )? G_SOURCE_CONTINUE:G_SOURCE_REMOVE;
return ( bench_update () == TRUE ) ? G_SOURCE_CONTINUE : G_SOURCE_REMOVE;
}
static void rofi_view_update_prompt ( RofiViewState *state )
@ -785,8 +785,9 @@ void __create_window ( MenuFlags menu_flags )
PangoFontMap *font_map = pango_cairo_font_map_get_default ();
pango_cairo_font_map_set_resolution ( (PangoCairoFontMap *) font_map, dpi );
config.dpi = dpi;
} else {
// default pango is 96.
}
else {
// default pango is 96.
PangoFontMap *font_map = pango_cairo_font_map_get_default ();
config.dpi = pango_cairo_font_map_get_resolution ( (PangoCairoFontMap *) font_map );
}

View file

@ -231,7 +231,9 @@ static void hori_calculate_size ( box *b )
int left = widget_padding_get_left ( WIDGET ( b ) );
double rem = rem_width - b->max_size;
int index = 0;
if ( rem < 0 ) rem = 0;
if ( rem < 0 ) {
rem = 0;
}
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
if ( child->enabled == FALSE ) {
@ -332,7 +334,7 @@ static widget *box_find_mouse_target ( widget *wid, WidgetType type, gint x, gin
static void box_set_state ( widget *wid, const char *state )
{
for ( GList *iter = g_list_first ( ((box*)wid)->children ); iter != NULL; iter = g_list_next ( iter ) ) {
for ( GList *iter = g_list_first ( ( (box *) wid )->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
widget_set_state ( child, state );
}

View file

@ -45,10 +45,10 @@
/**
* Orientation of the listview
*/
/** Vertical (classical) list */
#define LISTVIEW ROFI_ORIENTATION_VERTICAL
/** Horizontal list. (barview) */
#define BARVIEW ROFI_ORIENTATION_HORIZONTAL
/** Vertical (classical) list */
#define LISTVIEW ROFI_ORIENTATION_VERTICAL
/** Horizontal list. (barview) */
#define BARVIEW ROFI_ORIENTATION_HORIZONTAL
/**
* The moving direction of the selection, this (in barview) affects the scrolling.
@ -69,7 +69,7 @@ typedef struct
struct _listview
{
widget widget;
widget widget;
RofiOrientation type;
@ -143,8 +143,8 @@ const char *const listview_theme_prop_names[][3] = {
static void listview_set_state ( _listview_row r, TextBoxFontType tbft )
{
widget *w = WIDGET(r.box);
TextBoxFontType t = tbft & STATE_MASK;
widget *w = WIDGET ( r.box );
TextBoxFontType t = tbft & STATE_MASK;
if ( w == NULL ) {
return;
}
@ -171,25 +171,25 @@ static void listview_add_widget ( listview *lv, _listview_row *row, widget *wid,
if ( strcasecmp ( label, "element-icon" ) == 0 ) {
if ( config.show_icons ) {
row->icon = icon_create ( WIDGET ( wid ), "element-icon" );
box_add ( (box *)wid, WIDGET ( row->icon ), FALSE );
box_add ( (box *) wid, WIDGET ( row->icon ), FALSE );
}
}
else if ( strcasecmp ( label, "element-text" ) == 0 ) {
row->textbox = textbox_create ( WIDGET ( wid ), WIDGET_TYPE_TEXTBOX_TEXT, "element-text", TB_AUTOHEIGHT | flags, NORMAL, "DDD", 0, 0 );
box_add ( (box *)wid, WIDGET ( row->textbox ), TRUE );
box_add ( (box *) wid, WIDGET ( row->textbox ), TRUE );
}
else if ( strcasecmp ( label, "element-index" ) == 0 ) {
row->index = textbox_create ( WIDGET ( wid ), WIDGET_TYPE_TEXTBOX_TEXT, "element-text", TB_AUTOHEIGHT, NORMAL, " ", 0, 0 );
box_add ( (box *)wid, WIDGET ( row->index ), FALSE );
} else {
box_add ( (box *) wid, WIDGET ( row->index ), FALSE );
}
else {
widget *wid2 = (widget *) box_create ( wid, label, ROFI_ORIENTATION_VERTICAL );
box_add ( (box *) wid, WIDGET ( wid2 ), TRUE );
GList *list = rofi_theme_get_list ( WIDGET ( wid2 ), "children", "" );
GList *list = rofi_theme_get_list ( WIDGET ( wid2 ), "children", "" );
for ( GList *iter = g_list_first ( list ); iter != NULL; iter = g_list_next ( iter ) ) {
listview_add_widget ( lv,row, wid2, (const char *)iter->data );
listview_add_widget ( lv, row, wid2, (const char *) iter->data );
}
}
}
static void listview_create_row ( listview *lv, _listview_row *row )
@ -203,7 +203,7 @@ static void listview_create_row ( listview *lv, _listview_row *row )
row->index = NULL;
for ( GList *iter = g_list_first ( list ); iter != NULL; iter = g_list_next ( iter ) ) {
listview_add_widget ( lv,row, WIDGET(row->box), (const char *)iter->data );
listview_add_widget ( lv, row, WIDGET ( row->box ), (const char *) iter->data );
}
g_list_free_full ( list, g_free );
}
@ -348,7 +348,7 @@ static void barview_draw ( widget *wid, cairo_t *draw )
else {
for ( unsigned int i = 0; i < lv->cur_elements && width > 0 && i <= offset; i++ ) {
update_element ( lv, i, offset - i, TRUE );
int twidth = widget_get_desired_width ( WIDGET ( lv->boxes[i].box ) );
int twidth = widget_get_desired_width ( WIDGET ( lv->boxes[i].box ) );
if ( twidth >= width ) {
if ( !first ) {
break;
@ -553,8 +553,8 @@ static void listview_resize ( widget *wid, short w, short h )
lv->max_elements = lv->max_rows * lv->menu_columns;
widget_move ( WIDGET ( lv->scrollbar ),
lv->widget.w - widget_padding_get_right ( WIDGET ( lv ) ) - widget_get_width ( WIDGET ( lv->scrollbar ) ),
widget_padding_get_top ( WIDGET ( lv ) ) );
lv->widget.w - widget_padding_get_right ( WIDGET ( lv ) ) - widget_get_width ( WIDGET ( lv->scrollbar ) ),
widget_padding_get_top ( WIDGET ( lv ) ) );
widget_resize ( WIDGET ( lv->scrollbar ), widget_get_width ( WIDGET ( lv->scrollbar ) ), height );
@ -661,10 +661,13 @@ listview *listview_create ( widget *parent, const char *name, listview_update_ca
listview_create_row ( lv, &row );
// FIXME: hack to scale hight correctly.
if ( lv->eh > 1 && row.textbox ) {
char buff[lv->eh*2+1] ;
memset( buff, '\0', lv->eh*2+1);
for ( unsigned int i = 0; i < (lv->eh-1); i++) { buff[i*2] = 'a'; buff[i*2+1] ='\n'; };
textbox_text( row.textbox, buff);
char buff[lv->eh * 2 + 1];
memset ( buff, '\0', lv->eh * 2 + 1 );
for ( unsigned int i = 0; i < ( lv->eh - 1 ); i++ ) {
buff[i * 2] = 'a'; buff[i * 2 + 1] = '\n';
}
;
textbox_text ( row.textbox, buff );
}
lv->element_height = widget_get_desired_height ( WIDGET ( row.box ) );
widget_free ( WIDGET ( row.box ) );

View file

@ -914,7 +914,7 @@ double textbox_get_estimated_ch ( void )
int textbox_get_estimated_height ( const textbox *tb, int eh )
{
int height = pango_font_metrics_get_ascent ( tb->metrics ) + pango_font_metrics_get_descent ( tb->metrics );
return ceil(( eh * height ) / (double)PANGO_SCALE) + widget_padding_get_padding_height ( WIDGET ( tb ) );
return ceil ( ( eh * height ) / (double) PANGO_SCALE ) + widget_padding_get_padding_height ( WIDGET ( tb ) );
}
int textbox_get_desired_width ( widget *wid )
{

View file

@ -33,7 +33,7 @@
/** Default padding. */
#define WIDGET_DEFAULT_PADDING 0
#define WIDGET_PADDING_INIT { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }
#define WIDGET_PADDING_INIT { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }
/* Corner radius - tl, tr, br, bl */
static void draw_rounded_rect ( cairo_t * d,
@ -41,27 +41,31 @@ static void draw_rounded_rect ( cairo_t * d,
double r0, double r1, double r2, double r3 )
{
if ( r0 > 0 ) {
cairo_move_to ( d, x1, y1+r0 );
cairo_arc ( d, x1+r0, y1+r0, r0, -G_PI, -G_PI_2 );
} else {
cairo_move_to ( d, x1, y1 + r0 );
cairo_arc ( d, x1 + r0, y1 + r0, r0, -G_PI, -G_PI_2 );
}
else {
cairo_move_to ( d, x1, y1 );
}
if ( r1 > 0 ) {
cairo_line_to ( d, x2-r1, y1 );
cairo_arc ( d, x2-r1, y1+r1, r1, -G_PI_2, 0.0 );
} else {
cairo_line_to ( d, x2 - r1, y1 );
cairo_arc ( d, x2 - r1, y1 + r1, r1, -G_PI_2, 0.0 );
}
else {
cairo_line_to ( d, x2, y1 );
}
if ( r2 > 0 ) {
cairo_line_to ( d, x2, y2-r2 );
cairo_arc ( d, x2-r2, y2-r2, r2, 0.0, G_PI_2 );
} else {
cairo_line_to ( d, x2, y2 - r2 );
cairo_arc ( d, x2 - r2, y2 - r2, r2, 0.0, G_PI_2 );
}
else {
cairo_line_to ( d, x2, y2 );
}
if ( r3 > 0 ) {
cairo_line_to ( d, x1+r3, y2 );
cairo_arc ( d, x1+r3, y2-r3, r3, G_PI_2, G_PI );
} else {
cairo_line_to ( d, x1 + r3, y2 );
cairo_arc ( d, x1 + r3, y2 - r3, r3, G_PI_2, G_PI );
}
else {
cairo_line_to ( d, x1, y2 );
}
cairo_close_path ( d );
@ -69,9 +73,9 @@ static void draw_rounded_rect ( cairo_t * d,
void widget_init ( widget *wid, widget *parent, WidgetType type, const char *name )
{
wid->type = type;
wid->parent = parent;
wid->name = g_strdup ( name );
wid->type = type;
wid->parent = parent;
wid->name = g_strdup ( name );
wid->def_padding = (RofiPadding) { WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT };
wid->def_border = (RofiPadding) { WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT };
wid->def_border_radius = (RofiPadding) { WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT, WIDGET_PADDING_INIT };
@ -205,23 +209,23 @@ void widget_draw ( widget *widget, cairo_t *d )
int radius_tl = distance_get_pixel ( widget->border_radius.top, ROFI_ORIENTATION_VERTICAL );
int radius_br = distance_get_pixel ( widget->border_radius.bottom, ROFI_ORIENTATION_VERTICAL );
double minof_tl, minof_tr, minof_br, minof_bl;
double minof_tl, minof_tr, minof_br, minof_bl;
{
double left_2 = (double) left / 2;
double top_2 = (double) top / 2;
double right_2 = (double) right / 2;
double left_2 = (double) left / 2;
double top_2 = (double) top / 2;
double right_2 = (double) right / 2;
double bottom_2 = (double) bottom / 2;
// Calculate the different offsets for the corners.
minof_tl = MIN ( left_2, top_2 );
minof_tl = MIN ( left_2, top_2 );
minof_tr = MIN ( right_2, top_2 );
minof_br = MIN ( right_2, bottom_2 );
minof_bl = MIN ( left_2, bottom_2 );
minof_bl = MIN ( left_2, bottom_2 );
// Contain border radius in widget space
double vspace, vspace_2, hspace, hspace_2;
vspace = widget->h - ( margin_top + margin_bottom ) - ( top_2 + bottom_2 );
hspace = widget->w - ( margin_left + margin_right ) - ( left_2 + right_2 );
vspace = widget->h - ( margin_top + margin_bottom ) - ( top_2 + bottom_2 );
hspace = widget->w - ( margin_left + margin_right ) - ( left_2 + right_2 );
vspace_2 = vspace / 2;
hspace_2 = hspace / 2;
@ -249,9 +253,9 @@ void widget_draw ( widget *widget, cairo_t *d )
cairo_set_line_width ( d, 0 );
draw_rounded_rect ( d,
margin_left + ( left > 2 ? left - 1 : left == 1 ? 0.5 : 0 ),
margin_top + ( top > 2 ? top - 1 : top == 1 ? 0.5 : 0 ),
widget->w - margin_right - ( right > 2 ? right - 1 : right == 1 ? 0.5 : 0 ),
margin_left + ( left > 2 ? left - 1 : left == 1 ? 0.5 : 0 ),
margin_top + ( top > 2 ? top - 1 : top == 1 ? 0.5 : 0 ),
widget->w - margin_right - ( right > 2 ? right - 1 : right == 1 ? 0.5 : 0 ),
widget->h - margin_bottom - ( bottom > 2 ? bottom - 1 : bottom == 1 ? 0.5 : 0 ),
radius_tl - ( minof_tl > 1 ? minof_tl - 1 : 0 ),
radius_tr - ( minof_tr > 1 ? minof_tr - 1 : 0 ),
@ -277,28 +281,32 @@ void widget_draw ( widget *widget, cairo_t *d )
double radius_int_tl, radius_int_tr, radius_int_br, radius_int_bl;
double radius_out_tl, radius_out_tr, radius_out_br, radius_out_bl;
if (radius_tl > 0) {
radius_out_tl = radius_tl + minof_tl ,
if ( radius_tl > 0 ) {
radius_out_tl = radius_tl + minof_tl,
radius_int_tl = radius_tl - minof_tl;
} else {
}
else {
radius_out_tl = radius_int_tl = 0;
}
if (radius_tr > 0) {
radius_out_tr = radius_tr + minof_tr ,
if ( radius_tr > 0 ) {
radius_out_tr = radius_tr + minof_tr,
radius_int_tr = radius_tr - minof_tr;
} else {
}
else {
radius_out_tr = radius_int_tr = 0;
}
if (radius_br > 0) {
radius_out_br = radius_br + minof_br ,
if ( radius_br > 0 ) {
radius_out_br = radius_br + minof_br,
radius_int_br = radius_br - minof_br;
} else {
}
else {
radius_out_br = radius_int_br = 0;
}
if (radius_bl > 0) {
radius_out_bl = radius_bl + minof_bl ,
if ( radius_bl > 0 ) {
radius_out_bl = radius_bl + minof_bl,
radius_int_bl = radius_bl - minof_bl;
} else {
}
else {
radius_out_bl = radius_int_bl = 0;
}
@ -314,7 +322,7 @@ void widget_draw ( widget *widget, cairo_t *d )
cairo_new_sub_path ( d );
draw_rounded_rect ( d,
margin_left + left,
margin_top + top,
margin_top + top,
widget->w - margin_right - right,
widget->h - margin_bottom - bottom,
radius_int_tl,
@ -416,7 +424,7 @@ gboolean widget_need_redraw ( widget *wid )
if ( wid == NULL ) {
return FALSE;
}
if ( ! wid->enabled ) {
if ( !wid->enabled ) {
return FALSE;
}
return wid->need_redraw;

View file

@ -485,7 +485,7 @@ static gboolean __config_parser_set_property ( XrmOption *option, const Property
return TRUE;
}
*( option->value.charc ) = ( p->value.c );
option->source = CONFIG_FILE_THEME;
option->source = CONFIG_FILE_THEME;
}
else {
// TODO add type