ui: Update UI state based on output events
This commit is contained in:
@ -15,6 +15,7 @@ sources = [
|
||||
'dbus.c',
|
||||
'imservice.c',
|
||||
'server-context-service.c',
|
||||
'ui_manager.c',
|
||||
'wayland.c',
|
||||
'../eek/eek.c',
|
||||
'../eek/eek-element.c',
|
||||
|
||||
@ -139,6 +139,7 @@ make_window (ServerContextService *context)
|
||||
NULL
|
||||
);
|
||||
|
||||
squeek_uiman_set_surface(context->manager, context->window);
|
||||
g_object_connect (context->window,
|
||||
"signal::destroy", G_CALLBACK(on_destroy), context,
|
||||
"signal::map", G_CALLBACK(on_notify_map), context,
|
||||
|
||||
8
src/ui_manager.c
Normal file
8
src/ui_manager.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include "eek/layersurface.h"
|
||||
|
||||
void squeek_manager_set_surface_height(PhoshLayerSurface *surface, uint32_t desired_height) {
|
||||
phosh_layer_surface_set_size(surface, 0,
|
||||
(gint)desired_height);
|
||||
phosh_layer_surface_set_exclusive_zone(surface, (gint)desired_height);
|
||||
phosh_layer_surface_wl_surface_commit (surface);
|
||||
}
|
||||
@ -2,13 +2,14 @@
|
||||
#define UI_MANAGER__
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "eek/layersurface.h"
|
||||
#include "outputs.h"
|
||||
|
||||
struct ui_manager;
|
||||
|
||||
struct ui_manager *squeek_uiman_new(struct squeek_outputs *outputs);
|
||||
void squeek_uiman_set_output(struct ui_manager *uiman, struct squeek_output_handle output);
|
||||
void squeek_uiman_set_surface(struct ui_manager *uiman, PhoshLayerSurface *surface);
|
||||
uint32_t squeek_uiman_get_perceptual_height(struct ui_manager *uiman);
|
||||
|
||||
#endif
|
||||
|
||||
@ -20,9 +20,24 @@ use ::logging::Warn;
|
||||
|
||||
mod c {
|
||||
use super::*;
|
||||
use std::os::raw::c_void;
|
||||
use ::outputs::c::COutputs;
|
||||
use ::util::c::Wrapped;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(C)]
|
||||
pub struct PhoshLayerSurface(*const c_void);
|
||||
|
||||
extern "C" {
|
||||
// Rustc wrongly assumes
|
||||
// that COutputs allows C direct access to the underlying RefCell.
|
||||
#[allow(improper_ctypes)]
|
||||
pub fn squeek_manager_set_surface_height(
|
||||
surface: PhoshLayerSurface,
|
||||
height: u32,
|
||||
);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C"
|
||||
fn squeek_uiman_new(outputs: COutputs) -> Wrapped<Manager> {
|
||||
@ -58,6 +73,18 @@ mod c {
|
||||
let mut uiman = uiman.borrow_mut();
|
||||
uiman.set_output(output)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C"
|
||||
fn squeek_uiman_set_surface(
|
||||
uiman: Wrapped<Manager>,
|
||||
surface: PhoshLayerSurface,
|
||||
) {
|
||||
let uiman = uiman.clone_ref();
|
||||
let mut uiman = uiman.borrow_mut();
|
||||
// Surface is not state, so doesn't need to propagate updates.
|
||||
uiman.surface = Some(surface);
|
||||
}
|
||||
}
|
||||
|
||||
/// Stores current state of all things influencing what the UI should look like.
|
||||
@ -135,12 +162,14 @@ impl ManagerState {
|
||||
|
||||
pub struct Manager {
|
||||
state: ManagerState,
|
||||
surface: Option<c::PhoshLayerSurface>,
|
||||
}
|
||||
|
||||
impl Manager {
|
||||
fn new() -> Manager {
|
||||
Manager {
|
||||
state: ManagerState { current_output: None },
|
||||
state: ManagerState { current_output: None, },
|
||||
surface: None,
|
||||
}
|
||||
}
|
||||
fn set_output(&mut self, output: OutputHandle) {
|
||||
@ -176,11 +205,23 @@ impl Manager {
|
||||
current_output: Some((id.clone(), new_output_state)),
|
||||
..self.state.clone()
|
||||
};
|
||||
let new_height = new_state.get_perceptual_height();
|
||||
if new_height != self.state.get_perceptual_height() {
|
||||
println!("New height: {:?}", new_height);
|
||||
//update_layer_surface_height(new_height);
|
||||
// TODO: here hard-size the keyboard and suggestion box too.
|
||||
if let Some(surface) = &self.surface {
|
||||
let new_height = new_state.get_perceptual_height();
|
||||
if new_height != self.state.get_perceptual_height() {
|
||||
// TODO: here hard-size the keyboard and suggestion box too.
|
||||
match new_height {
|
||||
Some(new_height) => unsafe {
|
||||
c::squeek_manager_set_surface_height(
|
||||
*surface,
|
||||
new_height,
|
||||
)
|
||||
}
|
||||
None => log_print!(
|
||||
logging::Level::Bug,
|
||||
"Can't calculate new size",
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
self.state = new_state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user