LCOV - code coverage report
Current view: top level - src/libvalent/input - valent-input-adapter.c (source / functions) Coverage Total Hit
Test: Code Coverage Lines: 100.0 % 34 34
Test Date: 2024-04-23 06:02:46 Functions: 100.0 % 8 8
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 42.1 % 38 16

             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-input-adapter"
       5                 :             : 
       6                 :             : #include "config.h"
       7                 :             : 
       8                 :             : #include <gio/gio.h>
       9                 :             : #include <libvalent-core.h>
      10                 :             : 
      11                 :             : #include "valent-input-adapter.h"
      12                 :             : 
      13                 :             : 
      14                 :             : /**
      15                 :             :  * ValentInputAdapter:
      16                 :             :  *
      17                 :             :  * An abstract base class for virtual input devices.
      18                 :             :  *
      19                 :             :  * `ValentInputAdapter` is a base class for plugins that provide an interface to
      20                 :             :  * the pointer and keyboard. This usually means simulating pointer and keyboard
      21                 :             :  * events on the host system.
      22                 :             :  *
      23                 :             :  * ## `.plugin` File
      24                 :             :  *
      25                 :             :  * Implementations may define the following extra fields in the `.plugin` file:
      26                 :             :  *
      27                 :             :  * - `X-InputAdapterPriority`
      28                 :             :  *
      29                 :             :  *     An integer indicating the adapter priority. The implementation with the
      30                 :             :  *     lowest value will be used as the primary adapter.
      31                 :             :  *
      32                 :             :  * Since: 1.0
      33                 :             :  */
      34                 :             : 
      35                 :             : typedef struct
      36                 :             : {
      37                 :             :   uint8_t  active : 1;
      38                 :             : } ValentInputAdapterPrivate;
      39                 :             : 
      40   [ +  +  +  - ]:         520 : G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ValentInputAdapter, valent_input_adapter, VALENT_TYPE_EXTENSION)
      41                 :             : 
      42                 :             : /**
      43                 :             :  * ValentInputAdapterClass:
      44                 :             :  * @keyboard_keysym: the virtual function pointer for valent_input_adapter_keyboard_keysym()
      45                 :             :  * @pointer_axis: the virtual function pointer for valent_input_adapter_pointer_axis()
      46                 :             :  * @pointer_button: the virtual function pointer for valent_input_adapter_pointer_button()
      47                 :             :  * @pointer_motion: the virtual function pointer for valent_input_adapter_pointer_motion()
      48                 :             :  *
      49                 :             :  * The virtual function table for `ValentInputAdapter`.
      50                 :             :  */
      51                 :             : 
      52                 :             : 
      53                 :             : /* LCOV_EXCL_START */
      54                 :             : static void
      55                 :             : valent_input_adapter_real_keyboard_keysym (ValentInputAdapter *adapter,
      56                 :             :                                            uint32_t            keysym,
      57                 :             :                                            gboolean            state)
      58                 :             : {
      59                 :             : }
      60                 :             : 
      61                 :             : static void
      62                 :             : valent_input_adapter_real_pointer_axis (ValentInputAdapter *adapter,
      63                 :             :                                         double              dx,
      64                 :             :                                         double              dy)
      65                 :             : {
      66                 :             : }
      67                 :             : 
      68                 :             : static void
      69                 :             : valent_input_adapter_real_pointer_button (ValentInputAdapter  *adapter,
      70                 :             :                                           unsigned int         button,
      71                 :             :                                           gboolean             state)
      72                 :             : {
      73                 :             : }
      74                 :             : 
      75                 :             : static void
      76                 :             : valent_input_adapter_real_pointer_motion (ValentInputAdapter *adapter,
      77                 :             :                                           double              dx,
      78                 :             :                                           double              dy)
      79                 :             : {
      80                 :             : }
      81                 :             : /* LCOV_EXCL_STOP */
      82                 :             : 
      83                 :             : /*
      84                 :             :  * GObject
      85                 :             :  */
      86                 :             : static void
      87                 :          67 : valent_input_adapter_class_init (ValentInputAdapterClass *klass)
      88                 :             : {
      89                 :          67 :   klass->keyboard_keysym = valent_input_adapter_real_keyboard_keysym;
      90                 :          67 :   klass->pointer_axis = valent_input_adapter_real_pointer_axis;
      91                 :          67 :   klass->pointer_button = valent_input_adapter_real_pointer_button;
      92                 :          67 :   klass->pointer_motion = valent_input_adapter_real_pointer_motion;
      93                 :             : }
      94                 :             : 
      95                 :             : static void
      96                 :          10 : valent_input_adapter_init (ValentInputAdapter *adapter)
      97                 :             : {
      98                 :          10 : }
      99                 :             : 
     100                 :             : /**
     101                 :             :  * valent_input_adapter_keyboard_keysym:
     102                 :             :  * @adapter: a `ValentInputAdapter`
     103                 :             :  * @keysym: a keysym
     104                 :             :  * @state: %TRUE to press, or %FALSE to release
     105                 :             :  *
     106                 :             :  * Press or release @keysym.
     107                 :             :  *
     108                 :             :  * Since: 1.0
     109                 :             :  */
     110                 :             : void
     111                 :          28 : valent_input_adapter_keyboard_keysym (ValentInputAdapter *adapter,
     112                 :             :                                       uint32_t            keysym,
     113                 :             :                                       gboolean            state)
     114                 :             : {
     115                 :          28 :   VALENT_ENTRY;
     116                 :             : 
     117         [ +  - ]:          28 :   g_return_if_fail (VALENT_IS_INPUT_ADAPTER (adapter));
     118                 :             : 
     119                 :             :   /* Silently ignore empty symbols */
     120         [ +  - ]:          28 :   if G_UNLIKELY (keysym == 0)
     121                 :          28 :     VALENT_EXIT;
     122                 :             : 
     123                 :          28 :   VALENT_INPUT_ADAPTER_GET_CLASS (adapter)->keyboard_keysym (adapter,
     124                 :             :                                                              keysym,
     125                 :             :                                                              state);
     126                 :             : 
     127                 :          28 :   VALENT_EXIT;
     128                 :             : }
     129                 :             : 
     130                 :             : /**
     131                 :             :  * valent_input_adapter_pointer_axis:
     132                 :             :  * @adapter: a `ValentInputAdapter`
     133                 :             :  * @dx: movement on x-axis
     134                 :             :  * @dy: movement on y-axis
     135                 :             :  *
     136                 :             :  * Scroll the surface under the pointer (@dx, @dy), relative to its current
     137                 :             :  * position.
     138                 :             :  *
     139                 :             :  * Implementations should handle any necessary scaling.
     140                 :             :  *
     141                 :             :  * Since: 1.0
     142                 :             :  */
     143                 :             : void
     144                 :           4 : valent_input_adapter_pointer_axis (ValentInputAdapter *adapter,
     145                 :             :                                    double              dx,
     146                 :             :                                    double              dy)
     147                 :             : {
     148                 :           4 :   VALENT_ENTRY;
     149                 :             : 
     150         [ +  - ]:           4 :   g_return_if_fail (VALENT_IS_INPUT_ADAPTER (adapter));
     151                 :             : 
     152                 :             :   /* Silently ignore 0-delta motion */
     153   [ -  +  -  -  :           4 :   if G_UNLIKELY (G_APPROX_VALUE (dx, 0.0, 0.01) && G_APPROX_VALUE (dy, 0.0, 0.01))
          +  -  +  -  +  
                -  -  - ]
     154                 :           4 :     VALENT_EXIT;
     155                 :             : 
     156                 :           4 :   VALENT_INPUT_ADAPTER_GET_CLASS (adapter)->pointer_axis (adapter, dx, dy);
     157                 :             : 
     158                 :           4 :   VALENT_EXIT;
     159                 :             : }
     160                 :             : 
     161                 :             : /**
     162                 :             :  * valent_input_adapter_pointer_button:
     163                 :             :  * @adapter: a `ValentInputAdapter`
     164                 :             :  * @button: a button number
     165                 :             :  * @state: %TRUE to press, or %FALSE to release
     166                 :             :  *
     167                 :             :  * Press or release @button.
     168                 :             :  *
     169                 :             :  * Since: 1.0
     170                 :             :  */
     171                 :             : void
     172                 :          18 : valent_input_adapter_pointer_button (ValentInputAdapter *adapter,
     173                 :             :                                      unsigned int        button,
     174                 :             :                                      gboolean            state)
     175                 :             : {
     176                 :          18 :   VALENT_ENTRY;
     177                 :             : 
     178         [ +  - ]:          18 :   g_return_if_fail (VALENT_IS_INPUT_ADAPTER (adapter));
     179                 :             : 
     180                 :          18 :   VALENT_INPUT_ADAPTER_GET_CLASS (adapter)->pointer_button (adapter,
     181                 :             :                                                             button,
     182                 :             :                                                             state);
     183                 :             : 
     184                 :          18 :   VALENT_EXIT;
     185                 :             : }
     186                 :             : 
     187                 :             : /**
     188                 :             :  * valent_input_adapter_pointer_motion:
     189                 :             :  * @adapter: a `ValentInputAdapter`
     190                 :             :  * @dx: movement on x-axis
     191                 :             :  * @dy: movement on y-axis
     192                 :             :  *
     193                 :             :  * Move the pointer (@dx, @dy), relative to its current position.
     194                 :             :  *
     195                 :             :  * Implementation should handle any necessary scaling
     196                 :             :  *
     197                 :             :  * Since: 1.0
     198                 :             :  */
     199                 :             : void
     200                 :           7 : valent_input_adapter_pointer_motion (ValentInputAdapter *adapter,
     201                 :             :                                      double              dx,
     202                 :             :                                      double              dy)
     203                 :             : {
     204                 :           7 :   VALENT_ENTRY;
     205                 :             : 
     206         [ +  - ]:           7 :   g_return_if_fail (VALENT_IS_INPUT_ADAPTER (adapter));
     207                 :             : 
     208                 :             :   /* Silently ignore 0-delta motion */
     209   [ +  +  -  +  :           7 :   if G_UNLIKELY (G_APPROX_VALUE (dx, 0.0, 0.01) && G_APPROX_VALUE (dy, 0.0, 0.01))
          -  +  -  -  -  
                -  -  - ]
     210                 :           7 :     VALENT_EXIT;
     211                 :             : 
     212                 :           7 :   VALENT_INPUT_ADAPTER_GET_CLASS (adapter)->pointer_motion (adapter, dx, dy);
     213                 :             : 
     214                 :           7 :   VALENT_EXIT;
     215                 :             : }
     216                 :             : 
        

Generated by: LCOV version 2.0-1