• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2021 Red Hat, Inc.
3  * Copyright © 2021 José Expósito
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 
25 #include "config.h"
26 
27 #include "libinput-private-config.h"
28 #include "libinput-private.h"
29 
30 int
libinput_device_config_gesture_hold_is_available(struct libinput_device * device)31 libinput_device_config_gesture_hold_is_available(struct libinput_device *device)
32 {
33 	if (!libinput_device_has_capability(device,
34 					    LIBINPUT_DEVICE_CAP_GESTURE))
35 		return 0;
36 
37 	if (!device->config.gesture->get_hold_default(device))
38 		return 0;
39 
40 	return 1;
41 }
42 
43 enum libinput_config_status
libinput_device_config_gesture_set_hold_enabled(struct libinput_device * device,enum libinput_config_hold_state enable)44 libinput_device_config_gesture_set_hold_enabled(struct libinput_device *device,
45 						enum libinput_config_hold_state enable)
46 {
47 	if (enable != LIBINPUT_CONFIG_HOLD_ENABLED &&
48 	    enable != LIBINPUT_CONFIG_HOLD_DISABLED)
49 		return LIBINPUT_CONFIG_STATUS_INVALID;
50 
51 	if (!libinput_device_config_gesture_hold_is_available(device)) {
52 		return enable ? LIBINPUT_CONFIG_STATUS_UNSUPPORTED :
53 				LIBINPUT_CONFIG_STATUS_SUCCESS;
54 	}
55 
56 	return device->config.gesture->set_hold_enabled(device, enable);
57 }
58 
59 enum libinput_config_hold_state
libinput_device_config_gesture_get_hold_enabled(struct libinput_device * device)60 libinput_device_config_gesture_get_hold_enabled(struct libinput_device *device)
61 {
62 	if (!libinput_device_config_gesture_hold_is_available(device))
63 		return LIBINPUT_CONFIG_HOLD_DISABLED;
64 
65 	return device->config.gesture->get_hold_enabled(device);
66 }
67 
68 enum libinput_config_hold_state
libinput_device_config_gesture_get_hold_default_enabled(struct libinput_device * device)69 libinput_device_config_gesture_get_hold_default_enabled(struct libinput_device *device)
70 {
71 	if (!libinput_device_config_gesture_hold_is_available(device))
72 		return LIBINPUT_CONFIG_HOLD_DISABLED;
73 
74 	return device->config.gesture->get_hold_default(device);
75 }
76