1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

Add -Wshadow to build system. (#2042)

* Add -Wshadow to build system.

Issue: #2036

* Take out unintended change

* [Icon] Add more descriptive variable name.
This commit is contained in:
Dave Davenport 2024-10-20 12:54:13 +02:00 committed by GitHub
parent df7d8b65f0
commit 9d785b5ce1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 528 additions and 548 deletions

View file

@ -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

View file

@ -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
*

View file

@ -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 );

View file

@ -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)

View file

@ -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);
}

View file

@ -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);

File diff suppressed because it is too large Load diff

View file

@ -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",
box *new_box = box_create(WIDGET(state->main_window), "error-message",
ROFI_ORIENTATION_VERTICAL);
box_add(state->main_window, WIDGET(box), TRUE);
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) {

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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) {

View file

@ -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,
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, widget->w - margin_right - right,
widget->h - margin_bottom - offset_bbr);
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);
}
}

View file

@ -31,8 +31,8 @@
#include "config.h"
#ifdef XCB_IMDKIT
#include <xcb/xcb_keysyms.h>
#include <xcb-imdkit/encoding.h>
#include <xcb/xcb_keysyms.h>
#endif
#include <cairo-xcb.h>
#include <cairo.h>
@ -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;
}
}