summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@blame.services>2021-07-14 17:29:38 +0200
committerDave Davenport <qball@blame.services>2021-07-14 17:29:38 +0200
commitc4a156fb898372b709d5472d4a0db5cc6737b31f (patch)
tree65244ab12ac1b623adb556b82414055a9dc4b45c
parent87c60e75de112646af313ab826c896bcf14facc8 (diff)
[Icon] Add a squared option.
-rw-r--r--doc/rofi-theme.53
-rw-r--r--doc/rofi-theme.5.markdown1
-rw-r--r--source/widgets/icon.c22
3 files changed, 26 insertions, 0 deletions
diff --git a/doc/rofi-theme.5 b/doc/rofi-theme.5
index dc12e4fb..65a26eea 100644
--- a/doc/rofi-theme.5
+++ b/doc/rofi-theme.5
@@ -1400,6 +1400,9 @@ If the property \fB\fCaction\fR is set, it acts as a button.
\fB\fCaction\fR can be set to a keybinding name and completes that action. (see rofi \-show keys for a list).
.PP
+If the \fB\fCsquared\fR property is set to \fBfalse\fP the widget height and width are not forced to be equal.
+
+.PP
Example:
.PP
diff --git a/doc/rofi-theme.5.markdown b/doc/rofi-theme.5.markdown
index a79ad488..6864b44b 100644
--- a/doc/rofi-theme.5.markdown
+++ b/doc/rofi-theme.5.markdown
@@ -869,6 +869,7 @@ This is an icon widget. The displayed icon can be set with `filename` and size w
If the property `action` is set, it acts as a button.
`action` can be set to a keybinding name and completes that action. (see rofi -show keys for a list).
+If the `squared` property is set to **false** the widget height and width are not forced to be equal.
Example:
diff --git a/source/widgets/icon.c b/source/widgets/icon.c
index 190041b9..3fe60608 100644
--- a/source/widgets/icon.c
+++ b/source/widgets/icon.c
@@ -44,6 +44,8 @@ struct _icon
// Size of the icon.
int size;
+ int squared;
+
uint32_t icon_fetch_id;
double yalign, xalign;
@@ -56,6 +58,15 @@ static int icon_get_desired_height ( widget *widget )
{
icon *b = (icon *) widget;
int height = b->size;
+ if ( b->squared == FALSE ){
+ if( b->icon ) {
+ int iconh = cairo_image_surface_get_height ( b->icon );
+ int iconw = cairo_image_surface_get_width ( b->icon );
+ int icons = MAX ( iconh, iconw );
+ double scale = (double) b->size / icons;
+ height = iconh*scale;
+ }
+ }
height += widget_padding_get_padding_height ( widget );
return height;
}
@@ -63,6 +74,15 @@ static int icon_get_desired_width ( widget *widget )
{
icon *b = (icon *) widget;
int width = b->size;
+ if ( b->squared == FALSE ){
+ if( b->icon ) {
+ int iconh = cairo_image_surface_get_height ( b->icon );
+ int iconw = cairo_image_surface_get_width ( b->icon );
+ int icons = MAX ( iconh, iconw );
+ double scale = (double) b->size / icons;
+ width = iconw*scale;
+ }
+ }
width += widget_padding_get_padding_width ( widget );
return width;
}
@@ -152,6 +172,8 @@ icon * icon_create ( widget *parent, const char *name )
RofiDistance d = rofi_theme_get_distance ( WIDGET ( b ), "size", b->size );
b->size = distance_get_pixel ( d, ROFI_ORIENTATION_VERTICAL );
+ b->squared = rofi_theme_get_boolean ( WIDGET ( b ), "squared", TRUE );
+
const char * filename = rofi_theme_get_string ( WIDGET ( b ), "filename", NULL );
if ( filename ) {
b->icon_fetch_id = rofi_icon_fetcher_query ( filename, b->size );