diff options
| -rw-r--r-- | src/comet.c | 3 | ||||
| -rw-r--r-- | src/connect.c | 8 | ||||
| -rw-r--r-- | src/draw.c | 61 | ||||
| -rw-r--r-- | src/draw.h | 2 | ||||
| -rw-r--r-- | src/window.c | 2 |
5 files changed, 49 insertions, 27 deletions
diff --git a/src/comet.c b/src/comet.c index 7adebaf..24e89ea 100644 --- a/src/comet.c +++ b/src/comet.c @@ -282,6 +282,7 @@ int main(int argc, char **argv) int screen_width = con->screen_size->width; int screen_height = con->screen_size->height; + double scale = window_get_scale(win); int height = EVEN(round(screen_height * 0.021)); int x_padding = EVEN(round(screen_width * 0.005)); @@ -297,7 +298,7 @@ int main(int argc, char **argv) draw_set_separator(draw, 10); draw_set_font(draw, "Hack 13 Bold"); draw_set_context(draw, context); - draw_set_size(draw, height, x_padding, x_padding, y_padding); + draw_set_size(draw, height, x_padding, x_padding, y_padding, scale); State *state = state_create(win, draw); diff --git a/src/connect.c b/src/connect.c index 4b04ac4..79fd2b1 100644 --- a/src/connect.c +++ b/src/connect.c @@ -131,8 +131,12 @@ static bool button_action_find(State *state, GList *layouts, int x, int y) static void button_action(State *state, const char *event, int x, int y) { - log_debug("Checking %s event [x=%d, y=%d]", event, x, y); - if (!button_action_find(state, state->draw->layouts, x, y)) + double scale = window_get_scale(state->win); + int digital_x = x / scale; + int digital_y = y / scale; + + log_debug("Checking %s event [device_x=%d, device_y=%d, x=%d, y=%d]", event, x, y, digital_x, digital_y); + if (!button_action_find(state, state->draw->layouts, digital_x, digital_y)) log_debug("Ignoring %s", event); } @@ -34,20 +34,24 @@ static void paint_button(cairo_t *cr, const Layout *layout) int radius = (layout->height - 2 * layout->y_pad) / 2; int line_radius = radius - layout->line_w / 2; - //// Layout size - //cairo_set_source_rgb(cr, 0, 0, 0); - //cairo_move_to(cr, layout->x, layout->y); - //cairo_line_to(cr, layout->x, layout->y + layout->height); - //cairo_stroke(cr); +#if 0 + // Debug lines - //cairo_move_to(cr, layout->x + layout->width, layout->y); - //cairo_line_to(cr, layout->x + layout->width, layout->y + layout->height); - //cairo_stroke(cr); + // Layout size + cairo_set_source_rgb(cr, 0, 0, 0); + cairo_move_to(cr, layout->x, layout->y); + cairo_line_to(cr, layout->x, layout->y + layout->height); + cairo_stroke(cr); + + cairo_move_to(cr, layout->x + layout->width, layout->y); + cairo_line_to(cr, layout->x + layout->width, layout->y + layout->height); + cairo_stroke(cr); - //// Layout padding - //cairo_set_source_rgb(cr, 0.5, 0.1, 0.1); - //cairo_rectangle(cr, layout->x + layout->x_pad, layout->y + layout->y_pad, layout->width - 2 * layout->x_pad, layout->height - 2 * layout->y_pad); - //cairo_stroke(cr); + // Layout padding + cairo_set_source_rgb(cr, 0.5, 0.1, 0.1); + cairo_rectangle(cr, layout->x + layout->x_pad, layout->y + layout->y_pad, layout->width - 2 * layout->x_pad, layout->height - 2 * layout->y_pad); + cairo_stroke(cr); +#endif cairo_set_line_width(cr, layout->line_w); @@ -79,6 +83,9 @@ static void paint_text(cairo_t *cr, const Layout *layout) cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); cairo_move_to(cr, text_x, text_y); + // Update for scale + pango_cairo_update_layout(cr, layout->pl); + // NOTE: This works only if the text didn't change in size after the layouting pango_layout_set_text(layout->pl, CAST(layout->btn, ButtonSimple)->text, -1); pango_cairo_update_layout(cr, layout->pl); @@ -119,6 +126,11 @@ void draw_paint(Drawer *draw, Window *win) // Back buffering cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, draw->width, draw->height); + // Set scale + double scale = window_get_scale(win); + cairo_surface_set_device_scale(win->surface, scale, scale); + pango_cairo_update_context(win->cr, draw->context); + cairo_t *cr = cairo_create(surface); cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); @@ -131,10 +143,11 @@ void draw_paint(Drawer *draw, Window *win) paint_button_list(cr, draw->layouts); cairo_destroy(cr); - window_move(win, draw->left_pad, draw->top_pad); - window_resize(win, draw->width, draw->height); + // Use device pixels + window_move(win, draw->left_pad * scale, draw->top_pad * scale); + window_resize(win, draw->width * scale, draw->height * scale); - window_paint_surface(win, surface, draw->width, draw->height); + window_paint_surface(win, surface, draw->width * scale, draw->height * scale); cairo_surface_destroy(surface); } @@ -181,8 +194,9 @@ static void layout_set_text(Layout *layout, PangoFontDescription *desc, int heig static void compute_width(Drawer *draw, Window *win) { int screen_width = win->con->screen_size->width; - draw->width = screen_width - draw->right_pad - draw->left_pad; - log_debug("Draw context width calculated [width=%d]", draw->width); + double scale = window_get_scale(win); + draw->width = screen_width / scale - draw->right_pad - draw->left_pad; + log_debug("Draw context width calculated [scale=%lf, width=%d]", scale, draw->width); } static void layout_check_width(Layout *layout) @@ -356,17 +370,20 @@ void draw_set_context(Drawer *draw, PangoContext *context) log_debug("Pango context updated [context=%p]", context); } -void draw_set_size(Drawer *draw, int height, int left_pad, int right_pad, int top_pad) +void draw_set_size(Drawer *draw, int height, int left_pad, int right_pad, int top_pad, double scale) { g_assert(height > 0); - draw->height = height; - draw->left_pad = left_pad; - draw->right_pad = right_pad; - draw->top_pad = top_pad; + draw->height = height / scale; + draw->left_pad = left_pad / scale; + draw->right_pad = right_pad / scale; + draw->top_pad = top_pad / scale; log_debug("Draw context size updated [height=%d, left_pad=%d, right_pad=%d, top_pad=%d]", height, left_pad, right_pad, top_pad); + + log_debug("Draw context size scaled [scale=%lf, height=%d, left_pad=%d, right_pad=%d, top_pad=%d]", + scale, draw->height, draw->left_pad, draw->right_pad, draw->top_pad); } void draw_destroy(Drawer *draw) @@ -60,7 +60,7 @@ void draw_set_font(Drawer *draw, const char *font); void draw_set_context(Drawer *draw, PangoContext *context); -void draw_set_size(Drawer *draw, int height, int left_pad, int right_pad, int top_pad); +void draw_set_size(Drawer *draw, int height, int left_pad, int right_pad, int top_pad, double scale); void draw_destroy(Drawer *draw); diff --git a/src/window.c b/src/window.c index cc9c9fc..b35eb07 100644 --- a/src/window.c +++ b/src/window.c @@ -181,7 +181,7 @@ cairo_t *window_get_context(Window *win) double window_get_scale(Window *win) { - return MAX(1, win->con->screen_dpi/96.); + return MAX(1, win->con->screen_dpi / 96.0); } void window_get_screen_size(Window *win, int *width, int *height) |
