height: Derive from display width

This commit is contained in:
Dorota Czaplejewicz
2019-10-11 14:26:32 +00:00
parent 24126ad4f3
commit fbb3824a3d
3 changed files with 37 additions and 5 deletions

View File

@ -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

View File

@ -192,6 +192,32 @@ pub mod c {
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
}

View File

@ -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
);