Rename margin to padding
This commit is contained in:
parent
d453400ee6
commit
2610fb1cf2
1 changed files with 12 additions and 11 deletions
23
wl-overlay.c
23
wl-overlay.c
|
@ -17,7 +17,7 @@
|
||||||
#define STR_EQUAL 0
|
#define STR_EQUAL 0
|
||||||
|
|
||||||
#define DEFAULT_BORDER_RADIUS 15
|
#define DEFAULT_BORDER_RADIUS 15
|
||||||
#define DEFAULT_MARGIN 10
|
#define DEFAULT_PADDING 10
|
||||||
#define DEFAULT_WIDTH 256
|
#define DEFAULT_WIDTH 256
|
||||||
#define DEFAULT_HEIGHT 256
|
#define DEFAULT_HEIGHT 256
|
||||||
#define DEFAULT_FONT "Fira Sans 17"
|
#define DEFAULT_FONT "Fira Sans 17"
|
||||||
|
@ -111,7 +111,7 @@ struct user_request {
|
||||||
int border_radius;
|
int border_radius;
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
int margin;
|
int padding;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct client_state {
|
struct client_state {
|
||||||
|
@ -196,8 +196,8 @@ draw_frame(struct client_state *state, const int width, const int height)
|
||||||
/* Set transformations to fit image in box */
|
/* Set transformations to fit image in box */
|
||||||
int img_width = cairo_image_surface_get_width(cairo_png_surface);
|
int img_width = cairo_image_surface_get_width(cairo_png_surface);
|
||||||
int img_height = cairo_image_surface_get_height(cairo_png_surface);
|
int img_height = cairo_image_surface_get_height(cairo_png_surface);
|
||||||
double width_scale = ((double)width - 2*state->user_request.margin) / img_width;
|
double width_scale = ((double)width - 2*state->user_request.padding) / img_width;
|
||||||
double height_scale = (((double)height - 2*state->user_request.margin) * 3 / 4.0) / img_height;
|
double height_scale = (((double)height - 2*state->user_request.padding) * 3 / 4.0) / img_height;
|
||||||
double scale = MIN(width_scale, height_scale);
|
double scale = MIN(width_scale, height_scale);
|
||||||
if (scale > 1.0) scale = 1.0;
|
if (scale > 1.0) scale = 1.0;
|
||||||
cairo_translate(cairo,
|
cairo_translate(cairo,
|
||||||
|
@ -216,7 +216,7 @@ draw_frame(struct client_state *state, const int width, const int height)
|
||||||
PangoLayout *layout = pango_cairo_create_layout(cairo);
|
PangoLayout *layout = pango_cairo_create_layout(cairo);
|
||||||
pango_layout_set_text(layout, state->user_request.text, -1);
|
pango_layout_set_text(layout, state->user_request.text, -1);
|
||||||
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
|
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
|
||||||
pango_layout_set_width(layout, (width - 2*state->user_request.margin) * PANGO_SCALE);
|
pango_layout_set_width(layout, (width - 2*state->user_request.padding) * PANGO_SCALE);
|
||||||
PangoFontDescription *desc = pango_font_description_from_string(
|
PangoFontDescription *desc = pango_font_description_from_string(
|
||||||
state->user_request.font != NULL ? state->user_request.font : DEFAULT_FONT);
|
state->user_request.font != NULL ? state->user_request.font : DEFAULT_FONT);
|
||||||
pango_layout_set_font_description(layout, desc);
|
pango_layout_set_font_description(layout, desc);
|
||||||
|
@ -224,7 +224,7 @@ draw_frame(struct client_state *state, const int width, const int height)
|
||||||
set_source_argb_cairo(cairo, &state->user_request.text_color);
|
set_source_argb_cairo(cairo, &state->user_request.text_color);
|
||||||
int text_width = 0, text_height = 0;
|
int text_width = 0, text_height = 0;
|
||||||
pango_layout_get_size(layout, &text_width, &text_height);
|
pango_layout_get_size(layout, &text_width, &text_height);
|
||||||
cairo_move_to(cairo, state->user_request.margin, 3*height/4.0);
|
cairo_move_to(cairo, state->user_request.padding, 3*height/4.0);
|
||||||
pango_cairo_show_layout(cairo, layout);
|
pango_cairo_show_layout(cairo, layout);
|
||||||
g_object_unref(layout);
|
g_object_unref(layout);
|
||||||
}
|
}
|
||||||
|
@ -286,6 +286,7 @@ static const struct wl_registry_listener wl_registry_listener = {
|
||||||
.global_remove = registry_global_remove,
|
.global_remove = registry_global_remove,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parse_hex(char *hex, struct color_argb *result_color) {
|
parse_hex(char *hex, struct color_argb *result_color) {
|
||||||
if (strlen(hex) != 4 * 2) {
|
if (strlen(hex) != 4 * 2) {
|
||||||
|
@ -315,10 +316,10 @@ print_usage()
|
||||||
" --font=<str> Set font of text (default ‘" DEFAULT_FONT "’)\n"
|
" --font=<str> Set font of text (default ‘" DEFAULT_FONT "’)\n"
|
||||||
" --width=<int> \n"
|
" --width=<int> \n"
|
||||||
" --height=<int> Set width and height (default %d×%d)\n"
|
" --height=<int> Set width and height (default %d×%d)\n"
|
||||||
" --height=<int> Set margin around image and text (default %d)\n",
|
" --padding=<int> Set padding around image and text (default %d)\n",
|
||||||
DEFAULT_BORDER_RADIUS,
|
DEFAULT_BORDER_RADIUS,
|
||||||
DEFAULT_WIDTH, DEFAULT_HEIGHT,
|
DEFAULT_WIDTH, DEFAULT_HEIGHT,
|
||||||
DEFAULT_MARGIN);
|
DEFAULT_PADDING);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -330,7 +331,7 @@ main(int argc, char *argv[])
|
||||||
state.user_request.backdrop = DEFAULT_BACKDROP_COLOR;
|
state.user_request.backdrop = DEFAULT_BACKDROP_COLOR;
|
||||||
state.user_request.width = DEFAULT_WIDTH;
|
state.user_request.width = DEFAULT_WIDTH;
|
||||||
state.user_request.height = DEFAULT_HEIGHT;
|
state.user_request.height = DEFAULT_HEIGHT;
|
||||||
state.user_request.margin = DEFAULT_MARGIN;
|
state.user_request.padding = DEFAULT_PADDING;
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
|
@ -345,7 +346,7 @@ main(int argc, char *argv[])
|
||||||
{"font", required_argument, 0, 0 },
|
{"font", required_argument, 0, 0 },
|
||||||
{"width", required_argument, 0, 0 },
|
{"width", required_argument, 0, 0 },
|
||||||
{"height", required_argument, 0, 0 },
|
{"height", required_argument, 0, 0 },
|
||||||
{"margin", required_argument, 0, 0 },
|
{"padding", required_argument, 0, 0 },
|
||||||
{0, 0, 0, 0 }
|
{0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -362,7 +363,7 @@ main(int argc, char *argv[])
|
||||||
case 5: state.user_request.font = strdup(optarg); break;
|
case 5: state.user_request.font = strdup(optarg); break;
|
||||||
case 6: state.user_request.width = atoi(optarg); break;
|
case 6: state.user_request.width = atoi(optarg); break;
|
||||||
case 7: state.user_request.height = atoi(optarg); break;
|
case 7: state.user_request.height = atoi(optarg); break;
|
||||||
case 8: state.user_request.margin = atoi(optarg); break;
|
case 8: state.user_request.padding = atoi(optarg); break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue