Snap terminal size to an integer number of character cells.
This commit is contained in:
@@ -269,7 +269,7 @@ resize_window(struct gears *gears)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
resize_handler(struct window *window, int32_t width, int32_t height, void *data)
|
resize_handler(struct window *window, struct rectangle *rectangle, void *data)
|
||||||
{
|
{
|
||||||
struct gears *gears = data;
|
struct gears *gears = data;
|
||||||
|
|
||||||
|
|||||||
+25
-2
@@ -63,6 +63,7 @@ struct terminal {
|
|||||||
char escape[64];
|
char escape[64];
|
||||||
int escape_length;
|
int escape_length;
|
||||||
int state;
|
int state;
|
||||||
|
int margin;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -93,7 +94,8 @@ terminal_draw_contents(struct terminal *terminal)
|
|||||||
cairo_font_extents(cr, &extents);
|
cairo_font_extents(cr, &extents);
|
||||||
for (i = 0; i < terminal->total_rows; i++) {
|
for (i = 0; i < terminal->total_rows; i++) {
|
||||||
row = (terminal->tail + i) % terminal->height;
|
row = (terminal->tail + i) % terminal->height;
|
||||||
cairo_move_to(cr, 0, extents.ascent + extents.height * i);
|
cairo_move_to(cr, terminal->margin,
|
||||||
|
terminal->margin + extents.ascent + extents.height * i);
|
||||||
cairo_show_text(cr, &terminal->data[row * (terminal->width + 1)]);
|
cairo_show_text(cr, &terminal->data[row * (terminal->width + 1)]);
|
||||||
}
|
}
|
||||||
cairo_destroy(cr);
|
cairo_destroy(cr);
|
||||||
@@ -232,9 +234,29 @@ terminal_data(struct terminal *terminal, const char *data, size_t length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
resize_handler(struct window *window, int32_t width, int32_t height, void *data)
|
resize_handler(struct window *window, struct rectangle *rectangle, void *data)
|
||||||
{
|
{
|
||||||
struct terminal *terminal = data;
|
struct terminal *terminal = data;
|
||||||
|
cairo_surface_t *surface;
|
||||||
|
cairo_font_extents_t extents;
|
||||||
|
cairo_t *cr;
|
||||||
|
|
||||||
|
/* Adjust the size to an integer number of character cells.
|
||||||
|
* Maybe this is better done in the redraw path, as we're
|
||||||
|
* creating the cr and setting the font there anyway. */
|
||||||
|
|
||||||
|
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0);
|
||||||
|
cr = cairo_create(surface);
|
||||||
|
cairo_select_font_face (cr, "mono",
|
||||||
|
CAIRO_FONT_SLANT_NORMAL,
|
||||||
|
CAIRO_FONT_WEIGHT_NORMAL);
|
||||||
|
cairo_set_font_size(cr, 14);
|
||||||
|
cairo_font_extents(cr, &extents);
|
||||||
|
cairo_destroy(cr);
|
||||||
|
cairo_surface_destroy(surface);
|
||||||
|
|
||||||
|
rectangle->width -= (rectangle->width - 2 * terminal->margin) % (int32_t) extents.max_x_advance;
|
||||||
|
rectangle->height -= (rectangle->height - 2 * terminal->margin) % (int32_t) extents.height;
|
||||||
|
|
||||||
terminal_schedule_redraw(terminal);
|
terminal_schedule_redraw(terminal);
|
||||||
}
|
}
|
||||||
@@ -383,6 +405,7 @@ terminal_create(struct wl_display *display, int fd)
|
|||||||
terminal->width = 80;
|
terminal->width = 80;
|
||||||
terminal->height = 25;
|
terminal->height = 25;
|
||||||
terminal->total_rows = 1;
|
terminal->total_rows = 1;
|
||||||
|
terminal->margin = 5;
|
||||||
size = (terminal->width + 1) * terminal->height;
|
size = (terminal->width + 1) * terminal->height;
|
||||||
terminal->data = malloc(size);
|
terminal->data = malloc(size);
|
||||||
memset(terminal->data, 0, size);
|
memset(terminal->data, 0, size);
|
||||||
|
|||||||
@@ -190,6 +190,7 @@ event_handler(struct wl_display *display,
|
|||||||
uint32_t size, uint32_t *p, void *data)
|
uint32_t size, uint32_t *p, void *data)
|
||||||
{
|
{
|
||||||
struct window *window = data;
|
struct window *window = data;
|
||||||
|
struct rectangle rectangle;
|
||||||
int location;
|
int location;
|
||||||
int grip_size = 16;
|
int grip_size = 16;
|
||||||
|
|
||||||
@@ -251,11 +252,15 @@ event_handler(struct wl_display *display,
|
|||||||
if (window->height < window->minimum_height)
|
if (window->height < window->minimum_height)
|
||||||
window->height = window->minimum_height;
|
window->height = window->minimum_height;
|
||||||
|
|
||||||
|
window_get_child_rectangle(window, &rectangle);
|
||||||
if (window->resize_handler)
|
if (window->resize_handler)
|
||||||
(*window->resize_handler)(window,
|
(*window->resize_handler)(window,
|
||||||
window->width,
|
&rectangle,
|
||||||
window->height,
|
|
||||||
window->user_data);
|
window->user_data);
|
||||||
|
|
||||||
|
window->width = rectangle.width + 20;
|
||||||
|
window->height = rectangle.height + 60;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (opcode == 1) {
|
} else if (opcode == 1) {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ struct rectangle {
|
|||||||
int32_t height;
|
int32_t height;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*window_resize_handler_t)(struct window *window, int32_t width, int32_t height, void *data);
|
typedef void (*window_resize_handler_t)(struct window *window, struct rectangle *rectangle, void *data);
|
||||||
typedef void (*window_frame_handler_t)(struct window *window, uint32_t frame, uint32_t timestamp, void *data);
|
typedef void (*window_frame_handler_t)(struct window *window, uint32_t frame, uint32_t timestamp, void *data);
|
||||||
typedef void (*window_acknowledge_handler_t)(struct window *window, uint32_t key, void *data);
|
typedef void (*window_acknowledge_handler_t)(struct window *window, uint32_t key, void *data);
|
||||||
typedef void (*window_key_handler_t)(struct window *window, uint32_t key, uint32_t state, void *data);
|
typedef void (*window_key_handler_t)(struct window *window, uint32_t key, uint32_t state, void *data);
|
||||||
|
|||||||
Reference in New Issue
Block a user