summaryrefslogtreecommitdiff
path: root/rcm-server-main.c
diff options
context:
space:
mode:
Diffstat (limited to 'rcm-server-main.c')
-rw-r--r--rcm-server-main.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/rcm-server-main.c b/rcm-server-main.c
index 3d8ceee..283b685 100644
--- a/rcm-server-main.c
+++ b/rcm-server-main.c
@@ -190,6 +190,8 @@ static const sd_bus_vtable device_vtable[] = {
SD_BUS_METHOD("EchoString", "s", "s", method_echostring, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("ListKeymaps", NULL, "as", method_listkeymaps, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("GetKeymap", "s", "qqaa{sv}", method_getkeymap, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_SIGNAL("KeyPressed", "s", 0),
+ SD_BUS_SIGNAL("KeyReleased", "s", 0),
SD_BUS_VTABLE_END
};
@@ -477,6 +479,45 @@ block_signals(void)
return sigprocmask(SIG_BLOCK, &sigset, NULL);
}
+#include <time.h>
+
+typedef uint64_t usec_t;
+#define USEC_PER_SEC ((usec_t)1000000ULL)
+#define NSEC_PER_USEC ((usec_t)1000ULL)
+
+static usec_t
+now(clockid_t clk_id)
+{
+ struct timespec ts;
+
+ clock_gettime(clk_id, &ts);
+
+ return (usec_t)(ts.tv_sec * USEC_PER_SEC) + (usec_t)(ts.tv_nsec / NSEC_PER_USEC);
+}
+
+static int
+timeout_cb(sd_event_source *source, usec_t usec, void *userdata)
+{
+ struct manager *mgr = userdata;
+ static bool pressed = true;
+ unsigned timeout;
+
+ sd_bus_emit_signal(mgr->bus, "/org/gnome/RemoteControlManager/rc0",
+ "org.gnome.RemoteControlManager.Device",
+ pressed ? "KeyPressed" : "KeyReleased",
+ "s", "KEY_VIDEO");
+
+ if (pressed)
+ timeout = USEC_PER_SEC / 2;
+ else
+ timeout = USEC_PER_SEC * 3;
+
+ sd_event_source_set_time(source, now(CLOCK_MONOTONIC) + timeout);
+ sd_event_source_set_enabled(source, SD_EVENT_ONESHOT);
+ pressed = !pressed;
+ return 0;
+}
+
int
main(int argc, char **argv)
{
@@ -488,6 +529,7 @@ main(int argc, char **argv)
_cleanup_bus_slot_unref_ struct sd_bus_slot *objm_slot = NULL;
_cleanup_event_source_unref_ sd_event_source *sigint_ev = NULL;
_cleanup_event_source_unref_ sd_event_source *sigterm_ev = NULL;
+ _cleanup_event_source_unref_ sd_event_source *timeout_ev = NULL;
mgr = zmalloc(sizeof(*mgr));
if (!mgr) {
@@ -556,6 +598,11 @@ main(int argc, char **argv)
sd_event_add_signal(mgr->event, &sigint_ev, SIGINT, NULL, NULL);
sd_event_add_signal(mgr->event, &sigterm_ev, SIGTERM, NULL, NULL);
+ printf("Sending fake keypress events\n");
+ sd_event_add_time(mgr->event, &timeout_ev, CLOCK_MONOTONIC,
+ now(CLOCK_MONOTONIC) + 3 * USEC_PER_SEC,
+ 0, timeout_cb, mgr);
+
r = sd_event_loop(mgr->event);
if (r < 0) {
fprintf(stderr, "Event loop failed: %s\n", strerror(-r));