2022-01-23 17:58:48 +00:00
use graphics_server ::api ::{ Rectangle , TextView , Line , RoundedRectangle , Circle , Point , Gid } ;
2021-03-26 12:22:33 +00:00
use xous_ipc ::String ;
2021-01-17 09:02:40 +00:00
2021-04-04 21:47:17 +00:00
pub ( crate ) const SERVER_NAME_GAM : & str = " _Graphical Abstraction Manager_ " ;
2021-03-15 18:02:53 +00:00
#[ derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone) ]
2021-02-28 20:01:33 +00:00
pub enum GamObjectType {
Line ( Line ) ,
Circ ( Circle ) ,
Rect ( Rectangle ) ,
RoundRect ( RoundedRectangle ) ,
}
2021-03-15 18:02:53 +00:00
#[ derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone) ]
2021-02-28 20:01:33 +00:00
pub struct GamObject {
pub canvas : Gid ,
pub obj : GamObjectType ,
}
2022-01-24 08:33:01 +00:00
#[ derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) ]
pub struct GamObjectList {
pub canvas : Gid ,
pub list : [ Option < GamObjectType > ; 32 ] ,
free : usize ,
}
impl GamObjectList {
pub fn new ( canvas : Gid ) -> GamObjectList {
GamObjectList {
canvas ,
list : Default ::default ( ) ,
free : 0 ,
}
}
pub fn push ( & mut self , item : GamObjectType ) -> Result < ( ) , GamObjectType > {
if self . free < self . list . len ( ) {
self . list [ self . free ] = Some ( item ) ;
self . free + = 1 ;
Ok ( ( ) )
} else {
Err ( item )
}
}
}
2021-02-28 20:01:33 +00:00
2021-06-18 11:35:03 +00:00
#[ derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone, Eq, PartialEq) ]
pub enum TokenType {
/// GAM tokens are for objects that the GAM delegates to do app logic.
/// this is different to prevent delegated apps from masquerading as the app itself
Gam ,
/// App token is a token given to the app and only the app to identify itself to the Gam
/// for any requests
App ,
}
2021-03-15 18:02:53 +00:00
#[ derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone) ]
2021-03-07 10:58:48 +00:00
pub struct SetCanvasBoundsRequest {
2021-06-15 20:50:26 +00:00
pub token : [ u32 ; 4 ] ,
2021-06-18 11:35:03 +00:00
pub token_type : TokenType ,
2021-03-07 10:58:48 +00:00
pub requested : Point ,
pub granted : Option < Point > ,
}
2021-03-15 18:02:53 +00:00
#[ derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone) ]
2021-06-15 20:50:26 +00:00
pub struct SetAudioOpcode {
pub token : [ u32 ; 4 ] ,
pub opcode : u32 ,
2021-03-09 16:25:14 +00:00
}
2021-06-18 20:44:21 +00:00
#[ derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone) ]
pub struct SwitchToApp {
pub token : [ u32 ; 4 ] ,
pub app_name : String ::< 128 > ,
}
2021-06-15 20:50:26 +00:00
#[ derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone) ]
pub enum UxType {
Chat ,
Menu ,
2021-07-21 19:04:16 +00:00
Modal ,
2022-01-23 07:52:17 +00:00
Framebuffer ,
2021-06-15 20:50:26 +00:00
}
#[ derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone) ]
pub struct UxRegistration {
// request specification
pub app_name : String ::< 128 > , // the putative name of our application - GAM may modify this if a spoof attempt is detected
pub ux_type : UxType ,
pub predictor : Option < String ::< 64 > > , // optional specification for an IME prediction engine to use. This can be updated later on, or None and a default engine will be provided.
// Callbacks:
/// SID ofserver for callbacks from the GAM. Note this is a disclosure of the SID, which is normally a secret in the kernel services.
/// however, for apps, we allow disclosure of this to the kernel services, because we trust them.
pub listener : [ u32 ; 4 ] ,
/// opcode ID for redraw messages. This is mandatory.
pub redraw_id : u32 ,
/// optional opcode ID for inputs. If presented, input Strings are sent to this Ux
pub gotinput_id : Option < u32 > ,
/// optional opcode ID for audio frames. If presented, audio callbacks requests for more play/rec data will be sent directly to this opcode
pub audioframe_id : Option < u32 > ,
/// optional opcode ID for raw keystrokes. They are passed on to the caller in real-time.
pub rawkeys_id : Option < u32 > ,
2022-01-23 09:12:14 +00:00
/// optional opcode ID code for focus change notifications. Most applications will want to provide this to stop hogging resources when backgrounded
pub focuschange_id : Option < u32 > ,
2021-06-15 20:50:26 +00:00
}
2021-04-04 21:47:17 +00:00
#[ derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive) ]
2021-03-13 10:05:33 +00:00
pub ( crate ) enum Opcode {
2021-01-16 20:02:08 +00:00
// clears a canvas with a given GID
2021-04-04 21:47:17 +00:00
ClearCanvas , //(Gid),
2021-01-16 20:02:08 +00:00
2021-03-07 10:58:48 +00:00
// return the dimensions of a canvas as a Point (the top left is always (0,0))
2021-04-04 21:47:17 +00:00
GetCanvasBounds , //(Gid),
2021-03-07 10:58:48 +00:00
// request a new size for my canvas.
// This normally will be denied, unless the requested Gid corresponds to a special canvas that allows resizing.
2021-04-04 21:47:17 +00:00
SetCanvasBounds , //(SetCanvasBoundsRequest),
2021-03-07 10:58:48 +00:00
// draws an object
2021-04-04 21:47:17 +00:00
RenderObject , //(GamObject),
2022-01-24 08:33:01 +00:00
RenderObjectList ,
2021-03-07 10:58:48 +00:00
2021-01-16 20:02:08 +00:00
// renders a TextView
2021-04-04 21:47:17 +00:00
RenderTextView , //(TextView),
2021-01-16 20:02:08 +00:00
2021-03-08 18:32:36 +00:00
// forces a redraw (which also does defacement, etc.)
Redraw ,
2021-06-15 20:50:26 +00:00
// returns a GID to the "content" Canvas of the token holder
RequestContentCanvas ,
2021-06-15 04:50:29 +00:00
// registers a Ux of a requested type
2021-06-15 20:50:26 +00:00
// takes in the LayoutType, default PredictorType, a SID for UxEvents, a human-readable identifier token; returns a content canvas GID
2021-06-15 04:50:29 +00:00
// also takes a bunch of optional ID codes for the various callbacks
// internally assigns a trust level, based on a first-come first-serve basis for known services, and then a much lower trust for rando ones
RegisterUx ,
2021-03-07 10:58:48 +00:00
2021-06-15 20:50:26 +00:00
// updates the audio connection ID post-registration
SetAudioOpcode ,
2021-03-10 17:45:54 +00:00
// Requests setting the UI to the power down screen
PowerDownRequest ,
2021-04-22 10:07:41 +00:00
// Request blank screen for ship mode
ShipModeBlankRequest ,
2021-06-15 20:50:26 +00:00
// used to claim a GAM registration token (should be used only by status.rs)
2021-06-12 20:40:50 +00:00
ClaimToken ,
/// system-level API that can be called by the Xous process launcher to check if we're at a state where less trusted code could be run
/// it basically checks that all tokens have been claimed by trusted OS procesess, thus blocking any further token creation
2021-06-15 09:41:14 +00:00
TrustedInitDone ,
2021-06-12 20:40:50 +00:00
2021-06-15 20:50:26 +00:00
/// this is used internally to route input lines from the IMEF
InputLine ,
2021-06-16 17:12:25 +00:00
/// passed to the keyboard server to notify me of a keyboard event
KeyboardEvent ,
/// used to turn keyboard vibrate on and off
Vibe ,
2021-06-17 20:10:41 +00:00
/// called by a context when it's done with taking the screen; requests the GAM to revert focus to the last-focused app
RevertFocus ,
2021-06-18 20:44:21 +00:00
RevertFocusNb , // non-blocking version
2021-06-17 20:10:41 +00:00
2021-06-18 11:35:03 +00:00
/// pass-through to get glyph heights to assist with layout planning, without having to create a gfx connection
QueryGlyphProps ,
2021-06-12 20:40:50 +00:00
2021-06-18 16:25:18 +00:00
/// request redraw of IME area
RedrawIme ,
2021-06-18 20:44:21 +00:00
/// switch focus to an app
SwitchToApp ,
/// raise a context menu
RaiseMenu ,
2021-07-03 13:08:39 +00:00
/// Turn on Devboot Flag
Devboot ,
2021-09-15 17:00:22 +00:00
/// Show a test pattern. Can only call this once (to prevent abuse)
TestPattern ,
2021-06-12 20:40:50 +00:00
Quit ,
2021-04-04 21:47:17 +00:00
}
#[ derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) ]
pub ( crate ) enum Return {
2021-06-15 20:50:26 +00:00
UxToken ( Option < [ u32 ; 4 ] > ) ,
2021-04-04 21:47:17 +00:00
RenderReturn ( TextView ) ,
SetCanvasBoundsReturn ( SetCanvasBoundsRequest ) ,
2021-06-15 20:50:26 +00:00
ContentCanvasReturn ( Option < Gid > ) ,
2021-04-04 21:47:17 +00:00
Failure ,
2021-07-27 09:30:37 +00:00
NotCurrentlyDrawable ,
2021-01-16 20:02:08 +00:00
}
2021-07-28 15:00:25 +00:00
// small wart -- we have to reset the size of a modal to max size for resize computations
// reveal the max size globally, since it's a constant
2021-08-12 22:00:21 +00:00
pub const MODAL_Y_MAX : i16 = 350 ; // in absolute screen coords, not relative to top pad
2022-01-16 09:30:32 +00:00
#[ derive(Debug, Eq, PartialEq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) ]
pub ( crate ) enum MenuMgrOp {
// incoming is one of these ops
AddItem ,
DeleteItem ,
2022-02-02 18:46:37 +00:00
SetIndex ( usize ) ,
2022-01-16 09:30:32 +00:00
Quit ,
// response must be one of these
Ok ,
Err ,
}
#[ derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) ]
pub ( crate ) struct MenuManagement {
pub ( crate ) item : MenuItem ,
pub ( crate ) op : MenuMgrOp ,
}
#[ allow(dead_code) ] // here until Memory types are implemented
#[ derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) ]
pub enum MenuPayload {
/// memorized scalar payload
Scalar ( [ u32 ; 4 ] ) ,
/// this a nebulous-but-TBD maybe way of bodging in a more complicated record, which would involve
/// casting this memorized, static payload into a Buffer and passing it on. Let's not worry too much about it for now, it's mostly apirational...
Memory ( ( [ u8 ; 256 ] , usize ) ) ,
}
#[ derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) ]
pub struct MenuItem {
pub name : String ::< 64 > ,
/// if action_conn is None, this is a NOP menu item (it just does nothing and closes the menu)
pub action_conn : Option < xous ::CID > ,
pub action_opcode : u32 , // this is ignored if action_conn is None
pub action_payload : MenuPayload ,
pub close_on_select : bool ,
}
2022-01-23 17:58:48 +00:00
#[ derive(Debug, Copy, Clone, PartialEq, Eq) ]
pub enum CanvasType {
ChatContent ,
ChatInput ,
ChatPreditive ,
Framebuffer ,
Modal ,
Menu ,
Status ,
}
impl CanvasType {
pub fn is_content ( & self ) -> bool {
match & self {
CanvasType ::ChatContent |
CanvasType ::Framebuffer |
CanvasType ::Modal |
CanvasType ::Menu |
CanvasType ::Status = > true ,
_ = > false ,
}
}
}
#[ derive(Debug, Copy, Clone) ]
pub struct GidRecord {
pub gid : Gid ,
pub canvas_type : CanvasType ,
}