mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-07 04:06:07 -05:00
output: track output we're mapped on, and use maximum scale
Our surface may be on multiple outputs at the same time. In this case, we use the largest scale factor, and let the compositor down scale on the "other" output(s).
This commit is contained in:
parent
4b06360681
commit
c2451e2a80
4 changed files with 67 additions and 8 deletions
57
main.c
57
main.c
|
|
@ -128,7 +128,7 @@ output_scale(void *data, struct wl_output *wl_output, int32_t factor)
|
|||
{
|
||||
struct monitor *mon = data;
|
||||
mon->scale = factor;
|
||||
render_resize(mon->term, mon->term->width, mon->term->height, factor);
|
||||
render_resize(mon->term, mon->term->width, mon->term->height);
|
||||
}
|
||||
|
||||
static const struct wl_output_listener output_listener = {
|
||||
|
|
@ -248,17 +248,61 @@ handle_global(void *data, struct wl_registry *registry,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
surface_enter(void *data, struct wl_surface *wl_surface,
|
||||
struct wl_output *wl_output)
|
||||
{
|
||||
struct terminal *term = data;
|
||||
tll_foreach(term->wl.monitors, it) {
|
||||
if (it->item.output == wl_output) {
|
||||
LOG_DBG("mapped on %s", it->item.name);
|
||||
tll_push_back(term->wl.on_outputs, &it->item);
|
||||
|
||||
/* Resize, since scale-to-use may have changed */
|
||||
render_resize(term, term->width, term->height);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LOG_ERR("mapped on unknown output");
|
||||
}
|
||||
|
||||
static void
|
||||
surface_leave(void *data, struct wl_surface *wl_surface,
|
||||
struct wl_output *wl_output)
|
||||
{
|
||||
struct terminal *term = data;
|
||||
tll_foreach(term->wl.on_outputs, it) {
|
||||
if (it->item->output != wl_output)
|
||||
continue;
|
||||
|
||||
LOG_DBG("unmapped from %s", it->item->name);
|
||||
tll_remove(term->wl.on_outputs, it);
|
||||
|
||||
/* Resize, since scale-to-use may have changed */
|
||||
render_resize(term, term->width, term->height);
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_ERR("unmapped from unknown output");
|
||||
}
|
||||
|
||||
static const struct wl_surface_listener surface_listener = {
|
||||
.enter = &surface_enter,
|
||||
.leave = &surface_leave,
|
||||
};
|
||||
|
||||
static void
|
||||
xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel,
|
||||
int32_t width, int32_t height, struct wl_array *states)
|
||||
{
|
||||
//struct context *c = data;
|
||||
//LOG_DBG("xdg-toplevel: configure: %dx%d", width, height);
|
||||
LOG_DBG("xdg-toplevel: configure: %dx%d", width, height);
|
||||
|
||||
if (width <= 0 || height <= 0)
|
||||
return;
|
||||
|
||||
struct terminal *term = data;
|
||||
render_resize(term, width, height, term->scale);
|
||||
render_resize(term, width, height);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -662,6 +706,8 @@ main(int argc, char *const *argv)
|
|||
goto out;
|
||||
}
|
||||
|
||||
wl_surface_add_listener(term.wl.surface, &surface_listener, &term);
|
||||
|
||||
term.wl.xdg_surface = xdg_wm_base_get_xdg_surface(term.wl.shell, term.wl.surface);
|
||||
xdg_surface_add_listener(term.wl.xdg_surface, &xdg_surface_listener, &term);
|
||||
|
||||
|
|
@ -677,7 +723,7 @@ main(int argc, char *const *argv)
|
|||
/* TODO: use font metrics to calculate initial size from ROWS x COLS */
|
||||
const int default_width = 300;
|
||||
const int default_height = 300;
|
||||
render_resize(&term, default_width, default_height, term.scale);
|
||||
render_resize(&term, default_width, default_height);
|
||||
|
||||
wl_display_dispatch_pending(term.wl.display);
|
||||
|
||||
|
|
@ -933,6 +979,7 @@ out:
|
|||
|
||||
shm_fini();
|
||||
|
||||
tll_free(term.wl.on_outputs);
|
||||
tll_foreach(term.wl.monitors, it) {
|
||||
free(it->item.name);
|
||||
if (it->item.xdg != NULL)
|
||||
|
|
|
|||
13
render.c
13
render.c
|
|
@ -675,8 +675,19 @@ reflow(struct row **new_grid, int new_cols, int new_rows,
|
|||
|
||||
/* Move to terminal.c? */
|
||||
void
|
||||
render_resize(struct terminal *term, int width, int height, int scale)
|
||||
render_resize(struct terminal *term, int width, int height)
|
||||
{
|
||||
int scale = -1;
|
||||
tll_foreach(term->wl.on_outputs, it) {
|
||||
if (it->item->scale > scale)
|
||||
scale = it->item->scale;
|
||||
}
|
||||
|
||||
if (scale == -1) {
|
||||
/* Haven't 'entered' an output yet? */
|
||||
scale = 1;
|
||||
}
|
||||
|
||||
width *= term->scale;
|
||||
height *= term->scale;
|
||||
|
||||
|
|
|
|||
2
render.h
2
render.h
|
|
@ -6,7 +6,7 @@ struct font *attrs_to_font(
|
|||
struct terminal *term, const struct attributes *attrs);
|
||||
|
||||
void grid_render(struct terminal *term);
|
||||
void render_resize(struct terminal *term, int width, int height, int scale);
|
||||
void render_resize(struct terminal *term, int width, int height);
|
||||
void render_set_title(struct terminal *term, const char *title);
|
||||
void render_update_cursor_surface(struct terminal *term);
|
||||
void render_refresh(struct terminal *term);
|
||||
|
|
|
|||
|
|
@ -63,7 +63,8 @@ struct wayland {
|
|||
struct xdg_surface *xdg_surface;
|
||||
struct xdg_toplevel *xdg_toplevel;
|
||||
bool have_argb8888;
|
||||
tll(struct monitor) monitors;
|
||||
tll(struct monitor) monitors; /* All available outputs */
|
||||
tll(const struct monitor *) on_outputs; /* Outputs we're mapped on */
|
||||
};
|
||||
|
||||
struct rgb { float r, g, b; };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue