1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-04-14 17:43:01 -04:00

[CodeChecker] Several small fixes of detected bugs

This commit is contained in:
Qball 2025-02-18 11:47:07 +01:00
parent b61d60dff0
commit 542846c0f9
28 changed files with 215 additions and 168 deletions

View file

@ -1319,40 +1319,40 @@ void rofi_output_formatted_line(const char *format, const char *string,
int selected_line, const char *filter) {
for (int i = 0; format && format[i]; i++) {
if (format[i] == 'i') {
fprintf(stdout, "%d", selected_line);
(void)fprintf(stdout, "%d", selected_line);
} else if (format[i] == 'd') {
fprintf(stdout, "%d", (selected_line + 1));
(void)fprintf(stdout, "%d", (selected_line + 1));
} else if (format[i] == 's') {
fputs(string, stdout);
(void)fputs(string, stdout);
} else if (format[i] == 'p') {
char *esc = NULL;
pango_parse_markup(string, -1, 0, NULL, &esc, NULL, NULL);
if (esc) {
fputs(esc, stdout);
(void)fputs(esc, stdout);
g_free(esc);
} else {
fputs("invalid string", stdout);
(void)fputs("invalid string", stdout);
}
} else if (format[i] == 'q') {
char *quote = g_shell_quote(string);
fputs(quote, stdout);
(void)fputs(quote, stdout);
g_free(quote);
} else if (format[i] == 'f') {
if (filter) {
fputs(filter, stdout);
(void)fputs(filter, stdout);
}
} else if (format[i] == 'F') {
if (filter) {
char *quote = g_shell_quote(filter);
fputs(quote, stdout);
(void)fputs(quote, stdout);
g_free(quote);
}
} else {
fputc(format[i], stdout);
(void)fputc(format[i], stdout);
}
}
fputc('\n', stdout);
fflush(stdout);
(void)fputc('\n', stdout);
(void)fflush(stdout);
}
static gboolean helper_eval_cb2(const GMatchInfo *info, GString *res,

View file

@ -73,7 +73,7 @@ static void __history_write_element_list(FILE *fd, _element **list,
// Write out entries.
for (unsigned int iter = 0; iter < length; iter++) {
fprintf(fd, "%ld %s\n", list[iter]->index - min_value, list[iter]->name);
(void)fprintf(fd, "%ld %s\n", list[iter]->index - min_value, list[iter]->name);
}
}

View file

@ -123,9 +123,10 @@ char *mode_get_completion(const Mode *mode, unsigned int selected_line) {
if (mode->_get_completion != NULL) {
return mode->_get_completion(mode, selected_line);
}
int state;
int state = 0;
g_assert(mode->_get_display_value != NULL);
return mode->_get_display_value(mode, selected_line, &state, NULL, TRUE);
char *retv = mode->_get_display_value(mode, selected_line, &state, NULL, TRUE);
return retv;
}
ModeMode mode_result(Mode *mode, int menu_retv, char **input,
@ -203,10 +204,11 @@ const char *mode_get_display_name(const Mode *mode) {
}
void mode_set_config(Mode *mode) {
snprintf(mode->cfg_name_key, 128, "display-%s", mode->name);
config_parser_add_option(xrm_String, mode->cfg_name_key,
(void **)&(mode->display_name),
"The display name of this browser");
if (snprintf(mode->cfg_name_key, 128, "display-%s", mode->name) > 0 ){
config_parser_add_option(xrm_String, mode->cfg_name_key,
(void **)&(mode->display_name),
"The display name of this browser");
}
}
char *mode_preprocess_input(Mode *mode, const char *input) {

View file

@ -254,8 +254,9 @@ static char *combi_mgrv(const Mode *sw, unsigned int selected_line, int *state,
wid, P_COLOR, pd->switchers[i].mode->name, TRUE);
if (p != NULL) {
PangoAttribute *pa = pango_attr_foreground_new(
p->value.color.red * 65535, p->value.color.green * 65535,
p->value.color.blue * 65535);
(guint16)(p->value.color.red * UINT16_MAX),
(guint16)(p->value.color.green * UINT16_MAX),
(guint16)(p->value.color.blue * UINT16_MAX));
pa->start_index = PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING;
pa->end_index = strlen(dname);
*attr_list = g_list_append(*attr_list, pa);

View file

@ -753,7 +753,7 @@ static void dmenu_finish(DmenuModePrivateData *pd, RofiViewState *state,
}
if (pd->fd_file != NULL) {
if (pd->fd_file != stdin) {
fclose(pd->fd_file);
(void)fclose(pd->fd_file);
}
}
if (retv == FALSE) {

View file

@ -953,17 +953,25 @@ static gint drun_int_sort_list(gconstpointer a, gconstpointer b,
/** Version of the DRUN cache file format. */
#define CACHE_VERSION 3
static void drun_write_str(FILE *fd, const char *str) {
static int drun_write_str(FILE *fd, const char *str) {
size_t l = (str == NULL ? 0 : strlen(str));
fwrite(&l, sizeof(l), 1, fd);
if(fwrite(&l, sizeof(l), 1, fd)<=0){
return 1;
}
// Only write string if it is not NULL or empty.
if (l > 0) {
// Also writeout terminating '\0'
fwrite(str, 1, l + 1, fd);
if ( fwrite(str, 1, l + 1, fd) <= 0 ){
return 1;
}
}
return 0;
}
static void drun_write_integer(FILE *fd, int32_t val) {
fwrite(&val, sizeof(val), 1, fd);
static int drun_write_integer(FILE *fd, int32_t val) {
if ( fwrite(&val, sizeof(val), 1, fd) <= 0 ){
return 1;
}
return 0;
}
static gboolean drun_read_integer(FILE *fd, int32_t *type) {
if (fread(type, sizeof(int32_t), 1, fd) != 1) {
@ -993,9 +1001,13 @@ static gboolean drun_read_string(FILE *fd, char **str) {
}
static void drun_write_strv(FILE *fd, char **str) {
guint vl = (str == NULL ? 0 : g_strv_length(str));
fwrite(&vl, sizeof(vl), 1, fd);
if ( fwrite(&vl, sizeof(vl), 1, fd) <= 0 ){
return;
}
for (guint index = 0; index < vl; index++) {
drun_write_str(fd, str[index]);
if ( drun_write_str(fd, str[index])){
return ;
}
}
}
static gboolean drun_read_stringv(FILE *fd, char ***str) {
@ -1029,9 +1041,17 @@ static void write_cache(DRunModePrivateData *pd, const char *cache_file) {
return;
}
uint8_t version = CACHE_VERSION;
fwrite(&version, sizeof(version), 1, fd);
if ( fwrite(&version, sizeof(version), 1, fd) <= 0 ){
g_warning("Failed to write to drun cache file.");
(void)(void)fclose(fd);
return;
}
fwrite(&(pd->cmd_list_length), sizeof(pd->cmd_list_length), 1, fd);
if ( fwrite(&(pd->cmd_list_length), sizeof(pd->cmd_list_length), 1, fd) <= 0){
g_warning("Failed to write to drun cache file.");
(void)(void)fclose(fd);
return;
}
for (unsigned int index = 0; index < pd->cmd_list_length; index++) {
DRunModeEntry *entry = &(pd->entry_list[index]);
@ -1053,7 +1073,7 @@ static void write_cache(DRunModePrivateData *pd, const char *cache_file) {
drun_write_integer(fd, (int32_t)entry->type);
}
fclose(fd);
(void)(void)fclose(fd);
TICK_N("DRUN Write CACHE: end");
}
@ -1080,21 +1100,21 @@ static gboolean drun_read_cache(DRunModePrivateData *pd,
uint8_t version = 0;
if (fread(&version, sizeof(version), 1, fd) != 1) {
fclose(fd);
(void)fclose(fd);
g_warning("Cache corrupt, ignoring.");
TICK_N("DRUN Read CACHE: stop");
return TRUE;
}
if (version != CACHE_VERSION) {
fclose(fd);
(void)fclose(fd);
g_warning("Cache file wrong version, ignoring.");
TICK_N("DRUN Read CACHE: stop");
return TRUE;
}
if (fread(&(pd->cmd_list_length), sizeof(pd->cmd_list_length), 1, fd) != 1) {
fclose(fd);
(void)fclose(fd);
g_warning("Cache corrupt, ignoring.");
TICK_N("DRUN Read CACHE: stop");
return TRUE;
@ -1171,7 +1191,7 @@ static gboolean drun_read_cache(DRunModePrivateData *pd,
entry->type = type;
}
fclose(fd);
(void)fclose(fd);
if (error) {
for (size_t i = 0; i < pd->cmd_list_length; i++) {
drun_entry_clear(&(pd->entry_list[i]));

View file

@ -636,7 +636,7 @@ Mode *script_mode_parse_setup(const char *str) {
return sw;
}
fprintf(
(void)fprintf(
stderr,
"The script command '%s' has %u options, but needs 2: <name>:<script>.",
str, index);

View file

@ -989,9 +989,9 @@ static cairo_surface_t *draw_surface_from_data(uint32_t width, uint32_t height,
for (i = 0; i < len; i++) {
uint8_t a = (data[i] >> 24) & 0xff;
double alpha = a / 255.0;
uint8_t r = ((data[i] >> 16) & 0xff) * alpha;
uint8_t g = ((data[i] >> 8) & 0xff) * alpha;
uint8_t b = ((data[i] >> 0) & 0xff) * alpha;
uint8_t r = (uint8_t)(((data[i] >> 16) & 0xff) * alpha);
uint8_t g = (uint8_t)(((data[i] >> 8) & 0xff) * alpha);
uint8_t b = (uint8_t)(((data[i] >> 0) & 0xff) * alpha);
buffer[i] = (a << 24) | (r << 16) | (g << 8) | b;
}

View file

@ -641,7 +641,7 @@ static void rofi_icon_fetcher_worker(thread_state *sdata,
}
// no suitable icon or thumbnail was found
if (icon_path_ == NULL || !g_file_test(icon_path, G_FILE_TEST_EXISTS)) {
if (icon_path_ == NULL || !g_file_test(icon_path_, G_FILE_TEST_EXISTS)) {
sentry->query_done = TRUE;
rofi_view_reload();
return;

View file

@ -447,9 +447,9 @@ static void help_print_disabled_mode(const char *mode) {
int is_term = isatty(fileno(stdout));
// Only output to terminal
if (is_term) {
fprintf(stderr, "Mode %s%s%s is not enabled. I have enabled it for now.\n",
(void)fprintf(stderr, "Mode %s%s%s is not enabled. I have enabled it for now.\n",
color_red, mode, color_reset);
fprintf(stderr,
(void)fprintf(stderr,
"Please consider adding %s%s%s to the list of enabled modes: "
"%smodes: [%s%s%s,%s]%s.\n",
color_red, mode, color_reset, color_green, config.modes,
@ -789,8 +789,8 @@ static gboolean startup(G_GNUC_UNUSED gpointer data) {
if (list_of_warning_msgs != NULL) {
for (GList *iter = g_list_first(list_of_warning_msgs); iter != NULL;
iter = g_list_next(iter)) {
fputs(((GString *)iter->data)->str, stderr);
fputs("\n", stderr);
(void)fputs(((GString *)iter->data)->str, stderr);
(void)fputs("\n", stderr);
}
}
// Dmenu mode.
@ -939,7 +939,7 @@ int main(int argc, char *argv[]) {
cleanup();
return retv;
}
fprintf(stderr, "Usage: %s -rasi-validate my-theme.rasi", argv[0]);
(void)fprintf(stderr, "Usage: %s -rasi-validate my-theme.rasi", argv[0]);
return EXIT_FAILURE;
}
@ -1266,13 +1266,13 @@ int rofi_theme_rasi_validate(const char *filename) {
for (GList *iter = g_list_first(list_of_error_msgs); iter != NULL;
iter = g_list_next(iter)) {
fputs(((GString *)iter->data)->str, stderr);
fputs("\n", stderr);
(void)fputs(((GString *)iter->data)->str, stderr);
(void)fputs("\n", stderr);
}
for (GList *iter = g_list_first(list_of_warning_msgs); iter != NULL;
iter = g_list_next(iter)) {
fputs(((GString *)iter->data)->str, stderr);
fputs("\n", stderr);
(void)fputs(((GString *)iter->data)->str, stderr);
(void)fputs("\n", stderr);
}
return EXIT_FAILURE;

View file

@ -264,37 +264,37 @@ inline static void printf_double(double d) {
0,
};
g_ascii_formatd(buf, G_ASCII_DTOSTR_BUF_SIZE, "%.4f", d);
fputs(buf, stdout);
(void)fputs(buf, stdout);
}
static void rofi_theme_print_distance_unit(RofiDistanceUnit *unit) {
if (unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP) {
fputs("( ", stdout);
(void)fputs("( ", stdout);
}
if (unit->left) {
rofi_theme_print_distance_unit(unit->left);
}
if (unit->modtype == ROFI_DISTANCE_MODIFIER_ADD) {
fputs(" + ", stdout);
(void)fputs(" + ", stdout);
} else if (unit->modtype == ROFI_DISTANCE_MODIFIER_SUBTRACT) {
fputs(" - ", stdout);
(void)fputs(" - ", stdout);
} else if (unit->modtype == ROFI_DISTANCE_MODIFIER_DIVIDE) {
fputs(" / ", stdout);
(void)fputs(" / ", stdout);
} else if (unit->modtype == ROFI_DISTANCE_MODIFIER_MULTIPLY) {
fputs(" * ", stdout);
(void)fputs(" * ", stdout);
} else if (unit->modtype == ROFI_DISTANCE_MODIFIER_MODULO) {
fputs(" modulo ", stdout);
(void)fputs(" modulo ", stdout);
} else if (unit->modtype == ROFI_DISTANCE_MODIFIER_MIN) {
fputs(" min ", stdout);
(void)fputs(" min ", stdout);
} else if (unit->modtype == ROFI_DISTANCE_MODIFIER_MAX) {
fputs(" max ", stdout);
(void)fputs(" max ", stdout);
} else if (unit->modtype == ROFI_DISTANCE_MODIFIER_ROUND) {
fputs(" round ", stdout);
(void)fputs(" round ", stdout);
} else if (unit->modtype == ROFI_DISTANCE_MODIFIER_FLOOR) {
fputs(" floor ", stdout);
(void)fputs(" floor ", stdout);
} else if (unit->modtype == ROFI_DISTANCE_MODIFIER_CEIL) {
fputs(" ceil ", stdout);
(void)fputs(" ceil ", stdout);
}
if (unit->right) {
rofi_theme_print_distance_unit(unit->right);
@ -305,28 +305,28 @@ static void rofi_theme_print_distance_unit(RofiDistanceUnit *unit) {
printf("%upx ", (unsigned int)unit->distance);
} else if (unit->type == ROFI_PU_MM) {
printf_double(unit->distance);
fputs("mm ", stdout);
(void)fputs("mm ", stdout);
} else if (unit->type == ROFI_PU_PERCENT) {
printf_double(unit->distance);
fputs("% ", stdout);
(void)fputs("% ", stdout);
} else if (unit->type == ROFI_PU_CH) {
printf_double(unit->distance);
fputs("ch ", stdout);
(void)fputs("ch ", stdout);
} else {
printf_double(unit->distance);
fputs("em ", stdout);
(void)fputs("em ", stdout);
}
}
if (unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP) {
fputs(" )", stdout);
(void)fputs(" )", stdout);
}
}
static void rofi_theme_print_color(ThemeColor color) {
uint8_t r, g, b;
g = 255 * color.green;
r = 255 * color.red;
b = 255 * color.blue;
g = (uint8_t)(255 * color.green);
r = (uint8_t)(255 * color.red);
b = (uint8_t)(255 * color.blue);
if (color.alpha < 0.00001) {
printf("transparent");
return;
@ -345,11 +345,11 @@ static void rofi_theme_print_color(ThemeColor color) {
}
static void rofi_theme_print_distance(RofiDistance d) {
if (d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP) {
fputs("calc( ", stdout);
(void)fputs("calc( ", stdout);
}
rofi_theme_print_distance_unit(&(d.base));
if (d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP) {
fputs(")", stdout);
(void)fputs(")", stdout);
}
if (d.style == ROFI_HL_DASH) {
printf("dash ");
@ -410,31 +410,31 @@ static void int_rofi_theme_print_property(Property *p) {
case P_POSITION: {
switch (p->value.i) {
case WL_CENTER:
fputs("center", stdout);
(void)fputs("center", stdout);
break;
case WL_NORTH:
fputs("north", stdout);
(void)fputs("north", stdout);
break;
case WL_SOUTH:
fputs("south", stdout);
(void)fputs("south", stdout);
break;
case WL_WEST:
fputs("west", stdout);
(void)fputs("west", stdout);
break;
case WL_EAST:
fputs("east", stdout);
(void)fputs("east", stdout);
break;
case WL_NORTH | WL_EAST:
fputs("northeast", stdout);
(void)fputs("northeast", stdout);
break;
case WL_SOUTH | WL_EAST:
fputs("southeast", stdout);
(void)fputs("southeast", stdout);
break;
case WL_NORTH | WL_WEST:
fputs("northwest", stdout);
(void)fputs("northwest", stdout);
break;
case WL_SOUTH | WL_WEST:
fputs("southwest", stdout);
(void)fputs("southwest", stdout);
break;
}
break;
@ -448,7 +448,7 @@ static void int_rofi_theme_print_property(Property *p) {
case P_DOUBLE: {
char sign = (p->value.f < 0);
int top = (int)fabs(p->value.f);
int bottom = (fabs(fmod(p->value.f, 1.0))) * 100;
int bottom = (int)((fabs(fmod(p->value.f, 1.0))) * 100);
printf("%s%d.%02d", sign ? "-" : "", top, bottom);
break;
}
@ -526,8 +526,8 @@ static void rofi_theme_print_property_index(size_t pnl, int cur_depth,
int pl = strlen(p->name);
printf("%*s%s:%*s ", cur_depth, "", p->name, (int)pnl - pl, "");
int_rofi_theme_print_property(p);
putchar(';');
putchar('\n');
(void)putchar(';');
(void)putchar('\n');
}
void rofi_theme_print_index(ThemeWidget *wid, int index) {
@ -559,11 +559,11 @@ void rofi_theme_print_index(ThemeWidget *wid, int index) {
for (GList *citer = g_list_first(list); citer != NULL;
citer = g_list_next(citer)) {
char *name = (char *)citer->data;
fputs(name, stdout);
(void)fputs(name, stdout);
if (citer->prev == NULL && citer->next) {
putchar(' ');
(void)putchar(' ');
} else if (citer->next) {
putchar('.');
(void)putchar('.');
}
}
printf(" {\n");
@ -840,7 +840,7 @@ static int rofi_theme_get_integer_inside(Property *p, const widget *wid,
int rofi_theme_get_integer(const widget *wid, const char *property, int def) {
ThemeWidget *wid_find = rofi_theme_find_widget(wid->name, wid->state, FALSE);
Property *p = rofi_theme_find_property(wid_find, P_INTEGER, property, FALSE);
return (int)rofi_theme_get_integer_inside(p, wid, property, (double)def);
return (int)rofi_theme_get_integer_inside(p, wid, property, def);
}
static RofiDistance rofi_theme_get_distance_inside(Property *p,
const widget *wid,
@ -1403,7 +1403,7 @@ static double distance_unit_get_pixel(RofiDistanceUnit *unit,
}
int distance_get_pixel(RofiDistance d, RofiOrientation ori) {
return distance_unit_get_pixel(&(d.base), ori);
return (int)distance_unit_get_pixel(&(d.base), ori);
}
void distance_get_linestyle(RofiDistance d, cairo_t *draw) {
@ -1463,7 +1463,7 @@ static void rofi_theme_parse_process_conditionals_int(workarea mon,
rwidget->widgets[rwidget->num_widgets] = NULL;
switch (child_widget->media->type) {
case THEME_MEDIA_TYPE_MIN_WIDTH: {
int w = child_widget->media->value;
int w = (int)(child_widget->media->value);
if (mon.w >= w) {
for (unsigned int x = 0; x < child_widget->num_widgets; x++) {
rofi_theme_parse_merge_widgets(rwidget, child_widget->widgets[x]);
@ -1472,7 +1472,7 @@ static void rofi_theme_parse_process_conditionals_int(workarea mon,
break;
}
case THEME_MEDIA_TYPE_MAX_WIDTH: {
int w = child_widget->media->value;
int w = (int)(child_widget->media->value);
if (mon.w < w) {
for (unsigned int x = 0; x < child_widget->num_widgets; x++) {
rofi_theme_parse_merge_widgets(rwidget, child_widget->widgets[x]);
@ -1481,7 +1481,7 @@ static void rofi_theme_parse_process_conditionals_int(workarea mon,
break;
}
case THEME_MEDIA_TYPE_MIN_HEIGHT: {
int h = child_widget->media->value;
int h = (int)(child_widget->media->value);
if (mon.h >= h) {
for (unsigned int x = 0; x < child_widget->num_widgets; x++) {
rofi_theme_parse_merge_widgets(rwidget, child_widget->widgets[x]);
@ -1491,7 +1491,7 @@ static void rofi_theme_parse_process_conditionals_int(workarea mon,
break;
}
case THEME_MEDIA_TYPE_MAX_HEIGHT: {
int h = child_widget->media->value;
int h = (int)(child_widget->media->value);
if (mon.h < h) {
for (unsigned int x = 0; x < child_widget->num_widgets; x++) {
rofi_theme_parse_merge_widgets(rwidget, child_widget->widgets[x]);

View file

@ -266,7 +266,7 @@ void rofi_capture_screenshot(void) {
} else {
fpath = g_strdup(outp);
}
fprintf(stderr, color_green "Storing screenshot %s\n" color_reset, fpath);
(void)fprintf(stderr, color_green "Storing screenshot %s\n" color_reset, fpath);
cairo_surface_t *surf = cairo_image_surface_create(
CAIRO_FORMAT_ARGB32, state->width, state->height);
cairo_status_t status = cairo_surface_status(surf);
@ -594,7 +594,7 @@ static void rofi_view_set_user_timeout(G_GNUC_UNUSED gpointer data) {
if (prop != NULL && prop->type == P_DOUBLE && prop->value.f > 0.01) {
double delay = prop->value.f;
CacheState.user_timeout =
g_timeout_add(delay * 1000, rofi_view_user_timeout, NULL);
g_timeout_add((int)(delay * 1000), rofi_view_user_timeout, NULL);
}
}
}
@ -668,7 +668,8 @@ void rofi_view_set_selected_line(RofiViewState *state,
}
}
listview_set_selected(state->list_view, selected);
xcb_clear_area(xcb->connection, CacheState.main_window, 1, 0, 0, 1, 1);
// 2nd argument indicates exposure event should be generated.
xcb_clear_area(xcb->connection, 1, CacheState.main_window, 0, 0, 0, 0);
xcb_flush(xcb->connection);
}
@ -967,7 +968,7 @@ static void input_history_initialize(void) {
CacheState.entry_history_index++;
}
free(line);
fclose(fp);
(void)fclose(fp);
}
}
g_free(path);
@ -1001,10 +1002,10 @@ static void input_history_save(void) {
gssize start = MAX(0, (CacheState.entry_history_length - max_history));
for (gssize i = start; i < CacheState.entry_history_length; i++) {
if (strlen(CacheState.entry_history[i].string) > 0) {
fprintf(fp, "%s\n", CacheState.entry_history[i].string);
(void)fprintf(fp, "%s\n", CacheState.entry_history[i].string);
}
}
fclose(fp);
(void)fclose(fp);
}
g_free(path);
}
@ -1104,11 +1105,13 @@ void __create_window(MenuFlags menu_flags) {
g_debug("Auto-detected DPI: %.2lf", dpi);
PangoFontMap *font_map = pango_cairo_font_map_get_default();
pango_cairo_font_map_set_resolution((PangoCairoFontMap *)font_map, dpi);
config.dpi = dpi;
// TODO should be rounded?
config.dpi = (int)dpi;
} else {
// default pango is 96.
PangoFontMap *font_map = pango_cairo_font_map_get_default();
config.dpi =
// TODO should we round?
config.dpi = (int)
pango_cairo_font_map_get_resolution((PangoCairoFontMap *)font_map);
}
// Setup font.
@ -1226,7 +1229,7 @@ static void rofi_view_calculate_window_width(RofiViewState *state) {
return;
}
// Calculate as float to stop silly, big rounding down errors.
state->width = (CacheState.mon.w / 100.0) * DEFAULT_MENU_WIDTH;
state->width = (int)((CacheState.mon.w / 100.0) * DEFAULT_MENU_WIDTH);
// Use theme configured width, if set.
RofiDistance width = rofi_theme_get_distance(WIDGET(state->main_window),
"width", state->width);

View file

@ -176,7 +176,7 @@ static void vert_calculate_size(box *b) {
}
if (child->expand == TRUE) {
// Re-calculate to avoid round issues leaving one pixel left.
int expanding_widgets_size = (rem) / (expanding_widgets - index);
int expanding_widgets_size = (int)((rem) / (expanding_widgets - index));
widget_move(child, widget_padding_get_left(WIDGET(b)), top);
top += expanding_widgets_size;
widget_resize(child, rem_width, expanding_widgets_size);
@ -246,7 +246,7 @@ static void hori_calculate_size(box *b) {
}
if (child->expand == TRUE) {
// Re-calculate to avoid round issues leaving one pixel left.
int expanding_widgets_size = (rem) / (expanding_widgets - index);
int expanding_widgets_size = (int)((rem) / (expanding_widgets - index));
widget_move(child, left, widget_padding_get_top(WIDGET(b)));
left += expanding_widgets_size;
widget_resize(child, expanding_widgets_size, rem_height);

View file

@ -62,7 +62,8 @@ static int icon_get_desired_height(widget *wid, G_GNUC_UNUSED const int width) {
int iconw = cairo_image_surface_get_width(b->icon);
int icons = MAX(iconh, iconw);
double scale = (double)b->size / icons;
height = iconh * scale;
// TODO should this be a ceil?
height = (int)(iconh * scale);
}
}
height += widget_padding_get_padding_height(wid);
@ -76,8 +77,8 @@ static int icon_get_desired_width(widget *wid, G_GNUC_UNUSED const int height) {
int iconh = cairo_image_surface_get_height(b->icon);
int iconw = cairo_image_surface_get_width(b->icon);
int icons = MAX(iconh, iconw);
double scale = (double)b->size / icons;
width = iconw * scale;
double scale = (double)(b->size / (double)icons);
width = (int)(iconw * scale);
}
}
width += widget_padding_get_padding_width(wid);

View file

@ -49,7 +49,7 @@ static int scrollbar_get_desired_height(widget *wid,
// TODO
// This should behave more like a real scrollbar.
guint scrollbar_scroll_get_line(const scrollbar *sb, int y) {
y -= sb->widget.border.top.base.distance;
y -= (int)(sb->widget.border.top.base.distance);
if (y < 0) {
return 0;
}
@ -58,15 +58,15 @@ guint scrollbar_scroll_get_line(const scrollbar *sb, int y) {
return sb->length - 1;
}
short r =
(sb->length * sb->widget.h) / ((double)(sb->length + sb->pos_length));
short handle = sb->widget.h - r;
int r =
(int)((sb->length * sb->widget.h) / ((double)(sb->length + sb->pos_length)));
int handle = sb->widget.h - r;
double sec = ((r) / (double)(sb->length - 1));
short half_handle = handle / 2;
int half_handle = handle / 2;
y -= half_handle;
y = MIN(MAX(0, y), sb->widget.h - 2 * half_handle);
unsigned int sel = ((y) / sec);
unsigned int sel = (unsigned int)((y) / sec);
return MIN(sel, sb->length - 1);
}
@ -164,12 +164,12 @@ static void scrollbar_draw(widget *wid, cairo_t *draw) {
double wh = widget_padding_get_remaining_height(wid);
// Calculate position and size.
double r = (sb->length * wh) / ((double)(sb->length + sb->pos_length));
unsigned int handle = wid->h - r;
unsigned int handle = (unsigned int )(wid->h - r);
double sec = ((r) / (double)(sb->length - 1));
unsigned int height = handle;
unsigned int y = sb->pos * sec;
unsigned int y = (unsigned int)(sb->pos * sec);
// Set max pos.
y = MIN(y, wh - handle);
y = MIN(y, (unsigned int)(wh - handle));
// Never go out of bar.
height = MAX(2, height);
// Cap length;

View file

@ -518,7 +518,7 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
if (tb->yalign > 0.001) {
int bottom = widget_padding_get_bottom(WIDGET(tb));
top = (tb->widget.h - bottom - line_height - top) * tb->yalign + top;
top = (int)((tb->widget.h - bottom - line_height - top) * tb->yalign) + top;
}
y += top;
@ -536,13 +536,13 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
line_width);
switch (pango_layout_get_alignment(tb->layout)) {
case PANGO_ALIGN_CENTER:
x = rem * (tb->xalign - 0.5);
x = (int)(rem * (tb->xalign - 0.5));
break;
case PANGO_ALIGN_RIGHT:
x = rem * (tb->xalign - 1.0);
x = (int)(rem * (tb->xalign - 1.0));
break;
default:
x = rem * tb->xalign;
x = (int)(rem * tb->xalign);
break;
}
x += widget_padding_get_left(WIDGET(tb));
@ -1058,7 +1058,8 @@ double textbox_get_estimated_ch(void) {
}
int textbox_get_estimated_height(const textbox *tb, int eh) {
int height = tb->tbfc->height;
// TODO should this be a ceil?
int height = (int)(tb->tbfc->height);
return (eh * height) + widget_padding_get_padding_height(WIDGET(tb));
}
int textbox_get_desired_width(widget *wid, G_GNUC_UNUSED const int height) {

View file

@ -175,22 +175,22 @@ void widget_draw(widget *wid, cairo_t *d) {
double hspace =
wid->w - margin_left - margin_right - left / 2.0 - right / 2.0;
if ((radius_bl + radius_tl) > (vspace)) {
int j = ((vspace) / 2.0);
int j = (int)((vspace) / 2.0);
radius_bl = MIN(radius_bl, j);
radius_tl = MIN(radius_tl, j);
}
if ((radius_br + radius_tr) > (vspace)) {
int j = ((vspace) / 2.0);
int j = (int)((vspace) / 2.0);
radius_br = MIN(radius_br, j);
radius_tr = MIN(radius_tr, j);
}
if ((radius_tl + radius_tr) > (hspace)) {
int j = ((hspace) / 2.0);
int j = (int)((hspace) / 2.0);
radius_tr = MIN(radius_tr, j);
radius_tl = MIN(radius_tl, j);
}
if ((radius_bl + radius_br) > (hspace)) {
int j = ((hspace) / 2.0);
int j = (int)((hspace) / 2.0);
radius_br = MIN(radius_br, j);
radius_bl = MIN(radius_bl, j);
}

View file

@ -152,7 +152,7 @@ static uint32_t *create_kernel(double radius, double deviation,
uint32_t *kernel = (uint32_t *)(g_malloc(sizeof(uint32_t) * (size + 1)));
double radiusf = fabs(radius) + 1.0;
double value = -radius;
double sum = 0.0;
uint32_t sum = 0;
int i;
if (deviation == 0.0) {
@ -162,8 +162,8 @@ static uint32_t *create_kernel(double radius, double deviation,
kernel[0] = size;
for (i = 0; i < size; i++) {
kernel[1 + i] = INT16_MAX / (2.506628275 * deviation) *
exp(-((value * value) / (2.0 * (deviation * deviation))));
kernel[1 + i] = (uint32_t)(INT16_MAX / (2.506628275 * deviation) *
exp(-((value * value) / (2.0 * (deviation * deviation)))));
sum += kernel[1 + i];
value += 1.0;
@ -174,6 +174,13 @@ static uint32_t *create_kernel(double radius, double deviation,
return kernel;
}
inline static uint8_t rofi_uint32_uint8_range(const uint32_t v)
{
if ( v > UINT8_MAX){
return UINT8_MAX;
}
return (uint8_t)v;
}
void cairo_image_surface_blur(cairo_surface_t *surface, double radius,
double deviation) {
uint32_t *horzBlur;
@ -197,10 +204,16 @@ void cairo_image_surface_blur(cairo_surface_t *surface, double radius,
return;
}
horzBlur = (uint32_t *)(g_malloc(sizeof(uint32_t) * height * stride));
TICK();
uint32_t sum = 0;
kernel = create_kernel(radius, deviation, &sum);
if ( sum == 0 ){
// This is invalid.
g_warning("Failed to create blurring kernel.");
g_free(kernel);
return;
}
horzBlur = (uint32_t *)(g_malloc(sizeof(uint32_t) * height * stride));
TICK_N("BLUR: kernel");
/* Horizontal pass. */
@ -269,16 +282,16 @@ void cairo_image_surface_blur(cairo_surface_t *surface, double radius,
offset++;
}
*data++ = blue / sum;
*data++ = green / sum;
*data++ = red / sum;
*data++ = alpha / sum;
*data++ = rofi_uint32_uint8_range(blue / sum);
*data++ = rofi_uint32_uint8_range(green / sum);
*data++ = rofi_uint32_uint8_range(red / sum);
*data++ = rofi_uint32_uint8_range(alpha / sum);
}
}
TICK_N("BLUR: vert");
free(kernel);
free(horzBlur);
g_free(kernel);
g_free(horzBlur);
return;
}
@ -323,7 +336,7 @@ cairo_surface_t *x11_helper_get_screenshot_surface_window(xcb_window_t window,
double scale = (double)size / max;
cairo_surface_t *s2 = cairo_surface_create_similar_image(
t, CAIRO_FORMAT_ARGB32, reply->width * scale, reply->height * scale);
t, CAIRO_FORMAT_ARGB32, (int)(reply->width * scale), (int)(reply->height * scale));
free(reply);
if (cairo_surface_status(s2) != CAIRO_STATUS_SUCCESS) {
@ -547,8 +560,11 @@ x11_get_monitor_from_randr_monitor(xcb_randr_monitor_info_t *mon) {
#endif
static int x11_is_extension_present(const char *extension) {
// TODO add a quick check for the length of extension.
// We know how (as it is not a user-provided string) the length
// will always be less then 2**16
xcb_query_extension_cookie_t randr_cookie =
xcb_query_extension(xcb->connection, strlen(extension), extension);
xcb_query_extension(xcb->connection, (uint16_t)strlen(extension), extension);
xcb_query_extension_reply_t *randr_reply =
xcb_query_extension_reply(xcb->connection, randr_cookie, NULL);
@ -1612,8 +1628,10 @@ static void error_trap_pop(G_GNUC_UNUSED SnDisplay *display,
static void x11_create_frequently_used_atoms(void) {
// X atom values
for (int i = 0; i < NUM_NETATOMS; i++) {
// we know the length of the atoms are smaller then 2**16, so cast
// is valid.
xcb_intern_atom_cookie_t cc = xcb_intern_atom(
xcb->connection, 0, strlen(netatom_names[i]), netatom_names[i]);
xcb->connection, 0, (uint16_t)strlen(netatom_names[i]), netatom_names[i]);
xcb_intern_atom_reply_t *r =
xcb_intern_atom_reply(xcb->connection, cc, NULL);
if (r) {
@ -1751,7 +1769,8 @@ gboolean display_setup(GMainLoop *main_loop, NkBindings *bindings) {
.affectState = required_state_details,
.stateDetails = required_state_details,
};
xcb_xkb_select_events(xcb->connection, xcb->xkb.device_id,
// Unsure why xcb/xkb uses different length type for this.
xcb_xkb_select_events(xcb->connection, (uint16_t)xcb->xkb.device_id,
required_events, /* affectWhich */
0, /* clear */
required_events, /* selectAll */

View file

@ -838,47 +838,47 @@ void config_xresource_free(void) {
static void config_parse_dump_config_option(FILE *out, XrmOption *option) {
if (option->type == xrm_Char || (option->source & 3) == CONFIG_DEFAULT) {
fprintf(out, "/*");
(void)fprintf(out, "/*");
}
fprintf(out, "\t%s: ", option->name);
(void)fprintf(out, "\t%s: ", option->name);
switch (option->type) {
case xrm_Number:
fprintf(out, "%u", *(option->value.num));
(void)fprintf(out, "%u", *(option->value.num));
break;
case xrm_SNumber:
fprintf(out, "%i", *(option->value.snum));
(void)fprintf(out, "%i", *(option->value.snum));
break;
case xrm_String:
if ((*(option->value.str)) != NULL) {
// TODO should this be escaped?
fprintf(out, "\"%s\"", *(option->value.str));
(void)fprintf(out, "\"%s\"", *(option->value.str));
}
break;
case xrm_Boolean:
fprintf(out, "%s", (*(option->value.num) == TRUE) ? "true" : "false");
(void)fprintf(out, "%s", (*(option->value.num) == TRUE) ? "true" : "false");
break;
case xrm_Char:
// TODO
if (*(option->value.charc) > 32 && *(option->value.charc) < 127) {
fprintf(out, "'%c'", *(option->value.charc));
(void)fprintf(out, "'%c'", *(option->value.charc));
} else {
fprintf(out, "'\\x%02X'", *(option->value.charc));
(void)fprintf(out, "'\\x%02X'", *(option->value.charc));
}
fprintf(out, " /* unsupported */");
(void)fprintf(out, " /* unsupported */");
break;
default:
break;
}
fprintf(out, ";");
(void)fprintf(out, ";");
if (option->type == xrm_Char || (option->source & 3) == CONFIG_DEFAULT) {
fprintf(out, "*/");
(void)fprintf(out, "*/");
}
fprintf(out, "\n");
(void)fprintf(out, "\n");
}
void config_parse_dump_config_rasi_format(FILE *out, gboolean changes) {
fprintf(out, "configuration {\n");
(void)fprintf(out, "configuration {\n");
unsigned int entries = sizeof(xrmOptions) / sizeof(*xrmOptions);
for (unsigned int i = 0; i < entries; ++i) {
@ -910,10 +910,10 @@ void config_parse_dump_config_rasi_format(FILE *out, gboolean changes) {
rofi_theme_print_index(rofi_configuration->widgets[index], 2);
}
fprintf(out, "}\n");
(void)fprintf(out, "}\n");
if (config.theme != NULL) {
fprintf(out, "@theme \"%s\"\r\n", config.theme);
(void)fprintf(out, "@theme \"%s\"\r\n", config.theme);
}
}

View file

@ -88,7 +88,7 @@ double textbox_get_estimated_ch(void) { return 9.0; }
void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
void rofi_add_warning_message(G_GNUC_UNUSED GString *msg) {}
int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
fputs(msg, stderr);
(void)fputs(msg, stderr);
return TRUE;
}
@ -102,7 +102,7 @@ void display_startup_notification(
int main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) {
if (setlocale(LC_ALL, "") == NULL) {
fprintf(stderr, "Failed to set locale.\n");
(void)fprintf(stderr, "Failed to set locale.\n");
return EXIT_FAILURE;
}
char **list = NULL;

View file

@ -86,7 +86,7 @@ void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
void rofi_add_warning_message(G_GNUC_UNUSED GString *msg) {}
int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
fputs(msg, stderr);
(void)fputs(msg, stderr);
return TRUE;
}
@ -101,7 +101,7 @@ int main(int argc, char **argv) {
cmd_set_arguments(argc, argv);
if (setlocale(LC_ALL, "") == NULL) {
fprintf(stderr, "Failed to set locale.\n");
(void)fprintf(stderr, "Failed to set locale.\n");
return EXIT_FAILURE;
}

View file

@ -79,7 +79,7 @@ double textbox_get_estimated_ch(void) { return 9.0; }
void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
void rofi_add_warning_message(G_GNUC_UNUSED GString *msg) {}
int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
fputs(msg, stderr);
(void)fputs(msg, stderr);
return TRUE;
}
int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; }
@ -91,7 +91,7 @@ void display_startup_notification(
int main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) {
if (setlocale(LC_ALL, "") == NULL) {
fprintf(stderr, "Failed to set locale.\n");
(void)fprintf(stderr, "Failed to set locale.\n");
return EXIT_FAILURE;
}
// Pid test.

View file

@ -102,7 +102,7 @@ void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
void rofi_add_warning_message(G_GNUC_UNUSED GString *msg) {}
int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
fputs(msg, stderr);
(void)fputs(msg, stderr);
return TRUE;
}
@ -117,7 +117,7 @@ int main(int argc, char **argv) {
cmd_set_arguments(argc, argv);
if (setlocale(LC_ALL, "") == NULL) {
fprintf(stderr, "Failed to set locale.\n");
(void)fprintf(stderr, "Failed to set locale.\n");
return EXIT_FAILURE;
}

View file

@ -75,7 +75,7 @@ double textbox_get_estimated_ch(void) { return 9.0; }
void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
void rofi_add_warning_message(G_GNUC_UNUSED GString *msg) {}
int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
fputs(msg, stderr);
(void)fputs(msg, stderr);
return TRUE;
}
int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; }
@ -447,7 +447,7 @@ static Suite *helper_tokenizer_suite(void) {
int main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) {
if (setlocale(LC_ALL, "") == NULL) {
fprintf(stderr, "Failed to set locale.\n");
(void)fprintf(stderr, "Failed to set locale.\n");
return EXIT_FAILURE;
}

View file

@ -75,7 +75,7 @@ void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
void rofi_add_warning_message(G_GNUC_UNUSED GString *msg) {}
int monitor_active(G_GNUC_UNUSED workarea *d) { return 0; }
int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
fputs(msg, stderr);
(void)fputs(msg, stderr);
return TRUE;
}
void rofi_view_get_current_monitor(G_GNUC_UNUSED int *width,

View file

@ -89,7 +89,7 @@ void rofi_view_queue_redraw(void) {}
void rofi_view_get_current_monitor(G_GNUC_UNUSED int *width,
G_GNUC_UNUSED int *height) {}
int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
fputs(msg, stderr);
(void)fputs(msg, stderr);
return FALSE;
}

View file

@ -67,7 +67,7 @@ cairo_surface_t *rofi_icon_fetcher_get(G_GNUC_UNUSED const uint32_t uid) {
}
int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
fputs(msg, stderr);
(void)fputs(msg, stderr);
return TRUE;
}
@ -2054,7 +2054,7 @@ int main(int argc, char **argv) {
cmd_set_arguments(argc, argv);
if (setlocale(LC_ALL, "C") == NULL) {
fprintf(stderr, "Failed to set locale.\n");
(void)fprintf(stderr, "Failed to set locale.\n");
return EXIT_FAILURE;
}

View file

@ -81,7 +81,7 @@ int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; }
void rofi_view_get_current_monitor(G_GNUC_UNUSED int *width,
G_GNUC_UNUSED int *height) {}
int rofi_view_error_dialog(const char *msg, G_GNUC_UNUSED int markup) {
fputs(msg, stderr);
(void)fputs(msg, stderr);
return FALSE;
}