1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-13 19:22:58 +00:00

Use xft_dpi_scale function instead of DPI_SCALE macro

This commit is contained in:
Livanh 2021-04-10 14:58:37 +02:00 committed by Brenden Matthews
parent 1c6c4bcf6a
commit 3be1320e6c
4 changed files with 49 additions and 58 deletions

View File

@ -498,17 +498,17 @@ int calc_text_width(const char *s) {
#endif /* BUILD_X11 */
}
#ifdef BUILD_X11
#ifdef BUILD_XFT
int xft_dpi_scale(int value) {
#if defined(BUILD_X11) && defined(BUILD_XFT)
if (use_xft.get(*state)) {
return (value * xft_dpi + (value>0?48:-48)) / 96;
} else {
return value;
}
#else /* defined(BUILD_X11) && defined(BUILD_XFT) */
return value;
#endif /* defined(BUILD_X11) && defined(BUILD_XFT) */
}
#endif /* BUILD_XFT */
#endif /* BUILD_X11 */
/* formatted text to render on screen, generated in generate_text(),
@ -851,8 +851,8 @@ int get_string_width(const char *s) { return *s != 0 ? calc_text_width(s) : 0; }
#ifdef BUILD_X11
static inline int get_border_total() {
return DPI_SCALE(border_inner_margin.get(*state)) + DPI_SCALE(border_outer_margin.get(*state)) +
DPI_SCALE(border_width.get(*state));
return xft_dpi_scale(border_inner_margin.get(*state)) + xft_dpi_scale(border_outer_margin.get(*state)) +
xft_dpi_scale(border_width.get(*state));
}
static int get_string_width_special(char *s, int special_index) {
@ -944,15 +944,15 @@ static void update_text_area() {
if (fixed_size == 0)
#endif
{
text_width = DPI_SCALE(minimum_width.get(*state));
text_width = xft_dpi_scale(minimum_width.get(*state));
text_height = 0;
last_font_height = font_height();
for_each_line(text_buffer, text_size_updater);
text_width += 1;
if (text_height < DPI_SCALE(minimum_height.get(*state))) {
text_height = DPI_SCALE(minimum_height.get(*state));
if (text_height < xft_dpi_scale(minimum_height.get(*state))) {
text_height = xft_dpi_scale(minimum_height.get(*state));
}
int mw = DPI_SCALE(maximum_width.get(*state));
int mw = xft_dpi_scale(maximum_width.get(*state));
if (text_width > mw && mw > 0) { text_width = mw; }
}
@ -962,21 +962,21 @@ static void update_text_area() {
case TOP_LEFT:
case TOP_RIGHT:
case TOP_MIDDLE:
y = workarea[1] + DPI_SCALE(gap_y.get(*state));
y = workarea[1] + xft_dpi_scale(gap_y.get(*state));
break;
case BOTTOM_LEFT:
case BOTTOM_RIGHT:
case BOTTOM_MIDDLE:
default:
y = workarea[3] - text_height - DPI_SCALE(gap_y.get(*state));
y = workarea[3] - text_height - xft_dpi_scale(gap_y.get(*state));
break;
case MIDDLE_LEFT:
case MIDDLE_RIGHT:
case MIDDLE_MIDDLE:
y = workarea[1] + (workarea[3] - workarea[1]) / 2 - text_height / 2 -
DPI_SCALE(gap_y.get(*state));
xft_dpi_scale(gap_y.get(*state));
break;
}
switch (align) {
@ -984,20 +984,20 @@ static void update_text_area() {
case BOTTOM_LEFT:
case MIDDLE_LEFT:
default:
x = workarea[0] + DPI_SCALE(gap_x.get(*state));
x = workarea[0] + xft_dpi_scale(gap_x.get(*state));
break;
case TOP_RIGHT:
case BOTTOM_RIGHT:
case MIDDLE_RIGHT:
x = workarea[2] - text_width - DPI_SCALE(gap_x.get(*state));
x = workarea[2] - text_width - xft_dpi_scale(gap_x.get(*state));
break;
case TOP_MIDDLE:
case BOTTOM_MIDDLE:
case MIDDLE_MIDDLE:
x = workarea[0] + (workarea[2] - workarea[0]) / 2 - text_width / 2 -
DPI_SCALE(gap_x.get(*state));
xft_dpi_scale(gap_x.get(*state));
break;
}
#ifdef OWN_WINDOW
@ -1094,7 +1094,7 @@ static int text_size_updater(char *s, int special_index) {
w += get_string_width(s);
if (w > text_width) { text_width = w; }
int mw = DPI_SCALE(maximum_width.get(*state));
int mw = xft_dpi_scale(maximum_width.get(*state));
if (text_width > mw && mw > 0) { text_width = mw; }
text_height += last_font_height;
@ -1212,7 +1212,7 @@ static void draw_string(const char *s) {
}
#ifdef BUILD_X11
if (out_to_x.get(*state)) {
int mw = DPI_SCALE(maximum_width.get(*state));
int mw = xft_dpi_scale(maximum_width.get(*state));
if (text_width == mw) {
/* this means the text is probably pushing the limit,
* so we'll chop it */
@ -1307,7 +1307,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
#ifdef BUILD_X11
int font_h = 0;
int cur_y_add = 0;
int mw = DPI_SCALE(maximum_width.get(*state));
int mw = xft_dpi_scale(maximum_width.get(*state));
#endif /* BUILD_X11 */
char *p = s;
int orig_special_index = special_index;
@ -1390,7 +1390,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
if (w == 0) { w = text_start_x + text_width - cur_x - 1; }
if (w < 0) { w = 0; }
XSetLineAttributes(display, window.gc, DPI_SCALE(1), LineSolid, CapButt,
XSetLineAttributes(display, window.gc, xft_dpi_scale(1), LineSolid, CapButt,
JoinMiter);
XDrawRectangle(display, window.drawable, window.gc,
@ -1469,7 +1469,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
}
if (w < 0) { w = 0; }
if (draw_graph_borders.get(*state)) {
XSetLineAttributes(display, window.gc, DPI_SCALE(1), LineSolid, CapButt,
XSetLineAttributes(display, window.gc, xft_dpi_scale(1), LineSolid, CapButt,
JoinMiter);
XDrawRectangle(display, window.drawable, window.gc,
text_offset_x + cur_x, text_offset_y + by, w, h);
@ -1761,13 +1761,13 @@ static void draw_text() {
#ifdef BUILD_X11
if (out_to_x.get(*state)) {
cur_y = text_start_y;
int bw = DPI_SCALE(border_width.get(*state));
int bw = xft_dpi_scale(border_width.get(*state));
/* draw borders */
if (draw_borders.get(*state) && bw > 0) {
if (stippled_borders.get(*state) != 0) {
char ss[2] = {(char)DPI_SCALE(stippled_borders.get(*state)),
(char)DPI_SCALE(stippled_borders.get(*state))};
char ss[2] = {(char)xft_dpi_scale(stippled_borders.get(*state)),
(char)xft_dpi_scale(stippled_borders.get(*state))};
XSetLineAttributes(display, window.gc, bw, LineOnOffDash, CapButt,
JoinMiter);
XSetDashes(display, window.gc, 0, ss, 2);
@ -1776,7 +1776,7 @@ static void draw_text() {
JoinMiter);
}
int offset = DPI_SCALE(border_inner_margin.get(*state)) + bw;
int offset = xft_dpi_scale(border_inner_margin.get(*state)) + bw;
XDrawRectangle(display, window.drawable, window.gc,
text_offset_x + text_start_x - offset,
text_offset_y + text_start_y - offset,
@ -2185,7 +2185,7 @@ void main_loop() {
text_width = window.width - 2 * border_total;
text_height = window.height - 2 * border_total;
int mw = DPI_SCALE(maximum_width.get(*state));
int mw = xft_dpi_scale(maximum_width.get(*state));
if (text_width > mw && mw > 0) { text_width = mw; }
}
@ -2822,7 +2822,7 @@ void initialisation(int argc, char **argv) {
break;
case 'u':
state->pushinteger(DPI_SCALE(strtol(optarg, &conv_end, 10)));
state->pushinteger(xft_dpi_scale(strtol(optarg, &conv_end, 10)));
if (*conv_end != 0) {
CRIT_ERR(nullptr, nullptr, "'%s' is a wrong update-interval", optarg);
}

View File

@ -301,17 +301,8 @@ void set_updatereset(int);
int get_updatereset(void);
int get_total_updates(void);
#ifdef BUILD_X11
#ifdef BUILD_XFT
static int xft_dpi;
int xft_dpi_scale(int value);
#define DPI_SCALE(a) xft_dpi_scale(a)
#else
#define DPI_SCALE(a) a
#endif /* BUILD_XFT */
#else
#define DPI_SCALE(a) a
#endif /* BUILD_X11 */
int get_saved_coordinates_x(int);
int get_saved_coordinates_y(int);

View File

@ -134,8 +134,8 @@ void cimlib_add_image(const char *args) {
tmp += 3;
sscanf(tmp, "%i,%i", &cur->x, &cur->y);
#ifdef BUILD_XFT
cur->x = DPI_SCALE(cur->x);
cur->y = DPI_SCALE(cur->y);
cur->x = xft_dpi_scale(cur->x);
cur->y = xft_dpi_scale(cur->y);
#endif /* BUILD_XFT */
}
tmp = strstr(args, "-s ");
@ -143,8 +143,8 @@ void cimlib_add_image(const char *args) {
tmp += 3;
if (sscanf(tmp, "%ix%i", &cur->w, &cur->h) != 0) { cur->wh_set = 1; }
#ifdef BUILD_XFT
cur->w = DPI_SCALE(cur->w);
cur->h = DPI_SCALE(cur->h);
cur->w = xft_dpi_scale(cur->w);
cur->h = xft_dpi_scale(cur->h);
#endif /* BUILD_XFT */
}
@ -208,8 +208,8 @@ static void cimlib_draw_image(struct image_list_s *cur, int *clip_x,
w = imlib_image_get_width();
h = imlib_image_get_height();
if (cur->wh_set == 0) {
cur->w = DPI_SCALE(w);
cur->h = DPI_SCALE(h);
cur->w = xft_dpi_scale(w);
cur->h = xft_dpi_scale(h);
}
imlib_context_set_image(buffer);
imlib_blend_image_onto_image(image, 1, 0, 0, w, h, cur->x, cur->y, cur->w,

View File

@ -396,8 +396,8 @@ void new_gauge_in_x11(struct text_object *obj, char *buf, double usage) {
s = new_special(buf, GAUGE);
s->arg = usage;
s->width = DPI_SCALE(g->width);
s->height = DPI_SCALE(g->height);
s->width = xft_dpi_scale(g->width);
s->height = xft_dpi_scale(g->height);
s->scale = g->scale;
}
#endif /* BUILD_X11 */
@ -551,7 +551,7 @@ void new_graph(struct text_object *obj, char *buf, int buf_max_size,
s = new_special(buf, GRAPH);
/* set graph (special) width to width in obj */
s->width = DPI_SCALE(g->width);
s->width = xft_dpi_scale(g->width);
if (s->width != 0) { s->graph_width = s->width; }
if (s->graph_width != s->graph_allocated) {
@ -576,7 +576,7 @@ void new_graph(struct text_object *obj, char *buf, int buf_max_size,
s->graph_allocated = s->graph_width;
graphs[g->id] = graph;
}
s->height = DPI_SCALE(g->height);
s->height = xft_dpi_scale(g->height);
s->first_colour = adjust_colours(g->first_colour);
s->last_colour = adjust_colours(g->last_colour);
if (g->scale != 0) {
@ -611,7 +611,7 @@ void new_hr(struct text_object *obj, char *p, unsigned int p_max_size) {
if (p_max_size == 0) { return; }
new_special(p, HORIZONTAL_LINE)->height = DPI_SCALE(obj->data.l);
new_special(p, HORIZONTAL_LINE)->height = xft_dpi_scale(obj->data.l);
}
void scan_stippled_hr(struct text_object *obj, const char *arg) {
@ -643,8 +643,8 @@ void new_stippled_hr(struct text_object *obj, char *p,
s = new_special(p, STIPPLED_HR);
s->height = DPI_SCALE(sh->height);
s->arg = DPI_SCALE(sh->arg);
s->height = xft_dpi_scale(sh->height);
s->arg = xft_dpi_scale(sh->arg);
}
#endif /* BUILD_X11 */
@ -705,8 +705,8 @@ static void new_bar_in_x11(struct text_object *obj, char *buf, double usage) {
s = new_special(buf, BAR);
s->arg = usage;
s->width = DPI_SCALE(b->width);
s->height = DPI_SCALE(b->height);
s->width = xft_dpi_scale(b->width);
s->height = xft_dpi_scale(b->height);
s->scale = b->scale;
}
#endif /* BUILD_X11 */
@ -741,12 +741,12 @@ void new_outline(struct text_object *obj, char *p, unsigned int p_max_size) {
void new_offset(struct text_object *obj, char *p, unsigned int p_max_size) {
if (p_max_size == 0) { return; }
new_special(p, OFFSET)->arg = DPI_SCALE(obj->data.l);
new_special(p, OFFSET)->arg = xft_dpi_scale(obj->data.l);
}
void new_voffset(struct text_object *obj, char *p, unsigned int p_max_size) {
if (p_max_size == 0) { return; }
new_special(p, VOFFSET)->arg = DPI_SCALE(obj->data.l);
new_special(p, VOFFSET)->arg = xft_dpi_scale(obj->data.l);
}
void new_save_coordinates(struct text_object *obj, char *p,
@ -757,18 +757,18 @@ void new_save_coordinates(struct text_object *obj, char *p,
void new_alignr(struct text_object *obj, char *p, unsigned int p_max_size) {
if (p_max_size == 0) { return; }
new_special(p, ALIGNR)->arg = DPI_SCALE(obj->data.l);
new_special(p, ALIGNR)->arg = xft_dpi_scale(obj->data.l);
}
// A positive offset pushes the text further left
void new_alignc(struct text_object *obj, char *p, unsigned int p_max_size) {
if (p_max_size == 0) { return; }
new_special(p, ALIGNC)->arg = DPI_SCALE(obj->data.l);
new_special(p, ALIGNC)->arg = xft_dpi_scale(obj->data.l);
}
void new_goto(struct text_object *obj, char *p, unsigned int p_max_size) {
if (p_max_size == 0) { return; }
new_special(p, GOTO)->arg = DPI_SCALE(obj->data.l);
new_special(p, GOTO)->arg = xft_dpi_scale(obj->data.l);
}
void scan_tab(struct text_object *obj, const char *arg) {
@ -796,8 +796,8 @@ void new_tab(struct text_object *obj, char *p, unsigned int p_max_size) {
if ((t == nullptr) || (p_max_size == 0)) { return; }
s = new_special(p, TAB);
s->width = DPI_SCALE(t->width);
s->arg = DPI_SCALE(t->arg);
s->width = xft_dpi_scale(t->width);
s->arg = xft_dpi_scale(t->arg);
}
void clear_stored_graphs() {