Branch data Line data Source code
1 : : // SPDX-License-Identifier: GPL-3.0-or-later
2 : : // SPDX-FileCopyrightText: Andy Holmes <andrew.g.r.holmes@gmail.com>
3 : :
4 : : #define G_LOG_DOMAIN "valent-mousepad-plugin"
5 : :
6 : : #include "config.h"
7 : :
8 : : #include <glib/gi18n.h>
9 : : #include <gio/gio.h>
10 : : #include <json-glib/json-glib.h>
11 : : #include <valent.h>
12 : :
13 : : #include "valent-mousepad-device.h"
14 : : #include "valent-mousepad-keydef.h"
15 : : #include "valent-mousepad-plugin.h"
16 : :
17 : :
18 : : struct _ValentMousepadPlugin
19 : : {
20 : : ValentDevicePlugin parent_instance;
21 : :
22 : : ValentInputAdapter *local_adapter;
23 : : unsigned int local_state : 1;
24 : : unsigned int local_watch : 1;
25 : :
26 : : ValentMousepadDevice *remote_adapter;
27 : : unsigned int remote_state : 1;
28 : : };
29 : :
30 : : static void valent_mousepad_plugin_send_echo (ValentMousepadPlugin *self,
31 : : JsonNode *packet);
32 : : static void valent_mousepad_plugin_send_keyboardstate (ValentMousepadPlugin *self);
33 : :
34 [ + + + - ]: 105 : G_DEFINE_FINAL_TYPE (ValentMousepadPlugin, valent_mousepad_plugin, VALENT_TYPE_DEVICE_PLUGIN)
35 : :
36 : : static void
37 : 5 : on_primary_adapter_changed (ValentComponent *component,
38 : : GParamSpec *pspec,
39 : : ValentMousepadPlugin *self)
40 : : {
41 [ - + ]: 5 : g_assert (VALENT_IS_INPUT (component));
42 [ + - ]: 5 : g_assert (VALENT_IS_MOUSEPAD_PLUGIN (self));
43 : :
44 [ - + ]: 5 : g_clear_object (&self->local_adapter);
45 : 5 : g_object_get (component, "primary-adapter", &self->local_adapter, NULL);
46 : :
47 [ + - ]: 5 : if (self->local_state != (self->local_adapter != NULL))
48 : : {
49 : 5 : self->local_state = (self->local_adapter != NULL);
50 : 5 : valent_mousepad_plugin_send_keyboardstate (self);
51 : : }
52 : 5 : }
53 : :
54 : : static void
55 : 20 : valent_mousepad_plugin_watch_local_state (ValentMousepadPlugin *self,
56 : : gboolean watch)
57 : : {
58 : 20 : ValentInput *input = valent_input_get_default ();
59 : :
60 [ - + ]: 20 : g_assert (VALENT_IS_MOUSEPAD_PLUGIN (self));
61 : :
62 [ + + ]: 20 : if (self->local_watch == watch)
63 : : return;
64 : :
65 [ + + ]: 10 : if (watch)
66 : : {
67 : 5 : g_signal_connect_object (input,
68 : : "notify::primary-adapter",
69 : : G_CALLBACK (on_primary_adapter_changed),
70 : : self,
71 : : G_CONNECT_DEFAULT);
72 : 5 : on_primary_adapter_changed (VALENT_COMPONENT (input), NULL, self);
73 : 5 : self->local_watch = TRUE;
74 : : }
75 : : else
76 : : {
77 : 5 : g_signal_handlers_disconnect_by_data (input, self);
78 : 5 : self->local_watch = FALSE;
79 : : }
80 : : }
81 : :
82 : : static void
83 : 22 : valent_mousepad_plugin_update_remote_state (ValentMousepadPlugin *self,
84 : : gboolean state)
85 : : {
86 : 22 : ValentInput *input = valent_input_get_default ();
87 : 22 : GAction *action;
88 : :
89 [ - + ]: 22 : g_assert (VALENT_IS_MOUSEPAD_PLUGIN (self));
90 : :
91 : 22 : action = g_action_map_lookup_action (G_ACTION_MAP (self), "event");
92 [ + + ]: 22 : if (action != NULL)
93 : 17 : g_simple_action_set_enabled (G_SIMPLE_ACTION (action), state);
94 : :
95 [ + + ]: 22 : if (self->remote_state == state)
96 : : return;
97 : :
98 : 4 : self->remote_state = state;
99 [ + + + - ]: 4 : if (self->remote_state && self->remote_adapter == NULL)
100 : 2 : {
101 : 2 : ValentDevice *device = NULL;
102 : :
103 : 2 : device = valent_object_get_parent (VALENT_OBJECT (self));
104 : 2 : self->remote_adapter = valent_mousepad_device_new (device);
105 : 2 : valent_component_export_adapter (VALENT_COMPONENT (input),
106 : : VALENT_EXTENSION (self->remote_adapter));
107 : : }
108 [ + - + - ]: 2 : else if (!self->remote_state && self->remote_adapter != NULL)
109 : : {
110 : 2 : valent_component_unexport_adapter (VALENT_COMPONENT (input),
111 : : VALENT_EXTENSION (self->remote_adapter));
112 : 2 : valent_object_destroy (VALENT_OBJECT (self->remote_adapter));
113 [ + - ]: 2 : g_clear_object (&self->remote_adapter);
114 : : }
115 : : }
116 : :
117 : : static KeyModifierType
118 : 4 : event_to_mask (JsonObject *body)
119 : : {
120 : 4 : KeyModifierType mask = 0;
121 : :
122 [ + + ]: 4 : if (json_object_get_boolean_member_with_default (body, "alt", FALSE))
123 : 1 : mask |= KEYMOD_ALT_MASK;
124 : :
125 [ + + ]: 4 : if (json_object_get_boolean_member_with_default (body, "ctrl", FALSE))
126 : 1 : mask |= KEYMOD_CONTROL_MASK;
127 : :
128 [ + + ]: 4 : if (json_object_get_boolean_member_with_default (body, "shift", FALSE))
129 : 1 : mask |= KEYMOD_SHIFT_MASK;
130 : :
131 [ + + ]: 4 : if (json_object_get_boolean_member_with_default (body, "super", FALSE))
132 : 1 : mask |= KEYMOD_SUPER_MASK;
133 : :
134 : 4 : return mask;
135 : : }
136 : :
137 : : static inline void
138 : 2 : keyboard_mask (ValentInputAdapter *input,
139 : : unsigned int mask,
140 : : gboolean lock)
141 : : {
142 [ + - ]: 2 : if (mask & KEYMOD_ALT_MASK)
143 : 2 : valent_input_adapter_keyboard_keysym (input, KEYSYM_Alt_L, lock);
144 : :
145 [ + - ]: 2 : if (mask & KEYMOD_CONTROL_MASK)
146 : 2 : valent_input_adapter_keyboard_keysym (input, KEYSYM_Control_L, lock);
147 : :
148 [ + - ]: 2 : if (mask & KEYMOD_SHIFT_MASK)
149 : 2 : valent_input_adapter_keyboard_keysym (input, KEYSYM_Shift_L, lock);
150 : :
151 [ + - ]: 2 : if (mask & KEYMOD_SUPER_MASK)
152 : 2 : valent_input_adapter_keyboard_keysym (input, KEYSYM_Super_L, lock);
153 : 2 : }
154 : :
155 : : /*
156 : : * Packet Handlers
157 : : */
158 : : static void
159 : 12 : valent_mousepad_plugin_handle_mousepad_request (ValentMousepadPlugin *self,
160 : : JsonNode *packet)
161 : : {
162 : 12 : JsonObject *body;
163 : 12 : const char *key;
164 : 12 : int64_t keycode;
165 : :
166 [ - + ]: 12 : g_assert (VALENT_IS_MOUSEPAD_PLUGIN (self));
167 [ + - ]: 12 : g_assert (VALENT_IS_PACKET (packet));
168 : :
169 [ - + ]: 12 : if (self->local_adapter == NULL)
170 : : {
171 : 0 : g_warning ("%s(): No input adapter available", G_STRFUNC);
172 : 0 : return;
173 : : }
174 : :
175 : 12 : body = valent_packet_get_body (packet);
176 : :
177 : : /* Pointer movement */
178 [ + + - + ]: 12 : if (json_object_has_member (body, "dx") || json_object_has_member (body, "dy"))
179 : : {
180 : 2 : double dx, dy;
181 : :
182 : 2 : dx = json_object_get_double_member_with_default (body, "dx", 0.0);
183 : 2 : dy = json_object_get_double_member_with_default (body, "dy", 0.0);
184 : :
185 [ + + ]: 2 : if (valent_packet_check_field (packet, "scroll"))
186 : 1 : valent_input_adapter_pointer_axis (self->local_adapter, dx, dy);
187 : : else
188 : 1 : valent_input_adapter_pointer_motion (self->local_adapter, dx, dy);
189 : : }
190 : :
191 : : /* Keyboard Event */
192 [ + + ]: 10 : else if (valent_packet_get_string (packet, "key", &key))
193 : : {
194 : 3 : KeyModifierType mask;
195 : 3 : const char *next;
196 : 3 : gunichar codepoint;
197 : :
198 : : /* Lock modifiers */
199 [ + + ]: 3 : if ((mask = event_to_mask (body)) != 0)
200 : 1 : keyboard_mask (self->local_adapter, mask, TRUE);
201 : :
202 : : /* Input each keysym */
203 : 3 : next = key;
204 : :
205 [ + + ]: 9 : while ((codepoint = g_utf8_get_char (next)) != 0)
206 : : {
207 : 6 : uint32_t keysym;
208 : :
209 : 6 : keysym = valent_input_unicode_to_keysym (codepoint);
210 : 6 : valent_input_adapter_keyboard_keysym (self->local_adapter, keysym, TRUE);
211 : 6 : valent_input_adapter_keyboard_keysym (self->local_adapter, keysym, FALSE);
212 : :
213 : 6 : next = g_utf8_next_char (next);
214 : : }
215 : :
216 : : /* Unlock modifiers */
217 [ + + ]: 3 : if (mask != 0)
218 : 1 : keyboard_mask (self->local_adapter, mask, FALSE);
219 : :
220 : : /* Send ack, if requested */
221 [ - + ]: 3 : if (valent_packet_check_field (packet, "sendAck"))
222 : 0 : valent_mousepad_plugin_send_echo (self, packet);
223 : : }
224 [ + + ]: 7 : else if (valent_packet_get_int (packet, "specialKey", &keycode))
225 : : {
226 : 1 : KeyModifierType mask;
227 : 1 : uint32_t keysym;
228 : :
229 [ - + ]: 1 : if ((keysym = valent_mousepad_keycode_to_keysym (keycode)) == 0)
230 : : {
231 : 0 : g_debug ("%s(): expected \"specialKey\" field holding a keycode",
232 : : G_STRFUNC);
233 : 0 : return;
234 : : }
235 : :
236 : : /* Lock modifiers */
237 [ - + ]: 1 : if ((mask = event_to_mask (body)) != 0)
238 : 0 : keyboard_mask (self->local_adapter, mask, TRUE);
239 : :
240 : : /* Input each keysym */
241 : 1 : valent_input_adapter_keyboard_keysym (self->local_adapter, keysym, TRUE);
242 : 1 : valent_input_adapter_keyboard_keysym (self->local_adapter, keysym, FALSE);
243 : :
244 : : /* Unlock modifiers */
245 [ - + ]: 1 : if (mask != 0)
246 : 0 : keyboard_mask (self->local_adapter, mask, FALSE);
247 : :
248 : : /* Send ack, if requested */
249 [ - + ]: 1 : if (valent_packet_check_field (packet, "sendAck"))
250 : 0 : valent_mousepad_plugin_send_echo (self, packet);
251 : : }
252 : :
253 [ + + ]: 6 : else if (valent_packet_check_field (packet, "singleclick"))
254 : : {
255 : 1 : valent_input_adapter_pointer_button (self->local_adapter, VALENT_POINTER_PRIMARY, TRUE);
256 : 1 : valent_input_adapter_pointer_button (self->local_adapter, VALENT_POINTER_PRIMARY, FALSE);
257 : : }
258 : :
259 [ + + ]: 5 : else if (valent_packet_check_field (packet, "doubleclick"))
260 : : {
261 : 1 : valent_input_adapter_pointer_button (self->local_adapter, VALENT_POINTER_PRIMARY, TRUE);
262 : 1 : valent_input_adapter_pointer_button (self->local_adapter, VALENT_POINTER_PRIMARY, FALSE);
263 : 1 : valent_input_adapter_pointer_button (self->local_adapter, VALENT_POINTER_PRIMARY, TRUE);
264 : 1 : valent_input_adapter_pointer_button (self->local_adapter, VALENT_POINTER_PRIMARY, FALSE);
265 : : }
266 : :
267 [ + + ]: 4 : else if (valent_packet_check_field (packet, "middleclick"))
268 : : {
269 : 1 : valent_input_adapter_pointer_button (self->local_adapter, VALENT_POINTER_MIDDLE, TRUE);
270 : 1 : valent_input_adapter_pointer_button (self->local_adapter, VALENT_POINTER_MIDDLE, FALSE);
271 : : }
272 : :
273 [ + + ]: 3 : else if (valent_packet_check_field (packet, "rightclick"))
274 : : {
275 : 1 : valent_input_adapter_pointer_button (self->local_adapter, VALENT_POINTER_SECONDARY, TRUE);
276 : 1 : valent_input_adapter_pointer_button (self->local_adapter, VALENT_POINTER_SECONDARY, FALSE);
277 : : }
278 : :
279 [ + + ]: 2 : else if (valent_packet_check_field (packet, "singlehold"))
280 : : {
281 : 1 : valent_input_adapter_pointer_button (self->local_adapter, VALENT_POINTER_PRIMARY, TRUE);
282 : : }
283 : :
284 : : /* Not used by kdeconnect-android, hold is released with a regular click */
285 [ + - ]: 1 : else if (valent_packet_check_field (packet, "singlerelease"))
286 : : {
287 : 1 : valent_input_adapter_pointer_button (self->local_adapter, VALENT_POINTER_PRIMARY, FALSE);
288 : : }
289 : :
290 : : else
291 : : {
292 : 0 : g_debug ("%s: unknown input", G_STRFUNC);
293 : : }
294 : : }
295 : :
296 : : static void
297 : 1 : valent_mousepad_plugin_handle_mousepad_echo (ValentMousepadPlugin *self,
298 : : JsonNode *packet)
299 : : {
300 [ - + ]: 1 : g_assert (VALENT_IS_MOUSEPAD_PLUGIN (self));
301 [ + - ]: 1 : g_assert (VALENT_IS_PACKET (packet));
302 : :
303 : 1 : VALENT_NOTE ("Not implemented");
304 : 1 : }
305 : :
306 : : static void
307 : 2 : valent_mousepad_plugin_handle_mousepad_keyboardstate (ValentMousepadPlugin *self,
308 : : JsonNode *packet)
309 : : {
310 : 2 : gboolean state;
311 : :
312 [ - + ]: 2 : g_assert (VALENT_IS_MOUSEPAD_PLUGIN (self));
313 [ + - ]: 2 : g_assert (VALENT_IS_PACKET (packet));
314 : :
315 : : /* Update the remote keyboard state */
316 [ - + ]: 2 : if (!valent_packet_get_boolean (packet, "state", &state))
317 : : {
318 : 0 : g_debug ("%s(): expected \"state\" field holding a boolean",
319 : : G_STRFUNC);
320 : 0 : return;
321 : : }
322 : :
323 [ + - ]: 2 : if (self->remote_state != state)
324 : : {
325 : 2 : valent_mousepad_plugin_update_remote_state (self, state);
326 : : }
327 : : }
328 : :
329 : : /*
330 : : * Packet Providers
331 : : */
332 : : static void
333 : 3 : valent_mousepad_plugin_mousepad_request_keyboard (ValentMousepadPlugin *self,
334 : : uint32_t keysym,
335 : : KeyModifierType mask)
336 : : {
337 : 3 : g_autoptr (JsonBuilder) builder = NULL;
338 [ - - - + ]: 3 : g_autoptr (JsonNode) packet = NULL;
339 : 3 : uint32_t special_key = 0;
340 : :
341 [ - + ]: 3 : g_assert (VALENT_IS_MOUSEPAD_PLUGIN (self));
342 : :
343 : 3 : valent_packet_init (&builder, "kdeconnect.mousepad.request");
344 : :
345 [ + + ]: 3 : if ((special_key = valent_mousepad_keysym_to_keycode (keysym)) != 0)
346 : : {
347 : 1 : json_builder_set_member_name (builder, "specialKey");
348 : 1 : json_builder_add_int_value (builder, special_key);
349 : : }
350 : : else
351 : : {
352 [ - - ]: 2 : g_autoptr (GError) error = NULL;
353 [ - - - + ]: 2 : g_autofree char *key = NULL;
354 : 2 : gunichar wc;
355 : :
356 : 2 : wc = valent_input_keysym_to_unicode (keysym);
357 : 2 : key = g_ucs4_to_utf8 (&wc, 1, NULL, NULL, &error);
358 : :
359 [ - + ]: 2 : if (key == NULL)
360 : : {
361 : 0 : g_warning ("Converting %u to string: %s", keysym, error->message);
362 : 0 : return;
363 : : }
364 : :
365 : 2 : json_builder_set_member_name (builder, "key");
366 : 2 : json_builder_add_string_value (builder, key);
367 : : }
368 : :
369 [ + + ]: 3 : if (mask & KEYMOD_ALT_MASK)
370 : : {
371 : 1 : json_builder_set_member_name (builder, "alt");
372 : 1 : json_builder_add_boolean_value (builder, TRUE);
373 : : }
374 : :
375 [ + + ]: 3 : if (mask & KEYMOD_CONTROL_MASK)
376 : : {
377 : 1 : json_builder_set_member_name (builder, "ctrl");
378 : 1 : json_builder_add_boolean_value (builder, TRUE);
379 : : }
380 : :
381 [ + + ]: 3 : if (mask & KEYMOD_SHIFT_MASK)
382 : : {
383 : 1 : json_builder_set_member_name (builder, "shift");
384 : 1 : json_builder_add_boolean_value (builder, TRUE);
385 : : }
386 : :
387 [ + + ]: 3 : if (mask & KEYMOD_SUPER_MASK)
388 : : {
389 : 1 : json_builder_set_member_name (builder, "super");
390 : 1 : json_builder_add_boolean_value (builder, TRUE);
391 : : }
392 : :
393 : 3 : packet = valent_packet_end (&builder);
394 : :
395 [ + - ]: 3 : valent_device_plugin_queue_packet (VALENT_DEVICE_PLUGIN (self), packet);
396 : : }
397 : :
398 : : static void
399 : 2 : valent_mousepad_plugin_mousepad_request_pointer (ValentMousepadPlugin *self,
400 : : double dx,
401 : : double dy,
402 : : gboolean axis)
403 : : {
404 : 4 : g_autoptr (JsonBuilder) builder = NULL;
405 [ - + ]: 2 : g_autoptr (JsonNode) packet = NULL;
406 : :
407 [ - + ]: 2 : g_assert (VALENT_IS_MOUSEPAD_PLUGIN (self));
408 : :
409 : 2 : valent_packet_init (&builder, "kdeconnect.mousepad.request");
410 : :
411 : 2 : json_builder_set_member_name (builder, "dx");
412 : 2 : json_builder_add_double_value (builder, dx);
413 : 2 : json_builder_set_member_name (builder, "dy");
414 : 2 : json_builder_add_double_value (builder, dy);
415 : :
416 [ + + ]: 2 : if (axis)
417 : : {
418 : 1 : json_builder_set_member_name (builder, "scroll");
419 : 1 : json_builder_add_boolean_value (builder, TRUE);
420 : : }
421 : :
422 : 2 : packet = valent_packet_end (&builder);
423 : :
424 [ + - ]: 2 : valent_device_plugin_queue_packet (VALENT_DEVICE_PLUGIN (self), packet);
425 : 2 : }
426 : :
427 : : static void
428 : 0 : valent_mousepad_plugin_send_echo (ValentMousepadPlugin *self,
429 : : JsonNode *packet)
430 : : {
431 : 0 : g_autoptr (JsonBuilder) builder = NULL;
432 [ # # ]: 0 : g_autoptr (JsonNode) response = NULL;
433 : 0 : JsonObjectIter iter;
434 : 0 : const char *name;
435 : 0 : JsonNode *node;
436 : :
437 [ # # ]: 0 : g_assert (VALENT_IS_MOUSEPAD_PLUGIN (self));
438 : :
439 : 0 : valent_packet_init (&builder, "kdeconnect.mousepad.echo");
440 : :
441 : 0 : json_object_iter_init (&iter, valent_packet_get_body (packet));
442 : :
443 [ # # ]: 0 : while (json_object_iter_next (&iter, &name, &node))
444 : : {
445 [ # # ]: 0 : if (g_strcmp0 (name, "sendAck") == 0)
446 : 0 : continue;
447 : :
448 : 0 : json_builder_set_member_name (builder, name);
449 : 0 : json_builder_add_value (builder, json_node_ref (node));
450 : : }
451 : :
452 : 0 : json_builder_set_member_name (builder, "isAck");
453 : 0 : json_builder_add_boolean_value (builder, TRUE);
454 : :
455 : 0 : response = valent_packet_end (&builder);
456 : :
457 [ # # ]: 0 : valent_device_plugin_queue_packet (VALENT_DEVICE_PLUGIN (self), response);
458 : 0 : }
459 : :
460 : : static void
461 : 5 : valent_mousepad_plugin_send_keyboardstate (ValentMousepadPlugin *self)
462 : : {
463 : 10 : g_autoptr (JsonBuilder) builder = NULL;
464 [ - + ]: 5 : g_autoptr (JsonNode) packet = NULL;
465 : :
466 [ - + ]: 5 : g_assert (VALENT_IS_MOUSEPAD_PLUGIN (self));
467 : :
468 : 5 : valent_packet_init (&builder, "kdeconnect.mousepad.keyboardstate");
469 : 5 : json_builder_set_member_name (builder, "state");
470 : 5 : json_builder_add_boolean_value (builder, self->local_state);
471 : 5 : packet = valent_packet_end (&builder);
472 : :
473 [ + - ]: 5 : valent_device_plugin_queue_packet (VALENT_DEVICE_PLUGIN (self), packet);
474 : 5 : }
475 : :
476 : : /*
477 : : * GActions
478 : : */
479 : : static void
480 : 5 : mousepad_event_action (GSimpleAction *action,
481 : : GVariant *parameter,
482 : : gpointer user_data)
483 : : {
484 : 5 : ValentMousepadPlugin *self = VALENT_MOUSEPAD_PLUGIN (user_data);
485 : 5 : GVariantDict dict;
486 : 5 : double dx, dy;
487 : 5 : uint32_t keysym;
488 : :
489 [ - + ]: 5 : g_assert (VALENT_IS_MOUSEPAD_PLUGIN (self));
490 [ + - ]: 5 : g_return_if_fail (self->remote_state);
491 : :
492 : 5 : g_variant_dict_init (&dict, parameter);
493 : :
494 [ + + + - ]: 7 : if (g_variant_dict_lookup (&dict, "dx", "d", &dx) &&
495 : 2 : g_variant_dict_lookup (&dict, "dy", "d", &dy))
496 : 2 : {
497 : 2 : gboolean scroll = FALSE;
498 : :
499 : 2 : g_variant_dict_lookup (&dict, "scroll", "b", &scroll);
500 : 2 : valent_mousepad_plugin_mousepad_request_pointer (self, dx, dy, scroll);
501 : : }
502 [ + - ]: 3 : else if (g_variant_dict_lookup (&dict, "keysym", "u", &keysym))
503 : : {
504 : 3 : KeyModifierType mask = 0;
505 : :
506 : 3 : g_variant_dict_lookup (&dict, "mask", "u", &mask);
507 : 3 : valent_mousepad_plugin_mousepad_request_keyboard (self, keysym, mask);
508 : : }
509 : : else
510 : 0 : g_warning ("%s(): unknown event type", G_STRFUNC);
511 : :
512 : 5 : g_variant_dict_clear (&dict);
513 : : }
514 : :
515 : : static const GActionEntry actions[] = {
516 : : {"event", mousepad_event_action, "a{sv}", NULL, NULL}
517 : : };
518 : :
519 : : /*
520 : : * ValentDevicePlugin
521 : : */
522 : : static void
523 : 10 : valent_mousepad_plugin_update_state (ValentDevicePlugin *plugin,
524 : : ValentDeviceState state)
525 : : {
526 : 10 : ValentMousepadPlugin *self = VALENT_MOUSEPAD_PLUGIN (plugin);
527 : 10 : gboolean available;
528 : :
529 [ - + ]: 10 : g_assert (VALENT_IS_MOUSEPAD_PLUGIN (self));
530 : :
531 [ + + ]: 10 : available = (state & VALENT_DEVICE_STATE_CONNECTED) != 0 &&
532 [ - + ]: 5 : (state & VALENT_DEVICE_STATE_PAIRED) != 0;
533 : :
534 : 10 : valent_mousepad_plugin_watch_local_state (self, available);
535 [ + + + - ]: 20 : valent_mousepad_plugin_update_remote_state (self, available && self->remote_state);
536 : 10 : }
537 : :
538 : : static void
539 : 15 : valent_mousepad_plugin_handle_packet (ValentDevicePlugin *plugin,
540 : : const char *type,
541 : : JsonNode *packet)
542 : : {
543 : 15 : ValentMousepadPlugin *self = VALENT_MOUSEPAD_PLUGIN (plugin);
544 : :
545 [ - + ]: 15 : g_assert (VALENT_IS_MOUSEPAD_PLUGIN (self));
546 [ + - ]: 15 : g_assert (type != NULL);
547 [ + - ]: 15 : g_assert (VALENT_IS_PACKET (packet));
548 : :
549 : : /* A request to simulate input */
550 [ + + ]: 15 : if (g_str_equal (type, "kdeconnect.mousepad.request"))
551 : 12 : valent_mousepad_plugin_handle_mousepad_request (self, packet);
552 : :
553 : : /* A confirmation of input we requested */
554 [ + + ]: 3 : else if (g_str_equal (type, "kdeconnect.mousepad.echo"))
555 : 1 : valent_mousepad_plugin_handle_mousepad_echo (self, packet);
556 : :
557 : : /* The remote keyboard is ready/not ready for input */
558 [ + - ]: 2 : else if (g_str_equal (type, "kdeconnect.mousepad.keyboardstate"))
559 : 2 : valent_mousepad_plugin_handle_mousepad_keyboardstate (self, packet);
560 : :
561 : : else
562 : 0 : g_assert_not_reached ();
563 : 15 : }
564 : :
565 : : /*
566 : : * ValentObject
567 : : */
568 : : static void
569 : 10 : valent_mousepad_plugin_destroy (ValentObject *object)
570 : : {
571 : 10 : ValentMousepadPlugin *self = VALENT_MOUSEPAD_PLUGIN (object);
572 : :
573 : 10 : valent_mousepad_plugin_watch_local_state (self, FALSE);
574 : 10 : valent_mousepad_plugin_update_remote_state (self, FALSE);
575 : :
576 : 10 : VALENT_OBJECT_CLASS (valent_mousepad_plugin_parent_class)->destroy (object);
577 : 10 : }
578 : :
579 : : /*
580 : : * GObject
581 : : */
582 : : static void
583 : 5 : valent_mousepad_plugin_constructed (GObject *object)
584 : : {
585 : 5 : ValentDevicePlugin *plugin = VALENT_DEVICE_PLUGIN (object);
586 : :
587 : 5 : G_OBJECT_CLASS (valent_mousepad_plugin_parent_class)->constructed (object);
588 : :
589 : 5 : g_action_map_add_action_entries (G_ACTION_MAP (plugin),
590 : : actions,
591 : : G_N_ELEMENTS (actions),
592 : : plugin);
593 : 5 : }
594 : :
595 : : static void
596 : 1 : valent_mousepad_plugin_class_init (ValentMousepadPluginClass *klass)
597 : : {
598 : 1 : GObjectClass *object_class = G_OBJECT_CLASS (klass);
599 : 1 : ValentObjectClass *vobject_class = VALENT_OBJECT_CLASS (klass);
600 : 1 : ValentDevicePluginClass *plugin_class = VALENT_DEVICE_PLUGIN_CLASS (klass);
601 : :
602 : 1 : object_class->constructed = valent_mousepad_plugin_constructed;
603 : :
604 : 1 : vobject_class->destroy = valent_mousepad_plugin_destroy;
605 : :
606 : 1 : plugin_class->handle_packet = valent_mousepad_plugin_handle_packet;
607 : 1 : plugin_class->update_state = valent_mousepad_plugin_update_state;
608 : : }
609 : :
610 : : static void
611 : 5 : valent_mousepad_plugin_init (ValentMousepadPlugin *self)
612 : : {
613 : 5 : }
614 : :
|