From 9d785b5ce19402d28d790e48c9d407fdcdc5aa41 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sun, 20 Oct 2024 12:54:13 +0200 Subject: [PATCH] Add -Wshadow to build system. (#2042) * Add -Wshadow to build system. Issue: #2036 * Take out unintended change * [Icon] Add more descriptive variable name. --- include/widgets/icon.h | 4 +- include/widgets/widget.h | 74 +++--- lexer/theme-parser.y | 82 +++--- meson.build | 3 +- source/modes/dmenu.c | 5 +- source/rofi.c | 3 +- source/theme.c | 526 ++++++++++++++++++------------------- source/view.c | 24 +- source/widgets/box.c | 30 +-- source/widgets/container.c | 22 +- source/widgets/icon.c | 34 ++- source/widgets/widget.c | 263 +++++++++---------- source/xcb.c | 6 +- 13 files changed, 528 insertions(+), 548 deletions(-) diff --git a/include/widgets/icon.h b/include/widgets/icon.h index e0da5c7f4..2422a27b8 100644 --- a/include/widgets/icon.h +++ b/include/widgets/icon.h @@ -59,9 +59,9 @@ icon *icon_create(widget *parent, const char *name); void icon_set_size(widget *icon, const int size); /** - * @param icon The icon widget handle. + * @param icon_widget The icon widget handle. * @param surf The surface to display. */ -void icon_set_surface(icon *icon, cairo_surface_t *surf); +void icon_set_surface(icon *icon_widget, cairo_surface_t *surf); /**@}*/ #endif // ROFI_ICON_H diff --git a/include/widgets/widget.h b/include/widgets/widget.h index 28edb33a6..f68b8b64d 100644 --- a/include/widgets/widget.h +++ b/include/widgets/widget.h @@ -85,7 +85,7 @@ typedef enum { } WidgetTriggerActionResult; /** - * @param widget The container widget itself + * @param wid The container widget itself * @param type The widget type searched for * @param x The X coordination of the mouse event relative to #widget * @param y The Y coordination of the mouse event relative to #widget @@ -95,11 +95,11 @@ typedef enum { * * @returns A child widget if found, NULL otherwise */ -typedef widget *(*widget_find_mouse_target_cb)(widget *widget, WidgetType type, +typedef widget *(*widget_find_mouse_target_cb)(widget *wid, WidgetType type, gint x, gint y); /** - * @param widget The target widget + * @param wid The target widget * @param action The action value (which enum it is depends on the widget type) * @param x The X coordination of the mouse event relative to #widget * @param y The Y coordination of the mouse event relative to #widget @@ -110,7 +110,7 @@ typedef widget *(*widget_find_mouse_target_cb)(widget *widget, WidgetType type, * * @returns Whether the action was handled or not, see enum values for details */ -typedef WidgetTriggerActionResult (*widget_trigger_action_cb)(widget *widget, +typedef WidgetTriggerActionResult (*widget_trigger_action_cb)(widget *wid, guint action, gint x, gint y, void *user_data); @@ -119,7 +119,7 @@ typedef WidgetTriggerActionResult (*widget_trigger_action_cb)(widget *widget, #define WIDGET(a) ((widget *)(a)) /** - * @param widget The widget to check + * @param wid The widget to check * @param x The X position relative to parent window * @param y the Y position relative to parent window * @@ -127,65 +127,63 @@ typedef WidgetTriggerActionResult (*widget_trigger_action_cb)(widget *widget, * * @return TRUE if x,y falls within the widget */ -int widget_intersect(const widget *widget, int x, int y); +int widget_intersect(const widget *wid, int x, int y); /** - * @param widget The widget to move + * @param wid The widget to move * @param x The new X position relative to parent window * @param y The new Y position relative to parent window * * Moves the widget. */ -void widget_move(widget *widget, short x, short y); +void widget_move(widget *wid, short x, short y); /** - * @param widget Handle to widget + * @param wid Handle to widget * @param type The widget type. * * Set the widget type. */ -void widget_set_type(widget *widget, WidgetType type); +void widget_set_type(widget *wid, WidgetType type); /** - * @param widget Handle to widget + * @param wid Handle to widget * * Check if widget is enabled. * @returns TRUE when widget is enabled. */ -gboolean widget_enabled(widget *widget); +gboolean widget_enabled(widget *wid); /** - * @param widget Handle to widget + * @param wid Handle to widget * @param enabled The new state * * Disable the widget. */ -void widget_set_enabled(widget *widget, gboolean enabled); +void widget_set_enabled(widget *wid, gboolean enabled); /** - * @param widget Handle to widget + * @param wid Handle to widget * * Disable the widget. */ -static inline void widget_disable(widget *widget) { - widget_set_enabled(widget, FALSE); +static inline void widget_disable(widget *wid) { + widget_set_enabled(wid, FALSE); } /** - * @param widget Handle to widget + * @param wid Handle to widget * * Enable the widget. */ -static inline void widget_enable(widget *widget) { - widget_set_enabled(widget, TRUE); -} +static inline void widget_enable(widget *wid) { widget_set_enabled(wid, TRUE); } /** - * @param widget widget Handle to the widget + * @param wid widget Handle to the widget * @param d The cairo object used to draw itself. * * Render the textbox. */ -void widget_draw(widget *widget, cairo_t *d); +void widget_draw(widget *wid, cairo_t *d); /** * @param wid Handle to the widget @@ -195,58 +193,58 @@ void widget_draw(widget *widget, cairo_t *d); void widget_free(widget *wid); /** - * @param widget The widget toresize + * @param wid The widget toresize * @param w The new width * @param h The new height * * Resizes the widget. */ -void widget_resize(widget *widget, short w, short h); +void widget_resize(widget *wid, short w, short h); /** - * @param widget The widget handle + * @param wid The widget handle * * @returns the height of the widget. */ -int widget_get_height(widget *widget); +int widget_get_height(widget *wid); /** - * @param widget The widget handle + * @param wid The widget handle * * @returns the width of the widget. */ -int widget_get_width(widget *widget); +int widget_get_width(widget *wid); /** - * @param widget The widget handle + * @param wid The widget handle * * @returns the y position of the widget relative to its parent. */ -int widget_get_y_pos(widget *widget); +int widget_get_y_pos(widget *wid); /** - * @param widget The widget handle + * @param wid The widget handle * * @returns the x position of the widget relative to its parent. */ -int widget_get_x_pos(widget *widget); +int widget_get_x_pos(widget *wid); /** - * @param widget The widget handle + * @param wid The widget handle * @param x A pointer to the absolute X coordinates * @param y A pointer to the absolute Y coordinates * - * Will modify param x and param y to make them relative to param widget . + * Will modify param x and param y to make them relative to param wid . */ -void widget_xy_to_relative(widget *widget, gint *x, gint *y); +void widget_xy_to_relative(widget *wid, gint *x, gint *y); /** - * @param widget The widget handle + * @param wid The widget handle * * Update the widget, and its parent recursively. * This should be called when size of widget changes. */ -void widget_update(widget *widget); +void widget_update(widget *wid); /** * @param wid The widget handle * diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y index 57651a212..89d24baaf 100644 --- a/lexer/theme-parser.y +++ b/lexer/theme-parser.y @@ -362,13 +362,13 @@ t_entry_list T_CONFIGURATION T_BOPEN t_config_property_list_optional T_BCLOSE { | t_entry_list t_name_prefix_optional t_entry_name_path_selectors T_BOPEN t_property_list_optional T_BCLOSE { for ( GList *liter = g_list_first ( $3); liter; liter = g_list_next ( liter ) ) { - ThemeWidget *widget = $1; - for ( GList *iter = g_list_first ( (GList*)liter->data ); widget && iter ; iter = g_list_next ( iter ) ) { - widget = rofi_theme_find_or_create_name ( widget, iter->data ); + ThemeWidget *wid = $1; + for ( GList *iter = g_list_first ( (GList*)liter->data ); wid && iter ; iter = g_list_next ( iter ) ) { + wid = rofi_theme_find_or_create_name ( wid, iter->data ); } g_list_free_full ( (GList*)liter->data, g_free ); - widget->set = TRUE; - rofi_theme_widget_add_properties ( widget, $5); + wid->set = TRUE; + rofi_theme_widget_add_properties ( wid, $5); } if ( $5 ) { g_hash_table_destroy ( $5 ); @@ -376,78 +376,78 @@ t_entry_list T_CONFIGURATION T_BOPEN t_config_property_list_optional T_BCLOSE { g_list_free ( $3 ); } | t_entry_list T_PDEFAULTS T_BOPEN t_property_list_optional T_BCLOSE { - ThemeWidget *widget = rofi_theme_find_or_create_name ( $1, "*" ); - rofi_theme_widget_add_properties (widget, $4); + ThemeWidget *wid = rofi_theme_find_or_create_name ( $1, "*" ); + rofi_theme_widget_add_properties (wid, $4); if ( $4 ) { g_hash_table_destroy ( $4 ); } } | t_entry_list T_MEDIA T_PARENT_LEFT T_MEDIA_TYPE T_PSEP t_property_number T_PARENT_RIGHT T_BOPEN t_entry_list T_BCLOSE { gchar *name = g_strdup_printf("@media ( %s: %f )",$4, $6); - ThemeWidget *widget = rofi_theme_find_or_create_name ( $1, name ); - widget->set = TRUE; - widget->media = g_slice_new0(ThemeMedia); - widget->media->type = rofi_theme_parse_media_type ( $4 ); - widget->media->value = $6; + ThemeWidget *wid = rofi_theme_find_or_create_name ( $1, name ); + wid->set = TRUE; + wid->media = g_slice_new0(ThemeMedia); + wid->media->type = rofi_theme_parse_media_type ( $4 ); + wid->media->value = $6; for ( unsigned int i = 0; i < $9->num_widgets; i++ ) { ThemeWidget *d = $9->widgets[i]; - rofi_theme_parse_merge_widgets(widget, d); + rofi_theme_parse_merge_widgets(wid, d); } g_free ( $4 ); g_free ( name ); } | t_entry_list T_MEDIA T_PARENT_LEFT T_MEDIA_TYPE T_PSEP T_INT T_UNIT_PX T_PARENT_RIGHT T_BOPEN t_entry_list T_BCLOSE { gchar *name = g_strdup_printf("@media ( %s: %d px )",$4, $6); - ThemeWidget *widget = rofi_theme_find_or_create_name ( $1, name ); - widget->set = TRUE; - widget->media = g_slice_new0(ThemeMedia); - widget->media->type = rofi_theme_parse_media_type ( $4 ); - widget->media->value = (double)$6; + ThemeWidget *wid = rofi_theme_find_or_create_name ( $1, name ); + wid->set = TRUE; + wid->media = g_slice_new0(ThemeMedia); + wid->media->type = rofi_theme_parse_media_type ( $4 ); + wid->media->value = (double)$6; for ( unsigned int i = 0; i < $10->num_widgets; i++ ) { ThemeWidget *d = $10->widgets[i]; - rofi_theme_parse_merge_widgets(widget, d); + rofi_theme_parse_merge_widgets(wid, d); } g_free ( $4 ); g_free ( name ); } | t_entry_list T_MEDIA T_PARENT_LEFT T_MEDIA_TYPE T_PSEP T_BOOLEAN T_PARENT_RIGHT T_BOPEN t_entry_list T_BCLOSE { gchar *name = g_strdup_printf("@media ( %s: %s )",$4, $6?"true":"false"); - ThemeWidget *widget = rofi_theme_find_or_create_name ( $1, name ); - widget->set = TRUE; - widget->media = g_slice_new0(ThemeMedia); - widget->media->type = rofi_theme_parse_media_type ( $4 ); - widget->media->boolv = $6; + ThemeWidget *wid = rofi_theme_find_or_create_name ( $1, name ); + wid->set = TRUE; + wid->media = g_slice_new0(ThemeMedia); + wid->media->type = rofi_theme_parse_media_type ( $4 ); + wid->media->boolv = $6; for ( unsigned int i = 0; i < $9->num_widgets; i++ ) { ThemeWidget *d = $9->widgets[i]; - rofi_theme_parse_merge_widgets(widget, d); + rofi_theme_parse_merge_widgets(wid, d); } g_free ( $4 ); g_free ( name ); } | t_entry_list T_MEDIA T_PARENT_LEFT T_MEDIA_TYPE T_PSEP T_ENV_START T_PARENT_LEFT T_BOOLEAN T_COMMA T_BOOLEAN T_PARENT_RIGHT T_PARENT_RIGHT T_BOPEN t_entry_list T_BCLOSE { gchar *name = g_strdup_printf("@media ( %s: %s )",$4, $8?"true":"false"); - ThemeWidget *widget = rofi_theme_find_or_create_name ( $1, name ); - widget->set = TRUE; - widget->media = g_slice_new0(ThemeMedia); - widget->media->type = rofi_theme_parse_media_type ( $4 ); - widget->media->boolv = $8; + ThemeWidget *wid = rofi_theme_find_or_create_name ( $1, name ); + wid->set = TRUE; + wid->media = g_slice_new0(ThemeMedia); + wid->media->type = rofi_theme_parse_media_type ( $4 ); + wid->media->boolv = $8; for ( unsigned int i = 0; i < $14->num_widgets; i++ ) { ThemeWidget *d = $14->widgets[i]; - rofi_theme_parse_merge_widgets(widget, d); + rofi_theme_parse_merge_widgets(wid, d); } g_free ( $4 ); g_free ( name ); } | t_entry_list T_MEDIA T_PARENT_LEFT T_MEDIA_TYPE T_PSEP T_ENV_START T_PARENT_LEFT T_COMMA T_BOOLEAN T_PARENT_RIGHT T_PARENT_RIGHT T_BOPEN t_entry_list T_BCLOSE { gchar *name = g_strdup_printf("@media ( %s: %s )",$4, $9?"true":"false"); - ThemeWidget *widget = rofi_theme_find_or_create_name ( $1, name ); - widget->set = TRUE; - widget->media = g_slice_new0(ThemeMedia); - widget->media->type = rofi_theme_parse_media_type ( $4 ); - widget->media->boolv = $9; + ThemeWidget *wid = rofi_theme_find_or_create_name ( $1, name ); + wid->set = TRUE; + wid->media = g_slice_new0(ThemeMedia); + wid->media->type = rofi_theme_parse_media_type ( $4 ); + wid->media->boolv = $9; for ( unsigned int i = 0; i < $13->num_widgets; i++ ) { ThemeWidget *d = $13->widgets[i]; - rofi_theme_parse_merge_widgets(widget, d); + rofi_theme_parse_merge_widgets(wid, d); } g_free ( $4 ); g_free ( name ); @@ -487,10 +487,10 @@ t_config_property { for ( GList *iter = g_list_first( $1) ; iter; iter = g_list_next(iter)){ - ThemeWidget *widget = rofi_configuration; - widget = rofi_theme_find_or_create_name ( widget, iter->data ); - widget->set = TRUE; - rofi_theme_widget_add_properties ( widget, $3); + ThemeWidget *wid = rofi_configuration; + wid = rofi_theme_find_or_create_name ( wid, iter->data ); + wid->set = TRUE; + rofi_theme_widget_add_properties ( wid, $3); } if ( $3 ) { g_hash_table_destroy ( $3 ); diff --git a/meson.build b/meson.build index e49883c4a..f043c859b 100644 --- a/meson.build +++ b/meson.build @@ -25,7 +25,8 @@ flags = [ '-Wunreachable-code', '-Werror=missing-prototypes', '-Wno-overlength-strings', - '-Wno-inline' # A bit too noisy with Bison… + '-Wno-inline', # A bit too noisy with Bison… + '-Wshadow' ] foreach f : flags if c_compiler.has_argument(f) diff --git a/source/modes/dmenu.c b/source/modes/dmenu.c index d393fd36f..026244f6b 100644 --- a/source/modes/dmenu.c +++ b/source/modes/dmenu.c @@ -574,14 +574,13 @@ static int dmenu_mode_init(Mode *sw) { Property *p = rofi_theme_property_create(P_INTEGER); p->name = g_strdup("lines"); p->value.i = lines; - ThemeWidget *widget = - rofi_theme_find_or_create_name(rofi_theme, "listview"); + ThemeWidget *wid = rofi_theme_find_or_create_name(rofi_theme, "listview"); GHashTable *table = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)rofi_theme_property_free); g_hash_table_replace(table, p->name, p); - rofi_theme_widget_add_properties(widget, table); + rofi_theme_widget_add_properties(wid, table); g_hash_table_destroy(table); } diff --git a/source/rofi.c b/source/rofi.c index 9ebe28df6..a1a09853e 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -328,7 +328,8 @@ static void print_main_application_options(int is_term) { "Behave as a normal window. (experimental)", NULL, is_term); print_help_msg("-transient-window", "", "Behave as a modal dialog that is transient to the currently " - "focused window. (experimental)", NULL, is_term); + "focused window. (experimental)", + NULL, is_term); print_help_msg("-show", "[mode]", "Show the mode 'mode' and exit. The mode has to be enabled.", NULL, is_term); diff --git a/source/theme.c b/source/theme.c index 00aad8cce..c2a32f877 100644 --- a/source/theme.c +++ b/source/theme.c @@ -237,23 +237,23 @@ void rofi_theme_reset(void) { rofi_theme->name = g_strdup("Root"); } -void rofi_theme_free(ThemeWidget *widget) { - if (widget == NULL) { +void rofi_theme_free(ThemeWidget *wid) { + if (wid == NULL) { return; } - if (widget->properties) { - g_hash_table_destroy(widget->properties); - widget->properties = NULL; + if (wid->properties) { + g_hash_table_destroy(wid->properties); + wid->properties = NULL; } - if (widget->media) { - g_slice_free(ThemeMedia, widget->media); + if (wid->media) { + g_slice_free(ThemeMedia, wid->media); } - for (unsigned int i = 0; i < widget->num_widgets; i++) { - rofi_theme_free(widget->widgets[i]); + for (unsigned int i = 0; i < wid->num_widgets; i++) { + rofi_theme_free(wid->widgets[i]); } - g_free(widget->widgets); - g_free(widget->name); - g_slice_free(ThemeWidget, widget); + g_free(wid->widgets); + g_free(wid->name); + g_slice_free(ThemeWidget, wid); } /** @@ -521,29 +521,29 @@ static void int_rofi_theme_print_property(Property *p) { } } -static void rofi_theme_print_property_index(size_t pnl, int depth, +static void rofi_theme_print_property_index(size_t pnl, int cur_depth, Property *p) { int pl = strlen(p->name); - printf("%*s%s:%*s ", depth, "", p->name, (int)pnl - pl, ""); + printf("%*s%s:%*s ", cur_depth, "", p->name, (int)pnl - pl, ""); int_rofi_theme_print_property(p); putchar(';'); putchar('\n'); } -void rofi_theme_print_index(ThemeWidget *widget, int index) { +void rofi_theme_print_index(ThemeWidget *wid, int index) { GHashTableIter iter; gpointer key, value; - if (widget->media) { - printf("%s {\n", widget->name); - for (unsigned int i = 0; i < widget->num_widgets; i++) { - rofi_theme_print_index(widget->widgets[i], index + 4); + if (wid->media) { + printf("%s {\n", wid->name); + for (unsigned int i = 0; i < wid->num_widgets; i++) { + rofi_theme_print_index(wid->widgets[i], index + 4); } printf("}\n"); } else { - if (widget->properties) { + if (wid->properties) { GList *list = NULL; - ThemeWidget *w = widget; + ThemeWidget *w = wid; while (w) { if (g_strcmp0(w->name, "Root") == 0) { break; @@ -571,12 +571,12 @@ void rofi_theme_print_index(ThemeWidget *widget, int index) { printf("%*s* {\n", index, ""); } size_t property_name_length = 0; - g_hash_table_iter_init(&iter, widget->properties); + g_hash_table_iter_init(&iter, wid->properties); while (g_hash_table_iter_next(&iter, &key, &value)) { Property *pv = (Property *)value; property_name_length = MAX(strlen(pv->name), property_name_length); } - g_hash_table_iter_init(&iter, widget->properties); + g_hash_table_iter_init(&iter, wid->properties); while (g_hash_table_iter_next(&iter, &key, &value)) { Property *pv = (Property *)value; rofi_theme_print_property_index(property_name_length, index + 4, pv); @@ -584,17 +584,17 @@ void rofi_theme_print_index(ThemeWidget *widget, int index) { printf("%*s}\n", index, ""); g_list_free(list); } - for (unsigned int i = 0; i < widget->num_widgets; i++) { - rofi_theme_print_index(widget->widgets[i], index); + for (unsigned int i = 0; i < wid->num_widgets; i++) { + rofi_theme_print_index(wid->widgets[i], index); } } } -void rofi_theme_print(ThemeWidget *widget) { - if (widget != NULL) { +void rofi_theme_print(ThemeWidget *wid) { + if (wid != NULL) { printf("/**\n * rofi -dump-theme output.\n * Rofi version: %s\n **/\n", PACKAGE_VERSION); - rofi_theme_print_index(widget, 0); + rofi_theme_print_index(wid, 0); } } @@ -651,36 +651,36 @@ static void rofi_theme_copy_property_int(G_GNUC_UNUSED gpointer key, Property *p = rofi_theme_property_copy((Property *)value, NULL); g_hash_table_replace(table, p->name, p); } -void rofi_theme_widget_add_properties(ThemeWidget *widget, GHashTable *table) { +void rofi_theme_widget_add_properties(ThemeWidget *wid, GHashTable *table) { if (table == NULL) { return; } - if (widget->properties == NULL) { - widget->properties = + if (wid->properties == NULL) { + wid->properties = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)rofi_theme_property_free); } - g_hash_table_foreach(table, rofi_theme_copy_property_int, widget->properties); + g_hash_table_foreach(table, rofi_theme_copy_property_int, wid->properties); } /** * Public API */ -static inline ThemeWidget *rofi_theme_find_single(ThemeWidget *widget, +static inline ThemeWidget *rofi_theme_find_single(ThemeWidget *wid, const char *name) { - for (unsigned int j = 0; widget && j < widget->num_widgets; j++) { - if (g_strcmp0(widget->widgets[j]->name, name) == 0) { - return widget->widgets[j]; + for (unsigned int j = 0; wid && j < wid->num_widgets; j++) { + if (g_strcmp0(wid->widgets[j]->name, name) == 0) { + return wid->widgets[j]; } } - return widget; + return wid; } -static ThemeWidget *rofi_theme_find(ThemeWidget *widget, const char *name, +static ThemeWidget *rofi_theme_find(ThemeWidget *wid, const char *name, const gboolean exact) { - if (widget == NULL || name == NULL) { - return widget; + if (wid == NULL || name == NULL) { + return wid; } char *tname = g_strdup(name); char *saveptr = NULL; @@ -688,9 +688,9 @@ static ThemeWidget *rofi_theme_find(ThemeWidget *widget, const char *name, for (const char *iter = strtok_r(tname, ".", &saveptr); iter != NULL; iter = strtok_r(NULL, ".", &saveptr)) { found = FALSE; - ThemeWidget *f = rofi_theme_find_single(widget, iter); - if (f != widget) { - widget = f; + ThemeWidget *f = rofi_theme_find_single(wid, iter); + if (f != wid) { + wid = f; found = TRUE; } else if (exact) { break; @@ -698,16 +698,16 @@ static ThemeWidget *rofi_theme_find(ThemeWidget *widget, const char *name, } g_free(tname); if (!exact || found) { - return widget; + return wid; } return NULL; } -static void rofi_theme_resolve_link_property(Property *p, int depth) { +static void rofi_theme_resolve_link_property(Property *p, int cur_depth) { // Set name, remove '@' prefix. const char *name = p->value.link.name; // + (*(p->value.link.name)== '@'?1:0; g_info("Resolving link to %s", p->value.link.name); - if (depth > 20) { + if (cur_depth > 20) { g_warning("Found more then 20 redirects for property. Stopping."); p->value.link.ref = p; return; @@ -719,7 +719,7 @@ static void rofi_theme_resolve_link_property(Property *p, int depth) { g_info("Resolving link %s found: %s", p->value.link.name, pr->name); if (pr->type == P_LINK) { if (pr->value.link.ref == NULL) { - rofi_theme_resolve_link_property(pr, depth + 1); + rofi_theme_resolve_link_property(pr, cur_depth + 1); } if (pr->value.link.ref != pr) { p->value.link.ref = pr->value.link.ref; @@ -740,12 +740,11 @@ static void rofi_theme_resolve_link_property(Property *p, int depth) { p->value.link.ref = p; } -Property *rofi_theme_find_property(ThemeWidget *widget, PropertyType type, +Property *rofi_theme_find_property(ThemeWidget *wid, PropertyType type, const char *property, gboolean exact) { - while (widget) { - if (widget->properties && - g_hash_table_contains(widget->properties, property)) { - Property *p = g_hash_table_lookup(widget->properties, property); + while (wid) { + if (wid->properties && g_hash_table_contains(wid->properties, property)) { + Property *p = g_hash_table_lookup(wid->properties, property); if (p->type == P_INHERIT) { return p; } @@ -767,98 +766,94 @@ Property *rofi_theme_find_property(ThemeWidget *widget, PropertyType type, } g_debug("Found property: '%s' on '%s', but type %s does not match " "expected type %s.", - property, widget->name, PropertyTypeName[p->type], + property, wid->name, PropertyTypeName[p->type], PropertyTypeName[type]); } if (exact) { return NULL; } // Fall back to defaults. - widget = widget->parent; + wid = wid->parent; } return NULL; } ThemeWidget *rofi_config_find_widget(const char *name, const char *state, gboolean exact) { // First find exact match based on name. - ThemeWidget *widget = rofi_theme_find_single(rofi_configuration, name); - widget = rofi_theme_find(widget, state, exact); + ThemeWidget *wid = rofi_theme_find_single(rofi_configuration, name); + wid = rofi_theme_find(wid, state, exact); - return widget; + return wid; } ThemeWidget *rofi_theme_find_widget(const char *name, const char *state, gboolean exact) { // First find exact match based on name. - ThemeWidget *widget = rofi_theme_find_single(rofi_theme, name); - widget = rofi_theme_find(widget, state, exact); + ThemeWidget *wid = rofi_theme_find_single(rofi_theme, name); + wid = rofi_theme_find(wid, state, exact); - return widget; + return wid; } -static int rofi_theme_get_position_inside(Property *p, const widget *widget, +static int rofi_theme_get_position_inside(Property *p, const widget *wid, const char *property, int def) { if (p) { if (p->type == P_INHERIT) { - if (widget->parent) { + if (wid->parent) { ThemeWidget *parent = - rofi_theme_find_widget(widget->parent->name, widget->state, FALSE); + rofi_theme_find_widget(wid->parent->name, wid->state, FALSE); Property *pv = rofi_theme_find_property(parent, P_POSITION, property, FALSE); - return rofi_theme_get_position_inside(pv, widget->parent, property, - def); + return rofi_theme_get_position_inside(pv, wid->parent, property, def); } return def; } return p->value.i; } - g_debug("Theme entry: #%s %s property %s unset.", widget->name, - widget->state ? widget->state : "", property); + g_debug("Theme entry: #%s %s property %s unset.", wid->name, + wid->state ? wid->state : "", property); return def; } -int rofi_theme_get_position(const widget *widget, const char *property, - int def) { - ThemeWidget *wid = rofi_theme_find_widget(widget->name, widget->state, FALSE); - Property *p = rofi_theme_find_property(wid, P_POSITION, property, FALSE); - return rofi_theme_get_position_inside(p, widget, property, def); +int rofi_theme_get_position(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_POSITION, property, FALSE); + return rofi_theme_get_position_inside(p, wid, property, def); } -static int rofi_theme_get_integer_inside(Property *p, const widget *widget, +static int rofi_theme_get_integer_inside(Property *p, const widget *wid, const char *property, int def) { if (p) { if (p->type == P_INHERIT) { - if (widget->parent) { + if (wid->parent) { ThemeWidget *parent = - rofi_theme_find_widget(widget->parent->name, widget->state, FALSE); + rofi_theme_find_widget(wid->parent->name, wid->state, FALSE); Property *pv = rofi_theme_find_property(parent, P_INTEGER, property, FALSE); - return rofi_theme_get_integer_inside(pv, widget->parent, property, def); + return rofi_theme_get_integer_inside(pv, wid->parent, property, def); } return def; } return p->value.i; } - g_debug("Theme entry: #%s %s property %s unset.", widget->name, - widget->state ? widget->state : "", property); + g_debug("Theme entry: #%s %s property %s unset.", wid->name, + wid->state ? wid->state : "", property); return def; } -int rofi_theme_get_integer(const widget *widget, const char *property, - int def) { - ThemeWidget *wid = rofi_theme_find_widget(widget->name, widget->state, FALSE); - Property *p = rofi_theme_find_property(wid, P_INTEGER, property, FALSE); - return (int)rofi_theme_get_integer_inside(p, widget, property, (double)def); +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); } static RofiDistance rofi_theme_get_distance_inside(Property *p, - const widget *widget, + const widget *wid, const char *property, int def) { if (p) { if (p->type == P_INHERIT) { - if (widget->parent) { + if (wid->parent) { ThemeWidget *parent = - rofi_theme_find_widget(widget->parent->name, widget->state, FALSE); + rofi_theme_find_widget(wid->parent->name, wid->state, FALSE); Property *pv = rofi_theme_find_property(parent, P_PADDING, property, FALSE); - return rofi_theme_get_distance_inside(pv, widget->parent, property, - def); + return rofi_theme_get_distance_inside(pv, wid->parent, property, def); } return (RofiDistance){ .base = {def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, @@ -871,220 +866,218 @@ static RofiDistance rofi_theme_get_distance_inside(Property *p, } return p->value.padding.left; } - g_debug("Theme entry: #%s %s property %s unset.", widget->name, - widget->state ? widget->state : "", property); + g_debug("Theme entry: #%s %s property %s unset.", wid->name, + wid->state ? wid->state : "", property); return (RofiDistance){ .base = {def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID}; } -RofiDistance rofi_theme_get_distance(const widget *widget, const char *property, +RofiDistance rofi_theme_get_distance(const widget *wid, const char *property, int def) { - ThemeWidget *wid = rofi_theme_find_widget(widget->name, widget->state, FALSE); - Property *p = rofi_theme_find_property(wid, P_PADDING, property, FALSE); - return rofi_theme_get_distance_inside(p, widget, property, def); + ThemeWidget *wid_find = rofi_theme_find_widget(wid->name, wid->state, FALSE); + Property *p = rofi_theme_find_property(wid_find, P_PADDING, property, FALSE); + return rofi_theme_get_distance_inside(p, wid, property, def); } -static int rofi_theme_get_boolean_inside(Property *p, const widget *widget, +static int rofi_theme_get_boolean_inside(Property *p, const widget *wid, const char *property, int def) { if (p) { if (p->type == P_INHERIT) { - if (widget->parent) { + if (wid->parent) { ThemeWidget *parent = - rofi_theme_find_widget(widget->parent->name, widget->state, FALSE); + rofi_theme_find_widget(wid->parent->name, wid->state, FALSE); Property *pv = rofi_theme_find_property(parent, P_BOOLEAN, property, FALSE); - return rofi_theme_get_boolean_inside(pv, widget->parent, property, def); + return rofi_theme_get_boolean_inside(pv, wid->parent, property, def); } return def; } return p->value.b; } - g_debug("Theme entry: #%s %s property %s unset.", widget->name, - widget->state ? widget->state : "", property); + g_debug("Theme entry: #%s %s property %s unset.", wid->name, + wid->state ? wid->state : "", property); return def; } -int rofi_theme_get_boolean(const widget *widget, const char *property, - int def) { - ThemeWidget *wid = rofi_theme_find_widget(widget->name, widget->state, FALSE); - Property *p = rofi_theme_find_property(wid, P_BOOLEAN, property, FALSE); - return rofi_theme_get_boolean_inside(p, widget, property, def); +int rofi_theme_get_boolean(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_BOOLEAN, property, FALSE); + return rofi_theme_get_boolean_inside(p, wid, property, def); } static RofiOrientation rofi_theme_get_orientation_inside(Property *p, - const widget *widget, + const widget *wid, const char *property, RofiOrientation def) { if (p) { if (p->type == P_INHERIT) { - if (widget->parent) { + if (wid->parent) { ThemeWidget *parent = - rofi_theme_find_widget(widget->parent->name, widget->state, FALSE); + rofi_theme_find_widget(wid->parent->name, wid->state, FALSE); Property *pv = rofi_theme_find_property(parent, P_ORIENTATION, property, FALSE); - return rofi_theme_get_orientation_inside(pv, widget->parent, property, + return rofi_theme_get_orientation_inside(pv, wid->parent, property, def); } return def; } return p->value.b; } - g_debug("Theme entry: #%s %s property %s unset.", widget->name, - widget->state ? widget->state : "", property); + g_debug("Theme entry: #%s %s property %s unset.", wid->name, + wid->state ? wid->state : "", property); return def; } -RofiOrientation rofi_theme_get_orientation(const widget *widget, +RofiOrientation rofi_theme_get_orientation(const widget *wid, const char *property, RofiOrientation def) { - ThemeWidget *wid = rofi_theme_find_widget(widget->name, widget->state, FALSE); - Property *p = rofi_theme_find_property(wid, P_ORIENTATION, property, FALSE); - return rofi_theme_get_orientation_inside(p, widget, property, def); + ThemeWidget *wid_find = rofi_theme_find_widget(wid->name, wid->state, FALSE); + Property *p = + rofi_theme_find_property(wid_find, P_ORIENTATION, property, FALSE); + return rofi_theme_get_orientation_inside(p, wid, property, def); } static RofiCursorType rofi_theme_get_cursor_type_inside(Property *p, - const widget *widget, + const widget *wid, const char *property, RofiCursorType def) { if (p) { if (p->type == P_INHERIT) { - if (widget->parent) { + if (wid->parent) { ThemeWidget *parent = - rofi_theme_find_widget(widget->parent->name, widget->state, FALSE); + rofi_theme_find_widget(wid->parent->name, wid->state, FALSE); Property *pv = rofi_theme_find_property(parent, P_CURSOR, property, FALSE); - return rofi_theme_get_cursor_type_inside(pv, widget->parent, property, + return rofi_theme_get_cursor_type_inside(pv, wid->parent, property, def); } return def; } return p->value.i; } - g_debug("Theme entry: #%s %s property %s unset.", widget->name, - widget->state ? widget->state : "", property); + g_debug("Theme entry: #%s %s property %s unset.", wid->name, + wid->state ? wid->state : "", property); return def; } -RofiCursorType rofi_theme_get_cursor_type(const widget *widget, +RofiCursorType rofi_theme_get_cursor_type(const widget *wid, const char *property, RofiCursorType def) { - ThemeWidget *wid = rofi_theme_find_widget(widget->name, widget->state, FALSE); - Property *p = rofi_theme_find_property(wid, P_CURSOR, property, FALSE); - return rofi_theme_get_cursor_type_inside(p, widget, property, def); + ThemeWidget *wid_find = rofi_theme_find_widget(wid->name, wid->state, FALSE); + Property *p = rofi_theme_find_property(wid_find, P_CURSOR, property, FALSE); + return rofi_theme_get_cursor_type_inside(p, wid, property, def); } -static const char *rofi_theme_get_string_inside(Property *p, - const widget *widget, +static const char *rofi_theme_get_string_inside(Property *p, const widget *wid, const char *property, const char *def) { if (p) { if (p->type == P_INHERIT) { - if (widget->parent) { + if (wid->parent) { ThemeWidget *parent = - rofi_theme_find_widget(widget->parent->name, widget->state, FALSE); + rofi_theme_find_widget(wid->parent->name, wid->state, FALSE); Property *pv = rofi_theme_find_property(parent, P_STRING, property, FALSE); - return rofi_theme_get_string_inside(pv, widget->parent, property, def); + return rofi_theme_get_string_inside(pv, wid->parent, property, def); } return def; } return p->value.s; } - g_debug("Theme entry: #%s %s property %s unset.", widget->name, - widget->state ? widget->state : "", property); + g_debug("Theme entry: #%s %s property %s unset.", wid->name, + wid->state ? wid->state : "", property); return def; } -const char *rofi_theme_get_string(const widget *widget, const char *property, +const char *rofi_theme_get_string(const widget *wid, const char *property, const char *def) { - ThemeWidget *wid = rofi_theme_find_widget(widget->name, widget->state, FALSE); - Property *p = rofi_theme_find_property(wid, P_STRING, property, FALSE); - return rofi_theme_get_string_inside(p, widget, property, def); + ThemeWidget *wid_find = rofi_theme_find_widget(wid->name, wid->state, FALSE); + Property *p = rofi_theme_find_property(wid_find, P_STRING, property, FALSE); + return rofi_theme_get_string_inside(p, wid, property, def); } static double rofi_theme_get_double_integer_fb_inside(Property *p, - const widget *widget, + const widget *wid, const char *property, double def) { if (p) { if (p->type == P_INHERIT) { - if (widget->parent) { + if (wid->parent) { ThemeWidget *parent = - rofi_theme_find_widget(widget->parent->name, widget->state, FALSE); + rofi_theme_find_widget(wid->parent->name, wid->state, FALSE); Property *pv = rofi_theme_find_property(parent, P_INTEGER, property, FALSE); - return rofi_theme_get_double_integer_fb_inside(pv, widget->parent, + return rofi_theme_get_double_integer_fb_inside(pv, wid->parent, property, def); } return def; } return p->value.i; } - g_debug("Theme entry: #%s %s property %s unset.", widget->name, - widget->state ? widget->state : "", property); + g_debug("Theme entry: #%s %s property %s unset.", wid->name, + wid->state ? wid->state : "", property); return def; } static double rofi_theme_get_double_inside(const widget *orig, Property *p, - const widget *widget, + const widget *wid, const char *property, double def) { if (p) { if (p->type == P_INHERIT) { - if (widget->parent) { + if (wid->parent) { ThemeWidget *parent = - rofi_theme_find_widget(widget->parent->name, widget->state, FALSE); + rofi_theme_find_widget(wid->parent->name, wid->state, FALSE); Property *pv = rofi_theme_find_property(parent, P_DOUBLE, property, FALSE); - return rofi_theme_get_double_inside(orig, pv, widget->parent, property, + return rofi_theme_get_double_inside(orig, pv, wid->parent, property, def); } return def; } return p->value.f; } - ThemeWidget *wid = rofi_theme_find_widget(orig->name, widget->state, FALSE); + ThemeWidget *wid_find = rofi_theme_find_widget(orig->name, wid->state, FALSE); // Fallback to integer if double is not found. - p = rofi_theme_find_property(wid, P_INTEGER, property, FALSE); - return rofi_theme_get_double_integer_fb_inside(p, widget, property, def); + p = rofi_theme_find_property(wid_find, P_INTEGER, property, FALSE); + return rofi_theme_get_double_integer_fb_inside(p, wid, property, def); } -double rofi_theme_get_double(const widget *widget, const char *property, +double rofi_theme_get_double(const widget *wid, const char *property, double def) { - ThemeWidget *wid = rofi_theme_find_widget(widget->name, widget->state, FALSE); - Property *p = rofi_theme_find_property(wid, P_DOUBLE, property, FALSE); - return rofi_theme_get_double_inside(widget, p, widget, property, def); + ThemeWidget *wid_find = rofi_theme_find_widget(wid->name, wid->state, FALSE); + Property *p = rofi_theme_find_property(wid_find, P_DOUBLE, property, FALSE); + return rofi_theme_get_double_inside(wid, p, wid, property, def); } -static void rofi_theme_get_color_inside(const widget *widget, Property *p, +static void rofi_theme_get_color_inside(const widget *wid, Property *p, const char *property, cairo_t *d) { if (p) { if (p->type == P_INHERIT) { - if (widget->parent) { + if (wid->parent) { ThemeWidget *parent = - rofi_theme_find_widget(widget->parent->name, widget->state, FALSE); + rofi_theme_find_widget(wid->parent->name, wid->state, FALSE); Property *pv = rofi_theme_find_property(parent, P_COLOR, property, FALSE); - rofi_theme_get_color_inside(widget->parent, pv, property, d); + rofi_theme_get_color_inside(wid->parent, pv, property, d); } return; } cairo_set_source_rgba(d, p->value.color.red, p->value.color.green, p->value.color.blue, p->value.color.alpha); } else { - g_debug("Theme entry: #%s %s property %s unset.", widget->name, - widget->state ? widget->state : "", property); + g_debug("Theme entry: #%s %s property %s unset.", wid->name, + wid->state ? wid->state : "", property); } } -void rofi_theme_get_color(const widget *widget, const char *property, - cairo_t *d) { - ThemeWidget *wid = rofi_theme_find_widget(widget->name, widget->state, FALSE); - Property *p = rofi_theme_find_property(wid, P_COLOR, property, FALSE); - rofi_theme_get_color_inside(widget, p, property, d); +void rofi_theme_get_color(const widget *wid, const char *property, cairo_t *d) { + ThemeWidget *wid_find = rofi_theme_find_widget(wid->name, wid->state, FALSE); + Property *p = rofi_theme_find_property(wid_find, P_COLOR, property, FALSE); + rofi_theme_get_color_inside(wid, p, property, d); } -static gboolean rofi_theme_get_image_inside(Property *p, const widget *widget, +static gboolean rofi_theme_get_image_inside(Property *p, const widget *wid, const char *property, cairo_t *d) { if (p) { if (p->type == P_INHERIT) { - if (widget->parent) { + if (wid->parent) { ThemeWidget *parent = - rofi_theme_find_widget(widget->parent->name, widget->state, FALSE); + rofi_theme_find_widget(wid->parent->name, wid->state, FALSE); Property *pv = rofi_theme_find_property(parent, P_IMAGE, property, FALSE); - return rofi_theme_get_image_inside(pv, widget->parent, property, d); + return rofi_theme_get_image_inside(pv, wid->parent, property, d); } return FALSE; } @@ -1093,14 +1086,14 @@ static gboolean rofi_theme_get_image_inside(Property *p, const widget *widget, int hsize = -1; switch (p->value.image.scaling) { case ROFI_SCALE_BOTH: - wsize = widget->w; - hsize = widget->h; + wsize = wid->w; + hsize = wid->h; break; case ROFI_SCALE_WIDTH: - wsize = widget->w; + wsize = wid->w; break; case ROFI_SCALE_HEIGHT: - hsize = widget->h; + hsize = wid->h; break; case ROFI_SCALE_NONE: default: @@ -1126,25 +1119,23 @@ static gboolean rofi_theme_get_image_inside(Property *p, const widget *widget, cairo_pattern_t *pat = NULL; switch (p->value.image.dir) { case ROFI_DIRECTION_RIGHT: - pat = cairo_pattern_create_linear(0.0, 0.0, widget->w, 0.0); + pat = cairo_pattern_create_linear(0.0, 0.0, wid->w, 0.0); break; case ROFI_DIRECTION_LEFT: - pat = cairo_pattern_create_linear(widget->w, 0.0, 0.0, 0.0); + pat = cairo_pattern_create_linear(wid->w, 0.0, 0.0, 0.0); break; case ROFI_DIRECTION_BOTTOM: - pat = cairo_pattern_create_linear(0.0, 0.0, 0.0, widget->h); + pat = cairo_pattern_create_linear(0.0, 0.0, 0.0, wid->h); break; case ROFI_DIRECTION_TOP: - pat = cairo_pattern_create_linear(0.0, widget->h, 0.0, 0.0); + pat = cairo_pattern_create_linear(0.0, wid->h, 0.0, 0.0); break; case ROFI_DIRECTION_ANGLE: { - double offsety1 = - sin(G_PI * 2 * p->value.image.angle) * (widget->h / 2.0); - double offsetx1 = - cos(G_PI * 2 * p->value.image.angle) * (widget->w / 2.0); + double offsety1 = sin(G_PI * 2 * p->value.image.angle) * (wid->h / 2.0); + double offsetx1 = cos(G_PI * 2 * p->value.image.angle) * (wid->w / 2.0); pat = cairo_pattern_create_linear( - widget->w / 2.0 - offsetx1, widget->h / 2.0 - offsety1, - widget->w / 2.0 + offsetx1, widget->h / 2.0 + offsety1); + wid->w / 2.0 - offsetx1, wid->h / 2.0 - offsety1, + wid->w / 2.0 + offsetx1, wid->h / 2.0 + offsety1); break; } }; @@ -1174,29 +1165,28 @@ static gboolean rofi_theme_get_image_inside(Property *p, const widget *widget, } } } else { - g_debug("Theme entry: #%s %s property %s unset.", widget->name, - widget->state ? widget->state : "", property); + g_debug("Theme entry: #%s %s property %s unset.", wid->name, + wid->state ? wid->state : "", property); } return FALSE; } -gboolean rofi_theme_get_image(const widget *widget, const char *property, +gboolean rofi_theme_get_image(const widget *wid, const char *property, cairo_t *d) { - ThemeWidget *wid = rofi_theme_find_widget(widget->name, widget->state, FALSE); - Property *p = rofi_theme_find_property(wid, P_IMAGE, property, FALSE); - return rofi_theme_get_image_inside(p, widget, property, d); + ThemeWidget *wid_find = rofi_theme_find_widget(wid->name, wid->state, FALSE); + Property *p = rofi_theme_find_property(wid_find, P_IMAGE, property, FALSE); + return rofi_theme_get_image_inside(p, wid, property, d); } -static RofiPadding rofi_theme_get_padding_inside(Property *p, - const widget *widget, +static RofiPadding rofi_theme_get_padding_inside(Property *p, const widget *wid, const char *property, RofiPadding pad) { if (p) { if (p->type == P_INHERIT) { - if (widget->parent) { + if (wid->parent) { ThemeWidget *parent = - rofi_theme_find_widget(widget->parent->name, widget->state, FALSE); + rofi_theme_find_widget(wid->parent->name, wid->state, FALSE); Property *pv = rofi_theme_find_property(parent, P_PADDING, property, FALSE); - return rofi_theme_get_padding_inside(pv, widget->parent, property, pad); + return rofi_theme_get_padding_inside(pv, wid->parent, property, pad); } return pad; } @@ -1210,28 +1200,28 @@ static RofiPadding rofi_theme_get_padding_inside(Property *p, return (RofiPadding){d, d, d, d}; } } - g_debug("Theme entry: #%s %s property %s unset.", widget->name, - widget->state ? widget->state : "", property); + g_debug("Theme entry: #%s %s property %s unset.", wid->name, + wid->state ? wid->state : "", property); return pad; } -RofiPadding rofi_theme_get_padding(const widget *widget, const char *property, +RofiPadding rofi_theme_get_padding(const widget *wid, const char *property, RofiPadding pad) { - ThemeWidget *wid = rofi_theme_find_widget(widget->name, widget->state, FALSE); - Property *p = rofi_theme_find_property(wid, P_PADDING, property, FALSE); - return rofi_theme_get_padding_inside(p, widget, property, pad); + ThemeWidget *wid_find = rofi_theme_find_widget(wid->name, wid->state, FALSE); + Property *p = rofi_theme_find_property(wid_find, P_PADDING, property, FALSE); + return rofi_theme_get_padding_inside(p, wid, property, pad); } -static GList *rofi_theme_get_list_inside(Property *p, const widget *widget, +static GList *rofi_theme_get_list_inside(Property *p, const widget *wid, const char *property, PropertyType child_type) { if (p) { if (p->type == P_INHERIT) { - if (widget->parent) { + if (wid->parent) { ThemeWidget *parent = - rofi_theme_find_widget(widget->parent->name, widget->state, FALSE); + rofi_theme_find_widget(wid->parent->name, wid->state, FALSE); Property *pv = rofi_theme_find_property(parent, P_LIST, property, FALSE); - return rofi_theme_get_list_inside(pv, widget->parent, property, + return rofi_theme_get_list_inside(pv, wid->parent, property, child_type); } } else if (p->type == P_LIST) { @@ -1240,12 +1230,10 @@ static GList *rofi_theme_get_list_inside(Property *p, const widget *widget, } return NULL; } -GList *rofi_theme_get_list_distance(const widget *widget, - const char *property) { - ThemeWidget *wid2 = - rofi_theme_find_widget(widget->name, widget->state, FALSE); +GList *rofi_theme_get_list_distance(const widget *wid, const char *property) { + ThemeWidget *wid2 = rofi_theme_find_widget(wid->name, wid->state, FALSE); Property *p = rofi_theme_find_property(wid2, P_LIST, property, FALSE); - GList *list = rofi_theme_get_list_inside(p, widget, property, P_PADDING); + GList *list = rofi_theme_get_list_inside(p, wid, property, P_PADDING); GList *retv = NULL; for (GList *iter = g_list_first(list); iter != NULL; iter = g_list_next(iter)) { @@ -1268,11 +1256,10 @@ GList *rofi_theme_get_list_distance(const widget *widget, } return retv; } -GList *rofi_theme_get_list_strings(const widget *widget, const char *property) { - ThemeWidget *wid2 = - rofi_theme_find_widget(widget->name, widget->state, FALSE); +GList *rofi_theme_get_list_strings(const widget *wid, const char *property) { + ThemeWidget *wid2 = rofi_theme_find_widget(wid->name, wid->state, FALSE); Property *p = rofi_theme_find_property(wid2, P_LIST, property, FALSE); - GList *list = rofi_theme_get_list_inside(p, widget, property, P_STRING); + GList *list = rofi_theme_get_list_inside(p, wid, property, P_STRING); GList *retv = NULL; for (GList *iter = g_list_first(list); iter != NULL; iter = g_list_next(iter)) { @@ -1287,18 +1274,16 @@ GList *rofi_theme_get_list_strings(const widget *widget, const char *property) { } static RofiHighlightColorStyle -rofi_theme_get_highlight_inside(Property *p, widget *widget, - const char *property, +rofi_theme_get_highlight_inside(Property *p, widget *wid, const char *property, RofiHighlightColorStyle th) { if (p) { if (p->type == P_INHERIT) { - if (widget->parent) { + if (wid->parent) { ThemeWidget *parent = - rofi_theme_find_widget(widget->parent->name, widget->state, FALSE); + rofi_theme_find_widget(wid->parent->name, wid->state, FALSE); Property *pv = rofi_theme_find_property(parent, P_HIGHLIGHT, property, FALSE); - return rofi_theme_get_highlight_inside(pv, widget->parent, property, - th); + return rofi_theme_get_highlight_inside(pv, wid->parent, property, th); } return th; } else if (p->type == P_COLOR) { @@ -1309,27 +1294,28 @@ rofi_theme_get_highlight_inside(Property *p, widget *widget, return p->value.highlight; } else { - ThemeWidget *wid = - rofi_theme_find_widget(widget->name, widget->state, FALSE); - Property *p2 = rofi_theme_find_property(wid, P_COLOR, property, FALSE); + ThemeWidget *find_wid = + rofi_theme_find_widget(wid->name, wid->state, FALSE); + Property *p2 = rofi_theme_find_property(find_wid, P_COLOR, property, FALSE); if (p2 != NULL) { - return rofi_theme_get_highlight_inside(p2, widget, property, th); + return rofi_theme_get_highlight_inside(p2, wid, property, th); } return th; } - g_debug("Theme entry: #%s %s property %s unset.", widget->name, - widget->state ? widget->state : "", property); + g_debug("Theme entry: #%s %s property %s unset.", wid->name, + wid->state ? wid->state : "", property); return th; } -RofiHighlightColorStyle rofi_theme_get_highlight(widget *widget, +RofiHighlightColorStyle rofi_theme_get_highlight(widget *wid, const char *property, RofiHighlightColorStyle th) { - ThemeWidget *wid = rofi_theme_find_widget(widget->name, widget->state, FALSE); - Property *p = rofi_theme_find_property(wid, P_HIGHLIGHT, property, FALSE); + ThemeWidget *found_wid = rofi_theme_find_widget(wid->name, wid->state, FALSE); + Property *p = + rofi_theme_find_property(found_wid, P_HIGHLIGHT, property, FALSE); if (p == NULL) { - p = rofi_theme_find_property(wid, P_COLOR, property, FALSE); + p = rofi_theme_find_property(found_wid, P_COLOR, property, FALSE); } - return rofi_theme_get_highlight_inside(p, widget, property, th); + return rofi_theme_get_highlight_inside(p, wid, property, th); } static double get_pixels(RofiDistanceUnit *unit, RofiOrientation ori) { double val = unit->distance; @@ -1468,81 +1454,81 @@ static void rofi_theme_parse_process_conditionals_int(workarea mon, unsigned int i = 0; // for (unsigned int i = 0; i < rwidget->num_widgets; i++) { while (i < rwidget->num_widgets) { - ThemeWidget *widget = rwidget->widgets[i]; - if (widget->media != NULL) { + ThemeWidget *child_widget = rwidget->widgets[i]; + if (child_widget->media != NULL) { rwidget->num_widgets--; for (unsigned x = i; x < rwidget->num_widgets; x++) { rwidget->widgets[x] = rwidget->widgets[x + 1]; } rwidget->widgets[rwidget->num_widgets] = NULL; - switch (widget->media->type) { + switch (child_widget->media->type) { case THEME_MEDIA_TYPE_MIN_WIDTH: { - int w = widget->media->value; + int w = child_widget->media->value; if (mon.w >= w) { - for (unsigned int x = 0; x < widget->num_widgets; x++) { - rofi_theme_parse_merge_widgets(rwidget, widget->widgets[x]); + for (unsigned int x = 0; x < child_widget->num_widgets; x++) { + rofi_theme_parse_merge_widgets(rwidget, child_widget->widgets[x]); } } break; } case THEME_MEDIA_TYPE_MAX_WIDTH: { - int w = widget->media->value; + int w = child_widget->media->value; if (mon.w < w) { - for (unsigned int x = 0; x < widget->num_widgets; x++) { - rofi_theme_parse_merge_widgets(rwidget, widget->widgets[x]); + for (unsigned int x = 0; x < child_widget->num_widgets; x++) { + rofi_theme_parse_merge_widgets(rwidget, child_widget->widgets[x]); } } break; } case THEME_MEDIA_TYPE_MIN_HEIGHT: { - int h = widget->media->value; + int h = child_widget->media->value; if (mon.h >= h) { - for (unsigned int x = 0; x < widget->num_widgets; x++) { - rofi_theme_parse_merge_widgets(rwidget, widget->widgets[x]); + for (unsigned int x = 0; x < child_widget->num_widgets; x++) { + rofi_theme_parse_merge_widgets(rwidget, child_widget->widgets[x]); } } else { } break; } case THEME_MEDIA_TYPE_MAX_HEIGHT: { - int h = widget->media->value; + int h = child_widget->media->value; if (mon.h < h) { - for (unsigned int x = 0; x < widget->num_widgets; x++) { - rofi_theme_parse_merge_widgets(rwidget, widget->widgets[x]); + for (unsigned int x = 0; x < child_widget->num_widgets; x++) { + rofi_theme_parse_merge_widgets(rwidget, child_widget->widgets[x]); } } break; } case THEME_MEDIA_TYPE_MON_ID: { - if (mon.monitor_id == widget->media->value) { - for (unsigned int x = 0; x < widget->num_widgets; x++) { - rofi_theme_parse_merge_widgets(rwidget, widget->widgets[x]); + if (mon.monitor_id == child_widget->media->value) { + for (unsigned int x = 0; x < child_widget->num_widgets; x++) { + rofi_theme_parse_merge_widgets(rwidget, child_widget->widgets[x]); } } break; } case THEME_MEDIA_TYPE_MIN_ASPECT_RATIO: { - double r = widget->media->value; + double r = child_widget->media->value; if ((mon.w / (double)mon.h) >= r) { - for (unsigned int x = 0; x < widget->num_widgets; x++) { - rofi_theme_parse_merge_widgets(rwidget, widget->widgets[x]); + for (unsigned int x = 0; x < child_widget->num_widgets; x++) { + rofi_theme_parse_merge_widgets(rwidget, child_widget->widgets[x]); } } break; } case THEME_MEDIA_TYPE_MAX_ASPECT_RATIO: { - double r = widget->media->value; + double r = child_widget->media->value; if ((mon.w / (double)mon.h) < r) { - for (unsigned int x = 0; x < widget->num_widgets; x++) { - rofi_theme_parse_merge_widgets(rwidget, widget->widgets[x]); + for (unsigned int x = 0; x < child_widget->num_widgets; x++) { + rofi_theme_parse_merge_widgets(rwidget, child_widget->widgets[x]); } } break; } case THEME_MEDIA_TYPE_BOOLEAN: { - if (widget->media->boolv) { - for (unsigned int x = 0; x < widget->num_widgets; x++) { - rofi_theme_parse_merge_widgets(rwidget, widget->widgets[x]); + if (child_widget->media->boolv) { + for (unsigned int x = 0; x < child_widget->num_widgets; x++) { + rofi_theme_parse_merge_widgets(rwidget, child_widget->widgets[x]); } } break; @@ -1552,10 +1538,10 @@ static void rofi_theme_parse_process_conditionals_int(workarea mon, break; } } - rofi_theme_free(widget); + rofi_theme_free(child_widget); // endif } else { - rofi_theme_parse_process_conditionals_int(mon, widget); + rofi_theme_parse_process_conditionals_int(mon, child_widget); i++; } } @@ -1578,21 +1564,21 @@ static void rofi_theme_parse_process_links_int(ThemeWidget *wid) { } for (unsigned int i = 0; i < wid->num_widgets; i++) { - ThemeWidget *widget = wid->widgets[i]; - rofi_theme_parse_process_links_int(widget); - if (widget->properties == NULL) { + ThemeWidget *child_widget = wid->widgets[i]; + rofi_theme_parse_process_links_int(child_widget); + if (child_widget->properties == NULL) { continue; } GHashTableIter iter; gpointer key, value; - g_hash_table_iter_init(&iter, widget->properties); + g_hash_table_iter_init(&iter, child_widget->properties); while (g_hash_table_iter_next(&iter, &key, &value)) { Property *pv = (Property *)value; if (pv->type == P_LINK) { if (pv->value.link.ref == NULL) { rofi_theme_resolve_link_property(pv, 0); if (pv->value.link.ref == pv) { - char *n = rofi_theme_widget_get_name(widget); + char *n = rofi_theme_widget_get_name(child_widget); GString *str = g_string_new(NULL); g_string_printf(str, "Validating the theme failed: the variable '%s' in " @@ -1648,16 +1634,16 @@ ThemeMediaType rofi_theme_parse_media_type(const char *type) { } static gboolean rofi_theme_has_property_inside(Property *p, - const widget *widget, + const widget *wid_in, const char *property) { if (p) { if (p->type == P_INHERIT) { - if (widget->parent) { + if (wid_in->parent) { ThemeWidget *parent = - rofi_theme_find_widget(widget->parent->name, widget->state, FALSE); + rofi_theme_find_widget(wid_in->parent->name, wid_in->state, FALSE); Property *pp = rofi_theme_find_property(parent, P_STRING, property, FALSE); - return rofi_theme_has_property_inside(pp, widget->parent, property); + return rofi_theme_has_property_inside(pp, wid_in->parent, property); } return FALSE; } @@ -1665,8 +1651,8 @@ static gboolean rofi_theme_has_property_inside(Property *p, } return FALSE; } -gboolean rofi_theme_has_property(const widget *widget, const char *property) { - ThemeWidget *wid = rofi_theme_find_widget(widget->name, widget->state, FALSE); +gboolean rofi_theme_has_property(const widget *wid_in, const char *property) { + ThemeWidget *wid = rofi_theme_find_widget(wid_in->name, wid_in->state, FALSE); Property *p = rofi_theme_find_property(wid, P_STRING, property, FALSE); - return rofi_theme_has_property_inside(p, widget, property); + return rofi_theme_has_property_inside(p, wid_in, property); } diff --git a/source/view.c b/source/view.c index 995a79efd..e802a7489 100644 --- a/source/view.c +++ b/source/view.c @@ -572,9 +572,9 @@ static void rofi_view_set_user_timeout(G_GNUC_UNUSED gpointer data) { CacheState.user_timeout = g_timeout_add(delay * 1000, rofi_view_user_timeout, NULL); } else { - Property *p = rofi_theme_find_property(wid, P_DOUBLE, "delay", TRUE); - if (p != NULL && p->type == P_DOUBLE && p->value.f > 0.01) { - double delay = p->value.f; + Property *prop = rofi_theme_find_property(wid, P_DOUBLE, "delay", TRUE); + 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); } @@ -1305,9 +1305,9 @@ static void selection_changed_callback(G_GNUC_UNUSED listview *lv, int icon_height = widget_get_desired_height(WIDGET(state->icon_current_entry), WIDGET(state->icon_current_entry)->w); - cairo_surface_t *icon = + cairo_surface_t *surf_icon = mode_get_icon(state->sw, state->line_map[index], icon_height); - icon_set_surface(state->icon_current_entry, icon); + icon_set_surface(state->icon_current_entry, surf_icon); } else { icon_set_surface(state->icon_current_entry, NULL); } @@ -1325,9 +1325,9 @@ static void update_callback(textbox *t, icon *ico, unsigned int index, if (ico) { int icon_height = widget_get_desired_height(WIDGET(ico), WIDGET(ico)->w); - cairo_surface_t *icon = + cairo_surface_t *surf_icon = mode_get_icon(state->sw, state->line_map[index], icon_height); - icon_set_surface(ico, icon); + icon_set_surface(ico, surf_icon); } if (t) { // TODO needed for markup. @@ -2578,14 +2578,14 @@ int rofi_view_error_dialog(const char *msg, int markup) { state->finalize = process_result; state->main_window = box_create(NULL, "window", ROFI_ORIENTATION_VERTICAL); - box *box = box_create(WIDGET(state->main_window), "error-message", - ROFI_ORIENTATION_VERTICAL); - box_add(state->main_window, WIDGET(box), TRUE); + box *new_box = box_create(WIDGET(state->main_window), "error-message", + ROFI_ORIENTATION_VERTICAL); + box_add(state->main_window, WIDGET(new_box), TRUE); state->text = - textbox_create(WIDGET(box), WIDGET_TYPE_TEXTBOX_TEXT, "textbox", + textbox_create(WIDGET(new_box), WIDGET_TYPE_TEXTBOX_TEXT, "textbox", (TB_AUTOHEIGHT | TB_WRAP) + ((markup) ? TB_MARKUP : 0), NORMAL, (msg != NULL) ? msg : "", 0, 0); - box_add(box, WIDGET(state->text), TRUE); + box_add(new_box, WIDGET(state->text), TRUE); // Make sure we enable fixed num lines when in normal window mode. if ((CacheState.flags & MENU_NORMAL_WINDOW) == MENU_NORMAL_WINDOW) { diff --git a/source/widgets/box.c b/source/widgets/box.c index e0425b8e3..435ba1b76 100644 --- a/source/widgets/box.c +++ b/source/widgets/box.c @@ -284,34 +284,34 @@ static void box_free(widget *wid) { g_free(b); } -void box_add(box *box, widget *child, gboolean expand) { - if (box == NULL) { +void box_add(box *wid, widget *child, gboolean expand) { + if (wid == NULL) { return; } // Make sure box is width/heigh enough. - if (box->type == ROFI_ORIENTATION_VERTICAL) { - int width = box->widget.w; + if (wid->type == ROFI_ORIENTATION_VERTICAL) { + int width = wid->widget.w; width = - MAX(width, child->w + widget_padding_get_padding_width(WIDGET(box))); - box->widget.w = width; + MAX(width, child->w + widget_padding_get_padding_width(WIDGET(wid))); + wid->widget.w = width; } else { - int height = box->widget.h; + int height = wid->widget.h; height = - MAX(height, child->h + widget_padding_get_padding_height(WIDGET(box))); - box->widget.h = height; + MAX(height, child->h + widget_padding_get_padding_height(WIDGET(wid))); + wid->widget.h = height; } child->expand = rofi_theme_get_boolean(child, "expand", expand); - g_assert(child->parent == WIDGET(box)); - box->children = g_list_append(box->children, (void *)child); - widget_update(WIDGET(box)); + g_assert(child->parent == WIDGET(wid)); + wid->children = g_list_append(wid->children, (void *)child); + widget_update(WIDGET(wid)); } -static void box_resize(widget *widget, short w, short h) { - box *b = (box *)widget; +static void box_resize(widget *wid, short w, short h) { + box *b = (box *)wid; if (b->widget.w != w || b->widget.h != h) { b->widget.w = w; b->widget.h = h; - widget_update(widget); + widget_update(wid); } } diff --git a/source/widgets/container.c b/source/widgets/container.c index 63e04495a..172d69406 100644 --- a/source/widgets/container.c +++ b/source/widgets/container.c @@ -42,13 +42,13 @@ struct _container { static void container_update(widget *wid); -static int container_get_desired_height(widget *widget, const int width) { - container *b = (container *)widget; +static int container_get_desired_height(widget *wid, const int width) { + container *b = (container *)wid; int height = 0; if (b->child) { height += widget_get_desired_height(b->child, width); } - height += widget_padding_get_padding_height(widget); + height += widget_padding_get_padding_height(wid); return height; } @@ -65,21 +65,21 @@ static void container_free(widget *wid) { g_free(b); } -void container_add(container *container, widget *child) { - if (container == NULL) { +void container_add(container *cont, widget *child) { + if (cont == NULL) { return; } - container->child = child; - g_assert(child->parent == WIDGET(container)); - widget_update(WIDGET(container)); + cont->child = child; + g_assert(child->parent == WIDGET(cont)); + widget_update(WIDGET(cont)); } -static void container_resize(widget *widget, short w, short h) { - container *b = (container *)widget; +static void container_resize(widget *wid, short w, short h) { + container *b = (container *)wid; if (b->widget.w != w || b->widget.h != h) { b->widget.w = w; b->widget.h = h; - widget_update(widget); + widget_update(wid); } } diff --git a/source/widgets/icon.c b/source/widgets/icon.c index ebdd62f5a..f98fa2e72 100644 --- a/source/widgets/icon.c +++ b/source/widgets/icon.c @@ -53,9 +53,8 @@ struct _icon { cairo_surface_t *icon; }; -static int icon_get_desired_height(widget *widget, - G_GNUC_UNUSED const int width) { - icon *b = (icon *)widget; +static int icon_get_desired_height(widget *wid, G_GNUC_UNUSED const int width) { + icon *b = (icon *)wid; int height = b->size; if (b->squared == FALSE) { if (b->icon) { @@ -66,12 +65,11 @@ static int icon_get_desired_height(widget *widget, height = iconh * scale; } } - height += widget_padding_get_padding_height(widget); + height += widget_padding_get_padding_height(wid); return height; } -static int icon_get_desired_width(widget *widget, - G_GNUC_UNUSED const int height) { - icon *b = (icon *)widget; +static int icon_get_desired_width(widget *wid, G_GNUC_UNUSED const int height) { + icon *b = (icon *)wid; int width = b->size; if (b->squared == FALSE) { if (b->icon) { @@ -82,7 +80,7 @@ static int icon_get_desired_width(widget *widget, width = iconw * scale; } } - width += widget_padding_get_padding_width(widget); + width += widget_padding_get_padding_width(wid); return width; } @@ -129,26 +127,26 @@ static void icon_free(widget *wid) { g_free(b); } -static void icon_resize(widget *widget, short w, short h) { - icon *b = (icon *)widget; +static void icon_resize(widget *wid, short w, short h) { + icon *b = (icon *)wid; if (b->widget.w != w || b->widget.h != h) { b->widget.w = w; b->widget.h = h; - widget_update(widget); + widget_update(wid); } } -void icon_set_surface(icon *icon, cairo_surface_t *surf) { - icon->icon_fetch_id = 0; - if (icon->icon) { - cairo_surface_destroy(icon->icon); - icon->icon = NULL; +void icon_set_surface(icon *icon_widget, cairo_surface_t *surf) { + icon_widget->icon_fetch_id = 0; + if (icon_widget->icon) { + cairo_surface_destroy(icon_widget->icon); + icon_widget->icon = NULL; } if (surf) { cairo_surface_reference(surf); - icon->icon = surf; + icon_widget->icon = surf; } - widget_queue_redraw(WIDGET(icon)); + widget_queue_redraw(WIDGET(icon_widget)); } icon *icon_create(widget *parent, const char *name) { diff --git a/source/widgets/widget.c b/source/widgets/widget.c index 4aa3efa00..54f8c955f 100644 --- a/source/widgets/widget.c +++ b/source/widgets/widget.c @@ -55,126 +55,125 @@ void widget_init(widget *wid, widget *parent, WidgetType type, wid->enabled = rofi_theme_get_boolean(wid, "enabled", TRUE); } -void widget_set_state(widget *widget, const char *state) { - if (widget == NULL) { +void widget_set_state(widget *wid, const char *state) { + if (wid == NULL) { return; } - if (g_strcmp0(widget->state, state)) { - widget->state = state; + if (g_strcmp0(wid->state, state)) { + wid->state = state; // Update border. - widget->border = - rofi_theme_get_padding(widget, "border", widget->def_border); - widget->border_radius = rofi_theme_get_padding(widget, "border-radius", - widget->def_border_radius); - if (widget->set_state != NULL) { - widget->set_state(widget, state); + wid->border = rofi_theme_get_padding(wid, "border", wid->def_border); + wid->border_radius = + rofi_theme_get_padding(wid, "border-radius", wid->def_border_radius); + if (wid->set_state != NULL) { + wid->set_state(wid, state); } - widget_queue_redraw(widget); + widget_queue_redraw(wid); } } -int widget_intersect(const widget *widget, int x, int y) { - if (widget == NULL) { +int widget_intersect(const widget *wid, int x, int y) { + if (wid == NULL) { return FALSE; } - if (x >= (widget->x) && x < (widget->x + widget->w) && y >= (widget->y) && - y < (widget->y + widget->h)) { + if (x >= (wid->x) && x < (wid->x + wid->w) && y >= (wid->y) && + y < (wid->y + wid->h)) { return TRUE; } return FALSE; } -void widget_resize(widget *widget, short w, short h) { - if (widget == NULL) { +void widget_resize(widget *wid, short w, short h) { + if (wid == NULL) { return; } - if (widget->resize != NULL) { - if (widget->w != w || widget->h != h) { - widget->resize(widget, w, h); + if (wid->resize != NULL) { + if (wid->w != w || wid->h != h) { + wid->resize(wid, w, h); } } else { - widget->w = w; - widget->h = h; + wid->w = w; + wid->h = h; } // On a resize we always want to update. - widget_queue_redraw(widget); + widget_queue_redraw(wid); } -void widget_move(widget *widget, short x, short y) { - if (widget == NULL) { +void widget_move(widget *wid, short x, short y) { + if (wid == NULL) { return; } - widget->x = x; - widget->y = y; + wid->x = x; + wid->y = y; } -void widget_set_type(widget *widget, WidgetType type) { - if (widget == NULL) { +void widget_set_type(widget *wid, WidgetType type) { + if (wid == NULL) { return; } - widget->type = type; + wid->type = type; } -gboolean widget_enabled(widget *widget) { - if (widget == NULL) { +gboolean widget_enabled(widget *wid) { + if (wid == NULL) { return FALSE; } - return widget->enabled; + return wid->enabled; } -void widget_set_enabled(widget *widget, gboolean enabled) { - if (widget == NULL) { +void widget_set_enabled(widget *wid, gboolean enabled) { + if (wid == NULL) { return; } - if (widget->enabled != enabled) { - widget->enabled = enabled; - widget_update(widget); - widget_update(widget->parent); - widget_queue_redraw(widget); + if (wid->enabled != enabled) { + wid->enabled = enabled; + widget_update(wid); + widget_update(wid->parent); + widget_queue_redraw(wid); } } -void widget_draw(widget *widget, cairo_t *d) { - if (widget == NULL) { +void widget_draw(widget *wid, cairo_t *d) { + if (wid == NULL) { return; } // Check if enabled and if draw is implemented. - if (widget->enabled && widget->draw) { + if (wid->enabled && wid->draw) { // Don't draw if there is no space. - if (widget->h < 1 || widget->w < 1) { - widget->need_redraw = FALSE; + if (wid->h < 1 || wid->w < 1) { + wid->need_redraw = FALSE; return; } // Store current state. cairo_save(d); const int margin_left = - distance_get_pixel(widget->margin.left, ROFI_ORIENTATION_HORIZONTAL); + distance_get_pixel(wid->margin.left, ROFI_ORIENTATION_HORIZONTAL); const int margin_top = - distance_get_pixel(widget->margin.top, ROFI_ORIENTATION_VERTICAL); + distance_get_pixel(wid->margin.top, ROFI_ORIENTATION_VERTICAL); const int margin_right = - distance_get_pixel(widget->margin.right, ROFI_ORIENTATION_HORIZONTAL); + distance_get_pixel(wid->margin.right, ROFI_ORIENTATION_HORIZONTAL); const int margin_bottom = - distance_get_pixel(widget->margin.bottom, ROFI_ORIENTATION_VERTICAL); + distance_get_pixel(wid->margin.bottom, ROFI_ORIENTATION_VERTICAL); const int left = - distance_get_pixel(widget->border.left, ROFI_ORIENTATION_HORIZONTAL); + distance_get_pixel(wid->border.left, ROFI_ORIENTATION_HORIZONTAL); const int right = - distance_get_pixel(widget->border.right, ROFI_ORIENTATION_HORIZONTAL); + distance_get_pixel(wid->border.right, ROFI_ORIENTATION_HORIZONTAL); const int top = - distance_get_pixel(widget->border.top, ROFI_ORIENTATION_VERTICAL); + distance_get_pixel(wid->border.top, ROFI_ORIENTATION_VERTICAL); const int bottom = - distance_get_pixel(widget->border.bottom, ROFI_ORIENTATION_VERTICAL); - int radius_bl = distance_get_pixel(widget->border_radius.left, + distance_get_pixel(wid->border.bottom, ROFI_ORIENTATION_VERTICAL); + int radius_bl = distance_get_pixel(wid->border_radius.left, ROFI_ORIENTATION_HORIZONTAL); - int radius_tr = distance_get_pixel(widget->border_radius.right, + int radius_tr = distance_get_pixel(wid->border_radius.right, ROFI_ORIENTATION_HORIZONTAL); - int radius_tl = distance_get_pixel(widget->border_radius.top, - ROFI_ORIENTATION_VERTICAL); - int radius_br = distance_get_pixel(widget->border_radius.bottom, + int radius_tl = + distance_get_pixel(wid->border_radius.top, ROFI_ORIENTATION_VERTICAL); + int radius_br = distance_get_pixel(wid->border_radius.bottom, ROFI_ORIENTATION_VERTICAL); double vspace = - widget->h - margin_top - margin_bottom - top / 2.0 - bottom / 2.0; + wid->h - margin_top - margin_bottom - top / 2.0 - bottom / 2.0; double hspace = - widget->w - margin_left - margin_right - left / 2.0 - right / 2.0; + wid->w - margin_left - margin_right - left / 2.0 - right / 2.0; if ((radius_bl + radius_tl) > (vspace)) { int j = ((vspace) / 2.0); radius_bl = MIN(radius_bl, j); @@ -198,14 +197,14 @@ void widget_draw(widget *widget, cairo_t *d) { // Background painting. // Set new x/y position. - cairo_translate(d, widget->x, widget->y); + cairo_translate(d, wid->x, wid->y); cairo_set_line_width(d, 0); // Outer outline outlines double x1, y1, x2, y2; x1 = margin_left + left / 2.0, y1 = margin_top + top / 2.0, - x2 = widget->w - margin_right - right / 2.0, - y2 = widget->h - margin_bottom - bottom / 2.0; + x2 = wid->w - margin_right - right / 2.0, + y2 = wid->h - margin_bottom - bottom / 2.0; if (radius_tl > 0) { cairo_move_to(d, x1, y1 + radius_tl); @@ -238,15 +237,15 @@ void widget_draw(widget *widget, cairo_t *d) { cairo_close_path(d); cairo_set_source_rgba(d, 1.0, 1.0, 1.0, 1.0); - rofi_theme_get_color(widget, "background-color", d); + rofi_theme_get_color(wid, "background-color", d); cairo_fill_preserve(d); - if (rofi_theme_get_image(widget, "background-image", d)) { + if (rofi_theme_get_image(wid, "background-image", d)) { cairo_fill_preserve(d); } cairo_clip(d); - widget->draw(widget, d); - widget->need_redraw = FALSE; + wid->draw(wid, d); + wid->need_redraw = FALSE; cairo_restore(d); @@ -255,9 +254,9 @@ void widget_draw(widget *widget, cairo_t *d) { // thus no need for these. cairo_push_group(d); cairo_set_operator(d, CAIRO_OPERATOR_ADD); - cairo_translate(d, widget->x, widget->y); + cairo_translate(d, wid->x, wid->y); cairo_new_path(d); - rofi_theme_get_color(widget, "border-color", d); + rofi_theme_get_color(wid, "border-color", d); // Calculate the different offsets for the corners. double minof_tr = MIN(right / 2.0, top / 2.0); @@ -309,30 +308,30 @@ void widget_draw(widget *widget, cairo_t *d) { if (left > 0) { cairo_set_line_width(d, left); - distance_get_linestyle(widget->border.left, d); + distance_get_linestyle(wid->border.left, d); cairo_move_to(d, x1, margin_top + offset_ttl); - cairo_line_to(d, x1, widget->h - margin_bottom - offset_bbl); + cairo_line_to(d, x1, wid->h - margin_bottom - offset_bbl); cairo_stroke(d); } if (right > 0) { cairo_set_line_width(d, right); - distance_get_linestyle(widget->border.right, d); + distance_get_linestyle(wid->border.right, d); cairo_move_to(d, x2, margin_top + offset_ttr); - cairo_line_to(d, x2, widget->h - margin_bottom - offset_bbr); + cairo_line_to(d, x2, wid->h - margin_bottom - offset_bbr); cairo_stroke(d); } if (top > 0) { cairo_set_line_width(d, top); - distance_get_linestyle(widget->border.top, d); + distance_get_linestyle(wid->border.top, d); cairo_move_to(d, margin_left + offset_ltl, y1); - cairo_line_to(d, widget->w - margin_right - offset_rtr, y1); + cairo_line_to(d, wid->w - margin_right - offset_rtr, y1); cairo_stroke(d); } if (bottom > 0) { cairo_set_line_width(d, bottom); - distance_get_linestyle(widget->border.bottom, d); + distance_get_linestyle(wid->border.bottom, d); cairo_move_to(d, margin_left + offset_lbl, y2); - cairo_line_to(d, widget->w - margin_right - offset_rbr, y2); + cairo_line_to(d, wid->w - margin_right - offset_rbr, y2); cairo_stroke(d); } if (radius_tl > 0) { @@ -353,61 +352,59 @@ void widget_draw(widget *widget, cairo_t *d) { } if (radius_tr > 0) { double radius_outer = radius_tr + minof_tr; - cairo_arc(d, widget->w - margin_right - radius_outer, + cairo_arc(d, wid->w - margin_right - radius_outer, margin_top + radius_outer, radius_outer, -G_PI_2, 0); - cairo_line_to(d, widget->w - margin_right, margin_top + offset_ttr); - cairo_line_to(d, widget->w - margin_right - right, + cairo_line_to(d, wid->w - margin_right, margin_top + offset_ttr); + cairo_line_to(d, wid->w - margin_right - right, margin_top + offset_ttr); if (radius_inner_tr > 0) { - cairo_arc_negative( - d, widget->w - margin_right - right - radius_inner_tr, - margin_top + top + radius_inner_tr, radius_inner_tr, 0, -G_PI_2); - cairo_line_to(d, widget->w - margin_right - offset_rtr, + cairo_arc_negative(d, wid->w - margin_right - right - radius_inner_tr, + margin_top + top + radius_inner_tr, + radius_inner_tr, 0, -G_PI_2); + cairo_line_to(d, wid->w - margin_right - offset_rtr, margin_top + top); } - cairo_line_to(d, widget->w - margin_right - offset_rtr, margin_top); + cairo_line_to(d, wid->w - margin_right - offset_rtr, margin_top); cairo_close_path(d); cairo_fill(d); } if (radius_br > 0) { double radius_outer = radius_br + minof_br; - cairo_arc(d, widget->w - margin_right - radius_outer, - widget->h - margin_bottom - radius_outer, radius_outer, 0.0, + cairo_arc(d, wid->w - margin_right - radius_outer, + wid->h - margin_bottom - radius_outer, radius_outer, 0.0, G_PI_2); - cairo_line_to(d, widget->w - margin_right - offset_rbr, - widget->h - margin_bottom); - cairo_line_to(d, widget->w - margin_right - offset_rbr, - widget->h - margin_bottom - bottom); + cairo_line_to(d, wid->w - margin_right - offset_rbr, + wid->h - margin_bottom); + cairo_line_to(d, wid->w - margin_right - offset_rbr, + wid->h - margin_bottom - bottom); if (radius_inner_br > 0) { - cairo_arc_negative( - d, widget->w - margin_right - right - radius_inner_br, - widget->h - margin_bottom - bottom - radius_inner_br, - radius_inner_br, G_PI_2, 0.0); - cairo_line_to(d, widget->w - margin_right - right, - widget->h - margin_bottom - offset_bbr); + cairo_arc_negative(d, wid->w - margin_right - right - radius_inner_br, + wid->h - margin_bottom - bottom - radius_inner_br, + radius_inner_br, G_PI_2, 0.0); + cairo_line_to(d, wid->w - margin_right - right, + wid->h - margin_bottom - offset_bbr); } - cairo_line_to(d, widget->w - margin_right, - widget->h - margin_bottom - offset_bbr); + cairo_line_to(d, wid->w - margin_right, + wid->h - margin_bottom - offset_bbr); cairo_close_path(d); cairo_fill(d); } if (radius_bl > 0) { double radius_outer = radius_bl + minof_bl; cairo_arc(d, margin_left + radius_outer, - widget->h - margin_bottom - radius_outer, radius_outer, - G_PI_2, G_PI); - cairo_line_to(d, margin_left, widget->h - margin_bottom - offset_bbl); + wid->h - margin_bottom - radius_outer, radius_outer, G_PI_2, + G_PI); + cairo_line_to(d, margin_left, wid->h - margin_bottom - offset_bbl); cairo_line_to(d, margin_left + left, - widget->h - margin_bottom - offset_bbl); + wid->h - margin_bottom - offset_bbl); if (radius_inner_bl > 0) { cairo_arc_negative(d, margin_left + left + radius_inner_bl, - widget->h - margin_bottom - bottom - - radius_inner_bl, + wid->h - margin_bottom - bottom - radius_inner_bl, radius_inner_bl, G_PI, G_PI_2); cairo_line_to(d, margin_left + offset_lbl, - widget->h - margin_bottom - bottom); + wid->h - margin_bottom - bottom); } - cairo_line_to(d, margin_left + offset_lbl, widget->h - margin_bottom); + cairo_line_to(d, margin_left + offset_lbl, wid->h - margin_bottom); cairo_close_path(d); cairo_fill(d); @@ -430,53 +427,53 @@ void widget_free(widget *wid) { } } -int widget_get_height(widget *widget) { - if (widget == NULL) { +int widget_get_height(widget *wid) { + if (wid == NULL) { return 0; } - if (widget->get_height == NULL) { - return widget->h; + if (wid->get_height == NULL) { + return wid->h; } - return widget->get_height(widget); + return wid->get_height(wid); } -int widget_get_width(widget *widget) { - if (widget == NULL) { +int widget_get_width(widget *wid) { + if (wid == NULL) { return 0; } - if (widget->get_width == NULL) { - return widget->w; + if (wid->get_width == NULL) { + return wid->w; } - return widget->get_width(widget); + return wid->get_width(wid); } -int widget_get_x_pos(widget *widget) { - if (widget == NULL) { +int widget_get_x_pos(widget *wid) { + if (wid == NULL) { return 0; } - return widget->x; + return wid->x; } -int widget_get_y_pos(widget *widget) { - if (widget == NULL) { +int widget_get_y_pos(widget *wid) { + if (wid == NULL) { return 0; } - return widget->y; + return wid->y; } -void widget_xy_to_relative(widget *widget, gint *x, gint *y) { - *x -= widget->x; - *y -= widget->y; - if (widget->parent == NULL) { +void widget_xy_to_relative(widget *wid, gint *x, gint *y) { + *x -= wid->x; + *y -= wid->y; + if (wid->parent == NULL) { return; } - widget_xy_to_relative(widget->parent, x, y); + widget_xy_to_relative(wid->parent, x, y); } -void widget_update(widget *widget) { - if (widget == NULL) { +void widget_update(widget *wid) { + if (wid == NULL) { return; } - // When (desired )size of widget changes. - if (widget->update != NULL) { - widget->update(widget); + // When (desired )size of wid changes. + if (wid->update != NULL) { + wid->update(wid); } } diff --git a/source/xcb.c b/source/xcb.c index a1753677d..f2073fc53 100644 --- a/source/xcb.c +++ b/source/xcb.c @@ -31,8 +31,8 @@ #include "config.h" #ifdef XCB_IMDKIT -#include #include +#include #endif #include #include @@ -128,13 +128,13 @@ const struct { } cursor_names[] = { {"default", "left_ptr"}, {"pointer", "hand"}, {"text", "xterm"}}; -static xcb_visualtype_t *lookup_visual(xcb_screen_t *s, xcb_visualid_t visual) { +static xcb_visualtype_t *lookup_visual(xcb_screen_t *s, xcb_visualid_t vis) { xcb_depth_iterator_t d; d = xcb_screen_allowed_depths_iterator(s); for (; d.rem; xcb_depth_next(&d)) { xcb_visualtype_iterator_t v = xcb_depth_visuals_iterator(d.data); for (; v.rem; xcb_visualtype_next(&v)) { - if (v.data->visual_id == visual) { + if (v.data->visual_id == vis) { return v.data; } }