outputs: Remove ui manager

This commit is contained in:
Dorota Czaplejewicz
2022-01-30 16:54:32 +00:00
parent 697be64418
commit a3f91701d0
8 changed files with 2 additions and 153 deletions

View File

@ -40,6 +40,5 @@ mod style;
mod submission; mod submission;
pub mod tests; pub mod tests;
pub mod util; pub mod util;
mod ui_manager;
mod vkeyboard; mod vkeyboard;
mod xdg; mod xdg;

View File

@ -118,26 +118,6 @@ pub mod c {
/// Wrapping Outputs is required for calling its methods from C /// Wrapping Outputs is required for calling its methods from C
type COutputs = Wrapped<Outputs>; type COutputs = Wrapped<Outputs>;
/// A stable reference to an output.
#[derive(Clone)]
#[repr(C)]
pub struct OutputHandle {
wl_output: WlOutput,
outputs: COutputs,
}
impl OutputHandle {
// Cannot return an Output reference
// because COutputs is too deeply wrapped
pub fn get_state(&self) -> Option<OutputState> {
let outputs = self.outputs.clone_ref();
let outputs = outputs.borrow();
outputs
.find_output(self.wl_output.clone())
.map(|o| o.current.clone())
}
}
// Defined in Rust // Defined in Rust
// Callbacks from the output listener follow // Callbacks from the output listener follow
@ -303,17 +283,6 @@ pub mod c {
.unwrap_or(WlOutput::null()) .unwrap_or(WlOutput::null())
} }
#[no_mangle]
pub extern "C"
fn squeek_outputs_get_current(raw_collection: COutputs) -> OutputHandle {
let collection = raw_collection.clone_ref();
let collection = collection.borrow();
OutputHandle {
wl_output: collection.outputs[0].0.output.clone(),
outputs: raw_collection.clone(),
}
}
// TODO: handle unregistration // TODO: handle unregistration
} }
@ -437,14 +406,6 @@ impl Outputs {
} }
} }
fn find_output(&self, wl_output: c::WlOutput) -> Option<&Output> {
self.outputs
.iter()
.find_map(|(o, _global)|
if o.output == wl_output { Some(o) } else { None }
)
}
fn find_output_mut(&mut self, wl_output: c::WlOutput) fn find_output_mut(&mut self, wl_output: c::WlOutput)
-> Option<&mut Output> -> Option<&mut Output>
{ {

View File

@ -42,7 +42,6 @@ struct _ServerContextService {
/// Needed for instantiating the widget /// Needed for instantiating the widget
struct submission *submission; // unowned struct submission *submission; // unowned
struct squeek_layout_state *layout; struct squeek_layout_state *layout;
struct ui_manager *manager; // unowned
struct squeek_state_manager *state_manager; // shared reference struct squeek_state_manager *state_manager; // shared reference
PhoshLayerSurface *window; PhoshLayerSurface *window;
@ -315,13 +314,12 @@ init (ServerContextService *self) {
} }
ServerContextService * ServerContextService *
server_context_service_new (EekboardContextService *self, struct submission *submission, struct squeek_layout_state *layout, struct ui_manager *uiman, struct squeek_state_manager *state_manager) server_context_service_new (EekboardContextService *self, struct submission *submission, struct squeek_layout_state *layout, struct squeek_state_manager *state_manager)
{ {
ServerContextService *ui = g_object_new (SERVER_TYPE_CONTEXT_SERVICE, NULL); ServerContextService *ui = g_object_new (SERVER_TYPE_CONTEXT_SERVICE, NULL);
ui->submission = submission; ui->submission = submission;
ui->state = self; ui->state = self;
ui->layout = layout; ui->layout = layout;
ui->manager = uiman;
ui->state_manager = state_manager; ui->state_manager = state_manager;
init(ui); init(ui);
return ui; return ui;

View File

@ -20,7 +20,6 @@
#include "src/layout.h" #include "src/layout.h"
#include "src/submission.h" #include "src/submission.h"
#include "ui_manager.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -29,7 +28,7 @@ G_BEGIN_DECLS
/** Manages the lifecycle of the window displaying layouts. */ /** Manages the lifecycle of the window displaying layouts. */
G_DECLARE_FINAL_TYPE (ServerContextService, server_context_service, SERVER, CONTEXT_SERVICE, GObject) G_DECLARE_FINAL_TYPE (ServerContextService, server_context_service, SERVER, CONTEXT_SERVICE, GObject)
ServerContextService *server_context_service_new(EekboardContextService *self, struct submission *submission, struct squeek_layout_state *layout, struct ui_manager *uiman, struct squeek_state_manager *state_manager); ServerContextService *server_context_service_new(EekboardContextService *self, struct submission *submission, struct squeek_layout_state *layout, struct squeek_state_manager *state_manager);
enum squeek_arrangement_kind server_context_service_get_layout_type(ServerContextService *); enum squeek_arrangement_kind server_context_service_get_layout_type(ServerContextService *);
G_END_DECLS G_END_DECLS
#endif /* SERVER_CONTEXT_SERVICE_H */ #endif /* SERVER_CONTEXT_SERVICE_H */

View File

@ -33,7 +33,6 @@
#include "outputs.h" #include "outputs.h"
#include "submission.h" #include "submission.h"
#include "server-context-service.h" #include "server-context-service.h"
#include "ui_manager.h"
#include "wayland.h" #include "wayland.h"
#include <gdk/gdkwayland.h> #include <gdk/gdkwayland.h>
@ -56,8 +55,6 @@ struct squeekboard {
ServerContextService *ui_context; // mess, includes the entire UI ServerContextService *ui_context; // mess, includes the entire UI
/// Currently wanted layout. TODO: merge into state::Application /// Currently wanted layout. TODO: merge into state::Application
struct squeek_layout_state layout_choice; struct squeek_layout_state layout_choice;
/// UI shape tracker/chooser. TODO: merge into state::Application
struct ui_manager *ui_manager;
}; };
@ -400,8 +397,6 @@ main (int argc, char **argv)
// Also initializes wayland // Also initializes wayland
struct rsobjects rsobjects = squeek_init(); struct rsobjects rsobjects = squeek_init();
instance.ui_manager = squeek_uiman_new();
instance.settings_context = eekboard_context_service_new(&instance.layout_choice); instance.settings_context = eekboard_context_service_new(&instance.layout_choice);
// set up dbus // set up dbus
@ -446,7 +441,6 @@ main (int argc, char **argv)
instance.settings_context, instance.settings_context,
rsobjects.submission, rsobjects.submission,
&instance.layout_choice, &instance.layout_choice,
instance.ui_manager,
rsobjects.state_manager); rsobjects.state_manager);
if (!ui_context) { if (!ui_context) {
g_error("Could not initialize GUI"); g_error("Could not initialize GUI");

View File

@ -5,7 +5,6 @@
#include "virtual-keyboard-unstable-v1-client-protocol.h" #include "virtual-keyboard-unstable-v1-client-protocol.h"
#include "eek/eek-types.h" #include "eek/eek-types.h"
#include "main.h" #include "main.h"
#include "src/ui_manager.h"
struct squeek_layout; struct squeek_layout;

View File

@ -1,19 +0,0 @@
#ifndef UI_MANAGER__
#define UI_MANAGER__
#include <inttypes.h>
#include "eek/eek-types.h"
#include "outputs.h"
#include "main.h"
struct ui_manager;
struct ui_manager *squeek_uiman_new(void);
void squeek_uiman_set_output(struct ui_manager *uiman, struct squeek_output_handle output);
uint32_t squeek_uiman_get_perceptual_height(struct ui_manager *uiman);
struct vis_manager;
struct vis_manager *squeek_visman_new(struct squeek_state_manager *state_manager);
#endif

View File

@ -1,82 +0,0 @@
/* Copyright (C) 2020, 2021 Purism SPC
* SPDX-License-Identifier: GPL-3.0+
*/
/*! Centrally manages the shape of the UI widgets, and the choice of layout.
*
* Coordinates this based on information collated from all possible sources.
*/
use std::cmp::min;
use ::outputs::c::OutputHandle;
pub mod c {
use super::*;
use ::util::c::Wrapped;
#[no_mangle]
pub extern "C"
fn squeek_uiman_new() -> Wrapped<Manager> {
Wrapped::new(Manager { output: None })
}
/// Used to size the layer surface containing all the OSK widgets.
#[no_mangle]
pub extern "C"
fn squeek_uiman_get_perceptual_height(
uiman: Wrapped<Manager>,
) -> u32 {
let uiman = uiman.clone_ref();
let uiman = uiman.borrow();
// TODO: what to do when there's no output?
uiman.get_perceptual_height().unwrap_or(0)
}
#[no_mangle]
pub extern "C"
fn squeek_uiman_set_output(
uiman: Wrapped<Manager>,
output: OutputHandle,
) {
let uiman = uiman.clone_ref();
let mut uiman = uiman.borrow_mut();
uiman.output = Some(output);
}
}
/// Stores current state of all things influencing what the UI should look like.
pub struct Manager {
/// Shared output handle, current state updated whenever it's needed.
// TODO: Stop assuming that the output never changes.
// (There's no way for the output manager to update the ui manager.)
// FIXME: Turn into an OutputState and apply relevant connections elsewhere.
// Otherwise testability and predictablity is low.
output: Option<OutputHandle>,
//// Pixel size of the surface. Needs explicit updating.
//surface_size: Option<Size>,
}
impl Manager {
fn get_perceptual_height(&self) -> Option<u32> {
let output_info = (&self.output).as_ref()
.and_then(|o| o.get_state())
.map(|os| (os.scale as u32, os.get_pixel_size()));
match output_info {
Some((scale, Some(px_size))) => Some({
let height = if (px_size.width < 720) & (px_size.width > 0) {
px_size.width * 7 / 12 // to match 360×210
} else if px_size.width < 1080 {
360 + (1080 - px_size.width) * 60 / 360 // smooth transition
} else {
360
};
// Don't exceed half the display size
min(height, px_size.height / 2) / scale
}),
Some((scale, None)) => Some(360 / scale),
None => None,
}
}
}