summaryrefslogtreecommitdiffstats
path: root/waltham-transmitter/transmitter-plugin/input.c
blob: 9d35f3f3de910c0375fc369730f4c5dbcf0a0514 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
}
<?xml version="1.0" encoding="UTF-8"?>
<manifest>

  <!-- remote servers to query -->
  <remote name="agl"
         fetch="https://gerrit.automotivelinux.org/gerrit/"
         review="https://gerrit.automotivelinux.org/gerrit/"
         pushurl="ssh://gerrit.automotivelinux.org:29418"
  />
  <remote name="yocto" fetch="https://git.yoctoproject.org/git/" />
  <remote name="github" fetch="https://github.com/" />

  <!-- defaults -->
  <default remote="agl" sync-j="4" revision="refs/tags/icefish/8.99.5"/>


  <!-- CORE -->
  <!-- use agl revisions/branches here -->

  <!-- AGL things. -->
  <project name="AGL/meta-agl" path="meta-agl" />
  <project name="AGL/meta-agl-cluster-demo" path="meta-agl-cluster-demo" />
  <project name="AGL/meta-agl-demo" path="meta-agl-demo" />
  <project name="AGL/meta-agl-devel" path="meta-agl-devel" />
  <project name="AGL/meta-agl-extra" path="meta-agl-extra" />
  <project name="AGL/meta-agl-telematics-demo" path="meta-agl-telematics-demo" />


  <!-- ALL EXTERNAL REPOS BELOW USE A FIXED REVISION ! -->

  <!-- YOCTO & OE -->

  <!-- Yocto/OpenEmbedded things. -->
  <project name="poky" path="external/poky" remote="yocto" revision="51f6145f8f99a02df1dad937684f014b0172e72a" upstream="thud" />
  <project name="meta-gplv2" path="external/meta-gplv2" remote="yocto" revision="aabc30f3bd03f97326fb8596910b94639fea7575" upstream="thud" />
  <project name="openembedded/meta-openembedded" path="external/meta-openembedded" remote="github" revision="446bd615fd7cb9bc7a159fe5c2019ed08d1a7a93" upstream="thud" />


  <!-- UPSTREAM COMPONENTS -->

  <!-- meta-virtualization -->
  <project name="meta-virtualization" path="external/meta-virtualization" remote="yocto" revision="7685c7d415e0002c448007960837ae8898cd57a5" upstream="thud"/>

  <!-- Qt things -->
  <project name="meta-qt5/meta-qt5" path="external/meta-qt5" remote="github" revision="1520d5b2b2beec5e1c3209d3178219e93ef08bca" upstream="thud"/>

  <!-- Updater layers. -->
  <project name="advancedtelematic/meta-updater" path="external/meta-updater" remote="github" revision="e4dd74565f429b576e84972d12cc1ae2048be119" upstream="thud"/>
  <project name="advancedtelematic/meta-updater-qemux86-64" path="external/meta-updater-qemux86-64" remote="github" revision="214e14c4c45625842e542eebd696f903060d488f" upstream="thud"/>
  <project name="advancedtelematic/meta-updater-raspberrypi" path="external/meta-updater-raspberrypi" remote="github" revision="062194613515d4bf7d130f21ba3a0e1a2f0bb461" upstream="thud"/>

  <!-- Security layer -->
  <project name="meta-security" path="external/meta-security" remote="yocto" revision="31dc4e7532fa7a82060e0b50e5eb8d0414aa7e93" upstream="thud"/>

  <!-- SmartDeviceLink layer -->
  <project name="phongt/meta-sdl" path="external/meta-sdl" remote="github" revision="ab1e345171e799216b8fcb432943a2de5ff66f5f" upstream="thud"/>

  <!-- meta-spdxscanner - support for fossology -->
  <project name="dl9pf/meta-spdxscanner" path="external/meta-spdxscanner" remote="github" revision="a73c7581aa3076f2d21b3db754aacd85de3294ec" upstream="master"/>

  <!-- Alexa Auto SDK layer -->
  <project name="alexa/alexa-auto-sdk" path="external/alexa-auto-sdk" remote="github" revision="86916d2d8c1702a8be3c88a9012ca56583bcc0c8" upstream="2.0"/>


  <!-- BSPs -->

  <!-- Renesas Gen3 specific things -->
  <project name="AGL/meta-renesas-rcar-gen3" path="bsp/meta-renesas-rcar-gen3" />
  <project name="CogentEmbedded/meta-rcar" path="bsp/meta-rcar" remote="github" revision="e9bf7907fcf1f3013705de10a37b7561f6660e3c" upstream="thud-v3.21.0"/>

  <!-- MinnowBoard MAX specific things -->
  <project name="meta-intel" path="bsp/meta-intel" remote="yocto" revision="278f0b5fa2f1836635178bdc770e035d77ae03c7" upstream="thud"/>

  <!-- consolidate on meta-freescale from git.yoctoproject.org -->
  <project name="meta-freescale" path="bsp/meta-freescale" remote="yocto" revision="f5c932229c31b612cba38c2ed6f3c3ec6b800e92" upstream="thud"/>
  <project name="Freescale/meta-freescale-3rdparty" path="bsp/meta-freescale-3rdparty" remote="github" revision="c4b5ac6b20e4245ce0630e9197313aaef999a331" upstream="thud"/>

  <!-- Boundary devices bsp layer -->
  <project name="boundarydevices/meta-boundary" path="bsp/meta-boundary" remote="github" revision="4ea73c57f125ff0b8c3e17e5cc5d07b6168bbd6c" upstream="master"/>

  <!-- ti vayu / jacinto 6 / DRA7 -->
  <project name="meta-ti" path="bsp/meta-ti" remote="yocto" revision="727411f95ef1f66034beac08702f21b30a1b84c9" upstream="thud"/>

  <!-- rpi 2, 3 and 3 B+ -->
  <project name="meta-raspberrypi" path="bsp/meta-raspberrypi" remote="yocto" revision="4e5be97d75668804694412f9b86e9291edb38b9d" upstream="thud"/>

  <!-- DragonBoard 410c specific things -->
  <project name="meta-qcom" path="bsp/meta-qcom" remote="yocto" revision="d0a58e836444a7118acfc5a99d8cacaa5ae09f5c" upstream="thud"/>

  <!-- Altera SOCFPGA platform -->
  <!-- https://github.com/kraj/meta-altera -->
  <project name="kraj/meta-altera" path="bsp/meta-altera" remote="github" revision="8a1d00568078790dac6fc0d94ed199b850f3bb75" upstream="thud"/>

  <!-- Sancloud BSP layers -->
  <project name="SanCloudLtd/meta-sancloud" path="bsp/meta-sancloud" remote="github" revision="81c7f1bf9d0739892f72ff108474f3996f0a00b1" upstream="thud"/>
  <project name="EmbeddedAndroid/meta-rtlwifi" path="bsp/meta-rtlwifi" remote="github" revision="fd7ca0ca47c7095ced62a5a7cdef040dff87fb76" upstream="master"/>

  <!-- meta-synopsys - support for ARC HSDK board -->
  <project name="foss-for-synopsys-dwc-arc-processors/meta-synopsys" path="bsp/meta-synopsys" remote="github" revision="c4fb64eba16782524448c8287656b907633fd0ed" upstream="halibut-agl"/>

</manifest>
'n853' href='#n853'>853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
/*
 * Copyright (C) 2017 Advanced Driver Information Technology Joint Venture GmbH
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <stdlib.h>
#include <assert.h>
#include <string.h>

/* for fake stuff */
#include <math.h>

#include "compositor.h"

#include "plugin.h"
#include "transmitter_api.h"

/** @file
 *
 * This is an implementation of a remote input.
 *
 * Request wl_data_device_manager.get_data_device would need to be blocked,
 * except maybe it's not necessary, we just "forget" to forward data to/from
 * the remote wl_seat. It might still work inside the local compositor.
 *
 * weston_compositor_set_default_pointer_grab() will break our pointer
 * implementation, but no in-tree code is calling it.
 */

/* XXX: all functions and variables with a name, and things marked with a
 * comment, containing the word "fake" are mockups that need to be
 * removed from the final implementation.
 */

static void
pointer_focus_grab_handler(struct weston_pointer_grab *grab)
{
	/* No-op:
	 *
	 * Weston internal events do not change the focus.
	 */
}

static void
pointer_motion_grab_handler(struct weston_pointer_grab *grab,
			    uint32_t time,
			    struct weston_pointer_motion_event *event)
{
	weston_log("Unexpected! %s(pointer=%p, ...)\n",
		   __func__, grab->pointer);
}

static void
pointer_button_grab_handler(struct weston_pointer_grab *grab,
			    uint32_t time,
			    uint32_t button,
			    uint32_t state)
{
	weston_log("Unexpected! %s(pointer=%p, ...)\n",
		   __func__, grab->pointer);
}

static void
pointer_axis_grab_handler(struct weston_pointer_grab *grab,
			  uint32_t time,
			  struct weston_pointer_axis_event *event)
{
	weston_log("Unexpected! %s(pointer=%p, ...)\n",
		   __func__, grab->pointer);
}

static void
pointer_axis_source_grab_handler(struct weston_pointer_grab *grab,
				 uint32_t source)
{
	weston_log("Unexpected! %s(pointer=%p, ...)\n",
		   __func__, grab->pointer);
}

static void
pointer_frame_grab_handler(struct weston_pointer_grab *grab)
{
	weston_log("Unexpected! %s(pointer=%p, ...)\n",
		   __func__, grab->pointer);
}

static void
pointer_cancel_grab_handler(struct weston_pointer_grab *grab)
{
	weston_log("Unexpected! %s(pointer=%p, ...)\n",
		   __func__, grab->pointer);
}

/* These handlers would be called from the notify_*() functions in src/input.c.
 * However, as we do not use the low level input notify_*() functions that
 * backends drive, these are mostly uncalled, except the focus handler which
 * weston core generates internally.
 */
static const struct weston_pointer_grab_interface pointer_grab_impl = {
	pointer_focus_grab_handler,
	pointer_motion_grab_handler,
	pointer_button_grab_handler,
	pointer_axis_grab_handler,
	pointer_axis_source_grab_handler,
	pointer_frame_grab_handler,
	pointer_cancel_grab_handler,
};

static void
keyboard_grab_key(struct weston_keyboard_grab *grab,
		  uint32_t time,
		  uint32_t key,
		  uint32_t state)
{
}

static void
keyboard_grab_modifiers(struct weston_keyboard_grab *grab,
			uint32_t serial,
			uint32_t mods_depressed,
			uint32_t mods_latched,
			uint32_t mods_locked,
			uint32_t group)
{
}

static void
keyboard_grab_cancel(struct weston_keyboard_grab *grab)
{
}

static const struct weston_keyboard_grab_interface keyborad_grab_impl = {
	keyboard_grab_key,
	keyboard_grab_modifiers,
	keyboard_grab_cancel
};

static void
touch_grab_down_handler(struct weston_touch_grab *grab,
			uint32_t time,
			int touch_id,
			wl_fixed_t x,
			wl_fixed_t y)
{
}

static void
touch_grab_up_handler(struct weston_touch_grab *grab,
		      uint32_t time,
		      int touch_id)
{
}

static void
touch_grab_motion_handler(struct weston_touch_grab *grab,
			  uint32_t time,
			  int touch_id,
			  wl_fixed_t x,
			  wl_fixed_t y)
{
}

static void
touch_grab_frame_handler(struct weston_touch_grab *grab)
{
}

static void
touch_grab_cancel_handler(struct weston_touch_grab *grab)
{
}

static const struct weston_touch_grab_interface touch_grab_impl = {
	touch_grab_down_handler,
	touch_grab_up_handler,
	touch_grab_motion_handler,
	touch_grab_frame_handler,
	touch_grab_cancel_handler,
};


/* The different ways to get pointer focus on a remoted surface:
 *
 * 1. Transmitter seat has pointer. The client has wl_pointer. Transmitter
 *    receives pointer.enter. (transmitter_seat_pointer_enter())
 *
 * 2. Transmitter seat has pointer. Transmitter has received pointer.enter.
 *    The client calls wl_seat.get_pointer. => send enter only on the new
 *    wl_pointer. (seat_get_pointer_handler())
 *
 * 3. Client has wl_pointer. Transmitter seat adds pointer capability.
 *    Transmitter receives pointer.enter. wl_pointer MUST NOT enter,
 *    specified by wl_seat.capabilities.
 *
 * By definition, Transmitter cannot receive pointer.enter without having
 * pointer capability in the seat, so no other combinations are possible.
 *
 * The same applies to wl_keyboard and wl_touch.
 */

/* Implementor notes:
 *
 * The handling of all of wl_pointer, wl_keyboard and wl_touch should be
 * similar. To make it work, we need to add a signal to each of the
 * wl_seat.get_pointer, wl_seat.get_keyboard, and wl_seat.get_touch request
 * handlers in Weston core. Otherwise we cannot implement the case 2 of gaining
 * input device focus.
 *
 * However, weston_keyboard::focus is a weston_surface, not a weston_view, so
 * we may be able to leverage more of the core implementation and maybe do
 * without the wl_seat.get_keyboard signal. Weston_touch uses a weston_view, so
 * that is similar to weston_pointer.
 *
 * It might be useful to convert weston_keyboard and weston_touch to use a
 * similar thing as weston_pointer_client, in case it makes things more
 * consistent. It might also fix issues when a client has multiple copies of a
 * wl_keyboard or a wl_touch, but that is getting off-topic.
 *
 * This file shows which part of the Weston input path we skip and where we
 * hook in. We skip everything starting from the notify_*() API used by
 * backends, and stub out the grab handlers. Instead of actual grab handlers,
 * we have our own network protocol events handlers. They do much of the same
 * as normal grab handlers would do, except focus is pre-given, and we do not
 * have weston_view for the focus surfaces, so we need to bypass core code
 * dealing with those.
 *
 * Our remote seat implementation will leave many struct members unused and
 * replicate some from weston_pointer, weston_keyboard, and weston_touch.
 * Weston core must be kept out from the focus handling business, because we
 * will send enter/leave events ourselves, and focus assignments are given
 * to us from the remote, they cannot be changed at will by the local Weston.
 */

/** Callback from the protocol request handler for wl_seat.get_pointer
 *
 * The Weston core handler never sees focus set on the weston_pointer,
 * so it won't send wl_pointer.enter nor set focus_client. It does call
 * weston_pointer_ensure_pointer_client() though.
 */
static void
seat_get_pointer_handler(struct wl_listener *listener, void *data)
{
	struct wl_resource *new_pointer = data;
	struct weston_transmitter_seat *seat;
	struct wl_resource *surface;
	struct weston_pointer_client *pointer_client;
	struct wl_client *client;
	struct weston_pointer *pointer;

	seat = wl_container_of(listener, seat, get_pointer_listener);
	if (!seat->pointer_focus)
		return;

	client = wl_resource_get_client(new_pointer);
	surface = seat->pointer_focus->surface->resource;

	if (wl_resource_get_client(surface) != client)
		return;

	pointer = weston_seat_get_pointer(seat->base);
	assert(pointer); /* guaranteed by having pointer_focus */
	pointer_client = weston_pointer_get_pointer_client(pointer, client);

	if (!pointer->focus_client)
		pointer->focus_client = pointer_client;
	else
		assert(pointer->focus_client == pointer_client);

	wl_pointer_send_enter(new_pointer, pointer->focus_serial, surface,
			      seat->pointer_surface_x, seat->pointer_surface_y);

	if (wl_resource_get_version(new_pointer) >=
	    WL_POINTER_FRAME_SINCE_VERSION)
		wl_pointer_send_frame(new_pointer);
}

static void
transmitter_seat_create_pointer(struct weston_transmitter_seat *seat)
{
	struct weston_pointer *pointer;

	seat->pointer_phase = 0.0;
	seat->pointer_surface_x = wl_fixed_from_int(-1000000);
	seat->pointer_surface_y = wl_fixed_from_int(-1000000);
	seat->pointer_focus = NULL;
	wl_list_init(&seat->pointer_focus_destroy_listener.link);

	weston_seat_init_pointer(seat->base);

	pointer = weston_seat_get_pointer(seat->base);

	/* not exported:
	 * weston_pointer_set_default_grab(pointer, &pointer_grab_impl); */
	pointer->default_grab.interface = &pointer_grab_impl;

	/* Changes to local outputs are irrelevant. */
	wl_list_remove(&pointer->output_destroy_listener.link);
	wl_list_init(&pointer->output_destroy_listener.link);

	weston_log("Transmitter created pointer=%p for seat %p\n",
		   pointer, seat->base);
}

static void
seat_pointer_focus_destroy_handler(struct wl_listener *listener, void *data)
{
	struct weston_transmitter_surface *txs = data;
	struct weston_transmitter_seat *seat;

	seat = wl_container_of(listener, seat, pointer_focus_destroy_listener);
	assert(seat->pointer_focus == txs);

	seat->pointer_focus = NULL;
}

void
transmitter_seat_pointer_enter(struct weston_transmitter_seat *seat,
			       uint32_t serial,
			       struct weston_transmitter_surface *txs,
			       wl_fixed_t surface_x,
			       wl_fixed_t surface_y)
{
	struct wl_client *client;
	struct weston_pointer *pointer;
	struct wl_list *focus_resource_list;
	struct wl_resource *resource;

	pointer = weston_seat_get_pointer(seat->base);
	assert(pointer);

	assert(txs->surface);
	client = wl_resource_get_client(txs->surface->resource);

	seat->pointer_focus = txs;
	seat->pointer_focus_destroy_listener.notify =
		seat_pointer_focus_destroy_handler;
	wl_signal_add(&txs->destroy_signal,
		      &seat->pointer_focus_destroy_listener);

	/* If pointer-focus gets destroyed, txs will get destroyed, the
	 * remote surface object is destroyed, and the remote will send a
	 * leave and a frame.
	 */

	seat->pointer_surface_x = surface_x;
	seat->pointer_surface_y = surface_y;

	pointer->focus_serial = serial;

	/* pointer->focus is not used, because it is a weston_view, while
	 * remoted surfaces have no views.
	 *
	 * pointer->x,y are not used because they are in global coordinates.
	 * Remoted surfaces are not in the global space at all, so there are
	 * no such coordinates.
	 */

	if (!pointer->focus_client)
		return;

	focus_resource_list = &pointer->focus_client->pointer_resources;
	wl_resource_for_each(resource, focus_resource_list) {
		wl_pointer_send_enter(resource,
				      serial,
				      txs->surface->resource,
				      surface_x, surface_y);
	}
}

void
transmitter_seat_pointer_leave(struct weston_transmitter_seat *seat,
			       uint32_t serial,
			       struct weston_transmitter_surface *txs)
{
	struct weston_pointer *pointer;
	struct wl_list *focus_resource_list;
	struct wl_resource *surface_resource;
	struct wl_resource *resource;

	if (txs != seat->pointer_focus) {
		weston_log("Transmitter Warning: pointer leave for %p, expected %p\n",
			   txs, seat->pointer_focus);
	}

	seat->pointer_focus = NULL;
	wl_list_remove(&seat->pointer_focus_destroy_listener.link);
	wl_list_init(&seat->pointer_focus_destroy_listener.link);

	if (!txs)
		return;
	assert(txs->surface);
	surface_resource = txs->surface->resource;

	pointer = weston_seat_get_pointer(seat->base);
	assert(pointer);
	if (!pointer->focus_client)
		return;

	focus_resource_list = &pointer->focus_client->pointer_resources;
	wl_resource_for_each(resource, focus_resource_list)
		wl_pointer_send_leave(resource, serial, surface_resource);

	/* Do not reset pointer->focus_client, because we need to be able
	 * to send a following 'frame' event in
	 * transmitter_seat_pointer_frame().
	 */
}

void
transmitter_seat_pointer_motion(struct weston_transmitter_seat *seat,
				uint32_t time,
				wl_fixed_t surface_x,
				wl_fixed_t surface_y)
{
	struct weston_pointer *pointer;
	struct wl_list *focus_resource_list;
	struct wl_resource *resource;
	struct weston_transmitter_surface *txs;

	pointer = weston_seat_get_pointer(seat->base);
	assert(pointer);

	seat->pointer_surface_x = surface_x;
	seat->pointer_surface_y = surface_y;

	if (!pointer->focus_client)
		return;

	txs = seat->pointer_focus;
	if (txs)
		assert(wl_resource_get_client(txs->surface->resource) ==
		       pointer->focus_client->client);

	focus_resource_list = &pointer->focus_client->pointer_resources;
	wl_resource_for_each(resource, focus_resource_list) {
		wl_pointer_send_motion(resource, time,
				       surface_x, surface_y);
	}
}

void
transmitter_seat_pointer_button(struct weston_transmitter_seat *seat,
				uint32_t serial,
				uint32_t time,
				uint32_t button,
				uint32_t state)
{
	struct weston_pointer *pointer;
	struct wl_list *focus_resource_list;
	struct wl_resource *resource;
	struct weston_transmitter_surface *txs;

	pointer = weston_seat_get_pointer(seat->base);
	assert(pointer);

	if (!pointer->focus_client)
		return;

	txs = seat->pointer_focus;
	if (txs)
		assert(wl_resource_get_client(txs->surface->resource) ==
		       pointer->focus_client->client);

	focus_resource_list = &pointer->focus_client->pointer_resources;
	wl_resource_for_each(resource, focus_resource_list) {
		wl_pointer_send_button(resource, serial, time,
				       button, state);
        }
}

void
transmitter_seat_pointer_axis(struct weston_transmitter_seat *seat,
			      uint32_t time,
			      uint32_t axis,
			      wl_fixed_t value)
{
	struct weston_pointer *pointer;
	struct wl_list *focus_resource_list;
	struct wl_resource *resource;
	struct weston_transmitter_surface *txs;

	pointer = weston_seat_get_pointer(seat->base);
	assert(pointer);

	if (!pointer->focus_client)
		return;

	txs = seat->pointer_focus;
	if (txs)
		assert(wl_resource_get_client(txs->surface->resource) ==
		       pointer->focus_client->client);

	focus_resource_list = &pointer->focus_client->pointer_resources;
	wl_resource_for_each(resource, focus_resource_list) {
		wl_pointer_send_axis(resource, time,
				     axis, value);
	}
}

void
transmitter_seat_pointer_frame(struct weston_transmitter_seat *seat)
{
	struct weston_pointer *pointer;

	pointer = weston_seat_get_pointer(seat->base);
	if (pointer)
		weston_pointer_send_frame(pointer);
}

void
transmitter_seat_pointer_axis_source(struct weston_transmitter_seat *seat,
				     uint32_t axis_source)
{
	/* ToDo : implement axis event handling */
}

void
transmitter_seat_pointer_axis_stop(struct weston_transmitter_seat *seat,
				   uint32_t time,
				   uint32_t axis)
{
	/* ToDo : implement axis event handling */
}

void
transmitter_seat_pointer_axis_discrete(struct weston_transmitter_seat *seat,
				       uint32_t axis,
				       int32_t discrete)
{
	/* ToDo : implement axis event handling */
}

static void
transmitter_seat_create_keyboard(struct weston_transmitter_seat *seat)
{
	struct weston_keyboard *keyboard;

	seat->keyboard_focus = NULL;
	weston_seat_init_keyboard(seat->base, NULL);

	keyboard = weston_seat_get_keyboard(seat->base);

	keyboard->default_grab.interface = &keyborad_grab_impl;

	weston_log("Transmitter created keyboard=%p for seat %p\n",
		   keyboard, seat->base);
}

static void
transmitter_seat_keyboard_enter(struct weston_transmitter_seat *seat,
				uint32_t serial,
				struct weston_transmitter_surface *txs,
				struct wl_array *keys)
{
	struct weston_keyboard *keyboard;
	struct wl_resource *resource = NULL;
	struct wl_resource *surface_resource;

	keyboard = weston_seat_get_keyboard(seat->base);
	assert(keyboard);

	assert(txs->surface);
	surface_resource = txs->surface->resource;

	seat->keyboard_focus = txs;
	wl_array_copy(&keyboard->keys, keys);

	wl_resource_for_each(resource, &keyboard->resource_list) {
		if (wl_resource_get_client(resource) == wl_resource_get_client(surface_resource)) {
			wl_keyboard_send_enter(resource,
					       serial,
					       surface_resource,
					       &keyboard->keys);
		}
	}
}

static void
transmitter_seat_keyboard_leave(struct weston_transmitter_seat *seat,
				uint32_t serial,
				struct weston_transmitter_surface *txs)
{
	struct weston_keyboard *keyboard;
	struct wl_resource *resource = NULL;
	struct wl_resource *surface_resource;

	keyboard = weston_seat_get_keyboard(seat->base);
	assert(keyboard);

	assert(txs->surface);
	surface_resource = txs->surface->resource;

	wl_resource_for_each(resource, &keyboard->resource_list) {
		if (wl_resource_get_client(resource) == wl_resource_get_client(surface_resource)) {
			wl_keyboard_send_leave(resource,
					       serial,
					       surface_resource);
		}
	}
}

static void
transmitter_seat_keyboard_key(struct weston_transmitter_seat *seat,
	uint32_t serial,
	uint32_t time,
	uint32_t key,
	uint32_t state)
{
	struct weston_keyboard *keyboard;
	struct wl_resource *resource = NULL;

	keyboard = weston_seat_get_keyboard(seat->base);
	assert(keyboard);

	wl_resource_for_each(resource, &keyboard->resource_list) {
		if (wl_resource_get_client(resource) ==
		    wl_resource_get_client(seat->keyboard_focus->surface->resource)) {
			wl_keyboard_send_key(resource,
					     serial,
					     time,
					     key,
					     state);
		}
	}
}

static void
transmitter_seat_create_touch(struct weston_transmitter_seat *seat)
{
	struct weston_touch *touch;

	seat->touch_focus = NULL;
	weston_seat_init_touch(seat->base);

	touch = weston_seat_get_touch(seat->base);

	touch->default_grab.interface = &touch_grab_impl;

	weston_log("Transmitter created touch=%p for seat %p\n",
		   touch, seat->base);
}

static void
transmitter_seat_touch_down (struct weston_transmitter_seat *seat,
			     uint32_t serial,
			     uint32_t time,
			     struct weston_transmitter_surface *txs,
			     int32_t touch_id,
			     wl_fixed_t x,
			     wl_fixed_t y)
{
	struct weston_touch *touch;
	struct wl_resource *resource = NULL;
	struct wl_resource *surface_resource;

	touch = weston_seat_get_touch(seat->base);
	assert(touch);

	assert(txs->surface);
	surface_resource = txs->surface->resource;

	seat->touch_focus = txs;

	wl_resource_for_each(resource, &touch->resource_list) {
		if (wl_resource_get_client(resource) == wl_resource_get_client(surface_resource)) {
			wl_touch_send_down(resource, serial, time,
					   surface_resource,
					   touch_id, x, y);
		}
	}
}

static void
transmitter_seat_touch_up (struct weston_transmitter_seat *seat,
			   uint32_t serial,
			   uint32_t time,
			   int32_t touch_id)
{
	struct weston_touch *touch;
	struct wl_resource *resource = NULL;

	touch = weston_seat_get_touch(seat->base);
	assert(touch);

	wl_resource_for_each(resource, &touch->resource_list) {
		if (wl_resource_get_client(resource) ==
		    wl_resource_get_client(seat->touch_focus->surface->resource)) {
			wl_touch_send_up(resource, serial, time, touch_id);
		}
	}
}

static void
transmitter_seat_touch_motion (struct weston_transmitter_seat *seat,
			       uint32_t time,
			       int32_t touch_id,
			       wl_fixed_t x,
			       wl_fixed_t y)
{
	struct weston_touch *touch;
	struct wl_resource *resource = NULL;

	touch = weston_seat_get_touch(seat->base);
	assert(touch);

	wl_resource_for_each(resource, &touch->resource_list) {
		if (wl_resource_get_client(resource) ==
		    wl_resource_get_client(seat->touch_focus->surface->resource)) {
			wl_touch_send_motion(resource, time, touch_id, x, y);
		}
	}
}

static void
transmitter_seat_touch_frame (struct weston_transmitter_seat *seat)
{
	struct weston_touch *touch;
	struct wl_resource *resource = NULL;

	touch = weston_seat_get_touch(seat->base);
	assert(touch);

	wl_resource_for_each(resource, &touch->resource_list) {
		if (wl_resource_get_client(resource) ==
		    wl_resource_get_client(seat->touch_focus->surface->resource)) {
			wl_touch_send_frame(resource);
		}
	}
}

static void
transmitter_seat_touch_cancel (struct weston_transmitter_seat *seat)
{
	struct weston_touch *touch;
	struct wl_resource *resource = NULL;

	touch = weston_seat_get_touch(seat->base);
	assert(touch);

	wl_resource_for_each(resource, &touch->resource_list) {
		if (wl_resource_get_client(resource) ==
		    wl_resource_get_client(seat->touch_focus->surface->resource)) {
			wl_touch_send_cancel(resource);
		}
	}
}

static char *
make_seat_name(struct weston_transmitter_remote *remote, const char *name)
{
	char *str;

	if (asprintf(&str, "transmitter-%s-%s", remote->addr, name) < 0)
		return NULL;

	return str;
}

void
transmitter_seat_destroy(struct weston_transmitter_seat *seat)
{
	wl_list_remove(&seat->link);

	weston_log("Transmitter destroy seat=%p\n", seat->base);

	wl_list_remove(&seat->get_pointer_listener.link);
	wl_list_remove(&seat->pointer_focus_destroy_listener.link);

	if (seat->pointer_timer)
		wl_event_source_remove(seat->pointer_timer);

	free(seat);
}

static void
pointer_handle_enter(struct wthp_pointer *wthp_pointer,
		     uint32_t serial,
		     struct wthp_surface *surface,
		     wth_fixed_t surface_x,
		     wth_fixed_t surface_y)
{
	struct waltham_display *dpy =
		wth_object_get_user_data((struct wth_object *)wthp_pointer);
	struct weston_transmitter_remote *remote = dpy->remote;
	struct wl_list *seat_list = &remote->seat_list;
	struct weston_transmitter_seat *seat;
	struct weston_transmitter_surface *txs;

	seat = wl_container_of(seat_list->next, seat, link);

	wl_list_for_each(txs, &remote->surface_list, link)
	{
		if (txs->wthp_surf == surface) {
			if (txs != seat->pointer_focus)
				transmitter_seat_pointer_leave(seat, serial, seat->pointer_focus);
			transmitter_seat_pointer_enter(seat, serial, txs,
						       surface_x, surface_y);
		}
	}
}

static void
pointer_handle_leave(struct wthp_pointer *wthp_pointer,
		     uint32_t serial,
		     struct wthp_surface *surface)
{
	struct waltham_display *dpy =
		wth_object_get_user_data((struct wth_object *)wthp_pointer);
	struct weston_transmitter_remote *remote = dpy->remote;
	struct wl_list *seat_list = &remote->seat_list;
	struct weston_transmitter_seat *seat;
	struct weston_transmitter_surface *txs;

	seat = wl_container_of(seat_list->next, seat, link);

	wl_list_for_each(txs, &remote->surface_list, link)
	{
		if (txs->wthp_surf == surface) {
			transmitter_seat_pointer_leave(seat, serial, txs);
		}
	}
}

static void
pointer_handle_motion(struct wthp_pointer *wthp_pointer,
		      uint32_t time,
		      wth_fixed_t surface_x,
		      wth_fixed_t surface_y)
{
	struct waltham_display *dpy =
		wth_object_get_user_data((struct wth_object *)wthp_pointer);
	struct weston_transmitter_remote *remote = dpy->remote;
	struct wl_list *seat_list = &remote->seat_list;
	struct weston_transmitter_seat *seat;

	seat = wl_container_of(seat_list->next, seat, link);

	transmitter_seat_pointer_motion(seat, time,
					surface_x,
					surface_y);
}

static void
pointer_handle_button(struct wthp_pointer *wthp_pointer,
		      uint32_t serial,
		      uint32_t time,
		      uint32_t button,
		      uint32_t state)
{
	struct waltham_display *dpy =
		wth_object_get_user_data((struct wth_object *)wthp_pointer);
	struct weston_transmitter_remote *remote = dpy->remote;
	struct wl_list *seat_list = &remote->seat_list;
	struct weston_transmitter_seat *seat;

	seat = wl_container_of(seat_list->next, seat, link);

	transmitter_seat_pointer_button(seat, serial,
					time, button,
					state);
}

static void
pointer_handle_axis(struct wthp_pointer *wthp_pointer,
		    uint32_t time,
		    uint32_t axis, wth_fixed_t value)
{
	struct waltham_display *dpy =
		wth_object_get_user_data((struct wth_object *)wthp_pointer);
	struct weston_transmitter_remote *remote = dpy->remote;
	struct wl_list *seat_list = &remote->seat_list;
	struct weston_transmitter_seat *seat;

	seat = wl_container_of(seat_list->next, seat, link);

	transmitter_seat_pointer_axis(seat, time,
				      axis, value);
}

static void
pointer_handle_frame(struct wthp_pointer *wthp_pointer)
{
	/* ToDo : implement pointer handle frame */
}

static void
pointer_handle_axis_source(struct wthp_pointer *wthp_pointer,
			   uint32_t axis_source)
{
	/* ToDo : implement pointer handle axis source */
}

static void
pointer_handle_axis_stop(struct wthp_pointer *wthp_pointer,
			 uint32_t time,
			 uint32_t axis)
{
	/* ToDo : implement pointer handle axis stop */
}

static void
pointer_handle_axis_discrete(struct wthp_pointer *wthp_pointer,
			     uint32_t axis,
			     int32_t discrete)
{
	/* ToDo : implement pointer handle axis discrete */
}

static const struct wthp_pointer_listener pointer_listener = {
	pointer_handle_enter,
	pointer_handle_leave,
	pointer_handle_motion,
	pointer_handle_button,
	pointer_handle_axis,
	pointer_handle_frame,
	pointer_handle_axis_source,
	pointer_handle_axis_stop,
	pointer_handle_axis_discrete
};

static void
keyboard_handle_keymap(struct wthp_keyboard * wthp_keyboard,
	uint32_t format,
	uint32_t keymap_sz,
	void * keymap)
{
	/* ToDo : implement keyboard handle keymap */
}

static void
keyboard_handle_enter(struct wthp_keyboard *wthp_keyboard,
	uint32_t serial,
	struct wthp_surface *surface,
	struct wth_array *keys)
{
	struct waltham_display *dpy =
		wth_object_get_user_data((struct wth_object *)wthp_keyboard);
	struct weston_transmitter_remote *remote = dpy->remote;
	struct wl_list *seat_list = &remote->seat_list;
	struct weston_transmitter_seat *seat;
	struct weston_transmitter_surface *txs;
	struct wl_array *wl_key = (struct wl_array *)malloc(sizeof(struct wl_array));

	wl_key->size = keys->size;
	wl_key->alloc = keys->alloc;
	wl_key->data = keys->data;

	seat = wl_container_of(seat_list->next, seat, link);

	wl_list_for_each(txs, &remote->surface_list, link)
	{
		if (txs->wthp_surf == surface) {
			//transmitter_seat_keyboard_enter(seat, serial, txs, keys);
			transmitter_seat_keyboard_enter(seat, serial, txs, wl_key);
		}
	}
	free(wl_key);
}

static void
keyboard_handle_leave(struct wthp_keyboard *wthp_keyboard,
	uint32_t serial,
	struct wthp_surface *surface)
{
	struct waltham_display *dpy =
		wth_object_get_user_data((struct wth_object *)wthp_keyboard);
	struct weston_transmitter_remote *remote = dpy->remote;
	struct wl_list *seat_list = &remote->seat_list;
	struct weston_transmitter_seat *seat;
	struct weston_transmitter_surface *txs;

	seat = wl_container_of(seat_list->next, seat, link);

	wl_list_for_each(txs, &remote->surface_list, link)
	{
		if (txs->wthp_surf == surface) {
			transmitter_seat_keyboard_leave(seat, serial, txs);
		}
	}
}

static void
keyboard_handle_key(struct wthp_keyboard *wthp_keyboard,
	uint32_t serial,
	uint32_t time,
	uint32_t key,
	uint32_t state)
{
	struct waltham_display *dpy =
		wth_object_get_user_data((struct wth_object *)wthp_keyboard);
	struct weston_transmitter_remote *remote = dpy->remote;
	struct wl_list *seat_list = &remote->seat_list;
	struct weston_transmitter_seat *seat;

	seat = wl_container_of(seat_list->next, seat, link);

	transmitter_seat_keyboard_key(seat, serial, time, key, state);
}

static void
keyboard_handle_modifiers(struct wthp_keyboard *wthp_keyboard,
	uint32_t serial,
	uint32_t mods_depressed,
	uint32_t mods_latched,
	uint32_t mods_locked,
	uint32_t group)
{
	weston_log("keyboard_handle_modifiers\n");
}

static void
keyboard_handle_repeat_info(struct wthp_keyboard *wthp_keyboard,
	int32_t rate,
	int32_t delay)
{
	weston_log("keyboard_handle_repeat_info\n");
}

static const struct wthp_keyboard_listener keyboard_listener = {
	keyboard_handle_keymap,
	keyboard_handle_enter,
	keyboard_handle_leave,
	keyboard_handle_key,
	keyboard_handle_modifiers,
	keyboard_handle_repeat_info
};

static void
touch_handle_down (struct wthp_touch * wthp_touch,
		   uint32_t serial,
		   uint32_t time,
		   struct wthp_surface * surface,
		   int32_t id,
		   wth_fixed_t x,
		   wth_fixed_t y)
{
	struct waltham_display *dpy =
		wth_object_get_user_data((struct wth_object *)wthp_touch);
	struct weston_transmitter_remote *remote = dpy->remote;
	struct wl_list *seat_list = &remote->seat_list;
	struct weston_transmitter_seat *seat;
	struct weston_transmitter_surface *txs;

	seat = wl_container_of(seat_list->next, seat, link);

	wl_list_for_each(txs, &remote->surface_list, link)
	{
		if (txs->wthp_surf == surface) {
			transmitter_seat_touch_down(seat, serial, time,
						    txs, id, x, y);
		}
	}
}

static void
touch_handle_up (struct wthp_touch * wthp_touch,
		 uint32_t serial,
		 uint32_t time,
		 int32_t id)
{
	struct waltham_display *dpy =
		wth_object_get_user_data((struct wth_object *)wthp_touch);
	struct weston_transmitter_remote *remote = dpy->remote;
	struct wl_list *seat_list = &remote->seat_list;
	struct weston_transmitter_seat *seat;

	seat = wl_container_of(seat_list->next, seat, link);

	transmitter_seat_touch_up(seat, serial, time, id);
}

static void
touch_handle_motion (struct wthp_touch * wthp_touch,
		     uint32_t time,
		     int32_t id,
		     wth_fixed_t x,
		     wth_fixed_t y)
{
	struct waltham_display *dpy =
		wth_object_get_user_data((struct wth_object *)wthp_touch);
	struct weston_transmitter_remote *remote = dpy->remote;
	struct wl_list *seat_list = &remote->seat_list;
	struct weston_transmitter_seat *seat;

	seat = wl_container_of(seat_list->next, seat, link);

	transmitter_seat_touch_motion(seat, time, id, x, y);
}


static void
touch_handle_frame (struct wthp_touch * wthp_touch)
{
	struct waltham_display *dpy =
		wth_object_get_user_data((struct wth_object *)wthp_touch);
	struct weston_transmitter_remote *remote = dpy->remote;
	struct wl_list *seat_list = &remote->seat_list;
	struct weston_transmitter_seat *seat;

	seat = wl_container_of(seat_list->next, seat, link);

	transmitter_seat_touch_frame(seat);
}

static void
touch_handle_cancel (struct wthp_touch * wthp_touch)
{
	struct waltham_display *dpy =
		wth_object_get_user_data((struct wth_object *)wthp_touch);
	struct weston_transmitter_remote *remote = dpy->remote;
	struct wl_list *seat_list = &remote->seat_list;
	struct weston_transmitter_seat *seat;

	seat = wl_container_of(seat_list->next, seat, link);

	transmitter_seat_touch_cancel(seat);
}


static const struct wthp_touch_listener touch_listener = {
	touch_handle_down,
	touch_handle_up,
	touch_handle_motion,
	touch_handle_frame,
	touch_handle_cancel
};

void
seat_capabilities(struct wthp_seat *wthp_seat,
		  enum wthp_seat_capability caps)
{
	struct waltham_display *dpy = wth_object_get_user_data((struct wth_object *)wthp_seat);

	weston_log("seat_capabilities\n");

	if ((caps & WTHP_SEAT_CAPABILITY_POINTER) && !dpy->pointer)
	{
		weston_log("WTHP_SEAT_CAPABILITY_POINTER\n");
		dpy->pointer = wthp_seat_get_pointer(dpy->seat);
		wthp_pointer_set_listener(dpy->pointer, &pointer_listener, dpy);
	}
	if ((caps & WTHP_SEAT_CAPABILITY_KEYBOARD) && !dpy->keyboard)
	{
		weston_log("WTHP_SEAT_CAPABILITY_KEYBOARD\n");
		dpy->keyboard = wthp_seat_get_keyboard(dpy->seat);
		wthp_keyboard_set_listener(dpy->keyboard, &keyboard_listener, dpy);
	}
	if ((caps & WTHP_SEAT_CAPABILITY_TOUCH) && !dpy->touch)
	{
		weston_log("WTHP_SEAT_CAPABILITY_TOUCH\n");
		dpy->touch = wthp_seat_get_touch(dpy->seat);
		wthp_touch_set_listener(dpy->touch, &touch_listener, dpy);
	}
}

int
transmitter_remote_create_seat(struct weston_transmitter_remote *remote)
{
	struct weston_transmitter_seat *seat = NULL;
	char *name = NULL;
	struct weston_seat *weston_seat = NULL;

	seat = zalloc(sizeof *seat);
	if (!seat)
		goto fail;

	wl_list_init(&seat->get_pointer_listener.link);
	wl_list_init(&seat->pointer_focus_destroy_listener.link);

	/* XXX: get the name from remote */
	name = make_seat_name(remote, "default");
	if (!name)
		goto fail;


	if (wl_list_empty(&remote->transmitter->compositor->seat_list)) {
		weston_seat = zalloc(sizeof *weston_seat);
		if (!weston_seat)
			goto fail;

		weston_seat_init(weston_seat, remote->transmitter->compositor, name);
		seat->base = weston_seat;
		weston_log("Transmitter created seat=%p \n", &seat->base);
	} else {
		wl_list_for_each(weston_seat, &remote->transmitter->compositor->seat_list, link) {
			weston_log("Transmitter weston_seat %p\n", weston_seat);
			seat->base = weston_seat;
		}
	}

	free(name);
#if DEBUG
	weston_seat_init(&seat->base, remote->transmitter->compositor, name);
	free(name);

	/* Hide the weston_seat from the rest of Weston, there are too many
	 * things making assumptions:
	 * - backends assume they control all seats
	 * - shells assume they control all input foci
	 * We do not want either to mess with our seat.
	 */
	wl_list_remove(&seat->base.link);
	wl_list_init(&seat->base.link);

	/* The weston_compositor::seat_created_signal has already been
	 * emitted. Shells use it to subscribe to focus changes, but we should
	 * never handle focus with weston core... except maybe with keyboard.
	 * text-backend.c will also act on the new seat.
	 * It is possible weston_seat_init() needs to be split to fix this
	 * properly.
	 */

	weston_log("Transmitter created seat=%p '%s'\n",
		   &seat->base, seat->base.seat_name);
#endif

	/* XXX: mirror remote capabilities */
	transmitter_seat_create_pointer(seat);
	transmitter_seat_create_keyboard(seat);
	transmitter_seat_create_touch(seat);

	wl_list_insert(&remote->seat_list, &seat->link);

	return 0;

fail:
	free(seat);
	free(name);

	return -1;
}

static void
fake_pointer_get_position(struct weston_transmitter_seat *seat, double step,
			  wl_fixed_t *x, wl_fixed_t *y)
{
	double s, c;

	seat->pointer_phase += step;
	while (seat->pointer_phase > 2.0 * M_PI)
		seat->pointer_phase -= 2.0 * M_PI;

	sincos(seat->pointer_phase, &s, &c);
	*x = wl_fixed_from_double(100.0 + 50.0 * c);
	*y = wl_fixed_from_double(100.0 + 50.0 * s);
}

static int
fake_pointer_timer_handler(void *data)
{
	struct weston_transmitter_seat *seat = data;
	wl_fixed_t x, y;
	uint32_t time;
	struct timespec timespec;

	weston_compositor_get_time(&timespec);
	time=timespec.tv_sec * 1000 + timespec.tv_nsec / 1000000;

	fake_pointer_get_position(seat, 18.0 / 180.0 * M_PI, &x, &y);
	transmitter_seat_pointer_motion(seat, time, x, y);
	transmitter_seat_pointer_frame(seat);

	wl_event_source_timer_update(seat->pointer_timer, 100);

	return 0;
}

int
transmitter_seat_fake_pointer_input(struct weston_transmitter_seat *seat,
				    struct weston_transmitter_surface *txs)
{
	struct wl_event_loop *loop;
	wl_fixed_t x, y;
	uint32_t serial = 5;

	/* remove focus from earlier surface */
	transmitter_seat_pointer_leave(seat, serial++, seat->pointer_focus);
	transmitter_seat_pointer_frame(seat);

	/* set pointer focus to surface */
	fake_pointer_get_position(seat, 0.0, &x, &y);
	transmitter_seat_pointer_enter(seat, serial++, txs, x, y);
	transmitter_seat_pointer_frame(seat);

	if (!seat->pointer_timer) {
		/* schedule timer for motion */
		loop = wl_display_get_event_loop(seat->base->compositor->wl_display);
		seat->pointer_timer = wl_event_loop_add_timer(loop,
						fake_pointer_timer_handler, seat);
		wl_event_source_timer_update(seat->pointer_timer, 100);
	}

	/* XXX: if the now focused surface disappears, we should call
	 * transmitter_seat_pointer_leave() as part of the mockup. Otherwise
	 * you get a "Transmitter Warning: no pointer->focus_client?".
	 */

	return 0;
}