From fbb3824a3d7a8bf5af9f56240f9b17ad69162270 Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Fri, 11 Oct 2019 14:26:32 +0000 Subject: [PATCH] height: Derive from display width --- src/outputs.h | 2 +- src/outputs.rs | 28 +++++++++++++++++++++++++++- src/server-context-service.c | 12 +++++++++--- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/outputs.h b/src/outputs.h index 9e88ab92..38a207f6 100644 --- a/src/outputs.h +++ b/src/outputs.h @@ -9,5 +9,5 @@ struct squeek_outputs *squeek_outputs_new(); void squeek_outputs_free(struct squeek_outputs*); void squeek_outputs_register(struct squeek_outputs*, struct wl_output *output); struct wl_output *squeek_outputs_get_current(struct squeek_outputs*); - +int32_t squeek_outputs_get_perceptual_width(struct squeek_outputs*, struct wl_output *output); #endif diff --git a/src/outputs.rs b/src/outputs.rs index 0ce48476..7bdc19d4 100644 --- a/src/outputs.rs +++ b/src/outputs.rs @@ -191,7 +191,33 @@ pub mod c { let collection = collection.borrow(); collection.outputs[0].output.clone() } - + + #[no_mangle] + pub extern "C" + fn squeek_outputs_get_perceptual_width( + raw_collection: COutputs, + wl_output: WlOutput, + ) -> i32 { + let collection = raw_collection.clone_ref(); + let collection = collection.borrow(); + + let output_state = collection.outputs + .iter() + .find_map(|o| + if o.output == wl_output { Some(&o.current) } else { None } + ); + + match output_state { + Some(OutputState { + current_mode: Some(super::Mode { width, height: _ } ), + scale: scale, + }) => width / scale, + _ => { + eprintln!("No width registered on output"); + 0 + }, + } + } // TODO: handle unregistration } diff --git a/src/server-context-service.c b/src/server-context-service.c index a3ab820f..fd9617ef 100644 --- a/src/server-context-service.c +++ b/src/server-context-service.c @@ -113,7 +113,6 @@ on_notify_unmap (GObject *object, g_object_set (context, "visible", FALSE, NULL); } -#define KEYBOARD_HEIGHT 210 static void make_window (ServerContextService *context) { @@ -121,18 +120,25 @@ make_window (ServerContextService *context) g_error("Window already present"); struct wl_output *output = squeek_outputs_get_current(squeek_wayland->outputs); + int32_t width = squeek_outputs_get_perceptual_width(squeek_wayland->outputs, output); + uint32_t height = 180; + if (width < 360 && width > 0) { + height = ((unsigned)width * 7 / 12); // to match 360×210 + } else if (width < 540) { + height = 180 + (540 - (unsigned)width) * 30 / 180; // smooth transition + } context->window = g_object_new ( PHOSH_TYPE_LAYER_SURFACE, "layer-shell", squeek_wayland->layer_shell, "wl-output", output, - "height", KEYBOARD_HEIGHT, + "height", height, "anchor", ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT, "layer", ZWLR_LAYER_SHELL_V1_LAYER_TOP, "kbd-interactivity", FALSE, - "exclusive-zone", KEYBOARD_HEIGHT, + "exclusive-zone", height, "namespace", "osk", NULL );