Skip to content

Commit

Permalink
Add output scaling (#34)
Browse files Browse the repository at this point in the history
* feat: output scaling

* chore: update man file

* fix: message when scaling
  • Loading branch information
oliverfriedmann authored Nov 28, 2022
1 parent 4077064 commit 29943b5
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 7 deletions.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM debian:bookworm
RUN apt-get update
RUN apt-get install -y libwlroots-dev xwayland meson cmake libcairo2-dev libpango1.0-dev
ADD * ./
ADD examples ./examples
RUN meson build
RUN ninja -C build
1 change: 1 addition & 0 deletions examples/config
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ definekey top XF86MonBrightnessUp exec xbacklight -inc 1
#output eDP-1 disable
#output eDP-1 enable
#output eDP-1 prio 1
#output eDP-2 pos 0 0 res 1366x768 rate 60 scale 2.0

#####################
#Input configuration
Expand Down
3 changes: 2 additions & 1 deletion man/cagebreak-config.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,13 @@ message <text>
*only*
Remove all splits and make current window fill the entire screen

*output <name> [[pos <xpos> <ypos> res <width>x<height> rate <rate>] | enable | disable | prio <n> ]*
*output <name> [[pos <xpos> <ypos> res <width>x<height> rate <rate> [scale <scale>]] | enable | disable | prio <n> ]*
Configure output "<name>" -
- <xpos> and <ypos> are the position of the
monitor in pixels. The top-left monitor should have the coordinates 0 0.
- <width> and <height> specify the resolution in pixels.
- <rate> sets the refresh rate of the monitor (often this is 50 or 60).
- <scale> sets the output scale (default is 1.0)
- enable and disable enable or disable <name>. Note that if
<output> is the only enabled output, *output <output> disable* has
no effect.
Expand Down
8 changes: 4 additions & 4 deletions message.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ create_message_texture(const char *string, const struct cg_output *output) {
float *bg_col = output->server->message_config.bg_color;
cairo_set_source_rgba(cairo, bg_col[0], bg_col[1], bg_col[2], bg_col[3]);
cairo_paint(cairo);
PangoContext *pango = pango_cairo_create_context(cairo);
float *fg_col = output->server->message_config.fg_color;
cairo_set_source_rgba(cairo, fg_col[0], fg_col[1], fg_col[2], fg_col[3]);
cairo_set_line_width(cairo, 2);
Expand Down Expand Up @@ -168,7 +167,6 @@ create_message_texture(const char *string, const struct cg_output *output) {
wlr_buffer_end_data_ptr_access(&buf->base);

cairo_surface_destroy(surface);
g_object_unref(pango);
cairo_destroy(cairo);
return buf;
}
Expand Down Expand Up @@ -196,8 +194,9 @@ message_set_output(struct cg_output *output, const char *string,
message->position = box;
wl_list_insert(&output->messages, &message->link);

int width = buf->base.width;
int height = buf->base.height;
double scale = output->wlr_output->scale;
int width = buf->base.width/scale;
int height = buf->base.height/scale;
message->position->width = width;
message->position->height = height;
switch(align) {
Expand Down Expand Up @@ -235,6 +234,7 @@ message_set_output(struct cg_output *output, const char *string,
wlr_scene_node_set_enabled(&message->message->node, true);
struct wlr_box *outp_box = wlr_output_layout_get_box(
output->server->output_layout, output->wlr_output);
wlr_scene_buffer_set_dest_size(message->message,width,height);
wlr_scene_node_set_position(&message->message->node,
message->position->x + outp_box->x,
message->position->y + outp_box->y);
Expand Down
8 changes: 6 additions & 2 deletions output.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ output_find_config(struct cg_server *server, struct wlr_output *output) {

static int
output_set_mode(struct wlr_output *output, int width, int height,
float refresh_rate) {
float refresh_rate, float *scale) {
int mhz = (int)(refresh_rate * 1000);

if(wl_list_empty(&output->modes)) {
Expand Down Expand Up @@ -209,6 +209,10 @@ output_set_mode(struct wlr_output *output, int width, int height,
wlr_log(WLR_DEBUG, "Assigning configured mode to %s", output->name);
}
wlr_output_set_mode(output, best);
if (scale != NULL) {
wlr_log(WLR_INFO, "Setting output scale to %f", *scale);
wlr_output_set_scale(output, *scale);
}
wlr_output_commit(output);
if(!wlr_output_test(output)) {
wlr_log(WLR_ERROR,
Expand Down Expand Up @@ -294,7 +298,7 @@ output_configure(struct cg_server *server, struct cg_output *output) {
if(config->pos.x != -1) {
if(output_set_mode(wlr_output, config->pos.width,
config->pos.height,
config->refresh_rate) != 0) {
config->refresh_rate, config->scale) != 0) {
wlr_log(WLR_ERROR,
"Setting output mode failed, disabling output.");
output_clear(output);
Expand Down
1 change: 1 addition & 0 deletions output.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct cg_output_config {
struct wlr_box pos;
char *output_name;
float refresh_rate;
float *scale;
int priority;
struct wl_list link; // cg_server::output_config
};
Expand Down
14 changes: 14 additions & 0 deletions parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ parse_output_config(char **saveptr, char **errstr) {
cfg->output_name = NULL;
cfg->refresh_rate = 0;
cfg->priority = -1;
cfg->scale = NULL;
char *name = strtok_r(NULL, " ", saveptr);
if(name == NULL) {
*errstr =
Expand Down Expand Up @@ -619,6 +620,19 @@ parse_output_config(char **saveptr, char **errstr) {
goto error;
}

char *scale_str = strtok_r(NULL, " ", saveptr);
if(scale_str != NULL && strcmp(scale_str, "scale") == 0) {
cfg->scale = malloc(sizeof(float));
*cfg->scale = parse_float(saveptr, " ");
if(*cfg->scale <= 0.0) {
*errstr =
log_error("Error parsing scale of output configuration for "
"output %s, expected positive float",
name);
goto error;
}
}

cfg->output_name = strdup(name);
return cfg;
error:
Expand Down

0 comments on commit 29943b5

Please sign in to comment.