Libmacro  0.2
Libmacro is an extensible macro and hotkey library.
p_device.h
Go to the documentation of this file.
1 /* Libmacro - A multi-platform, extendable macro and hotkey C library
2  Copyright (C) 2013 Jonathan Pelletier, New Paradigm Software
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
27 #ifndef MCR_STANDARD_LINUX_P_DEVICE_H_
28 #define MCR_STANDARD_LINUX_P_DEVICE_H_
29 
30 #include "mcr/base/base.h"
31 #include "mcr/util/linux/p_util.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 typedef struct {
38  int set_ev_bit;
39  int first;
40  int last;
42 
44 struct mcr_Device {
45  struct mcr_context *context;
47  struct uinput_user_dev device;
48  struct {
49  const int *set_events;
50  size_t set_event_count;
51  };
53  struct {
54  const mcr_EvbitRange_t *event_bits;
55  size_t event_bit_count;
56  };
58  int fd;
60  int event_fd;
62  bool enabled;
63 };
64 
66 extern MCR_API const struct input_event mcr_syncer;
67 
72 MCR_API int mcr_Device_set_uinput_path(struct mcr_context *ctx, const char *path);
78 MCR_API int mcr_Device_set_event_path(struct mcr_context *ctx, const char *directoryPath);
83 MCR_API int mcr_Device_set_absolute_resolution(struct mcr_context *ctx, __s32 resolution);
89 MCR_API void mcr_Device_ctor(struct mcr_Device *devPt, struct mcr_context *ctx, const char *name, const int *setEvents, size_t setEventCount, const mcr_EvbitRange_t *eventBits, size_t eventBitCount);
95 MCR_API void mcr_Device_deinit(struct mcr_Device *devPt);
101 MCR_API int mcr_Device_enable(struct mcr_Device *devPt, bool enable);
106 MCR_API int mcr_Device_enable_all(struct mcr_context *ctx, bool enable);
107 
108 MCR_API void mcr_Device_set_uibit(struct mcr_Device *devPt, int *uiEvents, size_t count);
116 MCR_API void mcr_Device_set_evbits(struct mcr_Device *devPt, mcr_EvbitRange_t *evBits, size_t count);
123 MCR_API mcr_EvbitRange_t *mcr_Device_bits(struct mcr_Device *devPt, int setUiBit);
125 MCR_API bool mcr_Device_has_evbit(struct mcr_Device *devPt);
126 
127 /* Sending, inlined for efficiency. */
134 static MCR_INLINE int mcr_Device_send(struct mcr_Device *devPt, const struct input_event *eventObjects, size_t bytes)
135 {
136  int err;
137  if (devPt->fd == -1) {
138  mcr_err = ENXIO;
139  return ENXIO;
140  }
141  if (write(devPt->fd, eventObjects, bytes) != bytes) {
142  mcr_err = errno;
143  if (!mcr_err)
144  mcr_err = EIO;
145  }
146  return err;
147 }
148 
154 static MCR_INLINE int mcr_Device_single(struct mcr_Device *devPt, const struct input_event *eventObjects)
155 {
156  return mcr_Device_send(devPt, eventObjects, sizeof(struct input_event));
157 }
158 
160 static MCR_INLINE int mcr_Device_sync(struct mcr_Device *devPt)
161 {
162  return mcr_Device_send(devPt, &mcr_syncer, sizeof(struct input_event));
163 }
164 
168 MCR_API int mcr_Device_initialize(struct mcr_context *context);
170 MCR_API int mcr_Device_deinitialize(struct mcr_context *context);
171 
172 #ifdef __cplusplus
173 }
174 #endif
175 
176 #endif
MCR_API int mcr_Device_deinitialize(struct mcr_context *context)
MCR_API int mcr_Device_set_uinput_path(struct mcr_context *ctx, const char *path)
int event_fd
Definition: p_device.h:60
MCR_API mcr_EvbitRange_t * mcr_Device_bits(struct mcr_Device *devPt, int setUiBit)
MCR_API void mcr_Device_deinit(struct mcr_Device *devPt)
MCR_API int mcr_Device_set_event_path(struct mcr_context *ctx, const char *directoryPath)
int fd
Definition: p_device.h:58
MCR_API int mcr_Device_enable(struct mcr_Device *devPt, bool enable)
MCR_API const struct input_event mcr_syncer
MCR_API void mcr_Device_ctor(struct mcr_Device *devPt, struct mcr_context *ctx, const char *name, const int *setEvents, size_t setEventCount, const mcr_EvbitRange_t *eventBits, size_t eventBitCount)
Base module implements mcr_base - Libmacro first module.
MCR_API bool mcr_Device_has_evbit(struct mcr_Device *devPt)
MCR_API void mcr_Device_set_evbits(struct mcr_Device *devPt, mcr_EvbitRange_t *evBits, size_t count)
MCR_API int mcr_Device_enable_all(struct mcr_context *ctx, bool enable)
bool enabled
Definition: p_device.h:62
MCR_API int mcr_Device_set_absolute_resolution(struct mcr_context *ctx, __s32 resolution)
MCR_API int mcr_Device_initialize(struct mcr_context *context)