syntax = "proto2";
option optimize_for = LITE_RUNTIME;

package mir.protobuf;

// Outside of the IPC code no-one should care as this is all wrapped up.
// But for the following result messages we either populate the "real"
// attributes or, in the case of an error, the error attribute. So the
// attributes are all "optional" (or "repeated").

message StructuredError {
  optional uint32 domain = 1;
  optional uint32 code = 2;
}

message ConnectParameters {
  required string application_name = 1;
}

message SurfaceParameters {
  required int32 width = 1;
  required int32 height = 2;
  required int32 pixel_format = 3;
  required int32 buffer_usage = 4;
  optional string surface_name = 5;
  optional uint32 output_id = 6;

  optional int32 type = 7;
  optional int32 state = 8;
  optional int32 pref_orientation = 9;
  optional int32 parent_id = 10;
  
  optional Rectangle aux_rect = 11;
  optional int32 edge_attachment = 12;

  optional int32 min_width = 13;
  optional int32 min_height = 14;
  optional int32 max_width = 15;
  optional int32 max_height = 16;
  optional int32 width_inc = 17;
  optional int32 height_inc = 18;
  optional SurfaceAspectRatio min_aspect = 19;
  optional SurfaceAspectRatio max_aspect = 20;

  optional PersistentSurfaceId parent_persistent_id = 21;
  repeated Rectangle input_shape = 22;
  optional int32 shell_chrome = 24;
  repeated StreamConfiguration stream = 25; 
  optional int32 confine_pointer = 26;

  optional int32 placement_hints = 27;
  optional int32 surface_placement_gravity = 28;
  optional int32 aux_rect_placement_gravity = 29;
  optional int32 aux_rect_placement_offset_x = 30;
  optional int32 aux_rect_placement_offset_y = 31;
}

message SurfaceAspectRatio
{
    required uint32 width  = 1;
    required uint32 height = 2;
}

// If and when we break our protocol backward-compatibility, this could be
// merged with SurfaceParameters...
message SurfaceSpecification {
  optional int32 width = 1;
  optional int32 height = 2;
  optional int32 pixel_format = 3;
  optional int32 buffer_usage = 4;
  optional string name = 5;
  optional uint32 output_id = 6;
  optional int32 type = 7;
  optional int32 state = 8;
  optional int32 preferred_orientation = 9;
  optional int32 parent_id = 10;
  optional Rectangle aux_rect = 11;
  optional int32 edge_attachment = 12;

  optional int32 min_width = 13;
  optional int32 min_height = 14;
  optional int32 max_width = 15;
  optional int32 max_height = 16;

  optional int32 width_inc = 17;
  optional int32 height_inc = 18;
  optional SurfaceAspectRatio min_aspect = 19;
  optional SurfaceAspectRatio max_aspect = 20;

  repeated StreamConfiguration stream = 21; 

  optional PersistentSurfaceId parent_persistent_id = 22;
  repeated Rectangle input_shape = 23;
  optional int32 shell_chrome = 24;
  optional int32 confine_pointer = 25;

  // Intentionally missing 26 to get any further additions in line with SurfaceParameters
  optional int32 placement_hints = 27;
  optional int32 surface_placement_gravity = 28;
  optional int32 aux_rect_placement_gravity = 29;
  optional int32 aux_rect_placement_offset_x = 30;
  optional int32 aux_rect_placement_offset_y = 31;

  optional string cursor_name = 32;
  optional BufferStreamId cursor_id = 33;
  optional int32 hotspot_x = 34;
  optional int32 hotspot_y = 35;    
}

message StreamConfiguration {
  optional BufferStreamId id = 1;
  optional int32 displacement_x = 2;
  optional int32 displacement_y = 3;
  optional int32 swapinterval = 4;
  optional float scale = 5;

  optional int32 width = 6;
  optional int32 height = 7;

  optional string error = 127;
  optional StructuredError structured_error = 128;
};

message SurfaceModifications {
  required SurfaceId surface_id = 1;
  required SurfaceSpecification surface_specification = 2;
}

message SurfaceId {
  required int32 value = 1;
};

message PersistentSurfaceId {
  optional string value = 1;

  optional string error = 127;
  optional StructuredError structured_error = 128;
};

message BufferStreamId {
  required int32 value = 1;
};

message BufferStreamParameters {
    required int32 width = 1;
    required int32 height = 2;
    optional int32 pixel_format = 3;
    optional int32 buffer_usage = 4;
    optional uint32 native_format = 5;
    optional uint32 flags = 6;
};

message BufferAllocation {
  optional BufferStreamId id = 1;
  repeated BufferStreamParameters buffer_requests = 2;  
};

message BufferRelease {
  repeated Buffer buffers = 1;  
  optional BufferStreamId id = 2;
};

enum BufferOperation
{
    add = 0;
    update = 1;
    remove = 2;
};

message BufferRequest {
  optional BufferStreamId id = 1;
  optional Buffer buffer = 2;
  optional BufferOperation operation = 3;
};

message Buffer {
  optional int32 buffer_id = 1;
  repeated sint32 fd = 2;
  repeated int32  data = 3;
  optional int32  fds_on_side_channel = 4;
  optional int32  stride = 5;
  optional uint32 flags = 6;
  optional int32  width = 7;
  optional int32  height = 8;

  optional string error = 127;
  optional StructuredError structured_error = 128;
}

message ModuleProperties
{
    required string name = 1;
    required uint32 major_version = 2;
    required uint32 minor_version = 3;
    required uint32 micro_version = 4;
    required string file = 5;
};


message Platform {
  repeated sint32 fd = 1;
  repeated int32  data = 2;
  optional int32  fds_on_side_channel = 3;
  optional ModuleProperties graphics_module = 4;

  optional string error = 127;
  optional StructuredError structured_error = 128;
}

message DisplayCard {
    required uint32 card_id = 1;
    required uint32 max_simultaneous_outputs = 2;
}

message DisplayMode {
    optional uint32 vertical_resolution = 1;
    optional uint32 horizontal_resolution = 2;
    optional double refresh_rate = 3;
}

message DisplayOutput {
  repeated uint32 pixel_format = 1;
  optional uint32 current_format = 2;
  repeated DisplayMode mode = 3;
  optional uint32 current_mode = 4;
  optional sint32 position_x = 5;
  optional sint32 position_y = 6;
  optional uint32 card_id = 7;
  optional uint32 output_id = 8;
  optional uint32 connected = 9;
  optional uint32 used = 10;
  optional uint32 physical_width_mm = 11;
  optional uint32 physical_height_mm = 12;
  optional uint32 type = 13;
  optional uint32 preferred_mode = 14;
  optional uint32 power_mode = 15;
  optional sint32 orientation = 16;
  optional float scale_factor = 17;
  optional uint32 form_factor = 18;
  optional uint32 subpixel_arrangement = 19;
  optional bytes  gamma_red = 20;
  optional bytes  gamma_green = 21;
  optional bytes  gamma_blue = 22;
  optional uint32 gamma_supported = 23;
  optional bytes edid = 24;
  optional string model = 25;

  // Until recently logical_width/height were read-only fields calculated
  // by the server from the current mode and orientation. However they are
  // now user-customizable, so we need to be able to tell the difference
  // between logical dimensions calculated automatically (change dynamically)
  // and those chosen by the user (may only change by user intervention).
  optional uint32 logical_width = 26;
  optional uint32 logical_height = 27;
  optional bool custom_logical_size = 28;
}

message Extension
{
  optional string name = 1;
  repeated sint32 version = 2;
}

message Connection {
  optional Platform platform = 1;
//  optional DisplayInfo display_info = 2;
  repeated DisplayOutput display_output = 3;
  optional DisplayConfiguration display_configuration = 4;
  repeated uint32 surface_pixel_format = 5;
  optional InputDevices input_devices = 6;
  optional string input_configuration = 7;
  optional bool coordinate_translation_present = 8; 
  repeated Extension extension = 9;

  optional string error = 127;
  optional StructuredError structured_error = 128;
}

message BufferStream {
  optional BufferStreamId id = 1;
  optional int32 pixel_format = 2;
  optional int32 buffer_usage = 3;
  optional Buffer buffer = 4;
  
  optional string error = 127;
  optional StructuredError structured_error = 128;
}

message Surface {
  optional SurfaceId id = 1;
  optional int32 width = 2;
  optional int32 height = 3;
  optional int32 pixel_format = 4;
  optional int32 buffer_usage = 5;
  optional Buffer buffer = 6;

  repeated sint32 fd = 7;
  optional int32 fds_on_side_channel = 8;
  
  repeated SurfaceSetting attributes = 9;
  
  optional BufferStream buffer_stream = 10;

  optional string error = 127;
  optional StructuredError structured_error = 128;
}

message Void {
  optional string error = 127;
  optional StructuredError structured_error = 128;
}

message SurfaceSetting {
  optional SurfaceId surfaceid = 1;
  optional int32     attrib = 2;
  optional int32     ivalue = 3;
  // optional string    svalue = 4;  // Expected for future use
  optional string error = 127;
  optional StructuredError structured_error = 128;
}

message Event {
  optional bytes raw = 1;  // MirEvent structure
}

message DisplayConfiguration {
  repeated DisplayOutput display_output = 1;
  repeated DisplayCard   display_card = 2;
  optional string error = 127;
  optional StructuredError structured_error = 128;
}

message PreviewConfiguration {
  optional DisplayConfiguration configuration = 1;
  optional int32 timeout = 2;
}

message LifecycleEvent {
  required uint32 new_state = 1; // State transition
  optional string error = 127;
  optional StructuredError structured_error = 128;
}

message PingEvent {
  optional int32 serial = 1;  // Identifier for this ping
}

message EventSequence {
  repeated Event event = 1;
  optional DisplayConfiguration display_configuration = 2;
  optional LifecycleEvent lifecycle_event = 3;
  optional BufferRequest buffer_request = 4;
  optional PingEvent ping_event = 5;
  optional InputDevices input_devices = 6;
  optional string input_configuration = 7;

  optional string error = 127;
  optional StructuredError structured_error = 128;
}

message Rectangle {
  required int32 left = 1;
  required int32 top = 2;
  required uint32 width = 3;
  required uint32 height = 4;
}

message ScreencastParameters {
  required Rectangle region = 1;
  required uint32 width = 2;
  required uint32 height = 3;
  required int32 pixel_format = 4;
  optional uint32 num_buffers = 5;
  optional int32 mirror_mode = 6;
}

message ScreencastId {
  required uint32 value = 1;
}

message ScreencastRequest {
  optional ScreencastId id = 1;
  optional uint32 buffer_id = 2;
}

message Screencast {
  optional ScreencastId screencast_id = 1;
  optional Buffer buffer = 2;
  optional BufferStream buffer_stream = 3;
  optional string error = 127;
  optional StructuredError structured_error = 128;
}

message CursorSetting {
  required SurfaceId surfaceid = 1;
  // No name is interpreted as disabled cursor.
  optional string name = 2;
  // If we supply a buffer stream we must supply hotspot x and y
  optional BufferStreamId buffer_stream = 3;
  optional int32 hotspot_x = 4;
  optional int32 hotspot_y = 5;
}

message SocketFDRequest {
  required int32 number = 1;
  required int32 prompt_session_id = 2;
}

message SocketFD {
  repeated sint32 fd = 1;
  optional int32  fds_on_side_channel = 2;

  optional string error = 127;
  optional StructuredError structured_error = 128;
}

message PromptSessionParameters {
  required int32 application_pid = 1;
}

message PromptSession {
  optional int32 id = 1;

  optional string error = 127;
  optional StructuredError structured_error = 128;
}

message PlatformOperationMessage {
  optional uint32 opcode = 1;
  optional bytes data = 2;
  repeated sint32 fd = 3;
  optional int32  fds_on_side_channel = 4;

  optional string error = 127;
  optional StructuredError structured_error = 128;
}

message CoordinateTranslationRequest {
  required SurfaceId surfaceid = 1;
  required int32 x = 2;
  required int32 y = 3;
}

message CoordinateTranslationResponse {
  optional int32 x = 1;
  optional int32 y = 2;

  optional string error = 127;
  optional StructuredError structured_error = 128;
}

message Cookie {
  required bytes cookie = 1;
}

enum RequestOperation {
  UNKNOWN = 0;
  START_DRAG_AND_DROP = 1;
  MAKE_ACTIVE = 2;
  USER_MOVE = 3;
  USER_RESIZE = 4;
}

message RequestWithAuthority {
  required Cookie authority = 1;
  required SurfaceId surface_id = 2;
  required RequestOperation operation = 3;
  optional uint32 hint = 4;
}

message InputDevices {
  repeated InputDeviceInfo device_info = 1;
}

message InputDeviceInfo {
  optional int64 id = 1;
  optional uint32 capabilities = 2;
  optional string name = 3;
  optional string unique_id = 4;
  optional PointerConfiguration pointer_configuration = 5;
  optional TouchpadConfiguration touchpad_configuration = 6;
}

message PointerConfiguration {
  optional uint32 handedness = 1;
  optional uint32 acceleration = 2;
  optional double acceleration_bias = 3;
  optional double horizontal_scroll_scale = 4;
  optional double vertical_scroll_scale = 5;
}

message TouchpadConfiguration {
  optional uint32 click_modes = 1;
  optional uint32 scroll_modes = 2;
  optional int32 button_down_scroll_button = 3;
  optional uint32 tap_to_click = 4;
  optional uint32 middle_mouse_button_emulation = 5;
  optional uint32 disable_with_mouse = 6;
  optional uint32 disable_while_typing = 7;
}

message InputConfigurationRequest {
  optional string input_configuration = 1;
}
